From fe597c1cdf59f7193aeda9f7d226093e7db3860e Mon Sep 17 00:00:00 2001 From: george-andraws <96165956+george-andraws@users.noreply.github.com> Date: Mon, 25 May 2026 09:12:14 -0700 Subject: [PATCH] fix chat upload attachment paths --- static/messages.js | 2 +- tests/test_chat_upload_attachment_paths.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/test_chat_upload_attachment_paths.py diff --git a/static/messages.js b/static/messages.js index f10b5d9d..4da8e3a5 100644 --- a/static/messages.js +++ b/static/messages.js @@ -433,7 +433,7 @@ async function send(){ setComposerStatus(''); const uploadedNames=uploaded.map(u=>u.name||u); - const uploadedPaths=uploaded.map(u=>u&&u.is_image?(u.name||u.filename||u):(u.path||u.name||u)); + const uploadedPaths=uploaded.map(u=>u&&u.path?u.path:(u&&u.name?u.name:(u&&u.filename?u.filename:u))); let msgText=text; if(uploaded.length&&!msgText)msgText=`I've uploaded ${uploaded.length} file(s): ${uploadedPaths.join(', ')}`; else if(uploaded.length)msgText=`${text}\n\n[Attached files: ${uploadedPaths.join(', ')}]`; diff --git a/tests/test_chat_upload_attachment_paths.py b/tests/test_chat_upload_attachment_paths.py new file mode 100644 index 00000000..6e0fba38 --- /dev/null +++ b/tests/test_chat_upload_attachment_paths.py @@ -0,0 +1,21 @@ +"""Regression coverage for WebUI chat upload path handoff.""" +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] +MESSAGES_JS = ROOT / "static" / "messages.js" + + +def test_image_uploads_use_server_path_in_attached_files_context(): + """The agent text context must include real uploaded paths for images. + + /api/upload returns an absolute attachment path. The browser also sends the + structured attachment payload to /api/chat/start, but text/tool-mode agents + still rely on the literal ``[Attached files: ...]`` suffix. Images must not + be downgraded to bare filenames there, otherwise tools like vision_analyze + cannot open the uploaded file immediately. + """ + src = MESSAGES_JS.read_text(encoding="utf-8") + + assert "uploadedPaths=uploaded.map(u=>u&&u.is_image?" not in src + assert "uploadedPaths=uploaded.map(u=>u&&u.path?u.path" in src