Open History to see the last commit
Function: toServerSentEventsStream()#
function toServerSentEventsStream(stream, abortController?): ReadableStream<Uint8Array<ArrayBufferLike>>;
Defined in: packages/typescript/ai/src/stream-to-response.ts:50
Convert a StreamChunk async iterable to a ReadableStream in Server-Sent Events format
This creates a ReadableStream that emits chunks in SSE format:
- Each chunk is prefixed with "data: "
- Each chunk is followed by "\n\n"
- Stream ends when the underlying iterable is exhausted (RUN_FINISHED is the terminal event)
Parameters#
stream#
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
abortController?#
AbortController
Optional AbortController to abort when stream is cancelled
Returns#
ReadableStream<Uint8Array<ArrayBufferLike>>
ReadableStream in Server-Sent Events format