MCPcopy
hub / github.com/TanStack/ai / addToolApprovalResponse

Method addToolApprovalResponse

packages/ai-client/src/chat-client.ts:1260–1298  ·  view source on GitHub ↗

* Respond to a tool approval request

(response: {
    id: string // approval.id, not toolCallId
    approved: boolean
  })

Source from the content-addressed store, hash-verified

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

Callers 13

addToolApprovalResponseFunction · 0.45
addToolApprovalResponseFunction · 0.45
use-chat.test.tsFile · 0.45
addToolApprovalResponseFunction · 0.45
use-chat.test.tsFile · 0.45
devtools.test.tsFile · 0.45
useChatFunction · 0.45
use-chat.test.tsFile · 0.45
useChatFunction · 0.45
use-chat.test.tsFile · 0.45
addToolApprovalResponseFunction · 0.45

Calls 5

queuePostStreamActionMethod · 0.95
checkForContinuationMethod · 0.95
toolApprovalRespondedMethod · 0.80
getMessagesMethod · 0.45
emitSnapshotMethod · 0.45

Tested by

no test coverage detected