Skip to content

feat(ai-sdk): add streamText/streamObject streaming sample (AI SDK v7)#497

Merged
brianstrauch merged 7 commits into
mainfrom
ai-sdk-streaming-sample
Jul 24, 2026
Merged

feat(ai-sdk): add streamText/streamObject streaming sample (AI SDK v7)#497
brianstrauch merged 7 commits into
mainfrom
ai-sdk-streaming-sample

Conversation

@brianstrauch

Copy link
Copy Markdown
Member

Adds a streaming sample to the ai-sdk project and upgrades it to Vercel AI SDK v7.

What's added

  • streamingAgent (streamText) and streamObjectAgent (streamObject) in src/workflows.ts — each hosts new WorkflowStream() and publishes token/object deltas to a topic via a streamingTopic-configured provider.
  • A renderStream consumer plus stream / stream-object client commands in src/client.ts that subscribe by workflow id and render deltas live.
  • An offline src/mocha/streaming.test.ts (mock provider, no OPENAI_API_KEY needed) covering both agents end-to-end.
  • Bumps 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/workflow subpath.

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 whole workflows.ts succeeds, confirming the v7 /workflow migration also fixes bundling that is broken under v6.

⚠️ Held pending release

The v7 @temporalio/ai-sdk is not yet published to npm (latest is 1.20.3, AI SDK v6). Before merge:

  • Pin @temporalio/ai-sdk to the first v7-supporting release (left at ^1.20.3 placeholder) 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

…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>
@brianstrauch
brianstrauch requested review from a team as code owners July 17, 2026 20:03
brianstrauch and others added 4 commits July 23, 2026 11:36
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
brianstrauch enabled auto-merge (squash) July 23, 2026 21:02

@xumaple xumaple left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, have a couple comments

Comment thread ai-sdk/src/workflows.ts Outdated
Comment thread ai-sdk/src/workflows.ts Outdated
Comment thread ai-sdk/src/workflows.ts
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>
@brianstrauch
brianstrauch requested a review from xumaple July 23, 2026 23:53

@xumaple xumaple left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brianstrauch
brianstrauch merged commit 0b8d822 into main Jul 24, 2026
13 checks passed
@brianstrauch
brianstrauch deleted the ai-sdk-streaming-sample branch July 24, 2026 19:08
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.

3 participants