From 6d615283472f6b3ae42a522a89209ea030f307c8 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:33:14 +0530 Subject: [PATCH] feat(configManager): add update & removal methods --- src/lib/config/index.ts | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 5bed79b..5314df3 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -145,6 +145,54 @@ class ConfigManager { return obj === undefined ? defaultValue : obj; } + + public updateConfig(key: string, val: any) { + const parts = key.split('.'); + if (parts.length === 0) return; + + let target: any = this.currentConfig; + for (let i = 0; i < parts.length - 1; i++) { + const part = parts[i]; + if (target[part] === null || typeof target[part] !== 'object') { + target[part] = {}; + } + + target = target[part]; + } + + const finalKey = parts[parts.length - 1]; + target[finalKey] = val; + + this.saveConfig(); + } + + public addModelProvider(type: string, name: string, config: any) { + const newModelProvider: ConfigModelProvider = { + id: crypto.randomUUID(), + name, + type, + config, + chatModels: [], + embeddingModels: [], + hash: hashObj(config), + }; + + this.currentConfig.modelProviders.push(newModelProvider); + this.saveConfig(); + } + + public removeModelProvider(id: string) { + const index = this.currentConfig.modelProviders.findIndex( + (p) => p.id === id, + ); + + if (index === -1) return; + + this.currentConfig.modelProviders = + this.currentConfig.modelProviders.filter((p) => p.id !== id); + + this.saveConfig(); + } } const configManager = new ConfigManager();