Agent Zero AI framework
attachment system polishing
frdel82799a5b34bc
diff --git a/agent.py b/agent.pyindex b9c55145f..abe5276ca 100644--- a/agent.py+++ b/agent.py@@ -746,7 +746,7 @@ class Agent:# Fallback to local get_tool if MCP tool was not found or MCP lookup failedif not tool:tool = self.get_tool(- name=tool_name, method=tool_method, args=tool_args, message=msg+ name=tool_name, method=tool_method, args=tool_args, message=msg, loop_data=self.loop_data)if tool:@@ -801,7 +801,7 @@ class Agent:passdef get_tool(- self, name: str, method: str | None, args: dict, message: str, **kwargs+ self, name: str, method: str | None, args: dict, message: str, loop_data: LoopData | None, **kwargs):from python.tools.unknown import Unknownfrom python.helpers.tool import Tool@@ -811,7 +811,7 @@ class Agent:)tool_class = classes[0] if classes else Unknownreturn tool_class(- agent=self, name=name, method=method, args=args, message=message, **kwargs+ agent=self, name=name, method=method, args=args, message=message, loop_data=loop_data, **kwargs)async def call_extensions(self, folder: str, **kwargs) -> Any:diff --git a/python/api/image_get.py b/python/api/image_get.pyindex d3583645c..acca85dc7 100644--- a/python/api/image_get.py+++ b/python/api/image_get.py@@ -1,9 +1,13 @@+import base64import osimport refrom typing import overridefrom python.helpers.api import ApiHandlerfrom python.helpers import filesfrom flask import Request, Response, send_file+from python.helpers import runtime+import io+from mimetypes import guess_typeclass ImageGet(ApiHandler):@@ -13,189 +17,136 @@ class ImageGet(ApiHandler):return ["GET"]async def process(self, input: dict, request: Request) -> dict | Response:- # input data- path = input.get("path", request.args.get("path", ""))- metadata = input.get("metadata", request.args.get("metadata", "false")).lower() == "true"-- print(f"ImageGet: Processing path={path}, metadata={metadata}") # Debug-- if not path:- raise ValueError("No path provided")-- # check if path is within base directory- if not files.is_in_base_dir(path):- raise ValueError("Path is outside of allowed directory")-- # get file extension and info- file_ext = os.path.splitext(path)[1].lower()- filename = os.path.basename(path)-- print(f"ImageGet: file_ext={file_ext}, filename={filename}") # Debug-- # list of allowed image extensions- image_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg"]-- # If metadata is requested, return file information- if metadata:- return self._get_file_metadata(path, filename, file_ext, image_extensions)-- if file_ext in image_extensions:- # Handle image files- print(f"ImageGet: Handling as image file") # Debug- if not os.path.exists(path):- # If image doesn't exist, return default image icon- return self._get_fallback_icon("image")-- # send actual image file with proper headers for device sync+ # input data+ path = input.get("path", request.args.get("path", ""))+ metadata = (+ input.get("metadata", request.args.get("metadata", "false")).lower()+ == "true"+ )++ if not path:+ raise ValueError("No path provided")++ # check if path is within base directory+ if not runtime.call_development_function(files.is_in_base_dir, path):+ raise ValueError("Path is outside of allowed directory")++ # get file extension and info+ file_ext = os.path.splitext(path)[1].lower()+ filename = os.path.basename(path)++ # list of allowed image extensions+ image_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg"]++ # # If metadata is requested, return file information+ # if metadata:+ # return _get_file_metadata(path, filename, file_ext, image_extensions)++ if file_ext in image_extensions:+ # Handle image files+ if not runtime.call_development_function(files.exists, path):+ # If image doesn't exist, return default image icon+ return _send_fallback_icon("image")++ # send image file right away if dockerized, if development, read it from docker and send+ if runtime.is_dockerized():response = send_file(path)- # Add cache headers for better device sync performance- response.headers['Cache-Control'] = 'public, max-age=3600'- response.headers['X-File-Type'] = 'image'- response.headers['X-File-Name'] = filename- return responseelse:- # Handle non-image files with fallback icons- print(f"ImageGet: Handling as non-image file, getting icon") # Debug- return self._get_file_type_icon(file_ext, filename)-- def _get_file_type_icon(self, file_ext, filename=None):- """Return appropriate icon for file type"""- print(f"_get_file_type_icon: file_ext={file_ext}, filename={filename}") # Debug-- # Map file extensions to icon names- icon_mapping = {- # Archive files- '.zip': 'archive',- '.rar': 'archive',- '.7z': 'archive',- '.tar': 'archive',- '.gz': 'archive',-- # Document files- '.pdf': 'document',- '.doc': 'document',- '.docx': 'document',- '.txt': 'document',- '.rtf': 'document',- '.odt': 'document',-- # Code files- '.py': 'code',- '.js': 'code',- '.html': 'code',- '.css': 'code',- '.json': 'code',- '.xml': 'code',- '.md': 'code',- '.yml': 'code',- '.yaml': 'code',- '.sql': 'code',- '.sh': 'code',- '.bat': 'code',-- # Spreadsheet files- '.xls': 'document',- '.xlsx': 'document',- '.csv': 'document',-- # Presentation files- '.ppt': 'document',- '.pptx': 'document',- '.odp': 'document',- }-- # Get icon name, default to 'file' if not found- icon_name = icon_mapping.get(file_ext, 'file')- print(f"_get_file_type_icon: icon_name={icon_name}") # Debug-- response = self._get_fallback_icon(icon_name)-- # Add headers for device sync- if hasattr(response, 'headers'):- response.headers['Cache-Control'] = 'public, max-age=86400' # Cache icons for 24 hours- response.headers['X-File-Type'] = 'icon'- response.headers['X-Icon-Type'] = icon_name- if filename:- response.headers['X-File-Name'] = filename-- return response-- def _get_file_metadata(self, path, filename, file_ext, image_extensions):- """Return file metadata for device sync and UI enhancement"""- metadata = {- 'filename': filename,- 'extension': file_ext,- 'exists': os.path.exists(path),- 'is_image': file_ext in image_extensions,- 'file_type': 'image' if file_ext in image_extensions else self._get_file_category(file_ext),- 'api_url': f'/image_get?path={path}',- 'icon_type': self._get_icon_type(file_ext) if file_ext not in image_extensions else 'image'- }-- # Add file size if file exists- if metadata['exists']:- try:- metadata['size'] = os.path.getsize(path)- metadata['size_human'] = self._format_file_size(metadata['size'])- except OSError:- metadata['size'] = 0- metadata['size_human'] = 'Unknown'-- return metadata-- def _get_file_category(self, file_ext):- """Get file category for metadata"""- categories = {- '.zip': 'archive', '.rar': 'archive', '.7z': 'archive', '.tar': 'archive', '.gz': 'archive',- '.pdf': 'document', '.doc': 'document', '.docx': 'document', '.txt': 'document',- '.py': 'code', '.js': 'code', '.html': 'code', '.css': 'code', '.json': 'code',- '.xls': 'spreadsheet', '.xlsx': 'spreadsheet', '.csv': 'spreadsheet',- '.ppt': 'presentation', '.pptx': 'presentation'- }- return categories.get(file_ext, 'file')-- def _get_icon_type(self, file_ext):- """Get icon type for metadata (matches the icon mapping)"""- icon_mapping = {- '.zip': 'archive', '.rar': 'archive', '.7z': 'archive', '.tar': 'archive', '.gz': 'archive',- '.pdf': 'document', '.doc': 'document', '.docx': 'document', '.txt': 'document', '.rtf': 'document', '.odt': 'document',- '.py': 'code', '.js': 'code', '.html': 'code', '.css': 'code', '.json': 'code', '.xml': 'code', '.md': 'code',- '.yml': 'code', '.yaml': 'code', '.sql': 'code', '.sh': 'code', '.bat': 'code',- '.xls': 'document', '.xlsx': 'document', '.csv': 'document',- '.ppt': 'document', '.pptx': 'document', '.odp': 'document'- }- return icon_mapping.get(file_ext, 'file')-- def _format_file_size(self, size_bytes):- """Format file size in human readable format"""- if size_bytes == 0:- return "0 B"- size_names = ["B", "KB", "MB", "GB", "TB"]- import math- i = int(math.floor(math.log(size_bytes, 1024)))- p = math.pow(1024, i)- s = round(size_bytes / p, 2)- return f"{s} {size_names[i]}"-- def _get_fallback_icon(self, icon_name):- """Return fallback icon from public directory"""- print(f"_get_fallback_icon: icon_name={icon_name}") # Debug-- # Path to public icons- icon_path = files.get_abs_path(f"webui/public/{icon_name}.svg")- print(f"_get_fallback_icon: icon_path={icon_path}") # Debug-- # Check if specific icon exists, fallback to generic file icon- if not os.path.exists(icon_path):- print(f"_get_fallback_icon: Icon not found, falling back to file.svg") # Debug- icon_path = files.get_abs_path("webui/public/file.svg")-- # Final fallback if file.svg doesn't exist- if not os.path.exists(icon_path):- print(f"_get_fallback_icon: ERROR - file.svg not found at {icon_path}") # Debug- raise ValueError(f"Fallback icon not found: {icon_path}")-- print(f"_get_fallback_icon: Sending file {icon_path}") # Debug- return send_file(icon_path, mimetype='image/svg+xml')--\ No newline at end of file+ b64_content = await runtime.call_development_function(+ files.read_file_base64, path+ )+ file_content = base64.b64decode(b64_content)+ mime_type, _ = guess_type(filename)+ if not mime_type:+ mime_type = "application/octet-stream"+ response = send_file(+ io.BytesIO(file_content),+ mimetype=mime_type,+ as_attachment=False,+ download_name=filename,+ )++ # Add cache headers for better device sync performance+ response.headers["Cache-Control"] = "public, max-age=3600"+ response.headers["X-File-Type"] = "image"+ response.headers["X-File-Name"] = filename+ return response+ else:+ # Handle non-image files with fallback icons+ return _send_file_type_icon(file_ext, filename)+++def _send_file_type_icon(file_ext, filename=None):+ """Return appropriate icon for file type"""++ # Map file extensions to icon names+ icon_mapping = {+ # Archive files+ ".zip": "archive",+ ".rar": "archive",+ ".7z": "archive",+ ".tar": "archive",+ ".gz": "archive",+ # Document files+ ".pdf": "document",+ ".doc": "document",+ ".docx": "document",+ ".txt": "document",+ ".rtf": "document",+ ".odt": "document",+ # Code files+ ".py": "code",+ ".js": "code",+ ".html": "code",+ ".css": "code",+ ".json": "code",+ ".xml": "code",+ ".md": "code",+ ".yml": "code",+ ".yaml": "code",+ ".sql": "code",+ ".sh": "code",+ ".bat": "code",+ # Spreadsheet files+ ".xls": "document",+ ".xlsx": "document",+ ".csv": "document",+ # Presentation files+ ".ppt": "document",+ ".pptx": "document",+ ".odp": "document",+ }++ # Get icon name, default to 'file' if not found+ icon_name = icon_mapping.get(file_ext, "file")++ response = _send_fallback_icon(icon_name)++ # Add headers for device sync+ if hasattr(response, "headers"):+ response.headers["Cache-Control"] = (+ "public, max-age=86400" # Cache icons for 24 hours+ )+ response.headers["X-File-Type"] = "icon"+ response.headers["X-Icon-Type"] = icon_name+ if filename:+ response.headers["X-File-Name"] = filename++ return response+++def _send_fallback_icon(icon_name):+ """Return fallback icon from public directory"""++ # Path to public icons+ icon_path = files.get_abs_path(f"webui/public/{icon_name}.svg")++ # Check if specific icon exists, fallback to generic file icon+ if not os.path.exists(icon_path):+ icon_path = files.get_abs_path("webui/public/file.svg")++ # Final fallback if file.svg doesn't exist+ if not os.path.exists(icon_path):+ raise ValueError(f"Fallback icon not found: {icon_path}")++ return send_file(icon_path, mimetype="image/svg+xml")diff --git a/python/helpers/tool.py b/python/helpers/tool.pyindex cbaf5f5c7..d993eff41 100644--- a/python/helpers/tool.py+++ b/python/helpers/tool.py@@ -1,7 +1,7 @@from abc import abstractmethodfrom dataclasses import dataclass-from agent import Agent+from agent import Agent, LoopDatafrom python.helpers.print_style import PrintStylefrom python.helpers.strings import sanitize_string@@ -13,11 +13,12 @@ class Response:class Tool:- def __init__(self, agent: Agent, name: str, method: str | None, args: dict[str,str], message: str, **kwargs) -> None:+ def __init__(self, agent: Agent, name: str, method: str | None, args: dict[str,str], message: str, loop_data: LoopData | None, **kwargs) -> None:self.agent = agentself.name = nameself.method = methodself.args = args+ self.loop_data = loop_dataself.message = message@abstractmethoddiff --git a/python/tools/response.py b/python/tools/response.pyindex 668c9ac81..73d9d42d3 100644--- a/python/tools/response.py+++ b/python/tools/response.py@@ -12,4 +12,8 @@ class ResponseTool(Tool):passasync def after_execution(self, response, **kwargs):- pass # do not add anything to the history or output+ # do not add anything to the history or output++ if self.loop_data and "log_item_response" in self.loop_data.params_temporary:+ log = self.loop_data.params_temporary["log_item_response"]+ log.update(finished=True) # mark the message as finisheddiff --git a/webui/components/chat/attachments/attachmentsStore.js b/webui/components/chat/attachments/attachmentsStore.jsindex 840d2ca68..08be2f6bb 100644--- a/webui/components/chat/attachments/attachmentsStore.js+++ b/webui/components/chat/attachments/attachmentsStore.js@@ -1,4 +1,5 @@import { createStore } from "/js/AlpineStore.js";+import { fetchApi } from "/js/api.js";const model = {// State properties@@ -48,10 +49,12 @@ const model = {validateDuplicates(newAttachment) {// Check if attachment already exists based on name and size- const isDuplicate = this.attachments.some(existing =>- existing.name === newAttachment.name &&- existing.file && newAttachment.file &&- existing.file.size === newAttachment.file.size+ const isDuplicate = this.attachments.some(+ (existing) =>+ existing.name === newAttachment.name &&+ existing.file &&+ newAttachment.file &&+ existing.file.size === newAttachment.file.size);return !isDuplicate;},@@ -71,80 +74,101 @@ const model = {// Setup drag and drop event handlerssetupDragDropHandlers() {- console.log('Setting up drag and drop handlers...');+ console.log("Setting up drag and drop handlers...");let dragCounter = 0;// Prevent default drag behaviors- ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {- document.addEventListener(eventName, (e) => {- e.preventDefault();- e.stopPropagation();- }, false);+ ["dragenter", "dragover", "dragleave", "drop"].forEach((eventName) => {+ document.addEventListener(+ eventName,+ (e) => {+ e.preventDefault();+ e.stopPropagation();+ },+ false+ );});// Handle drag enter- document.addEventListener('dragenter', (e) => {- console.log('Drag enter detected');- dragCounter++;- if (dragCounter === 1) {- console.log('Showing drag drop overlay');- this.showDragDropOverlay();- }- }, false);+ document.addEventListener(+ "dragenter",+ (e) => {+ console.log("Drag enter detected");+ dragCounter++;+ if (dragCounter === 1) {+ console.log("Showing drag drop overlay");+ this.showDragDropOverlay();+ }+ },+ false+ );// Handle drag leave- document.addEventListener('dragleave', (e) => {- dragCounter--;- if (dragCounter === 0) {- this.hideDragDropOverlay();- }- }, false);+ document.addEventListener(+ "dragleave",+ (e) => {+ dragCounter--;+ if (dragCounter === 0) {+ this.hideDragDropOverlay();+ }+ },+ false+ );// Handle drop- document.addEventListener('drop', (e) => {- console.log('Drop detected with files:', e.dataTransfer.files.length);- dragCounter = 0;- this.hideDragDropOverlay();-- const files = e.dataTransfer.files;- this.handleFiles(files);- }, false);+ document.addEventListener(+ "drop",+ (e) => {+ console.log("Drop detected with files:", e.dataTransfer.files.length);+ dragCounter = 0;+ this.hideDragDropOverlay();++ const files = e.dataTransfer.files;+ this.handleFiles(files);+ },+ false+ );},// Setup paste event handler for clipboard imagessetupPasteHandler() {- console.log('Setting up paste handler...');- document.addEventListener('paste', (e) => {- console.log('Paste event detected, target:', e.target.tagName);-+ console.log("Setting up paste handler...");+ document.addEventListener("paste", (e) => {+ console.log("Paste event detected, target:", e.target.tagName);+const items = e.clipboardData.items;let imageFound = false;- console.log('Checking clipboard items:', items.length);-+ console.log("Checking clipboard items:", items.length);+// First, check if there are any images in the clipboardfor (let i = 0; i < items.length; i++) {const item = items[i];- if (item.type.indexOf('image') !== -1) {+ if (item.type.indexOf("image") !== -1) {imageFound = true;const blob = item.getAsFile();if (blob) {e.preventDefault(); // Prevent default paste behavior for imagesthis.handleClipboardImage(blob);- console.log('Image detected in clipboard, processing...');+ console.log("Image detected in clipboard, processing...");}break; // Only handle the first image found}}// If no images found and we're in an input field, let normal text paste happen- if (!imageFound && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA')) {- console.log('No images in clipboard, allowing normal text paste in input field');+ if (+ !imageFound &&+ (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA")+ ) {+ console.log(+ "No images in clipboard, allowing normal text paste in input field"+ );return;}// If no images found and not in input field, do nothingif (!imageFound) {- console.log('No images in clipboard');+ console.log("No images in clipboard");}});},@@ -155,16 +179,17 @@ const model = {// Generate unique filenameconst guid = this.generateGUID();const filename = `clipboard-${guid}.png`;-+// Create file object from blob- const file = new File([blob], filename, { type: 'image/png' });-+ const file = new File([blob], filename, { type: "image/png" });+// Create attachment objectconst attachment = {file: file,- type: 'image',+ type: "image",name: filename,- extension: 'png'+ extension: "png",+ displayInfo: this.getAttachmentDisplayInfo(file),};// Read as data URL for preview@@ -176,26 +201,28 @@ const model = {reader.readAsDataURL(file);// Show success feedback- console.log('Clipboard image pasted successfully:', filename);-+ console.log("Clipboard image pasted successfully:", filename);} catch (error) {- console.error('Failed to handle clipboard image:', error);+ console.error("Failed to handle clipboard image:", error);}},// File handling logic (moved from index.js)handleFiles(files) {- console.log('handleFiles called with', files.length, 'files');- Array.from(files).forEach(file => {- console.log('Processing file:', file.name, file.type);- const ext = file.name.split('.').pop().toLowerCase();- const isImage = ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'webp'].includes(ext);+ console.log("handleFiles called with", files.length, "files");+ Array.from(files).forEach((file) => {+ console.log("Processing file:", file.name, file.type);+ const ext = file.name.split(".").pop().toLowerCase();+ const isImage = ["jpg", "jpeg", "png", "bmp", "gif", "webp"].includes(+ ext+ );const attachment = {file: file,- type: isImage ? 'image' : 'file',+ type: isImage ? "image" : "file",name: file.name,- extension: ext+ extension: ext,+ displayInfo: this.getAttachmentDisplayInfo(file),};if (isImage) {@@ -215,106 +242,194 @@ const model = {// Get attachments for sending messagegetAttachmentsForSending() {- return this.attachments.map(attachment => {- if (attachment.type === 'image') {+ return this.attachments.map((attachment) => {+ if (attachment.type === "image") {return {...attachment,- url: URL.createObjectURL(attachment.file)+ url: URL.createObjectURL(attachment.file),};} else {return {- ...attachment+ ...attachment,};}});},// Generate server-side API URL for file (for device sync)- getServerFileUrl(filename) {+ getServerImgUrl(filename) {return `/image_get?path=/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;- }+ getServerFileUrl(filename) {+ 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'];- const extension = filename.split('.').pop().toLowerCase();+ const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg"];+ const extension = filename.split(".").pop().toLowerCase();return imageExtensions.includes(extension);},// Get attachment preview URL (server URL for persistence, blob URL for current session)getAttachmentPreviewUrl(attachment) {// If attachment has a name and we're dealing with a server-stored file- if (typeof attachment === 'string') {+ if (typeof attachment === "string") {// attachment is just a filename (from loaded chat)- return this.getServerFileUrl(attachment);+ return this.getServerImgUrl(attachment);} else if (attachment.name && attachment.file) {// attachment is an object from current session- if (attachment.type === 'image') {+ if (attachment.type === "image") {// For images, use blob URL for current session previewreturn attachment.url || URL.createObjectURL(attachment.file);} else {// For non-image files, use server URL to get appropriate icon- return this.getServerFileUrl(attachment.name);+ return this.getServerImgUrl(attachment.name);}}return null;},+ getFilePreviewUrl(filename) {+ const extension = filename.split(".").pop().toLowerCase();+ const types = {+ // Archive files+ zip: "archive",+ rar: "archive",+ "7z": "archive",+ tar: "archive",+ gz: "archive",+ // Document files+ pdf: "document",+ doc: "document",+ docx: "document",+ txt: "document",+ rtf: "document",+ odt: "document",+ // Code files+ py: "code",+ js: "code",+ html: "code",+ css: "code",+ json: "code",+ xml: "code",+ md: "code",+ yml: "code",+ yaml: "code",+ sql: "code",+ sh: "code",+ bat: "code",+ // Spreadsheet files+ xls: "document",+ xlsx: "document",+ csv: "document",+ // Presentation files+ ppt: "document",+ pptx: "document",+ odp: "document",+ };+ const type = types[extension] || "file";+ return `/public/${type}.svg`;+ },+// Enhanced method to get attachment display info for UIgetAttachmentDisplayInfo(attachment) {- if (typeof attachment === 'string') {+ if (typeof attachment === "string") {// attachment is filename only (from persistent storage)const filename = attachment;- const extension = filename.split('.').pop();+ const extension = filename.split(".").pop();+ const isImage = this.isImageFile(filename);+ const previewUrl = isImage+ ? this.getServerImgUrl(filename)+ : this.getFilePreviewUrl(filename);+return {filename: filename,extension: extension.toUpperCase(),- isImage: this.isImageFile(filename),- previewUrl: this.getServerFileUrl(filename),+ isImage: isImage,+ previewUrl: previewUrl,clickHandler: () => {if (this.isImageFile(filename)) {- this.openImageModal(this.getServerFileUrl(filename), filename);+ this.openImageModal(this.getServerImgUrl(filename), filename);+ } else {+ this.downloadAttachment(filename);}- }+ },};} else {// attachment is object (from current session)+ const isImage = this.isImageFile(attachment.name);+ const filename = attachment.name;+ const extension = filename.split(".").pop() || "";+ const previewUrl = isImage+ ? this.getServerImgUrl(attachment.name)+ : this.getFilePreviewUrl(attachment.name);return {- filename: attachment.name,- extension: attachment.extension.toUpperCase(),- isImage: attachment.type === 'image',- previewUrl: this.getAttachmentPreviewUrl(attachment),+ filename: filename,+ extension: extension.toUpperCase(),+ isImage: attachment.type === "image",+ previewUrl: previewUrl,clickHandler: () => {- if (attachment.type === 'image') {- const imageUrl = this.getAttachmentPreviewUrl(attachment);+ if (attachment.type === "image") {+ const imageUrl = this.getServerImgUrl(attachment.name);this.openImageModal(imageUrl, attachment.name);+ } else {+ this.downloadAttachment(attachment.name);}- }+ },};}},+ async downloadAttachment(filename) {+ try {+ const path = this.getServerFileUrl(filename);+ const response = await fetchApi("/download_work_dir_file?path=" + path);++ if (!response.ok) {+ throw new Error("Network response was not ok");+ }++ const blob = await response.blob();++ const link = document.createElement("a");+ link.href = window.URL.createObjectURL(blob);+ link.download = filename;+ document.body.appendChild(link);+ link.click();+ document.body.removeChild(link);+ window.URL.revokeObjectURL(link.href);+ } catch (error) {+ window.toastFetchError("Error downloading file", error);+ alert("Error downloading file");+ }+ },+// Generate GUID for unique filenamesgenerateGUID() {- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {- const r = Math.random() * 16 | 0;- const v = c == 'x' ? r : (r & 0x3 | 0x8);- return v.toString(16);- });+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(+ /[xy]/g,+ function (c) {+ const r = (Math.random() * 16) | 0;+ const v = c == "x" ? r : (r & 0x3) | 0x8;+ return v.toString(16);+ }+ );},// Image modal methods@@ -324,10 +439,10 @@ const model = {this.imageLoaded = false;this.imageError = false;this.zoomLevel = 1;-+// Open the modal using the modals systemif (window.openModal) {- window.openModal('chat/attachments/imageModal.html');+ window.openModal("chat/attachments/imageModal.html");}},@@ -356,15 +471,13 @@ const model = {},updateImageZoom() {- const img = document.querySelector('.modal-image');+ const img = document.querySelector(".modal-image");if (img) {img.style.transform = `scale(${this.zoomLevel})`;}- }+ },};-console.log('Creating chatAttachments store...');const store = createStore("chatAttachments", model);-console.log('chatAttachments store created:', store);-export { store };\ No newline at end of file+export { store };diff --git a/webui/components/chat/attachments/dragDropOverlay.html b/webui/components/chat/attachments/dragDropOverlay.htmlindex 7d9d3f7d4..7259d9c61 100644--- a/webui/components/chat/attachments/dragDropOverlay.html+++ b/webui/components/chat/attachments/dragDropOverlay.html@@ -2,7 +2,7 @@<head><title>Drag Drop Overlay</title>-+<script type="module">import { store } from "/components/chat/attachments/attachmentsStore.js";</script>@@ -10,20 +10,19 @@<body><!-- Drag and Drop Overlay -->- <div id="dragdrop-overlay"- x-cloak- x-show="$store.chatAttachments.dragDropOverlayVisible"- x-transition:enter="transition ease-out duration-300"- x-transition:enter-start="opacity-0"- 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-subtext"></div>+ <div x-data>+ <template x-if="$store.chatAttachments">+ <div x-cloak x-show="$store.chatAttachments.dragDropOverlayVisible" id="dragdrop-overlay"+ x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0"+ 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-subtext"></div>+ </div>+ </template></div>+</body>-</html>\ No newline at end of file+</html>\ No newline at end of filediff --git a/webui/components/chat/attachments/inputPreview.html b/webui/components/chat/attachments/inputPreview.htmlnew file mode 100644index 000000000..0ed55365a--- /dev/null+++ b/webui/components/chat/attachments/inputPreview.html@@ -0,0 +1,29 @@+<script type="module">+ import { store } from "/components/chat/attachments/attachmentsStore.js";+</script>++<div x-data>+ <template x-if="$store.chatAttachments">++ <div x-show="$store.chatAttachments.hasAttachments" class="preview-section">+ <template x-for="(attachment, index) in $store.chatAttachments.attachments" :key="index">+ <div class="attachment-item"+ :class="{'image-type': attachment.type === 'image', 'file-type': attachment.type === 'file'}">+ <template x-if="attachment.type === 'image'">+ <img :src="attachment.url" class="attachment-preview" :alt="attachment.name" style="cursor: pointer;"+ @click="$store.chatAttachments.openImageModal(attachment.url, attachment.name)">+ </template>+ <template x-if="attachment.type === 'file'">+ <div>+ <img :src="attachment.displayInfo.previewUrl" class="file-icon" :alt="attachment.extension">+ <span class="file-title" x-text="attachment.name"></span>+ </div>+ </template>+ <button @click="$store.chatAttachments.removeAttachment(index)"+ class="remove-attachment">×</button>+ </div>+ </template>+ </div>++ </template>+</div>\ No newline at end of filediff --git a/webui/index.css b/webui/index.cssindex 0af90fe00..9583c8b99 100644--- a/webui/index.css+++ b/webui/index.css@@ -106,6 +106,16 @@ body,color: var(--color-text);}+img {+ user-drag: none; /* Safari & old Chrome */+ -webkit-user-drag: none;+ user-select: none; /* Prevent selection for good measure */+ -webkit-user-select: none;+ -moz-user-select: none;+ -ms-user-select: none;+ pointer-events: auto; /* Allow clicks, just no drag */+}+/* Layout */.container {display: -webkit-flex;@@ -555,6 +565,12 @@ pre {background-color: var(--color-input);border-radius: 8px;margin-bottom: var(--spacing-xs);+ max-height: 10em;+ overflow-y: auto;+}++.light-mode .preview-section {+ background-color: none;}.preview-item {@@ -910,7 +926,7 @@ pre {grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));gap: 12px;padding: var(--spacing-sm);- background-color: var(--color-input);+ /* background-color: var(--color-input); */border-radius: 8px;max-width: 600px; /* Limits to ~5 columns at 120px each */overflow: visible;@@ -932,12 +948,21 @@ pre {box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);}+.light-mode .attachment-item {+ background-color: var(--color-panel-light);+ border: 2px solid var(--color-border-light);+}+.attachment-item:hover {border-color: var(--color-primary);box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);transform: translateY(-2px);}+.light-mode .attachment-item:hover {+ border-color: var(--color-primary-light);+}+/* Image attachment styling */.attachment-item.image-type {padding: 0;@@ -950,21 +975,6 @@ pre {border-radius: 10px;}-.attachment-item.image-type .image-badge {- position: absolute;- bottom: 6px;- left: 50%;- transform: translateX(-50%);- background: rgba(0, 0, 0, 0.7);- color: white;- padding: 2px 8px;- border-radius: 12px;- font-size: 0.65rem;- text-transform: uppercase;- backdrop-filter: blur(4px);- -webkit-backdrop-filter: blur(4px);-}-/* File attachment styling */.attachment-item.file-type {flex-direction: column;@@ -994,16 +1004,6 @@ pre {margin-bottom: 4px;}-.attachment-item.file-type .file-extension {- background: var(--color-primary);- color: var(--color-text);- padding: 2px 6px;- border-radius: 4px;- font-size: 0.7rem;- text-transform: uppercase;- white-space: nowrap;-}-.attachment-preview {width: 100%;height: 100%;@@ -1112,8 +1112,8 @@ pre {.remove-attachment {position: absolute;- top: -6px;- right: -6px;+ top: 5px;+ right: 5px;background-color: var(--color-primary);color: white;border: none;@@ -1296,11 +1296,11 @@ pre {background-color: var(--color-background);}-.preview-item img {+.image-preview img {max-height: 100px;object-fit: cover;border-radius: 8px;- border: 1px solid var(--color-border-light);+ /* border: 1px solid var(--color-border-light); */}.file-preview {@@ -1544,13 +1544,13 @@ input:checked + .slider:before {padding: 1px 4px;}- .remove-attachment,+ /* .remove-attachment,.remove-image {width: 20px;height: 20px;top: 2px;right: 2px;- }+ } */.attachment-item.image-type .image-badge {bottom: 4px;diff --git a/webui/index.html b/webui/index.htmlindex 928710366..015e82f9a 100644--- a/webui/index.html+++ b/webui/index.html@@ -102,7 +102,6 @@<script type="module" src="js/scheduler.js"></script><script type="module" src="js/speech.js"></script><script type="module" src="js/history.js"></script>- <script type="module" src="components/chat/attachments/attachmentsStore.js"></script><script type="module" src="index.js"></script><!-- Then load Alpine.js -->@@ -128,7 +127,7 @@<script type="text/javascript" src="js/settings.js"></script><script type="text/javascript" src="js/file_browser.js"></script><script type="text/javascript" src="js/modal.js"></script>- <script type="text/javascript" src="js/tunnel.js"></script>+ <script type="module" src="js/tunnel.js"></script></head><body class="dark-mode">@@ -364,7 +363,7 @@</div><div id="progress-bar-box" x-data="{ isSpeaking: false }" x-init="// Watch the speech synthesis status to update isSpeaking- setInterval(() => isSpeaking = window.speech.isSpeaking(), 100)+ setInterval(() => isSpeaking = window.speech && window.speech.isSpeaking(), 1000)"><h4 id="progress-bar-h"><span id="progress-bar-i">|></span><span id="progress-bar"></span>@@ -377,27 +376,11 @@paused: false}">- <!-- Preview section -->- <div x-show="$store.chatAttachments.hasAttachments" class="preview-section">- <template x-for="(attachment, index) in $store.chatAttachments.attachments" :key="index">- <div class="preview-item" :class="{'image-preview': attachment.type === 'image'}">- <template x-if="attachment.type === 'image'">- <img :src="attachment.url" :alt="attachment.name"- style="cursor: pointer;"- @click="$store.chatAttachments.openImageModal(attachment.url, attachment.name)">- </template>- <template x-if="attachment.type === 'file'">- <div class="file-preview">- <span class="filename" x-text="attachment.name"></span>- <span class="extension" x-text="attachment.extension.toUpperCase()"></span>- </div>- </template>- <button @click="$store.chatAttachments.removeAttachment(index)"- class="remove-attachment">×</button>- </div>- </template>+ <!-- Attachment Preview section -->+ <div>+ <x-component path="/chat/attachments/inputPreview.html" /></div>-+<!-- Top row with input and buttons --><div class="input-row"><!-- Attachment icon with tooltip -->diff --git a/webui/index.js b/webui/index.jsindex 8dcdf408e..f8303eccd 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 { 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@@ -91,19 +92,19 @@ function setupSidebarToggle() {document.addEventListener("DOMContentLoaded", setupSidebarToggle);export async function sendMessage() {- try {- const message = chatInput.value.trim();- const attachmentsStore = window.Alpine ? Alpine.store('chatAttachments') : null;- const attachments = attachmentsStore ? attachmentsStore.attachments : [];- const hasAttachments = attachmentsStore ? attachmentsStore.hasAttachments : false;+ 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;if (message || hasAttachments) {let response;const messageId = generateGUID();- // Include attachments in the user message- if (hasAttachments) {- const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();+ // Include attachments in the user message+ if (hasAttachments) {+ const attachmentsWithUrls = attachmentsStore.getAttachmentsForSending();// Render user message with attachmentssetMessage(messageId, "user", "", message, false, {@@ -155,16 +156,16 @@ export async function sendMessage() {setContext(jsonResponse.context);}- // Clear input and attachments- chatInput.value = '';- if (attachmentsStore) {- attachmentsStore.clearAttachments();- }- adjustTextareaHeight();- }- } catch (e) {- toastFetchError("Error sending message", e)+ // Clear input and attachments+ chatInput.value = "";+ // if (attachmentsStore) {+ attachmentsStore.clearAttachments();+ // }+ adjustTextareaHeight();}+ } catch (e) {+ toastFetchError("Error sending message", e);+ }}function toastFetchError(text, error) {@@ -309,16 +310,16 @@ function getConnectionStatus() {}function setConnectionStatus(connected) {- connectionStatus = connected- if (window.Alpine && timeDate) {- const statusIconEl = timeDate.querySelector('.status-icon');- if (statusIconEl) {- const statusIcon = Alpine.$data(statusIconEl);- if (statusIcon) {- statusIcon.connected = connected;- }- }+ connectionStatus = connected;+ if (window.Alpine && timeDate) {+ const statusIconEl = timeDate.querySelector(".status-icon");+ if (statusIconEl) {+ const statusIcon = Alpine.$data(statusIconEl);+ if (statusIcon) {+ statusIcon.connected = connected;+ }}+ }}let lastLogVersion = 0;@@ -372,60 +373,60 @@ async function poll() {updateProgress(response.log_progress, response.log_progress_active);- //set ui model vars from backend- if (window.Alpine && inputSection) {- const inputAD = Alpine.$data(inputSection);- if (inputAD) {- inputAD.paused = response.paused;- }- }+ //set ui model vars from backend+ if (window.Alpine && inputSection) {+ const inputAD = Alpine.$data(inputSection);+ if (inputAD) {+ inputAD.paused = response.paused;+ }+ }// Update status icon statesetConnectionStatus(true);- // Update chats list and sort by created_at time (newer first)- let chatsAD = null;- let contexts = response.contexts || [];- if (window.Alpine && chatsSection) {- chatsAD = Alpine.$data(chatsSection);- if (chatsAD) {- chatsAD.contexts = contexts.sort((a, b) =>- (b.created_at || 0) - (a.created_at || 0)- );- }- }+ // Update chats list and sort by created_at time (newer first)+ let chatsAD = null;+ let contexts = response.contexts || [];+ if (window.Alpine && chatsSection) {+ chatsAD = Alpine.$data(chatsSection);+ if (chatsAD) {+ chatsAD.contexts = contexts.sort(+ (a, b) => (b.created_at || 0) - (a.created_at || 0)+ );+ }+ }++ // Update tasks list and sort by creation time (newer first)+ const tasksSection = document.getElementById("tasks-section");+ if (window.Alpine && tasksSection) {+ const tasksAD = Alpine.$data(tasksSection);+ if (tasksAD) {+ let tasks = response.tasks || [];++ // Always update tasks to ensure state changes are reflected+ if (tasks.length > 0) {+ // Sort the tasks by creation time+ const sortedTasks = [...tasks].sort(+ (a, b) => (b.created_at || 0) - (a.created_at || 0)+ );- // Update tasks list and sort by creation time (newer first)- const tasksSection = document.getElementById('tasks-section');- if (window.Alpine && tasksSection) {- const tasksAD = Alpine.$data(tasksSection);- if (tasksAD) {- let tasks = response.tasks || [];-- // Always update tasks to ensure state changes are reflected- if (tasks.length > 0) {- // Sort the tasks by creation time- const sortedTasks = [...tasks].sort((a, b) =>- (b.created_at || 0) - (a.created_at || 0)- );-- // Assign the sorted tasks to the Alpine data- tasksAD.tasks = sortedTasks;- } else {- // Make sure to use a new empty array instance- tasksAD.tasks = [];- }- }+ // Assign the sorted tasks to the Alpine data+ tasksAD.tasks = sortedTasks;+ } else {+ // Make sure to use a new empty array instance+ tasksAD.tasks = [];}+ }+ }// Make sure the active context is properly selected in both listsif (context) {// Update selection in the active tabconst activeTab = localStorage.getItem("activeTab") || "chats";- if (activeTab === 'chats' && chatsAD) {- chatsAD.selected = context;- localStorage.setItem('lastSelectedChat', context);+ if (activeTab === "chats" && chatsAD) {+ chatsAD.selected = context;+ localStorage.setItem("lastSelectedChat", context);// Check if this context exists in the chats listconst contextExists = contexts.some((ctx) => ctx.id === context);@@ -451,26 +452,34 @@ async function poll() {// Check if this context exists in the tasks listconst taskExists = response.tasks?.some((task) => task.id === context);- // If it doesn't exist in the tasks list but we're in tasks tab, try to select the first task- if (!taskExists && response.tasks?.length > 0) {- const firstTaskId = response.tasks[0].id;- setContext(firstTaskId);- tasksAD.selected = firstTaskId;- localStorage.setItem('lastSelectedTask', firstTaskId);- }- }- } else if (response.tasks && response.tasks.length > 0 && localStorage.getItem('activeTab') === 'tasks') {- // If we're in tasks tab with no selection but have tasks, select the first one- const firstTaskId = response.tasks[0].id;- setContext(firstTaskId);- if (tasksSection) {- const tasksAD = Alpine.$data(tasksSection);- tasksAD.selected = firstTaskId;- localStorage.setItem('lastSelectedTask', firstTaskId);- }- } else if (contexts.length > 0 && localStorage.getItem('activeTab') === 'chats' && chatsAD) {- // If we're in chats tab with no selection but have chats, select the first one- const firstChatId = contexts[0].id;+ // If it doesn't exist in the tasks list but we're in tasks tab, try to select the first task+ if (!taskExists && response.tasks?.length > 0) {+ const firstTaskId = response.tasks[0].id;+ setContext(firstTaskId);+ tasksAD.selected = firstTaskId;+ localStorage.setItem("lastSelectedTask", firstTaskId);+ }+ }+ } else if (+ response.tasks &&+ response.tasks.length > 0 &&+ localStorage.getItem("activeTab") === "tasks"+ ) {+ // If we're in tasks tab with no selection but have tasks, select the first one+ const firstTaskId = response.tasks[0].id;+ setContext(firstTaskId);+ if (tasksSection) {+ const tasksAD = Alpine.$data(tasksSection);+ tasksAD.selected = firstTaskId;+ localStorage.setItem("lastSelectedTask", firstTaskId);+ }+ } else if (+ contexts.length > 0 &&+ localStorage.getItem("activeTab") === "chats" &&+ chatsAD+ ) {+ // If we're in chats tab with no selection but have chats, select the first one+ const firstChatId = contexts[0].id;// Only set context if we don't already have one to avoid duplicatesif (!context) {@@ -500,12 +509,26 @@ function speakMessages(logs) {// log.no, log.type, log.heading, log.contentfor (let i = logs.length - 1; i >= 0; i--) {const log = logs[i];- if (log.type == "response") {+ // finished response+ if (log.type == "response" && log.kvps && log.kvps.finished) {if (log.no > lastSpokenNo) {lastSpokenNo = log.no;speech.speak(log.content);return;}+ // finished LLM headline, not response+ } else if (+ log.type == "agent" &&+ log.kvps &&+ log.kvps.headline &&+ log.kvps.tool_args &&+ log.kvps.tool_name != "response"+ ) {+ if (log.no > lastSpokenNo) {+ lastSpokenNo = log.no;+ speech.speak(log.kvps.headline);+ return;+ }}}}@@ -700,18 +723,18 @@ export const setContext = function (id) {// Clear the chat history immediately to avoid showing stale contentchatHistory.innerHTML = "";- // Update both selected states- if (window.Alpine) {- if (chatsSection) {- const chatsAD = Alpine.$data(chatsSection);- if (chatsAD) chatsAD.selected = id;- }- if (tasksSection) {- const tasksAD = Alpine.$data(tasksSection);- if (tasksAD) tasksAD.selected = id;- }+ // Update both selected states+ if (window.Alpine) {+ if (chatsSection) {+ const chatsAD = Alpine.$data(chatsSection);+ if (chatsAD) chatsAD.selected = id;}-}+ if (tasksSection) {+ const tasksAD = Alpine.$data(tasksSection);+ if (tasksAD) tasksAD.selected = id;+ }+ }+};export const getContext = function () {return context;@@ -1020,13 +1043,13 @@ function hideToast() {}function scrollChanged(isAtBottom) {- if (window.Alpine && autoScrollSwitch) {- const inputAS = Alpine.$data(autoScrollSwitch);- if (inputAS) {- inputAS.autoScroll = isAtBottom;- }+ if (window.Alpine && autoScrollSwitch) {+ const inputAS = Alpine.$data(autoScrollSwitch);+ if (inputAS) {+ inputAS.autoScroll = isAtBottom;}- // autoScrollSwitch.checked = isAtBottom+ }+ // autoScrollSwitch.checked = isAtBottom}function updateAfterScroll() {@@ -1077,16 +1100,17 @@ 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!');- }-}+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 () {@@ -1145,9 +1169,9 @@ function activateTab(tabName) {chatsTab.classList.add("active");chatsSection.style.display = "";- // Get the available contexts from Alpine.js data- const chatsAD = window.Alpine ? Alpine.$data(chatsSection) : null;- const availableContexts = chatsAD?.contexts || [];+ // Get the available contexts from Alpine.js data+ const chatsAD = window.Alpine ? Alpine.$data(chatsSection) : null;+ const availableContexts = chatsAD?.contexts || [];// Restore previous chat selectionconst lastSelectedChat = localStorage.getItem("lastSelectedChat");@@ -1169,9 +1193,9 @@ function activateTab(tabName) {tasksSection.style.display = "flex";tasksSection.style.flexDirection = "column";- // Get the available tasks from Alpine.js data- const tasksAD = window.Alpine ? Alpine.$data(tasksSection) : null;- const availableTasks = tasksAD?.tasks || [];+ // Get the available tasks from Alpine.js data+ const tasksAD = window.Alpine ? Alpine.$data(tasksSection) : null;+ const availableTasks = tasksAD?.tasks || [];// Restore previous task selectionconst lastSelectedTask = localStorage.getItem("lastSelectedTask");@@ -1236,8 +1260,8 @@ function openTaskDetail(taskId) {return;}- // Get the Alpine.js data for the modal- const modalData = window.Alpine ? Alpine.$data(modalEl) : null;+ // Get the Alpine.js data for the modal+ const modalData = window.Alpine ? Alpine.$data(modalEl) : null;// Use a timeout to ensure the modal is fully renderedsetTimeout(() => {@@ -1255,8 +1279,10 @@ function openTaskDetail(taskId) {return;}- // Get the Alpine.js data for the scheduler component- const schedulerData = window.Alpine ? Alpine.$data(schedulerComponent) : null;+ // Get the Alpine.js data for the scheduler component+ const schedulerData = window.Alpine+ ? Alpine.$data(schedulerComponent)+ : null;// Show the task detail view for the specific taskschedulerData.showTaskDetail(taskId);diff --git a/webui/js/AlpineStore.js b/webui/js/AlpineStore.jsindex bf386c279..fea2d457f 100644--- a/webui/js/AlpineStore.js+++ b/webui/js/AlpineStore.js@@ -18,6 +18,8 @@ export function createStore(name, initialState) {return true;},get(target, prop) {+ const store = globalThis.Alpine?.store(name);+ if (store) return store[prop];return target[prop];}});diff --git a/webui/js/messages.js b/webui/js/messages.jsindex a7ca2cb0e..9e5401bb0 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -1,8 +1,9 @@// copy buttonimport { openImageModal } from "./image_modal.js";import { marked } from "../vendor/marked/marked.esm.js";-import { store as messageResizeStore } from "/components/messages/resize/message-resize-store.js";import { getAutoScroll } from "/index.js";+import { store as _messageResizeStore } from "/components/messages/resize/message-resize-store.js"; // keep here, required in html+import { store as attachmentsStore } from "/components/chat/attachments/attachmentsStore.js";const chatHistory = document.getElementById("chat-history");@@ -394,64 +395,9 @@ export function drawMessageUser(const attachmentDiv = document.createElement("div");attachmentDiv.classList.add("attachment-item");- // Get attachment store for enhanced device sync support- const attachmentStore = window.Alpine && window.Alpine.store('chatAttachments');-- // Helper function to generate server-side image URL (fallback if store not available)- const getServerImageUrl = (filename) => {- if (attachmentStore) {- return attachmentStore.getServerFileUrl(filename);- }- return `/image_get?path=/a0/tmp/uploads/${encodeURIComponent(filename)}`;- };-- // Helper function to check if file is an image (fallback if store not available)- const isImageFile = (filename) => {- if (attachmentStore) {- return attachmentStore.isImageFile(filename);- }- const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];- const extension = filename.split('.').pop().toLowerCase();- return imageExtensions.includes(extension);- };-- // Use enhanced attachment store methods for better device sync- let displayInfo;- if (attachmentStore) {- displayInfo = attachmentStore.getAttachmentDisplayInfo(attachment);- } else {- // Fallback for when store is not available- if (typeof attachment === "string") {- const filename = attachment;- const extension = filename.split(".").pop();- displayInfo = {- filename: filename,- extension: extension.toUpperCase(),- isImage: isImageFile(filename),- previewUrl: getServerImageUrl(filename),- clickHandler: () => {- if (isImageFile(filename) && window.Alpine && window.Alpine.store('chatAttachments')) {- window.Alpine.store('chatAttachments').openImageModal(getServerImageUrl(filename), filename);- }- }- };- } else {- displayInfo = {- filename: attachment.name,- extension: attachment.extension.toUpperCase(),- isImage: attachment.type === 'image',- previewUrl: attachment.url,- clickHandler: () => {- if (attachment.type === 'image' && window.Alpine && window.Alpine.store('chatAttachments')) {- window.Alpine.store('chatAttachments').openImageModal(attachment.url, attachment.name);- }- }- };- }- }+ const displayInfo = attachmentsStore.getAttachmentDisplayInfo(attachment);if (displayInfo.isImage) {- // Render as image tile with bottom badgeattachmentDiv.classList.add("image-type");const img = document.createElement("img");@@ -459,14 +405,9 @@ export function drawMessageUser(img.alt = displayInfo.filename;img.classList.add("attachment-preview");img.style.cursor = "pointer";- img.addEventListener('click', displayInfo.clickHandler);- const imageBadge = document.createElement("div");- imageBadge.classList.add("image-badge");- imageBadge.textContent = displayInfo.extension;attachmentDiv.appendChild(img);- attachmentDiv.appendChild(imageBadge);} else {// Render as file tile with title and iconattachmentDiv.classList.add("file-type");@@ -480,22 +421,15 @@ export function drawMessageUser(attachmentDiv.appendChild(iconImg);}- // File title (filename without extension)+ // File titleconst fileTitle = document.createElement("div");fileTitle.classList.add("file-title");- const nameWithoutExt = displayInfo.filename.replace(/\.[^/.]+$/, "");- fileTitle.textContent = nameWithoutExt;-- // File extension badge- const fileExtension = document.createElement("div");- fileExtension.classList.add("file-extension");- fileExtension.textContent = displayInfo.extension;-+ fileTitle.textContent = displayInfo.filename;+attachmentDiv.appendChild(fileTitle);- attachmentDiv.appendChild(fileExtension);}-+ attachmentDiv.addEventListener('click', displayInfo.clickHandler);attachmentsContainer.appendChild(attachmentDiv);});@@ -743,8 +677,6 @@ function drawKvps(container, kvps, latex) {});} else {const pre = document.createElement("pre");- // pre.classList.add("kvps-val");- // if (row.classList.contains("msg-thoughts")) {const span = document.createElement("span");span.innerHTML = convertHTML(value);pre.appendChild(span);@@ -766,17 +698,7 @@ function drawKvps(container, kvps, latex) {}}}- // } else {- // pre.textContent = value;- // // Add click handler- // pre.addEventListener("click", () => {- // copyText(value, pre);- // });-- // td.appendChild(pre);- // addCopyButtonToElement(row);- // }}container.appendChild(table);}@@ -896,32 +818,4 @@ function adjustMarkdownRender(element) {el.parentNode.insertBefore(wrapper, el);wrapper.appendChild(el);});-}--// function convertPathsToLinksInHtml(htmlString) {-// // 1. Parse the input safely-// const wrapper = document.createElement("div");-// wrapper.innerHTML = htmlString;--// // 2. Depth-first walk-// function walk(node) {-// // Skip <script> and <style> blocks entirely-// if (node.nodeName === "SCRIPT" || node.nodeName === "STYLE") return;--// if (node.nodeType === Node.TEXT_NODE) {-// const original = node.nodeValue;-// const replaced = convertPathsToLinks(original);-// if (replaced !== original) {-// // Turn the replacement HTML string into real nodes-// const frag = document.createRange().createContextualFragment(replaced);-// node.replaceWith(frag);-// }-// } else {-// // Recurse into children-// for (const child of Array.from(node.childNodes)) walk(child);-// }-// }--// walk(wrapper);-// return wrapper.innerHTML;-// }+}\ No newline at end of filediff --git a/webui/js/speech.js b/webui/js/speech.jsindex db586b5fb..040d0b783 100644--- a/webui/js/speech.js+++ b/webui/js/speech.js@@ -1,5 +1,6 @@// import { pipeline, read_audio } from '../[email protected]';import { updateChatInput, sendMessage } from "../index.js";+import { fetchApi } from "./api.js";const microphoneButton = document.getElementById("microphone-button");let microphoneInput = null;@@ -400,24 +401,34 @@ class Speech {}stripEmojis(str) {- return str- .replace(- /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,- ""- )- .replace(/\s+/g, " ")- .trim();+ // Remove emojis+ return str.replace(+ /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,+ ""+ );+ }++ normalizeWhitespace(str) {+ // Replace multiple spaces with a single space while preserving newlines+ str = str.split('\n').map(line => {+ return line.replace(/\s+/g, ' ').trim();+ }).join('\n');++ return str.trim();}speak(text) {- console.log("Speaking:", text);+ console.log("Starting speak:", text);// Stop any current utterancethis.stop();- // Remove emojis and create a new utterance- text = this.stripEmojis(text);+ // Process text for speech synthesis+ text = this.stripEmojis(text); // remove emojis+ text = this.normalizeWhitespace(text); // normalize whitespace while preserving newlinestext = this.replaceURLs(text);text = this.replaceGuids(text);++ console.log("Speaking text:", text);this.utterance = new SpeechSynthesisUtterance(text);// Speak the new utterancediff --git a/webui/js/tunnel.js b/webui/js/tunnel.jsindex 68e737907..8e257e47b 100644--- a/webui/js/tunnel.js+++ b/webui/js/tunnel.js@@ -1,3 +1,7 @@+++import { fetchApi } from "./api.js";+// Tunnel settings for the Settings modaldocument.addEventListener('alpine:init', () => {Alpine.data('tunnelSettings', () => ({