feat:执行过程编排新建分支单节点删除和整个分支节点删除

This commit is contained in:
liailing1026
2026-03-06 11:22:56 +08:00
parent 8cd3152c29
commit 73232babdc
4 changed files with 475 additions and 30 deletions

View File

@@ -2508,6 +2508,114 @@ def handle_delete_task_process_branch(data):
})
@socketio.on('delete_task_process_node')
def handle_delete_task_process_node(data):
"""
WebSocket版本删除任务过程分支中的单个节点
请求格式:
{
"id": "request-id",
"action": "delete_task_process_node",
"data": {
"task_id": "task-id", // 大任务ID数据库主键
"stepId": "step-id", // 小任务ID
"branchId": "branch-id", // 分支ID
"nodeId": "node-id" // 要删除的节点ID
}
}
"""
request_id = data.get('id')
incoming_data = data.get('data', {})
task_id = incoming_data.get('task_id')
step_id = incoming_data.get('stepId')
branch_id = incoming_data.get('branchId')
node_id = incoming_data.get('nodeId')
edges = incoming_data.get('edges', []) # 更新后的 edges 数据
if not task_id or not step_id or not branch_id or not node_id:
emit('response', {
'id': request_id,
'status': 'error',
'error': '缺少必要参数task_id, stepId, branchId, nodeId'
})
return
try:
with get_db_context() as db:
# 获取现有的 branches 数据
existing_task = MultiAgentTaskCRUD.get_by_id(db, task_id)
if existing_task:
# 使用深拷贝避免修改共享引用
existing_branches = copy.deepcopy(existing_task.branches) if existing_task.branches else {}
if isinstance(existing_branches, dict):
# 获取现有的 task_process_branches
task_process_branches = existing_branches.get('task_process_branches', {})
if step_id in task_process_branches:
step_branches = task_process_branches[step_id]
# 遍历所有 agentGroupKey 下的分支
for agent_key, branches_list in step_branches.items():
if isinstance(branches_list, list):
for branch in branches_list:
if branch.get('id') == branch_id:
# 找到目标分支,删除指定的节点
nodes = branch.get('nodes', [])
tasks = branch.get('tasks', [])
# 找到并删除节点
for i, node in enumerate(nodes):
if node.get('id') == node_id:
nodes.pop(i)
if i < len(tasks):
tasks.pop(i)
break
# 更新分支数据(包括 nodes, tasks, edges
branch['nodes'] = nodes
branch['tasks'] = tasks
branch['edges'] = edges # 使用前端传入的更新后的 edges
break
# 更新 branches 数据
existing_branches['task_process_branches'] = task_process_branches
# 直接更新数据库
existing_task.branches = existing_branches
db.flush()
db.commit()
print(f"[delete_task_process_node] 删除成功task_id={task_id}, step_id={step_id}, branch_id={branch_id}, node_id={node_id}")
emit('response', {
'id': request_id,
'status': 'success',
'data': {
"message": "节点删除成功",
"deleted_node_id": node_id
}
})
return
# 如果找不到对应的节点
print(f"[delete_task_process_node] 警告: 找不到要删除的节点task_id={task_id}, step_id={step_id}, branch_id={branch_id}, node_id={node_id}")
emit('response', {
'id': request_id,
'status': 'error',
'error': '未找到要删除的节点'
})
except Exception as e:
emit('response', {
'id': request_id,
'status': 'error',
'error': str(e)
})
@socketio.on('save_task_outline')
def handle_save_task_outline(data):
"""