use std::{future::Future, pin::Pin};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{ToolContext, ToolDescriptor, ToolError};
#[cfg(not(target_arch = "wasm32"))]
pub type ToolFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[cfg(target_arch = "wasm32")]
pub type ToolFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ToolOutput {
pub value: Value,
pub model_visible: bool,
}
impl ToolOutput {
pub const fn model_visible(value: Value) -> Self {
Self {
value,
model_visible: true,
}
}
}
pub trait Tool: Send + Sync {
fn descriptor(&self) -> &ToolDescriptor;
fn invoke(
&self,
input: Value,
context: ToolContext,
) -> ToolFuture<'_, Result<ToolOutput, ToolError>>;
}