LlmCall.SSE (llm_call v0.1.0)

Copy Markdown View Source

Server-sent event framing.

The transport hands over body chunks; this module turns them into data payloads. Only data: matters to the codecs — event:, id:, retry:, and comment lines are ignored — and multiple data: lines in one event are joined with a newline, as the SSE specification requires.

A chunk may split a line or an event; the remainder is kept in buffer until the next chunk. flush/1 returns a trailing event that arrived without its terminating blank line, and an empty buffer when the body ended cleanly.

{payloads, state} = SSE.parse(state, chunk)

Summary

Functions

Returns the event left in the buffer at end of body, if any.

Parses one body chunk into the events it completes.

Types

t()

@type t() :: %LlmCall.SSE{buffer: String.t(), cr_pending?: boolean()}

Functions

flush(sse)

@spec flush(t()) :: {[String.t()], t()}

Returns the event left in the buffer at end of body, if any.

Providers terminate events with a blank line, so this is normally empty; it exists so a truncated stream does not lose its last event.

new()

@spec new() :: t()

parse(sse, chunk)

@spec parse(t(), binary()) :: {[String.t()], t()}

Parses one body chunk into the events it completes.