# `LlmCall.SSE`
[🔗](https://github.com/gilbertwong96/llm_call/blob/main/lib/llm_call/sse.ex#L1)

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)

# `t`

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

# `flush`

```elixir
@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`

```elixir
@spec new() :: t()
```

# `parse`

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

Parses one body chunk into the events it completes.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
