Agent Zero AI framework
attachments fixes and polishing
frdelbb7388549a42
diff --git a/webui/components/chat/attachments/attachmentsStore.js b/webui/components/chat/attachments/attachmentsStore.jsindex 08be2f6bb..c1019ed94 100644--- a/webui/components/chat/attachments/attachmentsStore.js+++ b/webui/components/chat/attachments/attachmentsStore.js@@ -207,6 +207,13 @@ const model = {}},+ // Update handleFileUpload to use the attachments store+ handleFileUpload(event) {+ const files = event.target.files;+ this.handleFiles(files);+ event.target.value = ""; // clear uploader selection to fix issue where same file is ignored the second time+ },+// File handling logic (moved from index.js)handleFiles(files) {console.log("handleFiles called with", files.length, "files");@@ -265,20 +272,6 @@ const model = {return `/a0/tmp/uploads/${encodeURIComponent(filename)}`;},- // // Get file metadata from server (for device sync and enhanced UI)- // async getFileMetadata(filename) {- // try {- // const response = await fetch(`/image_get?path=/a0/tmp/uploads/${encodeURIComponent(filename)}&metadata=true`);- // if (response.ok) {- // return await response.json();- // }- // return null;- // } catch (error) {- // console.error('Failed to get file metadata:', error);- // return null;- // }- // },-// Check if file is an image based on extensionisImageFile(filename) {const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg"];diff --git a/webui/index.html b/webui/index.htmlindex 015e82f9a..97461b18a 100644--- a/webui/index.html+++ b/webui/index.html@@ -393,7 +393,7 @@d="M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z" /></svg></label>- <input type="file" id="file-input" accept="*" multiple style="display: none" @change="window.handleFileUpload($event)">+ <input type="file" id="file-input" accept="*" multiple style="display: none" @change="$store.chatAttachments.handleFileUpload($event)"><div x-show="showTooltip" class="tooltip">Add attachments to the messagediff --git a/webui/index.js b/webui/index.jsindex f8303eccd..c4b48feae 100644--- a/webui/index.js+++ b/webui/index.js@@ -2,6 +2,7 @@ import * as msgs from "./js/messages.js";import { speech } from "./js/speech.js";import * as api from "./js/api.js";import * as css from "./js/css.js";+import { sleep } from "./js/sleep.js";import { store as attachmentsStore } from "./components/chat/attachments/attachmentsStore.js";window.fetchApi = api.fetchApi; // TODO - backward compatibility for non-modular scripts, remove once refactored to alpine@@ -95,29 +96,40 @@ export async function sendMessage() {try {const message = chatInput.value.trim();// const attachmentsStore = attachmentsStore; //window.Alpine ? Alpine.store('chatAttachments') : null;- const attachments = attachmentsStore.attachments; // attachmentsStore ? attachmentsStore.attachments : [];- const hasAttachments = attachmentsStore.hasAttachments; // attachmentsStore ? attachmentsStore.hasAttachments : false;+ const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();+ const hasAttachments = attachmentsWithUrls.length > 0;if (message || hasAttachments) {let response;const messageId = generateGUID();+ // Clear input and attachments+ chatInput.value = "";+ attachmentsStore.clearAttachments();+ adjustTextareaHeight();+// Include attachments in the user messageif (hasAttachments) {- const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();+ const heading =+ attachmentsWithUrls.length > 0+ ? "Uploading attachments..."+ : "User message";// Render user message with attachments- setMessage(messageId, "user", "", message, false, {- attachments: attachmentsWithUrls,+ setMessage(messageId, "user", heading, message, false, {+ // attachments: attachmentsWithUrls, // skip here, let the backend properly log them});+ // sleep one frame to render the message before upload starts - better UX+ sleep(0);+const formData = new FormData();formData.append("text", message);formData.append("context", context);formData.append("message_id", messageId);- for (let i = 0; i < attachments.length; i++) {- formData.append("attachments", attachments[i].file);+ for (let i = 0; i < attachmentsWithUrls.length; i++) {+ formData.append("attachments", attachmentsWithUrls[i].file);}response = await api.fetchApi("/message_async", {@@ -144,24 +156,9 @@ export async function sendMessage() {const jsonResponse = await response.json();if (!jsonResponse) {toast("No response returned.", "error");- }- // else if (!jsonResponse.ok) {- // if (jsonResponse.message) {- // toast(jsonResponse.message, "error");- // } else {- // toast("Undefined error.", "error");- // }- // }- else {+ } else {setContext(jsonResponse.context);}-- // Clear input and attachments- chatInput.value = "";- // if (attachmentsStore) {- attachmentsStore.clearAttachments();- // }- adjustTextareaHeight();}} catch (e) {toastFetchError("Error sending message", e);@@ -1097,20 +1094,6 @@ async function startPolling() {document.addEventListener("DOMContentLoaded", startPolling);-// Drag and drop functionality has been moved to attachmentsStore.js--// Update handleFileUpload to use the attachments store-window.handleFileUpload = function (event) {- // console.log('handleFileUpload called with files:', event.target.files.length);- const files = event.target.files;- // if (window.Alpine && Alpine.store('chatAttachments')) {- // console.log('Calling store handleFiles...');- // Alpine.store('chatAttachments').handleFiles(files);- // } else {- // console.error('Alpine or chatAttachments store not found!');- // }- attachmentsStore.handleFiles(files);-};// Setup event handlers once the DOM is fully loadeddocument.addEventListener("DOMContentLoaded", function () {diff --git a/webui/js/messages.js b/webui/js/messages.jsindex 9e5401bb0..12a3a73a6 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -15,9 +15,9 @@ export function setMessage(id, type, heading, content, temp, kvps = null) {if (messageContainer) {// Don't re-render user messages- if (type === "user") {- return; // Skip re-rendering- }+ // if (type === "user") {+ // return; // Skip re-rendering+ // }// For other types, update the messagemessageContainer.innerHTML = "";} else {@@ -365,7 +365,7 @@ export function drawMessageUser(const headingElement = document.createElement("h4");headingElement.classList.add("msg-heading");headingElement.innerHTML =- "User message <span class='icon material-symbols-outlined'>person</span>";+ `${heading} <span class='icon material-symbols-outlined'>person</span>`;messageDiv.appendChild(headingElement);if (content && content.trim().length > 0) {