(
tool: ToolDefinition,
args: Record<string, unknown>,
opts: InvokeOptions,
)
| 448 | } |
| 449 | |
| 450 | private async executeTool( |
| 451 | tool: ToolDefinition, |
| 452 | args: Record<string, unknown>, |
| 453 | opts: InvokeOptions, |
| 454 | ): Promise<void> { |
| 455 | const startedAt = Date.now(); |
| 456 | const runtime = mapRuntimeToSentryToolRuntime(opts.runtime); |
| 457 | let transport: SentryToolTransport = 'direct'; |
| 458 | |
| 459 | const captureInvocationMetric = (outcome: SentryToolInvocationOutcome): void => { |
| 460 | recordToolInvocationMetric({ |
| 461 | toolName: tool.mcpName, |
| 462 | runtime, |
| 463 | transport, |
| 464 | outcome, |
| 465 | durationMs: Date.now() - startedAt, |
| 466 | }); |
| 467 | }; |
| 468 | |
| 469 | const captureInfraErrorMetric = (error: unknown): void => { |
| 470 | recordInternalErrorMetric({ |
| 471 | component: 'tool-invoker', |
| 472 | runtime, |
| 473 | errorKind: getErrorKind(error), |
| 474 | }); |
| 475 | }; |
| 476 | |
| 477 | const postProcessParams = { tool, catalog: this.catalog, runtime: opts.runtime }; |
| 478 | const xcodeIdeRemoteToolName = tool.xcodeIdeRemoteToolName; |
| 479 | const isDynamicXcodeIdeTool = |
| 480 | tool.workflow === 'xcode-ide' && typeof xcodeIdeRemoteToolName === 'string'; |
| 481 | |
| 482 | if (opts.runtime === 'cli' && isDynamicXcodeIdeTool) { |
| 483 | transport = 'xcode-ide-daemon'; |
| 484 | return this.invokeViaDaemon( |
| 485 | opts, |
| 486 | (client) => client.invokeXcodeIdeTool(xcodeIdeRemoteToolName, args), |
| 487 | { |
| 488 | label: 'xcode-ide', |
| 489 | errorTitle: 'Xcode IDE invocation failed', |
| 490 | captureInfraErrorMetric, |
| 491 | captureInvocationMetric, |
| 492 | consumeResult: (daemonResult: DaemonToolResult) => { |
| 493 | const structuredOutput = daemonResult.structuredOutput ?? undefined; |
| 494 | if (structuredOutput) { |
| 495 | opts.renderSession!.setStructuredOutput?.(structuredOutput); |
| 496 | opts.onStructuredOutput?.(structuredOutput); |
| 497 | } |
| 498 | |
| 499 | const ctx: ToolHandlerContext = { |
| 500 | emit: (fragment) => { |
| 501 | opts.renderSession!.emit(fragment); |
| 502 | }, |
| 503 | attach: (image) => opts.renderSession!.attach(image), |
| 504 | nextStepParams: daemonResult.nextStepParams, |
| 505 | nextSteps: daemonResult.nextSteps, |
| 506 | structuredOutput, |
| 507 | }; |
no test coverage detected