| 822 | } |
| 823 | |
| 824 | function appendAssistantDelta( |
| 825 | items: TranscriptEntry[], |
| 826 | assistantId: string, |
| 827 | text: string |
| 828 | ) { |
| 829 | const last = items.at(-1) |
| 830 | |
| 831 | if (last?.kind === "assistant" && last.id.startsWith(`assistant-${assistantId}`)) { |
| 832 | return items.map((item, index) => |
| 833 | index === items.length - 1 ? { ...item, text: item.text + text } : item |
| 834 | ) |
| 835 | } |
| 836 | |
| 837 | const segmentCount = items.filter((item) => |
| 838 | item.id.startsWith(`assistant-${assistantId}`) |
| 839 | ).length |
| 840 | |
| 841 | return [ |
| 842 | ...items, |
| 843 | { |
| 844 | id: `assistant-${assistantId}-${segmentCount}`, |
| 845 | kind: "assistant" as const, |
| 846 | label: "agent", |
| 847 | text, |
| 848 | }, |
| 849 | ] |
| 850 | } |
| 851 | |
| 852 | function applyAgentEvent( |
| 853 | items: TranscriptEntry[], |