implemented ClaudeOpenRouterProvider.
This commit is contained in:
@@ -90,6 +90,7 @@ export class ConfigManager {
|
||||
private storage: KGStorage;
|
||||
private isInitialized: boolean = false;
|
||||
private defaultConfig: AppConfig | null = null;
|
||||
private changeListeners: Set<(changedKeys: string[]) => void> = new Set();
|
||||
|
||||
// Private constructor to prevent direct instantiation
|
||||
private constructor() {
|
||||
@@ -361,6 +362,8 @@ export class ConfigManager {
|
||||
await this.saveToStorage();
|
||||
|
||||
console.log(`Config updated: ${key} = ${value}`);
|
||||
// Notify listeners of the specific key change
|
||||
this.notifyChangeListeners([key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,6 +381,11 @@ export class ConfigManager {
|
||||
await this.saveToStorage();
|
||||
|
||||
console.log('Config updated with multiple values:', updates);
|
||||
// Notify listeners of changed keys (dot notation)
|
||||
const changedKeys = this.collectDotKeys(updates as Record<string, unknown>);
|
||||
if (changedKeys.length > 0) {
|
||||
this.notifyChangeListeners(changedKeys);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,6 +404,7 @@ export class ConfigManager {
|
||||
await this.saveToStorage();
|
||||
|
||||
console.log('Config reset to defaults');
|
||||
this.notifyChangeListeners(['__all__']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,6 +452,44 @@ export class ConfigManager {
|
||||
current[keys[keys.length - 1]] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to config changes. Returns an unsubscribe function.
|
||||
*/
|
||||
public addChangeListener(listener: (changedKeys: string[]) => void): () => void {
|
||||
this.changeListeners.add(listener);
|
||||
return () => this.changeListeners.delete(listener);
|
||||
}
|
||||
|
||||
public removeChangeListener(listener: (changedKeys: string[]) => void): void {
|
||||
this.changeListeners.delete(listener);
|
||||
}
|
||||
|
||||
private notifyChangeListeners(changedKeys: string[]): void {
|
||||
for (const listener of this.changeListeners) {
|
||||
try {
|
||||
listener(changedKeys);
|
||||
} catch (error) {
|
||||
console.error('Config change listener error:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect dot-notation keys for all leaf values in a partial config object
|
||||
*/
|
||||
private collectDotKeys(obj: Record<string, unknown>, prefix = ''): string[] {
|
||||
const keys: string[] = [];
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
const path = prefix ? `${prefix}.${k}` : k;
|
||||
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
||||
keys.push(...this.collectDotKeys(v as Record<string, unknown>, path));
|
||||
} else {
|
||||
keys.push(path);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ConfigManager is initialized
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user