feat:执行过程编排页面重构及删除功能新增
This commit is contained in:
@@ -2381,6 +2381,118 @@ def handle_save_task_process_branches(data):
|
||||
})
|
||||
|
||||
|
||||
@socketio.on('delete_task_process_branch')
|
||||
def handle_delete_task_process_branch(data):
|
||||
"""
|
||||
WebSocket版本:删除任务过程分支数据
|
||||
|
||||
请求格式:
|
||||
{
|
||||
"id": "request-id",
|
||||
"action": "delete_task_process_branch",
|
||||
"data": {
|
||||
"task_id": "task-id", // 大任务ID(数据库主键)
|
||||
"stepId": "step-id", // 小任务ID
|
||||
"branchId": "branch-id" // 要删除的分支ID
|
||||
}
|
||||
}
|
||||
|
||||
数据库存储格式:
|
||||
{
|
||||
"branches": {
|
||||
"flow_branches": [...],
|
||||
"task_process_branches": {
|
||||
"stepId-1": {
|
||||
'["AgentA","AgentB"]': [{...分支数据...}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
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')
|
||||
|
||||
if not task_id or not step_id or not branch_id:
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': '缺少必要参数:task_id, stepId, branchId'
|
||||
})
|
||||
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:
|
||||
# 获取该 stepId 下的所有 agent 分支
|
||||
step_branches = task_process_branches[step_id]
|
||||
|
||||
# 遍历所有 agentGroupKey,删除对应分支
|
||||
for agent_key, branches_list in step_branches.items():
|
||||
# 过滤掉要删除的分支
|
||||
filtered_branches = [b for b in branches_list if b.get('id') != branch_id]
|
||||
|
||||
if len(filtered_branches) != len(branches_list):
|
||||
# 有分支被删除,更新数据
|
||||
if filtered_branches:
|
||||
step_branches[agent_key] = filtered_branches
|
||||
else:
|
||||
# 如果该 agentKey 下没有分支了,删除该 key
|
||||
del step_branches[agent_key]
|
||||
|
||||
# 如果该 stepId 下没有分支了,删除该 stepId
|
||||
if not step_branches:
|
||||
del task_process_branches[step_id]
|
||||
|
||||
# 更新 branches 数据
|
||||
existing_branches['task_process_branches'] = task_process_branches
|
||||
|
||||
# 直接更新数据库
|
||||
existing_task.branches = existing_branches
|
||||
db.flush()
|
||||
db.commit()
|
||||
|
||||
print(f"[delete_task_process_branch] 删除成功,task_id={task_id}, step_id={step_id}, branch_id={branch_id}")
|
||||
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'success',
|
||||
'data': {
|
||||
"message": "分支删除成功",
|
||||
"deleted_branch_id": branch_id
|
||||
}
|
||||
})
|
||||
return
|
||||
|
||||
# 如果找不到对应的分支
|
||||
print(f"[delete_task_process_branch] 警告: 找不到要删除的分支,task_id={task_id}, step_id={step_id}, branch_id={branch_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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user