fix: stop caching LETTA_BASE_URL in settings.json (#46)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2025-10-31 23:38:14 -07:00
committed by GitHub
parent 3dc6963dfb
commit 94393a8566
4 changed files with 21 additions and 15 deletions

View File

@@ -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 });
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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",