#[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
MessageStart
The stream has opened. Always the first event.
Fields
protocol_version: u32Revision of the wire framing the sender speaks.
Defaults to WIRE_PROTOCOL_VERSION when absent, so payloads
written before this field existed still parse.
provider: ProviderKindProvider serving the request.
TextDelta
An incremental piece of assistant text to append to the output so far.
ToolCallStart
A tool call has begun; its arguments arrive in later events.
Fields
ToolCallDelta
A fragment of the JSON argument string for a tool call.
Fields
ToolCallEnd
A tool call has finished streaming, with its arguments assembled.
Fields
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.
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.
MessageStop
Generation finished cleanly. Terminal.
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: ConversationTurnThe 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.
Implementations§
Source§impl WireStreamEvent
impl WireStreamEvent
Sourcepub fn message_start(model: impl Into<String>, provider: ProviderKind) -> Self
pub fn message_start(model: impl Into<String>, provider: ProviderKind) -> Self
Build the opening event for a stream, stamped with
WIRE_PROTOCOL_VERSION.
Sourcepub fn tag(&self) -> &'static str
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.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Whether this event ends the stream: MessageStop or Error.
Trait Implementations§
Source§impl Clone for WireStreamEvent
impl Clone for WireStreamEvent
Source§fn clone(&self) -> WireStreamEvent
fn clone(&self) -> WireStreamEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WireStreamEvent
impl Debug for WireStreamEvent
Source§impl<'de> Deserialize<'de> for WireStreamEvent
impl<'de> Deserialize<'de> for WireStreamEvent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<StreamEvent> for WireStreamEvent
impl From<StreamEvent> for WireStreamEvent
Source§fn from(event: StreamEvent) -> Self
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.