Skip to main content

Module sse_buffer

Module sse_buffer 

Source
Expand description

Reassemble newline-delimited frames across arbitrary network chunks.

Provider streams (SSE for OpenAI/Anthropic, NDJSON for Ollama) deliver “one frame per line”. A single TCP/HTTP chunk can split a frame at any byte, which the previous code did not handle — it ran text.lines() on each chunk in isolation and silently dropped the trailing partial line, eating characters mid-stream (e.g. “à rebours” arrived as “àours” because the “reb” segment lived on the boundary).

LineBuffer is the minimal fix: feed it chunk bytes, get back the complete lines that have accumulated. The unfinished tail stays inside the buffer until the next chunk completes it.

Structs§

LineBuffer
Accumulates raw bytes and yields complete \n-terminated lines. Partial trailing data is preserved across calls. Tolerates \r\n and mixed UTF-8 by accumulating bytes first and only converting to &str per complete line.