(blocks: ContentBlock[])
| 77 | * Preserves user intent by keeping blocks open if userOpened is true. |
| 78 | */ |
| 79 | export const autoCollapseBlocks = (blocks: ContentBlock[]): ContentBlock[] => { |
| 80 | return blocks.map((block) => { |
| 81 | // Handle thinking blocks (grouped text blocks) |
| 82 | if (block.type === 'text' && block.thinkingId) { |
| 83 | return block.userOpened ? block : { ...block, thinkingCollapseState: 'hidden' as const } |
| 84 | } |
| 85 | |
| 86 | // Handle agent blocks |
| 87 | if (block.type === 'agent') { |
| 88 | const updatedBlock = block.userOpened |
| 89 | ? block |
| 90 | : { ...block, isCollapsed: true } |
| 91 | |
| 92 | // Recursively update nested blocks |
| 93 | if (updatedBlock.blocks) { |
| 94 | return { |
| 95 | ...updatedBlock, |
| 96 | blocks: autoCollapseBlocks(updatedBlock.blocks), |
| 97 | } |
| 98 | } |
| 99 | return updatedBlock |
| 100 | } |
| 101 | |
| 102 | // Handle tool blocks |
| 103 | if (block.type === 'tool') { |
| 104 | return block.userOpened ? block : { ...block, isCollapsed: true } |
| 105 | } |
| 106 | |
| 107 | // Handle agent-list blocks |
| 108 | if (block.type === 'agent-list') { |
| 109 | return block.userOpened ? block : { ...block, isCollapsed: true } |
| 110 | } |
| 111 | |
| 112 | return block |
| 113 | }) |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Result of extracting content from a spawn_agents result value. |
no outgoing calls
no test coverage detected