pub enum StreamEvent {
TextDelta(String),
ToolCallStart {
name: String,
index: usize,
id: Option<String>,
},
ToolCallDelta {
index: usize,
arguments_delta: String,
},
Usage {
input_tokens: u64,
output_tokens: u64,
cache_read_input_tokens: u64,
cache_creation_input_tokens: u64,
},
StopReason(String),
ProviderOutputItem(Value),
Error(String),
Done {
text: String,
tool_calls: Vec<ToolCall>,
},
}Expand description
Events emitted during a streaming inference response.
Serialize/Deserialize are derived so the whole event stream can cross
the on-device inference-worker IPC boundary (car-releases#74) losslessly —
including the StopReason variant the daemon’s hand-rolled WS-runner JSON
mapping omits. The representation is internal (same crate version on both
ends of the pipe), so the default externally-tagged enum shape is fine.
Variants§
TextDelta(String)
Partial text token from the model.
ToolCallStart
A tool call is starting (name known, arguments pending).
ToolCallDelta
Partial tool call arguments (JSON fragment).
Usage
Provider-reported cumulative token usage observed mid-stream.
Anthropic emits this twice: once in message_start with the
finalized input_tokens (plus a stub output_tokens: 1), and
again in message_delta at end of stream with the real
output_tokens. Consumers should prefer per-field monotonicity
(see StreamAccumulator) rather than overwriting blindly.
Fields
input_tokens: u64Uncached prompt tokens. For providers whose streamed usage reports the cached subset inside the prompt total (OpenAI), the parser subtracts it here so this stays the uncached portion — matching the non-streaming convention.
StopReason(String)
Provider-reported termination reason, surfaced mid-stream as the raw
provider string (OpenAI finish_reason, Anthropic delta.stop_reason).
A value of "length"/"max_tokens" signals the output was cut off at
the token cap. Captured by StreamAccumulator and returned from
StreamAccumulator::finish_with_usage.
ProviderOutputItem(Value)
Opaque provider output item that must be replayed verbatim on a later
turn. The OpenAI Responses API emits completed reasoning items through
response.output_item.done; CAR does not interpret or rewrite their
id, status, summary, or encrypted_content.
Error(String)
Provider or transport failure observed after the HTTP stream began. This is terminal and must never be interpreted as a normal stop/success. Messages are sanitized at the provider adapter before entering the event.
Done
Stream is complete. Contains the final aggregated result.
Trait Implementations§
Source§impl Clone for StreamEvent
impl Clone for StreamEvent
Source§impl Debug for StreamEvent
impl Debug for StreamEvent
Source§impl<'de> Deserialize<'de> for StreamEvent
impl<'de> Deserialize<'de> for StreamEvent
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>,
Auto Trait Implementations§
impl Freeze for StreamEvent
impl RefUnwindSafe for StreamEvent
impl Send for StreamEvent
impl Sync for StreamEvent
impl Unpin for StreamEvent
impl UnsafeUnpin for StreamEvent
impl UnwindSafe for StreamEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more