We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e9eac4 commit 9e35c4cCopy full SHA for 9e35c4c
1 file changed
src/lib/components/chat/Chat.svelte
@@ -1925,6 +1925,17 @@
1925
1926
// Create user message
1927
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
1939
let userMessage = {
1940
id: userMessageId,
1941
parentId: history.currentId ?? null,
0 commit comments