Server-Sent Events (SSE) stream parser following the W3C EventSource specification.
Handles arbitrary chunk boundaries, LF / CR / CRLF line endings, multi-line data:
fields, the [DONE] sentinel used by OpenAI-compatible APIs, and JSON decoding.
Summary
Functions
Parses a stream (enumerable) of binary chunks into a lazy stream of SSE event maps.
Like parse_stream/1 but JSON-decodes each event's data field.
Types
Functions
@spec parse_stream(Enumerable.t()) :: Enumerable.t()
Parses a stream (enumerable) of binary chunks into a lazy stream of SSE event maps.
Filters out [DONE] sentinels and events with empty data fields.
@spec parse_stream_json(Enumerable.t()) :: Enumerable.t()
Like parse_stream/1 but JSON-decodes each event's data field.
- Raises
ProviderApiErrorif the decoded map contains a top-level"error"key. - Logs a warning and skips events whose
datacannot be decoded as JSON.