(config: Omit<AIServiceConfig, 'id' | 'createdAt' | 'updatedAt'>)
| 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, |
nothing calls this directly
no test coverage detected