Server-Sent Events
The API route returns a ReadableStream body with content-type: text/event-stream; the page opens an EventSource. bext drives the V8 isolate with a progressive driver — each enqueued chunk is forwarded to the HTTP body the moment the producer flushes it, so onmessage fires in real time at the cadence the handler chooses (one tick per 750ms below).
Warning
/api/* routes buffer the full response before delivery — EventSource won't receive chunks in real time from a PRISM API route. Use a dedicated src/app/api/sse/route.ts (not page.tsx) so the progressive driver flushes each chunk immediately.
Live stream
// src/app/api/sse/route.ts — emits text/event-stream
export async function GET(): Promise<Response> {
const encoder = new TextEncoder();
const stream = new ReadableStream({
async start(controller) {
controller.enqueue(encoder.encode(`data: ${JSON.stringify({tick:0,at:Date.now()})}\n\n`));
for (let i = 1; i <= 8; i++) {
await new Promise(r => setTimeout(r, 750));
controller.enqueue(encoder.encode(`data: ${JSON.stringify({tick:i,at:Date.now()})}\n\n`));
}
controller.close();
},
});
return new Response(stream, {
headers: { "content-type": "text/event-stream" },
});
}
// page.tsx — client opens an EventSource
const es = new EventSource("/api/sse");
es.onmessage = (e) => render(JSON.parse(e.data));