diff --git a/templates/index.html b/templates/index.html index 5c18947..56259fc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -206,10 +206,11 @@ } } - // 切换Agent - function switchAgent() { + // 切换Agent - 自动创建新对话 + async function switchAgent() { const newAgentId = document.getElementById('agentSelect').value; - if (newAgentId && newAgentId !== currentAgentId) { + if (newAgentId && parseInt(newAgentId) !== currentAgentId) { + const oldAgentId = currentAgentId; currentAgentId = parseInt(newAgentId); console.log('切换Agent:', currentAgentId); @@ -221,6 +222,9 @@ })); } + // 自动创建新对话 + await createNewConversation(); + // 显示切换提示 const agent = agents.find(a => a.id === currentAgentId); if (agent) { @@ -232,19 +236,14 @@ // 显示Agent切换提示 function showAgentSwitchNotice(agentName) { const container = document.getElementById('messagesContainer'); - const notice = document.createElement('div'); - notice.className = 'message assistant'; - notice.innerHTML = ` -
🔄
-
- 已切换到 Agent: ${agentName},开始新对话生效 + // 清空现有内容,显示切换提示 + container.innerHTML = ` +
+

🔄 已切换 Agent

+

${agentName}

+

已为您创建新对话,可直接开始聊天

`; - container.appendChild(notice); - container.scrollTop = container.scrollHeight; - - // 3秒后移除提示 - setTimeout(() => notice.remove(), 3000); } // 加载快捷语句