2026-07-21 06:24:20 +07:00
|
|
|
use crate::tools::{all_tools, Tool, ToolCtx};
|
2026-08-27 22:10:28 +07:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use std::future::Future;
|
|
|
|
|
use zesdex_application::agent::ToolExecutor;
|
2026-07-21 06:24:20 +07:00
|
|
|
|
|
|
|
|
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();
|
2026-08-27 22:10:28 +07:00
|
|
|
|
2026-07-21 06:24:20 +07:00
|
|
|
async move {
|
|
|
|
|
match tool_opt {
|
2026-08-27 22:10:28 +07:00
|
|
|
Some(tool) => tokio::task::block_in_place(move || tool.run(&ctx, &args)),
|
2026-07-21 06:24:20 +07:00
|
|
|
None => {
|
|
|
|
|
anyhow::bail!("Unknown tool: {}", tool_name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|