Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

toServerSentEventsStream.md

46 lines1.0 KB

1---
2id: toServerSentEventsStream
3title: toServerSentEventsStream
4---
5​
6```ts
7function toServerSentEventsStream(
8 stream,
9 abortController?,
10getId?): ReadableStream<Uint8Array<ArrayBufferLike>>;
11```
12​
13Defined in: packages/ai/src/stream-to-response.ts:473
14​
15Convert a StreamChunk async iterable to a ReadableStream in Server-Sent Events format
16​
17This creates a ReadableStream that emits chunks in SSE format:
18- Each chunk is prefixed with "data: "
19- Each chunk is followed by "\n\n"
20- Stream ends when the underlying iterable is exhausted (RUN_FINISHED is the terminal event)
21​
22## Parameters
23​
24### stream
25​
26`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
27​
28AsyncIterable of StreamChunks from chat()
29​
30### abortController?
31​
32`AbortController`
33​
34Optional AbortController to abort when stream is cancelled
35​
36### getId?
37​
38(`chunk`, `index`) => `string` \| `undefined`
39​
40Optional per-chunk durability offset; when present, each event gets an `id:` line
41​
42## Returns
43​
44`ReadableStream`\<`Uint8Array`\<`ArrayBufferLike`\>\>
45​
46ReadableStream in Server-Sent Events format