# `Gemini.SSE.Parser`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.15.0/lib/gemini/sse/parser.ex#L1)

Server-Sent Events (SSE) parser for streaming responses.

Handles partial chunks and maintains state across multiple calls.
Properly parses SSE format with incremental data.

# `parse_result`

```elixir
@type parse_result() :: {:ok, [map()], t()} | {:error, term()}
```

# `t`

```elixir
@type t() :: %Gemini.SSE.Parser{buffer: String.t(), events: [map()]}
```

# `extract_text`

```elixir
@spec extract_text(map()) :: String.t() | nil
```

Extract text content from a streaming event.

# `finalize`

```elixir
@spec finalize(t()) :: {:ok, [map()]}
```

Finalize parsing and return any remaining events in buffer.

Call this when the stream is complete to get any final partial events.

# `new`

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

Create a new SSE parser state.

# `parse_chunk`

```elixir
@spec parse_chunk(String.t(), t()) :: parse_result()
```

Parse incoming SSE chunk and return events + updated state.

## Examples

    iex> parser = SSE.Parser.new()
    iex> chunk = "data: {\"text\": \"hello\"}

"
    iex> {:ok, events, new_parser} = SSE.Parser.parse_chunk(chunk, parser)
    iex> length(events)
    1

# `stream_done?`

```elixir
@spec stream_done?(map()) :: boolean()
```

Check if an event indicates the stream is done.

---

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