From f328ae4bf9dff216e8a23471cc60b074f0e41e0d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 2 Sep 2024 20:45:32 +0100 Subject: [PATCH] account for arrays --- packages/backend-core/src/configs/configs.ts | 3 +- .../portal/settings/ai/ConfigModal.svelte | 49 ++++++++++++------- .../worker/src/api/routes/global/configs.ts | 20 +++++++- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/packages/backend-core/src/configs/configs.ts b/packages/backend-core/src/configs/configs.ts index 6062d3624f..1771716f57 100644 --- a/packages/backend-core/src/configs/configs.ts +++ b/packages/backend-core/src/configs/configs.ts @@ -1,5 +1,6 @@ import { - AIConfig, AIInnerConfig, + AIConfig, + AIInnerConfig, Config, ConfigType, GoogleConfig, diff --git a/packages/builder/src/pages/builder/portal/settings/ai/ConfigModal.svelte b/packages/builder/src/pages/builder/portal/settings/ai/ConfigModal.svelte index e9ec5159f9..749cebeb2c 100644 --- a/packages/builder/src/pages/builder/portal/settings/ai/ConfigModal.svelte +++ b/packages/builder/src/pages/builder/portal/settings/ai/ConfigModal.svelte @@ -23,37 +23,48 @@ const models = [ "gpt4o-mini", ] + + const defaultConfig = { + active: false, + isDefault: false, + } - let formValues = {} - + let aiConfig = defaultConfig let validation $: { - const { provider, model, name, apiKey } = formValues - validation = provider && model && name && apiKey + const { provider, defaultModel, name, apiKey } = aiConfig + validation = provider && defaultModel && name && apiKey } function prefillConfig(evt) { const provider = evt.detail // grab the preset config from the constants for that provider and fill it in if (ConfigMap[provider]) { - formValues = { - ...formValues, + aiConfig = { + ...aiConfig, ...ConfigMap[provider] } } else { - formValues = { + aiConfig = { + ...aiConfig, provider } } } async function saveConfig() { - formValues.type = "ai" + const config = { + type: "ai", + config: [ + // TODO: include the ones that are already there, or just handle this in the backend + aiConfig, + ] + } try { - const savedConfig = await API.saveConfig(formValues) - formValues._rev = savedConfig._rev - formValues._id = savedConfig._id + const savedConfig = await API.saveConfig(config) + aiConfig._rev = savedConfig._rev + aiConfig._id = savedConfig._id notifications.success(`Configuration saved`) } catch (error) { notifications.error( @@ -92,33 +103,33 @@
- +
- +
- +
- - + +