(data: SessionData, part: ToolPart)
| 340 | // tool's evolving state. Only triggers a footer update if the currently |
| 341 | // displayed permission was the one that changed. |
| 342 | function syncPermission(data: SessionData, part: ToolPart): FooterOutput | undefined { |
| 343 | data.call.set(key(part.messageID, part.callID), part.state.input) |
| 344 | if (data.permissions.length === 0) { |
| 345 | return undefined |
| 346 | } |
| 347 | |
| 348 | let changed = false |
| 349 | let active = false |
| 350 | data.permissions = data.permissions.map((request, index) => { |
| 351 | if (!request.tool || request.tool.messageID !== part.messageID || request.tool.callID !== part.callID) { |
| 352 | return request |
| 353 | } |
| 354 | |
| 355 | const next = enrichPermission(data, request) |
| 356 | if (next === request) { |
| 357 | return request |
| 358 | } |
| 359 | |
| 360 | changed = true |
| 361 | active ||= index === 0 |
| 362 | return next |
| 363 | }) |
| 364 | |
| 365 | if (!changed || !active) { |
| 366 | return undefined |
| 367 | } |
| 368 | |
| 369 | return { |
| 370 | view: pickSessionView(data), |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // Question tool replies can complete without a matching question.replied event. |
| 375 | // When that happens, drop the recovered pending request tied to this tool call so |
no test coverage detected