diff --git a/src/pages/Chat.vue b/src/pages/Chat.vue index 22b86f3..48efde1 100644 --- a/src/pages/Chat.vue +++ b/src/pages/Chat.vue @@ -285,12 +285,12 @@ async function setChatName(first_sentence: string) { } // Scroll to the bottom of the chat when new messages are added -async function scrollBottom() { +const scrollBottom = () => { scrollAreaRef.value?.lastElementChild?.scrollIntoView({ behavior: 'smooth', block: 'end', }); -} +}; // Generate a new response from the AI async function generatePersonaMessage() { @@ -445,8 +445,6 @@ async function sendMessage(content: string) { // Wipe the attachments // attachmentsRef.value = []; - nextTick(scrollBottom); - if (!content.trim()) return; if (content.trim() === '') return; @@ -495,12 +493,12 @@ async function setChat(chatId: string) { await setChatName(loadedChat.messages[0].content); } - // Determine if there are messages we need to respond to - // NOTE: this is assuming all chats should be initiated by the user - if (loadedChat.messages.length % 2 === 1) { + // Determine if there is a message we need to respond to + const lastMessage = loadedChat.messages.at(-1); + if (lastMessage?.author === 'user') { await generatePersonaMessage(); } - nextTick(scrollBottom); + scrollBottom(); } async function updateChatMessageContent(messageIndex: number, content: string, initialContent: string) {