Skip to main content

Module stream

Module stream 

Source
Expand description

Stream-completion collection with incremental event forwarding.

collect_stream_completion_with_events drains a provider stream, accumulates text and tool-call deltas into a final CompletionResponse, and (optionally) forwards incremental SessionEvent::TextChunk snapshots to a UI layer.

§Snapshot truncation

Each text chunk forwarded over event_tx is a full snapshot of the accumulated assistant text so far. For extremely long replies this would be O(n²) in memory; to bound the worst case the snapshot is capped at MAX_STREAM_SNAPSHOT_BYTES with a trailing " …[truncated]" marker. The full text is still returned in the final [CompletionResponse]; only the streamed previews are truncated.

Constants§

MAX_STREAM_SNAPSHOT_BYTES
Maximum bytes forwarded per SessionEvent::TextChunk snapshot.

Functions§

collect_stream_completion_with_events
Collect a streaming completion into a CompletionResponse, optionally forwarding incremental events.