( toolCall: ToolCallState, toolCallId: string, toolName: string, args: Record<string, unknown> | undefined, context: StreamingContext, execContext: ExecutionContext, options: OrchestratorOptions, clientExecutable: boolean, scope: ToolScope )
| 451 | } |
| 452 | |
| 453 | async function dispatchToolExecution( |
| 454 | toolCall: ToolCallState, |
| 455 | toolCallId: string, |
| 456 | toolName: string, |
| 457 | args: Record<string, unknown> | undefined, |
| 458 | context: StreamingContext, |
| 459 | execContext: ExecutionContext, |
| 460 | options: OrchestratorOptions, |
| 461 | clientExecutable: boolean, |
| 462 | scope: ToolScope |
| 463 | ): Promise<void> { |
| 464 | const scopeLabel = scope === 'subagent' ? 'subagent ' : '' |
| 465 | |
| 466 | const fireToolExecution = () => { |
| 467 | const pendingPromise = (async () => { |
| 468 | return executeToolAndReport(toolCallId, context, execContext, options) |
| 469 | })().catch((err) => { |
| 470 | logger.error(`Parallel ${scopeLabel}tool execution failed`, { |
| 471 | toolCallId, |
| 472 | toolName, |
| 473 | error: toError(err).message, |
| 474 | }) |
| 475 | return { |
| 476 | status: MothershipStreamV1ToolOutcome.error, |
| 477 | message: 'Tool execution failed', |
| 478 | data: { error: 'Tool execution failed' }, |
| 479 | } |
| 480 | }) |
| 481 | registerPendingToolPromise(context, toolCallId, pendingPromise) |
| 482 | } |
| 483 | |
| 484 | if (options.interactive === false) { |
| 485 | if (options.autoExecuteTools !== false) { |
| 486 | if (!abortPendingToolIfStreamDead(toolCall, toolCallId, options, context)) { |
| 487 | fireToolExecution() |
| 488 | } |
| 489 | } |
| 490 | return |
| 491 | } |
| 492 | |
| 493 | if (clientExecutable) { |
| 494 | const delegateWorkflowRunToClient = isWorkflowToolName(toolName) |
| 495 | if (isSimExecuted(toolName) && !delegateWorkflowRunToClient) { |
| 496 | if (!abortPendingToolIfStreamDead(toolCall, toolCallId, options, context)) { |
| 497 | fireToolExecution() |
| 498 | } |
| 499 | } else { |
| 500 | toolCall.status = 'executing' |
| 501 | const pendingPromise = withCopilotSpan( |
| 502 | TraceSpan.CopilotToolWaitForClientResult, |
| 503 | { |
| 504 | [TraceAttr.ToolName]: toolName, |
| 505 | [TraceAttr.ToolCallId]: toolCallId, |
| 506 | [TraceAttr.ToolTimeoutMs]: options.timeout || STREAM_TIMEOUT_MS, |
| 507 | ...(context.runId ? { [TraceAttr.RunId]: context.runId } : {}), |
| 508 | }, |
| 509 | async (span) => { |
| 510 | const completion = await waitForToolCompletion( |
no test coverage detected