Server-Sent Events framing helpers for the Streamable HTTP transport.
Event IDs are namespaced per stream (<stream_id>:<seq>) so the server can map a
Last-Event-ID back to the originating stream during resumption, as the transport
spec requires.
Summary
Functions
Builds an SSE comment line, useful as a keep-alive heartbeat.
Builds a per-stream event id of the form <stream_id>:<seq>.
Formats a JSON-RPC message as an SSE event with the given id.
Parses a Last-Event-ID value into {stream_id, seq}.
Builds the priming event: an event id with an empty data field, sent first so the
client can immediately reconnect using that id as Last-Event-ID.
Builds a retry directive instructing the client how long to wait before reconnecting.
Functions
Builds an SSE comment line, useful as a keep-alive heartbeat.
@spec event_id(String.t(), non_neg_integer()) :: String.t()
Builds a per-stream event id of the form <stream_id>:<seq>.
Formats a JSON-RPC message as an SSE event with the given id.
The JSON payload is emitted on a single data: line (JSON never contains raw
newlines once encoded).
@spec parse_event_id(String.t()) :: {String.t(), non_neg_integer()} | :error
Parses a Last-Event-ID value into {stream_id, seq}.
Returns :error when the value is not a recognised per-stream id.
Builds the priming event: an event id with an empty data field, sent first so the
client can immediately reconnect using that id as Last-Event-ID.
@spec retry(non_neg_integer()) :: iodata()
Builds a retry directive instructing the client how long to wait before reconnecting.