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

@@ -426,6 +426,7 @@ class Api {
fillStepTask = async (data: {
goal: string
stepTask: any
generation_id?: string
useWebSocket?: boolean
onProgress?: (progress: {
status: string
@@ -444,6 +445,7 @@ class Api {
{
'General Goal': data.goal,
stepTask: data.stepTask,
generation_id: data.generation_id || '',
},
undefined,
data.onProgress,
@@ -484,7 +486,7 @@ class Api {
}
// 使用重试机制执行请求
const response = await withRetry(executeRequest, {
const rawResponse = await withRetry(executeRequest, {
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
@@ -492,6 +494,10 @@ class Api {
},
})
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
const vec2Hsl = (color: number[]): string => {
const [h, s, l] = color
return `hsl(${h}, ${s}%, ${l}%)`
@@ -606,14 +612,21 @@ class Api {
}
// 使用重试机制执行请求
const response = await withRetry(executeRequest, {
const rawResponse = await withRetry(executeRequest, {
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
console.warn(`⚠️ [fillStepTaskTaskProcess] 第${attempt}次重试,等待 ${delay}ms...`, error?.message)
console.warn(
`⚠️ [fillStepTaskTaskProcess] 第${attempt}次重试,等待 ${delay}ms...`,
error?.message,
)
},
})
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
const vec2Hsl = (color: number[]): string => {
const [h, s, l] = color
return `hsl(${h}, ${s}%, ${l}%)`
@@ -688,7 +701,9 @@ class Api {
})
// 定义实际的 API 调用逻辑
const executeRequest = async (): Promise<Record<string, Record<string, { Reason: string; Score: number }>>> => {
const executeRequest = async (): Promise<
Record<string, Record<string, { Reason: string; Score: number }>>
> => {
if (useWs && websocket.connected) {
return await websocket.send(
'agent_select_modify_init',
@@ -712,18 +727,31 @@ class Api {
}
// 使用重试机制执行请求
const response = await withRetry(executeRequest, {
const rawResponse = await withRetry(executeRequest, {
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
console.warn(`⚠️ [agentSelectModifyInit] 第${attempt}次重试,等待 ${delay}ms...`, error?.message)
console.warn(
`⚠️ [agentSelectModifyInit] 第${attempt}次重试,等待 ${delay}ms...`,
error?.message,
)
},
})
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
const transformedData: Record<string, Record<string, { reason: string; score: number }>> = {}
// 确保 response 存在且是有效对象
if (!response || typeof response !== 'object' || Array.isArray(response)) {
console.warn('[agentSelectModifyInit] 后端返回数据格式异常:', response)
return transformedData
}
for (const [aspect, agents] of Object.entries(response)) {
for (const [agentName, scoreInfo] of Object.entries(agents)) {
for (const [agentName, scoreInfo] of Object.entries(agents as Record<string, { Reason: string; Score: number }> || {})) {
if (!transformedData[agentName]) {
transformedData[agentName] = {}
}
@@ -758,7 +786,7 @@ class Api {
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
response = await websocket.send(
const rawResponse = await websocket.send(
'agent_select_modify_add_aspect',
{
aspectList: data.aspectList,
@@ -766,6 +794,8 @@ class Api {
undefined,
data.onProgress,
)
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
response = rawResponse.data || rawResponse
} else {
// 否则使用REST API
response = await request<
@@ -818,7 +848,7 @@ class Api {
throw new Error('WebSocket未连接')
}
const response = (await websocket.send('add_steps_to_execution', {
const rawResponse = await websocket.send('add_steps_to_execution', {
execution_id: executionId,
new_steps: newSteps.map((step) => ({
StepName: step.StepName,
@@ -835,7 +865,11 @@ class Api {
ImportantInput: action.ImportantInput,
})),
})),
})) as { added_count: number }
})
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = (rawResponse.data || rawResponse) as { added_count: number }
return response?.added_count || 0
}