use super::description::ToolDescription;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
pub trait ToolError {}
#[async_trait]
pub trait Tool {
type Input: DeserializeOwned + Send + Sync;
type Output: Serialize;
type Error: std::fmt::Debug + std::error::Error + ToolError + From<serde_yaml::Error>;
async fn invoke_typed(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>;
fn description(&self) -> ToolDescription;
async fn invoke(&self, input: serde_yaml::Value) -> Result<serde_yaml::Value, Self::Error> {
let input = serde_yaml::from_value(input)
.map_err(<serde_yaml::Error as Into<Self::Error>>::into)?;
let output = self.invoke_typed(&input).await?;
Ok(serde_yaml::to_value(output)?)
}
fn matches(&self, name: &str) -> bool {
self.description().name == name
}
}