// The AI-SDK streaming shape exactly: response.body → TextDecoderStream → // EventSourceParserStream (the real eventsource-parser package, embedded) // → for await, against the harness's local SSE route. Byte-exact vs Node. import { EventSourceParserStream } from "eventsource-parser/stream"; const out = (line) => process.stdout.write(line + "\n"); export function runSse(base) { (async () => { const res = await fetch(base + "/sse"); out(`sse ${res.status} ${res.headers.get("content-type")}`); const events = res.body .pipeThrough(new TextDecoderStream()) .pipeThrough(new EventSourceParserStream()); for await (const ev of events) { out(`event ${JSON.stringify(ev.event === undefined ? null : ev.event)} ${JSON.stringify(ev.data)} ${JSON.stringify(ev.id === undefined ? null : ev.id)}`); } out("sse-done"); })().catch((e) => { out(`FATAL ${e}`); }); }