use std::fmt;
use std::future::Future;
use std::pin::Pin;
pub type ToolResult<'a> = Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>;
#[derive(Debug)]
pub enum ToolError {
NotFound(String),
ExecutionFailed(String),
PermissionDenied(String),
}
impl fmt::Display for ToolError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ToolError::NotFound(msg) => write!(f, "not found: {msg}"),
ToolError::ExecutionFailed(msg) => write!(f, "execution failed: {msg}"),
ToolError::PermissionDenied(msg) => write!(f, "permission denied: {msg}"),
}
}
}
impl std::error::Error for ToolError {}
pub trait Tool: Send + Sync {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn input_schema(&self) -> serde_json::Value;
fn execute(&self, input: serde_json::Value) -> ToolResult<'_>;
}