| 183 | } |
| 184 | |
| 185 | pub async fn execute(&self, call: ToolCall) -> ToolResult { |
| 186 | let tool = call.tool; |
| 187 | let result = match tool { |
| 188 | ToolName::ReadFile => self.read_file(&call.input).await, |
| 189 | ToolName::WriteFile => self.write_file(&call.input).await, |
| 190 | ToolName::PatchFile => self.patch_file(&call.input).await, |
| 191 | ToolName::ListDir => self.list_dir(&call.input).await, |
| 192 | ToolName::SearchFiles => self.search_files(&call.input).await, |
| 193 | ToolName::RunCommand => self.run_command(&call.input).await, |
| 194 | ToolName::WebSearch => self.web_search(&call.input).await, |
| 195 | }; |
| 196 | |
| 197 | match result { |
| 198 | Ok(output) => ToolResult { |
| 199 | tool, |
| 200 | output, |
| 201 | is_error: false, |
| 202 | }, |
| 203 | Err(error) => ToolResult { |
| 204 | tool, |
| 205 | output: error.to_string(), |
| 206 | is_error: true, |
| 207 | }, |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | async fn read_file(&self, input: &serde_json::Value) -> AppResult<String> { |
| 212 | let path_str = input["path"] |