mirror of
https://github.com/openai/codex.git
synced 2026-05-04 13:21:54 +03:00
## Why This continues the `codex-tools` migration by moving one more piece of generic tool-definition bookkeeping out of `codex-core`. The earlier extraction steps moved shared schema parsing into `codex-tools`, but `core/src/tools/spec.rs` still had to supply tool names separately and perform ad hoc rewrites for deferred MCP aliases. That meant the crate boundary was still awkward: the parsed shape coming back from `codex-tools` was missing part of the definition that `codex-core` ultimately needs to assemble a `ResponsesApiTool`. This change introduces a named `ToolDefinition` in `codex-tools` so both MCP tools and dynamic tools cross the crate boundary in the same reusable model. `codex-core` still owns the final `ResponsesApiTool` assembly, but less of the generic tool-definition shaping logic stays behind in `core`. ## What changed - replaced `ParsedToolDefinition` with a named `ToolDefinition` in `codex-rs/tools/src/tool_definition.rs` - added `codex-rs/tools/src/tool_definition_tests.rs` for `renamed()` and `into_deferred()` - updated `parse_dynamic_tool()` and `parse_mcp_tool()` to return `ToolDefinition` - simplified `codex-rs/core/src/tools/spec.rs` so it adapts `ToolDefinition` into `ResponsesApiTool` instead of rewriting names and deferred fields inline - updated parser tests and `codex-rs/tools/README.md` to reflect the named tool-definition model ## Test plan - `cargo test -p codex-tools` - `cargo test -p codex-core --lib tools::spec::`
71 lines
2.1 KiB
Rust
71 lines
2.1 KiB
Rust
use super::parse_dynamic_tool;
|
|
use crate::JsonSchema;
|
|
use crate::ToolDefinition;
|
|
use codex_protocol::dynamic_tools::DynamicToolSpec;
|
|
use pretty_assertions::assert_eq;
|
|
use std::collections::BTreeMap;
|
|
|
|
#[test]
|
|
fn parse_dynamic_tool_sanitizes_input_schema() {
|
|
let tool = DynamicToolSpec {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: serde_json::json!({
|
|
"properties": {
|
|
"id": {
|
|
"description": "Ticket identifier"
|
|
}
|
|
}
|
|
}),
|
|
defer_loading: false,
|
|
};
|
|
|
|
assert_eq!(
|
|
parse_dynamic_tool(&tool).expect("parse dynamic tool"),
|
|
ToolDefinition {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: JsonSchema::Object {
|
|
properties: BTreeMap::from([(
|
|
"id".to_string(),
|
|
JsonSchema::String {
|
|
description: Some("Ticket identifier".to_string()),
|
|
},
|
|
)]),
|
|
required: None,
|
|
additional_properties: None,
|
|
},
|
|
output_schema: None,
|
|
defer_loading: false,
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_dynamic_tool_preserves_defer_loading() {
|
|
let tool = DynamicToolSpec {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: serde_json::json!({
|
|
"type": "object",
|
|
"properties": {}
|
|
}),
|
|
defer_loading: true,
|
|
};
|
|
|
|
assert_eq!(
|
|
parse_dynamic_tool(&tool).expect("parse dynamic tool"),
|
|
ToolDefinition {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: JsonSchema::Object {
|
|
properties: BTreeMap::new(),
|
|
required: None,
|
|
additional_properties: None,
|
|
},
|
|
output_schema: None,
|
|
defer_loading: true,
|
|
}
|
|
);
|
|
}
|