UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

186 lines 7.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AI_AGENT_JOB_TOOL = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); exports.AI_AGENT_JOB_TOOL = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "aiAgentJobTool", defaultLabel: "Tool", parentType: "aiAgentJob", constraints: { editable: true, deletable: true, collapsable: true, creatable: true, movable: true, placement: { predecessor: { whitelist: [] } }, childFlowCreatable: false }, preview: { type: "text", key: "toolId" }, fields: [ { key: "toolId", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__TOOL_ID__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__TOOL_ID__DESCRIPTION", type: "cognigyLLMText", defaultValue: "unlock_account", params: { required: true, rows: 1, multiline: false, maxLength: 64, } }, { key: "description", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DESCRIPTION__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DESCRIPTION__DESCRIPTION", type: "cognigyLLMText", defaultValue: "This tool unlocks a locked user account.", params: { required: true, rows: 5, multiline: true } }, { key: "useParameters", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__USE_PARAMETERS__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__USE_PARAMETERS__DESCRIPTION", type: "toggle", defaultValue: false }, { key: "parameters", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__PARAMETERS__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__PARAMETERS__DESCRIPTION", type: "toolParameters", defaultValue: `{ "type": "object", "properties": { "email": { "type": "string", "description": "User's login email for their account." } }, "required": ["email"], "additionalProperties": false }`, params: { required: false, }, }, { key: "debugMessage", type: "toggle", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DEBUG_MESSAGE__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DEBUG_MESSAGE__DESCRIPTION", defaultValue: true, }, { key: "condition", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__CONDITION__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__CONDITION__DESCRIPTION", type: "cognigyText", defaultValue: "", }, ], sections: [ { key: "parameters", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__SECTIONS__PARAMETERS__LABEL", defaultCollapsed: true, fields: [ "parameters", ], condition: { key: "useParameters", value: true }, }, { key: "debugging", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__SECTIONS__DEBUG_SETTINGS__LABEL", defaultCollapsed: true, fields: [ "debugMessage", ], }, { key: "advanced", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__SECTIONS__ADVANCED__LABEL", defaultCollapsed: true, fields: [ "condition", ], }, ], form: [ { type: "field", key: "toolId" }, { type: "field", key: "description" }, { type: "field", key: "useParameters" }, { type: "section", key: "parameters" }, { type: "section", key: "debugging" }, { type: "section", key: "advanced" }, ], appearance: { color: "white", textColor: "#252525", variant: "mini", }, /** * Node function for aiAgentJobTool * * When this tool node is executed directly (e.g., via MCP Server endpoint), * we need to populate input.aiAgent.toolArgs with the arguments from the MCP call. * This mirrors what aiAgentJob does when it routes to a tool child node. * * For standard AI Agent flow (tool called by LLM), the parent aiAgentJob already * populates toolArgs, so this function is a no-op in that case. */ function: async ({ cognigy, config, nodeId }) => { var _a, _b, _c, _d, _e, _f; const { api, input } = cognigy; const { toolId, debugMessage } = config; // Check if this is an MCP direct tool call const mcpData = (_a = input.data) === null || _a === void 0 ? void 0 : _a._mcp; const isMcpToolCall = (mcpData === null || mcpData === void 0 ? void 0 : mcpData.method) === "tools/call" && ((_b = mcpData === null || mcpData === void 0 ? void 0 : mcpData.params) === null || _b === void 0 ? void 0 : _b.name); if (isMcpToolCall) { const mcpArgs = ((_c = mcpData.params) === null || _c === void 0 ? void 0 : _c.arguments) || {}; // Populate input.aiAgent.toolArgs with MCP arguments // This matches what aiAgentJob does for LLM tool calls input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (_e = (_d = input.aiAgent) === null || _d === void 0 ? void 0 : _d.toolArgs) !== null && _e !== void 0 ? _e : {}), mcpArgs) }); // Debug logging for MCP tool call if (debugMessage) { const messageLines = [`<b>MCP Tool Call:</b> ${toolId}`]; const slots = Object.keys(mcpArgs); const hasSlots = slots.length > 0; messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__SLOTS</b>${hasSlots ? "" : " -"}`); if (hasSlots) { slots.forEach(slot => { let slotValue = mcpArgs[slot]; if (typeof slotValue === "object" && slotValue !== null) { slotValue = JSON.stringify(slotValue, null, 2); } else { slotValue = String(slotValue); } messageLines.push(`- ${slot}: ${slotValue}`); }); } (_f = api.logDebugMessage) === null || _f === void 0 ? void 0 : _f.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER"); } } // The tool node itself doesn't have execution logic for the actual tool functionality. // Child nodes of this tool handle the business logic, or the flow continues to // subsequent nodes where the user implements their custom logic using input.aiAgent.toolArgs. }, }); //# sourceMappingURL=aiAgentJobTool.js.map