Skip to content

Commit 9e35c4c

Browse files
committed
fix: recover null currentId on message submit
1 parent 1e9eac4 commit 9e35c4c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/lib/components/chat/Chat.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,17 @@
19251925
19261926
// Create user message
19271927
let userMessageId = uuidv4();
1928+
1929+
// Recover currentId if it was unexpectedly cleared in an existing chat
1930+
if (!history.currentId && Object.keys(history.messages ?? {}).length > 0 && $chatId) {
1931+
const allParents = new Set(
1932+
Object.values(history.messages).map((m) => m.parentId).filter(Boolean)
1933+
);
1934+
const leaves = Object.values(history.messages).filter((m) => !allParents.has(m.id));
1935+
history.currentId =
1936+
leaves.sort((a, b) => (b.timestamp ?? 0) - (a.timestamp ?? 0))[0]?.id ?? null;
1937+
}
1938+
19281939
let userMessage = {
19291940
id: userMessageId,
19301941
parentId: history.currentId ?? null,

0 commit comments

Comments
 (0)