feat(agent): SSE — progressive Themen-Tabs (Phase 2)

Der Compliance-Check streamt jetzt progressive Events; der Impressum-Tab
erscheint, sobald das Thema fertig ist, statt am Ende alles auf einmal.
Additiv — das Polling fürs finale Ergebnis bleibt.

- backend: _sse.py (Queue/emit/event_generator) + Endpoint
  /compliance-check/{id}/stream; _update emittiert progress,
  run_agent_outputs emittiert topic (laeuft jetzt frueh nach Phase B),
  Orchestrator emittiert complete/error.
- frontend: SSE-Proxy-Route + EventSource in ComplianceCheckTab merged
  topic-Events in agent_outputs -> Tab erscheint progressiv.
- Tests: backend 5 passed (SSE + agent_outputs); tsc 0 neue Fehler,
  vitest 2 passed, check-loc 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-06-10 19:07:26 +02:00
parent e21984e0ad
commit 65de90114a
8 changed files with 246 additions and 5 deletions
@@ -30,6 +30,7 @@ import uuid as _uuid
import httpx
from fastapi import APIRouter
from fastapi.responses import StreamingResponse
# ── Re-exports: external callers import these from THIS module ──────
from .agent_check._constants import ( # noqa: F401
@@ -63,6 +64,7 @@ from .agent_check._schemas import (
ExtractTextRequest,
)
from .agent_check._single_check import _check_single # noqa: F401
from .agent_check._sse import event_generator, new_queue
logger = logging.getLogger(__name__)
@@ -137,6 +139,7 @@ async def start_compliance_check(req: ComplianceCheckRequest):
"result": None,
"error": "",
}
new_queue(check_id) # SSE: progressive topic-Events fürs Frontend
asyncio.create_task(_run_compliance_check(check_id, req))
return ComplianceCheckStartResponse(check_id=check_id, status="running")
@@ -157,6 +160,21 @@ async def get_compliance_check_status(check_id: str):
)
@router.get("/compliance-check/{check_id}/stream")
async def stream_compliance_check(check_id: str) -> StreamingResponse:
"""SSE-Stream: progressive Events (progress/topic/complete) eines
laufenden Checks. Additiv zum Polling auf /compliance-check/{check_id}."""
return StreamingResponse(
event_generator(check_id),
media_type="text/event-stream",
headers={
"Cache-Control": "no-cache",
"X-Accel-Buffering": "no", # nginx: nicht puffern
"Connection": "keep-alive",
},
)
# ── P80: Snapshot + Replay ───────────────────────────────────────────
@router.get("/snapshots")