fix: withSupermemory incompatible with AI SDK 6 — preserve prototype properties via Proxy#853
Closed
vorflux[bot] wants to merge 3 commits intomainfrom
Closed
fix: withSupermemory incompatible with AI SDK 6 — preserve prototype properties via Proxy#853vorflux[bot] wants to merge 3 commits intomainfrom
vorflux[bot] wants to merge 3 commits intomainfrom
Conversation
added 3 commits
April 15, 2026 19:12
…AI SDK 6 compatibility
Replace object spread with Object.create + Object.defineProperties to preserve
prototype getters (e.g. `provider`) that AI SDK v4/v5/v6 models define on their
class prototype rather than as own properties.
The spread operator `{ ...model }` only copies own enumerable properties, which
causes prototype getters like `provider` to become `undefined` on the wrapped
model. This triggers AI_UnsupportedModelVersionError at runtime with AI SDK 6.
The fix:
1. Creates the wrapper via Object.create(Object.getPrototypeOf(model)) to
inherit all prototype properties (getters, methods)
2. Copies all own property descriptors via Object.getOwnPropertyDescriptors
3. Overrides doGenerate/doStream on the instance to shadow the inherited ones
Tested with real OpenAI API calls against AI SDK v4, v5, and v6.
Closes #852
Addresses review feedback about ES private fields breaking with Object.create + Object.defineProperties approach: Source changes (packages/tools/src/vercel/index.ts): - Replace Object.create/Object.defineProperties with a Proxy that delegates property access to the original model instance. This preserves prototype getters, ES private fields (#field), and instance brand checks since 'this' inside getters remains the real model instance. - Extract doGenerate/doStream overrides into named functions (wrappedDoGenerate/wrappedDoStream) for clarity. - Remove one-use 'descriptors' intermediate variable (inlined). Test changes (packages/tools/test/with-supermemory/unit.test.ts): - Remove duplicate test 'should preserve all V3 metadata after wrapping' (strict subset of prototype getter test). - Add MockLanguageModelV3WithPrivateFields class using true ES private fields (#config) to catch TypeError that would occur with Object.create-based wrapping. - Add test 'should handle V3 models with ES private fields' that verifies the Proxy approach works with private field access. - Clean up 'valid API key' test to be intentionally minimal (property preservation covered by dedicated V2/V3 suites).
…rototype props The 'in' operator checks the entire prototype chain, so 'constructor' in overrides would match Object.prototype.constructor and return undefined from the overrides map. Use hasOwnProperty.call() to only match own keys (doGenerate, doStream).
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
supermemory-app | ee9bfe7 | Commit Preview URL Branch Preview URL |
Apr 15 2026, 07:35 PM |
Member
Contributor
Author
|
Thanks for the heads up @MaheshtheDev! Looks like #854 addresses the same root cause (spread dropping prototype properties) with a similar Proxy approach. Happy to defer to whichever PR the maintainers prefer to merge -- the core fix is the same in both. |
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
Fixes #852 —
withSupermemorythrowsAI_UnsupportedModelVersionErrorwhen used with AI SDK 6 (LanguageModelV3) models.Root Cause
The
wrapVercelLanguageModelfunction used object spread ({ ...model, doGenerate: ..., doStream: ... }) to wrap the model. The spread operator only copies own enumerable properties, but AI SDK v4/v5/v6 models are class instances whereprovider,doGenerate, anddoStreamare defined as prototype getters/methods. This causedproviderto becomeundefinedon the wrapped model, triggeringAI_UnsupportedModelVersionErrorat runtime.Fix
Replaced the object spread with a Proxy-based delegation pattern:
Proxyinterceptsgetoperations on the modeldoGenerateanddoStream— returns the memory-aware overridesReflect.get(target, prop, target), ensuringthisinside prototype getters remains the real model instanceThis preserves:
providerin V3 models)#config) — future-proof against SDK changesChanges
packages/tools/src/vercel/index.ts— replaced spread with Proxy delegationpackages/tools/test/with-supermemory/unit.test.ts— added V3 compatibility tests (prototype getters, ES private fields, Proxy correctness)Testing
Unit Tests (14/14 passing)
Cross-Version Real API Tests (v4, v5, v6 — all passing)
Tested with real OpenAI API calls (
gpt-4o-mini) against three isolated SDK installations:AI SDK v4 (specificationVersion: v1) — ALL PASSED
specificationVersion,provider,modelIdall preservedgenerateTextreturned valid responsestreamTextreturned valid responseAI SDK v5 (specificationVersion: v2) — ALL PASSED
specificationVersion,provider,modelId,supportedUrlsall preservedgenerateTextreturned valid responsestreamTextreturned valid responseAI SDK v6 (specificationVersion: v3) — ALL PASSED
specificationVersion,provider,modelId,supportedUrlsall preservedgenerateTextreturned valid responsestreamTextreturned valid responseBuild
Build succeeds with no errors.
Session Details
(aside)to your comment to have me ignore it.