use serde_json::Value;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct ToolDescription {
pub name: String,
pub description: String,
pub input_schema: Value,
}
impl ToolDescription {
#[must_use]
pub fn new(
name: impl Into<String>,
description: impl Into<String>,
input_schema: Value,
) -> Self {
Self {
name: name.into(),
description: description.into(),
input_schema,
}
}
}
#[derive(Debug, Default, Clone)]
pub struct ToolRegistry {
tools: Vec<ToolDescription>,
}
impl ToolRegistry {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn register(&mut self, tool: ToolDescription) {
if let Some(existing) = self.tools.iter_mut().find(|t| t.name == tool.name) {
*existing = tool;
} else {
self.tools.push(tool);
}
}
#[must_use]
pub fn list(&self) -> &[ToolDescription] {
&self.tools
}
#[must_use]
pub fn get(&self, name: &str) -> Option<&ToolDescription> {
self.tools.iter().find(|t| t.name == name)
}
}