use serde_json::{Value, json};
use crate::KitError;
use crate::generation::{AllowedToolMode, ProviderToolSpec, ToolChoice};
use crate::providers::anthropic::tools::AnthropicHostedPlanner;
pub(super) fn tool_choice_to_value(choice: &ToolChoice) -> Value {
match choice {
ToolChoice::Auto => json!({"type": "auto"}),
ToolChoice::None => json!({"type": "none"}),
ToolChoice::Required | ToolChoice::Any => json!({"type": "any"}),
ToolChoice::Tool { name } => json!({"type": "tool", "name": name.trim()}),
ToolChoice::Allowed { mode, .. } => match mode {
AllowedToolMode::Auto => json!({"type": "auto"}),
AllowedToolMode::Required => json!({"type": "any"}),
},
}
}
pub(super) fn tool_spec_to_value(tool: &ProviderToolSpec) -> Result<Value, KitError> {
match tool {
ProviderToolSpec::Function(tool) => Ok(json!({
"name": tool.name(),
"description": tool.description(),
"input_schema": tool.input_schema().schema(),
"strict": true,
})),
ProviderToolSpec::Hosted(tool) => hosted_tool_to_value(tool),
}
}
fn hosted_tool_to_value(declaration: &crate::hosted::HostedTool) -> Result<Value, KitError> {
AnthropicHostedPlanner::new().render_declaration(declaration)
}