Skip to content

Agent Zero AI framework

fix: notification fixes, refactor and restart toast persistence

Rafael Uzarowski9145c4d58da7
diff --git a/webui/components/notifications/notification-icons.html b/webui/components/notifications/notification-icons.html
index 9df55fbee..918cd885f 100644
--- a/webui/components/notifications/notification-icons.html
+++ b/webui/components/notifications/notification-icons.html
@@ -1,26 +1,28 @@
<html>
<head>
<script type="module">
- import { store } from "/js/notificationStore.js";
+ import { store } from "/components/notifications/notification-store.js";
</script>
</head>
<body>
<div x-data>
- <!-- Notification Toggle Button -->
- <div class="notification-toggle"
- :class="{
- 'has-unread': $store.notificationStore.unreadCount > 0,
- 'has-notifications': $store.notificationStore.notifications.length > 0
- }"
- @click="$store.notificationStore.openModal()"
- title="View Notifications">
- <div class="notification-icon">
- 🔔
+ <template x-if="$store.notificationStore">
+ <!-- Notification Toggle Button -->
+ <div class="notification-toggle"
+ :class="{
+ 'has-unread': $store.notificationStore.unreadCount > 0,
+ 'has-notifications': $store.notificationStore.notifications.length > 0
+ }"
+ @click="$store.notificationStore.openModal()"
+ title="View Notifications">
+ <div class="notification-icon">
+ <span class="material-symbols-outlined">notifications</span>
+ </div>
+ <span x-show="$store.notificationStore.unreadCount > 0"
+ class="notification-badge"
+ x-text="$store.notificationStore.unreadCount"></span>
</div>
- <span x-show="$store.notificationStore.unreadCount > 0"
- class="notification-badge"
- x-text="$store.notificationStore.unreadCount"></span>
- </div>
+ </template>
</div>
</body>
</html>
diff --git a/webui/components/notifications/notification-modal.html b/webui/components/notifications/notification-modal.html
index 21e63b2bc..1cd1c538c 100644
--- a/webui/components/notifications/notification-modal.html
+++ b/webui/components/notifications/notification-modal.html
@@ -2,12 +2,7 @@
<head>
<title>Notifications</title>
<script type="module">
- import { store } from "/js/notificationStore.js";
-
- // Ensure notification store is available globally for the modal
- if (!window.notificationStore) {
- window.notificationStore = store;
- }
+ import { store } from "/components/notifications/notification-store.js";
</script>
</head>
<body>
@@ -16,24 +11,24 @@
<div class="modal-subheader">
<div class="notification-header-actions">
<button class="notification-action"
- @click="$store.notificationStore.clearAll()"
- :disabled="$store.notificationStore.getDisplayNotifications().length === 0"
+ @click="$store.notificationStore?.clearAll()"
+ :disabled="!$store.notificationStore || $store.notificationStore.getDisplayNotifications().length === 0"
title="Clear All">
- 🗑️ Clear All
+ <span class="material-symbols-outlined">delete</span> Clear All
</button>
</div>
</div>
<!-- Notifications List -->
- <div class="notification-list" x-show="$store.notificationStore.getDisplayNotifications().length > 0">
- <template x-for="notification in $store.notificationStore.getDisplayNotifications()" :key="notification.id">
+ <div class="notification-list" 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 }"
- :class="$store.notificationStore.getNotificationItemClass(notification)"
- @click="$store.notificationStore.markAsRead(notification.id)">
+ :class="$store.notificationStore?.getNotificationItemClass(notification) || 'notification-item'"
+ @click="$store.notificationStore?.markAsRead(notification.id)">
<div class="notification-icon"
- x-html="$store.notificationStore.getNotificationIcon(notification.type)">
+ x-html="$store.notificationStore?.getNotificationIcon(notification.type) || ''">
</div>
<div class="notification-content">
@@ -45,7 +40,7 @@
x-text="notification.message">
</div>
<div class="notification-timestamp"
- x-text="$store.notificationStore.formatTimestamp(notification.timestamp)">
+ x-text="$store.notificationStore?.formatTimestamp(notification.timestamp) || notification.timestamp">
</div>
<!-- Expand Toggle Button (as last row element) -->
@@ -74,11 +69,13 @@
</div>
<!-- Empty State -->
- <div class="notification-empty" x-show="$store.notificationStore.getDisplayNotifications().length === 0">
- <div class="notification-empty-icon">🔔</div>
+ <div class="notification-empty" x-show="!$store.notificationStore || $store.notificationStore.getDisplayNotifications().length === 0">
+ <div class="notification-empty-icon">
+ <span class="material-symbols-outlined">notifications</span>
+ </div>
<p>No notifications to display</p>
<p style="font-size: 0.8rem; opacity: 0.7; margin-top: 0.5rem;"
- x-show="$store.notificationStore.notifications.length > 0">
+ x-show="$store.notificationStore && $store.notificationStore.notifications.length > 0">
All notifications have been read and are older than 5 minutes
</p>
</div>
diff --git a/webui/js/notificationStore.js b/webui/components/notifications/notification-store.js
similarity index 93%
rename from webui/js/notificationStore.js
rename to webui/components/notifications/notification-store.js
index 257b8b14f..869e54f41 100644
--- a/webui/js/notificationStore.js
+++ b/webui/components/notifications/notification-store.js
@@ -306,16 +306,17 @@ const model = {
return `notification-item ${typeClass} ${readClass}`;
},
- // Get icon for notification type
+ // Get icon for notification type (Google Material Icons)
getNotificationIcon(type) {
const icons = {
- info: "ℹ️",
- success: "✅",
- warning: "⚠️",
- error: "❌",
- progress: "⏳"
+ info: "info",
+ success: "check_circle",
+ warning: "warning",
+ error: "error",
+ progress: "hourglass_empty"
};
- return icons[type] || "ℹ️";
+ const iconName = icons[type] || "info";
+ return `<span class="material-symbols-outlined">${iconName}</span>`;
},
// Create notification via backend (will appear via polling)
@@ -491,10 +492,10 @@ const model = {
const store = createStore("notificationStore", model);
// NEW: Global function for frontend error toasts (replaces toastFetchError)
-window.toastFrontendError = async function(message, title = "Connection Error") {
+window.toastFrontendError = async function(message, title = "Connection Error", display_time = 8, group = "") {
if (window.Alpine && window.Alpine.store && window.Alpine.store('notificationStore')) {
try {
- return await window.Alpine.store('notificationStore').frontendError(message, title);
+ return await window.Alpine.store('notificationStore').addFrontendToast('error', message, title, display_time, group);
} catch (error) {
console.error('Failed to create frontend error notification:', error);
// Fallback to console if something goes wrong
@@ -509,10 +510,10 @@ window.toastFrontendError = async function(message, title = "Connection Error")
};
// NEW: Additional global convenience functions
-window.toastFrontendWarning = async function(message, title = "Warning") {
+window.toastFrontendWarning = async function(message, title = "Warning", display_time = 5, group = "") {
if (window.Alpine && window.Alpine.store && window.Alpine.store('notificationStore')) {
try {
- return await window.Alpine.store('notificationStore').frontendWarning(message, title);
+ return await window.Alpine.store('notificationStore').addFrontendToast('warning', message, title, display_time, group);
} catch (error) {
console.error('Failed to create frontend warning notification:', error);
console.warn('Frontend Warning:', title, '-', message);
@@ -524,10 +525,10 @@ window.toastFrontendWarning = async function(message, title = "Warning") {
}
};
-window.toastFrontendInfo = async function(message, title = "Info") {
+window.toastFrontendInfo = async function(message, title = "Info", display_time = 3, group = "") {
if (window.Alpine && window.Alpine.store && window.Alpine.store('notificationStore')) {
try {
- return await window.Alpine.store('notificationStore').frontendInfo(message, title);
+ return await window.Alpine.store('notificationStore').addFrontendToast('info', message, title, display_time, group);
} catch (error) {
console.error('Failed to create frontend info notification:', error);
console.log('Frontend Info:', title, '-', message);
@@ -539,4 +540,19 @@ window.toastFrontendInfo = async function(message, title = "Info") {
}
};
+window.toastFrontendSuccess = async function(message, title = "Success", display_time = 3, group = "") {
+ if (window.Alpine && window.Alpine.store && window.Alpine.store('notificationStore')) {
+ try {
+ return await window.Alpine.store('notificationStore').addFrontendToast('success', message, title, display_time, group);
+ } catch (error) {
+ console.error('Failed to create frontend success notification:', error);
+ console.log('Frontend Success:', title, '-', message);
+ return null;
+ }
+ } else {
+ console.log('Frontend Success:', title, '-', message);
+ return null;
+ }
+};
+
export { store };
diff --git a/webui/components/notifications/notification-toast-stack.html b/webui/components/notifications/notification-toast-stack.html
index 8bbd77fc2..4f37c6d5a 100644
--- a/webui/components/notifications/notification-toast-stack.html
+++ b/webui/components/notifications/notification-toast-stack.html
@@ -2,14 +2,15 @@
<head>
<title>Notification Toast Stack</title>
<script type="module">
- import { store } from "/js/notificationStore.js";
+ import { store } from "/components/notifications/notification-store.js";
</script>
</head>
<body>
<div x-data>
- <!-- Toast Stack Container -->
- <div class="toast-stack-container"
- x-show="$store.notificationStore.toastStack.length > 0">
+ <template x-if="$store.notificationStore">
+ <!-- Toast Stack Container -->
+ <div class="toast-stack-container"
+ x-show="$store.notificationStore.toastStack.length > 0">
<template x-for="(toast, index) in $store.notificationStore.toastStack" :key="toast.toastId">
<div class="toast-item"
@@ -41,11 +42,12 @@
<button class="toast-dismiss"
@click.stop="$store.notificationStore.removeFromToastStack(toast.toastId)"
title="Dismiss">
- ✕
+ <span class="material-symbols-outlined">close</span>
</button>
</div>
</template>
- </div>
+ </div>
+ </template>
</div>
<style>
diff --git a/webui/index.html b/webui/index.html
index 9de6562f0..a5d3d4032 100644
--- a/webui/index.html
+++ b/webui/index.html
@@ -103,7 +103,7 @@
<script type="module" src="js/scheduler.js"></script>
<script type="module" src="js/speech.js"></script>
<script type="module" src="js/history.js"></script>
- <script type="module" src="js/notificationStore.js"></script>
+
<script type="module" src="index.js"></script>
<!-- Then load Alpine.js -->
@@ -388,7 +388,7 @@
<div>
<x-component path="/chat/attachments/inputPreview.html" />
</div>
-
+
<!-- Top row with input and buttons -->
<div class="input-row">
<!-- Attachment icon with tooltip -->
diff --git a/webui/index.js b/webui/index.js
index 64cd5b639..4e435e51d 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -812,14 +812,14 @@ window.nudge = async function () {
window.restart = async function () {
try {
if (!getConnectionStatus()) {
- toast("Backend disconnected, cannot restart.", "error");
+ await toastFrontendError("Backend disconnected, cannot restart.", "Restart Error");
return;
}
// First try to initiate restart
const resp = await sendJsonData("/restart", {});
} catch (e) {
- // Show restarting message
- toast("Restarting...", "info", 0);
+ // Show restarting message with no timeout and restart group
+ await toastFrontendInfo("Restarting...", "System Restart", 9999, "restart");
let retries = 0;
const maxRetries = 240; // Maximum number of retries (60 seconds with 250ms interval)
@@ -827,9 +827,9 @@ window.restart = async function () {
while (retries < maxRetries) {
try {
const resp = await sendJsonData("/health", {});
- // Server is back up, show success message
+ // Server is back up, show success message that replaces the restarting message
await new Promise((resolve) => setTimeout(resolve, 250));
- toast("Restarted", "success", 5000);
+ await toastFrontendSuccess("Restarted", "System Restart", 5, "restart");
return;
} catch (e) {
// Server still down, keep waiting
@@ -839,7 +839,7 @@ window.restart = async function () {
}
// If we get here, restart failed or took too long
- toast("Restart timed out or failed", "error", 5000);
+ await toastFrontendError("Restart timed out or failed", "Restart Error", 8, "restart");
}
};
@@ -1056,13 +1056,7 @@ document.addEventListener("DOMContentLoaded", function () {
setupTabs();
initializeActiveTab();
- // Initialize notification store early to ensure it's ready for polling
- setTimeout(() => {
- if (globalThis.Alpine?.store('notificationStore')) {
- globalThis.Alpine.store('notificationStore').initialize();
- console.log('Notification store initialized on DOM ready');
- }
- }, 100); // Small delay to ensure Alpine is ready
+
});
// Setup tabs functionality
diff --git a/webui/js/initFw.js b/webui/js/initFw.js
index fe62ac6ca..5560d0eb6 100644
--- a/webui/js/initFw.js
+++ b/webui/js/initFw.js
@@ -1,6 +1,5 @@
import * as _modals from "./modals.js";
import * as _components from "./components.js";
-import "./notificationStore.js";
await import("../vendor/alpine/alpine.min.js");
@@ -12,13 +11,3 @@ Alpine.directive(
cleanup(() => onDestroy());
}
);
-
-// Initialize notification store when Alpine is ready
-document.addEventListener('alpine:init', () => {
- // Initialize the notification store
- setTimeout(() => {
- if (Alpine.store('notificationStore')) {
- Alpine.store('notificationStore').initialize();
- }
- }, 100);
-});