* Walk messages and build tool_use_id → tool_name from assistant tool_use * blocks. tool_use always precedes its tool_result (model calls, then result * arrives), so by the time budget enforcement sees a result, its name is known.
(messages: Message[])
| 534 | * arrives), so by the time budget enforcement sees a result, its name is known. |
| 535 | */ |
| 536 | function buildToolNameMap(messages: Message[]): Map<string, string> { |
| 537 | const map = new Map<string, string>() |
| 538 | for (const message of messages) { |
| 539 | if (message.type !== 'assistant') continue |
| 540 | const content = message.message.content |
| 541 | if (!Array.isArray(content)) continue |
| 542 | for (const block of content) { |
| 543 | if (block.type === 'tool_use') { |
| 544 | map.set(block.id, block.name) |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | return map |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Extract candidate tool_result blocks from a single user message: blocks |
no test coverage detected