(payload: ResponsePayload)
| 323 | } |
| 324 | |
| 325 | function extractFirstMessageContent(payload: ResponsePayload): string | undefined { |
| 326 | if (!payload.json || typeof payload.json !== "object") return undefined; |
| 327 | const root = payload.json as Record<string, unknown>; |
| 328 | if (!Array.isArray(root.choices) || root.choices.length === 0) return undefined; |
| 329 | const firstChoice = root.choices[0]; |
| 330 | if (!firstChoice || typeof firstChoice !== "object") return undefined; |
| 331 | const message = (firstChoice as Record<string, unknown>).message; |
| 332 | if (!message || typeof message !== "object") return undefined; |
| 333 | const content = (message as Record<string, unknown>).content; |
| 334 | return typeof content === "string" ? content : undefined; |
| 335 | } |
| 336 | |
| 337 | async function collectSse(res: Response): Promise<SsePayload> { |
| 338 | const text = await res.text(); |
no outgoing calls
no test coverage detected