aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
49
akode-rs/tools/src/catalog_tool_message.rs
Normal file
49
akode-rs/tools/src/catalog_tool_message.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
//! Applies sparse catalog overrides while preserving bundled tool transport requirements.
|
||||
//! Invalid parameters retain the bundled schema; other tool fields remain harness-owned.
|
||||
|
||||
use crate::ResponsesApiTool;
|
||||
use crate::parse_catalog_tool_parameters;
|
||||
use akode_protocol::openai_models::ToolMessage;
|
||||
|
||||
/// Apply catalog descriptions and parameters without changing the tool's identity or transport.
|
||||
pub fn with_catalog_tool_message(
|
||||
mut tool: ResponsesApiTool,
|
||||
messages: Option<&ToolMessage>,
|
||||
) -> ResponsesApiTool {
|
||||
let Some(messages) = messages else {
|
||||
return tool;
|
||||
};
|
||||
if let Some(description) = &messages.description {
|
||||
tool.description.clone_from(description);
|
||||
}
|
||||
if let Some(parameters) = &messages.parameters {
|
||||
let parameters = parse_catalog_tool_parameters(parameters).and_then(|mut parameters| {
|
||||
if let Some(properties) = &tool.parameters.properties {
|
||||
for (name, bundled_property) in properties.iter() {
|
||||
if bundled_property.encrypted == Some(true) {
|
||||
let property = parameters
|
||||
.properties
|
||||
.as_mut()
|
||||
.and_then(|properties| properties.get_mut(name))
|
||||
.ok_or("schema omits an encrypted parameter")?;
|
||||
property.encrypted = Some(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(parameters)
|
||||
});
|
||||
match parameters {
|
||||
Ok(parameters) => tool.parameters = parameters,
|
||||
Err(reason) => tracing::warn!(
|
||||
tool = %tool.name,
|
||||
reason,
|
||||
"Invalid catalog tool parameters; using bundled parameters"
|
||||
),
|
||||
}
|
||||
}
|
||||
tool
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "catalog_tool_message_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user