diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 512014cb4..9938d2b92 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -51,34 +51,43 @@ } }; - const confirmEditMessage = async (messageId, content) => { - let userPrompt = content; - let userMessageId = uuidv4(); + const confirmEditMessage = async (messageId, content, submit = true) => { + if (submit) { + let userPrompt = content; + let userMessageId = uuidv4(); - let userMessage = { - id: userMessageId, - parentId: history.messages[messageId].parentId, - childrenIds: [], - role: 'user', - content: userPrompt, - ...(history.messages[messageId].files && { files: history.messages[messageId].files }), - models: selectedModels - }; + let userMessage = { + id: userMessageId, + parentId: history.messages[messageId].parentId, + childrenIds: [], + role: 'user', + content: userPrompt, + ...(history.messages[messageId].files && { files: history.messages[messageId].files }), + models: selectedModels + }; - let messageParentId = history.messages[messageId].parentId; + let messageParentId = history.messages[messageId].parentId; - if (messageParentId !== null) { - history.messages[messageParentId].childrenIds = [ - ...history.messages[messageParentId].childrenIds, - userMessageId - ]; + if (messageParentId !== null) { + history.messages[messageParentId].childrenIds = [ + ...history.messages[messageParentId].childrenIds, + userMessageId + ]; + } + + history.messages[userMessageId] = userMessage; + history.currentId = userMessageId; + + await tick(); + await sendPrompt(userPrompt, userMessageId); + } else { + history.messages[messageId].content = content; + await tick(); + await updateChatById(localStorage.token, chatId, { + messages: messages, + history: history + }); } - - history.messages[userMessageId] = userMessage; - history.currentId = userMessageId; - - await tick(); - await sendPrompt(userPrompt, userMessageId); }; const updateChatMessages = async () => { diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index 67f682520..08dbd34e6 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -45,8 +45,8 @@ messageEditTextAreaElement?.focus(); }; - const editMessageConfirmHandler = async () => { - confirmEditMessage(message.id, editedContent); + const editMessageConfirmHandler = async (submit = true) => { + confirmEditMessage(message.id, editedContent, submit); edit = false; editedContent = ''; @@ -140,26 +140,40 @@ }} /> -