Skip to content

Agent Zero AI framework

Adjust message queue behavior

keyboardstaff34e0997e73e9
diff --git a/webui/components/chat/input/chat-bar-input.html b/webui/components/chat/input/chat-bar-input.html
index 66bdfe7ae..2551c7c7a 100644
--- a/webui/components/chat/input/chat-bar-input.html
+++ b/webui/components/chat/input/chat-bar-input.html
@@ -35,18 +35,22 @@
<!-- Send button -->
<button class="chat-button" id="send-button" aria-label="Send message"
@click="$store.chatInput.sendMessage()"
- :class="{ 'send-queue': $store.messageQueue?.hasQueue }"
- :title="$store.messageQueue?.hasQueue ? 'Send queued messages' : 'Send message'">
- <!-- Normal send icon -->
- <template x-if="!$store.messageQueue?.hasQueue">
+ :class="$store.chatInput.sendButtonClass"
+ :title="$store.chatInput.sendButtonTitle">
+ <!-- Send all queued: double arrow -->
+ <template x-if="$store.chatInput.sendButtonIcon === 'send-all'">
+ <span class="material-symbols-outlined">keyboard_double_arrow_right</span>
+ </template>
+ <!-- Queue message: schedule send -->
+ <template x-if="$store.chatInput.sendButtonIcon === 'queue'">
+ <span class="material-symbols-outlined">schedule_send</span>
+ </template>
+ <!-- Normal send -->
+ <template x-if="$store.chatInput.sendButtonIcon === 'send'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M25 20 L75 50 L25 80" fill="none" stroke="currentColor" stroke-width="15"></path>
</svg>
</template>
- <!-- Spinning loader when queue has messages -->
- <template x-if="$store.messageQueue?.hasQueue">
- <span class="send-queue-spinner"></span>
- </template>
</button>
<!-- Microphone button -->
@@ -123,19 +127,7 @@
#send-button.send-queue:hover { background-color: #d35400; }
#send-button:active { -webkit-transform: scale(1); transform: scale(1); transform-origin: center; background-color: #2b309c; }
.chat-button svg { width: 1.5rem; height: 1.5rem; }
-
- /* Queue spinner in send button */
- .send-queue-spinner {
- width: 18px;
- height: 18px;
- border: 3px solid rgba(255,255,255,0.3);
- border-top-color: white;
- border-radius: 50%;
- animation: send-queue-spin 0.8s linear infinite;
- }
- @keyframes send-queue-spin {
- to { transform: rotate(360deg); }
- }
+ #send-button .material-symbols-outlined { font-size: 1.5rem; }
/* Microphone button */
.chat-button.mic-inactive svg { /* Add specific styles if needed */ }
diff --git a/webui/components/chat/input/input-store.js b/webui/components/chat/input/input-store.js
index 0741be179..3a3cf5751 100644
--- a/webui/components/chat/input/input-store.js
+++ b/webui/components/chat/input/input-store.js
@@ -1,10 +1,41 @@
import { createStore } from "/js/AlpineStore.js";
import * as shortcuts from "/js/shortcuts.js";
import { store as fileBrowserStore } from "/components/modals/file-browser/file-browser-store.js";
+import { store as messageQueueStore } from "/components/chat/message-queue/message-queue-store.js";
+import { store as chatTopStore } from "/components/chat/top-section/chat-top-store.js";
+import { store as attachmentsStore } from "/components/chat/attachments/attachmentsStore.js";
const model = {
paused: false,
+ // Computed: send button icon type
+ get sendButtonIcon() {
+ const input = document.getElementById("chat-input");
+ const hasInput = input?.value?.trim() || attachmentsStore?.attachments?.length > 0;
+ const hasQueue = messageQueueStore?.hasQueue;
+ const running = chatTopStore?.running;
+
+ if (hasQueue && !hasInput) return "send-all";
+ if (running && hasInput) return "queue";
+ return "send";
+ },
+
+ // Computed: send button CSS class
+ get sendButtonClass() {
+ const icon = this.sendButtonIcon;
+ if (icon === "send-all") return "send-queue";
+ if (icon === "queue") return "send-queue";
+ return "";
+ },
+
+ // Computed: send button title
+ get sendButtonTitle() {
+ const icon = this.sendButtonIcon;
+ if (icon === "send-all") return "Send all queued messages";
+ if (icon === "queue") return "Add to queue";
+ return "Send message";
+ },
+
init() {
console.log("Input store initialized");
// Event listeners are now handled via Alpine directives in the component
diff --git a/webui/components/chat/message-queue/message-queue-store.js b/webui/components/chat/message-queue/message-queue-store.js
index 14fc8e804..dbc4b5f6d 100644
--- a/webui/components/chat/message-queue/message-queue-store.js
+++ b/webui/components/chat/message-queue/message-queue-store.js
@@ -3,19 +3,37 @@ import * as api from "/js/api.js";
const model = {
items: [],
+ pendingItems: [], // Local pending items (uploading to queue)
get hasQueue() {
- return this.items.length > 0;
+ return this.items.length > 0 || this.pendingItems.length > 0;
},
get count() {
- return this.items.length;
+ return this.items.length + this.pendingItems.length;
+ },
+
+ // Combined items for display: confirmed first, then pending at the end
+ get allItems() {
+ return [...this.items, ...this.pendingItems];
},
async addToQueue(text, attachments = []) {
const context = globalThis.getContext?.();
if (!context) return false;
+ // Generate a temporary ID for pending item
+ const tempId = `pending-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
+ const pendingItem = {
+ id: tempId,
+ text: text || "(attachment only)",
+ attachments: attachments.map(a => a.name || a.file?.name || "file"),
+ pending: true,
+ };
+
+ // Add to pending immediately for UI feedback
+ this.pendingItems = [...this.pendingItems, pendingItem];
+
try {
let filenames = [];
if (attachments.length > 0) {
@@ -30,9 +48,14 @@ const model = {
}
}
const response = await api.callJsonApi("/message_queue_add", { context, text, attachments: filenames });
+
+ // Remove from pending (poll will add the confirmed item)
+ this.pendingItems = this.pendingItems.filter(p => p.id !== tempId);
return response?.ok || false;
} catch (e) {
console.error("Failed to queue message:", e);
+ // Remove from pending on error
+ this.pendingItems = this.pendingItems.filter(p => p.id !== tempId);
return false;
}
},
diff --git a/webui/components/chat/message-queue/message-queue.html b/webui/components/chat/message-queue/message-queue.html
index 314e4f911..e4f78494d 100644
--- a/webui/components/chat/message-queue/message-queue.html
+++ b/webui/components/chat/message-queue/message-queue.html
@@ -10,18 +10,27 @@
<div class="queue-preview">
<div class="queue-header">
<span class="queue-title">
- <span class="queue-spinner"></span>
Queued Messages (<span x-text="$store.messageQueue.count"></span>)
</span>
- <button class="queue-clear-btn" @click="$store.messageQueue.clearQueue()" title="Clear all">
- <span class="material-symbols-outlined">delete_sweep</span>
- </button>
+ <div class="queue-header-actions">
+ <button class="queue-header-btn" @click="$store.messageQueue.sendAll()" title="Send all">
+ <span class="material-symbols-outlined">keyboard_double_arrow_right</span>
+ </button>
+ <button class="queue-header-btn delete" @click="$store.messageQueue.clearQueue()" title="Clear all">
+ <span class="material-symbols-outlined">delete_sweep</span>
+ </button>
+ </div>
</div>
<div class="queue-items">
- <template x-for="(item, index) in $store.messageQueue.items" :key="item.id">
- <div class="queue-item">
+ <template x-for="(item, index) in $store.messageQueue.allItems" :key="item.id">
+ <div class="queue-item" :class="{ 'queue-item-pending': item.pending }">
<div class="queue-item-content">
- <span class="queue-item-seq" x-text="index + 1"></span>
+ <template x-if="item.pending">
+ <span class="queue-item-pending-icon"></span>
+ </template>
+ <template x-if="!item.pending">
+ <span class="queue-item-seq" x-text="index + 1"></span>
+ </template>
<span class="queue-item-text" x-text="item.text || '(attachment only)'"></span>
<template x-if="item.attachments?.length > 0">
<div class="queue-attachments">
@@ -67,27 +76,16 @@
}
.queue-title {
- display: flex;
- align-items: center;
- gap: var(--spacing-xs);
font-size: var(--font-size-xs);
color: var(--color-text-secondary);
}
- .queue-spinner {
- width: 12px;
- height: 12px;
- border: 2px solid var(--color-border);
- border-top-color: var(--color-primary);
- border-radius: 50%;
- animation: queue-spin 1s linear infinite;
- }
-
- @keyframes queue-spin {
- to { transform: rotate(360deg); }
+ .queue-header-actions {
+ display: flex;
+ gap: 2px;
}
- .queue-clear-btn {
+ .queue-header-btn {
background: transparent;
border: none;
color: var(--color-text-secondary);
@@ -100,17 +98,17 @@
transition: all 0.1s ease-in-out;
}
- .queue-clear-btn:hover {
+ .queue-header-btn:hover {
opacity: 1;
transform: scale(1.1);
}
- .queue-clear-btn:active {
+ .queue-header-btn:active {
opacity: 0.5;
transform: scale(0.95);
}
- .queue-clear-btn .material-symbols-outlined {
+ .queue-header-btn .material-symbols-outlined {
font-size: var(--font-size-large);
}
@@ -194,14 +192,25 @@
display: flex;
gap: 2px;
flex-shrink: 0;
+ }
+
+ .device-pointer .queue-item-actions {
opacity: 0;
visibility: hidden;
+ pointer-events: none;
transition: opacity 0.15s;
}
- .queue-item:hover .queue-item-actions {
+ .device-pointer .queue-item:hover .queue-item-actions {
opacity: 1;
visibility: visible;
+ pointer-events: auto;
+ }
+
+ .device-touch .queue-item-actions {
+ opacity: 1;
+ visibility: visible;
+ pointer-events: auto;
}
.queue-action-btn {
@@ -218,6 +227,27 @@
.queue-action-btn .material-symbols-outlined {
font-size: var(--font-size-smaller);
}
+
+ .queue-item-pending {
+ opacity: 0.6;
+ }
+
+ .queue-item-pending .queue-item-actions {
+ display: none;
+ }
+
+ .queue-item-pending-icon {
+ width: 1rem;
+ height: 1rem;
+ border: 2px solid var(--color-border);
+ border-top-color: var(--color-primary);
+ border-radius: 50%;
+ animation: pending-spin 0.8s linear infinite;
+ }
+
+ @keyframes pending-spin {
+ to { transform: rotate(360deg); }
+ }
</style>
</body>
</html>
diff --git a/webui/components/chat/top-section/chat-top-store.js b/webui/components/chat/top-section/chat-top-store.js
index 68956db56..c14da0a09 100644
--- a/webui/components/chat/top-section/chat-top-store.js
+++ b/webui/components/chat/top-section/chat-top-store.js
@@ -3,7 +3,8 @@ import { createStore } from "/js/AlpineStore.js";
// define the model object holding data and functions
const model = {
connected: false,
- progressActive: false, // true when agent is working
+ progressActive: false, // true when progress bar is active
+ running: false, // true when agent is running (from context.is_running())
};
// convert it to alpine store
diff --git a/webui/index.js b/webui/index.js
index 0218c072f..8c1c2c93e 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -54,7 +54,7 @@ export async function sendMessage() {
if (message || hasAttachments) {
// Check if agent is busy - queue instead of sending
- if (chatTopStore.progressActive) {
+ if (chatTopStore.running) {
const success = await messageQueueStore.addToQueue(message, attachmentsWithUrls);
if (success) {
chatInputEl.value = "";
@@ -338,7 +338,7 @@ export async function poll() {
updateProgress(response.log_progress, response.log_progress_active);
// Update agent busy state for queue logic
- chatTopStore.progressActive = response.log_progress_active;
+ chatTopStore.running = response.running;
// Update message queue from poll
messageQueueStore.updateFromPoll(response.message_queue);