36 lines
975 B
Python
36 lines
975 B
Python
|
|
"""Hook dispatch — AP1.0 stub with audit trail."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any, Optional
|
||
|
|
|
||
|
|
from steering.hooks.registry import get_hook
|
||
|
|
from tenant_context import TenantContext
|
||
|
|
|
||
|
|
|
||
|
|
def dispatch_hook(
|
||
|
|
slug: str,
|
||
|
|
ctx: TenantContext | None,
|
||
|
|
payload: dict[str, Any],
|
||
|
|
*,
|
||
|
|
tenant_id: Optional[str] = None,
|
||
|
|
user_id: Optional[str] = None,
|
||
|
|
) -> list[dict[str, Any]]:
|
||
|
|
"""Dispatch hook — AP1.0: audit only, no handlers yet."""
|
||
|
|
hook = get_hook(slug)
|
||
|
|
if not hook:
|
||
|
|
return [{"kind": "hook_unknown", "slug": slug}]
|
||
|
|
|
||
|
|
tid = tenant_id or (ctx.tenant_id if ctx else None)
|
||
|
|
if tid and user_id:
|
||
|
|
from services.audit import log_audit
|
||
|
|
|
||
|
|
log_audit(
|
||
|
|
f"steering.hook.{slug}",
|
||
|
|
user_id=user_id,
|
||
|
|
tenant_id=tid,
|
||
|
|
details={"slug": slug, "payload": payload},
|
||
|
|
)
|
||
|
|
|
||
|
|
return [{"kind": "hook_dispatched", "slug": slug, "lifecycle_step": hook.lifecycle_step}]
|