(
tool: Tool,
toolUseID: string,
input: { [key: string]: boolean | string | number },
toolUseContext: ToolUseContext,
canUseTool: CanUseToolFn,
assistantMessage: AssistantMessage,
messageId: string,
requestId: string | undefined,
mcpServerType: McpServerType,
mcpServerBaseUrl: ReturnType<typeof getLoggingSafeMcpBaseUrl>,
onToolProgress: (
progress: ToolProgress<ToolProgressData> | ProgressMessage<HookProgress>,
) => void,
)
| 597 | } |
| 598 | |
| 599 | async function checkPermissionsAndCallTool( |
| 600 | tool: Tool, |
| 601 | toolUseID: string, |
| 602 | input: { [key: string]: boolean | string | number }, |
| 603 | toolUseContext: ToolUseContext, |
| 604 | canUseTool: CanUseToolFn, |
| 605 | assistantMessage: AssistantMessage, |
| 606 | messageId: string, |
| 607 | requestId: string | undefined, |
| 608 | mcpServerType: McpServerType, |
| 609 | mcpServerBaseUrl: ReturnType<typeof getLoggingSafeMcpBaseUrl>, |
| 610 | onToolProgress: ( |
| 611 | progress: ToolProgress<ToolProgressData> | ProgressMessage<HookProgress>, |
| 612 | ) => void, |
| 613 | ): Promise<MessageUpdateLazy[]> { |
| 614 | // Validate input types with zod (surprisingly, the model is not great at generating valid input) |
| 615 | const parsedInput = tool.inputSchema.safeParse(input) |
| 616 | if (!parsedInput.success) { |
| 617 | let errorContent = formatZodValidationError(tool.name, parsedInput.error) |
| 618 | |
| 619 | const schemaHint = buildSchemaNotSentHint( |
| 620 | tool, |
| 621 | toolUseContext.messages, |
| 622 | toolUseContext.options.tools, |
| 623 | ) |
| 624 | if (schemaHint) { |
| 625 | logEvent('tengu_deferred_tool_schema_not_sent', { |
| 626 | toolName: sanitizeToolNameForAnalytics(tool.name), |
| 627 | isMcp: tool.isMcp ?? false, |
| 628 | }) |
| 629 | errorContent += schemaHint |
| 630 | } |
| 631 | |
| 632 | logForDebugging( |
| 633 | `${tool.name} tool input error: ${errorContent.slice(0, 200)}`, |
| 634 | ) |
| 635 | logEvent('tengu_tool_use_error', { |
| 636 | error: |
| 637 | 'InputValidationError' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 638 | errorDetails: errorContent.slice( |
| 639 | 0, |
| 640 | 2000, |
| 641 | ) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 642 | messageID: |
| 643 | messageId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 644 | toolName: sanitizeToolNameForAnalytics(tool.name), |
| 645 | isMcp: tool.isMcp ?? false, |
| 646 | |
| 647 | queryChainId: toolUseContext.queryTracking |
| 648 | ?.chainId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 649 | queryDepth: toolUseContext.queryTracking?.depth, |
| 650 | ...(mcpServerType && { |
| 651 | mcpServerType: |
| 652 | mcpServerType as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 653 | }), |
| 654 | ...(mcpServerBaseUrl && { |
| 655 | mcpServerBaseUrl: |
| 656 | mcpServerBaseUrl as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
no test coverage detected