(history: readonly ContextMessage[])
| 112 | } |
| 113 | |
| 114 | export function groupIntoTurns(history: readonly ContextMessage[]): ContextMessage[][] { |
| 115 | const turns: ContextMessage[][] = []; |
| 116 | let current: ContextMessage[] = []; |
| 117 | |
| 118 | for (const msg of history) { |
| 119 | if (isInternalMessage(msg)) continue; |
| 120 | if (msg.role === 'user' && current.length > 0) { |
| 121 | turns.push(current); |
| 122 | current = []; |
| 123 | } |
| 124 | current.push(msg); |
| 125 | } |
| 126 | |
| 127 | if (current.length > 0) turns.push(current); |
| 128 | return turns; |
| 129 | } |
| 130 | |
| 131 | function formatTurnMd(messages: readonly ContextMessage[], turnNumber: number): string { |
| 132 | const lines: string[] = [`## Turn ${String(turnNumber)}`, '']; |
no test coverage detected