feat(ai-sdk): add streamText/streamObject streaming sample (AI SDK v7)#497
Merged
Conversation
…o AI SDK v7 Adds streamingAgent and streamObjectAgent that publish deltas to a WorkflowStream topic, a subscribing client consumer, and an offline test. Migrates workflow imports to the @temporalio/ai-sdk/workflow subpath and bumps ai/@ai-sdk deps to v7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # ai-sdk/package.json
The ai-sdk sample needs custom module settings (module: commonjs, moduleResolution: node) so the ESM-only AI SDK v7 works from this CommonJS sample. Add it to TSCONFIG_EXCLUDE so copy-shared-files doesn't clobber ai-sdk/tsconfig.json on push. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The static top-level `import { openai } from '@ai-sdk/openai'` compiles to
require() under the sample's CommonJS build. On Node 22's require(ESM)
implementation this throws "Unexpected module status 0" at module-load time,
aborting the entire mocha run — even though the workflow test is skipped when
OPENAI_API_KEY is unset (as in CI). Node 20 and 24 are unaffected.
Load @ai-sdk/openai via a native dynamic import() (wrapped in `new Function`
so TypeScript doesn't down-level it to require()), inside the `before` hook so
it only runs when the suite isn't skipped.
Verified against Node 22.23.1: old code reproduces the failure, new code passes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The sample's CommonJS mocha/ts-node tests must require() the ESM-only `ai`
package (via workflows.ts). That needs require(ESM), which is only enabled by
default on Node >= 22.12 / 20.19 / 24. The Windows CI runner uses Node 22.11.0,
where require(ESM) is still flagged — so requiring workflows.ts throws
ERR_REQUIRE_ESM, mocha falls back to import()-ing the .ts test file, and Node's
ESM loader rejects it ("Unknown file extension .ts").
Pass `--node-option experimental-require-module` via mocha (cross-platform,
unlike inline NODE_OPTIONS) to enable require(ESM) on older Node. The flag is a
no-op/accepted on 20.19, 22.12+, and 24.
Verified locally on Node 20.19.4, 22.11.0, 22.23.1, and 24: all pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
brianstrauch
enabled auto-merge (squash)
July 23, 2026 21:02
xumaple
reviewed
Jul 23, 2026
xumaple
left a comment
Contributor
There was a problem hiding this comment.
overall looks good, have a couple comments
Address PR #497 review comments: - Remove the streamObject sample; streamObject is @deprecated in ai@7.0.36 ("Use streamText with an output setting instead"). Drops streamObjectAgent, its provider/topic, the stream-object CLI case, test, and README entry. - Add the missing SNIPEND for middlewareAgent so its snippet no longer swallows the mcp-agent below it. - Replace the arbitrary 500ms linger-sleep in streamingAgent with a consumer-ack signal: the workflow waits for the subscriber to confirm it received the final delta (with a timeout fallback) instead of racing its in-memory stream log being discarded on completion. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # pnpm-lock.yaml
THardy98
approved these changes
Jul 24, 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.
Adds a streaming sample to the
ai-sdkproject and upgrades it to Vercel AI SDK v7.What's added
streamingAgent(streamText) andstreamObjectAgent(streamObject) insrc/workflows.ts— each hostsnew WorkflowStream()and publishes token/object deltas to a topic via astreamingTopic-configured provider.renderStreamconsumer plusstream/stream-objectclient commands insrc/client.tsthat subscribe by workflow id and render deltas live.src/mocha/streaming.test.ts(mock provider, noOPENAI_API_KEYneeded) covering both agents end-to-end.ai→^7,@ai-sdk/provider→^4,@ai-sdk/mcp→^2,@ai-sdk/openai→^4; adds@temporalio/workflow-streams; switches workflow imports to the sandbox-safe@temporalio/ai-sdk/workflowsubpath.Verification
Both streaming tests pass end-to-end against the v7 build (real
ai@7+ Temporal test server): live deltas published, full text/object durably reassembled. Bundling the wholeworkflows.tssucceeds, confirming the v7/workflowmigration also fixes bundling that is broken under v6.The v7
@temporalio/ai-sdkis not yet published to npm (latest is1.20.3, AI SDK v6). Before merge:@temporalio/ai-sdkto the first v7-supporting release (left at^1.20.3placeholder) and regenerate the lockfile.Related
Implements the streaming request from temporalio/sdk-typescript#2180. Streaming support itself landed in temporalio/sdk-typescript#2039; this sample demonstrates it. Docs PR: temporalio/documentation (branch
ai-sdk-streaming).🤖 Generated with Claude Code