| 62 | } |
| 63 | |
| 64 | function extractDeltaContent(delta: Record<string, unknown> | undefined): string { |
| 65 | if (!delta) { |
| 66 | return ""; |
| 67 | } |
| 68 | |
| 69 | const { content, text } = delta; |
| 70 | |
| 71 | if (typeof content === "string") { |
| 72 | return content; |
| 73 | } |
| 74 | |
| 75 | if (Array.isArray(content)) { |
| 76 | return content |
| 77 | .map((part) => { |
| 78 | if (typeof part === "string") { |
| 79 | return part; |
| 80 | } |
| 81 | if (part && typeof part === "object" && "text" in part) { |
| 82 | return String((part as { text?: string }).text ?? ""); |
| 83 | } |
| 84 | return ""; |
| 85 | }) |
| 86 | .join(""); |
| 87 | } |
| 88 | |
| 89 | if (typeof text === "string") { |
| 90 | return text; |
| 91 | } |
| 92 | |
| 93 | return ""; |
| 94 | } |
| 95 | |
| 96 | function extractDeltaReasoning(delta: Record<string, unknown> | undefined): string { |
| 97 | if (!delta) { |