( taskId: string, setAppState: SetAppState, )
| 436 | } |
| 437 | |
| 438 | export async function killWorkflowTask( |
| 439 | taskId: string, |
| 440 | setAppState: SetAppState, |
| 441 | ): Promise<void> { |
| 442 | let shouldNotify = false |
| 443 | |
| 444 | updateWorkflowTask(taskId, setAppState, task => { |
| 445 | if (task.status !== 'running') { |
| 446 | return task |
| 447 | } |
| 448 | |
| 449 | shouldNotify = true |
| 450 | task.abortController?.abort() |
| 451 | for (const controller of Object.values(task.agentControllers ?? {})) { |
| 452 | controller.abort() |
| 453 | } |
| 454 | |
| 455 | const agents = task.agents.map(agent => |
| 456 | agent.status === 'completed' || agent.status === 'failed' |
| 457 | ? agent |
| 458 | : { |
| 459 | ...agent, |
| 460 | status: 'killed', |
| 461 | endTime: agent.endTime ?? Date.now(), |
| 462 | }, |
| 463 | ) |
| 464 | |
| 465 | return { |
| 466 | ...task, |
| 467 | ...countAgents(agents), |
| 468 | status: 'killed', |
| 469 | endTime: Date.now(), |
| 470 | agents, |
| 471 | abortController: undefined, |
| 472 | agentControllers: {}, |
| 473 | } |
| 474 | }) |
| 475 | |
| 476 | if (shouldNotify) { |
| 477 | enqueueWorkflowNotification(taskId, setAppState, 'killed') |
| 478 | void evictTaskOutput(taskId) |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | export async function skipWorkflowAgent( |
| 483 | taskId: string, |
no test coverage detected