#[non_exhaustive]pub enum AssistantMessageEvent {
Start,
TextStart {
content_index: usize,
},
TextDelta {
content_index: usize,
delta: String,
},
TextEnd {
content_index: usize,
},
ThinkingStart {
content_index: usize,
},
ThinkingDelta {
content_index: usize,
delta: String,
},
ThinkingEnd {
content_index: usize,
signature: Option<String>,
},
ToolCallStart {
content_index: usize,
id: String,
name: String,
},
ToolCallDelta {
content_index: usize,
delta: String,
},
ToolCallEnd {
content_index: usize,
},
Done {
stop_reason: StopReason,
usage: Usage,
cost: Cost,
},
Error {
stop_reason: StopReason,
error_message: String,
usage: Option<Usage>,
error_kind: Option<StreamErrorKind>,
},
}Expand description
An incremental event emitted by a StreamFn implementation.
Events follow a strict start/delta/end protocol per content block. Each
block carries a content_index that identifies its position in the final
message’s content vec.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Start
The stream has opened.
TextStart
A new text content block is starting at content_index.
TextDelta
An incremental text fragment for the block at content_index.
TextEnd
The text block at content_index is complete.
ThinkingStart
A new thinking content block is starting at content_index.
ThinkingDelta
An incremental thinking fragment for the block at content_index.
ThinkingEnd
The thinking block at content_index is complete, with an optional
provider verification signature.
ToolCallStart
A new tool call content block is starting at content_index.
ToolCallDelta
An incremental JSON argument fragment for the tool call at content_index.
ToolCallEnd
The tool call at content_index is complete.
Done
The stream completed successfully.
Error
The stream ended with an error.
Fields
stop_reason: StopReasonerror_kind: Option<StreamErrorKind>Optional structured error classification.
When set, the agent loop uses this to classify the error without
falling back to string matching on error_message.
Implementations§
Source§impl AssistantMessageEvent
impl AssistantMessageEvent
Sourcepub fn error(message: impl Into<String>) -> Self
pub fn error(message: impl Into<String>) -> Self
Create a stream error event with no structured classification.
Convenience constructor used by adapters when the stream encounters
an error condition. The error_kind is set to None, so the agent
loop will fall back to string-based classification.
Sourcepub fn error_throttled(message: impl Into<String>) -> Self
pub fn error_throttled(message: impl Into<String>) -> Self
Create a throttle/rate-limit error event.
Sets StreamErrorKind::Throttled so the agent loop can classify
the error structurally.
Sourcepub fn error_context_overflow(message: impl Into<String>) -> Self
pub fn error_context_overflow(message: impl Into<String>) -> Self
Create a context-window overflow error event.
Sets StreamErrorKind::ContextWindowExceeded so the agent loop
can trigger context compaction.
Sourcepub fn error_auth(message: impl Into<String>) -> Self
pub fn error_auth(message: impl Into<String>) -> Self
Create an authentication error event.
Sets StreamErrorKind::Auth so the agent loop can treat this as
a non-retryable failure.
Sourcepub fn error_network(message: impl Into<String>) -> Self
pub fn error_network(message: impl Into<String>) -> Self
Create a network/server error event.
Sets StreamErrorKind::Network so the agent loop can classify
the error as retryable.
Sourcepub fn error_content_filtered(message: impl Into<String>) -> Self
pub fn error_content_filtered(message: impl Into<String>) -> Self
Create a content-filtered error event.
Sets StreamErrorKind::ContentFiltered so the agent loop can
treat this as a non-retryable safety policy violation.
Sourcepub fn text_response(text: &str) -> Vec<Self>
pub fn text_response(text: &str) -> Vec<Self>
Build a complete single-text-block response event sequence.
Useful for testing and mock StreamFn implementations. Returns the
five events needed for a valid text-only response: Start, TextStart,
TextDelta, TextEnd, and Done.
Trait Implementations§
Source§impl Clone for AssistantMessageEvent
impl Clone for AssistantMessageEvent
Source§fn clone(&self) -> AssistantMessageEvent
fn clone(&self) -> AssistantMessageEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more