Agent Zero AI framework
fix(_model_config): prevent Settings Save from clobbering API keys saved via Configure Models
keyboardstaffc16134e62424
diff --git a/plugins/_model_config/webui/api-keys-mixin.js b/plugins/_model_config/webui/api-keys-mixin.jsindex 04a3cad08..6db3c3b7f 100644--- a/plugins/_model_config/webui/api-keys-mixin.js+++ b/plugins/_model_config/webui/api-keys-mixin.js@@ -1,4 +1,5 @@const API_BASE = "/plugins/_model_config";+const API_KEY_PLACEHOLDER = "************";export const apiKeysState = {apiKeyStatus: {},@@ -17,6 +18,14 @@ export const apiKeysMethods = {);},+ _syncApiKeysToSettingsStore(savedKeys) {+ const settingsApiKeys = globalThis.Alpine?.store('settings')?.settings?.api_keys;+ if (!settingsApiKeys) return;+ for (const [provider, value] of Object.entries(savedKeys)) {+ settingsApiKeys[provider] = value.trim() ? API_KEY_PLACEHOLDER : '';+ }+ },+_ensureApiKeySlot(provider) {if (!provider) return;if (!(provider in this.apiKeyValues)) {@@ -37,6 +46,13 @@ export const apiKeysMethods = {this._setApiKeyDirty(provider, true);},+ setApiKeyValue(provider, value) {+ if (!provider) return;+ this._ensureApiKeySlot(provider);+ this.apiKeyValues = { ...this.apiKeyValues, [provider]: value };+ this._setApiKeyDirty(provider, true);+ },+async refreshApiKeyStatus() {await this.ensureLoaded();const res = await fetchApi(`${API_BASE}/api_keys`, {@@ -113,6 +129,11 @@ export const apiKeysMethods = {}this.apiKeyValues = nextValues;this.apiKeyDirty = nextDirty;++ // Sync saved keys into the Settings store so Settings Save+ // won't overwrite just-saved keys with stale empty values.+ this._syncApiKeysToSettingsStore(normalized);+return data;},@@ -158,4 +179,14 @@ export const apiKeysMethods = {}return this.saveApiKeys(updates);},++ async persistAllDirtyApiKeys() {+ const updates = {};+ for (const [provider, isDirty] of Object.entries(this.apiKeyDirty)) {+ if (!isDirty) continue;+ const value = this.apiKeyValues[provider];+ updates[provider] = typeof value === 'string' ? value : '';+ }+ return this.saveApiKeys(updates);+ },};diff --git a/plugins/_model_config/webui/api-keys.html b/plugins/_model_config/webui/api-keys.htmlindex 09f9c2769..4de040c5b 100644--- a/plugins/_model_config/webui/api-keys.html+++ b/plugins/_model_config/webui/api-keys.html@@ -35,14 +35,7 @@this.saving = true;this.error = '';try {- const updates = {};- const dirty = $store.modelConfig.apiKeyDirty;- const values = $store.modelConfig.apiKeyValues;- for (const provider of Object.keys(dirty)) {- if (!dirty[provider]) continue;- updates[provider] = values[provider] || '';- }- await $store.modelConfig.saveApiKeys(updates);+ await $store.modelConfig.persistAllDirtyApiKeys();await $store.modelConfig.refreshApiKeyStatus();window.closeModal?.();} catch (e) {@@ -78,10 +71,10 @@</div><div class="field-control" style="position:relative;" x-data="{ showKey: false }"><input :type="showKey ? 'text' : 'password'"- x-model="$store.modelConfig.apiKeyValues[provider.value]"+ :value="$store.modelConfig.apiKeyValues[provider.value]":placeholder="provider.has_key ? '••••••••••••' : ''"autocomplete="off"- @input="$store.modelConfig.touchApiKey(provider.value)"+ @input="$store.modelConfig.setApiKeyValue(provider.value, $el.value)"style="padding-right:32px;" /><span class="material-symbols-outlined eye-toggle"@click="diff --git a/plugins/_model_config/webui/main.html b/plugins/_model_config/webui/main.htmlindex 46c853323..33b1b28b8 100644--- a/plugins/_model_config/webui/main.html+++ b/plugins/_model_config/webui/main.html@@ -11,6 +11,8 @@x-init="await $store.modelConfig.ensureLoaded();await $store.modelConfig.loadGlobalPresets();+ $store.modelConfig.resetApiKeyDrafts();+ await $store.modelConfig.refreshApiKeyStatus();"><template x-if="$store.modelConfig._loaded && $store.modelConfig._presetsLoaded"><div class="presets-page" x-data="{ presets: JSON.parse(JSON.stringify($store.modelConfig.globalPresets)) }">@@ -46,12 +48,12 @@</div><div class="preset-subheader">Main Model</div>- <div x-data="{ model: preset.chat, modelType: 'chat', providers: $store.modelConfig.chatProviders, searchType: 'chat', apiKeyMode: 'inline' }">+ <div x-data="{ model: preset.chat, modelType: 'chat', providers: $store.modelConfig.chatProviders, searchType: 'chat', apiKeyMode: 'store' }"><x-component path="/plugins/_model_config/webui/model-field.html"></x-component></div><div class="preset-subheader">Utility Model <span style="opacity:0.5; font-size:0.75rem;">(optional — falls back to the configured Utility Model)</span></div>- <div x-data="{ model: preset.utility, modelType: 'utility', providers: $store.modelConfig.chatProviders, searchType: 'chat', apiKeyMode: 'inline', providerFallback: preset.chat.provider, apiBaseFallback: preset.chat.api_base }">+ <div x-data="{ model: preset.utility, modelType: 'utility', providers: $store.modelConfig.chatProviders, searchType: 'chat', apiKeyMode: 'store', providerFallback: preset.chat.provider, apiBaseFallback: preset.chat.api_base }"><x-component path="/plugins/_model_config/webui/model-field.html"></x-component></div></div>@@ -83,7 +85,7 @@</div><div class="presets-footer">- <button class="button" @click="$store.modelConfig.saveGlobalPresets(presets)">+ <button class="button" @click="(async () => { await $store.modelConfig.persistAllDirtyApiKeys(); await $store.modelConfig.saveGlobalPresets(presets); })()"><span class="icon material-symbols-outlined">save</span> Save Presets</button></div>diff --git a/plugins/_model_config/webui/model-config-store.js b/plugins/_model_config/webui/model-config-store.jsindex b4a3ed0e4..0633fe177 100644--- a/plugins/_model_config/webui/model-config-store.js+++ b/plugins/_model_config/webui/model-config-store.js@@ -154,12 +154,12 @@ export const store = createStore("modelConfig", {},async saveGlobalPresets(presets) {- // Strip UI-only fields before saving+ // Strip UI-only and globally-managed fields before savingconst clean = presets.map(p => {const c = { name: p.name };for (const slot of ['chat', 'utility']) {if (p[slot]) {- const { _kwargs_text, ...rest } = p[slot];+ const { _kwargs_text, api_key, ...rest } = p[slot];c[slot] = rest;}}diff --git a/plugins/_model_config/webui/model-field.html b/plugins/_model_config/webui/model-field.htmlindex 2186d49f6..f516ea6dc 100644--- a/plugins/_model_config/webui/model-field.html+++ b/plugins/_model_config/webui/model-field.html@@ -79,10 +79,10 @@</div><div class="field-control" style="position:relative;" x-data="{ showKey: false }"><input :type="showKey ? 'text' : 'password'"- x-model="$store.modelConfig.apiKeyValues[model.provider]"+ :value="$store.modelConfig.apiKeyValues[model.provider]":placeholder="$store.modelConfig.apiKeyStatus[model.provider] ? '••••••••••••' : ''"autocomplete="off"- @input="$store.modelConfig.touchApiKey(model.provider)"+ @input="$store.modelConfig.setApiKeyValue(model.provider, $el.value)"style="padding-right:32px;" /><span class="material-symbols-outlined eye-toggle"@click="