From f7767d6be774720e16265c6d016bf6a24a1a8759 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 13 Aug 2026 22:08:42 -0600 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 1ca2e45d6c..f63f17bb19 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -3668,7 +3668,13 @@ }; const stopResponse = async (processQueue = true) => { - if (taskIds) { + const responseMessage = history.currentId ? history.messages[history.currentId] : null; + const hasTaskIds = (taskIds?.length ?? 0) > 0; + const hasPendingAssistantResponse = + !!$chatId && + (hasTaskIds || (responseMessage?.role === 'assistant' && responseMessage?.done !== true)); + + if (hasTaskIds || hasPendingAssistantResponse) { if ($chatId) { await stopTasksByChatId(localStorage.token, $chatId).catch((error) => { toast.error(`${error}`); @@ -3685,15 +3691,16 @@ taskIds = null; - const responseMessage = history.messages[history.currentId]; // Set all response messages to done - if (responseMessage.parentId && history.messages[responseMessage.parentId]) { + if (responseMessage?.parentId && history.messages[responseMessage.parentId]) { for (const messageId of history.messages[responseMessage.parentId].childrenIds) { history.messages[messageId].done = true; } } - history.messages[history.currentId] = responseMessage; + if (responseMessage) { + history.messages[history.currentId] = responseMessage; + } if (shouldAutoScrollResponse()) { scrollToBottom();