refactor(block-h): knowledge retention job lives with plugin; compliance via contract
This commit is contained in:
@@ -19,11 +19,21 @@ from app.core.db import get_db
|
||||
from app.deps import require_permission
|
||||
from app.models.audit import AuditLog
|
||||
from app.models.compliance import ComplianceIncident
|
||||
from app.plugins.builtins.automation.models import AgentDefinition
|
||||
from app.plugins.builtins.contracts import get_contract as _get_automation_contract
|
||||
|
||||
router = APIRouter(prefix="/api/v1/compliance", tags=["compliance"])
|
||||
|
||||
|
||||
def _get_agent_definition_model():
|
||||
"""Resolve the AgentDefinition model via the automation contract.
|
||||
|
||||
Returns ``None`` when the automation plugin is not active — callers
|
||||
respond with 503 instead of failing at import time.
|
||||
"""
|
||||
contract = _get_automation_contract("automation")
|
||||
return getattr(contract, "AgentDefinition", None) if contract else None
|
||||
|
||||
|
||||
# ─── Schemas ───
|
||||
|
||||
|
||||
@@ -160,13 +170,17 @@ async def list_ai_registry(
|
||||
"""List all AI agents with their use-case metadata. Admin only."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
|
||||
agent_model = _get_agent_definition_model()
|
||||
if agent_model is None:
|
||||
raise HTTPException(503, detail={"detail": "Automation plugin not active", "code": "plugin_inactive"})
|
||||
|
||||
q = (
|
||||
select(AgentDefinition)
|
||||
select(agent_model)
|
||||
.where(
|
||||
AgentDefinition.tenant_id == tenant_id,
|
||||
AgentDefinition.deleted_at.is_(None),
|
||||
agent_model.tenant_id == tenant_id,
|
||||
agent_model.deleted_at.is_(None),
|
||||
)
|
||||
.order_by(AgentDefinition.name)
|
||||
.order_by(agent_model.name)
|
||||
)
|
||||
result = await db.execute(q)
|
||||
agents = result.scalars().all()
|
||||
@@ -214,10 +228,14 @@ async def get_dpia_template(
|
||||
except ValueError:
|
||||
raise HTTPException(400, detail={"detail": "Invalid agent_id", "code": "invalid_id"}) from None
|
||||
|
||||
q = select(AgentDefinition).where(
|
||||
AgentDefinition.id == aid,
|
||||
AgentDefinition.tenant_id == tenant_id,
|
||||
AgentDefinition.deleted_at.is_(None),
|
||||
agent_model = _get_agent_definition_model()
|
||||
if agent_model is None:
|
||||
raise HTTPException(503, detail={"detail": "Automation plugin not active", "code": "plugin_inactive"})
|
||||
|
||||
q = select(agent_model).where(
|
||||
agent_model.id == aid,
|
||||
agent_model.tenant_id == tenant_id,
|
||||
agent_model.deleted_at.is_(None),
|
||||
)
|
||||
result = await db.execute(q)
|
||||
agent = result.scalar_one_or_none()
|
||||
|
||||
Reference in New Issue
Block a user