feat(ai-sdk-middleware)!: support AI SDK v7 (provider spec V4)#43
Conversation
Migrate the middleware from AI SDK v6 (provider spec V3) to v7 (V4): - specificationVersion 'v3' -> 'v4'; public types LanguageModelV3* -> V4* - handle V4 FilePart.data tagged union (SharedV4FileData) in the prompt adapter via fileDataSignal(); binary/URL payloads still round-trip losslessly - bump peers to ai>=7 / @ai-sdk/provider>=4; build/dev deps to ai@7 / provider@4 - migrate test fixtures and assertions to V4 shapes AI SDK v7's wrapLanguageModel rejects v3-spec middleware, so this requires AI SDK v7. Released as 2.0 (changeset); v6 users stay on the 1.x line. Verified: tsc --noEmit clean, 126 tests pass, biome clean, full monorepo typecheck/test/build green (core + tanstack-ai untouched).
…apter
Review follow-up: the bump to @ai-sdk/provider-utils@5 widened app-level
FilePart.data to also accept V4 tagged shapes ({ type: 'data', data }, …),
not just the bare shorthand. modelMessageAdapter read it via
`typeof part.data === 'string'`, so a tagged inline-string payload recorded
an empty attachment presence signal — an asymmetry with the provider-prompt
adapter the two are documented to keep in sync.
Add a local fileDataSignal() (parallel to adapter.ts) covering both the bare
shorthand and the tagged { type: 'data', data: string } form; add a fixture
asserting the tagged signal + verbatim round-trip. Image parts unchanged.
Review pass (fresh-eyes code review)Ran an independent review of the diff. No critical/important issues — the V3→V4 migration is correct (usage One sub-threshold finding was acted on (commit Verification: tsc clean · 127 tests green · biome clean · full monorepo typecheck/test/build green (core + tanstack-ai untouched). |
These were marked '@deprecated … removed in the next major'; 2.0 is that major. Removed: - planCompaction / compactHistory / CompactionPlan (provider-prompt altitude) — use the ModelMessage-altitude equivalents (planCompactionModelMessages / compactModelMessages / CompactionPlanModelMessages) - onBudgetExceeded on ContextChefOptions — use onBeforeCompress Drop the now-unused fromAISDK/toAISDK + provider type imports in compaction.ts and the onBeforeCompress ?? onBudgetExceeded fallback in createJanitor. Delete tests/compaction.test.ts (covered only the removed fns; the turn-split algorithm is tested in core and at the ModelMessage boundary). Retarget the budget-exceeded hook test to onBeforeCompress (preserves coverage). Folded into the 2.0 changeset. Verified: tsc clean, 119 tests, biome clean, full monorepo green.
|
Landed the deprecated-API cleanup as commit |
Review of the cleanup surfaced shipped docs still pointing at APIs this 2.0 removed or at the old v6 spec: - README: dropped the compactHistory / planCompaction sections (removed APIs; the ModelMessage equivalents are already documented above) - middleware skill (SKILL.md + references/api-reference.md): LanguageModelV3 -> V4, onBudgetExceeded -> onBeforeCompress, 'ai (v6+)/(v3+)' -> (v7+)/(v4+) - core README: the 'ai-sdk users: prefer ...' pointer now references compactModelMessages / planCompactionModelMessages (core's own planCompaction/compactHistory docs are unchanged — core still ships them) Docs-only; no src/test changes. Repo-wide grep confirms no remaining references to the removed middleware APIs.
Summary
Adds AI SDK v7 (provider spec V4) support to
@context-chef/ai-sdk-middleware. Released as a major (2.0): AI SDK v7'swrapLanguageModelrejects a v3-spec middleware at the type level, so v7 support cannot coexist with v6 in one published artifact. v6 users stay on the existing1.xline — no existing user is broken.What changed
specificationVersion: 'v4'); all public typesLanguageModelV3*→LanguageModelV4*.FilePart.data(now theSharedV4FileDatatagged union) via a smallfileDataSignal()helper — at both the provider altitude (adapter.ts) and the appModelMessagealtitude (modelMessageAdapter.ts, where provider-utils@5 wideneddatatoo). Binary / URL / inline payloads still round-trip losslessly; runtime behavior unchanged.ai>=7/@ai-sdk/provider>=4.planCompaction/compactHistory/CompactionPlan(provider-prompt altitude → use theModelMessageequivalents), andonBudgetExceeded(→onBeforeCompress).onBeforeCompress; staleV3comments corrected.2.x= v7 /1.x= v6 split.Scope
@context-chef/ai-sdk-middleware.@context-chef/corehas noai/@ai-sdkdependency (verified) and is untouched;@context-chef/tanstack-aiis out of scope.Durable in-loop compaction on v7
No new API needed: AI SDK v7 fixed vercel/ai#9631 so
prepareStep-returned messages now persist across steps. That makescompactModelMessages()inside aToolLoopAgentprepareStepgenuinely durable on v7 (it wasn't on v6). Documented in the changeset.Verification
tsc --noEmitclean (incl. tests)vitest: 119/119 pass in this packagebiome check: cleanCommits
feat!: V3→V4 migration (AI SDK v7 support)fix: handle V4 tagged file data in the app-altitude ModelMessage adapter (review follow-up)refactor!: remove deprecated compaction APIs (planCompaction/compactHistory/CompactionPlan,onBudgetExceeded) — 2.0 is the major they were slated for