(
&self,
args: serde_json::Value,
ctx: ToolContext,
)
| 79 | } |
| 80 | |
| 81 | async fn execute( |
| 82 | &self, |
| 83 | args: serde_json::Value, |
| 84 | ctx: ToolContext, |
| 85 | ) -> Result<ToolResult, ToolError> { |
| 86 | let params: BatchParams = serde_json::from_value(args) |
| 87 | .map_err(|e| ToolError::InvalidArguments(format!("Invalid parameters: {}", e)))?; |
| 88 | |
| 89 | let total_calls = params.tool_calls.len(); |
| 90 | let tool_calls: Vec<_> = params.tool_calls.into_iter().take(MAX_BATCH_SIZE).collect(); |
| 91 | let discarded_count = total_calls.saturating_sub(MAX_BATCH_SIZE); |
| 92 | |
| 93 | if tool_calls.is_empty() { |
| 94 | return Err(ToolError::ValidationError( |
| 95 | "Provide at least one tool call".to_string(), |
| 96 | )); |
| 97 | } |
| 98 | |
| 99 | let registry = match &ctx.registry { |
| 100 | Some(r) => r.clone(), |
| 101 | None => { |
| 102 | return Err(ToolError::ExecutionError( |
| 103 | "Tool registry not available. Batch execution requires registry access." |
| 104 | .to_string(), |
| 105 | )); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | let mut futures: Vec<BatchFuture> = Vec::new(); |
| 110 | |
| 111 | for call in tool_calls { |
| 112 | if DISALLOWED_TOOLS.contains(&call.tool.as_str()) { |
| 113 | let tool_name = call.tool.clone(); |
| 114 | let err_msg = format!( |
| 115 | "Tool '{}' is not allowed in batch. Disallowed: {}", |
| 116 | tool_name, |
| 117 | DISALLOWED_TOOLS.join(", ") |
| 118 | ); |
| 119 | futures.push(Box::pin(async move { |
| 120 | BatchResult { |
| 121 | tool: tool_name, |
| 122 | success: false, |
| 123 | output: None, |
| 124 | title: None, |
| 125 | error: Some(err_msg), |
| 126 | metadata: None, |
| 127 | attachment: None, |
| 128 | } |
| 129 | }) as BatchFuture); |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | let registry = registry.clone(); |
| 134 | let tool_name = call.tool.clone(); |
| 135 | let tool_params = call.parameters.clone(); |
| 136 | let ctx_clone = ctx.clone(); |
| 137 | let session_id = ctx.session_id.clone(); |
| 138 | let message_id = ctx.message_id.clone(); |
nothing calls this directly
no test coverage detected