Skip to content

Commit edf2c6c

Browse files
committed
refac
1 parent 0eba3df commit edf2c6c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@
603603
} else if (type === 'chat:active') {
604604
if (!data?.active) {
605605
taskIds = null;
606+
if (chatIdProp && !$temporaryChatEnabled && hasPendingAssistantLeaf()) {
607+
await loadChat();
608+
}
606609
}
607610
} else if (type === 'chat:completion') {
608611
chatCompletionEventHandler(data, message, event.chat_id);
@@ -866,13 +869,18 @@
866869
} catch {}
867870
};
868871
872+
const hasPendingAssistantLeaf = () =>
873+
Object.values(history.messages).some(
874+
(message) =>
875+
message?.role === 'assistant' && !message.done && (message.childrenIds?.length ?? 0) === 0
876+
);
877+
869878
const handleSocketConnect = async () => {
870879
if (!chatIdProp || $temporaryChatEnabled) {
871880
return;
872881
}
873882
874-
const currentMessage = history.currentId ? history.messages[history.currentId] : null;
875-
if (currentMessage?.role !== 'assistant' || currentMessage.done) {
883+
if (!hasPendingAssistantLeaf()) {
876884
return;
877885
}
878886

0 commit comments

Comments
 (0)