From 7708ee851a1d6745a5ee3c106a0dd9f728bca732 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 21 Oct 2026 09:19:18 +0900 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 61 ++++++------------- .../chat/FileNav/FileEntryRow.svelte | 4 +- 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 15f1a9ef8c..366c0770f9 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -3210,29 +3210,8 @@ const chatActionHandler = async (_chatId, actionId, modelId, responseMessageId, event = null) => { const messages = createMessagesList(history, responseMessageId); - let changed = false; - const actionSocket = $socket; - const onEvent = (event) => { - if (event.chat_id !== _chatId || event.message_id !== responseMessageId) return; - const { type, data } = event.data ?? {}; - // These events are UI-only or already persisted by get_event_emitter. - if ( - [ - 'notification', - 'confirmation', - 'input', - 'status', - 'message', - 'replace', - 'files', - 'embeds' - ].includes(type) || - (['source', 'citation'].includes(type) && data?.type == null) - ) - return; - changed = true; - }; - actionSocket?.on('events', onEvent); + // Actions can also update this message through events. + const original = structuredClone(history.messages[responseMessageId]); const res = await chatAction(localStorage.token, actionId, { model: modelId, @@ -3249,19 +3228,17 @@ chat_id: _chatId, session_id: $socket?.id, id: responseMessageId - }) - .catch((error) => { - toast.error(`${error}`); - if ($chatId === _chatId && history.messages[responseMessageId]) { - history.messages[responseMessageId].error = { content: error }; - changed = true; - } - return null; - }) - .finally(() => actionSocket?.off('events', onEvent)); + }).catch((error) => { + toast.error(`${error}`); + if ($chatId === _chatId && history.messages[responseMessageId]) { + history.messages[responseMessageId].error = { content: error }; + } + return null; + }); if ($chatId !== _chatId) return; + let changed = !equal(original, history.messages[responseMessageId]); if (res?.messages) { // Update chat history with the new messages for (const message of res.messages) { @@ -3282,17 +3259,15 @@ } } - if (changed) { - if (!$temporaryChatEnabled) { - chat = await updateChatById(localStorage.token, _chatId, { - models: selectedModels, - messages: createMessagesList(history, responseMessageId), - history: history, - files: chatFiles - }); + if (changed && !$temporaryChatEnabled) { + chat = await updateChatById(localStorage.token, _chatId, { + models: selectedModels, + messages: createMessagesList(history, responseMessageId), + history: history, + files: chatFiles + }); - await refreshChatList(localStorage.token); - } + await refreshChatList(localStorage.token); } }; diff --git a/src/lib/components/chat/FileNav/FileEntryRow.svelte b/src/lib/components/chat/FileNav/FileEntryRow.svelte index 6804709355..255f8bd26b 100644 --- a/src/lib/components/chat/FileNav/FileEntryRow.svelte +++ b/src/lib/components/chat/FileNav/FileEntryRow.svelte @@ -318,10 +318,10 @@ { if (e.key === 'Enter') { e.preventDefault();