pub struct QueryResult {
pub result: String,
pub session_id: Option<String>,
pub thread_id: Option<String>,
pub usage: Option<TokenUsage>,
pub events: Vec<JsonLineEvent>,
}Expand description
A typed summary of a completed codex exec run, assembled from the JSONL
event stream.
This mirrors the shape of claude-wrapper’s QueryResult so a downstream
abstraction can treat both wrappers uniformly. The full parsed event stream
is retained in events as an escape hatch for fields
not surfaced here.
Fields§
§result: StringAssistant text, concatenated from the turn’s agent-message items.
Empty when the turn produced no agent message. A failed turn can still carry text produced before its terminal failure; native rollout-budget exhaustion is one observed example.
session_id: Option<String>The session_id captured from the event stream, if any.
Observed live runs carry only thread_id, so this is usually None.
Retained because it costs nothing and the field may exist under auth
modes not yet observed.
thread_id: Option<String>The thread_id captured from the event stream, if any.
Codex’s native identifier for resuming a conversation, emitted on
thread.started.
usage: Option<TokenUsage>Token counts from the terminal turn.completed event, if present.
The CLI reports tokens, not money. There is no cost field to read; see
TokenUsage.
events: Vec<JsonLineEvent>The full parsed event stream this result was assembled from.
The escape hatch for anything not surfaced above, including whatever this parser gets wrong.
Implementations§
Source§impl QueryResult
impl QueryResult
Sourcepub fn from_events(events: Vec<JsonLineEvent>) -> Self
pub fn from_events(events: Vec<JsonLineEvent>) -> Self
Assemble a QueryResult from a parsed JSONL event stream.
usage comes from the last turn.completed event; result is every
agent-message item concatenated in order; session_id and thread_id
are the first occurrences in the stream.
Sourcepub fn final_message(&self) -> Option<String>
pub fn final_message(&self) -> Option<String>
The text of the final agent message: the last completed
agent_message item after the last turn.started.
Unlike result, which concatenates every agent
message, this is the one a --output-schema run answers with.
Sourcepub fn decode_structured<T: DeserializeOwned>(
&self,
) -> Result<T, StructuredOutputError>
pub fn decode_structured<T: DeserializeOwned>( &self, ) -> Result<T, StructuredOutputError>
Decode the final agent message of a --output-schema run into T.
A failed turn is
StructuredOutputError::TurnFailed
even when it produced a message first. See crate::structured for
the full rules. This never runs the CLI.