* Extract candidate tool_result blocks from a single user message: blocks * that are non-empty, non-image, and not already compacted by tag (i.e. by * the per-tool limit, or an earlier iteration of this same query call). * Returns [] for messages with no eligible blocks.
(message: Message)
| 555 | * Returns [] for messages with no eligible blocks. |
| 556 | */ |
| 557 | function collectCandidatesFromMessage(message: Message): ToolResultCandidate[] { |
| 558 | if (message.type !== 'user' || !Array.isArray(message.message.content)) { |
| 559 | return [] |
| 560 | } |
| 561 | return message.message.content.flatMap(block => { |
| 562 | if (block.type !== 'tool_result' || !block.content) return [] |
| 563 | if (isContentAlreadyCompacted(block.content)) return [] |
| 564 | if (hasImageBlock(block.content)) return [] |
| 565 | return [ |
| 566 | { |
| 567 | toolUseId: block.tool_use_id, |
| 568 | content: block.content, |
| 569 | size: contentSize(block.content), |
| 570 | }, |
| 571 | ] |
| 572 | }) |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Extract candidate tool_result blocks grouped by API-level user message. |
no test coverage detected