Skip to content

Agent Zero AI framework

Add ZIP download toast feedback

Alessandro764339b5e797
diff --git a/api/notification_create.py b/api/notification_create.py
index b439f7833..11609a0db 100644
--- a/api/notification_create.py
+++ b/api/notification_create.py
@@ -26,10 +26,10 @@ class NotificationCreate(ApiHandler):
# Validate display_time
try:
display_time = int(display_time)
- if display_time <= 0:
- display_time = 3 # Reset to default if invalid
+ if display_time < 0:
+ display_time = 3 # Reset to default if negative
except (ValueError, TypeError):
- display_time = 3 # Reset to default if not convertible to int
+ display_time = 3 # Reset to default if not numeric
# Validate notification type
try:
diff --git a/tests/test_download_toast_regressions.py b/tests/test_download_toast_regressions.py
new file mode 100644
index 000000000..4ccbc0bc5
--- /dev/null
+++ b/tests/test_download_toast_regressions.py
@@ -0,0 +1,63 @@
+from pathlib import Path
+
+
+PROJECT_ROOT = Path(__file__).resolve().parents[1]
+
+
+def read(*parts: str) -> str:
+ return PROJECT_ROOT.joinpath(*parts).read_text(encoding="utf-8")
+
+
+def test_notification_store_supports_persistent_grouped_toasts():
+ store = read("webui", "components", "notifications", "notification-store.js")
+ api = read("api", "notification_create.py")
+
+ assert "isPersistentToast(toast)" in store
+ assert "return this.getToastDisplayTime(toast) <= 0;" in store
+ assert store.count("if (this.isPersistentToast(toast)) return;") >= 2
+ assert "this.restartToastTimer(toast.toastId);" in store
+ assert "this.removeFromToastStack(existingToast.toastId);" in store
+ assert "if display_time < 0:" in api
+ assert "if display_time <= 0:" not in api
+
+
+def test_backup_zip_downloads_emit_grouped_preparing_and_downloading_toasts():
+ store = read("webui", "components", "settings", "backup", "backup-store.js")
+
+ assert 'window.toastFrontendInfo?.("Preparing download...", "Download", 0, group, undefined, true);' in store
+ assert 'window.toastFrontendInfo?.("Downloading...", "Download", 3, group, undefined, true);' in store
+ assert 'window.toastFrontendError?.(message || "Download failed", "Download Error", 8, group, undefined, true);' in store
+ assert 'this.createDownloadToastGroup("backup-create")' in store
+ assert 'this.createDownloadToastGroup("backup-download")' in store
+
+ create_start = store.index("async createBackup()")
+ create_prepare = store.index("this.showDownloadPreparingToast(downloadToastGroup);", create_start)
+ create_fetch = store.index("const response = await fetchApi('/backup_create'", create_start)
+ assert create_prepare < create_fetch
+
+ download_start = store.index("async downloadBackup")
+ download_prepare = store.index("this.showDownloadPreparingToast(downloadToastGroup);", download_start)
+ download_fetch = store.index("const response = await fetchApi('/backup_download'", download_start)
+ assert download_prepare < download_fetch
+
+
+def test_file_browser_zip_downloads_emit_grouped_preparing_and_downloading_toasts():
+ store = read("webui", "components", "modals", "file-browser", "file-browser-store.js")
+
+ assert 'window.toastFrontendInfo?.("Preparing download...", "Download", 0, group, undefined, true);' in store
+ assert 'window.toastFrontendInfo?.("Downloading...", "Download", 3, group, undefined, true);' in store
+ assert 'this.createDownloadToastGroup("file-browser-bulk-download")' in store
+ assert 'this.createDownloadToastGroup("file-browser-directory-download")' in store
+ assert "if (file.is_dir) {" in store
+ assert "return this.downloadDirectory(file);" in store
+ assert "link.download = file.name;" in store
+
+ bulk_start = store.index("async bulkDownloadFiles()")
+ bulk_prepare = store.index("this.showDownloadPreparingToast(downloadToastGroup);", bulk_start)
+ bulk_fetch = store.index('const resp = await fetchApi("/download_work_dir_files"', bulk_start)
+ assert bulk_prepare < bulk_fetch
+
+ directory_start = store.index("async downloadDirectory(file)")
+ directory_prepare = store.index("this.showDownloadPreparingToast(downloadToastGroup);", directory_start)
+ directory_fetch = store.index("const resp = await fetchApi(`/download_work_dir_file", directory_start)
+ assert directory_prepare < directory_fetch
diff --git a/webui/components/modals/file-browser/file-browser-store.js b/webui/components/modals/file-browser/file-browser-store.js
index 3c71f325c..dd6fb0aca 100644
--- a/webui/components/modals/file-browser/file-browser-store.js
+++ b/webui/components/modals/file-browser/file-browser-store.js
@@ -610,14 +610,32 @@ const model = {
return asciiMatch?.[1] || fallback;
},
+ createDownloadToastGroup(prefix) {
+ return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
+ },
+
+ showDownloadPreparingToast(group) {
+ window.toastFrontendInfo?.("Preparing download...", "Download", 0, group, undefined, true);
+ },
+
+ showDownloadStartedToast(group) {
+ window.toastFrontendInfo?.("Downloading...", "Download", 3, group, undefined, true);
+ },
+
+ showDownloadErrorToast(group, message) {
+ window.toastFrontendError?.(message || "Download failed", "Download Error", 8, group, undefined, true);
+ },
+
async bulkDownloadFiles() {
const selectedFiles = this.selectedFiles;
if (!selectedFiles.length || this.isBulkBusy) return;
this.isBulkBusy = true;
this.closeDropdown();
+ const downloadToastGroup = this.createDownloadToastGroup("file-browser-bulk-download");
try {
+ this.showDownloadPreparingToast(downloadToastGroup);
const resp = await fetchApi("/download_work_dir_files", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -643,14 +661,11 @@ const model = {
document.body.removeChild(link);
setTimeout(() => URL.revokeObjectURL(url), 0);
- window.toastFrontendSuccess(
- `Prepared ${selectedFiles.length} ${selectedFiles.length === 1 ? "item" : "items"} as ZIP`,
- "File Browser"
- );
+ this.showDownloadStartedToast(downloadToastGroup);
} catch (error) {
- window.toastFrontendError(
- error?.message || "Failed to download selected files",
- "File Browser"
+ this.showDownloadErrorToast(
+ downloadToastGroup,
+ error?.message || "Failed to download selected files"
);
} finally {
this.isBulkBusy = false;
@@ -756,10 +771,47 @@ const model = {
}
},
+ async downloadDirectory(file) {
+ const downloadToastGroup = this.createDownloadToastGroup("file-browser-directory-download");
+
+ try {
+ this.showDownloadPreparingToast(downloadToastGroup);
+ const resp = await fetchApi(`/download_work_dir_file?path=${encodeURIComponent(file.path)}`, {
+ method: "GET",
+ });
+
+ if (!resp.ok) {
+ const message = await resp.text();
+ throw new Error(message || "Download failed");
+ }
+
+ const blob = await resp.blob();
+ const url = URL.createObjectURL(blob);
+ const fallback = `${file.name}.zip`;
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = this.getDownloadFilename(resp, fallback);
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ setTimeout(() => URL.revokeObjectURL(url), 0);
+ this.showDownloadStartedToast(downloadToastGroup);
+ } catch (error) {
+ this.showDownloadErrorToast(
+ downloadToastGroup,
+ error?.message || "Failed to download directory"
+ );
+ }
+ },
+
downloadFile(file) {
+ if (file.is_dir) {
+ return this.downloadDirectory(file);
+ }
+
const link = document.createElement("a");
link.href = `/api/download_work_dir_file?path=${encodeURIComponent(file.path)}`;
- link.download = file.is_dir ? `${file.name}.zip` : file.name;
+ link.download = file.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
diff --git a/webui/components/notifications/notification-store.js b/webui/components/notifications/notification-store.js
index 7b1a3f9fe..f41981903 100644
--- a/webui/components/notifications/notification-store.js
+++ b/webui/components/notifications/notification-store.js
@@ -111,6 +111,15 @@ const model = {
}
},
+ getToastDisplayTime(toast) {
+ const displayTime = Number(toast?.display_time);
+ return Number.isFinite(displayTime) ? displayTime : 3;
+ },
+
+ isPersistentToast(toast) {
+ return this.getToastDisplayTime(toast) <= 0;
+ },
+
// NEW: Add notification to toast stack
addToToastStack(notification) {
// If notification has a group, remove any existing toasts with the same group
@@ -148,6 +157,8 @@ const model = {
if (toastIndex < 0) return;
const toast = this.toastStack[toastIndex];
+ if (this.isPersistentToast(toast)) return;
+
if (toast.autoRemoveTimer) {
clearTimeout(toast.autoRemoveTimer);
toast.autoRemoveTimer = null;
@@ -159,11 +170,12 @@ const model = {
if (toastIndex < 0) return;
const toast = this.toastStack[toastIndex];
+ if (this.isPersistentToast(toast)) return;
this.clearToastTimer(toastId);
toast.autoRemoveTimer = setTimeout(() => {
this.removeFromToastStack(toast.toastId);
- }, toast.display_time * 1000);
+ }, this.getToastDisplayTime(toast) * 1000);
},
// NEW: Remove toast from stack
@@ -173,6 +185,7 @@ const model = {
const toast = this.toastStack[index];
if (toast.autoRemoveTimer) {
clearTimeout(toast.autoRemoveTimer);
+ toast.autoRemoveTimer = null;
}
this.toastStack.splice(index, 1);
@@ -198,8 +211,9 @@ const model = {
this.toastStack.forEach((toast) => {
if (toast.autoRemoveTimer) {
clearTimeout(toast.autoRemoveTimer);
- if (withCallback) this.afterToastRemoved(toast, removedByUser);
+ toast.autoRemoveTimer = null;
}
+ if (withCallback) this.afterToastRemoved(toast, removedByUser);
});
this.toastStack = [];
},
@@ -208,8 +222,11 @@ const model = {
cleanupExpiredToasts() {
const now = Date.now();
this.toastStack = this.toastStack.filter((toast) => {
+ if (this.isPersistentToast(toast)) {
+ return true;
+ }
const age = now - toast.addedAt;
- const maxAge = toast.display_time * 1000;
+ const maxAge = this.getToastDisplayTime(toast) * 1000;
if (age > maxAge) {
if (toast.autoRemoveTimer) {
@@ -624,10 +641,7 @@ const model = {
if (existingToastIndex >= 0) {
const existingToast = this.toastStack[existingToastIndex];
- if (existingToast.autoRemoveTimer) {
- clearTimeout(existingToast.autoRemoveTimer);
- }
- this.toastStack.splice(existingToastIndex, 1);
+ this.removeFromToastStack(existingToast.toastId);
}
}
@@ -653,9 +667,7 @@ const model = {
}
// Set auto-dismiss timer
- toast.autoRemoveTimer = setTimeout(() => {
- this.removeFromToastStack(toast.toastId);
- }, notification.display_time * 1000);
+ this.restartToastTimer(toast.toastId);
return notification.id;
},
diff --git a/webui/components/settings/backup/backup-store.js b/webui/components/settings/backup/backup-store.js
index 5dfebeffc..760782529 100644
--- a/webui/components/settings/backup/backup-store.js
+++ b/webui/components/settings/backup/backup-store.js
@@ -86,6 +86,22 @@ const model = {
this.fileOperationsLog = '';
},
+ createDownloadToastGroup(prefix) {
+ return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
+ },
+
+ showDownloadPreparingToast(group) {
+ window.toastFrontendInfo?.("Preparing download...", "Download", 0, group, undefined, true);
+ },
+
+ showDownloadStartedToast(group) {
+ window.toastFrontendInfo?.("Downloading...", "Download", 3, group, undefined, true);
+ },
+
+ showDownloadErrorToast(group, message) {
+ window.toastFrontendError?.(message || "Download failed", "Download Error", 8, group, undefined, true);
+ },
+
// Cleanup method for modal close
onClose() {
this.resetState();
@@ -389,12 +405,15 @@ const model = {
return;
}
+ const downloadToastGroup = this.createDownloadToastGroup("backup-create");
+
try {
this.loading = true;
this.loadingMessage = 'Creating backup...';
this.error = '';
this.clearFileOperations();
this.addFileOperation('Starting backup creation...');
+ this.showDownloadPreparingToast(downloadToastGroup);
const metadata = this.backupMetadataConfig;
@@ -421,7 +440,7 @@ const model = {
window.URL.revokeObjectURL(url);
this.addFileOperation('Backup created and downloaded successfully!');
- window.toastFrontendInfo('Backup created and downloaded successfully', 'Backup Status');
+ this.showDownloadStartedToast(downloadToastGroup);
} else {
// Try to parse error response
const errorText = await response.text();
@@ -432,18 +451,23 @@ const model = {
this.error = `Backup creation failed: ${response.status} ${response.statusText}`;
}
this.addFileOperation(`Error: ${this.error}`);
+ this.showDownloadErrorToast(downloadToastGroup, this.error);
}
} catch (error) {
this.error = `Backup error: ${error.message}`;
this.addFileOperation(`Error: ${error.message}`);
+ this.showDownloadErrorToast(downloadToastGroup, this.error);
} finally {
this.loading = false;
}
},
async downloadBackup(backupPath, backupName) {
+ const downloadToastGroup = this.createDownloadToastGroup("backup-download");
+
try {
+ this.showDownloadPreparingToast(downloadToastGroup);
const response = await fetchApi('/backup_download', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -458,9 +482,16 @@ const model = {
a.download = `${backupName}.zip`;
a.click();
window.URL.revokeObjectURL(url);
+ this.showDownloadStartedToast(downloadToastGroup);
+ } else {
+ const errorText = await response.text();
+ this.error = errorText || `Download failed: ${response.status}`;
+ this.showDownloadErrorToast(downloadToastGroup, this.error);
}
} catch (error) {
console.error('Download error:', error);
+ this.error = error.message || 'Download failed';
+ this.showDownloadErrorToast(downloadToastGroup, this.error);
}
},