mirror of
https://github.com/openai/codex.git
synced 2026-04-30 19:32:04 +03:00
fix(core): preserve tool_params for elicitations (#14769)
- [x] Preserve tool_params keys.
This commit is contained in:
@@ -156,6 +156,7 @@ pub(crate) struct ToolSuggestionRequest {
|
||||
struct McpToolApprovalDisplayParam {
|
||||
name: String,
|
||||
value: Value,
|
||||
display_name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -423,6 +424,7 @@ fn parse_tool_approval_display_params(meta: Option<&Value>) -> Vec<McpToolApprov
|
||||
.map(|(name, value)| McpToolApprovalDisplayParam {
|
||||
name: name.clone(),
|
||||
value: value.clone(),
|
||||
display_name: name.clone(),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
@@ -437,9 +439,18 @@ fn parse_tool_approval_display_param(value: &Value) -> Option<McpToolApprovalDis
|
||||
if name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let display_name = value
|
||||
.get("display_name")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or(name)
|
||||
.trim();
|
||||
if display_name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(McpToolApprovalDisplayParam {
|
||||
name: name.to_string(),
|
||||
value: value.get("value")?.clone(),
|
||||
display_name: display_name.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -472,7 +483,7 @@ fn format_tool_approval_display_message(
|
||||
fn format_tool_approval_display_param_line(param: &McpToolApprovalDisplayParam) -> String {
|
||||
format!(
|
||||
"{}: {}",
|
||||
param.name,
|
||||
param.display_name,
|
||||
format_tool_approval_display_param_value(¶m.value)
|
||||
)
|
||||
}
|
||||
@@ -1668,7 +1679,7 @@ mod tests {
|
||||
fn tool_approval_meta(
|
||||
persist_modes: &[&str],
|
||||
tool_params: Option<Value>,
|
||||
tool_params_display: Option<Vec<(&str, Value)>>,
|
||||
tool_params_display: Option<Vec<(&str, Value, &str)>>,
|
||||
) -> Option<Value> {
|
||||
let mut meta = serde_json::Map::from_iter([(
|
||||
APPROVAL_META_KIND_KEY.to_string(),
|
||||
@@ -1694,10 +1705,11 @@ mod tests {
|
||||
Value::Array(
|
||||
tool_params_display
|
||||
.into_iter()
|
||||
.map(|(name, value)| {
|
||||
.map(|(name, value, display_name)| {
|
||||
serde_json::json!({
|
||||
"name": name,
|
||||
"value": value,
|
||||
"display_name": display_name,
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
@@ -1961,8 +1973,16 @@ mod tests {
|
||||
"alpha": 1,
|
||||
})),
|
||||
Some(vec![
|
||||
("Calendar", Value::String("primary".to_string())),
|
||||
("Title", Value::String("Roadmap review".to_string())),
|
||||
(
|
||||
"calendar_id",
|
||||
Value::String("primary".to_string()),
|
||||
"Calendar",
|
||||
),
|
||||
(
|
||||
"title",
|
||||
Value::String("Roadmap review".to_string()),
|
||||
"Title",
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
@@ -1973,12 +1993,14 @@ mod tests {
|
||||
request.approval_display_params,
|
||||
vec![
|
||||
McpToolApprovalDisplayParam {
|
||||
name: "Calendar".to_string(),
|
||||
name: "calendar_id".to_string(),
|
||||
value: Value::String("primary".to_string()),
|
||||
display_name: "Calendar".to_string(),
|
||||
},
|
||||
McpToolApprovalDisplayParam {
|
||||
name: "Title".to_string(),
|
||||
name: "title".to_string(),
|
||||
value: Value::String("Roadmap review".to_string()),
|
||||
display_name: "Title".to_string(),
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -2348,13 +2370,26 @@ mod tests {
|
||||
"ignored_after_limit": "fourth param",
|
||||
})),
|
||||
Some(vec![
|
||||
("Calendar", Value::String("primary".to_string())),
|
||||
("Title", Value::String("Roadmap review".to_string())),
|
||||
(
|
||||
"Notes",
|
||||
Value::String("This is a deliberately long note that should truncate before it turns the approval body into a giant wall of text in the TUI overlay.".to_string()),
|
||||
"calendar_id",
|
||||
Value::String("primary".to_string()),
|
||||
"Calendar",
|
||||
),
|
||||
(
|
||||
"title",
|
||||
Value::String("Roadmap review".to_string()),
|
||||
"Title",
|
||||
),
|
||||
(
|
||||
"notes",
|
||||
Value::String("This is a deliberately long note that should truncate before it turns the approval body into a giant wall of text in the TUI overlay.".to_string()),
|
||||
"Notes",
|
||||
),
|
||||
(
|
||||
"ignored_after_limit",
|
||||
Value::String("fourth param".to_string()),
|
||||
"Ignored",
|
||||
),
|
||||
("Ignored", Value::String("fourth param".to_string())),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user