Skip to content

Commit 855fb9a

Browse files
committed
1. ✓ Added skipCredentialChecks parameter to validateConfiguration()
2. ✓ Fixed multi-provider credential preservation in saveProviderSpecificSettings() 3. ✓ Secured logging in both handleStorageChange() and getDebugInfo()
1 parent 1ab0393 commit 855fb9a

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

front_end/panels/ai_chat/core/LLMConfigurationManager.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Cache break: 2025-09-18T18:30:00Z - Add skipCredentialChecks parameter for AUTOMATED_MODE
4+
// Cache break: 2025-09-18T19:00:00Z - Add skipCredentialChecks + preserve credentials + secure logging
55

66
import { createLogger } from './Logger.js';
77
import type { LLMProvider } from '../LLM/LLMTypes.js';
@@ -294,38 +294,42 @@ export class LLMConfigurationManager {
294294

295295
/**
296296
* Save provider-specific settings to localStorage
297+
* Only modifies settings for the active provider, preserving other providers' credentials
297298
*/
298299
private saveProviderSpecificSettings(config: LLMConfig): void {
299-
// Clear all provider-specific keys first
300-
localStorage.removeItem(STORAGE_KEYS.OPENAI_API_KEY);
301-
localStorage.removeItem(STORAGE_KEYS.LITELLM_API_KEY);
302-
localStorage.removeItem(STORAGE_KEYS.LITELLM_ENDPOINT);
303-
localStorage.removeItem(STORAGE_KEYS.GROQ_API_KEY);
304-
localStorage.removeItem(STORAGE_KEYS.OPENROUTER_API_KEY);
305-
306-
// Save current provider's settings
300+
// Save current provider's settings only (do not clear others)
307301
switch (config.provider) {
308302
case 'openai':
309303
if (config.apiKey) {
310304
localStorage.setItem(STORAGE_KEYS.OPENAI_API_KEY, config.apiKey);
305+
} else {
306+
localStorage.removeItem(STORAGE_KEYS.OPENAI_API_KEY);
311307
}
312308
break;
313309
case 'litellm':
314310
if (config.endpoint) {
315311
localStorage.setItem(STORAGE_KEYS.LITELLM_ENDPOINT, config.endpoint);
312+
} else {
313+
localStorage.removeItem(STORAGE_KEYS.LITELLM_ENDPOINT);
316314
}
317315
if (config.apiKey) {
318316
localStorage.setItem(STORAGE_KEYS.LITELLM_API_KEY, config.apiKey);
317+
} else {
318+
localStorage.removeItem(STORAGE_KEYS.LITELLM_API_KEY);
319319
}
320320
break;
321321
case 'groq':
322322
if (config.apiKey) {
323323
localStorage.setItem(STORAGE_KEYS.GROQ_API_KEY, config.apiKey);
324+
} else {
325+
localStorage.removeItem(STORAGE_KEYS.GROQ_API_KEY);
324326
}
325327
break;
326328
case 'openrouter':
327329
if (config.apiKey) {
328330
localStorage.setItem(STORAGE_KEYS.OPENROUTER_API_KEY, config.apiKey);
331+
} else {
332+
localStorage.removeItem(STORAGE_KEYS.OPENROUTER_API_KEY);
329333
}
330334
break;
331335
}
@@ -336,9 +340,18 @@ export class LLMConfigurationManager {
336340
*/
337341
private handleStorageChange(event: StorageEvent): void {
338342
if (event.key && Object.values(STORAGE_KEYS).includes(event.key as any)) {
343+
const sensitiveKeys = new Set([
344+
STORAGE_KEYS.OPENAI_API_KEY,
345+
STORAGE_KEYS.LITELLM_API_KEY,
346+
STORAGE_KEYS.GROQ_API_KEY,
347+
STORAGE_KEYS.OPENROUTER_API_KEY,
348+
]);
349+
const redacted =
350+
sensitiveKeys.has(event.key as any) ? '(redacted)' :
351+
(event.newValue ? `${event.newValue.slice(0, 8)}…` : null);
339352
logger.debug('Configuration changed in another tab', {
340353
key: event.key,
341-
newValue: event.newValue
354+
newValue: redacted
342355
});
343356
this.notifyListeners();
344357
}
@@ -361,10 +374,15 @@ export class LLMConfigurationManager {
361374
* Get debug information about current configuration state
362375
*/
363376
getDebugInfo(): Record<string, any> {
377+
const redact = (cfg?: Partial<LLMConfig>) => cfg ? {
378+
...cfg,
379+
apiKey: cfg.apiKey ? '(redacted)' : undefined
380+
} : undefined;
381+
364382
return {
365383
hasOverride: this.hasOverride(),
366-
overrideConfig: this.overrideConfig,
367-
currentConfig: this.getConfiguration(),
384+
overrideConfig: redact(this.overrideConfig),
385+
currentConfig: redact(this.getConfiguration()),
368386
validation: this.validateConfiguration(),
369387
listenerCount: this.changeListeners.length,
370388
};

0 commit comments

Comments
 (0)