Repository navigation
feat: support Vercel AI SDK v7 - #511
Conversation
|
Review/context after the final two follow-up commits:
Fresh local checks run on the final 3-commit branch:
As expected for a fork PR, GitHub Actions have not started yet because the first workflow run needs maintainer approval. |
There was a problem hiding this comment.
Perry's Review
Migrates the OpenRouter provider to Vercel AI SDK v7 (the v4 provider model interfaces, a tagged file-data union, ESM-only output, Node 22) as a v7-only major release.
Verdict: 🔁 Needs changes
Details
Risk: 🟡 Medium — major-version breaking release touching the streaming/usage path, but the changes are structural type renames plus a well-tested file-part shape migration.
CI:
Findings (see inline comment):
- 🔴 package.json:68 — the lockfile was not regenerated after the zod peer-range bump, so pnpm install fails under CI's default frozen-lockfile.
What I verified locally (Node 22.23, pnpm 10.12):
- frozen-lockfile install fails with ERR_PNPM_OUTDATED_LOCKFILE (zod specifier mismatch).
- After a no-frozen-lockfile install (1-line lockfile change), everything is green: typecheck passes, node tests 427/427 pass, edge tests 427/427 pass, build succeeds with ESM-only output.
- The getFileDataUrl switch (data / url / text / reference + exhaustive never default) matches the SharedV4FileData union in the v4 provider package.
- getToolResultContent and mapToolResultContentParts cover all v4 output and content member types; the removed image-data / image-url / file-data / file-url / file-id cases no longer exist in v4.
- computeTokenUsage and emptyUsage match the structured v4 usage shape (inputTokens / outputTokens objects).
- The provider-defined tool factory exports exist in provider-utils v5 (the issue #474 export path).
- No leftover V3 type references remain in non-test source.
Codex (heavy second-opinion): no additional valid findings.
Analysis lanes: no valid net-new findings (candidates were stale restatements of the migration itself).
Research: Verified the v4 type surface directly against the published v4 provider and v5 provider-utils type declarations (unpkg) rather than from memory — the file-data union, usage shape, tool-result output union, and tool-factory exports all line up with the diff.
Security: Touches the streaming response path and file/media handling (categories 2, 4). No credential handling, auth, or tenant-isolation changes; the file-data union rewrite preserves the prior data-URL/base64 behavior (confirmed by the passing chat tests). No concerns.
Test coverage: Excellent — every test file was migrated to the v4 file-part shape and all 854 node and edge assertions pass against the new SDK.
Unresolved threads: none
Scope: first review (full)
Review: tier=large · model=claude-opus-latest · score=10.5
|
Local CodeRabbit CLI review result: Initial run found 3 issues, all addressed in follow-up commit
Fresh local checks after the fix commit:
Reran local CodeRabbit CLI against the full branch ( |
Superseded by updated Perry review
|
Final local + live retest update: Final PR-state checks run after reverting all temporary live-test slug changes:
Live API checks with temporary local slug/output-cap substitutions:
The temporary live-test substitutions were not committed; the branch is clean and still only contains the 5 PR commits. |
|
Follow-up for Perry's non-blocking stream-start symmetry note:
Fresh verification after commit
|
b3e696b to
5a01929
Compare
ai@7 is ESM-only and requires Node >=22; package.json now declares engines.node >=22, so the CI and publish workflows must match to avoid running install/test/build on an unsupported Node version.
- v7 rejects {role:'system'} in messages[] by default; the cache-control
tests intentionally attach cacheControl to a system message, so they now
pass allowSystemInMessages: true (issue-234, issue-341, issue-389).
- v7 excludes response bodies by default; opt in via
include: { responseBody: true } so result.response.body is populated (issue-432).
5a01929 to
777f517
Compare
|
Heads up: I force-pushed this branch only to fix commit attribution. All commits are now authored by the personal No new code changes were introduced by the force-push. |
|
Hi, any update on this PR? |
waiting on any feedback or update 😅 |
|
any update? 🔔 |
|
Just here to spread word that we also need this, this is a desired PR. thank you for your work! 🙌 |
|
Tagging @robert-j-y @Robinnnnn - apologies if not the right people, just saw y'all have committed recently |
|
Bugbot is not enabled for this team, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Small follow-up pushed: while rerunning the live issue tests, I found one more AI SDK v7 semantics case in That test intentionally sends a Reverified locally after the push:
Could a maintainer approve the workflow run for the latest fork push when convenient? |
There was a problem hiding this comment.
Perry's Review
Incremental re-review of the AI SDK v7 migration. Since my last review at b1e685d, the sole delta is one added line in the issue-196 1-hour-cache e2e regression test, enabling the AI SDK v7 opt-in that permits a system-role entry inside the messages array.
Verdict: 💬 Comments / questions
Details
Scope: incremental — 1 new line since prior review (b1e685d → 9e2941c)
Risk: 🟢 Low — test-only change; no production code touched since last review.
Delta reviewed: the added flag is the correct AI SDK v7 requirement. In v7, a system-role message placed inside the messages array is rejected by default (opting in also carries a documented prompt-injection caveat when the messages array is user-controlled). Here the content is static test fixture data, so the opt-in is safe, and this regression test must keep the exact message structure the issue reported — so switching to the top-level system property would change what is under test. The change is consistent with the sibling cache e2e tests, which set the same flag.
CI: the repo CI workflow is in an action_required state on the head SHA (a GitHub gate awaiting maintainer approval to run for this contributor), not a check failure. No failing checks. Perry does not gate its verdict on CI — branch protection handles merge-blocking.
Findings: none on the delta. No net-new nits regenerated on already-reviewed code (differential-scope re-review).
Codex (heavy second opinion): ran; all surfaced items target chat adapter code that is unchanged since the prior review — out of differential scope, not re-litigated here.
Analysis lanes: no verified findings.
Research: confirmed against the AI SDK v7 prompts docs — system messages in the messages array are opt-in via this flag in v7; the top-level system/instructions property is the alternative for non-reproduction cases.
Security: no concerns — test-only, static fixture content.
Test coverage: the change keeps the issue-196 regression test runnable under v7.
Unresolved threads: none.
Review: tier=large · model=claude-opus-latest · score=11.3
|
Hey folks - still blocked here for an upgrade, Could a mantainer look ? |
|
Please please please! 🙏 |
|
Thanks everyone for the support here 🙏 |
|
This is merged, lets keep an eye out for any issues that may come up from the community! |
…536) * fix(completion): finish AI SDK v7 migration for the completion model The v7 migration (#511) updated the chat model but left the completion model non-functional under AI SDK v7: - The AI SDK always sends a default toolChoice of { type: 'auto' }, even when no tools are configured, so every generateText/streamText call through the completion model threw UnsupportedFunctionalityError. Only reject tool choices that actually request tool usage. - doStream emitted bare text-delta parts, each with a fresh generated id and no text-start/text-end events. AI SDK v7 consumers drop deltas that do not belong to a started text part, so streamed text never reached result.text. Mirror the chat model's text lifecycle: emit text-start once with a stable id, reuse that id for every delta, and emit text-end in flush. Adds regression tests that call generateText/streamText from the ai package against the mock server, updates the stream unit test to expect the lifecycle events, and includes a patch changeset. * fix(completion): accept toolChoice none and tidy text lifecycle ids - Only reject 'required' and 'tool' tool choices; 'none' is satisfiable without tools. - Use textId as the started flag and drop the unreachable generateId() fallbacks. - Move the AI SDK integration tests into the existing doGenerate/doStream suites instead of a second test server for the same URL. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Luke Parke <5702154+LukasParke@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Fixes #510.
Design choice
Chose (A) v7-only. AI SDK v7 is Node >=22 and ESM-only, and first-party v7-line providers such as
@ai-sdk/openai@4target@ai-sdk/provider@4V4 interfaces. Keeping v6 support would require compatibility branching around provider/model specs, file payloads, tool factories, packaging, and usage shapes, so this is a major release.Summary
aito^7,@ai-sdk/providerto^4, and@ai-sdk/provider-utilsto^5; peers onai@^7.0.0.LanguageModelV4, including V4 content/file payloads, provider tools, reasoning, structured outputs, cache-control passthrough, tool calls, and stream lifecycle events.generateAudiocall option.createProviderDefinedToolFactory/ProviderDefinedToolFactory.type: module, Node >=22, and no CommonJS export branch.Usage/token remapping
Provider usage now follows the V4 internal shape:
inputTokens.cacheRead/cacheWrite/noCacheandoutputTokens.reasoning/text. In AI SDK v7 public results, cached input tokens are read fromusage.inputTokenDetails.cacheReadTokensand reasoning tokens fromusage.outputTokenDetails.reasoningTokens; OpenRouter-specific usage details remain underproviderMetadata.openrouter.usage.Local checks
Baseline on upstream
mainbefore migration:Final checks on this branch:
pnpm test:e2eandpnpm test:issueswere not run because they hit the real OpenRouter API and requireOPENROUTER_API_KEY.Release notes