* 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)
| 574 | * Returns [] for messages with no eligible blocks. |
| 575 | */ |
| 576 | function collectCandidatesFromMessage(message: Message): ToolResultCandidate[] { |
| 577 | if (message.type !== 'user' || !Array.isArray(message.message.content)) { |
| 578 | return [] |
| 579 | } |
| 580 | return message.message.content.flatMap(block => { |
| 581 | if (block.type !== 'tool_result' || !block.content) return [] |
| 582 | if (isContentAlreadyCompacted(block.content)) return [] |
| 583 | if (hasImageBlock(block.content)) return [] |
| 584 | return [ |
| 585 | { |
| 586 | toolUseId: block.tool_use_id, |
| 587 | content: block.content, |
| 588 | size: contentSize(block.content), |
| 589 | }, |
| 590 | ] |
| 591 | }) |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Extract candidate tool_result blocks grouped by API-level user message. |
no test coverage detected