Rename assistant message to agent message and fix item type field naming (#4610)

Naming cleanup
This commit is contained in:
pakrym-oai
2025-10-02 15:07:14 -07:00
committed by GitHub
parent 138be0fd73
commit c405d8c06c
9 changed files with 26 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ use std::sync::atomic::AtomicU64;
use crate::event_processor::CodexStatus; use crate::event_processor::CodexStatus;
use crate::event_processor::EventProcessor; use crate::event_processor::EventProcessor;
use crate::event_processor::handle_last_message; 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::CommandExecutionItem;
use crate::exec_events::CommandExecutionStatus; use crate::exec_events::CommandExecutionStatus;
use crate::exec_events::FileChangeItem; use crate::exec_events::FileChangeItem;
@@ -162,7 +162,7 @@ impl EventProcessorWithJsonOutput {
let item = ThreadItem { let item = ThreadItem {
id: self.get_next_item_id(), id: self.get_next_item_id(),
details: ThreadItemDetails::AssistantMessage(AssistantMessageItem { details: ThreadItemDetails::AgentMessage(AgentMessageItem {
text: payload.message.clone(), text: payload.message.clone(),
}), }),
}; };

View File

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

View File

@@ -14,7 +14,7 @@ use codex_core::protocol::PatchApplyEndEvent;
use codex_core::protocol::SessionConfiguredEvent; use codex_core::protocol::SessionConfiguredEvent;
use codex_core::protocol::WebSearchEndEvent; use codex_core::protocol::WebSearchEndEvent;
use codex_exec::event_processor_with_jsonl_output::EventProcessorWithJsonOutput; 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::CommandExecutionItem;
use codex_exec::exec_events::CommandExecutionStatus; use codex_exec::exec_events::CommandExecutionStatus;
use codex_exec::exec_events::ItemCompletedEvent; use codex_exec::exec_events::ItemCompletedEvent;
@@ -410,7 +410,7 @@ fn agent_reasoning_produces_item_completed_reasoning() {
} }
#[test] #[test]
fn agent_message_produces_item_completed_assistant_message() { fn agent_message_produces_item_completed_agent_message() {
let mut ep = EventProcessorWithJsonOutput::new(None); let mut ep = EventProcessorWithJsonOutput::new(None);
let ev = event( let ev = event(
"e1", "e1",
@@ -424,7 +424,7 @@ fn agent_message_produces_item_completed_assistant_message() {
vec![ThreadEvent::ItemCompleted(ItemCompletedEvent { vec![ThreadEvent::ItemCompleted(ItemCompletedEvent {
item: ThreadItem { item: ThreadItem {
id: "item_0".to_string(), id: "item_0".to_string(),
details: ThreadItemDetails::AssistantMessage(AssistantMessageItem { details: ThreadItemDetails::AgentMessage(AgentMessageItem {
text: "hello".to_string(), text: "hello".to_string(),
}), }),
}, },

View File

@@ -16,8 +16,8 @@ const thread = codex.startThread();
const rl = createInterface({ input, output }); const rl = createInterface({ input, output });
const handleItemCompleted = (item: ThreadItem): void => { const handleItemCompleted = (item: ThreadItem): void => {
switch (item.item_type) { switch (item.type) {
case "assistant_message": case "agent_message":
console.log(`Assistant: ${item.text}`); console.log(`Assistant: ${item.text}`);
break; break;
case "reasoning": case "reasoning":
@@ -38,7 +38,7 @@ const handleItemCompleted = (item: ThreadItem): void => {
}; };
const handleItemUpdated = (item: ThreadItem): void => { const handleItemUpdated = (item: ThreadItem): void => {
switch (item.item_type) { switch (item.type) {
case "todo_list": { case "todo_list": {
console.log(`Todo:`); console.log(`Todo:`);
for (const todo of item.items) { for (const todo of item.items) {

View File

@@ -12,7 +12,7 @@ export type {
} from "./events"; } from "./events";
export type { export type {
ThreadItem, ThreadItem,
AssistantMessageItem, AgentMessageItem,
ReasoningItem, ReasoningItem,
CommandExecutionItem, CommandExecutionItem,
FileChangeItem, FileChangeItem,

View File

@@ -6,7 +6,7 @@ export type CommandExecutionStatus = "in_progress" | "completed" | "failed";
/** A command executed by the agent. */ /** A command executed by the agent. */
export type CommandExecutionItem = { export type CommandExecutionItem = {
id: string; id: string;
item_type: "command_execution"; type: "command_execution";
/** The command line executed by the agent. */ /** The command line executed by the agent. */
command: string; command: string;
/** Aggregated stdout and stderr captured while the command was running. */ /** Aggregated stdout and stderr captured while the command was running. */
@@ -32,7 +32,7 @@ export type PatchApplyStatus = "completed" | "failed";
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */ /** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
export type FileChangeItem = { export type FileChangeItem = {
id: string; id: string;
item_type: "file_change"; type: "file_change";
/** Individual file changes that comprise the patch. */ /** Individual file changes that comprise the patch. */
changes: FileUpdateChange[]; changes: FileUpdateChange[];
/** Whether the patch ultimately succeeded or failed. */ /** Whether the patch ultimately succeeded or failed. */
@@ -48,7 +48,7 @@ export type McpToolCallStatus = "in_progress" | "completed" | "failed";
*/ */
export type McpToolCallItem = { export type McpToolCallItem = {
id: string; id: string;
item_type: "mcp_tool_call"; type: "mcp_tool_call";
/** Name of the MCP server handling the request. */ /** Name of the MCP server handling the request. */
server: string; server: string;
/** The tool invoked on the MCP server. */ /** The tool invoked on the MCP server. */
@@ -58,9 +58,9 @@ export type McpToolCallItem = {
}; };
/** Response from the agent. Either natural-language text or JSON when structured output is requested. */ /** Response from the agent. Either natural-language text or JSON when structured output is requested. */
export type AssistantMessageItem = { export type AgentMessageItem = {
id: string; id: string;
item_type: "assistant_message"; type: "agent_message";
/** Either natural-language text or JSON when structured output is requested. */ /** Either natural-language text or JSON when structured output is requested. */
text: string; text: string;
}; };
@@ -68,21 +68,21 @@ export type AssistantMessageItem = {
/** Agent's reasoning summary. */ /** Agent's reasoning summary. */
export type ReasoningItem = { export type ReasoningItem = {
id: string; id: string;
item_type: "reasoning"; type: "reasoning";
text: string; text: string;
}; };
/** Captures a web search request. Completes when results are returned to the agent. */ /** Captures a web search request. Completes when results are returned to the agent. */
export type WebSearchItem = { export type WebSearchItem = {
id: string; id: string;
item_type: "web_search"; type: "web_search";
query: string; query: string;
}; };
/** Describes a non-fatal error surfaced as an item. */ /** Describes a non-fatal error surfaced as an item. */
export type ErrorItem = { export type ErrorItem = {
id: string; id: string;
item_type: "error"; type: "error";
message: string; message: string;
}; };
@@ -98,19 +98,19 @@ export type TodoItem = {
*/ */
export type TodoListItem = { export type TodoListItem = {
id: string; id: string;
item_type: "todo_list"; type: "todo_list";
items: TodoItem[]; items: TodoItem[];
}; };
export type SessionItem = { export type SessionItem = {
id: string; id: string;
item_type: "session"; type: "session";
session_id: string; session_id: string;
}; };
/** Canonical union of thread items and their type-specific payloads. */ /** Canonical union of thread items and their type-specific payloads. */
export type ThreadItem = export type ThreadItem =
| AssistantMessageItem | AgentMessageItem
| ReasoningItem | ReasoningItem
| CommandExecutionItem | CommandExecutionItem
| FileChangeItem | FileChangeItem

View File

@@ -87,7 +87,7 @@ export class Thread {
let finalResponse: string = ""; let finalResponse: string = "";
for await (const event of generator) { for await (const event of generator) {
if (event.type === "item.completed") { if (event.type === "item.completed") {
if (event.item.item_type === "assistant_message") { if (event.item.type === "agent_message") {
finalResponse = event.item.text; finalResponse = event.item.text;
} }
items.push(event.item); items.push(event.item);

View File

@@ -33,7 +33,7 @@ describe("Codex", () => {
const expectedItems = [ const expectedItems = [
{ {
id: expect.any(String), id: expect.any(String),
item_type: "assistant_message", type: "agent_message",
text: "Hi!", text: "Hi!",
}, },
]; ];

View File

@@ -45,7 +45,7 @@ describe("Codex", () => {
type: "item.completed", type: "item.completed",
item: { item: {
id: "item_0", id: "item_0",
item_type: "assistant_message", type: "agent_message",
text: "Hi!", text: "Hi!",
}, },
}, },