From 00695e3113bfef7945e2e40232cc943cab1ec405 Mon Sep 17 00:00:00 2001 From: Saket Aryan Date: Mon, 20 Apr 2026 18:09:03 +0530 Subject: [PATCH] ci(sdk): require changelog entry on version bump + harden TS telemetry (#4900) --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++ .github/workflows/ts-sdk-ci.yml | 36 +++++++++++++++++++++++ docs/changelog/sdk.mdx | 7 +++++ mem0-ts/src/client/telemetry.ts | 6 +++- mem0-ts/src/global.d.ts | 5 +++- mem0-ts/src/oss/src/utils/telemetry.ts | 6 +++- 6 files changed, 97 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 335494d0f..0f9b89a2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,48 @@ on: - 'mem0/**' - 'tests/**' - 'embedchain/**' + - 'pyproject.toml' jobs: + changelog_check: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Require CHANGELOG entry when Python SDK version changes + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + set -euo pipefail + + extract_version() { + python3 -c "import sys, re; m = re.search(r'^\s*version\s*=\s*\"([^\"]+)\"', sys.stdin.read(), re.M); print(m.group(1) if m else '')" + } + + base_version=$(git show "$BASE_SHA:pyproject.toml" 2>/dev/null | extract_version || echo "") + head_version=$(extract_version < pyproject.toml) + + echo "Base version: ${base_version:-}" + echo "Head version: $head_version" + + if [ -z "$base_version" ] || [ "$base_version" = "$head_version" ]; then + echo "pyproject.toml version unchanged — no CHANGELOG entry required." + exit 0 + fi + + echo "Detected version bump ${base_version} -> ${head_version}. Checking docs/changelog/sdk.mdx…" + + if git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- docs/changelog/sdk.mdx | grep -q .; then + echo "Changelog update present in docs/changelog/sdk.mdx ✅" + else + echo "::error file=pyproject.toml::pyproject.toml version changed from ${base_version} to ${head_version} but docs/changelog/sdk.mdx was not updated in this PR. Add a new entry under the Python tab for v${head_version}." + exit 1 + fi + check_changes: runs-on: ubuntu-latest outputs: diff --git a/.github/workflows/ts-sdk-ci.yml b/.github/workflows/ts-sdk-ci.yml index c1fb0d0c8..8edfdecd8 100644 --- a/.github/workflows/ts-sdk-ci.yml +++ b/.github/workflows/ts-sdk-ci.yml @@ -24,6 +24,42 @@ jobs: ts_sdk: - 'mem0-ts/**' + changelog_check: + needs: check_changes + if: github.event_name == 'pull_request' && needs.check_changes.outputs.ts_sdk_changed == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Require CHANGELOG entry when SDK version changes + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + set -euo pipefail + + base_version=$(git show "$BASE_SHA:mem0-ts/package.json" 2>/dev/null | jq -r .version || echo "") + head_version=$(jq -r .version mem0-ts/package.json) + + echo "Base version: ${base_version:-}" + echo "Head version: $head_version" + + if [ -z "$base_version" ] || [ "$base_version" = "$head_version" ]; then + echo "mem0-ts/package.json version unchanged — no CHANGELOG entry required." + exit 0 + fi + + echo "Detected version bump ${base_version} -> ${head_version}. Checking docs/changelog/sdk.mdx…" + + if git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- docs/changelog/sdk.mdx | grep -q .; then + echo "Changelog update present in docs/changelog/sdk.mdx ✅" + else + echo "::error file=mem0-ts/package.json::mem0-ts/package.json version changed from ${base_version} to ${head_version} but docs/changelog/sdk.mdx was not updated in this PR. Add a new entry under the TypeScript tab for v${head_version}." + exit 1 + fi + build_ts_sdk: needs: check_changes if: needs.check_changes.outputs.ts_sdk_changed == 'true' diff --git a/docs/changelog/sdk.mdx b/docs/changelog/sdk.mdx index 30127625b..30b58e675 100644 --- a/docs/changelog/sdk.mdx +++ b/docs/changelog/sdk.mdx @@ -893,6 +893,13 @@ See the [OSS v1 to v2 migration guide](https://docs.mem0.ai/migration/oss-v1-to- + + +**Bug Fixes:** +- **Telemetry:** SDK version is now injected into telemetry at build time via esbuild's `define`, replacing the two hardcoded version strings in `src/client/telemetry.ts` and `src/oss/src/utils/telemetry.ts`. Previously these were stuck at `2.1.36` and `2.1.34` while the published package was on `3.x`, so every telemetry event was reporting the wrong `client_version`. The placeholder is substituted with a string literal at bundle time — no runtime `require("./package.json")` in the shipped bundle ([#4897](https://github.com/mem0ai/mem0/pull/4897)). + + + **Major Release** — TypeScript SDK with V3 memory pipeline, camelCase parameters, and cleaned-up API surface. diff --git a/mem0-ts/src/client/telemetry.ts b/mem0-ts/src/client/telemetry.ts index 0062c2326..ab5887820 100644 --- a/mem0-ts/src/client/telemetry.ts +++ b/mem0-ts/src/client/telemetry.ts @@ -1,7 +1,11 @@ // @ts-nocheck import type { TelemetryClient, TelemetryOptions } from "./telemetry.types"; -let version = __MEM0_SDK_VERSION__; +// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from +// package.json. In unbundled environments (ts-jest, jest globalSetup) the +// identifier is not defined, so guard with typeof to fall back safely. +let version = + typeof __MEM0_SDK_VERSION__ !== "undefined" ? __MEM0_SDK_VERSION__ : "dev"; // Safely check for process.env in different environments let MEM0_TELEMETRY = true; diff --git a/mem0-ts/src/global.d.ts b/mem0-ts/src/global.d.ts index 2ac217fb8..8f82c1cfc 100644 --- a/mem0-ts/src/global.d.ts +++ b/mem0-ts/src/global.d.ts @@ -1 +1,4 @@ -declare const __MEM0_SDK_VERSION__: string; +// Injected by tsup/esbuild's `define` at build time from package.json. +// May be undefined in unbundled environments (ts-jest, jest globalSetup), +// which is why consumers guard the reference with `typeof`. +declare const __MEM0_SDK_VERSION__: string | undefined; diff --git a/mem0-ts/src/oss/src/utils/telemetry.ts b/mem0-ts/src/oss/src/utils/telemetry.ts index 0fff8be95..9f75f5d05 100644 --- a/mem0-ts/src/oss/src/utils/telemetry.ts +++ b/mem0-ts/src/oss/src/utils/telemetry.ts @@ -4,7 +4,11 @@ import type { TelemetryEventData, } from "./telemetry.types"; -let version = __MEM0_SDK_VERSION__; +// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from +// package.json. In unbundled environments (ts-jest, jest globalSetup) the +// identifier is not defined, so guard with typeof to fall back safely. +let version = + typeof __MEM0_SDK_VERSION__ !== "undefined" ? __MEM0_SDK_VERSION__ : "dev"; // Safely check for process.env in different environments let MEM0_TELEMETRY = true;