(input, toolUseContext, canUseTool, parentMessage)
| 496 | return null |
| 497 | }, |
| 498 | async call(input, toolUseContext, canUseTool, parentMessage) { |
| 499 | if (toolUseContext.agentId) { |
| 500 | return { |
| 501 | data: { |
| 502 | status: 'disabled' as const, |
| 503 | message: |
| 504 | 'Workflow must be called from the main thread, not from a subagent.', |
| 505 | }, |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | const agents = resolveWorkflowAgents(input.agents, toolUseContext) |
| 510 | const workflowAbortController = new AbortController() |
| 511 | const rootSetAppState = |
| 512 | toolUseContext.setAppStateForTasks ?? toolUseContext.setAppState |
| 513 | const task = registerWorkflowTask(rootSetAppState, { |
| 514 | workflowName: input.workflow_name, |
| 515 | objective: input.objective, |
| 516 | executionMode: input.execution, |
| 517 | agents, |
| 518 | abortController: workflowAbortController, |
| 519 | toolUseId: toolUseContext.toolUseId, |
| 520 | }) |
| 521 | |
| 522 | void workflowRuntime({ |
| 523 | taskId: task.id, |
| 524 | workflowName: input.workflow_name, |
| 525 | objective: input.objective, |
| 526 | executionMode: input.execution, |
| 527 | agents, |
| 528 | workflowAbortController, |
| 529 | toolUseContext, |
| 530 | canUseTool, |
| 531 | parentMessage, |
| 532 | rootSetAppState, |
| 533 | }).catch(error => { |
| 534 | appendWorkflowLog(task.id, `Workflow ${input.workflow_name} failed: ${errorMessage(error)}`) |
| 535 | finalizeWorkflowTask(task.id, rootSetAppState, { |
| 536 | status: 'failed', |
| 537 | error: errorMessage(error), |
| 538 | }) |
| 539 | }) |
| 540 | |
| 541 | return { |
| 542 | data: { |
| 543 | status: 'async_launched' as const, |
| 544 | message: `Workflow "${input.workflow_name}" launched in the background with ${agents.length} agent${agents.length === 1 ? '' : 's'} (${input.execution}).`, |
| 545 | taskId: task.id, |
| 546 | workflowName: input.workflow_name, |
| 547 | outputFile: getTaskOutputPath(task.id), |
| 548 | agentCount: agents.length, |
| 549 | execution: input.execution, |
| 550 | }, |
| 551 | } |
| 552 | }, |
| 553 | mapToolResultToToolResultBlockParam(content, toolUseID) { |
| 554 | const result = content as Output |
| 555 | if (result.status === 'async_launched') { |
nothing calls this directly
no test coverage detected