mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Extract request_user_input normalization into codex-tools (#16503)
## Why This is another incremental step in the `codex-core` -> `codex-tools` migration called out in `AGENTS.md`: keep pure tool-definition and wire-shaping logic out of `codex-core` so the core crate can stay focused on runtime orchestration. `request_user_input` already had its spec and mode-availability helpers in `codex-tools` after #16471. The remaining argument validation and normalization still lived in the core runtime handler, which left that tool split across the two crates. ## What Changed - Export `REQUEST_USER_INPUT_TOOL_NAME` and `normalize_request_user_input_args()` from `codex-rs/tools/src/request_user_input_tool.rs`. - Use that `codex-tools` surface from `codex-rs/core/src/tools/spec.rs` and `codex-rs/core/src/tools/handlers/request_user_input.rs`. - Keep the core handler responsible for payload parsing, session dispatch, cancellation handling, and response serialization. This is intended to be a straight refactor with no behavior change. ## Verification - `cargo test -p codex-tools` - `cargo test -p codex-core request_user_input`
This commit is contained in:
committed by
GitHub
Unverified
parent
7c1c633f3f
commit
1b5a16f05e
@@ -7,6 +7,8 @@ use crate::tools::registry::ToolHandler;
|
||||
use crate::tools::registry::ToolKind;
|
||||
use async_trait::async_trait;
|
||||
use codex_protocol::request_user_input::RequestUserInputArgs;
|
||||
use codex_tools::REQUEST_USER_INPUT_TOOL_NAME;
|
||||
use codex_tools::normalize_request_user_input_args;
|
||||
use codex_tools::request_user_input_unavailable_message;
|
||||
|
||||
pub struct RequestUserInputHandler {
|
||||
@@ -33,9 +35,9 @@ impl ToolHandler for RequestUserInputHandler {
|
||||
let arguments = match payload {
|
||||
ToolPayload::Function { arguments } => arguments,
|
||||
_ => {
|
||||
return Err(FunctionCallError::RespondToModel(
|
||||
"request_user_input handler received unsupported payload".to_string(),
|
||||
));
|
||||
return Err(FunctionCallError::RespondToModel(format!(
|
||||
"{REQUEST_USER_INPUT_TOOL_NAME} handler received unsupported payload"
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -46,31 +48,21 @@ impl ToolHandler for RequestUserInputHandler {
|
||||
return Err(FunctionCallError::RespondToModel(message));
|
||||
}
|
||||
|
||||
let mut args: RequestUserInputArgs = parse_arguments(&arguments)?;
|
||||
let missing_options = args
|
||||
.questions
|
||||
.iter()
|
||||
.any(|question| question.options.as_ref().is_none_or(Vec::is_empty));
|
||||
if missing_options {
|
||||
return Err(FunctionCallError::RespondToModel(
|
||||
"request_user_input requires non-empty options for every question".to_string(),
|
||||
));
|
||||
}
|
||||
for question in &mut args.questions {
|
||||
question.is_other = true;
|
||||
}
|
||||
let args: RequestUserInputArgs = parse_arguments(&arguments)?;
|
||||
let args =
|
||||
normalize_request_user_input_args(args).map_err(FunctionCallError::RespondToModel)?;
|
||||
let response = session
|
||||
.request_user_input(turn.as_ref(), call_id, args)
|
||||
.await
|
||||
.ok_or_else(|| {
|
||||
FunctionCallError::RespondToModel(
|
||||
"request_user_input was cancelled before receiving a response".to_string(),
|
||||
)
|
||||
FunctionCallError::RespondToModel(format!(
|
||||
"{REQUEST_USER_INPUT_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_user_input response: {err}"
|
||||
"failed to serialize {REQUEST_USER_INPUT_TOOL_NAME} response: {err}"
|
||||
))
|
||||
})?;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use codex_protocol::openai_models::ApplyPatchToolType;
|
||||
use codex_protocol::openai_models::ConfigShellToolType;
|
||||
use codex_tools::CommandToolOptions;
|
||||
use codex_tools::DiscoverableTool;
|
||||
use codex_tools::REQUEST_USER_INPUT_TOOL_NAME;
|
||||
use codex_tools::ShellToolOptions;
|
||||
use codex_tools::SpawnAgentToolOptions;
|
||||
use codex_tools::TOOL_SEARCH_DEFAULT_LIMIT;
|
||||
@@ -344,7 +345,7 @@ pub(crate) fn build_specs_with_discoverable_tools(
|
||||
/*supports_parallel_tool_calls*/ false,
|
||||
config.code_mode_enabled,
|
||||
);
|
||||
builder.register_handler("request_user_input", request_user_input_handler);
|
||||
builder.register_handler(REQUEST_USER_INPUT_TOOL_NAME, request_user_input_handler);
|
||||
}
|
||||
|
||||
if config.request_permissions_tool_enabled {
|
||||
|
||||
Reference in New Issue
Block a user