From 5e4e0b7f15e454e97764a3f81d5973cc520e7763 Mon Sep 17 00:00:00 2001 From: liailing1026 <1815388873@qq.com> Date: Mon, 16 Mar 2026 16:23:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E5=A4=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E7=BC=96=E6=8E=92=E4=B8=AD=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=88=86=E6=94=AF=E5=88=A0=E9=99=A4=E5=8D=95=E4=B8=AA=E8=8A=82?= =?UTF-8?q?=E7=82=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/backend/server.py b/backend/server.py index ca23f28..8998d54 100644 --- a/backend/server.py +++ b/backend/server.py @@ -2804,6 +2804,7 @@ def handle_delete_task_process_node(data): for branch in branches_list: if branch.get('id') == branch_id: # 找到目标分支,删除指定的节点 + target_branch_content = branch.get('branchContent') # 保存branchContent用于匹配flow_branches nodes = branch.get('nodes', []) tasks = branch.get('tasks', []) @@ -2815,14 +2816,47 @@ def handle_delete_task_process_node(data): break if node_to_delete: + # 先获取 original_index(删除前获取,用于同步 flow_branches) + node_data = node_to_delete.get('data', {}) + original_index = node_data.get('originalIndex') + + # ========== 同步更新 flow_branches (在删除前执行) ========== + if original_index is not None: + flow_branches = existing_branches.get('flow_branches', []) + if isinstance(flow_branches, list): + # 在 nodes 中查找并删除 + for flow_branch in flow_branches: + flow_nodes = flow_branch.get('nodes', []) + if isinstance(flow_nodes, list): + for flow_node in flow_nodes: + flow_node_data = flow_node.get('data', {}) + task_data = flow_node_data.get('task', {}) + if task_data.get('Id') == step_id: + task_process = task_data.get('TaskProcess', []) + if 0 <= original_index < len(task_process): + task_process.pop(original_index) + task_data['TaskProcess'] = task_process + break + + # 在 tasks 中查找并删除 + for flow_branch in flow_branches: + flow_tasks = flow_branch.get('tasks', []) + if isinstance(flow_tasks, list): + for task_item in flow_tasks: + if task_item.get('Id') == step_id: + task_process = task_item.get('TaskProcess', []) + if 0 <= original_index < len(task_process): + task_process.pop(original_index) + task_item['TaskProcess'] = task_process + break + + existing_branches['flow_branches'] = flow_branches + # ========== 同步更新 flow_branches 结束 ========== + # 从 nodes 中删除 nodes = [n for n in nodes if n.get('id') != node_id] # 从 tasks 中删除:使用 originalIndex 精确匹配 - # nodes 包含 root 节点,所以 agent 节点的 originalIndex 对应 tasks 的索引 - node_data = node_to_delete.get('data', {}) - original_index = node_data.get('originalIndex') - if original_index is not None and 0 <= original_index < len(tasks): tasks.pop(original_index) else: