feat:智能体探索窗口预加载完善

This commit is contained in:
liailing1026
2026-01-26 16:46:58 +08:00
parent 641d70033d
commit 418b2e5f8f
3 changed files with 269 additions and 62 deletions

View File

@@ -101,22 +101,42 @@ const handleSubmit = async () => {
// 3. 异步更新 store等前端显示完成后再更新避免触发重新初始化
await nextTick()
const taskId = currentTask.value?.Id
// 🆕 更新按任务ID的存储
if (taskId) {
const existingTaskData = agentsStore.getTaskScoreData(taskId)
if (existingTaskData) {
// 检查维度是否已存在
if (!existingTaskData.aspectList.includes(response.aspectName)) {
existingTaskData.aspectList.push(response.aspectName)
}
// 更新评分数据
for (const [agentName, scoreInfo] of Object.entries(response.agentScores)) {
if (!existingTaskData.agentScores[agentName]) {
existingTaskData.agentScores[agentName] = {}
}
existingTaskData.agentScores[agentName][response.aspectName] = scoreInfo
}
// 保存到 store
agentsStore.setTaskScoreData(taskId, existingTaskData)
console.log(`✅ 已更新任务 ${taskId} 的 store新增维度: ${response.aspectName}`)
}
}
// 兼容旧版本:更新全局存储
const currentStoreData = agentsStore.IAgentSelectModifyAddRequest
if (currentStoreData && currentStoreData.aspectList) {
// 检查维度是否已存在防止store中已存在
if (!currentStoreData.aspectList.includes(response.aspectName)) {
currentStoreData.aspectList.push(response.aspectName)
}
// 更新评分数据
// response.agentScores: { agentName: { score, reason } }
// 转换为 agentScores[agentName][aspectName] = { score, reason }
for (const [agentName, scoreInfo] of Object.entries(response.agentScores)) {
if (!currentStoreData.agentScores[agentName]) {
currentStoreData.agentScores[agentName] = {}
}
currentStoreData.agentScores[agentName][response.aspectName] = scoreInfo
}
console.log(`已更新 store`)
console.log(`已更新全局 store(兼容旧版本)`)
}
// 清空输入框
@@ -495,40 +515,45 @@ const calculateAgentAverage = (agentData: AgentHeatmapData, selectedDimensions?:
// 模拟API调用 - 获取智能体评分数据
const fetchAgentScores = async () => {
// 先检查 store 中是否已有数据
const storedData = agentsStore.IAgentSelectModifyAddRequest
const taskId = currentTask.value?.Id
if (!taskId) {
console.warn('⚠️ fetchAgentScores: 当前任务没有 Id')
return null
}
// 🆕 先检查 store 中是否有该任务的评分数据
const storedData = agentsStore.getTaskScoreData(taskId)
if (storedData && storedData.aspectList && storedData.aspectList.length > 0) {
console.log('使用 store 中的评分数据')
return {
aspectList: storedData.aspectList,
agentScores: storedData.agentScores
console.log('✅ 使用任务缓存的评分数据')
return storedData
}
// 🆕 如果正在预加载中,等待预加载完成
if (agentsStore.isTaskPreloading(taskId)) {
console.log('⏳ 任务正在预加载中,等待完成...')
// 等待一小段时间,让预加载完成
await new Promise(resolve => setTimeout(resolve, 1000))
// 再次尝试获取
const cachedAfterPreload = agentsStore.getTaskScoreData(taskId)
if (cachedAfterPreload) {
return cachedAfterPreload
}
}
// TODO: 切换到真实API时取消注释下面这行
// 调用 API 获取评分(如果没有缓存或预加载)
const agentScores = await api.agentSelectModifyInit({
goal: agentsStore.agentRawPlan.data?.['General Goal'] || '',
stepTask: currentTask.value
})
// 🆕 使用 Mock API开发阶段传递当前任务的 AgentSelection 以获取对应的维度
const goal = agentsStore.agentRawPlan.data?.['General Goal'] || '开发智能协作系统'
console.log('📤 调用 mockAgentSelectModifyInit参数:', {
goal,
stepTask: currentTask.value,
agentSelection: currentTask.value?.AgentSelection
})
// const agentScores = await api.mockAgentSelectModifyInit()
// 从转换后的数据中提取维度列表第一个agent的所有维度
const firstAgent = Object.keys(agentScores)[0]
const aspectList = firstAgent ? Object.keys(agentScores[firstAgent] || {}) : []
console.log('✅ 获取到的维度列表:', aspectList)
// 保存到 store
agentsStore.setAgentScoreData({
// 🆕 保存到 store按任务ID存储
agentsStore.setTaskScoreData(taskId, {
aspectList,
agentScores
})
@@ -579,7 +604,13 @@ const initHeatmapData = async () => {
try {
// 获取接口数据
const { aspectList, agentScores } = await fetchAgentScores()
const scoreData = await fetchAgentScores()
if (!scoreData) {
console.warn('⚠️ initHeatmapData: 没有获取到评分数据')
return
}
const { aspectList, agentScores } = scoreData
// 设置评分维度
scoreDimensions.value = aspectList
@@ -591,17 +622,17 @@ const initHeatmapData = async () => {
const scoreDetails: Array<{ dimension: string; score: number; reason: string }> = []
// 按照维度顺序获取评分
aspectList.forEach(dimension => {
aspectList.forEach((dimension: string) => {
// 数据结构agentScores[agentName][dimension]
const agentScoreData = agentScores[agentName]
const scoreData = agentScoreData ? agentScoreData[dimension] : null
const scoreItem = agentScoreData ? agentScoreData[dimension] : null
if (scoreData) {
scores.push(scoreData.score)
if (scoreItem) {
scores.push(scoreItem.score)
scoreDetails.push({
dimension,
score: scoreData.score,
reason: scoreData.reason
score: scoreItem.score,
reason: scoreItem.reason
})
} else {
// 如果没有评分数据默认为1
@@ -655,11 +686,12 @@ const initHeatmapData = async () => {
}
}
// 监听agent列表变化初始化热力矩阵
// 🆕 监听agent列表变化或任务切换,初始化热力矩阵
watch(
() => allAgents.value.length,
newLength => {
if (newLength > 0) {
[() => allAgents.value.length, () => currentTask.value?.Id],
([agentLength, taskId]) => {
if (agentLength > 0 && taskId) {
console.log(`🔄 触发初始化热力图数据: agentCount=${agentLength}, taskId=${taskId}`)
initHeatmapData()
}
},
@@ -704,9 +736,8 @@ watch(
)
// 初始化和任务切换处理
// 1. 首次加载时,自动将初始 agent 组合添加到 confirmedAgentGroups
// 1. 首次加载时,自动将初始 agent 组合添加到 confirmedAgentGroups(不调用 API使用已有的 TaskProcess
// 2. 恢复之前的选择状态
// 3. 加载 TaskProcess 数据
watch(
() => currentTask.value,
async newTask => {
@@ -718,23 +749,27 @@ watch(
const existingGroups = agentsStore.getConfirmedAgentGroups(newTask.Id)
const hasInitialGroup = existingGroups.length > 0
// 首次初始化:自动添加初始组合(相当于系统自动执行了 confirmAgentSelection
// 首次初始化:自动添加初始组合 confirmedAgentGroups
if (!hasInitialGroup) {
console.log('🎯 首次初始化,自动添加初始 agent 组合到 Assignment')
agentsStore.addConfirmedAgentGroup(newTask.Id, [...newTask.AgentSelection])
// 调用 API 获取初始 agent 组合的 TaskProcess 数据
console.log('🔄 开始加载初始 agent 组合的 TaskProcess...')
// 🆕 检查 newTask 是否已有 TaskProcess步骤详情填充时已经包含
if (newTask.TaskProcess && newTask.TaskProcess.length > 0) {
console.log('✅ 初始 agent 组合已有 TaskProcess 数据,直接使用')
// 检查是否已有数据
if (!selectionStore.hasAgentTaskProcess(newTask.Id, newTask.AgentSelection)) {
// 直接存储已有的 TaskProcess 到 selectionStore不调用 API
selectionStore.setAgentTaskProcess(newTask.Id, newTask.AgentSelection, {
process: newTask.TaskProcess,
brief: newTask.Collaboration_Brief_frontEnd || { template: '', data: {} }
})
console.log('✅ 初始 agent 组合的 TaskProcess 已从现有数据加载')
} else {
// 🆕 如果没有 TaskProcess才调用 API 获取(兜底逻辑)
console.log('⚠️ 初始 agent 组合没有 TaskProcess 数据,调用 API 获取...')
try {
isLoadingInitialTask.value = true
console.log('=== 开始加载初始 agent 组合的 TaskProcess ===')
console.log('1. 任务ID:', newTask.Id)
console.log('2. 初始 agents:', newTask.AgentSelection)
// 将 IRawStepTask 转换为 IApiStepTask 格式
const stepTaskForApi = {
name: newTask.StepName || '',
content: newTask.TaskContent || '',
@@ -748,31 +783,21 @@ watch(
process: []
}
console.log('3. 转换后的 API 请求参数:', stepTaskForApi)
const goal = agentsStore.agentRawPlan.data?.['General Goal'] || '开发智能协作系统'
console.log('4. General Goal:', goal)
// 调用 Mock API 获取 TaskProcess
const filledTask = await api.fillStepTaskTaskProcess({
goal,
stepTask: stepTaskForApi,
agents: newTask.AgentSelection
})
console.log('=== 初始 agent 组合 TaskProcess 加载成功 ===')
console.log('5. TaskProcess 流程数量:', filledTask.process?.length || 0)
// 存储到 selectionStore
console.log(' 初始 agent 组合 TaskProcess API 加载成功')
selectionStore.setAgentTaskProcess(newTask.Id, newTask.AgentSelection, filledTask)
console.log('✅ 初始 agent 组合的 TaskProcess 已加载并存储')
} catch (error) {
console.error('❌ 加载初始 agent 组合的 TaskProcess 失败:', error)
} finally {
isLoadingInitialTask.value = false
}
} else {
console.log(' 初始 agent 组合已有 TaskProcess 数据,跳过加载')
}
}