本页还没有译文
本页 20 段还没译成简体中文,下面显示的是英文原文。toServerSentEventsResponse
还没翻译译自英文(tanstack.com)本页 20 段都还没译
function toServerSentEventsResponse<TOffset>(stream, init?): Response;Defined in: packages/ai/src/stream-to-response.ts:1059
Convert a StreamChunk async iterable to a Response in Server-Sent Events format
This creates a Response 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)
Pass a durability sink (memoryStream(request) / durableStream(request))
to make the stream resumable: fresh runs are appended to the log and each SSE
event is tagged with an id: offset; a reconnect (native Last-Event-ID) or
a ?offset join replays from the log without re-running the producer. batch
controls how many chunks are buffered per append (default 32), and
batchWaitMs how long a buffered chunk waits for more (default 50).
Type Parameters
TOffset
TOffset extends string = string
Parameters
stream
AsyncIterable<AGUIEvent>
AsyncIterable of StreamChunks from chat()
init?
ResponseInit & object
Optional Response initialization options (including abortController, durability with its optional batch and batchWaitMs, and debug)
Returns
Response
Response in Server-Sent Events format
Example
export async function POST(request: Request) {
const stream = chat({ adapter: openaiText('gpt-5.5'), messages: [...] });
return toServerSentEventsResponse(stream, { durability: { adapter: memoryStream(request) } });
}