feat:执行过程编排页面重构及删除功能新增

This commit is contained in:
liailing1026
2026-03-03 09:56:58 +08:00
parent f0f0d5bdcd
commit 2be5a5a454
5 changed files with 739 additions and 336 deletions

View File

@@ -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):
"""

View File

@@ -677,6 +677,37 @@ class Api {
}
}
/**
* 删除任务过程分支数据
* @param TaskID 大任务ID
* @param stepId 小任务ID
* @param branchId 要删除的分支ID
* @returns 是否删除成功
*/
deleteTaskProcessBranch = async (
TaskID: string,
stepId: string,
branchId: string,
): Promise<boolean> => {
if (!websocket.connected) {
throw new Error('WebSocket未连接')
}
try {
const rawResponse = await websocket.send('delete_task_process_branch', {
task_id: TaskID,
stepId,
branchId,
})
const response = this.extractResponse<{ status: string }>(rawResponse)
return response?.status === 'success' || false
} catch (error) {
console.error('删除任务过程分支数据失败:', error)
return false
}
}
/**
* 更新任务大纲数据
* @param taskId 任务ID

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { ref, computed, watch, nextTick } from 'vue'
import { useAgentsStore } from '@/stores'
import SvgIcon from '@/components/SvgIcon/index.vue'
import PlanModification from './TaskSyllabus/Branch/PlanModification.vue'
@@ -13,6 +13,9 @@ const visible = ref(false)
const activeTab = ref('outline')
const isMaximized = ref(false)
// PlanTask 组件引用
const planTaskRef = ref<InstanceType<typeof PlanTask> | null>(null)
// 判断是否有流程数据
const planReady = computed(() => {
return agentsStore.agentRawPlan.data !== undefined
@@ -66,6 +69,18 @@ const handleTabChange = (tabKey: string) => {
activeTab.value = tabKey
}
// 切换到执行过程编排时,延迟触发自适应视图
watch(activeTab, (newTab) => {
if (newTab === 'process') {
nextTick(() => {
setTimeout(() => {
// 通过 expose 的方法触发自适应视图(如果有的话)
;(planTaskRef.value as any)?.triggerFitView?.()
}, 400)
})
}
})
// 切换最大化/还原
const toggleMaximize = () => {
isMaximized.value = !isMaximized.value
@@ -126,7 +141,7 @@ defineExpose({
<!-- 任务过程 -->
<div v-show="activeTab === 'process'" class="tab-content">
<PlanTask />
<PlanTask ref="planTaskRef" />
</div>
</div>
</div>

View File

@@ -310,6 +310,26 @@ export const useSelectionStore = defineStore('selection', () => {
return result
}
/**
* 从数据库删除指定分支
* @param TaskID 大任务ID数据库主键
* @param stepId 小任务ID
* @param branchId 要删除的分支ID
* @returns Promise<boolean> 是否删除成功
*/
async function deleteTaskProcessBranchFromDB(
TaskID: string,
stepId: string,
branchId: string,
): Promise<boolean> {
// 导入 api避免循环导入问题
const { default: api } = await import('@/api')
const result = await api.deleteTaskProcessBranch(TaskID, stepId, branchId)
return result
}
/**
* 从数据库恢复任务过程分支数据
* @param dbBranches 从数据库读取的任务过程分支数据
@@ -676,6 +696,7 @@ export const useSelectionStore = defineStore('selection', () => {
saveBranchesToDB,
restoreAgentCombinationsFromDB,
saveTaskProcessBranchesToDB,
deleteTaskProcessBranchFromDB,
restoreTaskProcessBranchesFromDB,
}
})