({ saveButtonLabel }: AiSettingsProps)
| 253 | }; |
| 254 | |
| 255 | export function AiSettings({ saveButtonLabel }: AiSettingsProps) { |
| 256 | const { |
| 257 | aiProvider, |
| 258 | aiModel, |
| 259 | aiBaseUrl, |
| 260 | openaiKey: configOpenaiKey, |
| 261 | anthropicKey: configAnthropicKey, |
| 262 | customApiKey: configCustomApiKey, |
| 263 | xaiKey: configXaiKey, |
| 264 | geminiKey: configGeminiKey, |
| 265 | openrouterKey: configOpenrouterKey, |
| 266 | updateConfig: updateConfigContext, |
| 267 | } = useSettings(); |
| 268 | |
| 269 | const [openaiKey, setOpenaiKey] = useState<string>(configOpenaiKey ?? ''); |
| 270 | const [anthropicKey, setAnthropicKey] = useState<string>(configAnthropicKey ?? ''); |
| 271 | const [xaiKey, setXaiKey] = useState<string>(configXaiKey ?? ''); |
| 272 | const [geminiKey, setGeminiKey] = useState<string>(configGeminiKey ?? ''); |
| 273 | const [openrouterKey, setOpenrouterKey] = useState<string>(configOpenrouterKey ?? ''); |
| 274 | const [customApiKey, setCustomApiKey] = useState<string>(configCustomApiKey ?? ''); |
| 275 | const [model, setModel] = useState<string>(aiModel); |
| 276 | const [baseUrl, setBaseUrl] = useState<string>(aiBaseUrl || ''); |
| 277 | |
| 278 | const setAiProvider = (provider: AiProviderType) => { |
| 279 | const model = getDefaultModel(provider); |
| 280 | setModel(model); |
| 281 | updateConfigContext({ aiProvider: provider, aiModel: model }); |
| 282 | }; |
| 283 | |
| 284 | // Either the key from the server is null/undefined and the user entered input |
| 285 | // or the key from the server is a string and the user entered input is different. |
| 286 | const openaiKeySaveEnabled = |
| 287 | (typeof configOpenaiKey === 'string' && openaiKey !== configOpenaiKey) || |
| 288 | ((configOpenaiKey === null || configOpenaiKey === undefined) && openaiKey.length > 0) || |
| 289 | model !== aiModel; |
| 290 | |
| 291 | const anthropicKeySaveEnabled = |
| 292 | (typeof configAnthropicKey === 'string' && anthropicKey !== configAnthropicKey) || |
| 293 | ((configAnthropicKey === null || configAnthropicKey === undefined) && |
| 294 | anthropicKey.length > 0) || |
| 295 | model !== aiModel; |
| 296 | |
| 297 | const xaiKeySaveEnabled = |
| 298 | (typeof configXaiKey === 'string' && xaiKey !== configXaiKey) || |
| 299 | ((configXaiKey === null || configXaiKey === undefined) && xaiKey.length > 0) || |
| 300 | model !== aiModel; |
| 301 | |
| 302 | const geminiKeySaveEnabled = |
| 303 | (typeof configGeminiKey === 'string' && geminiKey !== configGeminiKey) || |
| 304 | ((configGeminiKey === null || configGeminiKey === undefined) && geminiKey.length > 0) || |
| 305 | model !== aiModel; |
| 306 | |
| 307 | const openrouterKeySaveEnabled = |
| 308 | (typeof configOpenrouterKey === 'string' && openrouterKey !== configOpenrouterKey) || |
| 309 | ((configOpenrouterKey === null || configOpenrouterKey === undefined) && |
| 310 | openrouterKey.length > 0) || |
| 311 | model !== aiModel; |
| 312 |
nothing calls this directly
no test coverage detected