(ctx: ConvertPartContext)
| 414 | } |
| 415 | |
| 416 | function convertPartToEntries(ctx: ConvertPartContext): PiJson[] { |
| 417 | const part = parseJsonObject<OpenCodePartData>(ctx.row.data); |
| 418 | switch (part.type) { |
| 419 | case "step-start": |
| 420 | case "step-finish": |
| 421 | case "patch": |
| 422 | return []; |
| 423 | case "text": |
| 424 | return part.text |
| 425 | ? [makeMessageEntry(ctx.role, part.text, ctx.timestamp, ctx.parentId, ctx.usage)] |
| 426 | : []; |
| 427 | case "reasoning": |
| 428 | return part.text |
| 429 | ? [makeThinkingEntry(part.text, ctx.timestamp, ctx.parentId, ctx.usage)] |
| 430 | : []; |
| 431 | case "tool": { |
| 432 | const tool = normalizeOpenCodeTool(part); |
| 433 | const call = makeToolCallEntry(tool, ctx.timestamp, ctx.parentId, ctx.usage); |
| 434 | const result = makeToolResultEntry(tool, ctx.timestamp, call.id as string); |
| 435 | return [call, result]; |
| 436 | } |
| 437 | case "file": { |
| 438 | const name = part.filename ?? part.name ?? "attachment"; |
| 439 | return [ |
| 440 | makeMessageEntry( |
| 441 | ctx.role, |
| 442 | `<file omitted: ${name}>`, |
| 443 | ctx.timestamp, |
| 444 | ctx.parentId, |
| 445 | ctx.usage, |
| 446 | ), |
| 447 | ]; |
| 448 | } |
| 449 | default: |
| 450 | return []; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | interface BuildEntriesResult { |
| 455 | entries: PiJson[]; |
no test coverage detected