Agent Zero AI framework
Fix notification actions in notifications modal and preset editor select state
Alessandro41476c478cd8
diff --git a/plugins/_model_config/webui/main.html b/plugins/_model_config/webui/main.htmlindex 83c58e6e1..92c4939dd 100644--- a/plugins/_model_config/webui/main.html+++ b/plugins/_model_config/webui/main.html@@ -30,7 +30,7 @@<span class="field-title">Preset</span><select x-model.number="selectedKey" x-init="$nextTick(() => $el.focus())"><template x-for="preset in presets" :key="preset._key">- <option :value="preset._key" x-text="preset.name"></option>+ <option :value="preset._key" :selected="preset._key === selectedKey" x-text="preset.name"></option></template></select></label>diff --git a/tests/test_download_toast_regressions.py b/tests/test_download_toast_regressions.pyindex a10ac78ac..0f9e8d360 100644--- a/tests/test_download_toast_regressions.py+++ b/tests/test_download_toast_regressions.py@@ -117,6 +117,28 @@ def test_notification_store_supports_persistent_grouped_toasts():assert "if (response?.success) window.location.reload();" in store+def test_notification_action_buttons_work_in_notifications_modal():+ store = read("webui", "components", "notifications", "notification-store.js")+ modal = read("webui", "components", "notifications", "notification-modal.html")++ # Action buttons inside notification messages are authored against the+ # toast-stack scope (``toast.toastId``). The notifications modal renders the+ # same message HTML through x-html, so it must expose a toast-compatible+ # scope or the buttons silently fail there.+ assert "toast: { ...notification, toastId: 'toast-' + notification.id }" in modal++ # Reload actions must keep working when the notification is not in the+ # toast stack anymore (clicked from the notifications modal).+ assert "const notificationId = toast?.id || notificationIdFromToastId(toastId);" in store+ assert "toastId.startsWith(toastIdPrefix)" in store+ assert "toastId.slice(toastIdPrefix.length)" in store++ # Plain dismissal from the modal mirrors the toast behavior by marking the+ # notification as read instead of being a silent no-op.+ assert "const notificationId = notificationIdFromToastId(toastId);" in store+ assert "if (notificationId) this.markAsRead(notificationId);" in store++def test_backup_zip_downloads_emit_grouped_preparing_and_downloading_toasts():store = read("webui", "components", "settings", "backup", "backup-store.js")diff --git a/tests/test_model_config_ui.py b/tests/test_model_config_ui.pyindex 2bc9f72b8..a3eee3c36 100644--- a/tests/test_model_config_ui.py+++ b/tests/test_model_config_ui.py@@ -38,6 +38,17 @@ def test_model_preset_rows_keep_stable_identity_after_middle_delete() -> None:assert "presets.splice" not in preset_store+def test_model_preset_editor_select_shows_selected_preset_on_open() -> None:+ preset_modal = read("plugins", "_model_config", "webui", "main.html")++ # x-model syncs the select value before the x-for template renders the+ # <option> elements, so the browser falls back to the first option+ # ("Default") while Alpine's selectedKey still points at the real preset.+ # Selecting that same first option then fires no change event. The :selected+ # binding keeps the DOM selection in sync with the model.+ assert ':selected="preset._key === selectedKey"' 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")diff --git a/webui/components/notifications/notification-modal.html b/webui/components/notifications/notification-modal.htmlindex d301d653c..f6bb6f3eb 100644--- a/webui/components/notifications/notification-modal.html+++ b/webui/components/notifications/notification-modal.html@@ -27,7 +27,8 @@x-show="$store.notificationStore && $store.notificationStore.getDisplayNotifications().length > 0"><template x-for="notification in ($store.notificationStore?.getDisplayNotifications() || [])":key="notification.id">- <div class="notification-item" x-data="{ expanded: false }"+ <div class="notification-item"+ x-data="{ expanded: false, toast: { ...notification, toastId: 'toast-' + notification.id } }":class="$store.notificationStore?.getNotificationItemClass(notification) || 'notification-item'"@click="$store.notificationStore?.markAsRead(notification.id)">diff --git a/webui/components/notifications/notification-store.js b/webui/components/notifications/notification-store.jsindex db1f5d712..c4b16cf44 100644--- a/webui/components/notifications/notification-store.js+++ b/webui/components/notifications/notification-store.js@@ -20,6 +20,17 @@ export const defaultPriority = NotificationPriority.NORMAL;const maxNotifications = 100;const maxToasts = 5;+const toastIdPrefix = "toast-";++// Notification action buttons are authored against the toast-stack scope, but the+// same message HTML is also rendered inside the notifications modal. Resolve the+// underlying notification ID from either surface so actions keep working there.+const notificationIdFromToastId = (toastId) => {+ if (typeof toastId !== "string" || !toastId.trim()) return "";+ return toastId.startsWith(toastIdPrefix)+ ? toastId.slice(toastIdPrefix.length)+ : toastId;+};const model = {notifications: Array(),@@ -197,15 +208,24 @@ const model = {// called by UIdismissToast(toastId) {- this.removeFromToastStack(toastId, true);+ const toast = this.toastStack.find((t) => t.toastId === toastId);+ if (toast) {+ this.removeFromToastStack(toastId, true);+ return;+ }+ // Clicked from the notifications modal: no toast to remove, but still+ // mirror the toast dismissal by marking the notification as read.+ const notificationId = notificationIdFromToastId(toastId);+ if (notificationId) this.markAsRead(notificationId);},async dismissToastAndReload(toastId) {const toast = this.toastStack.find((item) => item.toastId === toastId);- if (!toast?.id) return;+ const notificationId = toast?.id || notificationIdFromToastId(toastId);+ if (!notificationId) return;const response = await API.callJsonApi("notifications_mark_read", {- notification_ids: [toast.id],+ notification_ids: [notificationId],});if (response?.success) window.location.reload();},