(messages: Message[])
| 91 | * action burst → next user prompt). |
| 92 | */ |
| 93 | export function groupIntoTurns(messages: Message[]): Message[][] { |
| 94 | const turns: Message[][] = []; |
| 95 | let current: Message[] = []; |
| 96 | for (const m of messages) { |
| 97 | // Start a new turn at each user message — but only once the current turn |
| 98 | // already contains a user message. This keeps a leading system (or any |
| 99 | // pre-user preamble) attached to the first user turn instead of orphaning |
| 100 | // it into a turn of its own, which would inflate the turn count. |
| 101 | if (m.role === 'user' && current.some(x => x.role === 'user')) { |
| 102 | turns.push(current); |
| 103 | current = []; |
| 104 | } |
| 105 | current.push(m); |
| 106 | } |
| 107 | if (current.length > 0) turns.push(current); |
| 108 | return turns; |
| 109 | } |
| 110 | |
| 111 | export interface AnalyzeOptions { |
| 112 | /** Tokens consumed by the system prompt; same value applied to every turn. */ |
no test coverage detected