Skip to content

TextStreams

Namespace: Vercel.AI.Util

public static class TextStreams

Text-stream helpers: keep text deltas, build a response, and write it to a server response.

Inheritance: object

View source

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&lt;string&gt;
status int?
statusText string
headers HeaderCollection

Returns: TextStreamResponse

View source

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&lt;string&gt;
status int?
statusText string
headers HeaderCollection

Returns: Task

View source

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&lt;TextStreamPart&gt;

Returns: ReadableStream&lt;string&gt;

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product