From fc3980dadd1f7a4f111402c2ad28221c12664e6b Mon Sep 17 00:00:00 2001 From: Daniel Liljeberg Date: Wed, 20 May 2026 01:00:32 +0200 Subject: [PATCH] fix: inject text-file content into chat completions messages (#9896) Non-image/non-audio file attachments (txt, md, csv, json) were being stored in the 'files' metadata field but never added to the message content array sent to /v1/chat/completions. Images and audio correctly received content blocks; files did not. Fix: push a text content block into messageContent when textContent is present, matching the pattern used for image_url and audio_url. Also fixes Home.jsx addFiles which never called file.text() at all, meaning files attached on the home screen had empty textContent even before reaching useChat.js. Note: PDF files use file.text() which returns raw bytes rather than parsed text. Proper PDF support would require PDF.js or server-side extraction and is not part of this fix. Signed-off-by: Daniel Liljeberg --- core/http/react-ui/src/hooks/useChat.js | 12 +++++++++--- core/http/react-ui/src/pages/Home.jsx | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/http/react-ui/src/hooks/useChat.js b/core/http/react-ui/src/hooks/useChat.js index 30538ed12..43a869653 100644 --- a/core/http/react-ui/src/hooks/useChat.js +++ b/core/http/react-ui/src/hooks/useChat.js @@ -218,9 +218,15 @@ export function useChat(initialModel = '') { }) userFiles.push({ name: file.name, type: 'audio' }) } else { - // Text/PDF files - append to content - userFiles.push({ name: file.name, type: 'file', content: file.textContent || '' }) - } + // Text/PDF files - append to content + if (file.textContent) { + messageContent.push({ + type: 'text', + text: `\n\n--- File: ${file.name} ---\n${file.textContent}\n--- End of ${file.name} ---`, + }) + } + userFiles.push({ name: file.name, type: 'file', content: file.textContent || '' }) + } } } else { messageContent = content diff --git a/core/http/react-ui/src/pages/Home.jsx b/core/http/react-ui/src/pages/Home.jsx index fa560a8ca..f57dfb42d 100644 --- a/core/http/react-ui/src/pages/Home.jsx +++ b/core/http/react-ui/src/pages/Home.jsx @@ -161,7 +161,11 @@ export default function Home() { const newFiles = [] for (const file of fileList) { const base64 = await fileToBase64(file) - newFiles.push({ name: file.name, type: file.type, base64 }) + const entry = { name: file.name, type: file.type, base64 } + if (!file.type.startsWith('image/') && !file.type.startsWith('audio/')) { + entry.textContent = await file.text().catch(() => '') + } + newFiles.push(entry) } setter(prev => [...prev, ...newFiles]) }, [])