42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
|
|
"""Actor directory API — AP0.7."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Literal, Optional
|
||
|
|
|
||
|
|
from capabilities import require_capability
|
||
|
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||
|
|
from services import actors as actor_service
|
||
|
|
from tenant_context import TenantContext
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/api/actors", tags=["actors"])
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("")
|
||
|
|
def list_actors(
|
||
|
|
actor_type: Optional[Literal["human", "agent", "working_group", "external_system"]] = None,
|
||
|
|
include_inactive: bool = Query(default=False),
|
||
|
|
q: Optional[str] = Query(default=None, max_length=100),
|
||
|
|
ctx: TenantContext = Depends(require_capability("kairo.actor.read")),
|
||
|
|
):
|
||
|
|
try:
|
||
|
|
return actor_service.list_actors(
|
||
|
|
tenant_id=ctx.tenant_id,
|
||
|
|
actor_type=actor_type,
|
||
|
|
include_inactive=include_inactive,
|
||
|
|
q=q,
|
||
|
|
)
|
||
|
|
except ValueError as exc:
|
||
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{actor_id}")
|
||
|
|
def get_actor(
|
||
|
|
actor_id: str,
|
||
|
|
ctx: TenantContext = Depends(require_capability("kairo.actor.read")),
|
||
|
|
):
|
||
|
|
item = actor_service.get_actor(tenant_id=ctx.tenant_id, actor_id=actor_id)
|
||
|
|
if not item:
|
||
|
|
raise HTTPException(status_code=404, detail="Actor nicht gefunden")
|
||
|
|
return item
|