feat:智能体探索窗口与任务大纲探索窗口联动
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
<!-- 自定义任务节点 -->
|
||||
<template #node-task="nodeProps">
|
||||
<TaskNode
|
||||
:key="nodeProps.data.updateKey || nodeProps.id"
|
||||
v-bind="nodeProps"
|
||||
:is-adding-branch="currentAddingBranchNodeId === nodeProps.id"
|
||||
:is-branch-selected="selectedNodeIds.has(nodeProps.id)"
|
||||
@@ -77,7 +78,7 @@ const nodes = ref<Node[]>([])
|
||||
const edges = ref<Edge[]>([])
|
||||
|
||||
// Vue Flow 实例方法
|
||||
const { fitView: fit, setTransform } = useVueFlow()
|
||||
const { fitView: fit, setTransform, updateNode, findNode } = useVueFlow()
|
||||
|
||||
// 编辑状态管理
|
||||
const editingTasks = ref<Record<string, string>>({})
|
||||
@@ -212,14 +213,11 @@ const START_Y = 50 // 起始 Y 坐标
|
||||
|
||||
// 初始化流程图 - 横向布局(根节点为初始目标,只展示流程卡片)
|
||||
const initializeFlow = () => {
|
||||
// 检查是否已经初始化过
|
||||
const branchesInitialized = sessionStorage.getItem(BRANCHES_INIT_KEY) === 'true'
|
||||
const savedBranches = selectionStore.getAllFlowBranches()
|
||||
console.log('saveBranches:', savedBranches)
|
||||
debugger
|
||||
|
||||
// 如果已经初始化过,只恢复已保存的分支,不重新创建
|
||||
if (branchesInitialized && savedBranches.length > 0) {
|
||||
console.log('♻️ 已初始化过,恢复已保存的分支,跳过重新创建')
|
||||
|
||||
const newNodes: Node[] = []
|
||||
const newEdges: Edge[] = []
|
||||
@@ -261,25 +259,17 @@ const initializeFlow = () => {
|
||||
nodes.value = newNodes
|
||||
edges.value = newEdges
|
||||
|
||||
console.log('♻️ 已恢复', savedBranches.length, '个分支,总节点数:', newNodes.length)
|
||||
|
||||
// 🆕 恢复最后选中的分支状态
|
||||
// 恢复最后选中的分支状态
|
||||
const lastSelectedBranchId = sessionStorage.getItem(LAST_SELECTED_BRANCH_KEY)
|
||||
if (lastSelectedBranchId) {
|
||||
console.log('🔄 恢复最后选中的分支:', lastSelectedBranchId)
|
||||
|
||||
const lastSelectedBranch = savedBranches.find(branch => branch.id === lastSelectedBranchId)
|
||||
if (lastSelectedBranch) {
|
||||
// 🆕 恢复高亮状态(需要包含主流程路径 + 分支节点)
|
||||
let nodesToHighlight: string[] = []
|
||||
|
||||
if (lastSelectedBranch.branchContent === '初始流程') {
|
||||
// 初始流程:高亮所有主流程节点
|
||||
nodesToHighlight = nodes.value
|
||||
.filter(node => isMainProcessNode(node.id))
|
||||
.map(node => node.id)
|
||||
|
||||
console.log('🎯 已恢复高亮:初始流程,节点数:', nodesToHighlight.length)
|
||||
} else {
|
||||
// 其他分支:需要构建完整路径(主流程 + 分支)
|
||||
const firstBranchNode = lastSelectedBranch.nodes[0]
|
||||
@@ -297,72 +287,19 @@ const initializeFlow = () => {
|
||||
...mainPathNodes,
|
||||
...lastSelectedBranch.nodes.map(node => node.id)
|
||||
]
|
||||
|
||||
console.log(
|
||||
'🎯 已恢复高亮:完整路径,主流程节点数:',
|
||||
mainPathNodes.length,
|
||||
'分支节点数:',
|
||||
lastSelectedBranch.nodes.length
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectedNodeIds.value = new Set(nodesToHighlight)
|
||||
|
||||
// 🆕 恢复外界组件的数据
|
||||
if (lastSelectedBranch.branchContent === '初始流程') {
|
||||
// 初始流程:直接使用分支的任务
|
||||
agentsStore.setAgentRawPlan({
|
||||
data: {
|
||||
...agentsStore.agentRawPlan.data!,
|
||||
'Collaboration Process': JSON.parse(JSON.stringify(lastSelectedBranch.tasks))
|
||||
}
|
||||
})
|
||||
console.log('🔄 已恢复外界数据:初始流程,任务数:', lastSelectedBranch.tasks.length)
|
||||
} else {
|
||||
// 其他分支:需要构建完整路径(主流程 + 分支)
|
||||
if (nodesToHighlight.length > 0) {
|
||||
// 构建完整路径的任务
|
||||
let fullProcessTasks: IRawStepTask[] = []
|
||||
|
||||
// 获取主流程路径上的任务
|
||||
nodesToHighlight.forEach(nodeId => {
|
||||
const node = nodes.value.find(n => n.id === nodeId)
|
||||
if (node && node.data.task && isMainProcessNode(nodeId)) {
|
||||
fullProcessTasks.push(node.data.task)
|
||||
}
|
||||
})
|
||||
|
||||
// 添加分支的任务
|
||||
fullProcessTasks = [...fullProcessTasks, ...lastSelectedBranch.tasks]
|
||||
|
||||
// 更新外界组件的数据
|
||||
agentsStore.setAgentRawPlan({
|
||||
data: {
|
||||
...agentsStore.agentRawPlan.data!,
|
||||
'Collaboration Process': JSON.parse(JSON.stringify(fullProcessTasks))
|
||||
}
|
||||
})
|
||||
console.log(
|
||||
'🔄 已恢复外界数据:完整路径,主流程任务数:',
|
||||
fullProcessTasks.length - lastSelectedBranch.tasks.length,
|
||||
'分支任务数:',
|
||||
lastSelectedBranch.tasks.length
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 没有最后选中的分支,默认选中主流程分支
|
||||
const mainProcessNodeIds = nodes.value
|
||||
.filter(node => isMainProcessNode(node.id))
|
||||
.map(node => node.id)
|
||||
selectedNodeIds.value = new Set(mainProcessNodeIds)
|
||||
console.log('🎯 默认选中主流程分支:', mainProcessNodeIds)
|
||||
}
|
||||
|
||||
// 适应视图
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
fit({ padding: 0.15, duration: 300 })
|
||||
@@ -373,7 +310,6 @@ const initializeFlow = () => {
|
||||
}
|
||||
|
||||
// 首次初始化:创建完整的流程
|
||||
console.log('🆕 首次初始化,创建流程分支')
|
||||
|
||||
const newNodes: Node[] = []
|
||||
const newEdges: Edge[] = []
|
||||
@@ -411,7 +347,8 @@ const initializeFlow = () => {
|
||||
data: {
|
||||
task,
|
||||
isEditing: false,
|
||||
editingContent: task.TaskContent || ''
|
||||
editingContent: task.TaskContent || '',
|
||||
updateKey: Date.now() // 添加更新时间戳,用于强制组件重新渲染
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,37 +404,27 @@ const initializeFlow = () => {
|
||||
tasks: JSON.parse(JSON.stringify(collaborationProcess.value))
|
||||
})
|
||||
|
||||
console.log('💾 已保存初始流程为分支,任务数:', collaborationProcess.value.length)
|
||||
|
||||
// 🆕 标记已初始化
|
||||
sessionStorage.setItem(BRANCHES_INIT_KEY, 'true')
|
||||
console.log('✅ 已设置分支初始化标记')
|
||||
}
|
||||
|
||||
// 后续初始化:从 store 恢复所有分支节点
|
||||
if (savedBranches.length > 0) {
|
||||
savedBranches.forEach(branch => {
|
||||
// 恢复节点(排除已经在 newNodes 中的根节点)
|
||||
branch.nodes.forEach(node => {
|
||||
if (node.id !== 'root-goal') {
|
||||
nodes.value.push(node)
|
||||
}
|
||||
})
|
||||
// 恢复边
|
||||
branch.edges.forEach(edge => {
|
||||
edges.value.push(edge)
|
||||
})
|
||||
})
|
||||
|
||||
console.log('♻️ 已恢复', savedBranches.length, '个分支')
|
||||
}
|
||||
|
||||
// 默认选中主流程分支(初始数据的完整分支)
|
||||
const mainProcessNodeIds = nodes.value
|
||||
.filter(node => isMainProcessNode(node.id))
|
||||
.map(node => node.id)
|
||||
selectedNodeIds.value = new Set(mainProcessNodeIds)
|
||||
console.log('🎯 默认选中主流程分支:', mainProcessNodeIds)
|
||||
|
||||
// 只在首次挂载后初始化时适应视图,后续数据变化不适应
|
||||
if (isMounted.value && !isInitialized.value) {
|
||||
@@ -511,44 +438,56 @@ const initializeFlow = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 currentTask 变化,自动高亮对应分支
|
||||
// 监听 currentTask 变化,自动高亮对应分支并更新节点数据
|
||||
watch(
|
||||
() => agentsStore.currentTask,
|
||||
(newTask, oldTask) => {
|
||||
console.log('🔍 watch 触发 - oldTask:', oldTask?.StepName, 'newTask:', newTask?.StepName)
|
||||
|
||||
// 🆕 如果是初始化(从无到有),跳过高亮逻辑
|
||||
if (!oldTask && newTask) {
|
||||
console.log('🔄 currentTask 初始化,跳过高亮')
|
||||
return
|
||||
}
|
||||
|
||||
if (!newTask) {
|
||||
console.log('❌ newTask 为空,返回')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('🔍 开始查找匹配分支, taskId:', newTask.Id, 'taskName:', newTask.StepName)
|
||||
|
||||
// 1. 找到包含 currentTask 的分支(使用 Id 精确匹配)
|
||||
// 1. 找到包含 currentTask 的分支
|
||||
const allBranches = selectionStore.getAllFlowBranches()
|
||||
console.log('🔍 当前共有', allBranches.length, '个分支')
|
||||
|
||||
const matchedBranch = allBranches.find(branch => {
|
||||
const hasMatch = branch.tasks.some(task => task.Id === newTask.Id)
|
||||
if (hasMatch) {
|
||||
console.log(' ✓ 匹配到分支:', branch.branchContent, '任务数:', branch.tasks.length)
|
||||
}
|
||||
return hasMatch
|
||||
return branch.tasks.some(task => task.Id === newTask.Id)
|
||||
})
|
||||
|
||||
if (matchedBranch) {
|
||||
// 2. 高亮该分支的所有节点
|
||||
const branchNodeIds = matchedBranch.nodes.map(node => node.id)
|
||||
selectedNodeIds.value = new Set(branchNodeIds)
|
||||
console.log('🎯 自动高亮分支:', matchedBranch.branchContent, '节点数:', branchNodeIds.length)
|
||||
} else {
|
||||
console.warn('⚠️ 未找到匹配的分支, taskId:', newTask.Id, 'taskName:', newTask.StepName)
|
||||
|
||||
// 更新对应节点的 task 数据(同步 AgentAllocation 中的修改)
|
||||
if (newTask.StepName) {
|
||||
const matchedNodes = nodes.value.filter(node => {
|
||||
return node.data?.task?.StepName === newTask.StepName
|
||||
})
|
||||
|
||||
matchedNodes.forEach(node => {
|
||||
const newUpdateKey = Date.now()
|
||||
|
||||
updateNode(node.id, {
|
||||
data: {
|
||||
...node.data,
|
||||
task: { ...newTask },
|
||||
updateKey: newUpdateKey
|
||||
}
|
||||
})
|
||||
|
||||
const nodeIndex = nodes.value.findIndex(n => n.id === node.id)
|
||||
if (nodeIndex !== -1) {
|
||||
const updatedNode = {
|
||||
...nodes.value[nodeIndex],
|
||||
data: {
|
||||
...nodes.value[nodeIndex].data,
|
||||
task: { ...newTask },
|
||||
updateKey: newUpdateKey
|
||||
}
|
||||
}
|
||||
nodes.value.splice(nodeIndex, 1, updatedNode)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
@@ -559,42 +498,43 @@ onMounted(() => {
|
||||
isMounted.value = true
|
||||
initializeFlow()
|
||||
|
||||
// 🆕 初始化后,检查 currentTask 是否已有值
|
||||
if (agentsStore.currentTask) {
|
||||
console.log('🔍 组件挂载时 currentTask 已有值:', agentsStore.currentTask.StepName)
|
||||
console.log('🔍 组件挂载时 currentTask 已有值:', agentsStore.currentTask)
|
||||
// 主动同步 currentTask 数据到节点(解决组件晚挂载的问题)
|
||||
if (agentsStore.currentTask && agentsStore.currentTask.StepName) {
|
||||
const matchedNodes = nodes.value.filter(node => {
|
||||
return node.data?.task?.StepName === agentsStore.currentTask!.StepName
|
||||
})
|
||||
|
||||
matchedNodes.forEach(node => {
|
||||
const newUpdateKey = Date.now()
|
||||
const nodeIndex = nodes.value.findIndex(n => n.id === node.id)
|
||||
|
||||
if (nodeIndex !== -1) {
|
||||
const updatedNode = {
|
||||
...nodes.value[nodeIndex],
|
||||
data: {
|
||||
...nodes.value[nodeIndex].data,
|
||||
task: { ...agentsStore.currentTask! },
|
||||
updateKey: newUpdateKey
|
||||
}
|
||||
}
|
||||
nodes.value.splice(nodeIndex, 1, updatedNode)
|
||||
}
|
||||
})
|
||||
|
||||
const allBranches = selectionStore.getAllFlowBranches()
|
||||
console.log('🔍 当前共有', allBranches.length, '个分支')
|
||||
|
||||
const matchedBranch = allBranches.find(branch => {
|
||||
const hasMatch = branch.tasks.some(task => task.Id === agentsStore.currentTask!.Id)
|
||||
if (hasMatch) {
|
||||
console.log(' ✓ 匹配到分支:', branch.branchContent, '任务数:', branch.tasks.length)
|
||||
}
|
||||
return hasMatch
|
||||
return branch.tasks.some(task => task.Id === agentsStore.currentTask!.Id)
|
||||
})
|
||||
|
||||
if (matchedBranch) {
|
||||
const branchNodeIds = matchedBranch.nodes.map(node => node.id)
|
||||
selectedNodeIds.value = new Set(branchNodeIds)
|
||||
console.log(
|
||||
'🎯 初始化高亮分支:',
|
||||
matchedBranch.branchContent,
|
||||
'节点数:',
|
||||
branchNodeIds.length
|
||||
)
|
||||
} else {
|
||||
console.warn('⚠️ 初始化时未找到匹配的分支, taskId:', agentsStore.currentTask.Id)
|
||||
}
|
||||
} else {
|
||||
console.log('🔍 组件挂载时 currentTask 为空')
|
||||
}
|
||||
})
|
||||
|
||||
// 节点点击事件
|
||||
const onNodeClick = (event: any) => {
|
||||
console.log('点击节点:', event.node)
|
||||
|
||||
const nodeId = event.node.id
|
||||
const nodeData = event.node.data as any
|
||||
@@ -623,31 +563,20 @@ const onNodeClick = (event: any) => {
|
||||
'Collaboration Process': JSON.parse(JSON.stringify(initialBranch.tasks))
|
||||
}
|
||||
})
|
||||
console.log('🔄 已切换到初始流程,任务数:', initialBranch.tasks.length)
|
||||
|
||||
// 🆕 保存最后选中的分支ID
|
||||
sessionStorage.setItem(LAST_SELECTED_BRANCH_KEY, initialBranch.id)
|
||||
console.log('💾 已保存最后选中的分支ID:', initialBranch.id)
|
||||
}
|
||||
} else {
|
||||
// 点击的是分支节点
|
||||
// 🆕 向上回溯分支父节点链(多级分支)
|
||||
const branchParentChain = getBranchParentChain(nodeId)
|
||||
|
||||
// 🆕 向下遍历分支的子节点(只沿right handle方向)
|
||||
const branchChildNodes = getAllBranchNodes(nodeId)
|
||||
|
||||
// 找到最顶层的分支父节点(连接到主流程或根节点的)
|
||||
let topBranchNodeId: string | null = null
|
||||
if (branchParentChain.length > 0) {
|
||||
// 取父节点链的最后一个(最顶层的分支节点)
|
||||
topBranchNodeId = branchParentChain[branchParentChain.length - 1]
|
||||
} else {
|
||||
// 如果没有分支父节点,当前节点就是最顶层
|
||||
topBranchNodeId = nodeId
|
||||
}
|
||||
|
||||
// 找到最顶层分支节点的父节点(主流程节点或根节点)
|
||||
let parentNodeId: string | null = null
|
||||
const topBranchIncomingEdge = edges.value.find(edge => edge.target === topBranchNodeId)
|
||||
|
||||
@@ -656,24 +585,12 @@ const onNodeClick = (event: any) => {
|
||||
}
|
||||
|
||||
if (parentNodeId) {
|
||||
// 回溯到根节点,获取主流程路径
|
||||
const pathToRoot = getPathToRoot(parentNodeId)
|
||||
const correctPathToRoot = pathToRoot
|
||||
const correctBranchParentChain = [...branchParentChain].reverse()
|
||||
|
||||
// 🔧 getPathToRoot 已经返回正序(从左到右),不需要反转
|
||||
const correctPathToRoot = pathToRoot // [task-0, task-1, task-2, ...]
|
||||
const correctBranchParentChain = [...branchParentChain].reverse() // 顶层分支 → ... → 直接父分支(正序)
|
||||
|
||||
// 合并:主流程路径(正序) + 分支父节点链(正序) + 分支子节点(正序)
|
||||
nodesToHighlight = [...correctPathToRoot, ...correctBranchParentChain, ...branchChildNodes]
|
||||
|
||||
console.log('📋 路径顺序(从上到下、从左到右):', {
|
||||
pathToRoot: correctPathToRoot,
|
||||
branchParentChain: correctBranchParentChain,
|
||||
branchChildNodes: branchChildNodes,
|
||||
total: nodesToHighlight.length
|
||||
})
|
||||
|
||||
// 🆕 找到对应的分支并切换
|
||||
const allBranches = selectionStore.getAllFlowBranches()
|
||||
|
||||
// 根据分支节点找到对应的分支数据
|
||||
@@ -687,7 +604,6 @@ const onNodeClick = (event: any) => {
|
||||
const fullProcessTasks: IRawStepTask[] = []
|
||||
const allBranches = selectionStore.getAllFlowBranches()
|
||||
|
||||
console.log('🔍 开始按高亮路径收集数据,总节点数:', nodesToHighlight.length)
|
||||
|
||||
// 遍历所有高亮节点,收集对应的任务数据
|
||||
nodesToHighlight.forEach(nodeId => {
|
||||
@@ -700,28 +616,20 @@ const onNodeClick = (event: any) => {
|
||||
// 主流程节点:直接从 node.data.task 获取
|
||||
if (node.data.task) {
|
||||
fullProcessTasks.push(node.data.task)
|
||||
console.log(` 📦 添加主流程节点: ${nodeId}, 任务: ${node.data.task.StepName}`)
|
||||
}
|
||||
} else {
|
||||
// 分支节点:从对应的分支数据中获取(按索引匹配)
|
||||
const parentBranch = allBranches.find(branch => branch.nodes.some(n => n.id === nodeId))
|
||||
|
||||
if (parentBranch && parentBranch.tasks) {
|
||||
// 找到该节点在分支节点列表中的索引
|
||||
const nodeIndex = parentBranch.nodes.findIndex(n => n.id === nodeId)
|
||||
if (nodeIndex !== -1 && parentBranch.tasks[nodeIndex]) {
|
||||
const taskData = parentBranch.tasks[nodeIndex]
|
||||
fullProcessTasks.push(taskData)
|
||||
console.log(
|
||||
` 📦 添加分支节点: ${nodeId}, 分支: ${parentBranch.branchContent}, 索引: ${nodeIndex}, 任务: ${taskData.StepName}`
|
||||
)
|
||||
fullProcessTasks.push(parentBranch.tasks[nodeIndex])
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log(`✅ 数据收集完成,总任务数: ${fullProcessTasks.length}`)
|
||||
|
||||
// 更新 agentsStore 的数据为完整路径的任务
|
||||
agentsStore.setAgentRawPlan({
|
||||
data: {
|
||||
@@ -729,11 +637,9 @@ const onNodeClick = (event: any) => {
|
||||
'Collaboration Process': JSON.parse(JSON.stringify(fullProcessTasks))
|
||||
}
|
||||
})
|
||||
console.log('🔄 已切换到分支:', matchedBranch.branchContent)
|
||||
|
||||
// 🆕 保存最后选中的分支ID
|
||||
sessionStorage.setItem(LAST_SELECTED_BRANCH_KEY, matchedBranch.id)
|
||||
console.log('💾 已保存最后选中的分支ID:', matchedBranch.id)
|
||||
}
|
||||
} else {
|
||||
// 如果找不到父节点,只高亮分支节点(父节点链 + 子节点)
|
||||
@@ -744,7 +650,6 @@ const onNodeClick = (event: any) => {
|
||||
// 更新选中的节点集合
|
||||
selectedNodeIds.value = new Set(nodesToHighlight)
|
||||
|
||||
console.log('高亮节点:', nodesToHighlight)
|
||||
}
|
||||
|
||||
// 编辑任务
|
||||
@@ -767,7 +672,6 @@ const handleCancelAddBranch = () => {
|
||||
|
||||
// 添加分支
|
||||
const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
console.log('添加分支:', { taskId, branchContent })
|
||||
|
||||
// 获取父节点
|
||||
const parentNode = nodes.value.find(n => n.id === taskId)
|
||||
@@ -786,10 +690,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
node.position.y += 200
|
||||
})
|
||||
|
||||
console.log(
|
||||
`📍 移动了 ${branchesBelowParent.length} 个分支(Y坐标 > ${parentNodeY}),总共 ${allExistingBranchNodes.length} 个分支`
|
||||
)
|
||||
|
||||
// 开始加载
|
||||
branchLoading.value = true
|
||||
|
||||
@@ -824,7 +724,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
|
||||
if (USE_MOCK_DATA) {
|
||||
// 使用 Mock API
|
||||
console.log('[Mock] 调用 mockBranchPlanOutline API')
|
||||
const generalGoal = agentsStore.agentRawPlan.data?.['General Goal'] || ''
|
||||
const initialInput = agentsStore.agentRawPlan.data?.['Initial Input Object'] || []
|
||||
|
||||
@@ -855,13 +754,11 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks = response['Collaboration Process'] || []
|
||||
|
||||
// ========== 填充每个任务的 TaskProcess ==========
|
||||
console.log('[Mock] 开始调用 fill_stepTask 填充任务流程')
|
||||
for (let i = 0; i < newTasks.length; i++) {
|
||||
const task = newTasks[i]
|
||||
if (!task) continue
|
||||
|
||||
try {
|
||||
console.log(`[Mock] 填充任务 ${i + 1}/${newTasks.length}: ${task.StepName}`)
|
||||
const filledTask = await api.mockFillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
@@ -870,17 +767,12 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks[i]!.AgentSelection = filledTask.AgentSelection
|
||||
newTasks[i]!.TaskProcess = filledTask.TaskProcess
|
||||
newTasks[i]!.Collaboration_Brief_frontEnd = filledTask.Collaboration_Brief_frontEnd
|
||||
console.log(
|
||||
`[Mock] 任务 ${task.StepName} 填充成功,Agent 数量: ${
|
||||
filledTask.AgentSelection?.length || 0
|
||||
}, 流程数: ${filledTask.TaskProcess?.length || 0}`
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(`[Mock] 填充任务 ${task.StepName} 失败:`, error)
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
ElMessage.success('[Mock] 任务大纲分支创建成功')
|
||||
ElMessage.success('任务大纲分支创建成功')
|
||||
} else {
|
||||
// 调用真实 API
|
||||
const generalGoal = agentsStore.agentRawPlan.data?.['General Goal'] || ''
|
||||
@@ -912,18 +804,13 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks = response?.[0] || []
|
||||
|
||||
// 调试日志:验证数据提取
|
||||
console.log('[DEBUG] branch_PlanOutline API response:', response)
|
||||
console.log('[DEBUG] 提取到的 newTasks:', newTasks)
|
||||
console.log('[DEBUG] newTasks.length:', newTasks.length)
|
||||
|
||||
// ========== 填充每个任务的 TaskProcess ==========
|
||||
console.log('[Real API] 开始调用 fill_stepTask 填充任务流程')
|
||||
for (let i = 0; i < newTasks.length; i++) {
|
||||
const task = newTasks[i]
|
||||
if (!task) continue
|
||||
|
||||
try {
|
||||
console.log(`[Real API] 填充任务 ${i + 1}/${newTasks.length}: ${task.StepName}`)
|
||||
const filledTask = await api.fillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
@@ -932,13 +819,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks[i]!.AgentSelection = filledTask.AgentSelection
|
||||
newTasks[i]!.TaskProcess = filledTask.TaskProcess
|
||||
newTasks[i]!.Collaboration_Brief_frontEnd = filledTask.Collaboration_Brief_frontEnd
|
||||
console.log(
|
||||
`[Real API] 任务 ${task.StepName} 填充成功,Agent 数量: ${
|
||||
filledTask.AgentSelection?.length || 0
|
||||
}, 流程数: ${filledTask.TaskProcess?.length || 0}`
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(`[Real API] 填充任务 ${task.StepName} 失败:`, error)
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,7 +854,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
isEditing: false,
|
||||
editingContent: '',
|
||||
isBranchTask: true, // 标记为分支任务,可用于特殊样式
|
||||
branchId: String(timestamp) // 添加分支ID,用于识别和分组
|
||||
branchId: String(timestamp), // 添加分支ID,用于识别和分组
|
||||
updateKey: Date.now() // 添加更新时间戳,用于强制组件重新渲染
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1014,7 +897,7 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 📂 保存分支数据到 store
|
||||
// 保存分支数据到 store
|
||||
if (newBranchNodes.length > 0) {
|
||||
selectionStore.addFlowBranch({
|
||||
parentNodeId: taskId,
|
||||
@@ -1024,8 +907,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
edges: newBranchEdges,
|
||||
tasks: JSON.parse(JSON.stringify(newTasks))
|
||||
})
|
||||
|
||||
console.log('✅ 新分支已创建')
|
||||
}
|
||||
} else {
|
||||
// ========== 任务节点级别分支 ==========
|
||||
@@ -1037,7 +918,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
|
||||
if (USE_MOCK_DATA) {
|
||||
// 使用 Mock API
|
||||
console.log('[Mock] 调用 mockBranchPlanOutline API')
|
||||
const generalGoal = agentsStore.agentRawPlan.data?.['General Goal'] || ''
|
||||
const initialInput = agentsStore.agentRawPlan.data?.['Initial Input Object'] || []
|
||||
|
||||
@@ -1068,13 +948,11 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks = response['Collaboration Process'] || []
|
||||
|
||||
// ========== 填充每个任务的 TaskProcess ==========
|
||||
console.log('[Mock] 开始调用 fill_stepTask 填充任务流程')
|
||||
for (let i = 0; i < newTasks.length; i++) {
|
||||
const task = newTasks[i]
|
||||
if (!task) continue
|
||||
|
||||
try {
|
||||
console.log(`[Mock] 填充任务 ${i + 1}/${newTasks.length}: ${task.StepName}`)
|
||||
const filledTask = await api.mockFillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
@@ -1083,17 +961,12 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks[i]!.AgentSelection = filledTask.AgentSelection
|
||||
newTasks[i]!.TaskProcess = filledTask.TaskProcess
|
||||
newTasks[i]!.Collaboration_Brief_frontEnd = filledTask.Collaboration_Brief_frontEnd
|
||||
console.log(
|
||||
`[Mock] 任务 ${task.StepName} 填充成功,Agent 数量: ${
|
||||
filledTask.AgentSelection?.length || 0
|
||||
}, 流程数: ${filledTask.TaskProcess?.length || 0}`
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(`[Mock] 填充任务 ${task.StepName} 失败:`, error)
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
ElMessage.success('[Mock] 任务大纲分支创建成功')
|
||||
ElMessage.success('任务大纲分支创建成功')
|
||||
} else {
|
||||
// 调用真实 API
|
||||
const generalGoal = agentsStore.agentRawPlan.data?.['General Goal'] || ''
|
||||
@@ -1125,18 +998,13 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks = response?.[0] || []
|
||||
|
||||
// 调试日志:验证数据提取
|
||||
console.log('[DEBUG] branch_PlanOutline API response:', response)
|
||||
console.log('[DEBUG] 提取到的 newTasks:', newTasks)
|
||||
console.log('[DEBUG] newTasks.length:', newTasks.length)
|
||||
|
||||
// ========== 填充每个任务的 TaskProcess ==========
|
||||
console.log('[Real API] 开始调用 fill_stepTask 填充任务流程')
|
||||
for (let i = 0; i < newTasks.length; i++) {
|
||||
const task = newTasks[i]
|
||||
if (!task) continue
|
||||
|
||||
try {
|
||||
console.log(`[Real API] 填充任务 ${i + 1}/${newTasks.length}: ${task.StepName}`)
|
||||
const filledTask = await api.fillStepTask({
|
||||
goal: generalGoal,
|
||||
stepTask: task
|
||||
@@ -1145,13 +1013,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
newTasks[i]!.AgentSelection = filledTask.AgentSelection
|
||||
newTasks[i]!.TaskProcess = filledTask.TaskProcess
|
||||
newTasks[i]!.Collaboration_Brief_frontEnd = filledTask.Collaboration_Brief_frontEnd
|
||||
console.log(
|
||||
`[Real API] 任务 ${task.StepName} 填充成功,Agent 数量: ${
|
||||
filledTask.AgentSelection?.length || 0
|
||||
}, 流程数: ${filledTask.TaskProcess?.length || 0}`
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(`[Real API] 填充任务 ${task.StepName} 失败:`, error)
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1184,7 +1047,8 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
task,
|
||||
isEditing: false,
|
||||
editingContent: '',
|
||||
isBranchTask: true // 标记为分支任务,可用于特殊样式
|
||||
isBranchTask: true, // 标记为分支任务,可用于特殊样式
|
||||
updateKey: Date.now() // 添加更新时间戳,用于强制组件重新渲染
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1237,7 +1101,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
tasks: JSON.parse(JSON.stringify(newTasks))
|
||||
})
|
||||
|
||||
console.log('✅ 新分支已创建')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1251,7 +1114,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
}, 100)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('添加分支失败:', error)
|
||||
ElMessage.error('添加分支失败,请重试')
|
||||
// 重置当前添加分支的节点 ID
|
||||
currentAddingBranchNodeId.value = null
|
||||
@@ -1262,7 +1124,6 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
|
||||
|
||||
// 删除分支
|
||||
const handleDeleteBranch = (branchId: string) => {
|
||||
console.log('删除分支:', branchId)
|
||||
|
||||
// 删除分支节点
|
||||
nodes.value = nodes.value.filter(n => n.id !== branchId)
|
||||
|
||||
@@ -337,7 +337,8 @@ export const useAgentsStore = defineStore('agents', () => {
|
||||
if (plan.data) {
|
||||
plan.data['Collaboration Process'] = plan.data['Collaboration Process']?.map((item) => ({
|
||||
...item,
|
||||
Id: uuidv4(),
|
||||
// ✅ 只在任务没有 Id 时才生成新的 ID,保持已存在任务的 Id 不变
|
||||
Id: item.Id || uuidv4(),
|
||||
}))
|
||||
}
|
||||
agentRawPlan.value = {
|
||||
|
||||
Reference in New Issue
Block a user