From c79c64aad01db85abf6206f795e73c8e2e29a0cd Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Thu, 27 Aug 2026 09:43:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(sidebar):=20=E5=88=9B=E5=BB=BA=E6=96=B0?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E5=90=8E=E4=BE=A7=E8=BE=B9=E6=A0=8F=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BF=87=E6=BB=A4=E5=99=A8=E4=B8=8D=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E8=87=B4=E5=A4=9A=E6=99=BA=E8=83=BD=E4=BD=93=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E9=94=99=E4=BD=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - send.ts:占位对话按新建类型插入对应过滤器缓存并同步切换 sidebarConversationType - mode.ts:输入栏类型选择器切换时联动 setSidebarConversationType(纯本地零请求) --- static/src/app/methods/message/send.ts | 79 ++++++++++++++++---------- static/src/app/methods/ui/mode.ts | 15 ++++- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/static/src/app/methods/message/send.ts b/static/src/app/methods/message/send.ts index cf15366b..8a02865d 100644 --- a/static/src/app/methods/message/send.ts +++ b/static/src/app/methods/message/send.ts @@ -286,12 +286,6 @@ export const sendMethods = { targetConversationId = createResult.conversation_id; // 创建即定型:落地对话类型(与后端 metadata 保持一致) this.currentConversationType = isMultiAgent ? 'multi_agent' : 'normal'; - try { - const { useConversationStore } = await import('../../../stores/conversation'); - useConversationStore().$patch({ multiAgentMode: isMultiAgent }); - } catch (_e) { - // ignore - } this.skipConversationHistoryReload = true; this.currentConversationId = targetConversationId; this.currentConversationTitle = '新对话'; @@ -302,36 +296,61 @@ export const sendMethods = { total_messages: 0, total_tools: 0 }; - this.conversations.splice( - 0, - this.conversations.length, - newPlaceholder, - ...this.conversations.filter((conv) => conv && conv.id !== targetConversationId) - ); - - // 分组视图下同步到当前工作区 + // 新建对话的类型同时决定侧边栏过滤器目标类型 + const targetType = isMultiAgent ? 'multi_agent' : 'normal'; try { const { useConversationStore } = await import('../../../stores/conversation'); const conversationStore = useConversationStore(); - const currentWorkspaceId = this.currentHostWorkspaceId; - if (currentWorkspaceId) { - conversationStore.ensureWorkspaceGroup(currentWorkspaceId); - const group = conversationStore.workspaceGroups.find( - (g: any) => g.workspaceId === currentWorkspaceId - ); - if (group) { - group.conversations.splice( - 0, - group.conversations.length, - newPlaceholder, - ...group.conversations.filter((conv: any) => conv.id !== targetConversationId) + conversationStore.$patch({ multiAgentMode: isMultiAgent }); + + // 占位对话按「新建类型」插入对应过滤器缓存(而非当前过滤器类型的缓存), + // 并同步切换侧边栏「智能体/多智能体」过滤器,避免创建后错位显示(需刷新才归位)。 + const targetCache = conversationStore.conversationsCache[targetType]; + targetCache.list.splice( + 0, + targetCache.list.length, + newPlaceholder, + ...targetCache.list.filter((conv: any) => conv && conv.id !== targetConversationId) + ); + if (conversationStore.sidebarConversationType !== targetType) { + conversationStore.setSidebarConversationType(targetType); + } + + // 分组视图下同步到当前工作区(同样按目标类型缓存落位) + try { + const currentWorkspaceId = this.currentHostWorkspaceId; + if (currentWorkspaceId) { + conversationStore.ensureWorkspaceGroup(currentWorkspaceId); + const group = conversationStore.workspaceGroups.find( + (g: any) => g.workspaceId === currentWorkspaceId ); - group.expanded = true; - group.visibleOffset = 0; - group.visibleLimit = 5; + if (group) { + const groupList = group.conversationsByType?.[targetType]; + if (groupList) { + groupList.splice( + 0, + groupList.length, + newPlaceholder, + ...groupList.filter((conv: any) => conv && conv.id !== targetConversationId) + ); + } + group.expanded = true; + group.visibleOffset = 0; + group.visibleLimit = 5; + } + } + } catch (_err) { + // ignore + } + + // 目标类型缓存从未加载过时走切换补载:placeholder 会被真实列表全量覆盖, + // 新创建对话在后端 updated_at 最新仍在顶部,不会重复也不会丢失。 + if (!conversationStore.conversationsCache[targetType].loaded) { + if (typeof this.handleSidebarConversationTypeChange === 'function') { + this.handleSidebarConversationTypeChange(targetType).catch(() => {}); } } - } catch (_err) { + } catch (_e) { // ignore } diff --git a/static/src/app/methods/ui/mode.ts b/static/src/app/methods/ui/mode.ts index 1222843b..159bcd3f 100644 --- a/static/src/app/methods/ui/mode.ts +++ b/static/src/app/methods/ui/mode.ts @@ -138,11 +138,24 @@ export const modeMethods = { this.inputCloseMenus?.(); } }, - handleSelectNewConversationType(type) { + async handleSelectNewConversationType(type) { const normalized = type === 'multi_agent' ? 'multi_agent' : 'agent'; this.newConversationType = normalized; persistNewConversationType(normalized); this.agentTypeMenuOpen = false; + // 选择即联动:同步切换侧边栏「智能体/多智能体」过滤器(纯本地引用交换、零请求)。 + // 选择器仅在空对话可用(有对话时禁用展示态),此处置空判断作防御; + // 进入已有对话后两个状态保持解耦,互不干扰。 + if (!this.currentConversationId) { + try { + const { useConversationStore } = await import('../../../stores/conversation'); + useConversationStore().setSidebarConversationType( + normalized === 'multi_agent' ? 'multi_agent' : 'normal' + ); + } catch (_e) { + // ignore + } + } }, toggleModeMenu() { if (!this.isConnected || this.streamingMessage) {