Skip to content

Agent Zero AI framework

Support folder attachments in chat composer

Alessandro84ea6c27a122
diff --git a/webui/components/chat/attachments/attachmentsStore.js b/webui/components/chat/attachments/attachmentsStore.js
index e702c2afb..82e117b1d 100644
--- a/webui/components/chat/attachments/attachmentsStore.js
+++ b/webui/components/chat/attachments/attachmentsStore.js
@@ -112,12 +112,19 @@ const model = {
// Handle drop
document.addEventListener(
"drop",
- (e) => {
- console.log("Drop detected with files:", e.dataTransfer.files.length);
+ async (e) => {
+ const dataTransfer = e.dataTransfer;
+ console.log("Drop detected with files:", dataTransfer?.files?.length || 0);
dragCounter = 0;
this.hideDragDropOverlay();
- const files = e.dataTransfer.files;
+ let files = [];
+ try {
+ files = await this.getDroppedFiles(dataTransfer);
+ } catch (error) {
+ console.error("Failed to read dropped files:", error);
+ files = Array.from(dataTransfer?.files || []);
+ }
this.handleFiles(files);
},
false
@@ -209,10 +216,76 @@ const model = {
event.target.value = ""; // clear uploader selection to fix issue where same file is ignored the second time
},
+ async getDroppedFiles(dataTransfer) {
+ const items = Array.from(dataTransfer?.items || []);
+ const entries = items
+ .map((item) =>
+ typeof item.webkitGetAsEntry === "function"
+ ? item.webkitGetAsEntry()
+ : null
+ )
+ .filter(Boolean);
+
+ if (!entries.length) {
+ return Array.from(dataTransfer?.files || []);
+ }
+
+ const nested = await Promise.all(
+ entries.map((entry) => this.readEntryFiles(entry))
+ );
+ const files = nested.flat();
+ return files.length ? files : Array.from(dataTransfer?.files || []);
+ },
+
+ async readEntryFiles(entry) {
+ if (entry.isFile) {
+ return await new Promise((resolve, reject) => {
+ entry.file(
+ (file) => resolve([file]),
+ (error) => reject(error)
+ );
+ });
+ }
+
+ if (!entry.isDirectory) return [];
+
+ const reader = entry.createReader();
+ const childEntries = await this.readAllDirectoryEntries(reader);
+ const nested = await Promise.all(
+ childEntries.map((child) => this.readEntryFiles(child))
+ );
+ return nested.flat();
+ },
+
+ async readAllDirectoryEntries(reader) {
+ const entries = [];
+
+ return await new Promise((resolve, reject) => {
+ const readBatch = () => {
+ reader.readEntries(
+ (batch) => {
+ if (!batch.length) {
+ resolve(entries);
+ return;
+ }
+ entries.push(...batch);
+ readBatch();
+ },
+ (error) => reject(error)
+ );
+ };
+
+ readBatch();
+ });
+ },
+
// File handling logic (moved from index.js)
handleFiles(files) {
- console.log("handleFiles called with", files.length, "files");
- Array.from(files).forEach((file) => {
+ const fileList = Array.from(files || []);
+ console.log("handleFiles called with", fileList.length, "files");
+ fileList.forEach((file) => {
+ if (!file?.name) return;
+
console.log("Processing file:", file.name, file.type);
const ext = file.name.split(".").pop().toLowerCase();
const isImage = ["jpg", "jpeg", "png", "bmp", "gif", "webp", "svg"].includes(
diff --git a/webui/components/chat/attachments/dragDropOverlay.html b/webui/components/chat/attachments/dragDropOverlay.html
index 7259d9c61..cc3126e0d 100644
--- a/webui/components/chat/attachments/dragDropOverlay.html
+++ b/webui/components/chat/attachments/dragDropOverlay.html
@@ -17,7 +17,7 @@
x-transition:enter-end="opacity-100" x-transition:leave="transition ease-in duration-300"
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" class="dragdrop-overlay">
<img src="public/dragndrop.svg" alt="Drop files" class="dragdrop-icon">
- <div class="dragdrop-text">Drop files to attach them to your message</div>
+ <div class="dragdrop-text">Drop files or folders to attach them to your message</div>
<div class="dragdrop-subtext"></div>
</div>
</template>
diff --git a/webui/components/chat/input/bottom-actions.html b/webui/components/chat/input/bottom-actions.html
index c1ce1e0bf..43aaedec1 100644
--- a/webui/components/chat/input/bottom-actions.html
+++ b/webui/components/chat/input/bottom-actions.html
@@ -11,20 +11,42 @@
<body>
<template x-if="$store.chatInput">
<div class="chat-bottom-actions-menu">
- <label class="chat-bottom-menu-item" @click.stop>
- <input
- type="file"
- id="chat-file-input"
- class="chat-bottom-menu-file-input"
- accept="*"
- multiple
- @change="$store.chatAttachments.handleFileUpload($event); $store.chatInput.closeChatMoreMenu()"
- >
+ <input
+ type="file"
+ id="chat-file-input"
+ class="chat-bottom-menu-file-input"
+ accept="*"
+ multiple
+ @change="$store.chatAttachments.handleFileUpload($event); $store.chatInput.closeChatMoreMenu()"
+ >
+ <button
+ type="button"
+ class="chat-bottom-menu-item"
+ @click.stop="document.getElementById('chat-file-input')?.click()"
+ >
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path 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>
- <span>Add attachments</span>
- </label>
+ <span>Attach files</span>
+ </button>
+
+ <input
+ type="file"
+ id="chat-folder-input"
+ class="chat-bottom-menu-file-input"
+ webkitdirectory
+ directory
+ multiple
+ @change="$store.chatAttachments.handleFileUpload($event); $store.chatInput.closeChatMoreMenu()"
+ >
+ <button
+ type="button"
+ class="chat-bottom-menu-item"
+ @click.stop="document.getElementById('chat-folder-input')?.click()"
+ >
+ <span class="material-symbols-outlined" aria-hidden="true">drive_folder_upload</span>
+ <span>Attach folder</span>
+ </button>
<button
type="button"
@@ -94,10 +116,6 @@
button.chat-bottom-menu-item {
border: none;
}
- label.chat-bottom-menu-item {
- position: relative;
- font-weight: inherit;
- }
.chat-bottom-menu-file-input {
position: absolute;
width: 1px;
@@ -110,13 +128,11 @@
border: 0;
opacity: 0;
}
- button.chat-bottom-menu-item:hover:not(:disabled),
- label.chat-bottom-menu-item:hover {
+ button.chat-bottom-menu-item:hover:not(:disabled) {
opacity: 1;
background-color: var(--color-background-hover);
}
button.chat-bottom-menu-item:active:not(:disabled) { opacity: 0.72; }
- label.chat-bottom-menu-item:active { opacity: 0.72; }
button.chat-bottom-menu-item:disabled {
opacity: 0.38;
cursor: not-allowed;