* Convert OpenAI message content to unified MessageContent format
( content: string | null | Array<any>, )
| 137 | * Convert OpenAI message content to unified MessageContent format |
| 138 | */ |
| 139 | function convertMessageContent( |
| 140 | content: string | null | Array<any>, |
| 141 | ): MessageContent { |
| 142 | if (content === null) { |
| 143 | return ""; |
| 144 | } |
| 145 | |
| 146 | if (typeof content === "string") { |
| 147 | return content; |
| 148 | } |
| 149 | |
| 150 | if (Array.isArray(content)) { |
| 151 | return content.map((part: any) => { |
| 152 | if (part.type === "text") { |
| 153 | return { |
| 154 | type: "text" as const, |
| 155 | text: part.text, |
| 156 | }; |
| 157 | } else if (part.type === "image_url") { |
| 158 | return { |
| 159 | type: "imageUrl" as const, |
| 160 | imageUrl: { url: part.image_url.url }, |
| 161 | }; |
| 162 | } |
| 163 | throw new Error(`Unsupported content part type: ${part.type}`); |
| 164 | }); |
| 165 | } |
| 166 | |
| 167 | throw new Error(`Unsupported content type: ${typeof content}`); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Convert unified MessageContent to OpenAI format |
no outgoing calls
no test coverage detected