docs(examples): migrate deprecated streamText result helpers to standalone helpers#15741
Merged
Merged
Conversation
…alone helpers Follow-up to #14652. Migrates remaining usages of the deprecated `streamText` result methods in examples/, content/docs/ and content/cookbook/ to the new standalone helpers exported from `ai`: - result.toUIMessageStream(opts) -> toUIMessageStream({ stream: result.stream, ...opts }) - result.toUIMessageStreamResponse(opts) -> createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream, ...streamOpts }), ...responseInit }) - result.pipeUIMessageStreamToResponse(res) -> pipeUIMessageStreamToResponse({ response: res, stream: toUIMessageStream({ stream: result.stream, ...streamOpts }) }) - result.toTextStreamResponse(init) -> createTextStreamResponse({ stream: toTextStream({ stream: result.stream }), ...init }) - result.pipeTextStreamToResponse(res) -> pipeTextStreamToResponse({ response: res, stream: toTextStream({ stream: result.stream }), ...init }) Per the deferral note in #14652, the regression tests in packages/ai/src/generate-text/stream-text.test.ts and the historical migration guides under content/docs/08-migration-guides/ intentionally stay on the deprecated API and are left untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap long single-line `ai` imports introduced by the helper migration onto multiple lines (pnpm fix / oxfmt), and update the now-shifted highlight range in 22-stream-text-with-image-prompt.mdx. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…udflare provider doc
Extends the migration to two doc usages found outside the originally
enumerated examples/+docs/+cookbook scope:
- packages/angular/README.md: migrate the streamText chat/completion
endpoints (pipeUIMessageStreamToResponse / pipeTextStreamToResponse).
The streamObject structured-object endpoint is left untouched as its
pipeTextStreamToResponse is not deprecated.
- content/providers/.../cloudflare-workers-ai.mdx: migrate
toTextStreamResponse({ headers }) to createTextStreamResponse +
toTextStream.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
felixarntz
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Follow-up to #14652, which deprecated the five
streamTextresult methods that convert a result into other forms and added stateless standalone helpers in their place. That PR intentionally deferred migrating the existingexamples/,content/docs/, andcontent/cookbook/usages to keep the API change reviewable:This PR is that follow-up.
Summary
Migrated every remaining usage of the deprecated result methods to the standalone helpers exported from
ai. The result object's.streamis passed to the helper directly:streamTextresult)result.toUIMessageStream(opts)toUIMessageStream({ stream: result.stream, ...opts })result.toUIMessageStreamResponse(opts)createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream, ...streamOpts }), ...responseInit })result.pipeUIMessageStreamToResponse(res, opts)pipeUIMessageStreamToResponse({ response: res, stream: toUIMessageStream({ stream: result.stream, ...streamOpts }) })result.toTextStreamResponse(init)createTextStreamResponse({ stream: toTextStream({ stream: result.stream }), ...init })result.pipeTextStreamToResponse(res, init)pipeTextStreamToResponse({ response: res, stream: toTextStream({ stream: result.stream }), ...init })For
toUIMessageStreamResponse/pipeUIMessageStreamToResponse, the options object is split: stream options (originalMessages,generateMessageId,onFinish,messageMetadata,sendReasoning,sendSources,sendStart,sendFinish,onError) go intotoUIMessageStream, while response-init options (headers,status,statusText,consumeSseStream) stay on the responder helper.Scope: 149 files (80 examples, 37 docs, 32 cookbook).
Notable cases:
agent.stream()results (content/cookbook/01-next/77-track-agent-token-usage.mdx) return aStreamTextResult, so theirtoUIMessageStreamResponseis the deprecated method and was migrated. Where the snippet used the<AgentUIMessage>generic to type themessageMetadatacallback, the message generic moves totoUIMessageStream<ToolSet, AgentUIMessage>.streamText+Outputroutes (e.g.use-object,stream-object) usestreamText, so theirtoTextStreamResponseis deprecated and was migrated.streamObjectresults — whosetoTextStreamResponse/pipeTextStreamToResponseare not deprecated — were left untouched (none were present in the migrated files).examples/ai-functions/.../anthropic-reasoning-ui-stream.ts): the standalonetoUIMessageStreamreturns a plainReadableStreamrather than the oldAsyncIterableStream, so thefor awaitwas replaced with a reader loop.highlightranges: expanding single-line imports / one-line returns shifted line numbers inside fenced code blocks; affectedhighlight="..."attributes were recomputed.12-use-chat-an-error-occurred.mdx: the migrated snippet's stalegetErrorMessageoption was corrected totoUIMessageStream's actualonErroroption.Manual Verification
oxfmt+oxlintclean on all changed TS/TSX files.tsc --noEmiton the affected example packages (ai-functions,ai-e2e-next,express,hono,fastify,nest,node-http-server,angular,next,next-openai-pages,nuxt-openai,sveltekit-openai) shows no migration-related type errors. (Pre-existing, unrelated errors inai-functionsazure/xai web-search example files are not touched by this PR.)Checklist
pnpm changesetin the project root)Future Work
toUIMessageChunkagainst the newaihelper (tracked in feat(ai): exposetoUIMessageChunkStreamhelper #14652).Related Issues
Follow-up to #14652.