Skip to main content

Module stream_fold

Module stream_fold 

Source
Expand description

The streaming assistant message, folded from message_update frames (Rust-only). A message_update event carries the provider frame and the usage so far, not the message: sending the whole message with every delta made streaming quadratic in the answer’s length (serialized, sent and diffed once per token). A watcher starts from the message_start message and folds each frame into it, as the provider built its partial:

  • text_start / thinking_start open an empty block at the frame’s index; *_delta appends; *_end sets the block’s final text.
  • toolcall_start opens a call (id, toolName from the frame) with empty arguments; toolcall_delta appends to its streamed argument text, kept beside the call as partialJson, and parses it as the providers do (jsrt::json_parse::parse_streaming_json); toolcall_end puts the finished call in its place.

A message_update from an older worker still carries message: it replaces the fold (message_of).

Constants§

PARTIAL_JSON
The streamed argument text of a tool call still being written (dropped when the call ends).

Functions§

fold_frame
fold_update
Fold one message_update event into message (the streaming message so far): its frame, and its usage.
message_of
The message an update gives a watcher that had none: an older worker’s whole message, else nothing.