-
Notifications
You must be signed in to change notification settings - Fork 84
Description
Is your feature request related to a problem? Please describe.
convert_to_sse only emits data: lines. Consumers can't distinguish event types without parsing the JSON
payload, and there's no support for resumable streams via the SSE id field.
Describe the solution you'd like
Add an SseEvent dataclass with data, event, and id fields. When _convert_to_sse receives an SseEvent, it
emits the appropriate event: and id: lines. Plain values still produce data:-only frames — fully
backward-compatible.
Describe alternatives you've considered
- Tuple convention ((event_type, data)) — ambiguous since tuples could be legitimate data, and doesn't
support optional fields like id. - Structured envelope dicts ({"event": "...", "data": ...}) — breaking change that moves SSE framing into
the application layer.
Additional context
The SSE spec defines three frame fields: event, data, and id. Supporting event lets consumers route on
event type directly. Supporting id enables resumable streams via Last-Event-ID on reconnect. Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#fields