From 90006cb7290c5e320e58fda0f2aea69b62173f55 Mon Sep 17 00:00:00 2001 From: rafaelj Date: Thu, 21 May 2026 13:51:13 -0400 Subject: [PATCH] Add onboarding option picker tool --- .../schema/json/ServerRequest.json | 90 ++++++++++++ .../schema/json/ToolOptionPickerParams.json | 69 ++++++++++ .../schema/json/ToolOptionPickerResponse.json | 38 ++++++ .../codex_app_server_protocol.schemas.json | 128 ++++++++++++++++++ .../schema/typescript/ServerRequest.ts | 3 +- .../typescript/v2/ToolOptionPickerAction.ts | 8 ++ .../typescript/v2/ToolOptionPickerOption.ts | 8 ++ .../typescript/v2/ToolOptionPickerParams.ts | 9 ++ .../typescript/v2/ToolOptionPickerResponse.ts | 9 ++ .../schema/typescript/v2/index.ts | 4 + .../src/protocol/common.rs | 6 + .../src/protocol/v2/item.rs | 44 ++++++ .../app-server/src/bespoke_event_handling.rs | 119 ++++++++++++++++ codex-rs/core/src/session/handlers.rs | 13 ++ codex-rs/core/src/session/mod.rs | 75 ++++++++++ codex-rs/core/src/session/turn.rs | 1 + codex-rs/core/src/state/turn.rs | 18 +++ codex-rs/core/src/tools/handlers/mod.rs | 2 + .../core/src/tools/handlers/option_picker.rs | 77 +++++++++++ codex-rs/core/src/tools/spec_plan.rs | 4 + codex-rs/exec/src/lib.rs | 12 ++ codex-rs/mcp-server/src/codex_tool_runner.rs | 1 + codex-rs/protocol/src/lib.rs | 1 + codex-rs/protocol/src/option_picker.rs | 58 ++++++++ codex-rs/protocol/src/protocol.rs | 13 ++ codex-rs/rollout-trace/src/protocol_event.rs | 2 + codex-rs/rollout/src/policy.rs | 1 + codex-rs/tools/src/lib.rs | 3 + codex-rs/tools/src/option_picker_tool.rs | 65 +++++++++ .../tui/src/app/app_server_event_targets.rs | 3 + codex-rs/tui/src/app/app_server_requests.rs | 9 +- codex-rs/tui/src/app/side.rs | 1 + .../tui/src/chatwidget/protocol_requests.rs | 3 +- 33 files changed, 894 insertions(+), 3 deletions(-) create mode 100644 codex-rs/app-server-protocol/schema/json/ToolOptionPickerParams.json create mode 100644 codex-rs/app-server-protocol/schema/json/ToolOptionPickerResponse.json create mode 100644 codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerAction.ts create mode 100644 codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerOption.ts create mode 100644 codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerParams.ts create mode 100644 codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerResponse.ts create mode 100644 codex-rs/core/src/tools/handlers/option_picker.rs create mode 100644 codex-rs/protocol/src/option_picker.rs create mode 100644 codex-rs/tools/src/option_picker_tool.rs diff --git a/codex-rs/app-server-protocol/schema/json/ServerRequest.json b/codex-rs/app-server-protocol/schema/json/ServerRequest.json index 411095f2c2..0937487981 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerRequest.json +++ b/codex-rs/app-server-protocol/schema/json/ServerRequest.json @@ -1664,6 +1664,71 @@ "ThreadId": { "type": "string" }, + "ToolOptionPickerOption": { + "description": "EXPERIMENTAL. Defines a single selectable option for request_option_picker.", + "properties": { + "description": { + "type": [ + "string", + "null" + ] + }, + "label": { + "type": "string" + } + }, + "required": [ + "label" + ], + "type": "object" + }, + "ToolOptionPickerParams": { + "description": "EXPERIMENTAL. Params sent with a request_option_picker event.", + "properties": { + "allowMultiple": { + "type": "boolean" + }, + "itemId": { + "type": "string" + }, + "options": { + "items": { + "$ref": "#/definitions/ToolOptionPickerOption" + }, + "type": "array" + }, + "question": { + "type": "string" + }, + "skipLabel": { + "type": [ + "string", + "null" + ] + }, + "submitLabel": { + "type": [ + "string", + "null" + ] + }, + "threadId": { + "type": "string" + }, + "turnId": { + "type": "string" + } + }, + "required": [ + "allowMultiple", + "itemId", + "options", + "question", + "threadId", + "turnId" + ], + "type": "object" + }, "ToolRequestUserInputOption": { "description": "EXPERIMENTAL. Defines a single selectable option for request_user_input.", "properties": { @@ -1822,6 +1887,31 @@ "title": "Item/tool/requestUserInputRequest", "type": "object" }, + { + "description": "EXPERIMENTAL - Request compact option selection from the user for a tool call.", + "properties": { + "id": { + "$ref": "#/definitions/RequestId" + }, + "method": { + "enum": [ + "item/tool/requestOptionPicker" + ], + "title": "Item/tool/requestOptionPickerRequestMethod", + "type": "string" + }, + "params": { + "$ref": "#/definitions/ToolOptionPickerParams" + } + }, + "required": [ + "id", + "method", + "params" + ], + "title": "Item/tool/requestOptionPickerRequest", + "type": "object" + }, { "description": "Request input for an MCP server elicitation.", "properties": { diff --git a/codex-rs/app-server-protocol/schema/json/ToolOptionPickerParams.json b/codex-rs/app-server-protocol/schema/json/ToolOptionPickerParams.json new file mode 100644 index 0000000000..ec2df00177 --- /dev/null +++ b/codex-rs/app-server-protocol/schema/json/ToolOptionPickerParams.json @@ -0,0 +1,69 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "ToolOptionPickerOption": { + "description": "EXPERIMENTAL. Defines a single selectable option for request_option_picker.", + "properties": { + "description": { + "type": [ + "string", + "null" + ] + }, + "label": { + "type": "string" + } + }, + "required": [ + "label" + ], + "type": "object" + } + }, + "description": "EXPERIMENTAL. Params sent with a request_option_picker event.", + "properties": { + "allowMultiple": { + "type": "boolean" + }, + "itemId": { + "type": "string" + }, + "options": { + "items": { + "$ref": "#/definitions/ToolOptionPickerOption" + }, + "type": "array" + }, + "question": { + "type": "string" + }, + "skipLabel": { + "type": [ + "string", + "null" + ] + }, + "submitLabel": { + "type": [ + "string", + "null" + ] + }, + "threadId": { + "type": "string" + }, + "turnId": { + "type": "string" + } + }, + "required": [ + "allowMultiple", + "itemId", + "options", + "question", + "threadId", + "turnId" + ], + "title": "ToolOptionPickerParams", + "type": "object" +} \ No newline at end of file diff --git a/codex-rs/app-server-protocol/schema/json/ToolOptionPickerResponse.json b/codex-rs/app-server-protocol/schema/json/ToolOptionPickerResponse.json new file mode 100644 index 0000000000..7b773c4b9c --- /dev/null +++ b/codex-rs/app-server-protocol/schema/json/ToolOptionPickerResponse.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "ToolOptionPickerAction": { + "description": "EXPERIMENTAL. Action selected for request_option_picker.", + "enum": [ + "submit", + "skip", + "dismiss" + ], + "type": "string" + } + }, + "description": "EXPERIMENTAL. Captures a user's response to request_option_picker.", + "properties": { + "action": { + "$ref": "#/definitions/ToolOptionPickerAction" + }, + "freeformAnswer": { + "type": [ + "string", + "null" + ] + }, + "selectedOptions": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "action", + "selectedOptions" + ], + "title": "ToolOptionPickerResponse", + "type": "object" +} \ No newline at end of file diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json index dda285476d..c5fd14d61e 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json @@ -5296,6 +5296,31 @@ "title": "Item/tool/requestUserInputRequest", "type": "object" }, + { + "description": "EXPERIMENTAL - Request compact option selection from the user for a tool call.", + "properties": { + "id": { + "$ref": "#/definitions/v2/RequestId" + }, + "method": { + "enum": [ + "item/tool/requestOptionPicker" + ], + "title": "Item/tool/requestOptionPickerRequestMethod", + "type": "string" + }, + "params": { + "$ref": "#/definitions/ToolOptionPickerParams" + } + }, + "required": [ + "id", + "method", + "params" + ], + "title": "Item/tool/requestOptionPickerRequest", + "type": "object" + }, { "description": "Request input for an MCP server elicitation.", "properties": { @@ -5473,6 +5498,109 @@ ], "title": "ServerRequest" }, + "ToolOptionPickerAction": { + "description": "EXPERIMENTAL. Action selected for request_option_picker.", + "enum": [ + "submit", + "skip", + "dismiss" + ], + "type": "string" + }, + "ToolOptionPickerOption": { + "description": "EXPERIMENTAL. Defines a single selectable option for request_option_picker.", + "properties": { + "description": { + "type": [ + "string", + "null" + ] + }, + "label": { + "type": "string" + } + }, + "required": [ + "label" + ], + "type": "object" + }, + "ToolOptionPickerParams": { + "$schema": "http://json-schema.org/draft-07/schema#", + "description": "EXPERIMENTAL. Params sent with a request_option_picker event.", + "properties": { + "allowMultiple": { + "type": "boolean" + }, + "itemId": { + "type": "string" + }, + "options": { + "items": { + "$ref": "#/definitions/ToolOptionPickerOption" + }, + "type": "array" + }, + "question": { + "type": "string" + }, + "skipLabel": { + "type": [ + "string", + "null" + ] + }, + "submitLabel": { + "type": [ + "string", + "null" + ] + }, + "threadId": { + "type": "string" + }, + "turnId": { + "type": "string" + } + }, + "required": [ + "allowMultiple", + "itemId", + "options", + "question", + "threadId", + "turnId" + ], + "title": "ToolOptionPickerParams", + "type": "object" + }, + "ToolOptionPickerResponse": { + "$schema": "http://json-schema.org/draft-07/schema#", + "description": "EXPERIMENTAL. Captures a user's response to request_option_picker.", + "properties": { + "action": { + "$ref": "#/definitions/ToolOptionPickerAction" + }, + "freeformAnswer": { + "type": [ + "string", + "null" + ] + }, + "selectedOptions": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "action", + "selectedOptions" + ], + "title": "ToolOptionPickerResponse", + "type": "object" + }, "ToolRequestUserInputAnswer": { "description": "EXPERIMENTAL. Captures a user's answer to a request_user_input question.", "properties": { diff --git a/codex-rs/app-server-protocol/schema/typescript/ServerRequest.ts b/codex-rs/app-server-protocol/schema/typescript/ServerRequest.ts index 80e9ffc116..6f91189360 100644 --- a/codex-rs/app-server-protocol/schema/typescript/ServerRequest.ts +++ b/codex-rs/app-server-protocol/schema/typescript/ServerRequest.ts @@ -11,9 +11,10 @@ import type { DynamicToolCallParams } from "./v2/DynamicToolCallParams"; import type { FileChangeRequestApprovalParams } from "./v2/FileChangeRequestApprovalParams"; import type { McpServerElicitationRequestParams } from "./v2/McpServerElicitationRequestParams"; import type { PermissionsRequestApprovalParams } from "./v2/PermissionsRequestApprovalParams"; +import type { ToolOptionPickerParams } from "./v2/ToolOptionPickerParams"; import type { ToolRequestUserInputParams } from "./v2/ToolRequestUserInputParams"; /** * Request initiated from the server and sent to the client. */ -export type ServerRequest = { "method": "item/commandExecution/requestApproval", id: RequestId, params: CommandExecutionRequestApprovalParams, } | { "method": "item/fileChange/requestApproval", id: RequestId, params: FileChangeRequestApprovalParams, } | { "method": "item/tool/requestUserInput", id: RequestId, params: ToolRequestUserInputParams, } | { "method": "mcpServer/elicitation/request", id: RequestId, params: McpServerElicitationRequestParams, } | { "method": "item/permissions/requestApproval", id: RequestId, params: PermissionsRequestApprovalParams, } | { "method": "item/tool/call", id: RequestId, params: DynamicToolCallParams, } | { "method": "account/chatgptAuthTokens/refresh", id: RequestId, params: ChatgptAuthTokensRefreshParams, } | { "method": "attestation/generate", id: RequestId, params: AttestationGenerateParams, } | { "method": "applyPatchApproval", id: RequestId, params: ApplyPatchApprovalParams, } | { "method": "execCommandApproval", id: RequestId, params: ExecCommandApprovalParams, }; +export type ServerRequest = { "method": "item/commandExecution/requestApproval", id: RequestId, params: CommandExecutionRequestApprovalParams, } | { "method": "item/fileChange/requestApproval", id: RequestId, params: FileChangeRequestApprovalParams, } | { "method": "item/tool/requestUserInput", id: RequestId, params: ToolRequestUserInputParams, } | { "method": "item/tool/requestOptionPicker", id: RequestId, params: ToolOptionPickerParams, } | { "method": "mcpServer/elicitation/request", id: RequestId, params: McpServerElicitationRequestParams, } | { "method": "item/permissions/requestApproval", id: RequestId, params: PermissionsRequestApprovalParams, } | { "method": "item/tool/call", id: RequestId, params: DynamicToolCallParams, } | { "method": "account/chatgptAuthTokens/refresh", id: RequestId, params: ChatgptAuthTokensRefreshParams, } | { "method": "attestation/generate", id: RequestId, params: AttestationGenerateParams, } | { "method": "applyPatchApproval", id: RequestId, params: ApplyPatchApprovalParams, } | { "method": "execCommandApproval", id: RequestId, params: ExecCommandApprovalParams, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerAction.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerAction.ts new file mode 100644 index 0000000000..c14fb707ab --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerAction.ts @@ -0,0 +1,8 @@ +// GENERATED CODE! DO NOT MODIFY BY HAND! + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * EXPERIMENTAL. Action selected for request_option_picker. + */ +export type ToolOptionPickerAction = "submit" | "skip" | "dismiss"; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerOption.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerOption.ts new file mode 100644 index 0000000000..0748d4c119 --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerOption.ts @@ -0,0 +1,8 @@ +// GENERATED CODE! DO NOT MODIFY BY HAND! + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * EXPERIMENTAL. Defines a single selectable option for request_option_picker. + */ +export type ToolOptionPickerOption = { label: string, description: string | null, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerParams.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerParams.ts new file mode 100644 index 0000000000..3eedf19b88 --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerParams.ts @@ -0,0 +1,9 @@ +// GENERATED CODE! DO NOT MODIFY BY HAND! + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ToolOptionPickerOption } from "./ToolOptionPickerOption"; + +/** + * EXPERIMENTAL. Params sent with a request_option_picker event. + */ +export type ToolOptionPickerParams = { threadId: string, turnId: string, itemId: string, question: string, options: Array, allowMultiple: boolean, submitLabel: string | null, skipLabel: string | null, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerResponse.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerResponse.ts new file mode 100644 index 0000000000..a1cfe85cdf --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ToolOptionPickerResponse.ts @@ -0,0 +1,9 @@ +// GENERATED CODE! DO NOT MODIFY BY HAND! + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ToolOptionPickerAction } from "./ToolOptionPickerAction"; + +/** + * EXPERIMENTAL. Captures a user's response to request_option_picker. + */ +export type ToolOptionPickerResponse = { action: ToolOptionPickerAction, selectedOptions: Array, freeformAnswer: string | null, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts index e9b8993c26..10f8747d70 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts @@ -425,6 +425,10 @@ export type { ThreadUnsubscribeParams } from "./ThreadUnsubscribeParams"; export type { ThreadUnsubscribeResponse } from "./ThreadUnsubscribeResponse"; export type { ThreadUnsubscribeStatus } from "./ThreadUnsubscribeStatus"; export type { TokenUsageBreakdown } from "./TokenUsageBreakdown"; +export type { ToolOptionPickerAction } from "./ToolOptionPickerAction"; +export type { ToolOptionPickerOption } from "./ToolOptionPickerOption"; +export type { ToolOptionPickerParams } from "./ToolOptionPickerParams"; +export type { ToolOptionPickerResponse } from "./ToolOptionPickerResponse"; export type { ToolRequestUserInputAnswer } from "./ToolRequestUserInputAnswer"; export type { ToolRequestUserInputOption } from "./ToolRequestUserInputOption"; export type { ToolRequestUserInputParams } from "./ToolRequestUserInputParams"; diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index 76334e8a6a..63fd977f96 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -1334,6 +1334,12 @@ server_request_definitions! { response: v2::ToolRequestUserInputResponse, }, + /// EXPERIMENTAL - Request compact option selection from the user for a tool call. + ToolOptionPicker => "item/tool/requestOptionPicker" { + params: v2::ToolOptionPickerParams, + response: v2::ToolOptionPickerResponse, + }, + /// Request input for an MCP server elicitation. McpServerElicitationRequest => "mcpServer/elicitation/request" { params: v2::McpServerElicitationRequestParams, diff --git a/codex-rs/app-server-protocol/src/protocol/v2/item.rs b/codex-rs/app-server-protocol/src/protocol/v2/item.rs index 39e489d6aa..910231d79f 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/item.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/item.rs @@ -1447,3 +1447,47 @@ pub struct ToolRequestUserInputAnswer { pub struct ToolRequestUserInputResponse { pub answers: HashMap, } + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +/// EXPERIMENTAL. Defines a single selectable option for request_option_picker. +pub struct ToolOptionPickerOption { + pub label: String, + pub description: Option, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +/// EXPERIMENTAL. Params sent with a request_option_picker event. +pub struct ToolOptionPickerParams { + pub thread_id: String, + pub turn_id: String, + pub item_id: String, + pub question: String, + pub options: Vec, + pub allow_multiple: bool, + pub submit_label: Option, + pub skip_label: Option, +} + +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "snake_case")] +#[ts(export_to = "v2/")] +/// EXPERIMENTAL. Action selected for request_option_picker. +pub enum ToolOptionPickerAction { + Submit, + Skip, + Dismiss, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +/// EXPERIMENTAL. Captures a user's response to request_option_picker. +pub struct ToolOptionPickerResponse { + pub action: ToolOptionPickerAction, + pub selected_options: Vec, + pub freeform_answer: Option, +} diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rs index efe6c69a32..4a9cd37717 100644 --- a/codex-rs/app-server/src/bespoke_event_handling.rs +++ b/codex-rs/app-server/src/bespoke_event_handling.rs @@ -65,6 +65,10 @@ use codex_app_server_protocol::ThreadSettingsUpdatedNotification; use codex_app_server_protocol::ThreadStatus; use codex_app_server_protocol::ThreadTokenUsage; use codex_app_server_protocol::ThreadTokenUsageUpdatedNotification; +use codex_app_server_protocol::ToolOptionPickerAction; +use codex_app_server_protocol::ToolOptionPickerOption; +use codex_app_server_protocol::ToolOptionPickerParams; +use codex_app_server_protocol::ToolOptionPickerResponse; use codex_app_server_protocol::ToolRequestUserInputOption; use codex_app_server_protocol::ToolRequestUserInputParams; use codex_app_server_protocol::ToolRequestUserInputQuestion; @@ -90,6 +94,8 @@ use codex_core::review_prompts; use codex_protocol::ThreadId; use codex_protocol::items::parse_hook_prompt_message; use codex_protocol::models::AdditionalPermissionProfile as CoreAdditionalPermissionProfile; +use codex_protocol::option_picker::OptionPickerAction as CoreOptionPickerAction; +use codex_protocol::option_picker::OptionPickerResponse as CoreOptionPickerResponse; use codex_protocol::plan_tool::UpdatePlanArgs; use codex_protocol::protocol::CodexErrorInfo as CoreCodexErrorInfo; use codex_protocol::protocol::Event; @@ -690,6 +696,43 @@ pub(crate) async fn apply_bespoke_event_handling( .await; }); } + EventMsg::OptionPicker(request) => { + let user_input_guard = thread_watch_manager + .note_user_input_requested(&conversation_id.to_string()) + .await; + let options = request + .options + .into_iter() + .map(|option| ToolOptionPickerOption { + label: option.label, + description: option.description, + }) + .collect(); + let params = ToolOptionPickerParams { + thread_id: conversation_id.to_string(), + turn_id: request.turn_id, + item_id: request.call_id, + question: request.question, + options, + allow_multiple: request.allow_multiple, + submit_label: request.submit_label, + skip_label: request.skip_label, + }; + let (pending_request_id, rx) = outgoing + .send_request(ServerRequestPayload::ToolOptionPicker(params)) + .await; + tokio::spawn(async move { + on_option_picker_response( + event_turn_id, + pending_request_id, + rx, + conversation, + thread_state, + user_input_guard, + ) + .await; + }); + } EventMsg::ElicitationRequest(request) => { let permission_guard = thread_watch_manager .note_permission_requested(&conversation_id.to_string()) @@ -1599,6 +1642,82 @@ async fn handle_token_count_event( } } +async fn on_option_picker_response( + event_turn_id: String, + pending_request_id: RequestId, + receiver: oneshot::Receiver, + conversation: Arc, + thread_state: Arc>, + user_input_guard: ThreadWatchActiveGuard, +) { + let response = receiver.await; + resolve_server_request_on_thread_listener(&thread_state, pending_request_id).await; + drop(user_input_guard); + let value = match response { + Ok(Ok(value)) => value, + Ok(Err(err)) if is_turn_transition_server_request_error(&err) => return, + Ok(Err(err)) => { + error!("option picker request failed with client error: {err:?}"); + submit_empty_option_picker_response(event_turn_id, conversation).await; + return; + } + Err(err) => { + error!("option picker request failed: {err:?}"); + submit_empty_option_picker_response(event_turn_id, conversation).await; + return; + } + }; + + let response = + serde_json::from_value::(value).unwrap_or_else(|err| { + error!("failed to deserialize ToolOptionPickerResponse: {err}"); + ToolOptionPickerResponse { + action: ToolOptionPickerAction::Dismiss, + selected_options: Vec::new(), + freeform_answer: None, + } + }); + let response = CoreOptionPickerResponse { + action: match response.action { + ToolOptionPickerAction::Submit => CoreOptionPickerAction::Submit, + ToolOptionPickerAction::Skip => CoreOptionPickerAction::Skip, + ToolOptionPickerAction::Dismiss => CoreOptionPickerAction::Dismiss, + }, + selected_options: response.selected_options, + freeform_answer: response.freeform_answer, + }; + + if let Err(err) = conversation + .submit(Op::OptionPickerResponse { + id: event_turn_id, + response, + }) + .await + { + error!("failed to submit OptionPickerResponse: {err}"); + } +} + +async fn submit_empty_option_picker_response( + event_turn_id: String, + conversation: Arc, +) { + let response = CoreOptionPickerResponse { + action: CoreOptionPickerAction::Dismiss, + selected_options: Vec::new(), + freeform_answer: None, + }; + if let Err(err) = conversation + .submit(Op::OptionPickerResponse { + id: event_turn_id, + response, + }) + .await + { + error!("failed to submit OptionPickerResponse: {err}"); + } +} + async fn handle_error( _conversation_id: ThreadId, error: TurnError, diff --git a/codex-rs/core/src/session/handlers.rs b/codex-rs/core/src/session/handlers.rs index 3d57bd7074..e4ff2d9329 100644 --- a/codex-rs/core/src/session/handlers.rs +++ b/codex-rs/core/src/session/handlers.rs @@ -26,6 +26,7 @@ use crate::tasks::UserShellCommandTask; use crate::tasks::execute_user_shell_command; use codex_protocol::models::ContentItem; use codex_protocol::models::ResponseInputItem; +use codex_protocol::option_picker::OptionPickerResponse; use codex_protocol::protocol::CodexErrorInfo; use codex_protocol::protocol::ErrorEvent; use codex_protocol::protocol::Event; @@ -435,6 +436,14 @@ pub async fn request_user_input_response( sess.notify_user_input_response(&id, response).await; } +pub async fn option_picker_response( + sess: &Arc, + id: String, + response: OptionPickerResponse, +) { + sess.notify_option_picker_response(&id, response).await; +} + pub async fn request_permissions_response( sess: &Arc, id: String, @@ -792,6 +801,10 @@ pub(super) async fn submission_loop( request_user_input_response(&sess, id, response).await; false } + Op::OptionPickerResponse { id, response } => { + option_picker_response(&sess, id, response).await; + false + } Op::RequestPermissionsResponse { id, response } => { request_permissions_response(&sess, id, response).await; false diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index c73b43a838..a09e7050f1 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -325,6 +325,8 @@ use codex_protocol::models::ContentItem; use codex_protocol::models::ResponseInputItem; use codex_protocol::models::ResponseItem; use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig; +use codex_protocol::option_picker::OptionPickerArgs; +use codex_protocol::option_picker::OptionPickerResponse; use codex_protocol::protocol::ApplyPatchApprovalRequestEvent; use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::CodexErrorInfo; @@ -343,6 +345,7 @@ use codex_protocol::protocol::ModelVerificationEvent; use codex_protocol::protocol::NetworkApprovalContext; use codex_protocol::protocol::NonSteerableTurnKind; use codex_protocol::protocol::Op; +use codex_protocol::protocol::OptionPickerEvent; use codex_protocol::protocol::RateLimitSnapshot; use codex_protocol::protocol::RequestUserInputEvent; use codex_protocol::protocol::ReviewDecision; @@ -2319,6 +2322,78 @@ impl Session { rx_response.await.ok() } + #[expect( + clippy::await_holding_invalid_type, + reason = "active turn checks and turn state updates must remain atomic" + )] + pub async fn request_option_picker( + &self, + turn_context: &TurnContext, + call_id: String, + args: OptionPickerArgs, + ) -> Option { + let sub_id = turn_context.sub_id.clone(); + let (tx_response, rx_response) = oneshot::channel(); + let event_id = sub_id.clone(); + let prev_entry = { + let mut active = self.active_turn.lock().await; + match active.as_mut() { + Some(at) => { + let mut ts = at.turn_state.lock().await; + ts.insert_pending_option_picker(sub_id, tx_response) + } + None => None, + } + }; + if prev_entry.is_some() { + warn!("Overwriting existing pending option picker for sub_id: {event_id}"); + } + + let event = EventMsg::OptionPicker(OptionPickerEvent { + call_id, + turn_id: turn_context.sub_id.clone(), + question: args.question, + options: args.options, + allow_multiple: args.allow_multiple, + submit_label: args.submit_label, + skip_label: args.skip_label, + }); + turn_context + .turn_metadata_state + .mark_user_input_requested_during_turn(); + self.send_event(turn_context, event).await; + rx_response.await.ok() + } + + #[expect( + clippy::await_holding_invalid_type, + reason = "active turn checks and turn state updates must remain atomic" + )] + pub async fn notify_option_picker_response( + &self, + sub_id: &str, + response: OptionPickerResponse, + ) { + let entry = { + let mut active = self.active_turn.lock().await; + match active.as_mut() { + Some(at) => { + let mut ts = at.turn_state.lock().await; + ts.remove_pending_option_picker(sub_id) + } + None => None, + } + }; + match entry { + Some(tx_response) => { + tx_response.send(response).ok(); + } + None => { + warn!("No pending option picker found for sub_id: {sub_id}"); + } + } + } + #[expect( clippy::await_holding_invalid_type, reason = "active turn checks and turn state updates must remain atomic" diff --git a/codex-rs/core/src/session/turn.rs b/codex-rs/core/src/session/turn.rs index 26ba845460..1734b10097 100644 --- a/codex-rs/core/src/session/turn.rs +++ b/codex-rs/core/src/session/turn.rs @@ -1362,6 +1362,7 @@ pub(super) fn realtime_text_for_event(msg: &EventMsg) -> Option { | EventMsg::ExecApprovalRequest(_) | EventMsg::RequestPermissions(_) | EventMsg::RequestUserInput(_) + | EventMsg::OptionPicker(_) | EventMsg::DynamicToolCallRequest(_) | EventMsg::DynamicToolCallResponse(_) | EventMsg::GuardianAssessment(_) diff --git a/codex-rs/core/src/state/turn.rs b/codex-rs/core/src/state/turn.rs index 86438ad56a..f93fe9d8b8 100644 --- a/codex-rs/core/src/state/turn.rs +++ b/codex-rs/core/src/state/turn.rs @@ -23,6 +23,7 @@ use crate::session::TurnInputQueue; use crate::session::turn_context::TurnContext; use crate::tasks::AnySessionTask; use codex_protocol::models::AdditionalPermissionProfile; +use codex_protocol::option_picker::OptionPickerResponse; use codex_protocol::protocol::ReviewDecision; use codex_protocol::protocol::TokenUsage; @@ -113,6 +114,7 @@ pub(crate) struct TurnState { pending_approvals: HashMap>, pending_request_permissions: HashMap, pending_user_input: HashMap>, + pending_option_picker: HashMap>, pending_elicitations: HashMap<(String, RequestId), oneshot::Sender>, pending_dynamic_tools: HashMap>, pub(crate) pending_input: TurnInputQueue, @@ -150,6 +152,7 @@ impl TurnState { self.pending_approvals.clear(); self.pending_request_permissions.clear(); self.pending_user_input.clear(); + self.pending_option_picker.clear(); self.pending_elicitations.clear(); self.pending_dynamic_tools.clear(); } @@ -185,6 +188,21 @@ impl TurnState { self.pending_user_input.remove(key) } + pub(crate) fn insert_pending_option_picker( + &mut self, + key: String, + tx: oneshot::Sender, + ) -> Option> { + self.pending_option_picker.insert(key, tx) + } + + pub(crate) fn remove_pending_option_picker( + &mut self, + key: &str, + ) -> Option> { + self.pending_option_picker.remove(key) + } + pub(crate) fn insert_pending_elicitation( &mut self, server_name: String, diff --git a/codex-rs/core/src/tools/handlers/mod.rs b/codex-rs/core/src/tools/handlers/mod.rs index b2cbe62907..9f0db754cf 100644 --- a/codex-rs/core/src/tools/handlers/mod.rs +++ b/codex-rs/core/src/tools/handlers/mod.rs @@ -15,6 +15,7 @@ pub(crate) mod multi_agents; pub(crate) mod multi_agents_common; pub(crate) mod multi_agents_spec; pub(crate) mod multi_agents_v2; +mod option_picker; mod plan; pub(crate) mod plan_spec; mod request_permissions; @@ -61,6 +62,7 @@ pub use mcp::McpHandler; pub use mcp_resource::ListMcpResourceTemplatesHandler; pub use mcp_resource::ListMcpResourcesHandler; pub use mcp_resource::ReadMcpResourceHandler; +pub use option_picker::OptionPickerHandler; pub use plan::PlanHandler; pub use request_permissions::RequestPermissionsHandler; pub use request_plugin_install::RequestPluginInstallHandler; diff --git a/codex-rs/core/src/tools/handlers/option_picker.rs b/codex-rs/core/src/tools/handlers/option_picker.rs new file mode 100644 index 0000000000..3c1f34c983 --- /dev/null +++ b/codex-rs/core/src/tools/handlers/option_picker.rs @@ -0,0 +1,77 @@ +use crate::function_tool::FunctionCallError; +use crate::tools::context::FunctionToolOutput; +use crate::tools::context::ToolInvocation; +use crate::tools::context::ToolPayload; +use crate::tools::context::boxed_tool_output; +use crate::tools::handlers::parse_arguments; +use crate::tools::registry::CoreToolRuntime; +use crate::tools::registry::ToolExecutor; +use codex_protocol::option_picker::OptionPickerArgs; +use codex_tools::REQUEST_OPTION_PICKER_TOOL_NAME; +use codex_tools::ToolName; +use codex_tools::ToolSpec; +use codex_tools::create_request_option_picker_tool; + +pub struct OptionPickerHandler; + +#[async_trait::async_trait] +impl ToolExecutor for OptionPickerHandler { + fn tool_name(&self) -> ToolName { + ToolName::plain(REQUEST_OPTION_PICKER_TOOL_NAME) + } + + fn spec(&self) -> ToolSpec { + create_request_option_picker_tool() + } + + async fn handle( + &self, + invocation: ToolInvocation, + ) -> Result, FunctionCallError> { + let ToolInvocation { + session, + turn, + call_id, + payload, + .. + } = invocation; + + let arguments = match payload { + ToolPayload::Function { arguments } => arguments, + _ => { + return Err(FunctionCallError::RespondToModel(format!( + "{REQUEST_OPTION_PICKER_TOOL_NAME} handler received unsupported payload" + ))); + } + }; + + if turn.session_source.is_non_root_agent() { + return Err(FunctionCallError::RespondToModel( + "request_option_picker can only be used by the root thread".to_string(), + )); + } + + let args: OptionPickerArgs = parse_arguments(&arguments)?; + let response = session + .request_option_picker(turn.as_ref(), call_id, args) + .await + .ok_or_else(|| { + FunctionCallError::RespondToModel(format!( + "{REQUEST_OPTION_PICKER_TOOL_NAME} was cancelled before receiving a response" + )) + })?; + + let content = serde_json::to_string(&response).map_err(|err| { + FunctionCallError::Fatal(format!( + "failed to serialize {REQUEST_OPTION_PICKER_TOOL_NAME} response: {err}" + )) + })?; + + Ok(boxed_tool_output(FunctionToolOutput::from_text( + content, + Some(true), + ))) + } +} + +impl CoreToolRuntime for OptionPickerHandler {} diff --git a/codex-rs/core/src/tools/spec_plan.rs b/codex-rs/core/src/tools/spec_plan.rs index c3656f2434..d922ddc00f 100644 --- a/codex-rs/core/src/tools/spec_plan.rs +++ b/codex-rs/core/src/tools/spec_plan.rs @@ -13,6 +13,7 @@ use crate::tools::handlers::ListAvailablePluginsToInstallHandler; use crate::tools::handlers::ListMcpResourceTemplatesHandler; use crate::tools::handlers::ListMcpResourcesHandler; use crate::tools::handlers::McpHandler; +use crate::tools::handlers::OptionPickerHandler; use crate::tools::handlers::PlanHandler; use crate::tools::handlers::ReadMcpResourceHandler; use crate::tools::handlers::RequestPermissionsHandler; @@ -571,6 +572,9 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut planned_tools.add(RequestUserInputHandler { available_modes: request_user_input_available_modes(features), }); + if features.enabled(Feature::OnboardingInteractiveTools) { + planned_tools.add(OptionPickerHandler); + } if features.enabled(Feature::RequestPermissionsTool) { planned_tools.add(RequestPermissionsHandler); diff --git a/codex-rs/exec/src/lib.rs b/codex-rs/exec/src/lib.rs index 8ca5ba8a9a..f9c842a0d6 100644 --- a/codex-rs/exec/src/lib.rs +++ b/codex-rs/exec/src/lib.rs @@ -1596,6 +1596,18 @@ async fn handle_server_request( ) .await } + ServerRequest::ToolOptionPicker { request_id, params } => { + reject_server_request( + client, + request_id, + &method, + format!( + "request_option_picker is not supported in exec mode for thread `{}`", + params.thread_id + ), + ) + .await + } ServerRequest::DynamicToolCall { request_id, params } => { reject_server_request( client, diff --git a/codex-rs/mcp-server/src/codex_tool_runner.rs b/codex-rs/mcp-server/src/codex_tool_runner.rs index 167d56da5b..4d32912e09 100644 --- a/codex-rs/mcp-server/src/codex_tool_runner.rs +++ b/codex-rs/mcp-server/src/codex_tool_runner.rs @@ -369,6 +369,7 @@ async fn run_codex_tool_session_inner( | EventMsg::ReasoningRawContentDelta(_) | EventMsg::ExitedReviewMode(_) | EventMsg::RequestUserInput(_) + | EventMsg::OptionPicker(_) | EventMsg::RequestPermissions(_) | EventMsg::DynamicToolCallRequest(_) | EventMsg::DynamicToolCallResponse(_) diff --git a/codex-rs/protocol/src/lib.rs b/codex-rs/protocol/src/lib.rs index 63053159c6..94a43ec718 100644 --- a/codex-rs/protocol/src/lib.rs +++ b/codex-rs/protocol/src/lib.rs @@ -21,6 +21,7 @@ pub mod models; pub mod network_policy; pub mod num_format; pub mod openai_models; +pub mod option_picker; pub mod parse_command; pub mod permissions; pub mod plan_tool; diff --git a/codex-rs/protocol/src/option_picker.rs b/codex-rs/protocol/src/option_picker.rs new file mode 100644 index 0000000000..553980a659 --- /dev/null +++ b/codex-rs/protocol/src/option_picker.rs @@ -0,0 +1,58 @@ +use schemars::JsonSchema; +use serde::Deserialize; +use serde::Serialize; +use ts_rs::TS; + +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct OptionPickerOption { + pub label: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct OptionPickerArgs { + pub question: String, + pub options: Vec, + #[serde(default)] + pub allow_multiple: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub submit_label: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub skip_label: Option, +} + +#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "snake_case")] +pub enum OptionPickerAction { + Submit, + Skip, + Dismiss, +} + +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct OptionPickerResponse { + pub action: OptionPickerAction, + pub selected_options: Vec, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub freeform_answer: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct OptionPickerEvent { + /// Responses API call id for the associated tool call, if available. + pub call_id: String, + /// Turn ID that this request belongs to. + pub turn_id: String, + pub question: String, + pub options: Vec, + pub allow_multiple: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub submit_label: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub skip_label: Option, +} diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index b0f34bae4d..3406a0d1c5 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -43,6 +43,7 @@ use crate::models::SandboxEnforcement; use crate::models::WebSearchAction; use crate::num_format::format_with_separators; use crate::openai_models::ReasoningEffort as ReasoningEffortConfig; +use crate::option_picker::OptionPickerResponse; use crate::parse_command::ParsedCommand; use crate::plan_tool::UpdatePlanArgs; use crate::request_permissions::RequestPermissionsEvent; @@ -75,6 +76,7 @@ pub use crate::approvals::NetworkApprovalContext; pub use crate::approvals::NetworkApprovalProtocol; pub use crate::approvals::NetworkPolicyAmendment; pub use crate::approvals::NetworkPolicyRuleAction; +pub use crate::option_picker::OptionPickerEvent; pub use crate::permissions::FileSystemAccessMode; pub use crate::permissions::FileSystemPath; pub use crate::permissions::FileSystemSandboxEntry; @@ -579,6 +581,14 @@ pub enum Op { response: RequestUserInputResponse, }, + /// Resolve a request_option_picker tool call. + OptionPickerResponse { + /// Turn id for the in-flight request. + id: String, + /// User-provided selection. + response: OptionPickerResponse, + }, + /// Resolve a request_permissions tool call. RequestPermissionsResponse { /// Call id for the in-flight request. @@ -728,6 +738,7 @@ impl Op { Self::PatchApproval { .. } => "patch_approval", Self::ResolveElicitation { .. } => "resolve_elicitation", Self::UserInputAnswer { .. } => "user_input_answer", + Self::OptionPickerResponse { .. } => "option_picker_response", Self::RequestPermissionsResponse { .. } => "request_permissions_response", Self::DynamicToolResponse { .. } => "dynamic_tool_response", Self::RefreshMcpServers { .. } => "refresh_mcp_servers", @@ -1246,6 +1257,8 @@ pub enum EventMsg { RequestUserInput(RequestUserInputEvent), + OptionPicker(OptionPickerEvent), + DynamicToolCallRequest(DynamicToolCallRequest), DynamicToolCallResponse(DynamicToolCallResponseEvent), diff --git a/codex-rs/rollout-trace/src/protocol_event.rs b/codex-rs/rollout-trace/src/protocol_event.rs index a862af116c..4f53cde432 100644 --- a/codex-rs/rollout-trace/src/protocol_event.rs +++ b/codex-rs/rollout-trace/src/protocol_event.rs @@ -251,6 +251,7 @@ pub(crate) fn tool_runtime_trace_event(event: &EventMsg) -> Option Option<&'static s | EventMsg::ExecApprovalRequest(_) | EventMsg::RequestPermissions(_) | EventMsg::RequestUserInput(_) + | EventMsg::OptionPicker(_) | EventMsg::DynamicToolCallRequest(_) | EventMsg::DynamicToolCallResponse(_) | EventMsg::ElicitationRequest(_) diff --git a/codex-rs/rollout/src/policy.rs b/codex-rs/rollout/src/policy.rs index b6dbba98f8..d207a74dce 100644 --- a/codex-rs/rollout/src/policy.rs +++ b/codex-rs/rollout/src/policy.rs @@ -191,6 +191,7 @@ fn event_msg_persistence_mode(ev: &EventMsg) -> Option { | EventMsg::ExecApprovalRequest(_) | EventMsg::RequestPermissions(_) | EventMsg::RequestUserInput(_) + | EventMsg::OptionPicker(_) | EventMsg::ElicitationRequest(_) | EventMsg::ApplyPatchApprovalRequest(_) | EventMsg::StreamError(_) diff --git a/codex-rs/tools/src/lib.rs b/codex-rs/tools/src/lib.rs index 7b64776dca..0a6d4ff30e 100644 --- a/codex-rs/tools/src/lib.rs +++ b/codex-rs/tools/src/lib.rs @@ -7,6 +7,7 @@ mod function_call_error; mod image_detail; mod json_schema; mod mcp_tool; +mod option_picker_tool; mod request_plugin_install; mod responses_api; mod tool_call; @@ -36,6 +37,8 @@ pub use json_schema::JsonSchemaType; pub use json_schema::parse_tool_input_schema; pub use mcp_tool::mcp_call_tool_result_output_schema; pub use mcp_tool::parse_mcp_tool; +pub use option_picker_tool::REQUEST_OPTION_PICKER_TOOL_NAME; +pub use option_picker_tool::create_request_option_picker_tool; pub use request_plugin_install::REQUEST_PLUGIN_INSTALL_APPROVAL_KIND_VALUE; pub use request_plugin_install::REQUEST_PLUGIN_INSTALL_PERSIST_ALWAYS_VALUE; pub use request_plugin_install::REQUEST_PLUGIN_INSTALL_PERSIST_KEY; diff --git a/codex-rs/tools/src/option_picker_tool.rs b/codex-rs/tools/src/option_picker_tool.rs new file mode 100644 index 0000000000..67cc7dcac0 --- /dev/null +++ b/codex-rs/tools/src/option_picker_tool.rs @@ -0,0 +1,65 @@ +use crate::JsonSchema; +use crate::ResponsesApiTool; +use crate::ToolSpec; +use std::collections::BTreeMap; + +pub const REQUEST_OPTION_PICKER_TOOL_NAME: &str = "request_option_picker"; + +pub fn create_request_option_picker_tool() -> ToolSpec { + let option_props = BTreeMap::from([ + ( + "label".to_string(), + JsonSchema::string(Some("User-facing option label.".to_string())), + ), + ( + "description".to_string(), + JsonSchema::string(Some( + "Optional short description for the option.".to_string(), + )), + ), + ]); + let properties = BTreeMap::from([ + ( + "question".to_string(), + JsonSchema::string(Some("Question to show the user.".to_string())), + ), + ( + "options".to_string(), + JsonSchema::array( + JsonSchema::object( + option_props, + Some(vec!["label".to_string()]), + Some(false.into()), + ), + Some("Selectable options to show in the picker.".to_string()), + ), + ), + ( + "allowMultiple".to_string(), + JsonSchema::boolean(Some( + "Set true when the user may choose more than one option.".to_string(), + )), + ), + ( + "submitLabel".to_string(), + JsonSchema::string(Some("Optional label for the submit button.".to_string())), + ), + ( + "skipLabel".to_string(), + JsonSchema::string(Some("Optional label for the skip button.".to_string())), + ), + ]); + + ToolSpec::Function(ResponsesApiTool { + name: REQUEST_OPTION_PICKER_TOOL_NAME.to_string(), + description: "Ask the user to choose from a compact list of onboarding options. Use only when setting up Codex from the onboarding tutorial.".to_string(), + strict: false, + defer_loading: None, + parameters: JsonSchema::object( + properties, + Some(vec!["question".to_string(), "options".to_string()]), + Some(false.into()), + ), + output_schema: None, + }) +} diff --git a/codex-rs/tui/src/app/app_server_event_targets.rs b/codex-rs/tui/src/app/app_server_event_targets.rs index 0b2143b429..7736fde596 100644 --- a/codex-rs/tui/src/app/app_server_event_targets.rs +++ b/codex-rs/tui/src/app/app_server_event_targets.rs @@ -15,6 +15,9 @@ pub(super) fn server_request_thread_id(request: &ServerRequest) -> Option { ThreadId::from_string(¶ms.thread_id).ok() } + ServerRequest::ToolOptionPicker { params, .. } => { + ThreadId::from_string(¶ms.thread_id).ok() + } ServerRequest::McpServerElicitationRequest { params, .. } => { ThreadId::from_string(¶ms.thread_id).ok() } diff --git a/codex-rs/tui/src/app/app_server_requests.rs b/codex-rs/tui/src/app/app_server_requests.rs index 1843333023..e5343f3bf6 100644 --- a/codex-rs/tui/src/app/app_server_requests.rs +++ b/codex-rs/tui/src/app/app_server_requests.rs @@ -127,6 +127,12 @@ impl PendingAppServerRequests { ); None } + ServerRequest::ToolOptionPicker { request_id, .. } => { + Some(UnsupportedAppServerRequest { + request_id: request_id.clone(), + message: "Option picker requests are not available in TUI yet.".to_string(), + }) + } ServerRequest::DynamicToolCall { request_id, .. } => { Some(UnsupportedAppServerRequest { request_id: request_id.clone(), @@ -336,7 +342,8 @@ impl PendingAppServerRequests { .mcp_requests .values() .any(|pending_request_id| pending_request_id == request_id), - ServerRequest::DynamicToolCall { .. } + ServerRequest::ToolOptionPicker { .. } + | ServerRequest::DynamicToolCall { .. } | ServerRequest::ChatgptAuthTokensRefresh { .. } | ServerRequest::AttestationGenerate { .. } | ServerRequest::ApplyPatchApproval { .. } diff --git a/codex-rs/tui/src/app/side.rs b/codex-rs/tui/src/app/side.rs index 04831e16e4..5851b1189b 100644 --- a/codex-rs/tui/src/app/side.rs +++ b/codex-rs/tui/src/app/side.rs @@ -85,6 +85,7 @@ impl SideParentStatus { pub(super) fn for_request(request: &ServerRequest) -> Option { match request { ServerRequest::ToolRequestUserInput { .. } => Some(SideParentStatus::NeedsInput), + ServerRequest::ToolOptionPicker { .. } => Some(SideParentStatus::NeedsInput), ServerRequest::CommandExecutionRequestApproval { .. } | ServerRequest::FileChangeRequestApproval { .. } | ServerRequest::McpServerElicitationRequest { .. } diff --git a/codex-rs/tui/src/chatwidget/protocol_requests.rs b/codex-rs/tui/src/chatwidget/protocol_requests.rs index 5b53f44fdf..ab033b4c2f 100644 --- a/codex-rs/tui/src/chatwidget/protocol_requests.rs +++ b/codex-rs/tui/src/chatwidget/protocol_requests.rs @@ -35,7 +35,8 @@ impl ChatWidget { ServerRequest::ToolRequestUserInput { params, .. } => { self.on_request_user_input(params); } - ServerRequest::DynamicToolCall { .. } + ServerRequest::ToolOptionPicker { .. } + | ServerRequest::DynamicToolCall { .. } | ServerRequest::AttestationGenerate { .. } | ServerRequest::ChatgptAuthTokensRefresh { .. } | ServerRequest::ApplyPatchApproval { .. }