MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / addConfig

Method addConfig

packages/node-runtime/src/ai/llm-config-store.ts:179–213  ·  view source on GitHub ↗
(config: Omit<AIServiceConfig, 'id' | 'createdAt' | 'updatedAt'>)

Source from the content-addressed store, hash-verified

177 }
178
179 addConfig(config: Omit<AIServiceConfig, 'id' | 'createdAt' | 'updatedAt'>): {
180 success: boolean
181 config?: AIServiceConfig
182 error?: string
183 } {
184 const store = this.loadStore()
185
186 if (store.configs.length >= MAX_CONFIG_COUNT) {
187 return { success: false, error: this.t('llm.maxConfigs', { count: MAX_CONFIG_COUNT }) }
188 }
189
190 const now = Date.now()
191 const newConfig: AIServiceConfig = {
192 ...config,
193 id: this.generateId(),
194 createdAt: now,
195 updatedAt: now,
196 }
197
198 store.configs.push(newConfig)
199
200 if (store.configs.length === 1) {
201 store.defaultAssistant = { configId: newConfig.id, modelId: newConfig.model || '' }
202 }
203
204 if (newConfig.apiKey && this.onApiKeyCreated) {
205 const profileName = this.onApiKeyCreated(newConfig, newConfig.apiKey)
206 if (profileName) {
207 ;(newConfig as unknown as Record<string, unknown>).authProfile = profileName
208 }
209 }
210
211 this.saveStore(store)
212 return { success: true, config: { ...newConfig, apiKey: '' } }
213 }
214
215 updateConfig(
216 id: string,

Callers

nothing calls this directly

Calls 4

loadStoreMethod · 0.95
saveStoreMethod · 0.95
generateIdMethod · 0.80
nowMethod · 0.45

Tested by

no test coverage detected