Skip to content

Agent Zero AI framework

Queued Messages

keyboardstaffa8595e15759a
diff --git a/python/api/message.py b/python/api/message.py
index cd63e85fd..70606e886 100644
--- a/python/api/message.py
+++ b/python/api/message.py
@@ -1,11 +1,10 @@
from agent import AgentContext, UserMessage
from python.helpers.api import ApiHandler, Request, Response
-from python.helpers import files, extension
+from python.helpers import files, extension, message_queue as mq
import os
from werkzeug.utils import secure_filename
from python.helpers.defer import DeferredTask
-from python.helpers.print_style import PrintStyle
class Message(ApiHandler):
@@ -64,30 +63,7 @@ class Message(ApiHandler):
# Store attachments in agent data
# context.agent0.set_data("attachments", attachment_paths)
- # Prepare attachment filenames for logging
- attachment_filenames = (
- [os.path.basename(path) for path in attachment_paths]
- if attachment_paths
- else []
- )
-
- # Print to console and log
- PrintStyle(
- background_color="#6C3483", font_color="white", bold=True, padding=True
- ).print(f"User message:")
- PrintStyle(font_color="white", padding=False).print(f"> {message}")
- if attachment_filenames:
- PrintStyle(font_color="white", padding=False).print("Attachments:")
- for filename in attachment_filenames:
- PrintStyle(font_color="white", padding=False).print(f"- {filename}")
-
- # Log the message with message_id and attachments
- context.log.log(
- type="user",
- heading="",
- content=message,
- kvps={"attachments": attachment_filenames},
- id=message_id,
- )
+ # Log to console and UI using helper function
+ mq.log_user_message(context, message, attachment_paths, message_id)
return context.communicate(UserMessage(message, attachment_paths)), context
diff --git a/python/api/message_queue_add.py b/python/api/message_queue_add.py
new file mode 100644
index 000000000..9b8815913
--- /dev/null
+++ b/python/api/message_queue_add.py
@@ -0,0 +1,21 @@
+from python.helpers.api import ApiHandler, Request, Response
+from python.helpers import message_queue as mq
+from agent import AgentContext
+
+
+class MessageQueueAdd(ApiHandler):
+ """Add a message to the queue."""
+
+ async def process(self, input: dict, request: Request) -> dict | Response:
+ context = AgentContext.get(input.get("context", ""))
+ if not context:
+ return Response("Context not found", status=404)
+
+ text = input.get("text", "").strip()
+ attachments = input.get("attachments", []) # filenames from /upload API
+
+ if not text and not attachments:
+ return Response("Empty message", status=400)
+
+ item = mq.add(context, text, attachments)
+ return {"ok": True, "item_id": item["id"], "queue_length": len(mq.get_queue(context))}
diff --git a/python/api/message_queue_remove.py b/python/api/message_queue_remove.py
new file mode 100644
index 000000000..4b49ebafc
--- /dev/null
+++ b/python/api/message_queue_remove.py
@@ -0,0 +1,16 @@
+from python.helpers.api import ApiHandler, Request, Response
+from python.helpers import message_queue as mq
+from agent import AgentContext
+
+
+class MessageQueueRemove(ApiHandler):
+ """Remove message(s) from queue."""
+
+ async def process(self, input: dict, request: Request) -> dict | Response:
+ context = AgentContext.get(input.get("context", ""))
+ if not context:
+ return Response("Context not found", status=404)
+
+ item_id = input.get("item_id") # None means clear all
+ remaining = mq.remove(context, item_id)
+ return {"ok": True, "remaining": remaining}
diff --git a/python/api/message_queue_send.py b/python/api/message_queue_send.py
new file mode 100644
index 000000000..2825b9028
--- /dev/null
+++ b/python/api/message_queue_send.py
@@ -0,0 +1,30 @@
+from python.helpers.api import ApiHandler, Request, Response
+from python.helpers import message_queue as mq
+from agent import AgentContext
+
+
+class MessageQueueSend(ApiHandler):
+ """Send queued message(s) immediately."""
+
+ async def process(self, input: dict, request: Request) -> dict | Response:
+ context = AgentContext.get(input.get("context", ""))
+ if not context:
+ return Response("Context not found", status=404)
+
+ if not mq.has_queue(context):
+ return {"ok": True, "message": "Queue empty"}
+
+ item_id = input.get("item_id")
+ send_all = input.get("send_all", False)
+
+ if send_all:
+ count = mq.send_all_aggregated(context)
+ return {"ok": True, "sent_count": count}
+
+ # Send single item
+ item = mq.pop_item(context, item_id) if item_id else mq.pop_first(context)
+ if not item:
+ return Response("Item not found", status=404)
+
+ mq.send_message(context, item)
+ return {"ok": True, "sent_item_id": item["id"]}
diff --git a/python/api/poll.py b/python/api/poll.py
index dbe7105c6..4efa0fd43 100644
--- a/python/api/poll.py
+++ b/python/api/poll.py
@@ -122,4 +122,5 @@ class Poll(ApiHandler):
"notifications": notifications,
"notifications_guid": notification_manager.guid,
"notifications_version": len(notification_manager.updates),
+ "message_queue": context.output_data.get("message_queue", []) if context else [],
}
diff --git a/python/api/upload.py b/python/api/upload.py
index 4a596a577..e5d33824c 100644
--- a/python/api/upload.py
+++ b/python/api/upload.py
@@ -14,7 +14,7 @@ class UploadFile(ApiHandler):
for file in file_list:
if file and self.allowed_file(file.filename): # Check file type
filename = secure_filename(file.filename) # type: ignore
- file.save(files.get_abs_path("tmp/upload", filename))
+ file.save(files.get_abs_path("tmp/uploads", filename))
saved_filenames.append(filename)
return {"filenames": saved_filenames} # Return saved filenames
diff --git a/python/extensions/monologue_end/_95_process_queue.py b/python/extensions/monologue_end/_95_process_queue.py
new file mode 100644
index 000000000..51315ee4b
--- /dev/null
+++ b/python/extensions/monologue_end/_95_process_queue.py
@@ -0,0 +1,33 @@
+import asyncio
+from python.helpers.extension import Extension
+from python.helpers import message_queue as mq
+from agent import LoopData
+
+
+class ProcessQueue(Extension):
+ """Process queued messages after monologue ends."""
+
+ async def execute(self, loop_data: LoopData = LoopData(), **kwargs):
+ # Only process for agent0 (main agent)
+ if self.agent.number != 0:
+ return
+
+ context = self.agent.context
+
+ # Check if there are queued messages
+ if mq.has_queue(context):
+ # Schedule delayed task to send next queued message
+ # This allows current monologue to fully complete first
+ asyncio.create_task(self._delayed_send(context))
+
+ async def _delayed_send(self, context):
+ """Wait for task to complete, then send next queued message."""
+ # Small delay to ensure monologue fully completes
+ await asyncio.sleep(0.1)
+
+ # Wait for current task to finish
+ while context.task and context.task.is_alive():
+ await asyncio.sleep(0.1)
+
+ # Send next queued message
+ mq.send_next(context)
diff --git a/python/helpers/message_queue.py b/python/helpers/message_queue.py
new file mode 100644
index 000000000..3973f325b
--- /dev/null
+++ b/python/helpers/message_queue.py
@@ -0,0 +1,182 @@
+import os
+import uuid
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from agent import AgentContext
+
+from python.helpers.print_style import PrintStyle
+
+QUEUE_KEY = "message_queue"
+QUEUE_SEQ_KEY = "message_queue_seq"
+UPLOAD_FOLDER = "/a0/tmp/uploads"
+
+
+def get_queue(context: "AgentContext") -> list:
+ """Get current queue from context.data."""
+ return context.get_data(QUEUE_KEY) or []
+
+
+def _get_next_seq(context: "AgentContext") -> int:
+ """Get next sequence number."""
+ seq = context.get_data(QUEUE_SEQ_KEY) or 0
+ seq += 1
+ context.set_data(QUEUE_SEQ_KEY, seq)
+ return seq
+
+
+def _sync_output(context: "AgentContext"):
+ """Sync queue to output_data for frontend polling."""
+ queue = get_queue(context)
+ # Truncate text for frontend display
+ truncated = []
+ for item in queue:
+ truncated.append({
+ "id": item["id"],
+ "seq": item.get("seq", 0),
+ "text": item["text"][:100] + "..." if len(item["text"]) > 100 else item["text"],
+ "attachments": [a.split("/")[-1] for a in item.get("attachments", [])],
+ "attachment_count": len(item.get("attachments", [])),
+ })
+ context.set_output_data(QUEUE_KEY, truncated)
+
+
+def add(context: "AgentContext", text: str, attachments: list[str] | None = None) -> dict:
+ """Add message to queue. Attachments should be filenames, will be converted to full paths."""
+ queue = get_queue(context)
+
+ # Convert filenames to full paths
+ full_paths = []
+ for att in (attachments or []):
+ if att.startswith("/"):
+ full_paths.append(att)
+ else:
+ full_paths.append(f"{UPLOAD_FOLDER}/{att}")
+
+ item = {
+ "id": str(uuid.uuid4())[:8],
+ "seq": _get_next_seq(context),
+ "text": text,
+ "attachments": full_paths,
+ }
+ queue.append(item)
+ context.set_data(QUEUE_KEY, queue)
+ _sync_output(context)
+ return item
+
+
+def remove(context: "AgentContext", item_id: str | None = None) -> int:
+ """Remove item(s). If item_id is None, clears all. Returns remaining count."""
+ if not item_id:
+ context.set_data(QUEUE_KEY, [])
+ context.set_output_data(QUEUE_KEY, [])
+ return 0
+ queue = [i for i in get_queue(context) if i["id"] != item_id]
+ context.set_data(QUEUE_KEY, queue)
+ _sync_output(context)
+ return len(queue)
+
+
+def pop_first(context: "AgentContext") -> dict | None:
+ """Remove and return first item."""
+ queue = get_queue(context)
+ if not queue:
+ return None
+ item = queue.pop(0)
+ context.set_data(QUEUE_KEY, queue)
+ _sync_output(context)
+ return item
+
+
+def pop_item(context: "AgentContext", item_id: str) -> dict | None:
+ """Remove and return specific item."""
+ queue = get_queue(context)
+ for i, item in enumerate(queue):
+ if item["id"] == item_id:
+ queue.pop(i)
+ context.set_data(QUEUE_KEY, queue)
+ _sync_output(context)
+ return item
+ return None
+
+
+def has_queue(context: "AgentContext") -> bool:
+ """Check if queue has items."""
+ return len(get_queue(context)) > 0
+
+
+def log_user_message(
+ context: "AgentContext",
+ message: str,
+ attachment_paths: list[str],
+ message_id: str | None = None,
+ source: str = "",
+):
+ """Log user message to console and UI. Used by message API and queue processing."""
+ # Prepare attachment filenames for logging
+ attachment_filenames = (
+ [os.path.basename(path) for path in attachment_paths]
+ if attachment_paths
+ else []
+ )
+
+ # Print to console
+ label = f"User message{source}:"
+ PrintStyle(
+ background_color="#6C3483", font_color="white", bold=True, padding=True
+ ).print(label)
+ PrintStyle(font_color="white", padding=False).print(f"> {message}")
+ if attachment_filenames:
+ PrintStyle(font_color="white", padding=False).print("Attachments:")
+ for filename in attachment_filenames:
+ PrintStyle(font_color="white", padding=False).print(f"- {filename}")
+
+ # Log to UI
+ context.log.log(
+ type="user",
+ heading="",
+ content=message,
+ kvps={"attachments": attachment_filenames},
+ id=message_id,
+ )
+
+
+def send_message(context: "AgentContext", item: dict, source: str = " (from queue)"):
+ """Send a single queued message (log + communicate)."""
+ from agent import UserMessage # Import here to avoid circular import
+
+ message = item.get("text", "")
+ attachments = item.get("attachments", [])
+ log_user_message(context, message, attachments, source=source)
+ context.communicate(UserMessage(message, attachments))
+
+
+def send_next(context: "AgentContext") -> bool:
+ """Send next queued message. Returns True if sent, False if queue empty."""
+ if not has_queue(context):
+ return False
+ item = pop_first(context)
+ if item:
+ send_message(context, item)
+ return True
+ return False
+
+
+def send_all_aggregated(context: "AgentContext") -> int:
+ """Aggregate and send all queued messages as one. Returns count of items sent."""
+ from agent import UserMessage # Import here to avoid circular import
+
+ if not has_queue(context):
+ return 0
+
+ items = []
+ while has_queue(context):
+ items.append(pop_first(context))
+
+ # Combine texts with separator
+ text = "\n\n---\n\n".join(i["text"] for i in items if i["text"])
+ attachments = [a for i in items for a in i.get("attachments", [])]
+
+ log_user_message(context, text, attachments, source=" (queued batch)")
+ context.communicate(UserMessage(text, attachments))
+ return len(items)
diff --git a/webui/components/chat/input/chat-bar-input.html b/webui/components/chat/input/chat-bar-input.html
index 96b60735a..66bdfe7ae 100644
--- a/webui/components/chat/input/chat-bar-input.html
+++ b/webui/components/chat/input/chat-bar-input.html
@@ -4,6 +4,7 @@
import { store as speechStore } from "/components/chat/speech/speech-store.js";
import { store as attachmentsStore } from "/components/chat/attachments/attachmentsStore.js";
import { store as fullScreenStore } from "/components/modals/full-screen-input/full-screen-store.js";
+ import { store as messageQueueStore } from "/components/chat/message-queue/message-queue-store.js";
</script>
</head>
<body>
@@ -33,10 +34,19 @@
<div id="chat-buttons-wrapper">
<!-- Send button -->
<button class="chat-button" id="send-button" aria-label="Send message"
- @click="$store.chatInput.sendMessage()">
- <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>
+ @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">
+ <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 -->
@@ -108,9 +118,25 @@
#chat-buttons-wrapper { gap: var(--spacing-xs); padding-left: var(--spacing-xs); line-height: 0.5rem; display: -webkit-flex; display: flex; }
.chat-button { border: none; border-radius: 50%; color: var(--color-background); cursor: pointer; font-size: var(--font-size-normal); height: 2.525rem; width: 2.525rem; margin: 0 0.18rem 0 0 var(--spacing-xs); display: -webkit-flex; display: flex; align-items: center; justify-content: center; flex-shrink: 0; flex-grow: 0; min-width: 2.525rem; -webkit-transition: all var(--transition-speed), transform 0.1s ease-in-out; transition: all var(--transition-speed), transform 0.1s ease-in-out; }
#send-button { background-color: #4248f1; }
+ #send-button.send-queue { background-color: #e67e22; }
#send-button:hover { -webkit-transform: scale(1.05); transform: scale(1.05); transform-origin: center; background-color: #353bc5; }
+ #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); }
+ }
+
/* Microphone button */
.chat-button.mic-inactive svg { /* Add specific styles if needed */ }
/* Responsive tweaks */
diff --git a/webui/components/chat/input/chat-bar.html b/webui/components/chat/input/chat-bar.html
index 6d02e393a..9ab9a9678 100644
--- a/webui/components/chat/input/chat-bar.html
+++ b/webui/components/chat/input/chat-bar.html
@@ -2,12 +2,16 @@
<head>
<script type="module">
import { store } from "/components/chat/input/input-store.js";
+ import { store as messageQueueStore } from "/components/chat/message-queue/message-queue-store.js";
</script>
</head>
<body>
<div id="input-section" x-data>
<template x-if="$store.chatInput">
<div style="width: 100%; display: contents;">
+ <!-- Message Queue section -->
+ <x-component path="chat/message-queue/message-queue.html"></x-component>
+
<!-- Attachment Preview section -->
<div>
<x-component path="/chat/attachments/inputPreview.html" />
diff --git a/webui/components/chat/message-queue/message-queue-store.js b/webui/components/chat/message-queue/message-queue-store.js
new file mode 100644
index 000000000..14fc8e804
--- /dev/null
+++ b/webui/components/chat/message-queue/message-queue-store.js
@@ -0,0 +1,90 @@
+import { createStore } from "/js/AlpineStore.js";
+import * as api from "/js/api.js";
+
+const model = {
+ items: [],
+
+ get hasQueue() {
+ return this.items.length > 0;
+ },
+
+ get count() {
+ return this.items.length;
+ },
+
+ async addToQueue(text, attachments = []) {
+ const context = globalThis.getContext?.();
+ if (!context) return false;
+
+ try {
+ let filenames = [];
+ if (attachments.length > 0) {
+ const formData = new FormData();
+ for (const att of attachments) {
+ formData.append("file", att.file || att);
+ }
+ const resp = await api.fetchApi("/upload", { method: "POST", body: formData });
+ if (resp.ok) {
+ const result = await resp.json();
+ filenames = result.filenames || [];
+ }
+ }
+ const response = await api.callJsonApi("/message_queue_add", { context, text, attachments: filenames });
+ return response?.ok || false;
+ } catch (e) {
+ console.error("Failed to queue message:", e);
+ return false;
+ }
+ },
+
+ async removeItem(itemId) {
+ const context = globalThis.getContext?.();
+ if (!context) return;
+ try {
+ await api.callJsonApi("/message_queue_remove", { context, item_id: itemId });
+ } catch (e) {
+ console.error("Failed to remove from queue:", e);
+ }
+ },
+
+ async clearQueue() {
+ const context = globalThis.getContext?.();
+ if (!context) return;
+ try {
+ await api.callJsonApi("/message_queue_remove", { context });
+ } catch (e) {
+ console.error("Failed to clear queue:", e);
+ }
+ },
+
+ async sendItem(itemId) {
+ const context = globalThis.getContext?.();
+ if (!context) return;
+ try {
+ await api.callJsonApi("/message_queue_send", { context, item_id: itemId });
+ } catch (e) {
+ console.error("Failed to send queued message:", e);
+ }
+ },
+
+ async sendAll() {
+ const context = globalThis.getContext?.();
+ if (!context || !this.hasQueue) return;
+ try {
+ await api.callJsonApi("/message_queue_send", { context, send_all: true });
+ } catch (e) {
+ console.error("Failed to send all queued:", e);
+ }
+ },
+
+ updateFromPoll(queue) {
+ this.items = queue || [];
+ },
+
+ getAttachmentUrl(filename) {
+ return `/image_get?path=/a0/tmp/uploads/${encodeURIComponent(filename)}`;
+ },
+};
+
+const store = createStore("messageQueue", model);
+export { store };
diff --git a/webui/components/chat/message-queue/message-queue.html b/webui/components/chat/message-queue/message-queue.html
new file mode 100644
index 000000000..314e4f911
--- /dev/null
+++ b/webui/components/chat/message-queue/message-queue.html
@@ -0,0 +1,223 @@
+<html>
+<head>
+ <script type="module">
+ import { store } from "/components/chat/message-queue/message-queue-store.js";
+ </script>
+</head>
+<body>
+ <div x-data>
+ <template x-if="$store.messageQueue?.hasQueue">
+ <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>
+ <div class="queue-items">
+ <template x-for="(item, index) in $store.messageQueue.items" :key="item.id">
+ <div class="queue-item">
+ <div class="queue-item-content">
+ <span class="queue-item-seq" x-text="index + 1"></span>
+ <span class="queue-item-text" x-text="item.text || '(attachment only)'"></span>
+ <template x-if="item.attachments?.length > 0">
+ <div class="queue-attachments">
+ <template x-for="att in item.attachments" :key="att">
+ <img
+ :src="$store.messageQueue.getAttachmentUrl(att)"
+ :alt="att"
+ class="queue-attachment-thumb"
+ :title="att"
+ />
+ </template>
+ </div>
+ </template>
+ </div>
+ <div class="queue-item-actions">
+ <button class="queue-action-btn send" @click="$store.messageQueue.sendItem(item.id)" title="Send now">
+ <span class="material-symbols-outlined">send</span>
+ </button>
+ <button class="queue-action-btn delete" @click="$store.messageQueue.removeItem(item.id)" title="Remove">
+ <span class="material-symbols-outlined">close</span>
+ </button>
+ </div>
+ </div>
+ </template>
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <style>
+ .queue-preview {
+ border: 1px solid var(--color-border);
+ border-radius: 8px;
+ padding: var(--spacing-sm);
+ margin-bottom: var(--spacing-xs);
+ }
+
+ .queue-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: var(--spacing-xs);
+ }
+
+ .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-clear-btn {
+ background: transparent;
+ border: none;
+ color: var(--color-text-secondary);
+ cursor: pointer;
+ padding: 2px;
+ border-radius: 4px;
+ display: flex;
+ align-items: center;
+ opacity: 0.6;
+ transition: all 0.1s ease-in-out;
+ }
+
+ .queue-clear-btn:hover {
+ opacity: 1;
+ transform: scale(1.1);
+ }
+
+ .queue-clear-btn:active {
+ opacity: 0.5;
+ transform: scale(0.95);
+ }
+
+ .queue-clear-btn .material-symbols-outlined {
+ font-size: var(--font-size-large);
+ }
+
+ .queue-items {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ max-height: 120px;
+ overflow-y: auto;
+ }
+
+ .queue-items::-webkit-scrollbar {
+ flex: 1;
+ min-height: 0;
+ overflow: scroll;
+ scroll-behavior: smooth;
+ max-height: 100%;
+ scrollbar-width: none;
+ -ms-overflow-style: none;
+ }
+
+ .queue-item {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--spacing-sm);
+ padding: 6px 8px;
+ border-radius: 4px;
+ cursor: default;
+ }
+
+ .queue-item:hover {
+ background-color: var(--color-background-hover);
+ }
+
+ .queue-item-content {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-sm);
+ flex: 1;
+ min-width: 0;
+ }
+
+ .queue-item-seq {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 1rem;
+ height: 1rem;
+ font-size: 0.5rem;
+ color: var(--color-text-secondary);
+ background: var(--color-background);
+ border-radius: 50%;
+ }
+
+ .queue-item-text {
+ font-size: var(--font-size-small);
+ color: var(--color-text);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ flex: 1;
+ min-width: 0;
+ }
+
+ .queue-attachments {
+ display: flex;
+ gap: 4px;
+ flex-shrink: 0;
+ }
+
+ .queue-attachment-thumb {
+ width: 20px;
+ height: 20px;
+ object-fit: contain;
+ border-radius: 3px;
+ border: 1px solid var(--color-border);
+ }
+
+ .queue-item-actions {
+ display: flex;
+ gap: 2px;
+ flex-shrink: 0;
+ opacity: 0;
+ visibility: hidden;
+ transition: opacity 0.15s;
+ }
+
+ .queue-item:hover .queue-item-actions {
+ opacity: 1;
+ visibility: visible;
+ }
+
+ .queue-action-btn {
+ background: transparent;
+ border: none;
+ color: var(--color-primary);
+ cursor: pointer;
+ padding: 4px;
+ border-radius: 4px;
+ display: flex;
+ align-items: center;
+ }
+
+ .queue-action-btn .material-symbols-outlined {
+ font-size: var(--font-size-smaller);
+ }
+ </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 8dd47b000..68956db56 100644
--- a/webui/components/chat/top-section/chat-top-store.js
+++ b/webui/components/chat/top-section/chat-top-store.js
@@ -3,6 +3,7 @@ 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
};
// convert it to alpine store
diff --git a/webui/index.js b/webui/index.js
index 791e19248..3dccacb4b 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -11,6 +11,7 @@ import { store as chatsStore } from "/components/sidebar/chats/chats-store.js";
import { store as tasksStore } from "/components/sidebar/tasks/tasks-store.js";
import { store as chatTopStore } from "/components/chat/top-section/chat-top-store.js";
import { store as _tooltipsStore } from "/components/tooltips/tooltip-store.js";
+import { store as messageQueueStore } from "/components/chat/message-queue/message-queue-store.js";
import { applyModeSteps } from "/components/messages/process-group/process-group-dom.js";
globalThis.fetchApi = api.fetchApi; // TODO - backward compatibility for non-modular scripts, remove once refactored to alpine
@@ -46,7 +47,24 @@ export async function sendMessage() {
const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();
const hasAttachments = attachmentsWithUrls.length > 0;
+ // If empty input but has queued messages, send all queued
+ if (!message && !hasAttachments && messageQueueStore.hasQueue) {
+ await messageQueueStore.sendAll();
+ return;
+ }
+
if (message || hasAttachments) {
+ // Check if agent is busy - queue instead of sending
+ if (chatTopStore.progressActive) {
+ const success = await messageQueueStore.addToQueue(message, attachmentsWithUrls);
+ if (success) {
+ chatInputEl.value = "";
+ attachmentsStore.clearAttachments();
+ adjustTextareaHeight();
+ }
+ return;
+ }
+
// Sending a message is an explicit user intent to go to the bottom
forceScrollChatToBottom();
@@ -327,6 +345,12 @@ export async function poll() {
lastLogGuid = response.log_guid;
updateProgress(response.log_progress, response.log_progress_active);
+
+ // Update agent busy state for queue logic
+ chatTopStore.progressActive = response.log_progress_active;
+
+ // Update message queue from poll
+ messageQueueStore.updateFromPoll(response.message_queue);
// Update notifications from response
notificationStore.updateFromPoll(response);