feat:智能体探索窗口预加载完善
This commit is contained in:
@@ -73,6 +73,13 @@ export interface IScoreItem {
|
||||
reason: string
|
||||
}
|
||||
|
||||
// 单个任务的评分数据结构
|
||||
export interface ITaskScoreData {
|
||||
aspectList: string[] // 维度列表
|
||||
agentScores: Record<string, Record<string, IScoreItem>> // agent -> 维度 -> 评分
|
||||
timestamp: number // 缓存时间戳
|
||||
}
|
||||
|
||||
export interface IAgentSelectModifyAddRequest {
|
||||
aspectList: string[] // 维度列表
|
||||
agentScores: Record<string, Record<string, IScoreItem>> // agent -> 维度 -> 评分(与后端返回格式一致)
|
||||
@@ -105,13 +112,104 @@ export const useAgentsStore = defineStore('agents', () => {
|
||||
agents.value = agent
|
||||
}
|
||||
|
||||
// 智能体评分数据存储
|
||||
// 🆕 新的按任务ID存储的评分数据
|
||||
const taskScoreDataMap = useStorage<Record<string, ITaskScoreData>>(
|
||||
`${storageKey}-task-score-data`,
|
||||
{},
|
||||
)
|
||||
|
||||
// 🆕 预加载状态追踪(用于避免重复预加载)
|
||||
const preloadingTaskIds = ref<Set<string>>(new Set())
|
||||
|
||||
// 🆕 获取指定任务的评分数据(按任务ID获取)
|
||||
function getTaskScoreData(taskId: string): IAgentSelectModifyAddRequest | null {
|
||||
if (!taskId) {
|
||||
console.warn('⚠️ getTaskScoreData: taskId 为空')
|
||||
return null
|
||||
}
|
||||
|
||||
const taskScoreData = taskScoreDataMap.value[taskId]
|
||||
if (taskScoreData) {
|
||||
console.log(`✅ 使用任务 ${taskId} 的缓存评分数据,维度数: ${taskScoreData.aspectList.length}`)
|
||||
return {
|
||||
aspectList: taskScoreData.aspectList,
|
||||
agentScores: taskScoreData.agentScores,
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`ℹ️ 任务 ${taskId} 没有缓存的评分数据`)
|
||||
return null
|
||||
}
|
||||
|
||||
// 🆕 设置指定任务的评分数据
|
||||
function setTaskScoreData(taskId: string, data: IAgentSelectModifyAddRequest) {
|
||||
if (!taskId) {
|
||||
console.warn('⚠️ setTaskScoreData: taskId 为空,无法存储')
|
||||
return
|
||||
}
|
||||
taskScoreDataMap.value = {
|
||||
...taskScoreDataMap.value,
|
||||
[taskId]: {
|
||||
...data,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
}
|
||||
console.log(`✅ 任务 ${taskId} 的评分数据已存储`, {
|
||||
aspectCount: data.aspectList.length,
|
||||
agentCount: Object.keys(data.agentScores).length,
|
||||
})
|
||||
}
|
||||
|
||||
// 🆕 检查指定任务是否有评分数据
|
||||
function hasTaskScoreData(taskId: string): boolean {
|
||||
if (!taskId) return false
|
||||
return !!taskScoreDataMap.value[taskId]?.aspectList?.length
|
||||
}
|
||||
|
||||
// 🆕 获取所有已预加载的任务ID列表
|
||||
function getPreloadedTaskIds(): string[] {
|
||||
return Object.keys(taskScoreDataMap.value)
|
||||
}
|
||||
|
||||
// 🆕 清除指定任务的评分数据
|
||||
function clearTaskScoreData(taskId: string) {
|
||||
if (taskId && taskScoreDataMap.value[taskId]) {
|
||||
const newMap = { ...taskScoreDataMap.value }
|
||||
delete newMap[taskId]
|
||||
taskScoreDataMap.value = newMap
|
||||
console.log(`✅ 任务 ${taskId} 的评分数据已清除`)
|
||||
}
|
||||
}
|
||||
|
||||
// 🆕 清除所有任务的评分数据
|
||||
function clearAllTaskScoreData() {
|
||||
taskScoreDataMap.value = {}
|
||||
preloadingTaskIds.value.clear()
|
||||
console.log('✅ 所有任务的评分数据已清除')
|
||||
}
|
||||
|
||||
// 🆕 标记任务正在预加载中
|
||||
function markTaskPreloading(taskId: string) {
|
||||
preloadingTaskIds.value.add(taskId)
|
||||
}
|
||||
|
||||
// 🆕 标记任务预加载完成
|
||||
function markTaskPreloadComplete(taskId: string) {
|
||||
preloadingTaskIds.value.delete(taskId)
|
||||
}
|
||||
|
||||
// 🆕 检查任务是否正在预加载
|
||||
function isTaskPreloading(taskId: string): boolean {
|
||||
return preloadingTaskIds.value.has(taskId)
|
||||
}
|
||||
|
||||
// 兼容旧版本:全局评分数据存储(单任务模式,已废弃,保留用于兼容)
|
||||
const IAgentSelectModifyAddRequest = useStorage<IAgentSelectModifyAddRequest | null>(
|
||||
`${storageKey}-score-data`,
|
||||
null,
|
||||
)
|
||||
|
||||
// 设置智能体评分数据
|
||||
// 设置智能体评分数据(兼容旧版本)
|
||||
function setAgentScoreData(data: IAgentSelectModifyAddRequest) {
|
||||
IAgentSelectModifyAddRequest.value = data
|
||||
}
|
||||
@@ -131,8 +229,6 @@ export const useAgentsStore = defineStore('agents', () => {
|
||||
}
|
||||
|
||||
// 添加该维度的评分数据
|
||||
// scores: { agentName: { score, reason } }
|
||||
// 转换为 agentScores[agentName][aspectName] = { score, reason }
|
||||
for (const [agentName, scoreItem] of Object.entries(scores)) {
|
||||
if (!IAgentSelectModifyAddRequest.value.agentScores[agentName]) {
|
||||
IAgentSelectModifyAddRequest.value.agentScores[agentName] = {}
|
||||
@@ -141,7 +237,7 @@ export const useAgentsStore = defineStore('agents', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 清除智能体评分数据
|
||||
// 清除智能体评分数据(兼容旧版本)
|
||||
function clearAgentScoreData() {
|
||||
IAgentSelectModifyAddRequest.value = null
|
||||
}
|
||||
@@ -476,6 +572,18 @@ export const useAgentsStore = defineStore('agents', () => {
|
||||
setAgentScoreData,
|
||||
addAgentScoreAspect,
|
||||
clearAgentScoreData,
|
||||
// 🆕 按任务ID存储的评分数据
|
||||
taskScoreDataMap,
|
||||
getTaskScoreData,
|
||||
setTaskScoreData,
|
||||
hasTaskScoreData,
|
||||
getPreloadedTaskIds,
|
||||
clearTaskScoreData,
|
||||
clearAllTaskScoreData,
|
||||
preloadingTaskIds,
|
||||
markTaskPreloading,
|
||||
markTaskPreloadComplete,
|
||||
isTaskPreloading,
|
||||
// 确认的agent组合列表(按任务ID分别存储)
|
||||
confirmedAgentGroupsMap,
|
||||
getConfirmedAgentGroups,
|
||||
|
||||
Reference in New Issue
Block a user