diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 4b4fab6e1..242c016c1 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -985,19 +985,18 @@ } }; - const addMessages = async ({ modelId, messages }) => { + const addMessages = async ({ modelId, parentId, messages }) => { const model = $models.filter((m) => m.id === modelId).at(0); - const messageList = createMessagesList(history.currentId); - let parentMessage = messageList.length !== 0 ? messageList.at(-1) : null; - let parentId = parentMessage ? parentMessage.id : null; + let parentMessage = history.messages[parentId]; + let currentParentId = parentMessage ? parentMessage.id : null; for (const message of messages) { let messageId = uuidv4(); if (message.role === 'user') { const userMessage = { id: messageId, - parentId: parentId, + parentId: currentParentId, childrenIds: [], timestamp: Math.floor(Date.now() / 1000), ...message @@ -1010,11 +1009,11 @@ history.messages[messageId] = userMessage; parentMessage = userMessage; - parentId = messageId; + currentParentId = messageId; } else { const responseMessage = { id: messageId, - parentId: parentId, + parentId: currentParentId, childrenIds: [], done: true, model: model.id, @@ -1031,11 +1030,11 @@ history.messages[messageId] = responseMessage; parentMessage = responseMessage; - parentId = messageId; + currentParentId = messageId; } } - history.currentId = parentId; + history.currentId = currentParentId; await tick(); if (autoScroll) { diff --git a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte index a6ac48ce9..6b1c7b146 100644 --- a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte +++ b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte @@ -197,6 +197,7 @@ onAdd({ modelId: model, + parentId: id, messages: messages }); }; diff --git a/src/lib/components/chat/Messages/ContentRenderer.svelte b/src/lib/components/chat/Messages/ContentRenderer.svelte index e71df0636..40cf0352f 100644 --- a/src/lib/components/chat/Messages/ContentRenderer.svelte +++ b/src/lib/components/chat/Messages/ContentRenderer.svelte @@ -165,9 +165,9 @@ {id} model={model?.id} messages={createMessagesList(history, id)} - onAdd={({ modelId, messages }) => { - console.log(modelId, messages); - onAddMessages({ modelId, messages }); + onAdd={({ modelId, parentId, messages }) => { + console.log(modelId, parentId, messages); + onAddMessages({ modelId, parentId, messages }); closeFloatingButtons(); }} /> diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 33068880d..ae056531f 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -636,8 +636,8 @@ sourceButton.click(); } }} - onAddMessages={({ modelId, messages }) => { - addMessages({ modelId, messages }); + onAddMessages={({ modelId, parentId, messages }) => { + addMessages({ modelId, parentId, messages }); }} on:update={(e) => { const { raw, oldContent, newContent } = e.detail;