fix(webui): upload TUI and WebUI attachments over binary HTTP (#5980)

* feat(webui): add bounded binary attachment staging

* feat(webui): bridge binary HTTP bodies alongside websocket listener

* fix(webui): deliver attachments over authenticated binary HTTP

* fix(webui): bound incomplete upload headers and preserve staging markers

* test: reflect aiohttp runtime dependency for binary uploads

* fix(webui): relay binary uploads and retain rejected drafts

* refactor(webui): remove obsolete attachment transport errors

* refactor(websocket): own binary attachment transport

* fix(websocket): allow bounded uploads over slow connections

* test(webui): restore upload timeout before retry

* docs(websocket): focus attachment guide on client usage
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-08 11:55:13 +08:00
1 parent 5be1e589f2
commit 6646f5fbee
53 files changed
+1972 -847

No files matched your search

+24 -17
View File
@@ -1099,11 +1099,9 @@ export function ThreadComposer({
? "Empty files cannot be attached"
: reason === "total_too_large"
? "Attachments are too large together — remove some or use smaller files"
: reason === "transport_too_large"
? "This attachment would exceed the gateway transport limit"
: reason === "too_large"
? "File is too large"
: "Unsupported file type";
: reason === "too_large"
? "File is too large"
: "Unsupported file type";
return t(key, { max: maxAttachments, defaultValue: fallback });
},
[maxAttachments, t],
@@ -1965,6 +1963,16 @@ export function ThreadComposer({
});
}, []);
const observeQueuedSend = useCallback((prompt: QueuedPrompt, result: void | boolean | Promise<void | boolean>) => {
const restore = (error?: unknown) => {
skipNextQueuedFlushRef.current = true;
setQueuedPrompts((items) => items.some((item) => item.id === prompt.id) ? items : [prompt, ...items]);
setInlineError(error instanceof Error ? error.message : "Message not sent; queued draft retained");
};
if (result instanceof Promise) void result.then((accepted) => { if (accepted === false) restore(); }).catch(restore);
else if (result === false) restore();
}, []);
const sendQueuedPrompt = useCallback(
(prompt: QueuedPrompt) => {
secondEnterPromptIdRef.current = null;
@@ -1985,11 +1993,11 @@ export function ThreadComposer({
...(isStreaming ? { continueActiveTurn: true } : {}),
}
: undefined;
onSend(text, queuedImages, options);
observeQueuedSend(prompt, onSend(text, queuedImages, options));
}
requestAnimationFrame(() => textareaRef.current?.focus());
},
[isStreaming, onSend],
[isStreaming, onSend, observeQueuedSend],
);
const sendNextQueuedPrompt = useCallback(() => {
@@ -2011,12 +2019,13 @@ export function ThreadComposer({
: {}),
}
: undefined;
if (queuedImages?.length && options) onSend(nextPrompt.text.trim(), queuedImages, options);
else if (queuedImages?.length) onSend(nextPrompt.text.trim(), queuedImages);
else if (options) onSend(nextPrompt.text.trim(), undefined, options);
else onSend(nextPrompt.text.trim());
const result = queuedImages?.length && options ? onSend(nextPrompt.text.trim(), queuedImages, options)
: queuedImages?.length ? onSend(nextPrompt.text.trim(), queuedImages)
: options ? onSend(nextPrompt.text.trim(), undefined, options)
: onSend(nextPrompt.text.trim());
observeQueuedSend(nextPrompt, result);
requestAnimationFrame(() => textareaRef.current?.focus());
}, [onSend, queuedPrompts]);
}, [onSend, queuedPrompts, observeQueuedSend]);
useEffect(() => {
const previous = previousQueueRunRef.current;
@@ -2057,10 +2066,8 @@ export function ThreadComposer({
setInlineError(textTooLargeMessage());
return;
}
// Share the same ``data:`` URL with both the wire payload and the
// optimistic bubble preview: data URLs are self-contained (no blob
// lifetime, safe under React StrictMode double-mount) and keep the bubble
// in sync with whatever the backend actually sees.
// Keep self-contained local previews across drafts and optimistic bubbles.
// The client decodes these to HTTP binary; WS messages contain only refs.
const payload: SendAttachment[] | undefined =
readyImages.length > 0
? readyImages.map((img) => ({
@@ -2142,7 +2149,7 @@ export function ThreadComposer({
if (accepted !== false) finishSend();
})
.catch((error: unknown) => {
console.error("Failed to send message", error);
setInlineError(error instanceof Error ? error.message : "Failed to send message");
})
.finally(() => setSendPending(false));
return;