agentmux_srv/server/
tool_handlers.rs1use std::sync::Arc;
8
9use crate::backend::rpc::engine::WshRpcEngine;
10use crate::backend::rpc_types::{
11 CommandGetToolStatusData, CommandInstallToolData, GetToolStatusResult, InstallFailure,
12 InstallToolResult,
13 COMMAND_GET_TOOL_STATUS, COMMAND_INSTALL_TOOL,
14};
15use crate::backend::tool_store;
16
17use super::AppState;
18
19pub fn register_tool_handlers(engine: &Arc<WshRpcEngine>, state: &AppState) {
20 let http_client = state.http_client.clone();
21
22 engine.register_typed(
24 COMMAND_GET_TOOL_STATUS,
25 move |_req: CommandGetToolStatusData, _ctx| async move {
26 Ok(GetToolStatusResult { tools: tool_store::get_tool_statuses() })
27 },
28 );
29
30 engine.register_typed(
32 COMMAND_INSTALL_TOOL,
33 move |cmd: CommandInstallToolData, _ctx| {
34 let client = http_client.clone();
35 async move {
36
37 let mut installed = Vec::new();
38 let mut failed = Vec::new();
39
40 for id in &cmd.tool_ids {
41 match tool_store::install_tool(id, &client).await {
42 Ok(path) => {
43 tracing::info!(tool = %id, path = %path, "tool installed");
44 installed.push(id.clone());
45 }
46 Err(e) => {
47 tracing::warn!(tool = %id, error = %e, "tool install failed");
48 failed.push(InstallFailure {
49 id: id.clone(),
50 error: e,
51 });
52 }
53 }
54 }
55
56 Ok(InstallToolResult { installed, failed })
57 }
58 },
59 );
60}