Expand description
Hand-rolled SSE framing (DW-075).
The locked M4 dependency decision is in-house framing: the
text/event-stream wire format is small enough (a line grammar over
a byte stream) that pulling an SSE crate โ and the transitive
futures-stack it would drag into the AI domain โ buys nothing. This
decoder implements the parts the provider dialects actually use:
- events are separated by a blank line (
\n\nor\r\n\r\n), data:lines carry the payload (multipledata:lines in one event join with\n, per the WHATWG spec),event:names the event (Anthropic sendsevent: message_startalongside the data payload),id:andretry:lines are ignored, and:-prefixed comment lines are ignored,- leading whitespace after the field name is stripped once.
What it deliberately does NOT do: charset negotiation,
Last-Event-ID resumption (providers do not support it), or BOM
sniffing โ none of the shipped dialects use any of that.
Structsยง
- SseDecoder
- An incremental SSE decoder: feed it raw bytes as they arrive, take
complete frames back. Call
SseDecoder::finishat stream end to recover a final frame not terminated by a blank line (tolerant providers exist; a well-formed stream yields nothing there). - SseFrame
- One decoded SSE event: its optional name and its data payload.