From 3eedaddf9515020d23ff7e6951a52fbc70376e25 Mon Sep 17 00:00:00 2001 From: Sreeram Sreedhar Date: Mon, 1 Jun 2026 21:25:03 -0400 Subject: [PATCH 1/2] add baseUrl to config --- README.md | 2 ++ src/config.ts | 33 +++++++++++++++++++++++++++++---- src/services/client.ts | 13 +++++-------- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 357d747..6ae4b1e 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ anything else fails, they exit cleanly without breaking your Codex session. | Variable | Purpose | | ------------------------------ | ------------------------------------------------------ | | `SUPERMEMORY_CODEX_API_KEY` | Your Supermemory API key (browser auth is preferred). | +| `SUPERMEMORY_API_URL` | Override the Supermemory API base URL (takes precedence over config). | | `SUPERMEMORY_DEBUG` | Set to any truthy value to enable debug logging to `~/.codex-supermemory.log`. | ### `~/.codex/supermemory.json` (optional) @@ -90,6 +91,7 @@ Drop this file in to override defaults: | Key | Type | Default | Description | | ------------------------ | ---------- | -------------- | -------------------------------------------------------------------------------------------- | | `apiKey` | `string` | — | API key (env var takes precedence, browser auth is preferred). | +| `baseUrl` | `string` | `https://api.supermemory.ai` | Supermemory API base URL (`SUPERMEMORY_API_URL`/`SUPERMEMORY_BASE_URL` env vars take precedence). | | `similarityThreshold` | `number` | `0.6` | Minimum similarity score for retrieved memories. | | `maxMemories` | `number` | `5` | Max memories injected per prompt. | | `maxProfileItems` | `number` | `5` | Max profile items considered. | diff --git a/src/config.ts b/src/config.ts index 8680506..42c08f5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,6 +5,7 @@ import { loadCredentialData, loadCredentials } from "./services/auth.js"; export const CONFIG_FILE = join(homedir(), ".codex", "supermemory.json"); export const PLUGIN_VERSION = "1.0.7"; +export const DEFAULT_BASE_URL = "https://api.supermemory.ai"; export interface CustomContainer { tag: string; @@ -13,6 +14,7 @@ export interface CustomContainer { interface CodexSupermemoryConfig { apiKey?: string; + baseUrl?: string; similarityThreshold?: number; maxMemories?: number; maxProfileItems?: number; @@ -132,13 +134,36 @@ export function getApiKeyValue(): string | undefined { return SUPERMEMORY_API_KEY; } -export function getApiBaseUrl(): string { - return ( +function normalizeBaseUrl(baseUrl: unknown): string | null { + if (typeof baseUrl !== "string" || !baseUrl.trim()) return null; + + const trimmed = baseUrl.trim(); + try { + const url = new URL(trimmed); + if (url.protocol !== "http:" && url.protocol !== "https:") return null; + return trimmed; + } catch { + return null; + } +} + +export function getBaseUrl(): string { + const configured = process.env.SUPERMEMORY_API_URL || process.env.SUPERMEMORY_BASE_URL || + fileConfig.baseUrl || loadCredentialData()?.apiBaseUrl || - "https://api.supermemory.ai" - ); + DEFAULT_BASE_URL; + const normalized = normalizeBaseUrl(configured); + if (!normalized) { + throw new Error("Invalid baseUrl: expected an absolute http(s) URL"); + } + return normalized; +} + +// Backwards-compatible alias for the credential-based accessor introduced on main. +export function getApiBaseUrl(): string { + return getBaseUrl(); } export function getSignalConfig(): { diff --git a/src/services/client.ts b/src/services/client.ts index 1c78840..da26e07 100644 --- a/src/services/client.ts +++ b/src/services/client.ts @@ -1,14 +1,10 @@ import Supermemory from "supermemory"; -import { CONFIG, isConfigured, getApiBaseUrl, getApiKeyValue, PLUGIN_VERSION } from "../config.js"; +import { CONFIG, isConfigured, getApiKeyValue, getBaseUrl, PLUGIN_VERSION } from "../config.js"; import { log } from "./logger.js"; import type { MemoryType } from "../types/index.js"; const TIMEOUT_MS = 30000; const SPACE_NAME_TIMEOUT_MS = 5000; -const API_URL = - process.env.SUPERMEMORY_API_URL || - process.env.SUPERMEMORY_BASE_URL || - "https://api.supermemory.ai"; const CODEX_SOURCE = "codex"; function withTimeout(promise: Promise, ms: number): Promise { @@ -101,7 +97,7 @@ export class SupermemoryClient { // writes to the Codex plugin in PostHog / `document.source`. this.client = new Supermemory({ apiKey: getApiKeyValue(), - baseURL: getApiBaseUrl(), + baseURL: getBaseUrl(), defaultHeaders: { "x-sm-source": CODEX_SOURCE }, }); } @@ -270,8 +266,9 @@ export class SupermemoryClient { async updateContainerTagName(containerTag: string, name: string) { log("updateContainerTagName: start", { containerTag, name }); try { + const baseUrl = getBaseUrl(); const currentResponse = await withTimeout( - fetch(`${API_URL}/v3/container-tags/${encodeURIComponent(containerTag)}`, { + fetch(`${baseUrl}/v3/container-tags/${encodeURIComponent(containerTag)}`, { headers: { Authorization: `Bearer ${getApiKeyValue()}`, }, @@ -303,7 +300,7 @@ export class SupermemoryClient { } const response = await withTimeout( - fetch(`${API_URL}/v3/container-tags/${encodeURIComponent(containerTag)}`, { + fetch(`${baseUrl}/v3/container-tags/${encodeURIComponent(containerTag)}`, { method: "PATCH", headers: { Authorization: `Bearer ${getApiKeyValue()}`, From 1773fcfa2b259cdd692752f166d81c1cc03dcf03 Mon Sep 17 00:00:00 2001 From: Sreeram Sreedhar Date: Tue, 9 Jun 2026 22:54:19 -0700 Subject: [PATCH 2/2] chore: bump version to 1.0.8 Co-Authored-By: Claude Opus 4.8 (1M context) --- package-lock.json | 4 ++-- package.json | 2 +- src/config.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 648d894..3ccf5c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codex-supermemory", - "version": "1.0.7", + "version": "1.0.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "codex-supermemory", - "version": "1.0.7", + "version": "1.0.8", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/package.json b/package.json index b6075b9..989a37f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codex-supermemory", - "version": "1.0.7", + "version": "1.0.8", "description": "Persistent memory for OpenAI Codex CLI — powered by Supermemory", "type": "module", "main": "dist/cli.js", diff --git a/src/config.ts b/src/config.ts index 42c08f5..fe3c08f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,7 +4,7 @@ import { homedir } from "node:os"; import { loadCredentialData, loadCredentials } from "./services/auth.js"; export const CONFIG_FILE = join(homedir(), ".codex", "supermemory.json"); -export const PLUGIN_VERSION = "1.0.7"; +export const PLUGIN_VERSION = "1.0.8"; export const DEFAULT_BASE_URL = "https://api.supermemory.ai"; export interface CustomContainer {