From 486c004cbb43f15d5c3e31561f51f22effff1f6c Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 15 Mar 2026 18:49:49 -0500 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index efd4d9141..41b25606a 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1340,18 +1340,6 @@ } taskIds = null; - - // Process message queue - combine all queued messages and submit at once - if (messageQueue.length > 0) { - const combinedPrompt = messageQueue.map((m) => m.prompt).join('\n\n'); - const combinedFiles = messageQueue.flatMap((m) => m.files); - messageQueue = []; - - // Set the files and submit - files = combinedFiles; - await tick(); - await submitPrompt(combinedPrompt); - } }; const chatActionHandler = async (_chatId, actionId, modelId, responseMessageId, event = null) => { @@ -1693,12 +1681,26 @@ scrollToBottom(); } - await chatCompletedHandler( + // Fire-and-forget: run chatCompletedHandler for background work + // (outlet filters, chat save, title gen, follow-ups, tags) + // without blocking the user from sending new messages. + chatCompletedHandler( chatId, message.model, message.id, createMessagesList(history, message.id) ); + + // Process message queue immediately after main response finishes + if (messageQueue.length > 0) { + const combinedPrompt = messageQueue.map((m) => m.prompt).join('\n\n'); + const combinedFiles = messageQueue.flatMap((m) => m.files); + messageQueue = []; + + files = combinedFiles; + await tick(); + await submitPrompt(combinedPrompt); + } } console.log(data); @@ -1755,8 +1757,12 @@ return; } - // Check if there are pending tasks (more reliable than lastMessage.done) - if (taskIds !== null && taskIds.length > 0) { + // Check if the assistant is still generating the main response + // (don't block on background tasks like title gen, follow-ups, tags) + const lastMessage = history.currentId ? history.messages[history.currentId] : null; + const isGenerating = lastMessage && lastMessage.role === 'assistant' && !lastMessage.done; + + if (isGenerating) { if ($settings?.enableMessageQueue ?? true) { // Queue the message const _files = structuredClone(files); @@ -1781,9 +1787,9 @@ } if (history?.currentId) { - const lastMessage = history.messages[history.currentId]; + const currentMessage = history.messages[history.currentId]; - if (lastMessage.error && !lastMessage.content) { + if (currentMessage.error && !currentMessage.content) { // Error in response toast.error($i18n.t(`Oops! There was an error in the previous response.`)); return;