pub struct StreamedTurnAssembler { /* private fields */ }Expand description
Sans-IO accumulator that assembles one streamed model turn. See the module docs for the driving protocol.
Implementations§
Source§impl StreamedTurnAssembler
impl StreamedTurnAssembler
Sourcepub fn new(
executable_tool_names: BTreeSet<String>,
allowed_tool_names: BTreeSet<String>,
) -> Self
pub fn new( executable_tool_names: BTreeSet<String>, allowed_tool_names: BTreeSet<String>, ) -> Self
Create an assembler for one streamed turn with the tool names advertised to the provider for that turn.
Sourcepub fn aggregated_text(&self) -> &str
pub fn aggregated_text(&self) -> &str
Aggregated assistant text streamed so far this turn (empty until the first text delta).
Sourcepub fn ingest<R>(
&mut self,
item: &StreamedAssistantContent<R>,
) -> Result<Vec<StreamedTurnEvent>, CompletionError>
pub fn ingest<R>( &mut self, item: &StreamedAssistantContent<R>, ) -> Result<Vec<StreamedTurnEvent>, CompletionError>
Ingest one provider stream item and return what the driver must do.
§Errors
Returns an error when the provider stream is inconsistent (argument deltas finishing without a validated tool name) or when an invalid tool call is still awaiting resolution.
Sourcepub fn resolve_pending_invalid(
&mut self,
resolution: &StreamedResolution,
) -> Vec<StreamedTurnEvent>
pub fn resolve_pending_invalid( &mut self, resolution: &StreamedResolution, ) -> Vec<StreamedTurnEvent>
Apply the machine’s resolution for the invalid tool call surfaced by
the last StreamedTurnEvent::InvalidToolCall. For a repaired name
this returns the deltas to forward (the repaired name plus any
buffered argument deltas).
Sourcepub fn pending_delta_error(&self) -> Option<CompletionError>
pub fn pending_delta_error(&self) -> Option<CompletionError>
Error when argument deltas were buffered for a tool call whose name never validated — a provider-stream consistency violation.
Sourcepub fn partial_turn(&self, message_id: Option<String>) -> PartialStreamedTurn
pub fn partial_turn(&self, message_id: Option<String>) -> PartialStreamedTurn
Snapshot of the turn so far, for diagnostics and rollback messages.
Sourcepub fn finish(
self,
message_id: Option<String>,
final_choice: &OneOrMany<AssistantContent>,
) -> StreamedTurn
pub fn finish( self, message_id: Option<String>, final_choice: &OneOrMany<AssistantContent>, ) -> StreamedTurn
Assemble the completed turn. final_choice is the provider’s
aggregated choice for the turn
(crate::streaming::StreamingCompletionResponse::choice).