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
@@ -0,0 +1,41 @@
/**
* Compliance-Check SSE-Proxy
* GET /api/sdk/v1/agent/compliance-check/{check_id}/stream
* → backend /api/compliance/agent/compliance-check/{check_id}/stream
*
* Reicht den text/event-stream-Body unmodifiziert durch (progressive
* topic-/progress-Events fürs Frontend). Additiv zum Polling.
*/
import { NextRequest, NextResponse } from 'next/server'
const BACKEND_URL =
process.env.BACKEND_API_URL || process.env.BACKEND_URL ||
'http://backend-compliance:8002'
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ check_id: string }> },
) {
const { check_id } = await params
try {
const response = await fetch(
`${BACKEND_URL}/api/compliance/agent/compliance-check/${check_id}/stream`,
{ signal: AbortSignal.timeout(1_800_000) }, // 30 min
)
return new NextResponse(response.body, {
status: response.status,
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'X-Accel-Buffering': 'no',
},
})
} catch {
return NextResponse.json(
{ error: 'SSE-Stream zum Backend fehlgeschlagen' },
{ status: 503 },
)
}
}