-

AI 对话 v2.0

+

AI 对话 v3.0

@@ -230,20 +200,6 @@
- -
- -
-
- 工具设置 - -
-
-
-
@@ -324,7 +280,6 @@ document.addEventListener('DOMContentLoaded', () => { loadProviders(); // 加载大模型池 - loadToolsData(); // 加载工具列表 loadAgents(); loadQuickPhrases(); connectWebSocket(); @@ -359,117 +314,6 @@ return agentTools.includes(toolType); } - // 获取当前Agent不支持的工具列表(用户已启用但Agent不支持) - function getUnsupportedTools() { - const unsupported = []; - // 检查所有工具checkbox(排除disabled的) - const toolCheckboxes = document.querySelectorAll('.tool-checkbox:not([disabled])'); - toolCheckboxes.forEach(cb => { - if (cb.checked) { - // 检查Agent是否支持 - if (!checkAgentToolSupport(cb.dataset.toolType)) { - // 获取工具显示名称 - const label = cb.closest('.tool-item')?.querySelector('label')?.textContent?.trim() || cb.dataset.toolType; - unsupported.push(label); - } - } - }); - return unsupported; - } - - // 渲染工具选择区域(根据系统工具列表) - function renderToolToggles() { - const container = document.getElementById('toolsPanelContent'); - if (!container || toolsData.length === 0) return; - - // 获取当前Agent支持的工具 - const agent = agents.find(a => a.id === currentAgentId); - const agentTools = agent?.tools || []; - - // 渲染工具checkbox列表 - let html = ''; - toolsData.filter(t => t.is_active).forEach(t => { - const toolType = t.tool_type || 'unknown'; - const isSupported = agentTools.includes(toolType); - const icon = getToolIconFrontend(toolType); - const disabledClass = isSupported ? '' : 'disabled'; - html += `
- - -
`; - }); - - container.innerHTML = html || '
暂无可用工具
'; - - // 更新工具数量badge - updateToolsBadge(); - } - - // 更新工具数量badge - function updateToolsBadge() { - const badge = document.getElementById('toolsBadge'); - const selectedCount = document.querySelectorAll('.tool-checkbox:checked').length; - if (selectedCount > 0) { - badge.textContent = selectedCount; - badge.style.display = 'inline'; - } else { - badge.style.display = 'none'; - } - } - - // 切换工具面板显示 - function toggleToolsPanel() { - const panel = document.getElementById('toolsPanel'); - const btn = document.querySelector('.tools-toggle-btn'); - panel.classList.toggle('show'); - btn.classList.toggle('active'); - } - - // 前端工具图标 - function getToolIconFrontend(toolType) { - const icons = { - 'search': 'ri-search-line', - 'calculator': 'ri-calculator-line', - 'code': 'ri-code-line', - 'image': 'ri-image-line', - 'web': 'ri-global-line' - }; - return icons[toolType] || 'ri-tools-line'; - } - - // 加载工具列表 - let toolsData = []; - async function loadToolsData() { - try { - const res = await fetch('/api/v2/tools'); - const data = await res.json(); - toolsData = data.tools || []; - renderToolToggles(); - } catch (e) { console.error('加载工具列表失败:', e); } - } - - // 显示工具不支持提示 - function showToolWarning() { - updateToolsBadge(); // 更新badge数量 - - const unsupported = getUnsupportedTools(); - const warningDiv = document.getElementById('tool-warning-tip'); - - if (unsupported.length > 0) { - const agent = agents.find(a => a.id === currentAgentId); - const agentName = agent?.display_name || agent?.name || '当前Agent'; - const msg = ` ${agentName} 不支持 ${unsupported.join('、')} 工具,请关闭或切换Agent`; - - warningDiv.innerHTML = msg; - warningDiv.style.display = 'block'; - // 禁用发送按钮 - document.getElementById('sendBtn').disabled = true; - } else { - warningDiv.style.display = 'none'; - document.getElementById('sendBtn').disabled = false; - } - } - // 加载Agent async function loadAgents() { try { @@ -479,10 +323,6 @@ const defaultAgent = agents.find(a => a.is_default) || agents[0]; if (defaultAgent) currentAgentId = defaultAgent.id; renderAgentSelect(); - // 加载后检查工具支持 - showToolWarning(); - // 渲染工具选择区域 - renderToolToggles(); } catch (e) { console.error('加载Agent失败:', e); } } @@ -505,8 +345,6 @@ if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify({ action: 'switch_agent', agent_id: currentAgentId })); await createNewConversation(); showAgentSwitchNotice(); - // 切换Agent后检查工具支持 - showToolWarning(); } } @@ -1208,16 +1046,6 @@ return; } - // 检查工具支持 - const unsupported = getUnsupportedTools(); - if (unsupported.length > 0) { - const agent = agents.find(a => a.id === currentAgentId); - const agentName = agent?.display_name || agent?.name || '当前Agent'; - alert(`⚠️ ${agentName} 不支持 ${unsupported.join('、')} 工具\n\n请关闭不支持的工具,或切换到支持该工具的Agent。`); - document.getElementById('sendBtn').disabled = false; - return; - } - document.getElementById('sendBtn').disabled = true; input.value = ''; input.style.height = 'auto'; @@ -1230,13 +1058,7 @@ pendingFiles = []; document.getElementById('filePreviewArea').innerHTML = ''; - // 获取禁用的工具列表(所有系统工具 - 用户选中的工具) - const disabledTools = []; - const allToolTypes = toolsData.filter(t => t.is_active).map(t => t.tool_type); - const selectedTools = Array.from(document.querySelectorAll('.tool-checkbox:checked')).map(cb => cb.dataset.toolType); - allToolTypes.forEach(t => { - if (!selectedTools.includes(t)) disabledTools.push(t); - }); + // v3.0: Function Calling模式,不再需要 disabled_tools // 发送消息(包含文件) if (ws?.readyState === WebSocket.OPEN) { @@ -1245,7 +1067,6 @@ message: msg, conversation_id: currentConversationId, agent_id: currentAgentId, - disabled_tools: disabledTools, files: lastSentFiles || [] // 发送的文件列表 })); }