From edf2c6c8f76e7f6a5917e991f371a604adc34c5f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 29 Jun 2026 05:23:20 -0500 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 5209d946dd..aa74ef915d 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -603,6 +603,9 @@ } else if (type === 'chat:active') { if (!data?.active) { taskIds = null; + if (chatIdProp && !$temporaryChatEnabled && hasPendingAssistantLeaf()) { + await loadChat(); + } } } else if (type === 'chat:completion') { chatCompletionEventHandler(data, message, event.chat_id); @@ -866,13 +869,18 @@ } catch {} }; + const hasPendingAssistantLeaf = () => + Object.values(history.messages).some( + (message) => + message?.role === 'assistant' && !message.done && (message.childrenIds?.length ?? 0) === 0 + ); + const handleSocketConnect = async () => { if (!chatIdProp || $temporaryChatEnabled) { return; } - const currentMessage = history.currentId ? history.messages[history.currentId] : null; - if (currentMessage?.role !== 'assistant' || currentMessage.done) { + if (!hasPendingAssistantLeaf()) { return; }