From 6f0aa70ae150035bd87112383cc4cd6ffc4eabf8 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 4 Aug 2026 11:11:48 +0000 Subject: [PATCH] keep AI settings editor in sync with the config it just saved (#10503) * fix: keep AI settings editor in sync with the config it just saved Co-Authored-By: Claude Opus 5 (1M context) * fix: skip the post-save reload and record why the saved config is cloned Co-Authored-By: Claude Opus 5 (1M context) --------- Co-authored-by: Claude Opus 5 (1M context) --- .../instanceSettings/InstanceAISettings.svelte | 3 +++ .../components/workspaceSettings/AISettings.svelte | 11 +++++++++-- .../(root)/(logged)/workspace_settings/+page.svelte | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/instanceSettings/InstanceAISettings.svelte b/frontend/src/lib/components/instanceSettings/InstanceAISettings.svelte index 91b08eb46e..8d7d107940 100644 --- a/frontend/src/lib/components/instanceSettings/InstanceAISettings.svelte +++ b/frontend/src/lib/components/instanceSettings/InstanceAISettings.svelte @@ -145,5 +145,8 @@ link="https://www.windmill.dev/docs/core_concepts/ai_generation" promptScope="instance" customSave={handleCustomSave} + onSave={(savedConfig) => { + initialConfig = savedConfig + }} /> {/if} diff --git a/frontend/src/lib/components/workspaceSettings/AISettings.svelte b/frontend/src/lib/components/workspaceSettings/AISettings.svelte index 48e3fb7f15..60d1cb77a0 100644 --- a/frontend/src/lib/components/workspaceSettings/AISettings.svelte +++ b/frontend/src/lib/components/workspaceSettings/AISettings.svelte @@ -57,7 +57,7 @@ usesInstanceAiConfig?: boolean instanceAiSummary?: InstanceAISummary customSave?: (config: AIConfig) => Promise - onSave?: (info?: GetCopilotSettingsStateResponse) => void | Promise + onSave?: (savedConfig: AIConfig, info?: GetCopilotSettingsStateResponse) => void | Promise title?: string description?: string link?: string @@ -332,7 +332,14 @@ sendUserToast('AI settings updated') } storeInitialState() - await onSave?.(settingsState) + // Hand the parent what was persisted: it owns `initialConfig`, and this component is + // destroyed on a settings tab switch, so a stale prop returns as editor state on remount + // and is written back by the next save. Clone it, since `providers` aliases our `$state` + // and the `lastLoadedConfigKey` guard would then track our own edits; pre-arm that guard + // so the prop update does not re-apply the config over what the editor now shows. + const savedConfig = clone(config) + lastLoadedConfigKey = JSON.stringify(savedConfig) + await onSave?.(savedConfig, settingsState) } async function onAiProviderChange(provider: AIProvider) { diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 9407bbcc29..8b12bc16c3 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -2029,7 +2029,8 @@ export async function main( {hasInstanceAiConfig} {usesInstanceAiConfig} {instanceAiSummary} - onSave={(copilotSettingsState) => { + onSave={(savedConfig, copilotSettingsState) => { + aiInitialConfig = savedConfig if (!copilotSettingsState) { return }