MCPcopy
hub / github.com/garrytan/gstack / parseNDJSON

Function parseNDJSON

test/helpers/session-runner.ts:78–112  ·  view source on GitHub ↗
(lines: string[])

Source from the content-addressed store, hash-verified

76 * reader and unit tests.
77 */
78export function parseNDJSON(lines: string[]): ParsedNDJSON {
79 const transcript: any[] = [];
80 let resultLine: any = null;
81 let turnCount = 0;
82 let toolCallCount = 0;
83 const toolCalls: ParsedNDJSON['toolCalls'] = [];
84
85 for (const line of lines) {
86 if (!line.trim()) continue;
87 try {
88 const event = JSON.parse(line);
89 transcript.push(event);
90
91 // Track turns and tool calls from assistant events
92 if (event.type === 'assistant') {
93 turnCount++;
94 const content = event.message?.content || [];
95 for (const item of content) {
96 if (item.type === 'tool_use') {
97 toolCallCount++;
98 toolCalls.push({
99 tool: item.name || 'unknown',
100 input: item.input || {},
101 output: '',
102 });
103 }
104 }
105 }
106
107 if (event.type === 'result') resultLine = event;
108 } catch { /* skip malformed lines */ }
109 }
110
111 return { transcript, resultLine, turnCount, toolCallCount, toolCalls };
112}
113
114function truncate(s: string, max: number): string {
115 return s.length > max ? s.slice(0, max) + '…' : s;

Callers 2

runSkillTestFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected