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 }