( blocks: ContentBlock[], startIndex: number, predicate: (block: ContentBlock) => block is T, )
| 117 | * Returns the group and the next index to process. |
| 118 | */ |
| 119 | export function groupConsecutiveBlocks<T extends ContentBlock>( |
| 120 | blocks: ContentBlock[], |
| 121 | startIndex: number, |
| 122 | predicate: (block: ContentBlock) => block is T, |
| 123 | ): { group: T[]; nextIndex: number } { |
| 124 | const group: T[] = [] |
| 125 | let i = startIndex |
| 126 | |
| 127 | while (i < blocks.length) { |
| 128 | const block = blocks[i] |
| 129 | if (!predicate(block)) { |
| 130 | break |
| 131 | } |
| 132 | group.push(block) |
| 133 | i++ |
| 134 | } |
| 135 | |
| 136 | return { group, nextIndex: i } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Group consecutive implementor agents from a blocks array. |
no outgoing calls
no test coverage detected