* Respond to a tool approval request
(response: {
id: string // approval.id, not toolCallId
approved: boolean
})
| 1258 | * Respond to a tool approval request |
| 1259 | */ |
| 1260 | async addToolApprovalResponse(response: { |
| 1261 | id: string // approval.id, not toolCallId |
| 1262 | approved: boolean |
| 1263 | }): Promise<void> { |
| 1264 | // Find the tool call ID from the approval ID |
| 1265 | const messages = this.processor.getMessages() |
| 1266 | let foundToolCallId: string | undefined |
| 1267 | |
| 1268 | for (const msg of messages) { |
| 1269 | const toolCallPart = msg.parts.find( |
| 1270 | (p: MessagePart): p is ToolCallPart => |
| 1271 | p.type === 'tool-call' && p.approval?.id === response.id, |
| 1272 | ) |
| 1273 | if (toolCallPart) { |
| 1274 | foundToolCallId = toolCallPart.id |
| 1275 | break |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | if (foundToolCallId) { |
| 1280 | this.events.toolApprovalResponded( |
| 1281 | response.id, |
| 1282 | foundToolCallId, |
| 1283 | response.approved, |
| 1284 | ) |
| 1285 | } |
| 1286 | |
| 1287 | // Add response via processor |
| 1288 | this.processor.addToolApprovalResponse(response.id, response.approved) |
| 1289 | this.devtoolsBridge.emitSnapshot() |
| 1290 | |
| 1291 | // If stream is in progress, queue continuation check for after it ends |
| 1292 | if (this.isLoading) { |
| 1293 | this.queuePostStreamAction(() => this.checkForContinuation()) |
| 1294 | return |
| 1295 | } |
| 1296 | |
| 1297 | await this.checkForContinuation() |
| 1298 | } |
| 1299 | |
| 1300 | /** |
| 1301 | * Queue an action to be executed after the current stream ends |
no test coverage detected