( tool: Tool, toolCall: ToolCall, extras: ToolExtras, )
| 233 | // Returns an error context item if the tool call fails |
| 234 | // Note: Edit tool is handled on client |
| 235 | export async function callTool( |
| 236 | tool: Tool, |
| 237 | toolCall: ToolCall, |
| 238 | extras: ToolExtras, |
| 239 | ): Promise<{ |
| 240 | contextItems: ContextItem[]; |
| 241 | errorMessage: string | undefined; |
| 242 | errorReason?: ContinueErrorReason; |
| 243 | mcpUiState?: McpUiState; |
| 244 | }> { |
| 245 | try { |
| 246 | const args = safeParseToolCallArgs(toolCall); |
| 247 | const { contextItems, mcpUiState } = tool.uri |
| 248 | ? await callToolFromUri(tool.uri, args, extras) |
| 249 | : { |
| 250 | contextItems: await callBuiltInTool(tool.function.name, args, extras), |
| 251 | }; |
| 252 | if (tool.faviconUrl) { |
| 253 | contextItems.forEach((item) => { |
| 254 | item.icon = tool.faviconUrl; |
| 255 | }); |
| 256 | } |
| 257 | |
| 258 | return { |
| 259 | contextItems, |
| 260 | errorMessage: undefined, |
| 261 | mcpUiState, |
| 262 | }; |
| 263 | } catch (e) { |
| 264 | let errorMessage = `${e}`; |
| 265 | let errorReason: ContinueErrorReason | undefined; |
| 266 | |
| 267 | if (e instanceof ContinueError) { |
| 268 | errorMessage = e.message; |
| 269 | errorReason = e.reason; |
| 270 | } else if (e instanceof Error) { |
| 271 | errorMessage = e.message; |
| 272 | } |
| 273 | |
| 274 | return { |
| 275 | contextItems: [], |
| 276 | errorMessage, |
| 277 | errorReason, |
| 278 | }; |
| 279 | } |
| 280 | } |
no test coverage detected