Files
AgentCoord/frontend/src/api/index.ts

879 lines
25 KiB
TypeScript
Raw Normal View History

import request from '@/utils/request'
import websocket from '@/utils/websocket'
2026-01-09 13:54:32 +08:00
import type { Agent, IApiStepTask, IRawPlanResponse, IRawStepTask } from '@/stores'
2026-01-30 15:27:00 +08:00
import { withRetry } from '@/utils/retry'
export interface ActionHistory {
ID: string
ActionType: string
AgentName: string
Description: string
ImportantInput: string[]
Action_Result: string
}
2026-01-30 15:27:00 +08:00
export interface BranchAction {
ID: string
ActionType: string
AgentName: string
Description: string
ImportantInput: string[]
}
export type IExecuteRawResponse = {
LogNodeType: string
NodeId: string
InputName_List?: string[] | null
OutputName?: string
content?: string
ActionHistory: ActionHistory[]
}
2026-01-21 15:18:15 +08:00
/**
* SSE
*/
export type StreamingEvent =
| {
type: 'step_start'
step_index: number
total_steps: number
step_name: string
task_description?: string
}
| {
type: 'action_complete'
step_index: number
step_name: string
action_index: number
total_actions: number
completed_actions: number
action_result: ActionHistory
batch_info?: {
batch_index: number
batch_size: number
is_parallel: boolean
}
}
| {
type: 'step_complete'
step_index: number
step_name: string
step_log_node: any
object_log_node: any
}
| {
type: 'execution_complete'
total_steps: number
}
| {
type: 'error'
message: string
}
2025-12-31 19:04:58 +08:00
export interface IFillAgentSelectionRequest {
goal: string
stepTask: IApiStepTask
agents: string[]
}
class Api {
// 默认使用WebSocket
private useWebSocketDefault = true
2026-01-30 15:27:00 +08:00
setAgents = (
data: Pick<Agent, 'Name' | 'Profile' | 'apiUrl' | 'apiKey' | 'apiModel'>[],
useWebSocket: boolean = this.useWebSocketDefault,
) => {
// 如果启用WebSocket且已连接使用WebSocket
if (useWebSocket && websocket.connected) {
return websocket.send('set_agents', data)
}
// 否则使用REST API
return request({
url: '/setAgents',
data,
method: 'POST',
})
}
generateBasePlan = (data: {
goal: string
inputs: string[]
apiUrl?: string
apiKey?: string
apiModel?: string
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
}) => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
2026-01-30 15:27:00 +08:00
return websocket.send(
'generate_base_plan',
{
'General Goal': data.goal,
'Initial Input Object': data.inputs,
apiUrl: data.apiUrl,
apiKey: data.apiKey,
apiModel: data.apiModel,
},
undefined,
data.onProgress,
)
}
// 否则使用REST API
return request<unknown, IRawPlanResponse>({
url: '/generate_basePlan',
method: 'POST',
data: {
'General Goal': data.goal,
'Initial Input Object': data.inputs,
apiUrl: data.apiUrl,
apiKey: data.apiKey,
apiModel: data.apiModel,
},
})
}
executePlan = (plan: IRawPlanResponse) => {
return request<unknown, IExecuteRawResponse[]>({
url: '/executePlan',
method: 'POST',
data: {
RehearsalLog: [],
num_StepToRun: null,
plan: {
'Initial Input Object': plan['Initial Input Object'],
'General Goal': plan['General Goal'],
'Collaboration Process': plan['Collaboration Process']?.map((step) => ({
StepName: step.StepName,
TaskContent: step.TaskContent,
InputObject_List: step.InputObject_List,
OutputObject: step.OutputObject,
AgentSelection: step.AgentSelection,
2025-12-31 19:04:58 +08:00
Collaboration_Brief_frontEnd: step.Collaboration_Brief_frontEnd,
TaskProcess: step.TaskProcess.map((action) => ({
ActionType: action.ActionType,
AgentName: action.AgentName,
Description: action.Description,
ID: action.ID,
ImportantInput: action.ImportantInput,
})),
})),
},
},
})
}
2025-12-31 19:04:58 +08:00
2026-01-21 15:18:15 +08:00
/**
*
* + +
2026-01-21 15:18:15 +08:00
*/
executePlanOptimized = (
plan: IRawPlanResponse,
onMessage: (event: StreamingEvent) => void,
onError?: (error: Error) => void,
onComplete?: () => void,
useWebSocket?: boolean,
existingKeyObjects?: Record<string, any>,
enableDynamic?: boolean,
onExecutionStarted?: (executionId: string) => void,
executionId?: string,
2026-01-30 15:27:00 +08:00
restartFromStepIndex?: number, // 新增:从指定步骤重新执行的索引
rehearsalLog?: any[], // 新增:传递截断后的 RehearsalLog
2026-01-21 15:18:15 +08:00
) => {
const useWs = useWebSocket !== undefined ? useWebSocket : this.useWebSocketDefault
2026-01-21 15:18:15 +08:00
const data = {
2026-01-30 15:27:00 +08:00
RehearsalLog: rehearsalLog || [], // ✅ 使用传递的 RehearsalLog
2026-01-21 15:18:15 +08:00
num_StepToRun: null,
existingKeyObjects: existingKeyObjects || {},
enable_dynamic: enableDynamic || false,
execution_id: executionId || null,
2026-01-30 15:27:00 +08:00
restart_from_step_index: restartFromStepIndex ?? null, // 新增:传递重新执行索引
2026-01-21 15:18:15 +08:00
plan: {
'Initial Input Object': plan['Initial Input Object'],
'General Goal': plan['General Goal'],
'Collaboration Process': plan['Collaboration Process']?.map((step) => ({
StepName: step.StepName,
TaskContent: step.TaskContent,
InputObject_List: step.InputObject_List,
OutputObject: step.OutputObject,
AgentSelection: step.AgentSelection,
Collaboration_Brief_frontEnd: step.Collaboration_Brief_frontEnd,
TaskProcess: step.TaskProcess.map((action) => ({
ActionType: action.ActionType,
AgentName: action.AgentName,
Description: action.Description,
ID: action.ID,
ImportantInput: action.ImportantInput,
})),
})),
},
}
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
websocket.subscribe(
'execute_plan_optimized',
data,
// onProgress
(progressData) => {
try {
let event: StreamingEvent
// 处理不同类型的progress数据
if (typeof progressData === 'string') {
event = JSON.parse(progressData)
} else {
event = progressData as StreamingEvent
}
// 处理特殊事件类型
if (event && typeof event === 'object') {
// 检查是否是execution_started事件
if ('status' in event && event.status === 'execution_started') {
if ('execution_id' in event && onExecutionStarted) {
onExecutionStarted(event.execution_id as string)
}
return
}
}
onMessage(event)
} catch (e) {
// Failed to parse WebSocket data
}
},
// onComplete
() => {
onComplete?.()
},
// onError
(error) => {
onError?.(error)
2026-01-30 15:27:00 +08:00
},
)
return
}
// 否则使用原有的SSE方式
2026-01-21 15:18:15 +08:00
fetch('/api/executePlanOptimized', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(async (response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const reader = response.body?.getReader()
const decoder = new TextDecoder()
if (!reader) {
throw new Error('Response body is null')
}
let buffer = ''
while (true) {
const { done, value } = await reader.read()
if (done) {
onComplete?.()
break
}
buffer += decoder.decode(value, { stream: true })
const lines = buffer.split('\n')
buffer = lines.pop() || ''
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6)
try {
const event = JSON.parse(data)
onMessage(event)
} catch (e) {
// Failed to parse SSE data
2026-01-21 15:18:15 +08:00
}
}
}
}
})
.catch((error) => {
onError?.(error)
})
}
/**
*
*/
2025-12-31 19:04:58 +08:00
branchPlanOutline = (data: {
branch_Number: number
Modification_Requirement: string
Existing_Steps: IRawStepTask[]
2025-12-31 19:04:58 +08:00
Baseline_Completion: number
initialInputs: string[]
goal: string
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
2025-12-31 19:04:58 +08:00
}) => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
2026-01-30 15:27:00 +08:00
return websocket.send(
'branch_plan_outline',
{
branch_Number: data.branch_Number,
Modification_Requirement: data.Modification_Requirement,
Existing_Steps: data.Existing_Steps,
Baseline_Completion: data.Baseline_Completion,
'Initial Input Object': data.initialInputs,
'General Goal': data.goal,
},
undefined,
data.onProgress,
)
}
// 否则使用REST API
2025-12-31 19:04:58 +08:00
return request<unknown, IRawPlanResponse>({
url: '/branch_PlanOutline',
method: 'POST',
data: {
branch_Number: data.branch_Number,
Modification_Requirement: data.Modification_Requirement,
Existing_Steps: data.Existing_Steps,
Baseline_Completion: data.Baseline_Completion,
'Initial Input Object': data.initialInputs,
'General Goal': data.goal,
},
})
}
2026-01-21 15:18:15 +08:00
/**
*
*/
2025-12-31 19:04:58 +08:00
branchTaskProcess = (data: {
branch_Number: number
Modification_Requirement: string
Existing_Steps: BranchAction[]
2025-12-31 19:04:58 +08:00
Baseline_Completion: number
stepTaskExisting: any
goal: string
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
2025-12-31 19:04:58 +08:00
}) => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
2026-01-30 15:27:00 +08:00
return websocket.send(
'branch_task_process',
{
branch_Number: data.branch_Number,
Modification_Requirement: data.Modification_Requirement,
Existing_Steps: data.Existing_Steps,
Baseline_Completion: data.Baseline_Completion,
stepTaskExisting: data.stepTaskExisting,
'General Goal': data.goal,
},
undefined,
data.onProgress,
)
}
// 否则使用REST API
2026-01-09 13:54:32 +08:00
return request<unknown, BranchAction[][]>({
2025-12-31 19:04:58 +08:00
url: '/branch_TaskProcess',
method: 'POST',
data: {
branch_Number: data.branch_Number,
Modification_Requirement: data.Modification_Requirement,
Existing_Steps: data.Existing_Steps,
Baseline_Completion: data.Baseline_Completion,
stepTaskExisting: data.stepTaskExisting,
'General Goal': data.goal,
},
})
}
fillStepTask = async (data: {
goal: string
stepTask: any
2026-02-02 17:09:20 +08:00
generation_id?: string
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
}): Promise<IRawStepTask> => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
2026-01-30 15:27:00 +08:00
// 定义实际的 API 调用逻辑
const executeRequest = async (): Promise<any> => {
if (useWs && websocket.connected) {
return await websocket.send(
'fill_step_task',
{
'General Goal': data.goal,
stepTask: data.stepTask,
2026-02-02 17:09:20 +08:00
generation_id: data.generation_id || '',
2026-01-30 15:27:00 +08:00
},
undefined,
data.onProgress,
)
}
// 否则使用REST API
2026-01-30 15:27:00 +08:00
return await request<
{
'General Goal': string
stepTask: any
},
{
AgentSelection?: string[]
Collaboration_Brief_FrontEnd?: {
template: string
data: Record<string, { text: string; color: number[] }>
}
InputObject_List?: string[]
OutputObject?: string
StepName?: string
TaskContent?: string
TaskProcess?: Array<{
ID: string
ActionType: string
AgentName: string
Description: string
ImportantInput: string[]
}>
}
>({
url: '/fill_stepTask',
method: 'POST',
data: {
'General Goal': data.goal,
stepTask: data.stepTask,
},
})
}
2026-01-09 13:54:32 +08:00
2026-01-30 15:27:00 +08:00
// 使用重试机制执行请求
2026-02-02 17:09:20 +08:00
const rawResponse = await withRetry(executeRequest, {
2026-01-30 15:27:00 +08:00
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
console.warn(`⚠️ [fillStepTask] 第${attempt}次重试,等待 ${delay}ms...`, error?.message)
},
})
2026-02-02 17:09:20 +08:00
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
2026-01-09 13:54:32 +08:00
const vec2Hsl = (color: number[]): string => {
const [h, s, l] = color
return `hsl(${h}, ${s}%, ${l}%)`
}
const briefData: Record<string, { text: string; style?: Record<string, string> }> = {}
if (response.Collaboration_Brief_FrontEnd?.data) {
for (const [key, value] of Object.entries(response.Collaboration_Brief_FrontEnd.data)) {
briefData[key] = {
2026-01-30 15:27:00 +08:00
text: (value as { text: string; color: number[] }).text,
2026-01-09 13:54:32 +08:00
style: {
2026-01-30 15:27:00 +08:00
background: vec2Hsl((value as { text: string; color: number[] }).color),
2026-01-09 13:54:32 +08:00
},
}
}
}
2026-01-21 15:18:15 +08:00
/**
* IRawStepTask
*/
2026-01-09 13:54:32 +08:00
return {
StepName: response.StepName || '',
TaskContent: response.TaskContent || '',
InputObject_List: response.InputObject_List || [],
OutputObject: response.OutputObject || '',
AgentSelection: response.AgentSelection || [],
Collaboration_Brief_frontEnd: {
template: response.Collaboration_Brief_FrontEnd?.template || '',
data: briefData,
},
TaskProcess: response.TaskProcess || [],
}
2025-12-31 19:04:58 +08:00
}
fillStepTaskTaskProcess = async (data: {
goal: string
stepTask: IApiStepTask
agents: string[]
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
2025-12-31 19:04:58 +08:00
}): Promise<IApiStepTask> => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
2026-01-30 15:27:00 +08:00
// 定义实际的 API 调用逻辑
const executeRequest = async (): Promise<any> => {
if (useWs && websocket.connected) {
return await websocket.send(
'fill_step_task_process',
{
'General Goal': data.goal,
stepTask_lackTaskProcess: {
StepName: data.stepTask.name,
TaskContent: data.stepTask.content,
InputObject_List: data.stepTask.inputs,
OutputObject: data.stepTask.output,
AgentSelection: data.agents,
},
},
undefined,
data.onProgress,
)
}
// 否则使用REST API
2026-01-30 15:27:00 +08:00
return await request<
{
'General Goal': string
stepTask_lackTaskProcess: {
StepName: string
TaskContent: string
InputObject_List: string[]
OutputObject: string
AgentSelection: string[]
}
},
{
StepName?: string
TaskContent?: string
InputObject_List?: string[]
OutputObject?: string
AgentSelection?: string[]
TaskProcess?: Array<{
ID: string
ActionType: string
AgentName: string
Description: string
ImportantInput: string[]
}>
Collaboration_Brief_FrontEnd?: {
template: string
data: Record<string, { text: string; color: number[] }>
}
}
>({
url: '/fill_stepTask_TaskProcess',
method: 'POST',
data: {
'General Goal': data.goal,
stepTask_lackTaskProcess: {
StepName: data.stepTask.name,
TaskContent: data.stepTask.content,
InputObject_List: data.stepTask.inputs,
OutputObject: data.stepTask.output,
AgentSelection: data.agents,
},
},
})
}
2025-12-31 19:04:58 +08:00
2026-01-30 15:27:00 +08:00
// 使用重试机制执行请求
2026-02-02 17:09:20 +08:00
const rawResponse = await withRetry(executeRequest, {
2026-01-30 15:27:00 +08:00
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
2026-02-02 17:09:20 +08:00
console.warn(
`⚠️ [fillStepTaskTaskProcess] 第${attempt}次重试,等待 ${delay}ms...`,
error?.message,
)
2026-01-30 15:27:00 +08:00
},
})
2026-02-02 17:09:20 +08:00
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
2025-12-31 19:04:58 +08:00
const vec2Hsl = (color: number[]): string => {
const [h, s, l] = color
return `hsl(${h}, ${s}%, ${l}%)`
}
const briefData: Record<string, { text: string; style: { background: string } }> = {}
if (response.Collaboration_Brief_FrontEnd?.data) {
for (const [key, value] of Object.entries(response.Collaboration_Brief_FrontEnd.data)) {
briefData[key] = {
2026-01-30 15:27:00 +08:00
text: (value as { text: string; color: number[] }).text,
2025-12-31 19:04:58 +08:00
style: {
2026-01-30 15:27:00 +08:00
background: vec2Hsl((value as { text: string; color: number[] }).color),
2025-12-31 19:04:58 +08:00
},
}
}
}
const process = (response.TaskProcess || []).map((action: any) => ({
2025-12-31 19:04:58 +08:00
id: action.ID,
type: action.ActionType,
agent: action.AgentName,
description: action.Description,
inputs: action.ImportantInput,
}))
return {
name: response.StepName || '',
content: response.TaskContent || '',
inputs: response.InputObject_List || [],
output: response.OutputObject || '',
agents: response.AgentSelection || [],
brief: {
template: response.Collaboration_Brief_FrontEnd?.template || '',
data: briefData,
},
process,
}
}
2026-01-21 15:18:15 +08:00
/**
2026-01-30 15:27:00 +08:00
*
2026-01-21 15:18:15 +08:00
*/
2025-12-31 19:04:58 +08:00
agentSelectModifyInit = async (data: {
goal: string
stepTask: any
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
2025-12-31 19:04:58 +08:00
}): Promise<Record<string, Record<string, { reason: string; score: number }>>> => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
2026-01-30 15:27:00 +08:00
// 调试日志:打印请求参数
const requestPayload = {
'General Goal': data.goal,
stepTask: {
StepName: data.stepTask.StepName || data.stepTask.name,
TaskContent: data.stepTask.TaskContent || data.stepTask.content,
InputObject_List: data.stepTask.InputObject_List || data.stepTask.inputs,
OutputObject: data.stepTask.OutputObject || data.stepTask.output,
},
}
console.log('🔍 [agentSelectModifyInit] 请求参数:', {
goal: requestPayload['General Goal'],
stepTaskName: requestPayload.stepTask.StepName,
stepTaskContentLength: requestPayload.stepTask.TaskContent?.length,
useWebSocket: useWs && websocket.connected,
wsConnected: websocket.connected,
})
// 定义实际的 API 调用逻辑
2026-02-02 17:09:20 +08:00
const executeRequest = async (): Promise<
Record<string, Record<string, { Reason: string; Score: number }>>
> => {
2026-01-30 15:27:00 +08:00
if (useWs && websocket.connected) {
return await websocket.send(
'agent_select_modify_init',
requestPayload,
undefined,
data.onProgress,
)
}
// 否则使用REST API
2026-01-30 15:27:00 +08:00
return await request<
{
'General Goal': string
stepTask: any
},
Record<string, Record<string, { Reason: string; Score: number }>>
>({
url: '/agentSelectModify_init',
method: 'POST',
2026-01-30 15:27:00 +08:00
data: requestPayload,
})
}
2025-12-31 19:04:58 +08:00
2026-01-30 15:27:00 +08:00
// 使用重试机制执行请求
2026-02-02 17:09:20 +08:00
const rawResponse = await withRetry(executeRequest, {
2026-01-30 15:27:00 +08:00
maxRetries: 3,
initialDelayMs: 2000,
onRetry: (error, attempt, delay) => {
2026-02-02 17:09:20 +08:00
console.warn(
`⚠️ [agentSelectModifyInit] 第${attempt}次重试,等待 ${delay}ms...`,
error?.message,
)
2026-01-30 15:27:00 +08:00
},
})
2026-02-02 17:09:20 +08:00
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = rawResponse.data || rawResponse
2025-12-31 19:04:58 +08:00
const transformedData: Record<string, Record<string, { reason: string; score: number }>> = {}
2026-02-02 17:09:20 +08:00
// 确保 response 存在且是有效对象
if (!response || typeof response !== 'object' || Array.isArray(response)) {
console.warn('[agentSelectModifyInit] 后端返回数据格式异常:', response)
return transformedData
}
2025-12-31 19:04:58 +08:00
for (const [aspect, agents] of Object.entries(response)) {
2026-02-02 17:09:20 +08:00
for (const [agentName, scoreInfo] of Object.entries(agents as Record<string, { Reason: string; Score: number }> || {})) {
2025-12-31 19:04:58 +08:00
if (!transformedData[agentName]) {
transformedData[agentName] = {}
}
transformedData[agentName][aspect] = {
reason: scoreInfo.Reason,
score: scoreInfo.Score,
}
}
}
return transformedData
}
2026-01-21 15:18:15 +08:00
/**
*
*/
2025-12-31 19:04:58 +08:00
agentSelectModifyAddAspect = async (data: {
aspectList: string[]
useWebSocket?: boolean
2026-01-30 15:27:00 +08:00
onProgress?: (progress: {
status: string
stage?: string
message?: string
[key: string]: any
}) => void
2025-12-31 19:04:58 +08:00
}): Promise<{
aspectName: string
agentScores: Record<string, { score: number; reason: string }>
}> => {
const useWs = data.useWebSocket !== undefined ? data.useWebSocket : this.useWebSocketDefault
let response: Record<string, Record<string, { Reason: string; Score: number }>>
// 如果启用WebSocket且已连接使用WebSocket
if (useWs && websocket.connected) {
2026-02-02 17:09:20 +08:00
const rawResponse = await websocket.send(
2026-01-30 15:27:00 +08:00
'agent_select_modify_add_aspect',
{
aspectList: data.aspectList,
},
undefined,
data.onProgress,
)
2026-02-02 17:09:20 +08:00
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
response = rawResponse.data || rawResponse
} else {
// 否则使用REST API
response = await request<
{
aspectList: string[]
},
Record<string, Record<string, { Reason: string; Score: number }>>
>({
url: '/agentSelectModify_addAspect',
method: 'POST',
data: {
aspectList: data.aspectList,
},
})
}
2025-12-31 19:04:58 +08:00
2026-01-21 15:18:15 +08:00
/**
*
*/
2025-12-31 19:04:58 +08:00
const newAspect = data.aspectList[data.aspectList.length - 1]
if (!newAspect) {
throw new Error('aspectList is empty')
}
const newAspectAgents = response[newAspect]
const agentScores: Record<string, { score: number; reason: string }> = {}
if (newAspectAgents) {
for (const [agentName, scoreInfo] of Object.entries(newAspectAgents)) {
agentScores[agentName] = {
score: scoreInfo.Score,
reason: scoreInfo.Reason,
}
}
}
return {
aspectName: newAspect,
agentScores,
}
}
/**
*
* @param executionId ID
* @param newSteps
* @returns
*/
addStepsToExecution = async (executionId: string, newSteps: IRawStepTask[]): Promise<number> => {
if (!websocket.connected) {
throw new Error('WebSocket未连接')
}
2026-02-02 17:09:20 +08:00
const rawResponse = await websocket.send('add_steps_to_execution', {
execution_id: executionId,
2026-01-30 15:27:00 +08:00
new_steps: newSteps.map((step) => ({
StepName: step.StepName,
TaskContent: step.TaskContent,
InputObject_List: step.InputObject_List,
OutputObject: step.OutputObject,
AgentSelection: step.AgentSelection,
Collaboration_Brief_frontEnd: step.Collaboration_Brief_frontEnd,
2026-01-30 15:27:00 +08:00
TaskProcess: step.TaskProcess.map((action) => ({
ActionType: action.ActionType,
AgentName: action.AgentName,
Description: action.Description,
ID: action.ID,
ImportantInput: action.ImportantInput,
})),
})),
2026-02-02 17:09:20 +08:00
})
// WebSocket 返回格式: { data: {...}, generation_id, execution_id }
// REST API 返回格式: {...}
const response = (rawResponse.data || rawResponse) as { added_count: number }
return response?.added_count || 0
}
}
export default new Api()