feat:执行状态单例状态bug修复

This commit is contained in:
liailing1026
2026-02-02 17:09:20 +08:00
parent f272ccc390
commit 328f8e7ec6
12 changed files with 899 additions and 278 deletions

View File

@@ -679,10 +679,13 @@ const submitBranch = async () => {
goal: generalGoal
})
// WebSocket 返回格式: { data: [[action1, action2], [action3, action4]], ... }
// REST API 返回格式: [[action1, action2], [action3, action4]]
const responseData = response.data || response
// 后端返回格式: [[action1, action2], [action3, action4]]
// 取第一个分支
if (response && response.length > 0) {
const firstBranch = response[0]
if (responseData && responseData.length > 0) {
const firstBranch = responseData[0]
// 直接遍历 action 数组
firstBranch.forEach((action: any) => {
@@ -974,10 +977,13 @@ const submitBranch = async () => {
goal: generalGoal
})
// WebSocket 返回格式: { data: [[action1, action2], [action3, action4]], ... }
// REST API 返回格式: [[action1, action2], [action3, action4]]
const responseData = response.data || response
// 后端返回格式: [[action1, action2], [action3, action4]]
// 取第一个分支
if (response && response.length > 0) {
const firstBranch = response[0]
if (responseData && responseData.length > 0) {
const firstBranch = responseData[0]
// 直接遍历 action 数组
firstBranch.forEach((action: any) => {

View File

@@ -480,8 +480,14 @@ async function handlePauseResume() {
// 正常恢复执行
try {
if (websocket.connected) {
// 检查 execution_id 是否存在
if (!currentExecutionId.value) {
warning('无法恢复', '执行ID不存在请等待执行开始')
return
}
await websocket.send('resume_execution', {
execution_id: currentExecutionId.value || ''
execution_id: currentExecutionId.value
})
isPaused.value = false
@@ -498,12 +504,19 @@ async function handlePauseResume() {
// 暂停执行
try {
if (websocket.connected) {
// 检查 execution_id 是否存在
if (!currentExecutionId.value) {
warning('无法暂停', '执行ID不存在请等待执行开始')
isPausing.value = false
return
}
// 先设置 isPausing允许接收当前正在执行的动作的结果
isPausing.value = true
info('暂停中', '正在等待当前动作完成')
await websocket.send('pause_execution', {
execution_id: currentExecutionId.value || ''
execution_id: currentExecutionId.value
})
/*不立即设置 isPaused = true
@@ -881,11 +894,14 @@ async function restartFromStep(stepIndex: number) {
// 清空修改记录
agentsStore.clearModifiedSteps()
// 保存旧的 execution_id 用于停止
const oldExecutionId = currentExecutionId.value
// 停止旧的执行
if (websocket.connected && currentExecutionId.value) {
if (websocket.connected && oldExecutionId) {
try {
const stopResponse = await websocket.send('stop_execution', {
execution_id: currentExecutionId.value || ''
await websocket.send('stop_execution', {
execution_id: oldExecutionId
})
// 等待一下确保后端完全停止
await new Promise(resolve => setTimeout(resolve, 1000))
@@ -893,6 +909,13 @@ async function restartFromStep(stepIndex: number) {
console.warn('⚠️ 停止旧执行失败(可能已经停止):', err)
}
}
// 前端生成新的 execution_id确保前端和后端使用同一个 ID
const generalGoal = agentsStore.agentRawPlan.data?.['General Goal'] || ''
const newExecutionId = `${generalGoal.replace(/\s+/g, '_')}_${Date.now()}`
currentExecutionId.value = newExecutionId
console.log('🔄 [DEBUG] restartFromStep: 生成新的 execution_id =', newExecutionId)
// 构建截断后的 RehearsalLog
const truncatedLog = buildTruncatedRehearsalLog(stepIndex)
@@ -936,7 +959,7 @@ async function restartFromStep(stepIndex: number) {
isStreaming.value = true
currentExecutionId.value = executionId
},
undefined,
newExecutionId, // 传入前端生成的 execution_id
stepIndex,
truncatedLog
)
@@ -1007,8 +1030,41 @@ async function handleTaskProcess() {
}
// 重置执行结果
function handleRefresh() {
async function handleRefresh() {
// 如果有正在执行的任务,先通知后端停止
if (websocket.connected && currentExecutionId.value) {
try {
await websocket.send('stop_execution', {
execution_id: currentExecutionId.value
})
// 等待一下确保后端完全停止
await new Promise(resolve => setTimeout(resolve, 500))
} catch (err) {
console.warn('⚠️ 停止执行失败(可能已经停止):', err)
}
}
// 重置所有状态
agentsStore.setExecutePlan([])
stepExecutionStatus.value = {}
sentStepIds.value.clear()
currentExecutionId.value = null
isPaused.value = false
isStreaming.value = false
isPausing.value = false
loading.value = false
isRestarting.value = false
// 重置进度通知标题
currentProgressTitle.value = '任务执行中'
// 关闭进度通知
if (currentProgressNotificationId.value) {
removeNotification(currentProgressNotificationId.value)
currentProgressNotificationId.value = null
}
success('已重置', '执行状态已重置')
}
// 添加滚动状态指示器

View File

@@ -797,13 +797,16 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
goal: generalGoal
})
// WebSocket 返回格式: { data: [[{...}]], ... }
// REST API 返回格式: [[{...}]]
const responseData = response.data || response
// 直接获取协作流程数据
if (Array.isArray(response)) {
if (Array.isArray(responseData)) {
// 可能是二维数组
newTasks = (response as any[])[0] || []
} else if (response && (response as any)['Collaboration Process']) {
newTasks = responseData[0] || []
} else if (responseData && responseData['Collaboration Process']) {
// 如果返回的是对象,尝试读取 Collaboration Process 字段
newTasks = (response as any)['Collaboration Process'] || []
newTasks = responseData['Collaboration Process'] || []
} else {
newTasks = []
}
@@ -1136,14 +1139,17 @@ const handleAddBranch = async (taskId: string, branchContent: string) => {
initialInputs: Array.isArray(initialInput) ? initialInput : [initialInput],
goal: generalGoal
})
// WebSocket 返回格式: { data: [[{...}]], ... }
// REST API 返回格式: [[{...}]]
const responseData = response.data || response
// 直接获取协作流程数据
// newTasks = response?.[0] || []
if (Array.isArray(response)) {
if (Array.isArray(responseData)) {
// 可能是二维数组
newTasks = (response as any[])[0] || []
} else if (response && (response as any)['Collaboration Process']) {
newTasks = responseData[0] || []
} else if (responseData && responseData['Collaboration Process']) {
// 如果返回的是对象,尝试读取 Collaboration Process 字段
newTasks = (response as any)['Collaboration Process'] || []
newTasks = responseData['Collaboration Process'] || []
} else {
newTasks = []
}