Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

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

Shinji-Li34b5a32aa1f4
diff --git a/src/features/Conversation/store/slices/generation/action.ts b/src/features/Conversation/store/slices/generation/action.ts
index e6895b2cc64..cc363315d95 100644
--- a/src/features/Conversation/store/slices/generation/action.ts
+++ b/src/features/Conversation/store/slices/generation/action.ts
@@ -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,
});