use std::future::Future;
use std::pin::Pin;
use serde_json::Value;
use crate::types::io::FunctionTool;
#[derive(Debug, Clone)]
pub struct ToolOutput {
pub call_id: String,
pub output: String,
}
#[derive(Debug, thiserror::Error)]
pub enum ToolError {
#[error("execution failed: {0}")]
Execution(String),
#[error("invalid tool config: {0}")]
Config(String),
}
pub trait ToolHandler: Send + Sync {
#[must_use]
fn tool_type(&self) -> super::registry::ToolType;
fn validate(&self, param: &Value) -> Result<(), ToolError>;
#[must_use]
fn normalize(&self, param: &Value) -> Vec<FunctionTool>;
}
pub trait GatewayExecutor: ToolHandler + 'static {
fn execute(
&self,
call_id: &str,
tool_name: &str,
arguments: &str,
config: &Value,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + '_>>;
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;
fn _assert_gateway_executor_dyn_compatible(_: Arc<dyn GatewayExecutor>) {}
}