From b213550a8e9610ceaecf1318c2cf1931acd616f0 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 28 Apr 2025 17:44:35 +0100 Subject: [PATCH] Fix the way that the AI settings page finds AI configs for a given provider. --- .../builder/portal/settings/ai/index.svelte | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/settings/ai/index.svelte b/packages/builder/src/pages/builder/portal/settings/ai/index.svelte index 4e987ddba7..0923e5846f 100644 --- a/packages/builder/src/pages/builder/portal/settings/ai/index.svelte +++ b/packages/builder/src/pages/builder/portal/settings/ai/index.svelte @@ -55,18 +55,25 @@ $: enabled = !isCloud ? providers.filter(p => p.key === activeKey) : providers $: disabled = !isCloud ? providers.filter(p => p.key !== activeKey) : [] + function getConfigForProvider(key: AIProviderPartial) { + for (const config of Object.values(aiConfig.config)) { + if (config.provider === key) { + return config + } + } + return undefined + } + function getProviderConfig(key: AIProviderPartial): ProviderConfig { const details = ProviderDetails[key] - const loadedConfig = aiConfig?.config[key] || {} - let baseConfig = { ...details.defaultConfig } + const config = getConfigForProvider(key) || { ...details.defaultConfig } return { - ...baseConfig, - ...loadedConfig, + ...config, provider: details.provider as AIProvider, name: details.name, - active: loadedConfig.active ?? baseConfig.active ?? false, - isDefault: loadedConfig.isDefault ?? baseConfig.isDefault ?? false, + active: config.active ?? false, + isDefault: config.isDefault ?? false, } } @@ -108,12 +115,7 @@ } } - // handle the old budibase_ai key const baseConfig = { ...aiConfig.config } - if (baseConfig["budibase_ai"]) { - delete baseConfig["budibase_ai"] - } - const payload = { type: ConfigType.AI, config: { ...baseConfig, [key]: updated },