Agent Zero AI framework
Move preset editor behavior into Alpine store
Alessandrodb7b90823e28
diff --git a/AGENTS.md b/AGENTS.mdindex 31ab6a620..07bbca052 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -131,6 +131,7 @@ Key Files:</div>```- Store Registration: Use createStore from /js/AlpineStore.js.+- Template Expression Scope: Keep Alpine attributes declarative: property reads, bindings, guards, and short method calls. Put object or array construction, cloning, multi-step mutation, async workflows, and reusable behavior in named JavaScript store or component methods; simple toggles and assignments may stay inline.- Modals: Use openModal(path) and closeModal() from /js/modals.js.### Plugin Architecturediff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.mdindex 969cce154..c0101d740 100644--- a/plugins/_model_config/AGENTS.md+++ b/plugins/_model_config/AGENTS.md@@ -20,7 +20,7 @@- `model_config_get` exposes `model_configured` as a derived chat-model readiness flag from provider, model name, and API-key availability.- Applying a model preset may inherit durable tuning such as context windows and rate limits, but must replace or clear per-slot `kwargs` so provider-specific extra params never leak across model providers.- 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`.-- Preset editor rows use stable UI-only keys; never key them by array position or editable preset name because deleting or renaming a row must not rebind nested model fields to another preset.+- `modelConfig.createPresetEditor()` owns local preset drafts, row actions, and stable UI-only row keys so deletion or renaming cannot rebind nested model fields.## Work Guidancediff --git a/plugins/_model_config/webui/main.html b/plugins/_model_config/webui/main.htmlindex 6d3b54b7f..ad2846827 100644--- a/plugins/_model_config/webui/main.html+++ b/plugins/_model_config/webui/main.html@@ -15,10 +15,7 @@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)).map((preset, idx) => ({ ...preset, _key: idx })),- nextPresetKey: $store.modelConfig.globalPresets.length- }">+ <div class="presets-page" x-data="$store.modelConfig.createPresetEditor()"><div class="presets-header"><div class="field-title" style="font-size:1rem;">Model Presets</div><div class="field-description">Global presets shared across all projects and agents. Used by the model switcher in the chat area.</div>@@ -34,7 +31,7 @@<span class="preset-card-summary" x-show="!expanded"x-text="(preset.chat?.provider ? preset.chat.provider + '/' : '') + (preset.chat?.name || '')"></span><button class="text-button preset-delete-btn"- @click.stop="$confirmClick($event, () => { presets.splice(idx, 1); presets = [...presets]; })"+ @click.stop="$confirmClick($event, () => removePreset(idx))"title="Remove preset"><span class="material-symbols-outlined" style="font-size:16px;">close</span></button>@@ -64,14 +61,7 @@</template><div class="presets-actions">- <button class="text-button preset-add-btn"- @click="- presets = [...presets, {- _key: nextPresetKey++,- name: 'Preset ' + (presets.length + 1),- chat: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' },- utility: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' }- }]">+ <button class="text-button preset-add-btn" @click="addPreset()"><span class="material-symbols-outlined">add</span><span>Add Preset</span></button>@@ -89,7 +79,7 @@</div><div class="presets-footer">- <button class="button" @click="(async () => { await $store.modelConfig.persistAllDirtyApiKeys(); await $store.modelConfig.saveGlobalPresets(presets); })()">+ <button class="button" @click="savePresets()"><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 c574b84cd..65415623e 100644--- a/plugins/_model_config/webui/model-config-store.js+++ b/plugins/_model_config/webui/model-config-store.js@@ -268,6 +268,35 @@ export const store = createStore("modelConfig", {},// Global presets+ createPresetEditor() {+ const store = this;+ let nextPresetKey = 0;+ const presets = clonePlain(this.globalPresets).map(preset => ({+ ...preset,+ _key: nextPresetKey++,+ }));++ return {+ presets,+ addPreset() {+ this.presets = [...this.presets, {+ _key: nextPresetKey++,+ name: `Preset ${this.presets.length + 1}`,+ chat: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' },+ utility: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' },+ }];+ },+ removePreset(index) {+ this.presets.splice(index, 1);+ this.presets = [...this.presets];+ },+ async savePresets() {+ await store.persistAllDirtyApiKeys();+ await store.saveGlobalPresets(this.presets);+ },+ };+ },+async loadGlobalPresets() {try {const res = await fetchApi(`${API_BASE}/model_presets`, {diff --git a/tests/test_model_config_ui.py b/tests/test_model_config_ui.pyindex 9151d63b6..b7735c19d 100644--- a/tests/test_model_config_ui.py+++ b/tests/test_model_config_ui.py@@ -24,8 +24,13 @@ def test_model_config_text_buttons_have_shared_primitive() -> None:def test_model_preset_rows_keep_stable_identity_after_middle_delete() -> None:preset_modal = read("plugins", "_model_config", "webui", "main.html")+ preset_store = read("plugins", "_model_config", "webui", "model-config-store.js")+ assert 'x-data="$store.modelConfig.createPresetEditor()"' in preset_modalassert ':key="preset._key"' in preset_modal- assert "_key: idx" in preset_modal- assert "_key: nextPresetKey++" in preset_modal+ assert "createPresetEditor()" in preset_store+ assert "_key: nextPresetKey++" in preset_store+ assert "removePreset(index)" in preset_storeassert ':key="idx"' not in preset_modal+ assert "JSON.parse(JSON.stringify" not in preset_modal+ assert "presets.splice" not in preset_modal