(entries: readonly TranscriptEntry[])
| 57 | * following turn) become their own turn. |
| 58 | */ |
| 59 | export function groupTurns(entries: readonly TranscriptEntry[]): TranscriptTurn[] { |
| 60 | const turns: TranscriptTurn[] = []; |
| 61 | let current: TranscriptTurn | undefined; |
| 62 | let pendingUndefined: TranscriptEntry[] = []; |
| 63 | |
| 64 | for (const entry of entries) { |
| 65 | const turnId = entry.turnId; |
| 66 | if (turnId === undefined) { |
| 67 | pendingUndefined.push(entry); |
| 68 | continue; |
| 69 | } |
| 70 | if (current !== undefined && current.turnId === turnId) { |
| 71 | current.entries.push(entry); |
| 72 | } else { |
| 73 | current = { turnId, entries: [...pendingUndefined, entry] }; |
| 74 | pendingUndefined = []; |
| 75 | turns.push(current); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (pendingUndefined.length > 0) { |
| 80 | turns.push({ turnId: undefined, entries: pendingUndefined }); |
| 81 | } |
| 82 | |
| 83 | return turns; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Decide which entries to destroy so the remaining turns fit within |
no test coverage detected