(call: ChatToolCall)
| 200 | |
| 201 | // Execute tool. |
| 202 | async executeTool(call: ChatToolCall) { |
| 203 | if (this.pending) |
| 204 | throw new Error('Can not execute tool when there is pending message.'); |
| 205 | this.pending = true; |
| 206 | // Get tool and execute it. |
| 207 | let tool: Tool; |
| 208 | let result: ToolExecutionResult; |
| 209 | try { |
| 210 | tool = toolManager.getToolByName(call.name); |
| 211 | result = await tool.execute(this.aborter.signal, call.arg); |
| 212 | } catch(error) { |
| 213 | if (error.name != 'AbortError') |
| 214 | this.onExecuteToolError.emit(error); |
| 215 | return; |
| 216 | } finally { |
| 217 | this.pending = false; |
| 218 | } |
| 219 | // Some tool does not handle abort signal and we have to manually abort |
| 220 | // after tool finishes execution. |
| 221 | if (this.isAborted()) { |
| 222 | this.onExecuteToolError.emit(new AbortError()); |
| 223 | return; |
| 224 | } |
| 225 | // Send the result to API and wait for response. |
| 226 | await this.sendMessage({ |
| 227 | role: ChatRole.Tool, |
| 228 | content: result.resultForModel, |
| 229 | toolName: tool.name, |
| 230 | toolResult: result.resultForHuman, |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | // Called when user clicks the reload button, should usually resend last user |
| 235 | // message or regenerate last bot message. |
nothing calls this directly
no test coverage detected