Skip to main content

JsonLineEvent

Struct JsonLineEvent 

Source
pub struct JsonLineEvent {
    pub event_type: String,
    pub extra: HashMap<String, Value>,
}
Expand description

A single parsed JSONL event from --json output.

The event_type field corresponds to the "type" key in the JSON. All other fields are captured in extra.

Fields§

§event_type: String§extra: HashMap<String, Value>

Implementations§

Source§

impl JsonLineEvent

Source

pub fn session_id(&self) -> Option<&str>

Returns the session_id field, if present and a string.

Source

pub fn thread_id(&self) -> Option<&str>

Returns the thread_id field, if present and a string.

Source

pub fn is_turn_completed(&self) -> bool

Returns true when this is the terminal event of a successful turn.

Source

pub fn is_turn_failed(&self) -> bool

Returns true when this is the terminal event of a failed turn.

Source

pub fn usage(&self) -> Option<TokenUsage>

Token counts reported by a turn.completed event.

Returns None on any other event, or when no usage object is present. The CLI reports tokens, not money; see TokenUsage.

Source

pub fn agent_message_text(&self) -> Option<String>

Assistant text carried by an item.completed agent-message item.

Returns None for any other event or item type.

Real output uses a type discriminator and a text field; see the schema block at the top of this module. An item_type discriminator and a content block array are also accepted, neither of them observed. Tolerating the unobserved shapes is deliberate: the previous parser committed to one exact layout and silently yielded empty results when it was wrong, which is the bug this replaces.

Source

pub fn role(&self) -> Option<&str>

Returns the role field, if present and a string.

Source

pub fn content_text(&self) -> Option<String>

Extracts concatenated text from a content blocks array.

Each block with "type": "text" contributes its "text" value. Returns None if there is no content array or no text blocks.

Source

pub fn item_type(&self) -> Option<&str>

The item discriminator on an item.* event.

agent_message and command_execution are the observed values. This is the field to match on when narrowing an item event, and it is present on item.started as well as item.completed.

Accepts item_type as well as type for the same reason agent_message_text does.

Source

pub fn command_execution(&self) -> Option<CommandExecution>

A shell command the model ran, from a command_execution item.

None for any other item. exit_code and status are only populated on item.completed; an item.started for the same command carries the command alone.

Trait Implementations§

Source§

impl Clone for JsonLineEvent

Source§

fn clone(&self) -> JsonLineEvent

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 JsonLineEvent

Source§

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

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

impl<'de> Deserialize<'de> for JsonLineEvent

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 Serialize for JsonLineEvent

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

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