UNPKG

ai

Version:

AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.

22 lines (20 loc) 613 B
import type { ToolSet } from '@ai-sdk/provider-utils'; import type { TextStreamPart } from '../generate-text/stream-text-result'; /** * Converts a stream of `TextStreamPart` chunks into a stream of text deltas. */ export function toTextStream<TOOLS extends ToolSet = ToolSet>({ stream, }: { stream: ReadableStream<TextStreamPart<TOOLS>>; }): ReadableStream<string> { return stream.pipeThrough( new TransformStream<TextStreamPart<TOOLS>, string>({ transform(part, controller) { if (part.type === 'text-delta') { controller.enqueue(part.text); } }, }), ); }