Skip to main content

RawStreamingChoice

Enum RawStreamingChoice 

Source
pub enum RawStreamingChoice<R = StreamFinal> {
Show 14 variants Message(String), TextStart { id: StreamPartId, additional_params: Option<AdditionalParams>, }, TextAdditionalParams(AdditionalParams), ToolCall(RawStreamingToolCall), ToolCallDelta { id: StreamPartId, content: ToolCallDeltaContent, }, ToolInputEnd(ToolInputEnd), Reasoning { id: StreamPartId, provider_id: Option<WireId>, content: ReasoningContent, }, ReasoningStart { id: StreamPartId, provider_id: Option<WireId>, }, ReasoningEnd { id: StreamPartId, reasoning: Option<Reasoning>, signature: Option<String>, wire_sent: bool, }, TextEnd { id: StreamPartId, }, ReasoningDelta { id: StreamPartId, provider_id: Option<WireId>, reasoning: String, }, FinalResponse(R), MessageId(String), Unknown(UnknownPayload),
}
Expand description

Enum representing a streaming chunk from the model.

R is the terminal record type. Ordinary streams use the normalized StreamFinal default; a provider’s inherent raw_stream method substitutes its own native terminal type over the same event vocabulary, which is what keeps crate::completion::CompletionModel free of response associated types.

Variants§

§

Message(String)

A text chunk from a message response

§

TextStart

Start a new text content block in the accumulated final choice.

This is an internal provider-normalization event. It is not yielded to public stream consumers, but lets providers preserve block boundaries and metadata for final aggregated assistant text blocks.

Fields

§id: StreamPartId

Identity of the text block being opened.

The same mandatory-identity contract as RawStreamingChoice::Reasoning::id: distinct wire output items must aggregate as distinct text parts (two OpenAI Responses message items must not concatenate), so the accumulator keys text blocks by identity. Providers propagate the wire’s item identity (StreamPartId::Wire: the Responses item_id, Anthropic’s block index) when it exists, or mint one at the boundary (StreamPartId::Minted, via SyntheticIds). A wire that never announces text boundaries may skip TextStart entirely: a bare RawStreamingChoice::Message with no open block opens a boundary-minted block.

§additional_params: Option<AdditionalParams>

Provider-specific metadata attached to this text block.

§

TextAdditionalParams(AdditionalParams)

Provider-specific metadata for the current text content block.

This is not yielded to public stream consumers. The metadata is merged into the current aggregated Text block. crate::message::AdditionalParams is non-empty by construction, so a provider with nothing to attach skips the variant instead of emitting an empty carrier.

§

ToolCall(RawStreamingToolCall)

A tool call response (in its entirety) — wires that never fragment tool input emit this directly; fragmenting wires emit RawStreamingChoice::ToolCallDelta fragments closed by RawStreamingChoice::ToolInputEnd, and the shared accumulator assembles the completed call.

§

ToolCallDelta

A tool call partial/delta.

All fragments of one call carry one id; the shared accumulator keys assembly by it and mints the internal correlation id when the call opens, so adapters never track per-call state.

Fields

§id: StreamPartId

Identity of the tool call this fragment extends, stable across the call’s fragments.

The same mandatory-identity contract as RawStreamingChoice::Reasoning::id: parallel calls interleave their fragments on real wires, so the accumulator must key assembly by identity. Providers propagate the wire’s tool-call id (StreamPartId::Wire), or mint one at the boundary from the wire’s own index (StreamPartId::Minted, via SyntheticIds) when the wire omits it — a shared identity would collapse parallel calls into one corrupted assembly. A minted identity keys assembly only; it never becomes the completed call’s durable ToolCall::id.

§

ToolInputEnd(ToolInputEnd)

End of a streamed tool call’s input: the shared accumulator finalizes the assembled fragments (or the event’s authoritative payload) into a completed tool call.

§

Reasoning

A reasoning (in its entirety)

Fields

§id: StreamPartId

Identity of the reasoning item this block belongs to.

Required: reasoning interleaves with other output on real wires (OpenAI Responses emits the completed item after tool calls), so the accumulator must key by identity rather than guess by adjacency. Providers propagate the wire’s item id (StreamPartId::Wire: item_id on Responses events) or mint a stream-scoped id at the boundary (StreamPartId::Minted, via SyntheticIds) when the wire has none. Deltas and the full block for the same item MUST carry the same key.

§provider_id: Option<WireId>

The provider-issued reasoning item id, when one exists — the durable handle that becomes Reasoning::id and round-trips upstream. Carried separately from the accumulation key: the key is opaque and can never leak; the handle is data.

§content: ReasoningContent

Complete reasoning content block.

§

ReasoningStart

Open the reasoning part identified by id.

Optional — a bare RawStreamingChoice::ReasoningDelta opens its part leniently — but a wire that announces block starts should emit it so arrival order is fixed at the wire’s own boundary. A start for an already-open key is a no-op; a start for a finished key opens a new part (key reuse). Not yielded to public stream consumers.

Fields

§id: StreamPartId

Accumulation key of the reasoning part being opened.

§provider_id: Option<WireId>

The provider-issued reasoning item id, when one exists.

§

ReasoningEnd

Close the reasoning part identified by id — the lifecycle primitive every wire has (or has synthesized by its adapter at the boundaries it already detects), so “is this part still open?” is never re-derived per wire.

reasoning is the wire’s authoritative whole-block restatement; it supersedes the delta accumulation. signature is a provider signature closing the block; it attaches to the part’s text — and because an end for an already-finished key with only a signature attaches to THAT part, a trailing signature signs the block that holds the chain-of-thought instead of fabricating an empty sibling. A repeated end with no payload is a no-op: idempotence belongs to the entity, not to a guard each route must remember.

The completed part is yielded to consumers as StreamedAssistantContent::Reasoning — the uniform block-completed signal across every wire — when the wire itself said something at the boundary: an end carrying a restatement or signature, or a bare end frame the wire actually sent (wire_sent). A bare end an adapter synthesized at an interleaving boundary stays silent: the consumer already received every delta, and fabricating a completion event the wire never sent would change what downstream history builders observe.

Fields

§id: StreamPartId

Accumulation key of the reasoning part being closed.

§reasoning: Option<Reasoning>

The wire’s authoritative completed block, when it restates one.

§signature: Option<String>

A provider signature closing the block.

§wire_sent: bool

Whether the wire itself sent this end frame (anthropic’s content_block_stop), as opposed to the adapter synthesizing it at a boundary the wire never announces. Wire-sent ends yield the completed block even when bare.

§

TextEnd

Close the text block identified by id: later bare text deltas open a fresh block instead of extending it. (A later RawStreamingChoice::TextStart with the same key still reactivates the block — the keyed collapse is explicit.) Not yielded to public stream consumers.

Fields

§id: StreamPartId

Accumulation key of the text block being closed.

§

ReasoningDelta

A reasoning partial/delta

Fields

§id: StreamPartId

Accumulation key of the reasoning item this delta extends. Same contract as RawStreamingChoice::Reasoning::id; all deltas of one block share one key.

§provider_id: Option<WireId>

The provider-issued reasoning item id, when one exists (see RawStreamingChoice::Reasoning::provider_id) — what a delta-built part records as its durable id.

§reasoning: String

Partial reasoning text.

§

FinalResponse(R)

The final response object, must be yielded if you want the response field to be populated on the StreamingCompletionResponse

§

MessageId(String)

Provider-assigned message ID (e.g. OpenAI Responses API msg_ ID). Captured silently into StreamingCompletionResponse::message_id.

§

Unknown(UnknownPayload)

A provider-native output item this version does not model — e.g. an OpenAI Responses hosted-tool result (web_search_call, file_search_call, computer_call, code_interpreter_call). Carries the raw item object verbatim. Forwarded to the stream consumer as StreamedAssistantContent::Unknown but not folded into the accumulated assistant message (there is no AssistantContent::Unknown history slot).

Implementations§

Source§

impl<R> RawStreamingChoice<R>

Source

pub fn try_map_final<S>( self, map: impl FnOnce(R) -> Result<S, CompletionError>, ) -> Result<RawStreamingChoice<S>, CompletionError>

Convert only the terminal record, preserving every incremental content event unchanged.

Trait Implementations§

Source§

impl<R> Clone for RawStreamingChoice<R>
where R: Clone,

Source§

fn clone(&self) -> RawStreamingChoice<R>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for RawStreamingChoice<R>
where R: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for RawStreamingChoice<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for RawStreamingChoice<R>
where R: RefUnwindSafe,

§

impl<R> Send for RawStreamingChoice<R>
where R: Send,

§

impl<R> Sync for RawStreamingChoice<R>
where R: Sync,

§

impl<R> Unpin for RawStreamingChoice<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for RawStreamingChoice<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for RawStreamingChoice<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneDebuggableStorage for T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more