🐛 fix: fix when use branch topic,the branch index error problem (#11049)

fix: fix when use branch topic,the branch index error problem
This commit is contained in:
Shinji-Li
2025-12-30 16:25:01 +08:00
committed by GitHub
parent 5e10ac8d88
commit 34b5a32aa1
@@ -276,8 +276,15 @@ export const generationSlice: StateCreator<
});
try {
// Calculate next branch index by counting children of this user message
// We need to count how many assistant messages have this user message as parent
const { dbMessages } = get();
const childrenCount = dbMessages.filter((m) => m.parentId === messageId).length;
// New branch index = current children count (since index is 0-based)
const nextBranchIndex = childrenCount;
// Switch to a new branch (pass operationId for correct context in optimistic update)
await chatStore.switchMessageBranch(messageId, item.branch ? item.branch.count : 1, {
await chatStore.switchMessageBranch(messageId, nextBranchIndex, {
operationId,
});