use crate::context::ToolContext;
use crate::error::ToolError;
use futures::future::BoxFuture;
pub trait Tool: Send + Sync + 'static {
type Input: Send + 'static;
type Output: Send + 'static;
const NAME: &'static str;
const DESCRIPTION: &'static str;
fn call(
&self,
input: Self::Input,
ctx: &ToolContext,
) -> BoxFuture<'static, Result<Self::Output, ToolError>>;
}
pub trait ToolCodec<T: Tool>: Send + Sync + 'static {
type WireIn: serde::de::DeserializeOwned + schemars::JsonSchema + Send + 'static;
type WireOut: serde::Serialize + schemars::JsonSchema + Send + 'static;
fn decode(wire: Self::WireIn) -> Result<T::Input, ToolError>;
fn encode(native: T::Output) -> Result<Self::WireOut, ToolError>;
}
impl<T> ToolCodec<T> for ()
where
T: Tool,
T::Input: serde::de::DeserializeOwned + schemars::JsonSchema,
T::Output: serde::Serialize + schemars::JsonSchema,
{
type WireIn = T::Input;
type WireOut = T::Output;
fn decode(wire: Self::WireIn) -> Result<T::Input, ToolError> {
Ok(wire)
}
fn encode(native: T::Output) -> Result<Self::WireOut, ToolError> {
Ok(native)
}
}