pub trait ToolCallParser: Send {
// Required methods
fn push_text(&mut self, chunk: &str) -> ParserOutput;
fn push_reasoning(&mut self, chunk: &str) -> ParserOutput;
fn finish(&mut self) -> ParserOutput;
}Expand description
Stream-stateful parser that normalizes a single LLM dialect into
canonical ParserOutput fragments.
Implementations MUST:
- Be chunk-safe: dialect markers may straddle chunk boundaries, so the
parser must internally buffer ambiguous trailing bytes and flush them
on a later call or at
Self::finish. - Be deterministic: feeding the same byte sequence in any chunking yields the same total output (modulo when individual bytes flush).
- Never lose input bytes: every byte of input is either forwarded
verbatim, consumed as part of a recognised marker, or surfaced via a
NormalizationError.
Implementations are NOT required to be Send here — the
NormalizingStream adapter erases the parser through Box<dyn …> and
adds the Send bound at that boundary.
Required Methods§
Sourcefn push_text(&mut self, chunk: &str) -> ParserOutput
fn push_text(&mut self, chunk: &str) -> ParserOutput
Feed a chunk that arrived on the upstream text channel.
Sourcefn push_reasoning(&mut self, chunk: &str) -> ParserOutput
fn push_reasoning(&mut self, chunk: &str) -> ParserOutput
Feed a chunk that arrived on the upstream reasoning channel.
Sourcefn finish(&mut self) -> ParserOutput
fn finish(&mut self) -> ParserOutput
Flush any buffered partial state at end-of-stream.
Called exactly once per stream, after the last push_* call and
before the surrounding Done event is forwarded downstream.
Implementations should emit any held-back bytes as text and surface
any unfinished marker state as an NormalizationError.