( aiDataDir: string, config: Omit<AIServiceConfig, 'id'> )
| 106 | } |
| 107 | |
| 108 | export function addLlmConfig( |
| 109 | aiDataDir: string, |
| 110 | config: Omit<AIServiceConfig, 'id'> |
| 111 | ): { success: boolean; config?: AIServiceConfig; error?: string } { |
| 112 | const store = loadLlmConfig(aiDataDir) |
| 113 | |
| 114 | if (store.configs.length >= MAX_CONFIG_COUNT) { |
| 115 | return { success: false, error: `Maximum ${MAX_CONFIG_COUNT} configs reached` } |
| 116 | } |
| 117 | |
| 118 | const newConfig: AIServiceConfig = { |
| 119 | ...config, |
| 120 | id: randomUUID(), |
| 121 | } |
| 122 | |
| 123 | const storeForSave = loadRawConfigStore(aiDataDir) |
| 124 | storeForSave.configs.push({ |
| 125 | ...newConfig, |
| 126 | apiKey: '', |
| 127 | }) |
| 128 | |
| 129 | if (storeForSave.configs.length === 1) { |
| 130 | storeForSave.defaultAssistant = { configId: newConfig.id, modelId: newConfig.model || '' } |
| 131 | } |
| 132 | |
| 133 | if (config.apiKey) { |
| 134 | const profileName = config.name?.toLowerCase().replace(/\s+/g, '-') || config.provider |
| 135 | writeAuthProfile(profileName, { |
| 136 | type: 'api_key', |
| 137 | provider: config.provider, |
| 138 | key: config.apiKey, |
| 139 | }) |
| 140 | ;(storeForSave.configs[storeForSave.configs.length - 1] as unknown as Record<string, unknown>).authProfile = |
| 141 | profileName |
| 142 | } |
| 143 | |
| 144 | saveLlmConfig(aiDataDir, storeForSave) |
| 145 | return { success: true, config: { ...newConfig, apiKey: '' } } |
| 146 | } |
| 147 | |
| 148 | export function updateLlmConfig( |
| 149 | aiDataDir: string, |
nothing calls this directly
no test coverage detected