Skip to main content

WireStreamEvent

Enum WireStreamEvent 

Source
#[non_exhaustive]
pub enum WireStreamEvent { MessageStart { protocol_version: u32, model: String, provider: ProviderKind, }, TextDelta { text: String, }, ToolCallStart { id: String, name: String, }, ToolCallDelta { id: String, arguments: String, }, ToolCallEnd { id: String, name: String, arguments: String, }, ToolResult { id: String, result: String, }, Usage { usage: Usage, }, MessageStop { finish_reason: Option<String>, }, TurnComplete { turn: ConversationTurn, }, Error { error: WireError, }, }
Expand description

A stream event in its serializable, over-the-wire form.

See the module documentation for the JSON shape and the compatibility guarantees attached to the "type" tags.

A well-formed stream starts with exactly one MessageStart and ends with exactly one terminal event — MessageStop on success, Error on failure (see is_terminal). A stream that simply stops is a truncated stream: the connection died. That distinction is the whole point of putting errors on the wire, and StreamAccumulator::finish enforces it.

This enum is #[non_exhaustive]: new event types are additive, so match with a catch-all arm.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

MessageStart

The stream has opened. Always the first event.

Fields

§protocol_version: u32

Revision of the wire framing the sender speaks.

Defaults to WIRE_PROTOCOL_VERSION when absent, so payloads written before this field existed still parse.

§model: String

Model identifier the request was routed to.

§provider: ProviderKind

Provider serving the request.

§

TextDelta

An incremental piece of assistant text to append to the output so far.

Fields

§text: String

Text to append.

§

ToolCallStart

A tool call has begun; its arguments arrive in later events.

Fields

§id: String

Provider-assigned call identifier.

§name: String

Name of the tool the model wants to run.

§

ToolCallDelta

A fragment of the JSON argument string for a tool call.

Fields

§id: String

Identifier of the call these arguments belong to.

§arguments: String

Partial JSON text to append to previously received fragments.

§

ToolCallEnd

A tool call has finished streaming, with its arguments assembled.

Fields

§id: String

Provider-assigned call identifier.

§name: String

Name of the tool the model wants to run.

§arguments: String

Complete raw JSON argument string.

§

ToolResult

The result of executing a tool call.

Never emitted by stream_wire_events, which does not run tools. It exists so a proxy that executes tools itself can report them to its client using the same envelope.

Fields

§id: String

Identifier of the call this result answers.

§result: String

Serialized tool output.

§

Usage

Token usage for the generation.

Emitted once, just before the terminal event, when the provider reports usage. This is the event a server bills against and a client displays, so it deliberately carries the counts rather than a summary.

Fields

§usage: Usage

Token counts as reported by the provider.

§

MessageStop

Generation finished cleanly. Terminal.

Fields

§finish_reason: Option<String>

Why generation stopped, e.g. "stop", "length", or "tool_use".

§

TurnComplete

An assembled conversation turn, ready to be stored as history.

Never emitted by stream_wire_events; it is the wire form of StreamEvent::TurnComplete, so events from generate_stream_events can be forwarded without loss.

Fields

§turn: ConversationTurn

The complete turn.

§

Error

Generation failed. Terminal.

Receiving this means the provider or the SDK rejected the request after the stream opened. A client that never receives a terminal event lost its connection instead — a different failure with a different remedy.

Fields

§error: WireError

What went wrong.

Implementations§

Source§

impl WireStreamEvent

Source

pub fn message_start(model: impl Into<String>, provider: ProviderKind) -> Self

Build the opening event for a stream, stamped with WIRE_PROTOCOL_VERSION.

Source

pub fn error(error: &Error) -> Self

Build a terminal error event from a crate Error.

Source

pub fn tag(&self) -> &'static str

The "type" discriminant this event serializes with.

Useful as the SSE event: name, or for logging and metrics labels without serializing the whole payload.

Source

pub fn is_terminal(&self) -> bool

Whether this event ends the stream: MessageStop or Error.

Trait Implementations§

Source§

impl Clone for WireStreamEvent

Source§

fn clone(&self) -> WireStreamEvent

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 Debug for WireStreamEvent

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WireStreamEvent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<StreamEvent> for WireStreamEvent

Source§

fn from(event: StreamEvent) -> Self

Forward a high-level StreamEvent onto the wire without loss.

Every StreamEvent has an exact counterpart here, and TryFrom<WireStreamEvent> converts it back to the same value.

Source§

impl PartialEq for WireStreamEvent

Source§

fn eq(&self, other: &WireStreamEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for WireStreamEvent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for WireStreamEvent

Source§

impl TryFrom<WireStreamEvent> for StreamEvent

Source§

type Error = UnrepresentableWireEvent

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

fn try_from(event: WireStreamEvent) -> Result<Self, UnrepresentableWireEvent>

Performs the conversion.

Auto Trait Implementations§

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, 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> 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<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