AP0.4: Feature-, Prompt- und Config-Registry mit Single-Render und Entitlements-Features.
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 18s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 24s
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 18s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 24s
Migration 005, Registry-Sync, Placeholder-Validation, capability-geschuetzte API, Tests und Abschlussbericht v0.1. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f8af47d1d5
commit
53047b6c16
39 files changed
+2404
-34
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""Configuration registry API."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from capabilities import require_capability_ctx
|
||||
from config_service import SECRET_VALUE_FORBIDDEN, list_configs, upsert_config
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
from tenant_context import TenantContext
|
||||
|
||||
router = APIRouter(prefix="/api/config", tags=["config"])
|
||||
|
||||
|
||||
class ConfigUpsertRequest(BaseModel):
|
||||
config_key: str
|
||||
scope: str = "global"
|
||||
value: Any = None
|
||||
value_type: str = "string"
|
||||
description: str = ""
|
||||
is_secret: bool = False
|
||||
tenant_id: str | None = None
|
||||
|
||||
|
||||
@router.get("")
|
||||
def get_configs(
|
||||
scope: str | None = None,
|
||||
ctx: TenantContext = Depends(require_capability_ctx("kairo.config.registry.read")),
|
||||
):
|
||||
tenant_id = ctx.tenant_id if scope == "tenant" else None
|
||||
if scope == "tenant" and not tenant_id:
|
||||
raise HTTPException(status_code=400, detail="Aktiver Tenant erforderlich für tenant-scope")
|
||||
return list_configs(scope=scope, tenant_id=tenant_id)
|
||||
|
||||
|
||||
@router.post("")
|
||||
def post_config(
|
||||
body: ConfigUpsertRequest,
|
||||
ctx: TenantContext = Depends(require_capability_ctx("kairo.config.registry.manage")),
|
||||
):
|
||||
tenant_id = body.tenant_id
|
||||
if body.scope == "tenant":
|
||||
tenant_id = tenant_id or ctx.tenant_id
|
||||
if not tenant_id:
|
||||
raise HTTPException(status_code=400, detail="tenant_id erforderlich")
|
||||
try:
|
||||
return upsert_config(
|
||||
config_key=body.config_key,
|
||||
scope=body.scope,
|
||||
value=body.value,
|
||||
value_type=body.value_type,
|
||||
description=body.description,
|
||||
is_secret=body.is_secret,
|
||||
tenant_id=tenant_id,
|
||||
user_id=ctx.user_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
if str(exc) == SECRET_VALUE_FORBIDDEN:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Feature registry API."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from capabilities import require_capability_ctx
|
||||
from db import get_connection
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
router = APIRouter(prefix="/api/features", tags=["features"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_features(_ctx=Depends(require_capability_ctx("kairo.feature.registry.read"))):
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT feature_key, module, name, description, is_active
|
||||
FROM features
|
||||
ORDER BY feature_key
|
||||
"""
|
||||
)
|
||||
return [
|
||||
{
|
||||
"feature_key": row[0],
|
||||
"module": row[1],
|
||||
"name": row[2],
|
||||
"description": row[3],
|
||||
"is_active": row[4],
|
||||
}
|
||||
for row in cur.fetchall()
|
||||
]
|
||||
finally:
|
||||
conn.close()
|
||||
@@ -0,0 +1,74 @@
|
||||
"""Prompt registry and rendering API."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from capabilities import require_capability_ctx
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from prompt_context import merge_context_values
|
||||
from prompt_registry import list_prompt_definitions, load_active_prompt_version, load_prompt_definition
|
||||
from prompt_rendering import PromptRenderError, render_prompt_single
|
||||
from pydantic import BaseModel, Field
|
||||
from tenant_context import TenantContext
|
||||
|
||||
router = APIRouter(prefix="/api/prompts", tags=["prompts"])
|
||||
|
||||
|
||||
class RenderPromptRequest(BaseModel):
|
||||
values: dict[str, Any] = Field(default_factory=dict)
|
||||
use_context: bool = True
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_prompts(_ctx=Depends(require_capability_ctx("kairo.prompt.registry.read"))):
|
||||
return list_prompt_definitions()
|
||||
|
||||
|
||||
@router.get("/{prompt_key}")
|
||||
def get_prompt(prompt_key: str, _ctx=Depends(require_capability_ctx("kairo.prompt.registry.read"))):
|
||||
definition = load_prompt_definition(prompt_key)
|
||||
if not definition:
|
||||
raise HTTPException(status_code=404, detail="Prompt nicht gefunden")
|
||||
version = load_active_prompt_version(definition)
|
||||
return {
|
||||
"definition": definition,
|
||||
"active_version": version,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{prompt_key}/render")
|
||||
def render_prompt(
|
||||
prompt_key: str,
|
||||
body: RenderPromptRequest,
|
||||
ctx: TenantContext = Depends(require_capability_ctx("kairo.prompt.render")),
|
||||
):
|
||||
definition = load_prompt_definition(prompt_key)
|
||||
if not definition:
|
||||
raise HTTPException(status_code=404, detail="Prompt nicht gefunden")
|
||||
|
||||
if body.use_context and definition["context_kind"] in (
|
||||
"kairo.tenant_context",
|
||||
"kairo.actor_context",
|
||||
):
|
||||
if not ctx.tenant_id:
|
||||
raise HTTPException(status_code=403, detail="Aktiver Tenant erforderlich für diesen Prompt")
|
||||
|
||||
values = body.values
|
||||
if body.use_context:
|
||||
values = merge_context_values(ctx, definition["context_kind"], body.values)
|
||||
|
||||
try:
|
||||
return render_prompt_single(
|
||||
prompt_key,
|
||||
values=values,
|
||||
user_id=ctx.user_id,
|
||||
log_execution=True,
|
||||
)
|
||||
except PromptRenderError as exc:
|
||||
status = 400
|
||||
if exc.code == "not_found":
|
||||
status = 404
|
||||
elif exc.code == "mode_not_implemented":
|
||||
status = 501
|
||||
raise HTTPException(status_code=status, detail=str(exc)) from exc
|
||||
Reference in new issue
Block a user