Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codex-rs/exec/src/event_processor_with_jsonl_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::atomic::AtomicU64;
use crate::event_processor::CodexStatus;
use crate::event_processor::EventProcessor;
use crate::event_processor::handle_last_message;
use crate::exec_events::AssistantMessageItem;
use crate::exec_events::AgentMessageItem;
use crate::exec_events::CommandExecutionItem;
use crate::exec_events::CommandExecutionStatus;
use crate::exec_events::FileChangeItem;
Expand Down Expand Up @@ -162,7 +162,7 @@ impl EventProcessorWithJsonOutput {
let item = ThreadItem {
id: self.get_next_item_id(),

details: ThreadItemDetails::AssistantMessage(AssistantMessageItem {
details: ThreadItemDetails::AgentMessage(AgentMessageItem {
text: payload.message.clone(),
}),
};
Expand Down
6 changes: 3 additions & 3 deletions codex-rs/exec/src/exec_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ pub struct ThreadItem {

/// Typed payloads for each supported thread item type.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
#[serde(tag = "item_type", rename_all = "snake_case")]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ThreadItemDetails {
/// Response from the agent.
/// Either a natural-language response or a JSON string when structured output is requested.
AssistantMessage(AssistantMessageItem),
AgentMessage(AgentMessageItem),
/// Agent's reasoning summary.
Reasoning(ReasoningItem),
/// Tracks a command executed by the agent. The item starts when the command is
Expand All @@ -124,7 +124,7 @@ pub enum ThreadItemDetails {
/// Response from the agent.
/// Either a natural-language response or a JSON string when structured output is requested.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
pub struct AssistantMessageItem {
pub struct AgentMessageItem {
pub text: String,
}

Expand Down
6 changes: 3 additions & 3 deletions codex-rs/exec/tests/event_processor_with_json_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use codex_core::protocol::PatchApplyEndEvent;
use codex_core::protocol::SessionConfiguredEvent;
use codex_core::protocol::WebSearchEndEvent;
use codex_exec::event_processor_with_jsonl_output::EventProcessorWithJsonOutput;
use codex_exec::exec_events::AssistantMessageItem;
use codex_exec::exec_events::AgentMessageItem;
use codex_exec::exec_events::CommandExecutionItem;
use codex_exec::exec_events::CommandExecutionStatus;
use codex_exec::exec_events::ItemCompletedEvent;
Expand Down Expand Up @@ -410,7 +410,7 @@ fn agent_reasoning_produces_item_completed_reasoning() {
}

#[test]
fn agent_message_produces_item_completed_assistant_message() {
fn agent_message_produces_item_completed_agent_message() {
let mut ep = EventProcessorWithJsonOutput::new(None);
let ev = event(
"e1",
Expand All @@ -424,7 +424,7 @@ fn agent_message_produces_item_completed_assistant_message() {
vec![ThreadEvent::ItemCompleted(ItemCompletedEvent {
item: ThreadItem {
id: "item_0".to_string(),
details: ThreadItemDetails::AssistantMessage(AssistantMessageItem {
details: ThreadItemDetails::AgentMessage(AgentMessageItem {
text: "hello".to_string(),
}),
},
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/samples/basic_streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const thread = codex.startThread();
const rl = createInterface({ input, output });

const handleItemCompleted = (item: ThreadItem): void => {
switch (item.item_type) {
case "assistant_message":
switch (item.type) {
case "agent_message":
console.log(`Assistant: ${item.text}`);
break;
case "reasoning":
Expand All @@ -38,7 +38,7 @@ const handleItemCompleted = (item: ThreadItem): void => {
};

const handleItemUpdated = (item: ThreadItem): void => {
switch (item.item_type) {
switch (item.type) {
case "todo_list": {
console.log(`Todo:`);
for (const todo of item.items) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type {
} from "./events";
export type {
ThreadItem,
AssistantMessageItem,
AgentMessageItem,
ReasoningItem,
CommandExecutionItem,
FileChangeItem,
Expand Down
22 changes: 11 additions & 11 deletions sdk/typescript/src/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type CommandExecutionStatus = "in_progress" | "completed" | "failed";
/** A command executed by the agent. */
export type CommandExecutionItem = {
id: string;
item_type: "command_execution";
type: "command_execution";
/** The command line executed by the agent. */
command: string;
/** Aggregated stdout and stderr captured while the command was running. */
Expand All @@ -32,7 +32,7 @@ export type PatchApplyStatus = "completed" | "failed";
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
export type FileChangeItem = {
id: string;
item_type: "file_change";
type: "file_change";
/** Individual file changes that comprise the patch. */
changes: FileUpdateChange[];
/** Whether the patch ultimately succeeded or failed. */
Expand All @@ -48,7 +48,7 @@ export type McpToolCallStatus = "in_progress" | "completed" | "failed";
*/
export type McpToolCallItem = {
id: string;
item_type: "mcp_tool_call";
type: "mcp_tool_call";
/** Name of the MCP server handling the request. */
server: string;
/** The tool invoked on the MCP server. */
Expand All @@ -58,31 +58,31 @@ export type McpToolCallItem = {
};

/** Response from the agent. Either natural-language text or JSON when structured output is requested. */
export type AssistantMessageItem = {
export type AgentMessageItem = {
id: string;
item_type: "assistant_message";
type: "agent_message";
/** Either natural-language text or JSON when structured output is requested. */
text: string;
};

/** Agent's reasoning summary. */
export type ReasoningItem = {
id: string;
item_type: "reasoning";
type: "reasoning";
text: string;
};

/** Captures a web search request. Completes when results are returned to the agent. */
export type WebSearchItem = {
id: string;
item_type: "web_search";
type: "web_search";
query: string;
};

/** Describes a non-fatal error surfaced as an item. */
export type ErrorItem = {
id: string;
item_type: "error";
type: "error";
message: string;
};

Expand All @@ -98,19 +98,19 @@ export type TodoItem = {
*/
export type TodoListItem = {
id: string;
item_type: "todo_list";
type: "todo_list";
items: TodoItem[];
};

export type SessionItem = {
id: string;
item_type: "session";
type: "session";
session_id: string;
};

/** Canonical union of thread items and their type-specific payloads. */
export type ThreadItem =
| AssistantMessageItem
| AgentMessageItem
| ReasoningItem
| CommandExecutionItem
| FileChangeItem
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Thread {
let finalResponse: string = "";
for await (const event of generator) {
if (event.type === "item.completed") {
if (event.item.item_type === "assistant_message") {
if (event.item.type === "agent_message") {
finalResponse = event.item.text;
}
items.push(event.item);
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/tests/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Codex", () => {
const expectedItems = [
{
id: expect.any(String),
item_type: "assistant_message",
type: "agent_message",
text: "Hi!",
},
];
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/tests/runStreamed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("Codex", () => {
type: "item.completed",
item: {
id: "item_0",
item_type: "assistant_message",
type: "agent_message",
text: "Hi!",
},
},
Expand Down
Loading