use serde::{Deserialize, Serialize};
use crate::wasm_compat::{WasmCompatSend, WasmCompatSync};
use super::{IntoToolOutput, ToolExecutionError};
pub trait PortableTool: Sized + WasmCompatSend + WasmCompatSync {
const NAME: &'static str;
type Args: for<'de> Deserialize<'de> + WasmCompatSend + WasmCompatSync;
type Output: IntoToolOutput + WasmCompatSend;
type Error: std::error::Error + WasmCompatSend + WasmCompatSync + 'static;
fn description(&self) -> String;
fn parameters(&self) -> serde_json::Value;
fn map_error(&self, error: Self::Error) -> ToolExecutionError {
ToolExecutionError::from_error(error)
}
fn call(
&self,
arguments: Self::Args,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend;
}
pub trait PortableToolEmbedding: PortableTool {
type InitError: std::error::Error + WasmCompatSend + WasmCompatSync + 'static;
type Context: for<'de> Deserialize<'de> + Serialize;
type State: WasmCompatSend;
fn embedding_docs(&self) -> Vec<String>;
fn context(&self) -> Self::Context;
fn init(state: Self::State, context: Self::Context) -> Result<Self, Self::InitError>;
}