From cb2a57b2a1a4d5480eb63a8cd83f356223aff159 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Mon, 10 Nov 2025 09:17:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=9B=BE=E8=B0=B1=E7=BB=93=E6=9E=9C=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 `ToolResultRenderer.vue` 中,改进知识图谱结果的判断逻辑,增加对数据格式的验证,确保返回有效的三元组。 - 在 `agent.js` 中,添加用户权限检查,确保只有管理员可以加载智能体配置。 --- .../ToolCallingResult/ToolResultRenderer.vue | 38 +++++++++++++++---- web/src/stores/agent.js | 10 ++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/web/src/components/ToolCallingResult/ToolResultRenderer.vue b/web/src/components/ToolCallingResult/ToolResultRenderer.vue index 17db38a9..86a37940 100644 --- a/web/src/components/ToolCallingResult/ToolResultRenderer.vue +++ b/web/src/components/ToolCallingResult/ToolResultRenderer.vue @@ -74,7 +74,7 @@ const parsedData = computed(() => { if (typeof props.resultContent === 'string') { try { return JSON.parse(props.resultContent) - } catch { + } catch (error) { return props.resultContent } } @@ -138,15 +138,39 @@ const isImageResult = computed(() => { // 判断是否为知识图谱查询结果 const isKnowledgeGraphResult = computed(() => { const toolNameLower = props.toolName.toLowerCase() - const isGraphTool = toolNameLower.includes('graph') || - toolNameLower.includes('kg') || - toolNameLower.includes('query_knowledge_graph') - if (!isGraphTool) return false + // 工具名称初步筛选 - 支持中英文关键词 + const hasGraphKeyword = toolNameLower.includes('graph') || + toolNameLower.includes('图谱') || + toolNameLower.includes('kg') const data = parsedData.value - // 支持新格式:包含nodes、edges、triples的对象 - return data && typeof data === 'object' && 'triples' in data && Array.isArray(data.triples) + + // 数据格式验证 - 核心判断依据 + const hasBasicStructure = data && typeof data === 'object' + const hasTriples = hasBasicStructure && 'triples' in data + const triplesIsArray = hasTriples && Array.isArray(data.triples) + const triplesHasContent = triplesIsArray && data.triples.length > 0 + + // 进一步验证triples数组的内容格式 + let triplesHasValidFormat = false + if (triplesHasContent) { + // 检查是否至少有一个有效的三元组 + triplesHasValidFormat = data.triples.some(triple => { + return Array.isArray(triple) && + triple.length >= 3 && + triple.every(item => typeof item === 'string' && item.trim() !== '') + }) + } + + // 最终判断:数据格式符合规范优先,工具名称作为辅助判断 + // 1. 如果数据格式完全符合规范,直接认为是知识图谱结果 + if (hasBasicStructure && triplesIsArray && triplesHasContent && triplesHasValidFormat) { + return true + } + + // 2. 如果数据格式基本符合且有相关关键词,也认为是知识图谱结果 + return hasTriples && triplesIsArray && hasGraphKeyword }) // 判断是否为计算器结果 diff --git a/web/src/stores/agent.js b/web/src/stores/agent.js index f395cb5c..353a1b20 100644 --- a/web/src/stores/agent.js +++ b/web/src/stores/agent.js @@ -2,8 +2,10 @@ import { defineStore } from 'pinia' import { ref, computed } from 'vue' import { agentApi } from '@/apis/agent_api' import { handleChatError } from '@/utils/errorHandler' +import { useUserStore } from '@/stores/user' export const useAgentStore = defineStore('agent', () => { + const userStore = useUserStore() // ==================== 状态定义 ==================== // 智能体相关状态 const agents = ref([]) @@ -84,7 +86,9 @@ export const useAgentStore = defineStore('agent', () => { } if (selectedAgentId.value) { - await loadAgentConfig() + if (userStore.isAdmin) { + await loadAgentConfig() + } await fetchTools() } @@ -161,6 +165,8 @@ export const useAgentStore = defineStore('agent', () => { * 加载智能体配置 */ async function loadAgentConfig(agentId = null) { + if (!userStore.isAdmin) return + const targetAgentId = agentId || selectedAgentId.value if (!targetAgentId) return @@ -308,4 +314,4 @@ export const useAgentStore = defineStore('agent', () => { storage: localStorage, paths: ['selectedAgentId', 'defaultAgentId'] } -}) \ No newline at end of file +})