From 3111d1bf610a96eef849bf0ac73352aa812c3f9f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 29 Aug 2025 02:07:31 +0400 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 86d86a9ae4..284ddd7ad1 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1396,10 +1396,10 @@ const submitPrompt = async (userPrompt, { _raw = false } = {}) => { console.log('submitPrompt', userPrompt, $chatId); - const messages = createMessagesList(history, history.currentId); const _selectedModels = selectedModels.map((modelId) => $models.map((m) => m.id).includes(modelId) ? modelId : '' ); + if (JSON.stringify(selectedModels) !== JSON.stringify(_selectedModels)) { selectedModels = _selectedModels; } @@ -1413,15 +1413,6 @@ return; } - if (messages.length != 0 && messages.at(-1).done != true) { - // Response not done - return; - } - if (messages.length != 0 && messages.at(-1).error && !messages.at(-1).content) { - // Error in response - toast.error($i18n.t(`Oops! There was an error in the previous response.`)); - return; - } if ( files.length > 0 && files.filter((file) => file.type !== 'image' && file.status === 'uploading').length > 0 @@ -1431,6 +1422,7 @@ ); return; } + if ( ($config?.file?.max_count ?? null) !== null && files.length + chatFiles.length > $config?.file?.max_count @@ -1443,9 +1435,25 @@ return; } + if (history?.currentId) { + const lastMessage = history.messages[history.currentId]; + if (lastMessage.done != true) { + // Response not done + return; + } + + if (lastMessage.error && !lastMessage.content) { + // Error in response + toast.error($i18n.t(`Oops! There was an error in the previous response.`)); + return; + } + } + messageInput?.setText(''); prompt = ''; + const messages = createMessagesList(history, history.currentId); + // Reset chat input textarea if (!($settings?.richTextInput ?? true)) { const chatInputElement = document.getElementById('chat-input');