(row: OpenCodePartRow)
| 300 | } |
| 301 | |
| 302 | function* extractOpenCodePart(row: OpenCodePartRow): Generator<TranscriptEvent> { |
| 303 | const data = safeJsonParse(row.part_data); |
| 304 | if (!data || typeof data !== 'object') return; |
| 305 | const role = isTranscriptRole(row.message_role) ? row.message_role : undefined; |
| 306 | const ts = row.part_time ?? row.message_time; |
| 307 | |
| 308 | if (data.type === 'text' && typeof data.text === 'string' && data.text.trim()) { |
| 309 | yield { ts, kind: 'text', role, text: data.text, raw: data }; |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | if (data.type !== 'tool') return; |
| 314 | const callId = typeof data.callID === 'string' ? data.callID : row.part_id; |
| 315 | const state = data.state; |
| 316 | yield { |
| 317 | ts, |
| 318 | kind: 'tool_call', |
| 319 | role: role ?? 'assistant', |
| 320 | toolCallId: callId, |
| 321 | toolName: typeof data.tool === 'string' ? data.tool : undefined, |
| 322 | inputText: stringifyValue(state?.input ?? {}), |
| 323 | raw: data, |
| 324 | }; |
| 325 | |
| 326 | if (shouldEmitToolResult(state)) { |
| 327 | yield { |
| 328 | ts, |
| 329 | kind: 'tool_result', |
| 330 | role: role ?? 'assistant', |
| 331 | toolCallId: callId, |
| 332 | text: resultText(state) ?? '', |
| 333 | raw: data, |
| 334 | }; |
| 335 | } |
| 336 | } |
no test coverage detected