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::TextChunksnapshot.
Functions§
- collect_
stream_ completion_ with_ events - Collect a streaming completion into a
CompletionResponse, optionally forwarding incremental events.