"""Server-sent events, the one way this API streams. Two endpoints stream (a chat turn and a section refinement) and they frame the same way, so the wire format lives here rather than in both. `event:` names the frame, `data:` carries a JSON object, and a blank line ends it. """ import json from typing import Any def sse(event: str, data: dict[str, Any]) -> str: return f"event: {event}\ndata: {json.dumps(data)}\n\n"