fix(vercel-ai-sdk): inject the provider version at build instead of hardcoding it

Review finding from @karthik-indla on this PR. src/mem0-utils.ts carried
PROVIDER_VERSION = "3.0.2" as a literal. It matches package.json today and
misreports the client version from the next release bump onwards, which is the
one thing X-Mem0-Client exists to carry. Every other client in the repo injects
at build: mem0-ts via __MEM0_SDK_VERSION__, the Python side via
importlib.metadata, the CLIs via __CLI_VERSION__.

tsup now defines __MEM0_PROVIDER_VERSION__ from package.json, and the source
falls back to "dev" only when run unbundled, such as in tests. Verified in the
built bundle: PROVIDER_VERSION resolves to "3.0.2" and no placeholder survives.

resolveJsonModule is enabled alongside it, matching mem0-ts, because tsc
--noEmit covers tsup.config.ts and the package.json import fails without it.

Type check clean, build clean. The jest suite's failure is pre-existing and
unrelated: it requires a live MEM0_API_KEY, confirmed by running it on a stashed
tree. Python side 311 passed, 8 skipped; pi-agent 94 passed.

Claude-Session: https://claude.ai/code/session_01C7tEmH86HAr7GoAAKCEHZb
This commit is contained in:
Saket Aryan
2026-09-16 22:16:20 +05:30
parent 75a2952004
commit 92aa8a1de1
3 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -1,4 +1,9 @@
const PROVIDER_VERSION = "3.0.2";
declare const __MEM0_PROVIDER_VERSION__: string | undefined;
// Replaced at build time by tsup `define`. The fallback only applies when the
// source is run unbundled, such as in tests.
const PROVIDER_VERSION =
typeof __MEM0_PROVIDER_VERSION__ !== "undefined" ? __MEM0_PROVIDER_VERSION__ : "dev";
import { LanguageModelV3Prompt } from '@ai-sdk/provider';
import { Mem0ConfigSettings } from './mem0-types';
+1
View File
@@ -12,6 +12,7 @@
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"types": ["@types/node", "jest"],
@@ -1,4 +1,5 @@
import { defineConfig } from 'tsup'
import pkg from './package.json'
export default defineConfig([
{
@@ -6,5 +7,11 @@ export default defineConfig([
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
sourcemap: true,
// Injected rather than written in the source. A hardcoded literal matches
// package.json on the day it is written and misreports the client version
// from the next release bump onwards. Same mechanism as mem0-ts.
define: {
__MEM0_PROVIDER_VERSION__: JSON.stringify(pkg.version),
},
},
])