Skip to content

docs(examples): migrate deprecated streamText result helpers to standalone helpers#15741

Merged
gr2m merged 4 commits into
mainfrom
migrate-deprecated-stream-helpers-docs-examples
Jun 1, 2026
Merged

docs(examples): migrate deprecated streamText result helpers to standalone helpers#15741
gr2m merged 4 commits into
mainfrom
migrate-deprecated-stream-helpers-docs-examples

Conversation

@gr2m
Copy link
Copy Markdown
Collaborator

@gr2m gr2m commented Jun 1, 2026

Background

Follow-up to #14652, which deprecated the five streamText result methods that convert a result into other forms and added stateless standalone helpers in their place. That PR intentionally deferred migrating the existing examples/, content/docs/, and content/cookbook/ usages to keep the API change reviewable:

Migrate remaining usages of the deprecated methods in examples/ and content/docs/ + content/cookbook/ to the new standalone helpers. Intentionally deferred to a follow-up PR so the API change here stays 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 .stream is passed to the helper directly:

Deprecated (on streamText result) Standalone replacement
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 into toUIMessageStream, 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 a StreamTextResult, so their toUIMessageStreamResponse is the deprecated method and was migrated. Where the snippet used the <AgentUIMessage> generic to type the messageMetadata callback, the message generic moves to toUIMessageStream<ToolSet, AgentUIMessage>.
  • streamText + Output routes (e.g. use-object, stream-object) use streamText, so their toTextStreamResponse is deprecated and was migrated. streamObject results — whose toTextStreamResponse/pipeTextStreamToResponse are not deprecated — were left untouched (none were present in the migrated files).
  • Chunk iteration (examples/ai-functions/.../anthropic-reasoning-ui-stream.ts): the standalone toUIMessageStream returns a plain ReadableStream rather than the old AsyncIterableStream, so the for await was replaced with a reader loop.
  • MDX highlight ranges: expanding single-line imports / one-line returns shifted line numbers inside fenced code blocks; affected highlight="..." attributes were recomputed.
  • Minor correctness fix in 12-use-chat-an-error-occurred.mdx: the migrated snippet's stale getErrorMessage option was corrected to toUIMessageStream's actual onError option.

Manual Verification

  • oxfmt + oxlint clean on all changed TS/TSX files.
  • tsc --noEmit on 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 in ai-functions azure/xai web-search example files are not touched by this PR.)
  • No production package code changed, so no changeset is required.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

Related Issues

Follow-up to #14652.

…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>
@gr2m gr2m marked this pull request as ready for review June 1, 2026 17:11
@gr2m gr2m merged commit 42f9240 into main Jun 1, 2026
46 checks passed
@gr2m gr2m deleted the migrate-deprecated-stream-helpers-docs-examples branch June 1, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants