pub struct StreamEvent {
pub data: Value,
}Expand description
A single line from --output-format stream-json output.
Each line is an NDJSON object. The structure varies by message type, so we provide the raw JSON value and convenience accessors.
Fields§
§data: ValueThe raw JSON object for this event.
Implementations§
Source§impl StreamEvent
impl StreamEvent
Sourcepub fn event_type(&self) -> Option<&str>
pub fn event_type(&self) -> Option<&str>
Get the event type, if present.
Sourcepub fn result_text(&self) -> Option<&str>
pub fn result_text(&self) -> Option<&str>
Extract the result text from a result event.
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Get the session ID if present.
Sourcepub fn cost_usd(&self) -> Option<f64>
pub fn cost_usd(&self) -> Option<f64>
Get the cost in USD if present (usually on result events).
Prefers total_cost_usd (the CLI’s primary key) and falls back
to the legacy cost_usd alias.
Sourcepub fn partial_message(&self) -> Option<PartialMessageEvent>
pub fn partial_message(&self) -> Option<PartialMessageEvent>
Decode a partial-message event into a typed view.
Returns Some when the event is one of the content-block lifecycle
events surfaced by QueryCommand::include_partial_messages – start,
delta, or stop. Returns None for any other event (system, assistant,
result, message-level stream events, etc).
The CLI wraps each raw streaming event as
{"type":"stream_event","event":{...}}; this accessor unwraps that
envelope. Unknown block types and unknown delta types fall through to
BlockType::Other / BlockDelta::Other rather than erroring, so
future content-block kinds remain accessible (just untyped).
§Example
Pull incremental thinking text out of a partial-message event:
use claude_wrapper::streaming::{BlockDelta, PartialMessageEvent, StreamEvent};
use serde_json::json;
let event: StreamEvent = serde_json::from_value(json!({
"type": "stream_event",
"event": {
"type": "content_block_delta",
"index": 0,
"delta": { "type": "thinking_delta", "thinking": "Let me think..." }
},
"session_id": "abc"
})).unwrap();
match event.partial_message() {
Some(PartialMessageEvent::BlockDelta { delta: BlockDelta::Thinking(t), .. }) => {
assert_eq!(t, "Let me think...");
}
_ => unreachable!(),
}Trait Implementations§
Source§impl Clone for StreamEvent
impl Clone for StreamEvent
Source§fn clone(&self) -> StreamEvent
fn clone(&self) -> StreamEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more