Skip to content

feat(ai)!: upgrade to AI SDK v7 (parity + seam hardening)#40

Merged
bratsos merged 1 commit into
mainfrom
chore/ai-sdk-v7
Jul 13, 2026
Merged

feat(ai)!: upgrade to AI SDK v7 (parity + seam hardening)#40
bratsos merged 1 commit into
mainfrom
chore/ai-sdk-v7

Conversation

@bratsos

@bratsos bratsos commented Jul 12, 2026

Copy link
Copy Markdown
Owner

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/codemod does 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 keeps system/onFinish/onStepFinish/totalUsage as working deprecated aliases, so only a handful of things actually needed to change.

Breaking changes (TypeScript; pre-1.0 minor)

  • ProviderResolver and registerEmbeddingProvider now type against LanguageModelV4/EmbeddingModelV4 (the @ai-sdk/provider@4 interface). Consumers passing their own provider must supply a v7 provider.
  • TextOptions.experimental_outputoutput (the one v7 param renamed with no alias).
  • onStepFinishonStepEnd on TextOptions/ObjectOptions/StreamOptions.
  • streamText input systeminstructions.

The batch API's own system field is unchanged (it's not the streamText system). No runtime behavior change; cost/usage accounting is identical.

Seam hardening

  • The stream onFinish callback (previously an untyped hand-written inline shape reading totalUsage) is now onEnd typed with the SDK's exported GenerateTextEndEvent<ToolSet>, reading event.usage with a totalUsage fallback — so a future SDK shape change surfaces at compile time.
  • Removed the two aiGenerateText(... as any) casts; they now use the typed as Parameters<typeof aiGenerateText>[0] (still needed to dodge NoInfer<TTools>, but no longer any).
  • getReasoning() prefers result.finalStep.reasoningText (v7 canonical) with the deprecated top-level as fallback.

Extra fix caught during migration

v7 widened Tool.description to string | ((options) => string) (dynamic descriptions). Batch tool defs are static, so anthropic-batch.ts now coerces tool.description to a string.

Verification

  • pnpm -r typecheck clean across all four packages.
  • Tests: core 1095 passed / 1 skipped (matches main), host packages 118 passed.
  • Lint clean.

Docs

  • Changeset (ai-sdk-v7.md, minor).
  • New migration guide migrate-0.11-to-0.12.md (mirrors the 0.10→0.11 structure) covering the four renames and the provider-interface change for custom ProviderResolver/embedding providers.
  • Skill reference 04-ai-integration.md updated to v7 names.

Not in this PR

The consumer-surface expansion (full usage detail → cost ledger, toolApproval → Approval conventions, telemetry → OTel, result richness, messages on text/object, unified reasoning option) lands as a separate PR stacked on this one.

@bratsos bratsos merged commit 8bab603 into main Jul 13, 2026
4 checks passed
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.

1 participant