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:
1 parent
5be1e589f2
commit
6646f5fbee
53 files changed
+1972
-847
No files matched your search
@@ -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;
|
||||
|
||||
@@ -538,6 +538,7 @@ function randomHeroGreetingKey(): (typeof HERO_GREETING_KEYS)[number] {
|
||||
}
|
||||
|
||||
interface PendingFirstMessage {
|
||||
finish?: (accepted: boolean) => void;
|
||||
content: string;
|
||||
images?: SendAttachment[];
|
||||
options?: SendOptions;
|
||||
@@ -1442,6 +1443,9 @@ export function ThreadShell({
|
||||
activeViewportTurnByChatIdRef.current.set(chatId, submitted.turnId);
|
||||
setSubmittedViewportTurnId(submitted.turnId);
|
||||
}
|
||||
if (submitted?.delivery) {
|
||||
void submitted.delivery.then(() => pending.finish?.(true), () => pending.finish?.(false));
|
||||
} else pending.finish?.(submitted !== null);
|
||||
setBooting(false);
|
||||
}, [chatId, pendingFirstTargetChatId, send]);
|
||||
|
||||
@@ -1489,7 +1493,9 @@ export function ThreadShell({
|
||||
async (content: string, images?: SendAttachment[], options?: SendOptions) => {
|
||||
if (booting) return false;
|
||||
setBooting(true);
|
||||
pendingFirstRef.current = { content, images, options: withWorkspaceScope(options) };
|
||||
let finish!: (accepted: boolean) => void;
|
||||
const delivery = new Promise<boolean>((resolve) => { finish = resolve; });
|
||||
pendingFirstRef.current = { content, images, options: withWorkspaceScope(options), finish };
|
||||
setPendingFirstTargetChatId(null);
|
||||
const newId = await onCreateChat?.(workspaceScope, content, localModelPreset);
|
||||
if (!newId) {
|
||||
@@ -1502,7 +1508,7 @@ export function ThreadShell({
|
||||
await client.sendSystemCommand(newId, `/model ${localModelPreset}`).catch(() => {});
|
||||
}
|
||||
setPendingFirstTargetChatId(newId);
|
||||
return true;
|
||||
return delivery;
|
||||
},
|
||||
[booting, client, localModelPreset, onCreateChat, withWorkspaceScope, workspaceScope],
|
||||
);
|
||||
@@ -1519,7 +1525,7 @@ export function ThreadShell({
|
||||
activeViewportTurnByChatIdRef.current.set(chatId, submitted.turnId);
|
||||
setSubmittedViewportTurnId(submitted.turnId);
|
||||
}
|
||||
return submitted !== null;
|
||||
return submitted?.delivery ? submitted.delivery.then(() => true) : submitted !== null;
|
||||
},
|
||||
[chatId, send, withWorkspaceScope],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user