chore: upgrade AI SDK v6 → v7 (api)#716
Conversation
Bump to v7: ai 6.0.190 → 7.0.2; @ai-sdk/{anthropic,google,openai} 3 → 4;
@ai-sdk/gateway 3 → 4; @ai-sdk/mcp 1 → 2. (Zod already v4.)
The agent harness survived v7 intact — ToolLoopAgent, the agent loop, and
context passthrough all still exist. This was a rename + typed-context
migration, not a redesign.
Codemod handled the mechanical renames (isToolOrDynamicToolUIPart →
isToolUIPart, experimental_generateImage → generateImage, stepCountIs →
isStepCount, system → instructions, experimental_context → context, etc.).
Manual work, by category:
- Typed tool context (the real v7 change): v7 infers a tool's context as
`never` unless declared, which broke both `tool()` overloads (TS2769) and
`toolsContext`. Annotated every context-using tool's execute 2nd arg as
`ToolExecutionOptions<AgentContext>` (bash/glob/grep/task/webFetch/read/
write/edit/skill). v7 also split the old single `experimental_context` into
a per-tool-name `toolsContext` map — added `buildToolsContext()` to fan the
one AgentContext out to every tool key; wired it into runAgentStep + taskTool.
- Usage token shape: v7 nests details under inputTokenDetails/outputTokenDetails
and drops top-level reasoningTokens/cachedInputTokens. Fixed
addLanguageModelUsage (codemod had doubled a path), ZERO_USAGE,
recordCreditDeduction.
- Provider options: GoogleProviderOptions → GoogleGenerativeAIProviderOptions.
- ToolLoopAgent gained a 4th (runtime-context) generic — updated RoutingDecision
/ ChatConfig agent types to v7 arity.
- Reverted codemod over-applications: local generateText/generateArray `{system}`
wrappers (pass `instructions: system` inward), toolChain `system`→`instructions`
on the custom ToolChainItem/PrepareStepResult types, webFetch discriminant
`as const` + param-default move (v7 tool() inference).
- Test fixtures aligned to v7 (mock exports + usage/UIMessage shapes); no
weakened assertions.
Verified: source `tsc --noEmit` clean (0 errors), full `pnpm test` green
(3676 passed / 659 files). Pre-existing test-file type-debt in unrelated
domains left untouched. Full build validated on Vercel preview.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 55 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (22)
📒 Files selected for processing (25)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
No issues found across 46 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Client as Client / Request
participant Workflow as runAgentWorkflow
participant Step as runAgentStep
participant SDK as AI SDK v7 (streamText)
participant Tools as Agent Tools (bash/glob/grep/read/write/edit/skill/task/webFetch)
participant TaskTool as taskTool (subagent)
participant SubSDK as AI SDK v7 (subagent streamText)
participant SubTools as Subagent Tools
Note over Client,SubTools: Agent Step Execution (v7 migration)
Client->>Workflow: runAgentWorkflow(messages, chatId)
Workflow->>Workflow: Build DurableAgentContext
alt New Step
Workflow->>Step: runAgentStep(context, tools, messages)
Step->>Step: buildToolsContext(tools, agentContext)
Note over Step: Fans single AgentContext to per-tool map
Step->>SDK: streamText({ model, instructions, messages, tools, toolsContext, stopWhen: isStepCount(111) })
Note over Step,SDK: instructions replaces system,<br/>toolsContext replaces experimental_context
SDK->>Tools: execute() with ToolExecutionOptions<AgentContext>
alt Bash/Glob/Grep Tool
Tools->>Tools: Destructure { context } from ToolExecutionOptions
Tools->>Tools: Read sandbox, workingDirectory from context
Tools-->>SDK: Result
else Read/Write/Edit/Skill Tool
Tools->>Tools: Destructure { context } from ToolExecutionOptions
Tools-->>SDK: Result
else webFetch Tool
Tools->>Tools: method = methodInput ?? "GET" (default in body)
Tools-->>SDK: Result with as const discriminant
else taskTool
Step->>TaskTool: execute(task, instructions, { context, abortSignal }: ToolExecutionOptions<AgentContext>)
TaskTool->>TaskTool: getSubagentModel(context)
TaskTool->>SubTools: buildSubagentTools()
TaskTool->>TaskTool: buildToolsContext(subagentTools, context)
Note over TaskTool: Build subagent tool context map
TaskTool->>SubSDK: streamText({ model, instructions, prompt, tools, toolsContext, stopWhen: isStepCount(2) })
Note over TaskTool,SubSDK: Subagent uses its own streamText call
SubSDK-->>TaskTool: stream (yield tool-call/finish parts)
loop For each part in result.stream
TaskTool->>TaskTool: Aggregate tool calls and usage
TaskTool-->>Step: Yield TaskToolOutput chunks
end
TaskTool-->>Tools: Final result
end
Step->>Step: onStepEnd / onEnd callbacks capture responseMessage
Note over Step: onStepEnd replaces onStepFinish,<br/>onEnd replaces onFinish
SDK-->>Step: stream result
Step-->>Workflow: StepResult with responseMessage, usage
end
Workflow->>Workflow: addLanguageModelUsage(accumulated, step.usage)
Note over Workflow: Usage shape: inputTokenDetails.cacheReadTokens,<br/>no top-level reasoningTokens/cachedInputTokens
Workflow->>Workflow: recordCreditDeduction with usage
Note over Workflow: Reads usage.inputTokenDetails.cacheReadTokens
Workflow-->>Client: Response
Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.
Requires human review: Major AI SDK v6→v7 upgrade across 46 files with API renames and structural changes; high risk for production regressions.
Re-trigger cubic
CI on the v7 bump surfaced three failures (code was correct; tooling wasn't): - lint: `@typescript-eslint/no-explicit-any` on the `ToolLoopAgent` 4th (runtime-context) generic in RoutingDecision/ChatConfig → use `Record<string, unknown>` (which is v7's `Context` constraint, and the source agent's inferred `any` slot is assignable to it). - format: prettier on two v7-updated test fixtures. - Vercel build: `Error: dynamic usage of require is not supported` while collecting page data for the Workflow step route — `@vercel/oidc` (pulled in by `@ai-sdk/gateway@4`) does a dynamic require Turbopack can't bundle. Switch the build to `next build --webpack` (which tolerates it), matching what chat and marketing already use. Verified locally: webpack compiles the Workflow routes; the require error is gone (remaining local failures are env-only, present on Vercel). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
0 issues found across 4 files (changes from recent commits).
Requires human review: Major AI SDK v6→v7 upgrade with changes to tool context, usage token shape, and callback renames across agent tools and workflow logic. High impact requires human review.
Re-trigger cubic
Webpack got past Turbopack's "dynamic require" refusal, but then the Workflow
step route failed at runtime: bundling `@vercel/oidc/index.js` made its
internal `require('./get-vercel-oidc-token.js')` resolve to a relative path
that doesn't exist on Vercel ("Cannot find module …/get-vercel-oidc-token.js").
Fix: add `@vercel/oidc` to `serverExternalPackages` (+ as a direct dependency
so it's resolvable). Node then loads the package — and its internal require —
natively instead of bundling it. Pairs with the `next build --webpack` switch;
Turbopack refuses to externalize it ("can't be external").
Verified locally (webpack): the Workflow routes compile and collect page data
with no @vercel/oidc error; only env-dependent routes fail locally (env present
on Vercel).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Requires human review: Core AI SDK v6→v7 upgrade with changes to tool context, streaming callbacks, and usage tracking; requires human review due to high risk of runtime breakage.
Re-trigger cubic
✅ All checks green under AI SDK v7
The build fix (worth recording for
|
The hard one in the monorepo-wide AI SDK v6→v7 migration (chat#1816). Targets
test. Key outcome: v7's agent abstraction survived intact (ToolLoopAgent, the agent loop, context passthrough all still exist) — this was a rename + typed-context migration, not the ground-up redesign we feared.Versions
ai6.0.190→7.0.2@ai-sdk/{anthropic,google,openai}3→4,@ai-sdk/gateway3→4,@ai-sdk/mcp1→2 (Zod already v4)The real v7 change: typed tool context
v7 infers a tool's context type as
neverunless declared, which broke both thetool()overloads (TS2769) and thetoolsContextoption. Fix: annotate every context-using tool'sexecutesecond arg asToolExecutionOptions<AgentContext>(bash/glob/grep/task/webFetch/read/write/edit/skill). v7 also split the singleexperimental_contextinto a per-tool-nametoolsContextmap — addedlib/agent/tools/buildToolsContext.tsto fan the oneAgentContextout to every tool key; wired intorunAgentStep+taskTool.Other manual work
inputTokenDetails/outputTokenDetails, drops top-levelreasoningTokens/cachedInputTokens(addLanguageModelUsage— codemod had doubled a path,ZERO_USAGE,recordCreditDeduction).GoogleProviderOptions→GoogleGenerativeAIProviderOptions.ToolLoopAgentgained a 4th (runtime-context) generic → updatedRoutingDecision/ChatConfigagent types.generateText/generateArray{ system }wrappers (passinstructions: systeminward), toolChainsystem→instructionson customToolChainItem/PrepareStepResulttypes, webFetch discriminantas const+ param-default move.isToolOrDynamicToolUIPart→isToolUIPart,stepCountIs→isStepCount,system→instructions,experimental_context→context,experimental_generateImage→generateImage).UIMessageshapes); no weakened assertions.Verification (local)
tsc --noEmit(source)pnpm test(~199 pre-existing
__tests__type-debt errors in unrelated domains — Slack/Privy/Resend — left untouched; all tests pass at runtime.next buildneeds env → validated on the Vercel preview.)Tracking: chat#1816. Merge target
test; synctest→mainper repo flow on release. Sibling: chat#1817.🤖 Generated with Claude Code
Summary by cubic
Upgrade API to AI SDK v7, replacing
experimental_contextwith typed per-tooltoolsContextand adopting v7 APIs. Preserves the agent loop; adds a build fix by externalizing@vercel/oidc.Dependencies
ai6.0.190→7.0.2@ai-sdk/{anthropic,google,openai}^3→^4,@ai-sdk/gateway^3→^4,@ai-sdk/mcp^1→^2@vercel/oidcas a direct dependencyMigration
executewithToolExecutionOptions<AgentContext>; addedbuildToolsContext()and wired intorunAgentStepandtaskTool.system→instructions,experimental_context→context,stepCountIs→isStepCount,fullStream→stream.inputTokenDetails/outputTokenDetails; update zero-usage and credit deduction to readinputTokenDetails.cacheReadTokens.ToolLoopAgentgeneric arity updated;RoutingDecision/ChatConfignow useRecord<string, unknown>for the runtime-context slot.next build --webpackand externalize@vercel/oidcviaserverExternalPackagesto avoid dynamic require issues from@ai-sdk/gateway@4.onStepFinish→onStepEnd,onFinish→onEnd); minor tool fixes (keepwebFetchdefaults in-body fortool()inference).Written for commit dfc4803. Summary will update on new commits.