Files
zesdex/apps/infrastructure/src/tools/executor.rs
T

45 lines
1.1 KiB
Rust
Raw Normal View History

use std::future::Future;
use anyhow::Result;
use zesdex_application::agent::ToolExecutor;
use crate::tools::{all_tools, Tool, ToolCtx};
pub struct InfrastructureToolExecutor {
ctx: ToolCtx,
tools: Vec<Box<dyn Tool>>,
}
impl InfrastructureToolExecutor {
pub fn new(ctx: ToolCtx) -> Self {
Self {
ctx,
tools: all_tools(),
}
}
}
impl ToolExecutor for InfrastructureToolExecutor {
fn execute(
&self,
tool_name: &str,
args: &serde_json::Value,
) -> impl Future<Output = Result<String>> + Send {
// Find the tool by name
let tool_opt = self.tools.iter().find(|t| t.name() == tool_name);
let ctx = self.ctx.clone();
let args = args.clone();
async move {
match tool_opt {
Some(tool) => {
tokio::task::block_in_place(move || {
tool.run(&ctx, &args)
})
}
None => {
anyhow::bail!("Unknown tool: {}", tool_name)
}
}
}
}
}