* Type predicate: Check if a message is a tool result for collapsible tools. * Returns true if ALL tool results in the message are for tracked collapsible tools.
( msg: RenderableMessage, collapsibleToolUseIds: Set<string>, )
| 458 | * Returns true if ALL tool results in the message are for tracked collapsible tools. |
| 459 | */ |
| 460 | function isCollapsibleToolResult( |
| 461 | msg: RenderableMessage, |
| 462 | collapsibleToolUseIds: Set<string>, |
| 463 | ): msg is CollapsibleMessage { |
| 464 | if (msg.type === 'user') { |
| 465 | const toolResults = msg.message.content.filter( |
| 466 | (c): c is { type: 'tool_result'; tool_use_id: string } => |
| 467 | c.type === 'tool_result', |
| 468 | ) |
| 469 | // Only return true if there are tool results AND all of them are for collapsible tools |
| 470 | return ( |
| 471 | toolResults.length > 0 && |
| 472 | toolResults.every(r => collapsibleToolUseIds.has(r.tool_use_id)) |
| 473 | ) |
| 474 | } |
| 475 | return false |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Get all tool use IDs from a single message (handles grouped tool uses). |
no test coverage detected