From b940b23b91ab316e8cd978b5d3ad34c168c2697b Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Sun, 31 Aug 2025 12:22:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor(agent):=20=E4=BC=98=E5=8C=96=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E4=BD=93=E9=80=89=E6=8B=A9=E5=92=8C=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除未使用的侧边栏相关代码 修改默认智能体设置函数以接收agentId参数 优化AgentChatComponent的加载逻辑和监听处理 重构agent store的初始化流程并添加调试日志 --- web/src/components/AgentChatComponent.vue | 37 ++++++++++++++--------- web/src/stores/agent.js | 20 ++++++------ web/src/views/AgentSingleView.vue | 16 ---------- web/src/views/AgentView.vue | 29 +++--------------- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/web/src/components/AgentChatComponent.vue b/web/src/components/AgentChatComponent.vue index 906d31af..4bd533cb 100644 --- a/web/src/components/AgentChatComponent.vue +++ b/web/src/components/AgentChatComponent.vue @@ -146,6 +146,7 @@ import { storeToRefs } from 'pinia'; // ==================== PROPS & EMITS ==================== const props = defineProps({ state: { type: Object, default: () => ({}) }, + agentId: { type: String, default: '' }, singleMode: { type: Boolean, default: true } }); const emit = defineEmits(['open-config', 'open-agent-modal']); @@ -380,8 +381,15 @@ const initAll = async () => { const loadChatsList = async () => { try { - if (!AgentValidator.validateLoadOperation(agentStore.selectedAgentId, '加载对话列表')) return; - await agentStore.fetchThreads(agentStore.selectedAgentId); + const agentId = agentStore.selectedAgentId; + if (!AgentValidator.validateLoadOperation(agentId, '加载对话列表')) return; + + await agentStore.fetchThreads(agentId); + + // If selected agent changed during fetch, abort. The watcher will trigger a new load. + if (agentStore.selectedAgentId !== agentId) { + return; + } if (currentAgentThreads.value && currentAgentThreads.value.length > 0) { const threadToSelect = currentAgentThreads.value[0].id; @@ -398,20 +406,21 @@ const loadChatsList = async () => { onMounted(async () => { await initAll(); scrollController.enableAutoScroll(); - watch(() => agentStore.selectedAgentId, (newAgentId, oldAgentId) => { - if (newAgentId && newAgentId !== oldAgentId) { - initAll(); - } - }); - - // 只监听streaming状态,用于流式消息的智能滚动 - watch(conversations, () => { - if (isProcessing.value) { - scrollController.scrollToBottom(); - } - }, { deep: true, flush: 'post' }); }); +watch(() => agentStore.selectedAgentId, (newAgentId, oldAgentId) => { + if (newAgentId && newAgentId !== oldAgentId) { + loadChatsList(); + } +}); + +// 只监听streaming状态,用于流式消息的智能滚动 +watch(conversations, () => { + if (isProcessing.value) { + scrollController.scrollToBottom(); + } +}, { deep: true, flush: 'post' }); +