diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index a423b1694..2b50beb4d 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1103,7 +1103,7 @@ if (history.currentId) { for (const message of Object.values(history.messages)) { - if (message.role === 'assistant') { + if (message && message.role === 'assistant') { message.done = true; } } @@ -2084,8 +2084,10 @@ const responseMessage = history.messages[history.currentId]; // Set all response messages to done - for (const messageId of history.messages[responseMessage.parentId].childrenIds) { - history.messages[messageId].done = true; + if (responseMessage.parentId && history.messages[responseMessage.parentId]) { + for (const messageId of history.messages[responseMessage.parentId].childrenIds) { + history.messages[messageId].done = true; + } } history.messages[history.currentId] = responseMessage; diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index a019648a2..20579689a 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -77,7 +77,15 @@ let _messages = []; let message = history.messages[history.currentId]; + const visitedMessageIds = new Set(); + while (message && (messagesCount !== null ? _messages.length <= messagesCount : true)) { + if (visitedMessageIds.has(message.id)) { + console.warn('Circular dependency detected in message history', message.id); + break; + } + visitedMessageIds.add(message.id); + _messages.unshift({ ...message }); message = message.parentId !== null ? history.messages[message.parentId] : null; } diff --git a/src/lib/components/chat/Overview/View.svelte b/src/lib/components/chat/Overview/View.svelte index dc1276abe..b3164e6e7 100644 --- a/src/lib/components/chat/Overview/View.svelte +++ b/src/lib/components/chat/Overview/View.svelte @@ -75,6 +75,8 @@ Object.keys(history.messages).forEach((id) => { const message = history.messages[id]; + if (!message) return; + const level = message.parentId ? (positionMap.get(message.parentId)?.level ?? -1) + 1 : 0; if (!layerWidths[level]) layerWidths[level] = 0; @@ -88,6 +90,8 @@ // Adjust positions based on siblings count to centralize vertical spacing Object.keys(history.messages).forEach((id) => { const pos = positionMap.get(id); + if (!pos) return; + const x = direction === 'vertical' ? pos.position * siblingOffset : pos.level * levelOffset; const y = direction === 'vertical' ? pos.level * levelOffset : pos.position * siblingOffset;