MCPcopy Index your code
hub / github.com/simstudioai/sim / dispatchToolExecution

Function dispatchToolExecution

apps/sim/lib/copilot/request/handlers/tool.ts:453–560  ·  view source on GitHub ↗
(
  toolCall: ToolCallState,
  toolCallId: string,
  toolName: string,
  args: Record<string, unknown> | undefined,
  context: StreamingContext,
  execContext: ExecutionContext,
  options: OrchestratorOptions,
  clientExecutable: boolean,
  scope: ToolScope
)

Source from the content-addressed store, hash-verified

451}
452
453async 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(

Callers 1

handleCallPhaseFunction · 0.85

Calls 13

isWorkflowToolNameFunction · 0.90
isSimExecutedFunction · 0.90
withCopilotSpanFunction · 0.90
handleClientCompletionFunction · 0.90
markAsyncToolDeliveredFunction · 0.90
toErrorFunction · 0.90
emitSyntheticToolResultFunction · 0.90
fireToolExecutionFunction · 0.85
waitForToolCompletionFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected