fix: change EventMsg enum so every variant takes a single struct (#925)

https://github.com/openai/codex/pull/922 did this for the
`SessionConfigured` enum variant, and I think it is generally helpful to
be able to work with the values as each enum variant as their own type,
so this converts the remaining variants and updates all of the
callsites.

Added a simple unit test to verify that the JSON-serialized version of
`Event` does not have any unexpected nesting.
This commit is contained in:
Michael Bolin authored and GitHub committed 2025-05-13 20:44:42 -07:00
1 parent e6c206d19d
commit a5f3a34827
9 files changed
+288 -183

No files matched your search

+5 -4
View File
@@ -4,6 +4,7 @@
use codex_core::codex_wrapper::init_codex;
use codex_core::config::Config as CodexConfig;
use codex_core::protocol::AgentMessageEvent;
use codex_core::protocol::Event;
use codex_core::protocol::EventMsg;
use codex_core::protocol::InputItem;
@@ -85,10 +86,10 @@ pub async fn run_codex_tool_session(
let _ = outgoing.send(codex_event_to_notification(&event)).await;
match &event.msg {
EventMsg::AgentMessage { message } => {
EventMsg::AgentMessage(AgentMessageEvent { message }) => {
last_agent_message = Some(message.clone());
}
EventMsg::ExecApprovalRequest { .. } => {
EventMsg::ExecApprovalRequest(_) => {
let result = CallToolResult {
content: vec![CallToolResultContent::TextContent(TextContent {
r#type: "text".to_string(),
@@ -106,7 +107,7 @@ pub async fn run_codex_tool_session(
.await;
break;
}
EventMsg::ApplyPatchApprovalRequest { .. } => {
EventMsg::ApplyPatchApprovalRequest(_) => {
let result = CallToolResult {
content: vec![CallToolResultContent::TextContent(TextContent {
r#type: "text".to_string(),
@@ -153,7 +154,7 @@ pub async fn run_codex_tool_session(
.await;
break;
}
EventMsg::SessionConfigured { .. } => {
EventMsg::SessionConfigured(_) => {
tracing::error!("unexpected SessionConfigured event");
}
_ => {}