use async_trait::async_trait;
use crate::context::tool_data::ToolResultPayload;
use crate::ports::control::CallControl;
use crate::ports::tool::{ToolCallContext, ToolDefinition};
#[async_trait]
pub trait DynamicToolSource: Send + Sync {
fn id(&self) -> &str;
fn version(&self) -> u64 {
0
}
async fn list(&self) -> Result<Vec<ToolDefinition>, SourceError>;
async fn invoke(
&self,
call: &ToolCallContext,
control: &CallControl,
store: Option<&dyn crate::ports::tool::ArtifactStore>,
) -> Result<ToolResultPayload, ToolExecutionError>;
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum SourceError {
#[error("tool source unavailable: {0}")]
Unavailable(String),
#[error("tool source protocol error: {0}")]
Protocol(String),
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ToolExecutionError {
#[error("tool call timed out")]
TimedOut,
#[error("tool call cancelled")]
Cancelled,
#[error("unknown tool: {0}")]
UnknownTool(String),
#[error("tool source unavailable: {0}")]
Unavailable(String),
#[error("tool source protocol error: {0}")]
Protocol(String),
}