Extract concatenated tool_result text from the stream-json transcript.
(transcript: any[])
| 48 | |
| 49 | /** Extract concatenated tool_result text from the stream-json transcript. */ |
| 50 | function toolResultText(transcript: any[]): string { |
| 51 | const chunks: string[] = []; |
| 52 | for (const event of transcript) { |
| 53 | if (event.type !== 'user') continue; |
| 54 | for (const item of event.message?.content ?? []) { |
| 55 | if (item.type !== 'tool_result') continue; |
| 56 | if (typeof item.content === 'string') chunks.push(item.content); |
| 57 | else for (const c of item.content ?? []) if (c.type === 'text') chunks.push(c.text); |
| 58 | } |
| 59 | } |
| 60 | return chunks.join('\n'); |
| 61 | } |
| 62 | |
| 63 | function initEvent(transcript: any[]): any { |
| 64 | return transcript.find((e) => e.type === 'system' && e.subtype === 'init'); |
no test coverage detected