pub struct ResponseAccumulator { /* private fields */ }Expand description
Folds a sequence of LlmResponseChunks into the terminal AggLlmResponse.
Text and reasoning deltas concatenate; tool-call deltas assemble by index (name,
id, and a growing arguments string parsed as JSON at the end); MessageStart,
Usage, and MessageStop set the corresponding fields.
DecodeError and
StreamError chunks are ignored here; use
LlmResponse::into_agg when they must become errors.
Folding is lossy for multiple outputs: text and reasoning indices are ignored,
and finish produces one assistant output. Prefer
LlmResponse::into_agg when stream errors must be surfaced.
Drive it by push-ing each chunk in order, then call finish.
Implementations§
Source§impl ResponseAccumulator
impl ResponseAccumulator
Sourcepub fn push(&mut self, chunk: LlmResponseChunk)
pub fn push(&mut self, chunk: LlmResponseChunk)
Apply one chunk. Later MessageStart/Usage/MessageStop fields overwrite
earlier ones; text, reasoning, and tool-call arguments append.
Sourcepub fn finish(self) -> AggLlmResponse
pub fn finish(self) -> AggLlmResponse
Build the buffered response. Content is ordered reasoning, then text, then tool calls (by ascending delta index) — a single assistant output.