From 44c06f693522f5cf27d2eb09c9fb8b5aed0719c5 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Tue, 16 Sep 2025 02:18:34 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/AgentChatComponent.vue | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/web/src/components/AgentChatComponent.vue b/web/src/components/AgentChatComponent.vue index d066dc50..08ef9f71 100644 --- a/web/src/components/AgentChatComponent.vue +++ b/web/src/components/AgentChatComponent.vue @@ -534,9 +534,32 @@ const updateMessageInThread = (threadId, messageIndex, updatedMessage) => { }; // ==================== CHAT ACTIONS ==================== +// 检查第一个对话是否为空 +const isFirstChatEmpty = () => { + if (threads.value.length === 0) return false; + const firstThread = threads.value[0]; + const firstThreadMessages = threadMessages.value[firstThread.id] || []; + return firstThreadMessages.length === 0; +}; + +// 如果第一个对话为空,直接切换到第一个对话 +const switchToFirstChatIfEmpty = async () => { + if (threads.value.length > 0 && isFirstChatEmpty()) { + await selectChat(threads.value[0].id); + return true; + } + return false; +}; + const createNewChat = async () => { if (!AgentValidator.validateAgentId(currentAgentId.value, '创建对话') || isProcessing.value) return; - if (currentChatId.value && conversations.value.length === 0) return; + + // 如果第一个对话为空,直接切换到第一个对话而不是创建新对话 + if (await switchToFirstChatIfEmpty()) return; + + // 只有当当前对话是第一个对话且为空时,才阻止创建新对话 + const currentThreadIndex = threads.value.findIndex(thread => thread.id === currentChatId.value); + if (currentChatId.value && conversations.value.length === 0 && currentThreadIndex === 0) return; chatState.creatingNewChat = true; try {