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

Function updateLlmConfig

apps/cli/src/ai/llm-config.ts:148–179  ·  view source on GitHub ↗
(
  aiDataDir: string,
  id: string,
  updates: Partial<Omit<AIServiceConfig, 'id'>>
)

Source from the content-addressed store, hash-verified

146}
147
148export function updateLlmConfig(
149 aiDataDir: string,
150 id: string,
151 updates: Partial<Omit<AIServiceConfig, 'id'>>
152): { success: boolean; error?: string } {
153 const storeForSave = loadRawConfigStore(aiDataDir)
154 const index = storeForSave.configs.findIndex((c) => c.id === id)
155
156 if (index === -1) {
157 return { success: false, error: 'Config not found' }
158 }
159
160 const { apiKey: newApiKey, ...restUpdates } = updates
161 const updated = {
162 ...storeForSave.configs[index],
163 ...restUpdates,
164 }
165 storeForSave.configs[index] = updated
166
167 if (newApiKey) {
168 const profileName = updated.name?.toLowerCase().replace(/\s+/g, '-') || updated.provider
169 writeAuthProfile(profileName, {
170 type: 'api_key',
171 provider: updated.provider,
172 key: newApiKey,
173 })
174 ;(storeForSave.configs[index] as unknown as Record<string, unknown>).authProfile = profileName
175 }
176
177 saveLlmConfig(aiDataDir, storeForSave)
178 return { success: true }
179}
180
181export function deleteLlmConfig(aiDataDir: string, id: string): { success: boolean; error?: string } {
182 const storeForSave = loadRawConfigStore(aiDataDir)

Callers

nothing calls this directly

Calls 3

writeAuthProfileFunction · 0.90
loadRawConfigStoreFunction · 0.85
saveLlmConfigFunction · 0.85

Tested by

no test coverage detected