diff --git a/src/agent/client.ts b/src/agent/client.ts index 0f90fe9..b277a1b 100644 --- a/src/agent/client.ts +++ b/src/agent/client.ts @@ -53,21 +53,11 @@ export async function getClient() { process.exit(1); } - // Auto-cache: if env vars are set but not in settings, write them to settings - let needsUpdate = false; - const updatedEnv = { ...settings.env }; - + // Auto-cache: if LETTA_API_KEY is set in env but not in settings, write it to settings + // Note: LETTA_BASE_URL is intentionally NOT cached - it should only come from env vars if (process.env.LETTA_API_KEY && !settings.env?.LETTA_API_KEY) { + const updatedEnv = { ...settings.env }; updatedEnv.LETTA_API_KEY = process.env.LETTA_API_KEY; - needsUpdate = true; - } - - if (process.env.LETTA_BASE_URL && !settings.env?.LETTA_BASE_URL) { - updatedEnv.LETTA_BASE_URL = process.env.LETTA_BASE_URL; - needsUpdate = true; - } - - if (needsUpdate) { settingsManager.updateSettings({ env: updatedEnv }); } diff --git a/src/auth/setup-ui.tsx b/src/auth/setup-ui.tsx index 9849c74..a89ce42 100644 --- a/src/auth/setup-ui.tsx +++ b/src/auth/setup-ui.tsx @@ -70,12 +70,13 @@ export function SetupUI({ onComplete }: SetupUIProps) { ) .then((tokens) => { // Save tokens + // Note: LETTA_BASE_URL is intentionally NOT saved to settings + // It should only come from environment variables const now = Date.now(); settingsManager.updateSettings({ env: { ...settingsManager.getSettings().env, LETTA_API_KEY: tokens.access_token, - LETTA_BASE_URL: OAUTH_CONFIG.apiBaseUrl, }, refreshToken: tokens.refresh_token, tokenExpiresAt: now + tokens.expires_in * 1000, diff --git a/src/cli/App.tsx b/src/cli/App.tsx index b044646..3afd3d5 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -643,7 +643,8 @@ export default function App({ const currentSettings = settingsManager.getSettings(); const newEnv = { ...currentSettings.env }; delete newEnv.LETTA_API_KEY; - delete newEnv.LETTA_BASE_URL; + // Note: LETTA_BASE_URL is intentionally NOT deleted from settings + // because it should not be stored there in the first place settingsManager.updateSettings({ env: newEnv, diff --git a/src/tests/settings-manager.test.ts b/src/tests/settings-manager.test.ts index 8c7ee22..5c52a52 100644 --- a/src/tests/settings-manager.test.ts +++ b/src/tests/settings-manager.test.ts @@ -170,6 +170,20 @@ describe("Settings Manager - Global Settings", () => { }); }); + test("LETTA_BASE_URL should not be cached in settings", () => { + // This test verifies that LETTA_BASE_URL is NOT persisted to settings + // It should only come from environment variables + settingsManager.updateSettings({ + env: { + LETTA_API_KEY: "sk-test-123", + // LETTA_BASE_URL should not be included here + }, + }); + + const settings = settingsManager.getSettings(); + expect(settings.env?.LETTA_BASE_URL).toBeUndefined(); + }); + test("Settings persist to disk", async () => { settingsManager.updateSettings({ uiMode: "rich",