From 7c5cb8d4dbf91304bc1c8649468cef8cbbd7fd8d Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Mon, 10 Nov 2025 16:23:53 -0800 Subject: [PATCH] split into two methods --- .../src/protocol/common.rs | 18 +++++++--- .../app-server-protocol/src/protocol/v2.rs | 36 +++++++++++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index c29d59946b..3e1215779e 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -427,19 +427,29 @@ impl TryFrom for ServerRequest { server_request_definitions! { /// NEW APIs - /// Sent when approval is requested for a specific item (e.g. file edit, command execution). - ItemRequestApproval => "item/requestApproval" { - params: v2::ItemRequestApprovalParams, - response: v2::ItemRequestApprovalResponse, + /// Sent when approval is requested for a specific command execution. + /// This request is used when calling turn/start instead of the legacy APIs (i.e. SendUserTurn, SendUserMessage). + CommandExecutionRequestApproval => "item/commandExecution/requestApproval" { + params: v2::CommandExecutionRequestApprovalParams, + response: v2::CommandExecutionRequestApprovalResponse, + }, + + /// Sent when approval is requested for a specific file change. + /// This request is used when calling turn/start instead of the legacy APIs (i.e. SendUserTurn, SendUserMessage). + FileChangeRequestApproval => "item/fileChange/requestApproval" { + params: v2::FileChangeRequestApprovalParams, + response: v2::FileChangeRequestApprovalResponse, }, /// DEPRECATED APIs below /// Request to approve a patch. + /// This request is used only when calling the legacy APIs (i.e. SendUserTurn, SendUserMessage). ApplyPatchApproval { params: v1::ApplyPatchApprovalParams, response: v1::ApplyPatchApprovalResponse, }, /// Request to exec a command. + /// This request is used only when calling the legacy APIs (i.e. SendUserTurn, SendUserMessage). ExecCommandApproval { params: v1::ExecCommandApprovalParams, response: v1::ExecCommandApprovalResponse, diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rs index fafbeb75e5..aef171d41a 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -883,20 +883,33 @@ pub struct McpToolCallProgressNotification { #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] -pub struct ItemRequestApprovalParams { +pub struct CommandExecutionRequestApprovalParams { pub thread_id: String, pub turn_id: String, pub item_id: String, - pub request: ItemApprovalRequest, + pub request: CommandExecutionRequest, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] -#[serde(tag = "type", rename_all = "camelCase")] -#[ts(tag = "type")] #[ts(export_to = "v2/")] -pub enum ItemApprovalRequest { - CommandExecution(CommandExecutionRequest), - FileEdit(FileEditRequest), +pub struct CommandExecutionRequestApprovalResponse { + pub decision: ReviewDecision, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +pub struct FileChangeRequestApprovalParams { + pub thread_id: String, + pub turn_id: String, + pub item_id: String, + pub request: FileChangeRequest, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[ts(export_to = "v2/")] +pub struct FileChangeRequestApprovalResponse { + pub decision: ReviewDecision, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] @@ -915,7 +928,7 @@ pub struct CommandExecutionRequest { #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] -pub struct FileEditRequest { +pub struct FileChangeRequest { pub call_id: String, pub file_changes: HashMap, /// Optional explanatory reason (e.g. request for extra write access). @@ -923,13 +936,6 @@ pub struct FileEditRequest { pub grant_root: Option, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export_to = "v2/")] -pub struct ItemRequestApprovalResponse { - pub decision: ReviewDecision, -} - #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")]