MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / groupIntoTurns

Function groupIntoTurns

src/diagnostics/token-analyzer.ts:93–109  ·  view source on GitHub ↗
(messages: Message[])

Source from the content-addressed store, hash-verified

91 * action burst → next user prompt).
92 */
93export 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
111export interface AnalyzeOptions {
112 /** Tokens consumed by the system prompt; same value applied to every turn. */

Callers 2

analyzeMessagesFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected