From 9eeeace88cc724869551473ff3810fd87cdbd218 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Mon, 27 Apr 2026 23:56:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=A5=E5=85=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=AE=B0=E5=BF=86=20+=20=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E8=81=94=E7=BD=91=E6=90=9C=E7=B4=A2=20+=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=9C=AA=E5=90=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/www/app.js b/www/app.js index 16b1e50..edffcca 100644 --- a/www/app.js +++ b/www/app.js @@ -118,13 +118,11 @@ async function loadBackendConfig() { // 加载工具列表 if (backendConfig.allTools) { - allTools = backendConfig.allTools; + // 过滤掉联网搜索(已有单独按钮) + allTools = backendConfig.allTools.filter(t => t.type !== 'search'); } - // 加载默认启用的工具 - if (backendConfig.tools) { - enabledTools = backendConfig.tools.map(t => t.tool_id); - } + // 不加载默认启用的工具,所有工具默认未启用 updateAgentsDisplay(); console.log('后台配置已加载', backendConfig); @@ -3044,6 +3042,9 @@ async function openAgent(agentId) { currentAgent = systemAgents.find(a => a.id === agentId); if (!currentAgent) return; + // 加载该智能体的工具选择状态 + loadToolsState(); + // 检查未登录用户的智能体限制 if (!currentUser) { const check = canUseAgent(agentId); @@ -3599,6 +3600,10 @@ function openConversation(id) { return; } + // 普通对话,加载普通对话的工具状态 + currentAgent = null; + loadToolsState(); + // 渲染对话页面 const chatHtml = `
@@ -4232,6 +4237,9 @@ function confirmToolsSelection() { enabledTools = selectedTools; + // 保存工具选择状态 + saveToolsState(); + // 更新按钮显示 const moreToolsBtn = document.getElementById('moreToolsBtn'); if (moreToolsBtn) { @@ -4254,6 +4262,38 @@ function confirmToolsSelection() { showToast(`已启用 ${enabledTools.length} 个工具`); } +// 保存工具选择状态 +function saveToolsState() { + if (currentAgent) { + // 智能体对话:保存到 localStorage(按智能体ID) + localStorage.setItem(`agentEnabledTools_${currentAgent.id}`, JSON.stringify(enabledTools)); + } else { + // 普通对话:保存到 localStorage + localStorage.setItem('chatEnabledTools', JSON.stringify(enabledTools)); + } +} + +// 加载工具选择状态 +function loadToolsState() { + if (currentAgent) { + // 智能体对话:加载该智能体的工具状态 + const saved = localStorage.getItem(`agentEnabledTools_${currentAgent.id}`); + if (saved) { + enabledTools = JSON.parse(saved); + } else { + enabledTools = []; + } + } else { + // 普通对话:加载普通对话的工具状态 + const saved = localStorage.getItem('chatEnabledTools'); + if (saved) { + enabledTools = JSON.parse(saved); + } else { + enabledTools = []; + } + } +} + // 渲染头像(支持 emoji 和上传的图片) function renderAvatar(avatar) { if (!avatar) return '👤';