Agent Zero AI framework
Fix model preset reset flow
Alessandro48cba46181e5
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.mdindex 0bf427f72..ee46e3039 100644--- a/plugins/_model_config/AGENTS.md+++ b/plugins/_model_config/AGENTS.md@@ -22,6 +22,7 @@- Changing a model provider in the settings UI must clear `api_base` and `kwargs` because both may be provider-specific.- Repair provider-specific model-config aliases at the model-config read/build boundary; keep provider-specific repairs out of provider-agnostic core wrappers such as `models.py`.- `modelConfig.createPresetEditor()` owns local preset drafts, row actions, and stable UI-only row keys so deletion or renaming cannot rebind nested model fields.+- Preset editor reset actions must remove the user override through the preset API and refresh the open draft from bundled defaults.- Model-name catalogs open below the input from either a field click or the embedded magnifier.## Work Guidancediff --git a/plugins/_model_config/webui/main.html b/plugins/_model_config/webui/main.htmlindex ad2846827..ca6472961 100644--- a/plugins/_model_config/webui/main.html+++ b/plugins/_model_config/webui/main.html@@ -68,6 +68,7 @@<button class="text-button" @click="(async () => {await import('/components/plugins/plugin-settings-store.js');await $store.pluginSettingsPrototype.openConfig('_model_config');+ refreshPresets();})()"><span class="material-symbols-outlined">settings</span><span>Settings</span>@@ -79,6 +80,9 @@</div><div class="presets-footer">+ <button class="button" @click="$confirmClick($event, () => resetPresets())">+ <span class="icon material-symbols-outlined">restart_alt</span> Reset to default+ </button><button class="button" @click="savePresets()"><span class="icon material-symbols-outlined">save</span> Save Presets</button>@@ -100,6 +104,7 @@margin-top: 12px;display: flex;justify-content: flex-end;+ gap: 8px;}.preset-card {border: 1px solid var(--color-border);diff --git a/plugins/_model_config/webui/model-config-store.js b/plugins/_model_config/webui/model-config-store.jsindex 65415623e..57945c372 100644--- a/plugins/_model_config/webui/model-config-store.js+++ b/plugins/_model_config/webui/model-config-store.js@@ -294,6 +294,17 @@ export const store = createStore("modelConfig", {await store.persistAllDirtyApiKeys();await store.saveGlobalPresets(this.presets);},+ refreshPresets() {+ this.presets = clonePlain(store.globalPresets).map(preset => ({+ ...preset,+ _key: nextPresetKey++,+ }));+ },+ async resetPresets() {+ if (!await store.resetGlobalPresets()) return;+ this.refreshPresets();+ globalThis.justToast?.('Presets reset to default.', 'info');+ },};},@@ -355,8 +366,11 @@ export const store = createStore("modelConfig", {this.globalPresets = this._normalizePresets(data.presets);this.switcherPresets = this.globalPresets.filter(p => p.name);this._presetsLoaded = true;+ return true;} catch (e) {console.error('Failed to reset presets:', e);+ globalThis.justToast?.('Failed to reset presets', 'error');+ return false;}},diff --git a/tests/test_model_config_ui.py b/tests/test_model_config_ui.pyindex b7735c19d..0a6a02add 100644--- a/tests/test_model_config_ui.py+++ b/tests/test_model_config_ui.py@@ -34,3 +34,24 @@ def test_model_preset_rows_keep_stable_identity_after_middle_delete() -> None:assert ':key="idx"' not in preset_modalassert "JSON.parse(JSON.stringify" not in preset_modalassert "presets.splice" not in preset_modal+++def test_model_preset_editor_can_reset_to_bundled_defaults() -> None:+ preset_modal = read("plugins", "_model_config", "webui", "main.html")+ preset_store = read("plugins", "_model_config", "webui", "model-config-store.js")++ assert '$confirmClick($event, () => resetPresets())' in preset_modal+ assert "Reset to default" in preset_modal+ assert "async resetPresets()" in preset_store+ assert "if (!await store.resetGlobalPresets()) return;" in preset_store+ assert "this.refreshPresets();" in preset_store+ assert "refreshPresets();" in preset_modal+++def test_plugin_settings_reset_is_explicit_and_does_not_capture_toast_early() -> None:+ settings_modal = read("webui", "components", "plugins", "plugin-settings.html")+ settings_store = read("webui", "components", "plugins", "plugin-settings-store.js")++ assert "Reset to default" in settings_modal+ assert "const justToast = globalThis.justToast" not in settings_store+ assert 'globalThis.justToast?.("Settings reset to default.", "info")' in settings_storediff --git a/webui/components/plugins/AGENTS.md b/webui/components/plugins/AGENTS.mdindex 219c01176..eb921b78a 100644--- a/webui/components/plugins/AGENTS.md+++ b/webui/components/plugins/AGENTS.md@@ -16,6 +16,7 @@- Keep plugin settings modals bound through `$store.pluginSettingsPrototype` conventions.- Preserve global and scoped toggle semantics using `.toggle-1` and `.toggle-0`.- Use notification helpers for plugin UI feedback.+- Label reset actions `Reset to default` and resolve notification globals when the action runs so late WebUI initialization cannot abort the reset lifecycle.## Work Guidancediff --git a/webui/components/plugins/plugin-settings-store.js b/webui/components/plugins/plugin-settings-store.jsindex c754ecae4..064d2edb2 100644--- a/webui/components/plugins/plugin-settings-store.js+++ b/webui/components/plugins/plugin-settings-store.js@@ -4,8 +4,6 @@ import { fetchApi } from "/js/api.js";import { showConfirmDialog } from "/js/confirmDialog.js";import { store as pluginToggleStore } from "/components/plugins/toggle/plugin-toggle-store.js";-const justToast = globalThis.justToast;-const model = {// which plugin this modal is showingpluginName: null,@@ -359,7 +357,7 @@ const model = {async resetToDefault() {if (!this.pluginName) return;const confirmed = await showConfirmDialog({- title: "Reset to Default",+ title: "Reset to default",message: "This will replace the current settings with the plugin defaults. Any unsaved changes will be lost.",confirmText: "Reset",type: "warning",@@ -373,7 +371,7 @@ const model = {const result = await response.json().catch(() => ({}));if (result.ok) {this.settings = result.data || {};- justToast("Settings reset to default.", "info");+ globalThis.justToast?.("Settings reset to default.", "info");}},diff --git a/webui/components/plugins/plugin-settings.html b/webui/components/plugins/plugin-settings.htmlindex a37d8e7c1..75c22f0e5 100644--- a/webui/components/plugins/plugin-settings.html+++ b/webui/components/plugins/plugin-settings.html@@ -139,7 +139,7 @@x-show="!context.hideSettingsActions"@click="context.resetToDefault()":disabled="context?.isSaving || context?.isLoading">- Default+ Reset to default</button><button class="btn btn-field"x-show="context.wizardFooter?.showNext?.()"