Arcanum.SSE (arcanum v0.1.10)

Copy Markdown View Source

Shared Server-Sent Events parsing for Arcanum adapters.

Provides the common SSE stream transform and chunk/line parsing. Adapters supply their own event-to-delta conversion via a callback.

Summary

Functions

Parses a single SSE chunk into a list of events.

Transforms a raw SSE stream into a stream of parsed events.

Functions

parse_chunk(chunk, parse_event, done_sentinel)

@spec parse_chunk(term(), (map() -> term()), String.t() | nil) :: list()

Parses a single SSE chunk into a list of events.

stream(raw_stream, opts)

@spec stream(
  Enumerable.t(),
  keyword()
) :: Enumerable.t()

Transforms a raw SSE stream into a stream of parsed events.

Each chunk is split into SSE lines. Lines matching "data: " prefix are JSON-decoded and passed to parse_event_fn. The stream halts when parse_event_fn returns :done or the done_sentinel is encountered.

Options

  • :parse_eventfn json_map -> {:data, delta} | :done | :skip (required)

  • :done_sentinel — string that signals end of stream (e.g. "[DONE]"), optional