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

Function executeToolAndReport

apps/sim/lib/copilot/request/tools/executor.ts:375–435  ·  view source on GitHub ↗
(
  toolCallId: string,
  context: StreamingContext,
  execContext: ExecutionContext,
  options?: OrchestratorOptions
)

Source from the content-addressed store, hash-verified

373}
374
375export async function executeToolAndReport(
376 toolCallId: string,
377 context: StreamingContext,
378 execContext: ExecutionContext,
379 options?: OrchestratorOptions
380): Promise<AsyncToolCompletion> {
381 const toolCall = context.toolCalls.get(toolCallId)
382 if (!toolCall)
383 return buildCompletionSignal({
384 status: MothershipStreamV1ToolOutcome.error,
385 message: 'Tool call not found',
386 })
387
388 const argsPayload = toolCall.params
389 ? (() => {
390 try {
391 return JSON.stringify(toolCall.params)
392 } catch {
393 return undefined
394 }
395 })()
396 : undefined
397 return withCopilotToolSpan(
398 {
399 toolName: toolCall.name,
400 toolCallId: toolCall.id,
401 runId: context.runId,
402 chatId: execContext.chatId,
403 argsBytes: argsPayload?.length,
404 argsPreview: argsPayload?.slice(0, 200),
405 },
406 async (otelSpan) => {
407 const startedAt = Date.now()
408 try {
409 const completion = await executeToolAndReportInner(toolCall, context, execContext, options)
410 const durationMs = Date.now() - startedAt
411 otelSpan.setAttribute(TraceAttr.ToolOutcome, completion.status)
412 otelSpan.setAttribute(TraceAttr.ToolDurationMs, durationMs)
413 if (completion.message) {
414 otelSpan.setAttribute(
415 TraceAttr.ToolOutcomeMessage,
416 String(completion.message).slice(0, 500)
417 )
418 }
419 // Durable Grafana signal for "which Sim tool is slowest" (executor=sim);
420 // pairs with the Go executor-boundary metric (U15) as one series set.
421 recordSimToolMetric(toolCall.name, completion.status, durationMs)
422 return completion
423 } catch (err) {
424 // executeToolAndReportInner threw (infra/unexpected error, not a normal
425 // 'error' completion). Still stamp the span + record the dispatch so
426 // copilot.tool.* isn't silently biased toward successful calls.
427 const durationMs = Date.now() - startedAt
428 otelSpan.setAttribute(TraceAttr.ToolOutcome, 'error')
429 otelSpan.setAttribute(TraceAttr.ToolDurationMs, durationMs)
430 recordSimToolMetric(toolCall.name, 'error', durationMs)
431 throw err
432 }

Callers 2

runCheckpointLoopFunction · 0.90
fireToolExecutionFunction · 0.90

Calls 5

withCopilotToolSpanFunction · 0.90
recordSimToolMetricFunction · 0.90
buildCompletionSignalFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected