feat(ai)!: upgrade to AI SDK v7 (parity + seam hardening)#40
Merged
Conversation
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.
Summary
Upgrades the AI layer from AI SDK v6 → v7 (
ai@7,@ai-sdk/provider@4,@ai-sdk/google@4,@openrouter/ai-sdk-provider@3). This is the parity + seam-hardening pass — zero intended runtime behavior change; the follow-up PR adds the new consumer-facing surface (usage detail,toolApproval, telemetry, etc.).Targets 0.12 and is independent of the pending 0.11 release.
Approach
A measurement spike first established that the official
@ai-sdk/codemoddoes net harm here — it renames object properties by name and half-renamed our own internal types. So the codemod output was discarded and the real changes hand-applied. The measured break surface turned out small: v7 keepssystem/onFinish/onStepFinish/totalUsageas working deprecated aliases, so only a handful of things actually needed to change.Breaking changes (TypeScript; pre-1.0 minor)
ProviderResolverandregisterEmbeddingProvidernow type againstLanguageModelV4/EmbeddingModelV4(the@ai-sdk/provider@4interface). Consumers passing their own provider must supply a v7 provider.TextOptions.experimental_output→output(the one v7 param renamed with no alias).onStepFinish→onStepEndonTextOptions/ObjectOptions/StreamOptions.system→instructions.The batch API's own
systemfield is unchanged (it's not the streamTextsystem). No runtime behavior change; cost/usage accounting is identical.Seam hardening
onFinishcallback (previously an untyped hand-written inline shape readingtotalUsage) is nowonEndtyped with the SDK's exportedGenerateTextEndEvent<ToolSet>, readingevent.usagewith atotalUsagefallback — so a future SDK shape change surfaces at compile time.aiGenerateText(... as any)casts; they now use the typedas Parameters<typeof aiGenerateText>[0](still needed to dodgeNoInfer<TTools>, but no longerany).getReasoning()prefersresult.finalStep.reasoningText(v7 canonical) with the deprecated top-level as fallback.Extra fix caught during migration
v7 widened
Tool.descriptiontostring | ((options) => string)(dynamic descriptions). Batch tool defs are static, soanthropic-batch.tsnow coercestool.descriptionto a string.Verification
pnpm -r typecheckclean across all four packages.Docs
ai-sdk-v7.md, minor).migrate-0.11-to-0.12.md(mirrors the 0.10→0.11 structure) covering the four renames and the provider-interface change for customProviderResolver/embedding providers.04-ai-integration.mdupdated to v7 names.Not in this PR
The consumer-surface expansion (full usage detail → cost ledger,
toolApproval→ Approval conventions,telemetry→ OTel, result richness,messageson text/object, unifiedreasoningoption) lands as a separate PR stacked on this one.