Wires the AI relay into the BFF per ADR-0024 (now accepted):
- AiBridgeController exposes POST /api/ai/chat (text/event-stream),
GET /api/ai/rag/search, GET /api/ai/models under /api/ai/*.
Session-gated (req.session.user) without an admin role — AI is
an end-user surface. CSRF and double-submit token handled by the
global middleware mounted in main.ts.
- sse.writer translates ChatEvent oneof cases to kebab-case SSE
event names (token / citation / agent-step / tool-call / error /
done), JSON-encodes the inner payload, and produces a relay-side
error frame on upstream failures (mapped from gRPC Status codes
into the urn:apf-ai:* namespace the AI service already uses).
- DTOs (class-validator) cap message count + length, restrict the
role enum to user/assistant/system (tool messages are constructed
caller-side by the BFF when tool dispatch lands), and bound RAG
top_k between 1 and 50.
- Browser disconnect (req 'close' event) → AbortController →
call.cancel(), upstream LLM stops without leaking the stream.
- AiClientModule now implements OnApplicationShutdown to close the
four gRPC stubs on SIGTERM/SIGINT; main.ts calls
app.enableShutdownHooks() to make it fire.
- ADR-0024 promoted from proposed to accepted; README index + the
CLAUDE.md roll-up updated. apps/portal-bff/.env.example documents
AI_SERVICE_GRPC_ENDPOINT / CLIENT_ID / TLS for local boot.