fix: 增强知识图谱结果判断逻辑

- 在 `ToolResultRenderer.vue` 中,改进知识图谱结果的判断逻辑,增加对数据格式的验证,确保返回有效的三元组。
- 在 `agent.js` 中,添加用户权限检查,确保只有管理员可以加载智能体配置。
This commit is contained in:
Wenjie Zhang 2025-11-10 09:17:06 +08:00
parent 92710097ba
commit cb2a57b2a1
2 changed files with 39 additions and 9 deletions

View File

@ -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
// nodesedgestriples
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
})
//

View File

@ -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']
}
})
})