TextStreams
Namespace: Vercel.AI.Util
public static class TextStreamsText-stream helpers: keep text deltas, build a response, and write it to a server response.
Inheritance: object
Methods
Section titled “Methods”CreateTextStreamResponse(ReadableStream<string>, int?, string?, HeaderCollection?)
Section titled “CreateTextStreamResponse(ReadableStream<string>, int?, string?, HeaderCollection?)”public static TextStreamResponse CreateTextStreamResponse(ReadableStream<string> stream, int? status = null, string? statusText = null, HeaderCollection? headers = null)Builds a response with content-type: text/plain; charset=utf-8 unless already set.
Each string chunk is encoded as its own UTF-8 body chunk.
Parameters
| Name | Type | Description |
|---|---|---|
stream |
ReadableStream<string> |
|
status |
int? | |
statusText |
string | |
headers |
HeaderCollection |
Returns: TextStreamResponse
PipeTextStreamToResponseAsync(ServerResponse, ReadableStream<string>, int?, string?, HeaderCollection?)
Section titled “PipeTextStreamToResponseAsync(ServerResponse, ReadableStream<string>, int?, string?, HeaderCollection?)”public static Task PipeTextStreamToResponseAsync(ServerResponse response, ReadableStream<string> stream, int? status = null, string? statusText = null, HeaderCollection? headers = null)Encodes <code class=“paramref”>stream</code> as UTF-8 and writes it to <code class=“paramref”>response</code>.
Parameters
| Name | Type | Description |
|---|---|---|
response |
ServerResponse | |
stream |
ReadableStream<string> |
|
status |
int? | |
statusText |
string | |
headers |
HeaderCollection |
Returns: Task
ToTextStream(ReadableStream<TextStreamPart>)
Section titled “ToTextStream(ReadableStream<TextStreamPart>)”public static ReadableStream<string> ToTextStream(ReadableStream<TextStreamPart> stream)Yields only text-delta text from <code class=“paramref”>stream</code>.
Parameters
| Name | Type | Description |
|---|---|---|
stream |
ReadableStream<TextStreamPart> |
Returns: ReadableStream<string>
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product