( aiDataDir: string, id: string, updates: Partial<Omit<AIServiceConfig, 'id'>> )
| 146 | } |
| 147 | |
| 148 | export 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 | |
| 181 | export function deleteLlmConfig(aiDataDir: string, id: string): { success: boolean; error?: string } { |
| 182 | const storeForSave = loadRawConfigStore(aiDataDir) |
nothing calls this directly
no test coverage detected