(chunks: unknown[], includeDone = false)
| 730 | } |
| 731 | |
| 732 | function createEventStream(chunks: unknown[], includeDone = false) { |
| 733 | const lines = chunks.map((chunk) => `data: ${typeof chunk === "string" ? chunk : JSON.stringify(chunk)}`) |
| 734 | if (includeDone) { |
| 735 | lines.push("data: [DONE]") |
| 736 | } |
| 737 | const payload = lines.join("\n\n") + "\n\n" |
| 738 | const encoder = new TextEncoder() |
| 739 | return new ReadableStream<Uint8Array>({ |
| 740 | start(controller) { |
| 741 | controller.enqueue(encoder.encode(payload)) |
| 742 | controller.close() |
| 743 | }, |
| 744 | }) |
| 745 | } |
| 746 | |
| 747 | function createEventResponse(chunks: unknown[], includeDone = false) { |
| 748 | return new Response(createEventStream(chunks, includeDone), { |
no test coverage detected