-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
How can I return a stream from better call?
I have the following streaming endpoint I would like to support for example:
return new Response(stream, {
status: 200,
headers: {
"Content-Type": "application/x-ndjson",
"Transfer-Encoding": "chunked",
"Cache-Control": "no-cache",
Connection: "keep-alive",
},
});Suggestion:
One way to do it would be to use generators to yield the data back in a typesafe manner.
export const endpoint = createGeneratorEndpoint(
"/ai/realtime",
{
method: "POST",
requireRequest: true,
},
async function* (ctx) {
for(const value of result) {
// type safe value that is converted to a SSE (Server Sent Event)
// and streamed to the client
yield value;
}
},
);lacherogwu
Metadata
Metadata
Assignees
Labels
No labels