diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 17b2696cbf5..51a6cd08cc6 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -3047,7 +3047,6 @@ name = "codex-goal-extension" version = "0.0.0" dependencies = [ "anyhow", - "async-trait", "chrono", "codex-analytics", "codex-core", @@ -3101,7 +3100,6 @@ dependencies = [ name = "codex-image-generation-extension" version = "0.0.0" dependencies = [ - "async-trait", "codex-api", "codex-core", "codex-extension-api", @@ -3301,7 +3299,6 @@ dependencies = [ name = "codex-memories-extension" version = "0.0.0" dependencies = [ - "async-trait", "codex-core", "codex-extension-api", "codex-features", @@ -3916,7 +3913,6 @@ dependencies = [ name = "codex-tools" version = "0.0.0" dependencies = [ - "async-trait", "codex-app-server-protocol", "codex-code-mode", "codex-features", @@ -4297,7 +4293,6 @@ dependencies = [ name = "codex-web-search-extension" version = "0.0.0" dependencies = [ - "async-trait", "codex-api", "codex-core", "codex-extension-api", diff --git a/codex-rs/core/src/tools/code_mode/execute_handler.rs b/codex-rs/core/src/tools/code_mode/execute_handler.rs index 0bdb8b20a6e..2e46c1bd6b9 100644 --- a/codex-rs/core/src/tools/code_mode/execute_handler.rs +++ b/codex-rs/core/src/tools/code_mode/execute_handler.rs @@ -91,7 +91,6 @@ impl CodeModeExecuteHandler { } } -#[async_trait::async_trait] impl ToolExecutor for CodeModeExecuteHandler { fn tool_name(&self) -> ToolName { ToolName::plain(PUBLIC_TOOL_NAME) @@ -101,11 +100,8 @@ impl ToolExecutor for CodeModeExecuteHandler { self.spec.clone() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/code_mode/wait_handler.rs b/codex-rs/core/src/tools/code_mode/wait_handler.rs index c1928955f4a..953391a573c 100644 --- a/codex-rs/core/src/tools/code_mode/wait_handler.rs +++ b/codex-rs/core/src/tools/code_mode/wait_handler.rs @@ -44,7 +44,6 @@ where }) } -#[async_trait::async_trait] impl ToolExecutor for CodeModeWaitHandler { fn tool_name(&self) -> ToolName { ToolName::plain(WAIT_TOOL_NAME) @@ -54,11 +53,8 @@ impl ToolExecutor for CodeModeWaitHandler { create_wait_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs b/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs index 5f2a6153295..579cc25ffb7 100644 --- a/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs +++ b/codex-rs/core/src/tools/handlers/agent_jobs/report_agent_job_result.rs @@ -13,7 +13,6 @@ use super::*; pub struct ReportAgentJobResultHandler; -#[async_trait::async_trait] impl ToolExecutor for ReportAgentJobResultHandler { fn tool_name(&self) -> ToolName { ToolName::plain("report_agent_job_result") @@ -23,11 +22,8 @@ impl ToolExecutor for ReportAgentJobResultHandler { create_report_agent_job_result_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs b/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs index 16e1b1f72c8..6da517b9cc5 100644 --- a/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs +++ b/codex-rs/core/src/tools/handlers/agent_jobs/spawn_agents_on_csv.rs @@ -14,7 +14,6 @@ use super::*; pub struct SpawnAgentsOnCsvHandler; -#[async_trait::async_trait] impl ToolExecutor for SpawnAgentsOnCsvHandler { fn tool_name(&self) -> ToolName { ToolName::plain("spawn_agents_on_csv") @@ -24,11 +23,8 @@ impl ToolExecutor for SpawnAgentsOnCsvHandler { create_spawn_agents_on_csv_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 6a322ed6aea..70452b6657e 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -305,7 +305,6 @@ async fn effective_patch_permissions( ) } -#[async_trait::async_trait] impl ToolExecutor for ApplyPatchHandler { fn tool_name(&self) -> ToolName { ToolName::plain("apply_patch") @@ -315,11 +314,8 @@ impl ToolExecutor for ApplyPatchHandler { create_apply_patch_freeform_tool(self.multi_environment) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/dynamic.rs b/codex-rs/core/src/tools/handlers/dynamic.rs index e0151cf1896..dabcea8e5af 100644 --- a/codex-rs/core/src/tools/handlers/dynamic.rs +++ b/codex-rs/core/src/tools/handlers/dynamic.rs @@ -61,7 +61,6 @@ impl DynamicToolHandler { } } -#[async_trait::async_trait] impl ToolExecutor for DynamicToolHandler { fn tool_name(&self) -> ToolName { self.tool_name.clone() @@ -86,11 +85,8 @@ impl ToolExecutor for DynamicToolHandler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/extension_tools.rs b/codex-rs/core/src/tools/handlers/extension_tools.rs index a94c764a9f7..d429b6c1fc0 100644 --- a/codex-rs/core/src/tools/handlers/extension_tools.rs +++ b/codex-rs/core/src/tools/handlers/extension_tools.rs @@ -11,13 +11,11 @@ use codex_tools::ToolSpec; use codex_tools::TurnItemEmissionFuture; use codex_tools::TurnItemEmitter; -use crate::function_tool::FunctionCallError; use crate::session::session::Session; use crate::session::turn_context::TurnContext; use crate::stream_events_utils::TurnItemContributorPolicy; use crate::stream_events_utils::finalize_turn_item; use crate::tools::context::ToolInvocation; -use crate::tools::context::ToolOutput; use crate::tools::context::ToolPayload; use crate::tools::registry::CoreToolRuntime; use crate::tools::registry::ToolExecutor; @@ -30,7 +28,6 @@ impl ExtensionToolAdapter { } } -#[async_trait::async_trait] impl ToolExecutor for ExtensionToolAdapter { fn tool_name(&self) -> ToolName { self.0.tool_name() @@ -52,11 +49,8 @@ impl ToolExecutor for ExtensionToolAdapter { self.0.search_info() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.0.handle(to_extension_call(&invocation).await).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { self.0.handle(to_extension_call(&invocation).await).await }) } } @@ -162,7 +156,6 @@ mod tests { struct StubExtensionExecutor; - #[async_trait::async_trait] impl codex_extension_api::ToolExecutor for StubExtensionExecutor { fn tool_name(&self) -> codex_tools::ToolName { codex_tools::ToolName::plain("extension_echo") @@ -187,13 +180,13 @@ mod tests { }) } - async fn handle( - &self, - _call: codex_tools::ToolCall, - ) -> Result, codex_tools::FunctionCallError> { - Ok(Box::new(codex_tools::JsonToolOutput::new( - json!({ "ok": true }), - ))) + fn handle(&self, _call: codex_tools::ToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { + Ok( + Box::new(codex_tools::JsonToolOutput::new(json!({ "ok": true }))) + as Box, + ) + }) } } @@ -201,7 +194,6 @@ mod tests { captured_call: Arc>>, } - #[async_trait::async_trait] impl codex_extension_api::ToolExecutor for CapturingExtensionExecutor { fn tool_name(&self) -> codex_tools::ToolName { codex_tools::ToolName::plain("extension_echo") @@ -218,11 +210,8 @@ mod tests { }) } - async fn handle( - &self, - call: codex_tools::ToolCall, - ) -> Result, codex_tools::FunctionCallError> { - self.handle_call(call).await + fn handle(&self, call: codex_tools::ToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } @@ -242,9 +231,10 @@ mod tests { call.turn_item_emitter.emit_started(item.clone()).await; call.turn_item_emitter.emit_completed(item).await; *self.captured_call.lock().await = Some(call); - Ok(Box::new(codex_tools::JsonToolOutput::new( - json!({ "ok": true }), - ))) + Ok( + Box::new(codex_tools::JsonToolOutput::new(json!({ "ok": true }))) + as Box, + ) } } @@ -441,7 +431,6 @@ mod tests { ); } - #[async_trait::async_trait] impl codex_extension_api::ToolExecutor for ImageGenerationExtensionExecutor { fn tool_name(&self) -> codex_tools::ToolName { codex_tools::ToolName::namespaced("image_gen", "imagegen") @@ -458,11 +447,8 @@ mod tests { }) } - async fn handle( - &self, - call: codex_tools::ToolCall, - ) -> Result, codex_tools::FunctionCallError> { - self.handle_call(call).await + fn handle(&self, call: codex_tools::ToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } @@ -493,9 +479,10 @@ mod tests { }, )) .await; - Ok(Box::new(codex_tools::JsonToolOutput::new( - json!({ "ok": true }), - ))) + Ok( + Box::new(codex_tools::JsonToolOutput::new(json!({ "ok": true }))) + as Box, + ) } } diff --git a/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs b/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs index 2b782e4552f..766b0e9b753 100644 --- a/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs +++ b/codex-rs/core/src/tools/handlers/list_available_plugins_to_install.rs @@ -54,7 +54,6 @@ impl ListAvailablePluginsToInstallHandler { } } -#[async_trait::async_trait] impl ToolExecutor for ListAvailablePluginsToInstallHandler { fn tool_name(&self) -> ToolName { ToolName::plain(LIST_AVAILABLE_PLUGINS_TO_INSTALL_TOOL_NAME) @@ -68,11 +67,8 @@ impl ToolExecutor for ListAvailablePluginsToInstallHandler { false } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/mcp.rs b/codex-rs/core/src/tools/handlers/mcp.rs index d60cdfdd0cf..efb32aab945 100644 --- a/codex-rs/core/src/tools/handlers/mcp.rs +++ b/codex-rs/core/src/tools/handlers/mcp.rs @@ -64,7 +64,6 @@ fn ensure_mcp_prefix(name: &str) -> String { } } -#[async_trait::async_trait] impl ToolExecutor for McpHandler { fn tool_name(&self) -> ToolName { self.tool_info.canonical_tool_name() @@ -113,11 +112,8 @@ impl ToolExecutor for McpHandler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs index 8974d678fdd..80b183dabab 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resource_templates.rs @@ -26,7 +26,6 @@ use super::serialize_function_output; pub struct ListMcpResourceTemplatesHandler; -#[async_trait::async_trait] impl ToolExecutor for ListMcpResourceTemplatesHandler { fn tool_name(&self) -> ToolName { ToolName::plain("list_mcp_resource_templates") @@ -40,11 +39,8 @@ impl ToolExecutor for ListMcpResourceTemplatesHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs index f3a7b43c28b..a77d617b942 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/list_mcp_resources.rs @@ -26,7 +26,6 @@ use super::serialize_function_output; pub struct ListMcpResourcesHandler; -#[async_trait::async_trait] impl ToolExecutor for ListMcpResourcesHandler { fn tool_name(&self) -> ToolName { ToolName::plain("list_mcp_resources") @@ -40,11 +39,8 @@ impl ToolExecutor for ListMcpResourcesHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs b/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs index 9861e5d22d6..9ca15718a0c 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource/read_mcp_resource.rs @@ -26,7 +26,6 @@ use super::serialize_function_output; pub struct ReadMcpResourceHandler; -#[async_trait::async_trait] impl ToolExecutor for ReadMcpResourceHandler { fn tool_name(&self) -> ToolName { ToolName::plain("read_mcp_resource") @@ -40,11 +39,8 @@ impl ToolExecutor for ReadMcpResourceHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs index 0d4e17447dc..d1017adb65c 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs @@ -6,7 +6,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::namespaced(MULTI_AGENT_V1_NAMESPACE, "close_agent") @@ -23,11 +22,8 @@ impl ToolExecutor for Handler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - handle_close_agent(invocation).await.map(boxed_tool_output) + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { handle_close_agent(invocation).await.map(boxed_tool_output) }) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs index 8f95abe4e31..fa464ddbbb2 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs @@ -7,7 +7,6 @@ use std::sync::Arc; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::namespaced(MULTI_AGENT_V1_NAMESPACE, "resume_agent") @@ -24,11 +23,8 @@ impl ToolExecutor for Handler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - handle_resume_agent(invocation).await.map(boxed_tool_output) + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { handle_resume_agent(invocation).await.map(boxed_tool_output) }) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs index b811faf91a6..375bb50ac7c 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs @@ -6,7 +6,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::namespaced(MULTI_AGENT_V1_NAMESPACE, "send_input") @@ -23,11 +22,8 @@ impl ToolExecutor for Handler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs index 3f6c97fcbcb..204385934e2 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs @@ -22,7 +22,6 @@ impl Handler { } } -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::namespaced(MULTI_AGENT_V1_NAMESPACE, "spawn_agent") @@ -39,11 +38,8 @@ impl ToolExecutor for Handler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - handle_spawn_agent(invocation).await.map(boxed_tool_output) + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { handle_spawn_agent(invocation).await.map(boxed_tool_output) }) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs index 1f6b7db8f10..be22b369082 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs @@ -27,7 +27,6 @@ impl Handler { } } -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::namespaced(MULTI_AGENT_V1_NAMESPACE, "wait_agent") @@ -44,11 +43,8 @@ impl ToolExecutor for Handler { ) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs index 66a39cc79d0..bd4dafe7c26 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs @@ -7,7 +7,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("followup_task") @@ -17,11 +16,8 @@ impl ToolExecutor for Handler { create_followup_task_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs index 159c49127a8..aeed055b4ef 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/interrupt_agent.rs @@ -6,7 +6,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("interrupt_agent") @@ -16,13 +15,12 @@ impl ToolExecutor for Handler { create_interrupt_agent_tool_v2() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - handle_interrupt_agent(invocation) - .await - .map(boxed_tool_output) + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { + handle_interrupt_agent(invocation) + .await + .map(boxed_tool_output) + }) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs index 18421278fe0..99e54e1ce91 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs @@ -5,7 +5,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("list_agents") @@ -15,11 +14,8 @@ impl ToolExecutor for Handler { create_list_agents_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs index 2fd636a85c5..717e3bc9203 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs @@ -7,7 +7,6 @@ use codex_tools::ToolSpec; pub(crate) struct Handler; -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("send_message") @@ -17,11 +16,8 @@ impl ToolExecutor for Handler { create_send_message_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs index 34fddc60b4e..2186a4a6d60 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs @@ -22,7 +22,6 @@ impl Handler { } } -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("spawn_agent") @@ -32,11 +31,8 @@ impl ToolExecutor for Handler { create_spawn_agent_tool_v2(self.options.clone()) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - handle_spawn_agent(invocation).await.map(boxed_tool_output) + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async move { handle_spawn_agent(invocation).await.map(boxed_tool_output) }) } } diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs index 9d671b1989a..36e5aa24f68 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs @@ -19,7 +19,6 @@ impl Handler { } } -#[async_trait::async_trait] impl ToolExecutor for Handler { fn tool_name(&self) -> ToolName { ToolName::plain("wait_agent") @@ -29,11 +28,8 @@ impl ToolExecutor for Handler { create_wait_agent_tool_v2(self.options) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/plan.rs b/codex-rs/core/src/tools/handlers/plan.rs index ff18a328131..1b30c281ce2 100644 --- a/codex-rs/core/src/tools/handlers/plan.rs +++ b/codex-rs/core/src/tools/handlers/plan.rs @@ -45,7 +45,6 @@ impl ToolOutput for PlanToolOutput { } } -#[async_trait::async_trait] impl ToolExecutor for PlanHandler { fn tool_name(&self) -> ToolName { ToolName::plain("update_plan") @@ -55,11 +54,8 @@ impl ToolExecutor for PlanHandler { create_update_plan_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/request_permissions.rs b/codex-rs/core/src/tools/handlers/request_permissions.rs index 7c24f15697a..4faf9d328b3 100644 --- a/codex-rs/core/src/tools/handlers/request_permissions.rs +++ b/codex-rs/core/src/tools/handlers/request_permissions.rs @@ -25,7 +25,6 @@ struct RequestPermissionsEnvironmentArgs { environment_id: Option, } -#[async_trait::async_trait] impl ToolExecutor for RequestPermissionsHandler { fn tool_name(&self) -> ToolName { ToolName::plain("request_permissions") @@ -35,11 +34,8 @@ impl ToolExecutor for RequestPermissionsHandler { create_request_permissions_tool(request_permissions_tool_description()) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/request_plugin_install.rs b/codex-rs/core/src/tools/handlers/request_plugin_install.rs index 64625aaac0d..801031348f3 100644 --- a/codex-rs/core/src/tools/handlers/request_plugin_install.rs +++ b/codex-rs/core/src/tools/handlers/request_plugin_install.rs @@ -48,7 +48,6 @@ impl RequestPluginInstallHandler { } } -#[async_trait::async_trait] impl ToolExecutor for RequestPluginInstallHandler { fn tool_name(&self) -> ToolName { ToolName::plain(REQUEST_PLUGIN_INSTALL_TOOL_NAME) @@ -62,11 +61,8 @@ impl ToolExecutor for RequestPluginInstallHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/request_user_input.rs b/codex-rs/core/src/tools/handlers/request_user_input.rs index 3f3adf0ba39..4f26865a687 100644 --- a/codex-rs/core/src/tools/handlers/request_user_input.rs +++ b/codex-rs/core/src/tools/handlers/request_user_input.rs @@ -20,7 +20,6 @@ pub struct RequestUserInputHandler { pub available_modes: Vec, } -#[async_trait::async_trait] impl ToolExecutor for RequestUserInputHandler { fn tool_name(&self) -> ToolName { ToolName::plain(REQUEST_USER_INPUT_TOOL_NAME) @@ -30,11 +29,8 @@ impl ToolExecutor for RequestUserInputHandler { create_request_user_input_tool(request_user_input_tool_description(&self.available_modes)) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/shell/shell_command.rs b/codex-rs/core/src/tools/handlers/shell/shell_command.rs index e9fcf82046d..b754187d4ac 100644 --- a/codex-rs/core/src/tools/handlers/shell/shell_command.rs +++ b/codex-rs/core/src/tools/handlers/shell/shell_command.rs @@ -124,7 +124,6 @@ impl From for ShellCommandHandler { } } -#[async_trait::async_trait] impl ToolExecutor for ShellCommandHandler { fn tool_name(&self) -> ToolName { ToolName::plain("shell_command") @@ -141,11 +140,8 @@ impl ToolExecutor for ShellCommandHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/test_sync.rs b/codex-rs/core/src/tools/handlers/test_sync.rs index 802859c916c..08d983b6160 100644 --- a/codex-rs/core/src/tools/handlers/test_sync.rs +++ b/codex-rs/core/src/tools/handlers/test_sync.rs @@ -57,7 +57,6 @@ fn barrier_map() -> &'static tokio::sync::Mutex> { BARRIERS.get_or_init(|| tokio::sync::Mutex::new(HashMap::new())) } -#[async_trait::async_trait] impl ToolExecutor for TestSyncHandler { fn tool_name(&self) -> ToolName { ToolName::plain("test_sync_tool") @@ -71,11 +70,8 @@ impl ToolExecutor for TestSyncHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/tool_search.rs b/codex-rs/core/src/tools/handlers/tool_search.rs index a4781e75e21..9254f4bee07 100644 --- a/codex-rs/core/src/tools/handlers/tool_search.rs +++ b/codex-rs/core/src/tools/handlers/tool_search.rs @@ -53,7 +53,6 @@ impl ToolSearchHandler { } } -#[async_trait::async_trait] impl ToolExecutor for ToolSearchHandler { fn tool_name(&self) -> ToolName { ToolName::plain(TOOL_SEARCH_TOOL_NAME) @@ -67,11 +66,8 @@ impl ToolExecutor for ToolSearchHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs index 9fe3b343b57..7c914deb4f5 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs @@ -71,7 +71,6 @@ impl ExecCommandHandler { } } -#[async_trait::async_trait] impl ToolExecutor for ExecCommandHandler { fn tool_name(&self) -> ToolName { ToolName::plain("exec_command") @@ -92,11 +91,8 @@ impl ToolExecutor for ExecCommandHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs b/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs index 9b319d54336..8ddce658402 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec/write_stdin.rs @@ -31,7 +31,6 @@ struct WriteStdinArgs { pub struct WriteStdinHandler; -#[async_trait::async_trait] impl ToolExecutor for WriteStdinHandler { fn tool_name(&self) -> ToolName { ToolName::plain("write_stdin") @@ -41,11 +40,8 @@ impl ToolExecutor for WriteStdinHandler { create_write_stdin_tool() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rs index eb761359a7a..0432ad338fa 100644 --- a/codex-rs/core/src/tools/handlers/view_image.rs +++ b/codex-rs/core/src/tools/handlers/view_image.rs @@ -64,7 +64,6 @@ enum ViewImageDetail { Original, } -#[async_trait::async_trait] impl ToolExecutor for ViewImageHandler { fn tool_name(&self) -> ToolName { ToolName::plain("view_image") @@ -78,11 +77,8 @@ impl ToolExecutor for ViewImageHandler { true } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } diff --git a/codex-rs/core/src/tools/parallel.rs b/codex-rs/core/src/tools/parallel.rs index a6f630a342c..c40886b56cb 100644 --- a/codex-rs/core/src/tools/parallel.rs +++ b/codex-rs/core/src/tools/parallel.rs @@ -257,7 +257,6 @@ mod tests { tool_name: codex_tools::ToolName, } - #[async_trait::async_trait] impl ToolExecutor for ImmediateHandler { fn tool_name(&self) -> codex_tools::ToolName { self.tool_name.clone() @@ -274,14 +273,13 @@ mod tests { }) } - async fn handle( - &self, - _invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - Ok(Box::new(FunctionToolOutput::from_text( - "ok".to_string(), - Some(true), - ))) + fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { + Ok( + Box::new(FunctionToolOutput::from_text("ok".to_string(), Some(true))) + as Box, + ) + }) } } @@ -294,7 +292,6 @@ mod tests { allow_cleanup: Arc, } - #[async_trait::async_trait] impl ToolExecutor for CancellationCleanupHandler { fn tool_name(&self) -> codex_tools::ToolName { self.tool_name.clone() @@ -311,11 +308,8 @@ mod tests { }) } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(invocation)) } } @@ -345,7 +339,7 @@ mod tests { Ok(Box::new(FunctionToolOutput::from_text( "cleanup complete".to_string(), Some(false), - ))) + )) as Box) } } diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rs index 20e08e9f7da..76e3f5f3414 100644 --- a/codex-rs/core/src/tools/registry.rs +++ b/codex-rs/core/src/tools/registry.rs @@ -250,7 +250,6 @@ struct ExposureOverride { exposure: ToolExposure, } -#[async_trait::async_trait] impl ToolExecutor for ExposureOverride { fn tool_name(&self) -> ToolName { self.handler.tool_name() @@ -272,11 +271,8 @@ impl ToolExecutor for ExposureOverride { self.handler.search_info() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handler.handle(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + self.handler.handle(invocation) } } diff --git a/codex-rs/core/src/tools/registry_tests.rs b/codex-rs/core/src/tools/registry_tests.rs index cc7f39e2a39..67613f1d081 100644 --- a/codex-rs/core/src/tools/registry_tests.rs +++ b/codex-rs/core/src/tools/registry_tests.rs @@ -5,7 +5,6 @@ struct TestHandler { tool_name: codex_tools::ToolName, } -#[async_trait::async_trait] impl ToolExecutor for TestHandler { fn tool_name(&self) -> codex_tools::ToolName { self.tool_name.clone() @@ -15,13 +14,15 @@ impl ToolExecutor for TestHandler { test_spec(&self.tool_name) } - async fn handle( - &self, - _invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - Ok(Box::new( - crate::tools::context::FunctionToolOutput::from_text("ok".to_string(), Some(true)), - )) + fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { + Ok( + Box::new(crate::tools::context::FunctionToolOutput::from_text( + "ok".to_string(), + Some(true), + )) as Box, + ) + }) } } @@ -38,7 +39,6 @@ struct LifecycleTestHandler { result: LifecycleTestResult, } -#[async_trait::async_trait] impl ToolExecutor for LifecycleTestHandler { fn tool_name(&self) -> codex_tools::ToolName { self.tool_name.clone() @@ -48,11 +48,8 @@ impl ToolExecutor for LifecycleTestHandler { test_spec(&self.tool_name) } - async fn handle( - &self, - _invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - self.handle_call().await + fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call()) } } @@ -66,7 +63,8 @@ impl LifecycleTestHandler { "ok".to_string(), Some(success), ), - )), + ) + as Box), LifecycleTestResult::Err => Err(FunctionCallError::RespondToModel( "handler failed".to_string(), )), diff --git a/codex-rs/core/src/tools/router_tests.rs b/codex-rs/core/src/tools/router_tests.rs index a9a52ca463c..4024cb61f73 100644 --- a/codex-rs/core/src/tools/router_tests.rs +++ b/codex-rs/core/src/tools/router_tests.rs @@ -44,7 +44,6 @@ impl codex_extension_api::ToolContributor for ExtensionEchoContributor { struct ExtensionEchoExecutor; -#[async_trait::async_trait] impl ToolExecutor for ExtensionEchoExecutor { fn tool_name(&self) -> ToolName { ToolName::namespaced("extension/", "echo") @@ -73,11 +72,8 @@ impl ToolExecutor for ExtensionEchoExecutor { }) } - async fn handle( - &self, - call: ExtensionToolCall, - ) -> Result, codex_tools::FunctionCallError> { - self.handle_call(call).await + fn handle(&self, call: ExtensionToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } @@ -93,7 +89,7 @@ impl ExtensionEchoExecutor { "callId": call.call_id, "conversationHistory": call.conversation_history.items(), "ok": true, - })))) + }))) as Box) } } diff --git a/codex-rs/core/src/tools/spec_plan.rs b/codex-rs/core/src/tools/spec_plan.rs index 19f4c9f8976..697eba1d4a1 100644 --- a/codex-rs/core/src/tools/spec_plan.rs +++ b/codex-rs/core/src/tools/spec_plan.rs @@ -72,7 +72,6 @@ use codex_tools::ToolCall as ExtensionToolCall; use codex_tools::ToolEnvironmentMode; use codex_tools::ToolExecutor; use codex_tools::ToolName; -use codex_tools::ToolOutput; use codex_tools::ToolSearchInfo; use codex_tools::ToolSpec; use codex_tools::UnifiedExecShellMode; @@ -946,7 +945,6 @@ struct MultiAgentV2NamespaceOverride { namespace: String, } -#[async_trait::async_trait] impl ToolExecutor for MultiAgentV2NamespaceOverride { fn tool_name(&self) -> ToolName { ToolName::namespaced(self.namespace.clone(), self.handler.tool_name().name) @@ -975,11 +973,8 @@ impl ToolExecutor for MultiAgentV2NamespaceOverride { self.handler.search_info() } - async fn handle( - &self, - invocation: ToolInvocation, - ) -> Result, codex_tools::FunctionCallError> { - self.handler.handle(invocation).await + fn handle(&self, invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + self.handler.handle(invocation) } } diff --git a/codex-rs/core/src/tools/spec_plan_tests.rs b/codex-rs/core/src/tools/spec_plan_tests.rs index f96f41f0f25..a9eb5012d52 100644 --- a/codex-rs/core/src/tools/spec_plan_tests.rs +++ b/codex-rs/core/src/tools/spec_plan_tests.rs @@ -285,7 +285,6 @@ fn use_bedrock_provider(turn: &mut TurnContext) { struct WebRunExtensionTool; -#[async_trait::async_trait] impl ToolExecutor for WebRunExtensionTool { fn tool_name(&self) -> ToolName { ToolName::namespaced("web", "run") @@ -306,17 +305,15 @@ impl ToolExecutor for WebRunExtensionTool { }) } - async fn handle( - &self, - _call: ExtensionToolCall, - ) -> Result, codex_tools::FunctionCallError> { - Ok(Box::new(codex_tools::JsonToolOutput::new(json!({})))) + fn handle(&self, _call: ExtensionToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { + Ok(Box::new(codex_tools::JsonToolOutput::new(json!({}))) as Box) + }) } } struct DeferredExtensionTool; -#[async_trait::async_trait] impl ToolExecutor for DeferredExtensionTool { fn tool_name(&self) -> ToolName { ToolName::plain("extension_echo") @@ -344,11 +341,8 @@ impl ToolExecutor for DeferredExtensionTool { ToolExposure::Deferred } - async fn handle( - &self, - _call: ExtensionToolCall, - ) -> Result, codex_tools::FunctionCallError> { - panic!("spec planning should not execute extension tools") + fn handle(&self, _call: ExtensionToolCall) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { panic!("spec planning should not execute extension tools") }) } } diff --git a/codex-rs/core/src/tools/tool_dispatch_trace_tests.rs b/codex-rs/core/src/tools/tool_dispatch_trace_tests.rs index 69dc8ab5803..b09996872ea 100644 --- a/codex-rs/core/src/tools/tool_dispatch_trace_tests.rs +++ b/codex-rs/core/src/tools/tool_dispatch_trace_tests.rs @@ -30,7 +30,6 @@ struct TestHandler { tool_name: codex_tools::ToolName, } -#[async_trait::async_trait] impl ToolExecutor for TestHandler { fn tool_name(&self) -> codex_tools::ToolName { self.tool_name.clone() @@ -47,14 +46,13 @@ impl ToolExecutor for TestHandler { }) } - async fn handle( - &self, - _invocation: ToolInvocation, - ) -> Result, FunctionCallError> { - Ok(Box::new(FunctionToolOutput::from_text( - "ok".to_string(), - Some(true), - ))) + fn handle(&self, _invocation: ToolInvocation) -> codex_tools::ToolExecutorFuture<'_> { + Box::pin(async { + Ok( + Box::new(FunctionToolOutput::from_text("ok".to_string(), Some(true))) + as Box, + ) + }) } } diff --git a/codex-rs/ext/extension-api/src/lib.rs b/codex-rs/ext/extension-api/src/lib.rs index dc3495a71c0..52f15c894c3 100644 --- a/codex-rs/ext/extension-api/src/lib.rs +++ b/codex-rs/ext/extension-api/src/lib.rs @@ -20,6 +20,7 @@ pub use codex_tools::NoopTurnItemEmitter; pub use codex_tools::ResponsesApiTool; pub use codex_tools::ToolCall; pub use codex_tools::ToolExecutor; +pub use codex_tools::ToolExecutorFuture; pub use codex_tools::ToolName; pub use codex_tools::ToolOutput; pub use codex_tools::ToolPayload; diff --git a/codex-rs/ext/goal/Cargo.toml b/codex-rs/ext/goal/Cargo.toml index 1e21f5ac884..4d75ba2f26a 100644 --- a/codex-rs/ext/goal/Cargo.toml +++ b/codex-rs/ext/goal/Cargo.toml @@ -14,7 +14,6 @@ doctest = false workspace = true [dependencies] -async-trait = { workspace = true } codex-analytics = { workspace = true } codex-core = { workspace = true } codex-extension-api = { workspace = true } diff --git a/codex-rs/ext/goal/src/tool.rs b/codex-rs/ext/goal/src/tool.rs index c45ed81b0ad..d280f6e04b6 100644 --- a/codex-rs/ext/goal/src/tool.rs +++ b/codex-rs/ext/goal/src/tool.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use async_trait::async_trait; use codex_extension_api::FunctionCallError; use codex_extension_api::JsonToolOutput; use codex_extension_api::ToolCall; @@ -132,7 +131,6 @@ impl GoalToolExecutor { } } -#[async_trait] impl ToolExecutor for GoalToolExecutor { fn tool_name(&self) -> ToolName { ToolName::plain(match self.kind { @@ -150,12 +148,14 @@ impl ToolExecutor for GoalToolExecutor { } } - async fn handle(&self, invocation: ToolCall) -> Result, FunctionCallError> { - match self.kind { - GoalToolKind::Get => self.handle_get(invocation).await, - GoalToolKind::Create => self.handle_create(invocation).await, - GoalToolKind::Update => self.handle_update(invocation).await, - } + fn handle(&self, invocation: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(async move { + match self.kind { + GoalToolKind::Get => self.handle_get(invocation).await, + GoalToolKind::Create => self.handle_create(invocation).await, + GoalToolKind::Update => self.handle_update(invocation).await, + } + }) } } diff --git a/codex-rs/ext/image-generation/Cargo.toml b/codex-rs/ext/image-generation/Cargo.toml index cb5ddda0a81..dfa85ee82e1 100644 --- a/codex-rs/ext/image-generation/Cargo.toml +++ b/codex-rs/ext/image-generation/Cargo.toml @@ -13,7 +13,6 @@ doctest = false workspace = true [dependencies] -async-trait = { workspace = true } codex-api = { workspace = true } codex-core = { workspace = true } codex-extension-api = { workspace = true } diff --git a/codex-rs/ext/image-generation/src/tool.rs b/codex-rs/ext/image-generation/src/tool.rs index 70880b4661f..07ed8f4bf6f 100644 --- a/codex-rs/ext/image-generation/src/tool.rs +++ b/codex-rs/ext/image-generation/src/tool.rs @@ -78,7 +78,6 @@ struct ImagegenArgs { num_last_images_to_include: Option, } -#[async_trait::async_trait] impl ToolExecutor for ImageGenerationTool { /// Keeps the tool in the existing image-generation Responses namespace. fn tool_name(&self) -> ToolName { @@ -96,8 +95,8 @@ impl ToolExecutor for ImageGenerationTool { } /// Executes the selected image operation and returns the completed image result. - async fn handle(&self, call: ToolCall) -> Result, FunctionCallError> { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/ext/memories/Cargo.toml b/codex-rs/ext/memories/Cargo.toml index 68eeaf8ec1b..e283140b15e 100644 --- a/codex-rs/ext/memories/Cargo.toml +++ b/codex-rs/ext/memories/Cargo.toml @@ -13,7 +13,6 @@ doctest = false workspace = true [dependencies] -async-trait = { workspace = true } codex-core = { workspace = true } codex-extension-api = { workspace = true } codex-features = { workspace = true } diff --git a/codex-rs/ext/memories/src/tools/ad_hoc_note.rs b/codex-rs/ext/memories/src/tools/ad_hoc_note.rs index 3495d57d328..0ce9cade676 100644 --- a/codex-rs/ext/memories/src/tools/ad_hoc_note.rs +++ b/codex-rs/ext/memories/src/tools/ad_hoc_note.rs @@ -41,7 +41,6 @@ pub(super) struct AddAdHocNoteTool { pub(super) metrics_client: Option, } -#[async_trait::async_trait] impl ToolExecutor for AddAdHocNoteTool where B: MemoriesBackend, @@ -57,12 +56,8 @@ where ) } - async fn handle( - &self, - call: ToolCall, - ) -> Result, codex_extension_api::FunctionCallError> - { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/ext/memories/src/tools/list.rs b/codex-rs/ext/memories/src/tools/list.rs index d3b23b1ca2e..b7b9ad05862 100644 --- a/codex-rs/ext/memories/src/tools/list.rs +++ b/codex-rs/ext/memories/src/tools/list.rs @@ -39,7 +39,6 @@ pub(super) struct ListTool { pub(super) metrics_client: Option, } -#[async_trait::async_trait] impl ToolExecutor for ListTool where B: MemoriesBackend, @@ -55,12 +54,8 @@ where ) } - async fn handle( - &self, - call: ToolCall, - ) -> Result, codex_extension_api::FunctionCallError> - { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/ext/memories/src/tools/read.rs b/codex-rs/ext/memories/src/tools/read.rs index e408a17cad7..6625cdaf8bd 100644 --- a/codex-rs/ext/memories/src/tools/read.rs +++ b/codex-rs/ext/memories/src/tools/read.rs @@ -38,7 +38,6 @@ pub(super) struct ReadTool { pub(super) metrics_client: Option, } -#[async_trait::async_trait] impl ToolExecutor for ReadTool where B: MemoriesBackend, @@ -54,12 +53,8 @@ where ) } - async fn handle( - &self, - call: ToolCall, - ) -> Result, codex_extension_api::FunctionCallError> - { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/ext/memories/src/tools/search.rs b/codex-rs/ext/memories/src/tools/search.rs index cc8ba201a65..928c98b475d 100644 --- a/codex-rs/ext/memories/src/tools/search.rs +++ b/codex-rs/ext/memories/src/tools/search.rs @@ -47,7 +47,6 @@ pub(super) struct SearchTool { pub(super) metrics_client: Option, } -#[async_trait::async_trait] impl ToolExecutor for SearchTool where B: MemoriesBackend, @@ -63,12 +62,8 @@ where ) } - async fn handle( - &self, - call: ToolCall, - ) -> Result, codex_extension_api::FunctionCallError> - { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/ext/web-search/Cargo.toml b/codex-rs/ext/web-search/Cargo.toml index 954ac3dac9e..d007d6146de 100644 --- a/codex-rs/ext/web-search/Cargo.toml +++ b/codex-rs/ext/web-search/Cargo.toml @@ -13,7 +13,6 @@ doctest = false workspace = true [dependencies] -async-trait = { workspace = true } codex-api = { workspace = true } codex-core = { workspace = true } codex-extension-api = { workspace = true } diff --git a/codex-rs/ext/web-search/src/tool.rs b/codex-rs/ext/web-search/src/tool.rs index 1de65edf865..9b8dbf56d6f 100644 --- a/codex-rs/ext/web-search/src/tool.rs +++ b/codex-rs/ext/web-search/src/tool.rs @@ -39,7 +39,6 @@ pub(crate) struct WebSearchTool { pub(crate) settings: SearchSettings, } -#[async_trait::async_trait] impl ToolExecutor for WebSearchTool { fn tool_name(&self) -> ToolName { ToolName::namespaced(WEB_NAMESPACE, RUN_TOOL_NAME) @@ -74,8 +73,8 @@ impl ToolExecutor for WebSearchTool { true } - async fn handle(&self, call: ToolCall) -> Result, FunctionCallError> { - self.handle_call(call).await + fn handle(&self, call: ToolCall) -> codex_extension_api::ToolExecutorFuture<'_> { + Box::pin(self.handle_call(call)) } } diff --git a/codex-rs/tools/Cargo.toml b/codex-rs/tools/Cargo.toml index 7cc0e348458..4b2a3257f39 100644 --- a/codex-rs/tools/Cargo.toml +++ b/codex-rs/tools/Cargo.toml @@ -8,7 +8,6 @@ version.workspace = true workspace = true [dependencies] -async-trait = { workspace = true } codex-app-server-protocol = { workspace = true } codex-code-mode = { workspace = true } codex-features = { workspace = true } diff --git a/codex-rs/tools/src/lib.rs b/codex-rs/tools/src/lib.rs index 1cee3f7d2d5..848bab3e1c0 100644 --- a/codex-rs/tools/src/lib.rs +++ b/codex-rs/tools/src/lib.rs @@ -93,6 +93,7 @@ pub use tool_discovery::ToolSearchSourceInfo; pub use tool_discovery::collect_request_plugin_install_entries; pub use tool_discovery::filter_request_plugin_install_discoverable_tools_for_client; pub use tool_executor::ToolExecutor; +pub use tool_executor::ToolExecutorFuture; pub use tool_executor::ToolExposure; pub use tool_output::JsonToolOutput; pub use tool_output::ToolOutput; diff --git a/codex-rs/tools/src/tool_executor.rs b/codex-rs/tools/src/tool_executor.rs index 541d2443e0c..708ed1c3b1f 100644 --- a/codex-rs/tools/src/tool_executor.rs +++ b/codex-rs/tools/src/tool_executor.rs @@ -3,6 +3,12 @@ use crate::ToolName; use crate::ToolOutput; use crate::ToolSearchInfo; use crate::ToolSpec; +use std::future::Future; +use std::pin::Pin; + +/// The boxed future returned by [`ToolExecutor::handle`]. +pub type ToolExecutorFuture<'a> = + Pin, FunctionCallError>> + Send + 'a>>; /// Controls where a tool is exposed to the model. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -40,7 +46,6 @@ impl ToolExposure { /// Implementations keep the model-visible spec tied to the executable runtime. /// Host crates can layer routing, hooks, telemetry, or other orchestration on /// top without reopening the spec/runtime split. -#[async_trait::async_trait] pub trait ToolExecutor: Send + Sync { /// The concrete tool name handled by this runtime instance. fn tool_name(&self) -> ToolName; @@ -60,8 +65,5 @@ pub trait ToolExecutor: Send + Sync { false } - async fn handle( - &self, - invocation: Invocation, - ) -> Result, FunctionCallError>; + fn handle(&self, invocation: Invocation) -> ToolExecutorFuture<'_>; }