MCPcopy
hub / github.com/simstudioai/sim / executeToolAndReportInner

Function executeToolAndReportInner

apps/sim/lib/copilot/request/tools/executor.ts:437–864  ·  view source on GitHub ↗
(
  toolCall: ToolCallState,
  context: StreamingContext,
  execContext: ExecutionContext,
  options?: OrchestratorOptions
)

Source from the content-addressed store, hash-verified

435}
436
437async function executeToolAndReportInner(
438 toolCall: ToolCallState,
439 context: StreamingContext,
440 execContext: ExecutionContext,
441 options?: OrchestratorOptions
442): Promise<AsyncToolCompletion> {
443 if (toolCall.status === 'executing') {
444 return buildCompletionSignal({
445 status: MothershipStreamV1AsyncToolRecordStatus.running,
446 message: 'Tool already executing',
447 })
448 }
449 if (toolCall.endTime || isTerminalToolCallStatus(toolCall.status)) {
450 return terminalCompletionFromToolCall(toolCall)
451 }
452
453 const markToolCallCancelled = (message: string) => {
454 setTerminalToolCallState(toolCall, {
455 status: MothershipStreamV1ToolOutcome.cancelled,
456 error: message,
457 })
458 }
459
460 if (abortRequested(context, execContext, options)) {
461 markToolCallCancelled('Request aborted before tool execution')
462 markToolResultSeen(toolCall.id)
463 await completeAsyncToolCall({
464 toolCallId: toolCall.id,
465 status: MothershipStreamV1AsyncToolRecordStatus.cancelled,
466 result: { cancelled: true },
467 error: 'Request aborted before tool execution',
468 }).catch((err) => {
469 logger.warn('Failed to persist async tool status', {
470 toolCallId: toolCall.id,
471 error: toError(err).message,
472 })
473 })
474 publishTerminalToolConfirmation({
475 toolCallId: toolCall.id,
476 status: MothershipStreamV1ToolOutcome.cancelled,
477 message: 'Request aborted before tool execution',
478 data: { cancelled: true },
479 })
480 return cancelledCompletion('Request aborted before tool execution')
481 }
482
483 toolCall.status = 'executing'
484 await upsertAsyncToolCall({
485 runId: context.runId,
486 toolCallId: toolCall.id,
487 toolName: toolCall.name,
488 args: toolCall.params,
489 }).catch((err) => {
490 logger.warn('Failed to persist async tool row before execution', {
491 toolCallId: toolCall.id,
492 error: toError(err).message,
493 })
494 })

Callers 1

executeToolAndReportFunction · 0.85

Calls 15

isTerminalToolCallStatusFunction · 0.90
markToolResultSeenFunction · 0.90
completeAsyncToolCallFunction · 0.90
toErrorFunction · 0.90
upsertAsyncToolCallFunction · 0.90
markAsyncToolRunningFunction · 0.90
ensureHandlersRegisteredFunction · 0.90
maybeWriteOutputToFileFunction · 0.90
maybeWriteOutputToTableFunction · 0.90
maybeWriteReadCsvToTableFunction · 0.90
setTerminalToolCallStateFunction · 0.90
requireToolCallErrorFunction · 0.90

Tested by

no test coverage detected