incremental server-sent-events parser.
pure functional: feed(state, bytes) -> {events, new_state}. the
caller pumps bytes in (typically arriving from finch), and gets back
whatever fully-formed events the parser could complete from the
combined buffer. partial lines stay in state.buffer.
understands:
data:,event:,id:,retry:- comment lines starting with
: - crlf and lf line endings
- multi-line
data:(joined with\n) - the openai-style
[DONE]terminator (emitted as:done)
Summary
Functions
feed bytes into the parser. returns {events, new_state} where
events is the (possibly empty) list of newly completed events in
arrival order.
fresh parser state
Types
@type emitted() :: OpenrouterSdk.SSE.Event.t() | :done
@type state() :: %{ buffer: binary(), event: String.t() | nil, id: String.t() | nil, data: [String.t()], retry: non_neg_integer() | nil }