UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

124 lines 5.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AI_AGENT_TOOL_ANSWER = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); const transcripts_1 = require("../../../../interfaces/transcripts/transcripts"); /** * This is now being referred to as "Resolve Tool Action" in the UI */ exports.AI_AGENT_TOOL_ANSWER = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "aiAgentToolAnswer", defaultLabel: "Resolve Tool Action", summary: "UI__NODE_EDITOR__SERVICE__AI_AGENT_ANSWER__SUMMARY", parentType: "", preview: { type: "text", key: "answer" }, behavior: { stopping: true }, fields: [ { key: "answer", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_ANSWER__FIELDS__ANSWER_TEXT__LABEL", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_ANSWER__FIELDS__ANSWER_TEXT__DESCRIPTION", type: "cognigyText", params: { required: true, rows: 5, multiline: true } }, { key: "debugToolAnswer", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_ANSWER__FIELDS__DEBUG_MESSAGE__LABEL", type: "toggle", description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_ANSWER__FIELDS__DEBUG_MESSAGE__DESCRIPTION", defaultValue: false }, ], sections: [ { key: "debugging", label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__SECTIONS__DEBUG_SETTINGS__LABEL", defaultCollapsed: true, fields: [ "debugToolAnswer", ], } ], form: [ { type: "field", key: "answer" }, { type: "section", key: "debugging" } ], appearance: { color: "#252525", }, tags: ["ai", "aiAgent"], function: async ({ cognigy, config, nodeId: thisNodeId }) => { var _a, _b, _c, _d, _e, _f; const { api, context } = cognigy; const { answer, debugToolAnswer, } = config; const sessionState = await api.loadSessionState(); const toolCall = (_a = sessionState.lastToolCall) === null || _a === void 0 ? void 0 : _a.toolCall; const aiAgentJobNode = (_b = sessionState.lastToolCall) === null || _b === void 0 ? void 0 : _b.aiAgentJobNode; if (!(toolCall === null || toolCall === void 0 ? void 0 : toolCall.id)) { (_c = api.logDebugError) === null || _c === void 0 ? void 0 : _c.call(api, "UI__DEBUG_MODE__AI_AGENT_ANSWER__ERROR__MESSAGE"); } if (toolCall && aiAgentJobNode) { if (!((_d = api.checkThink) === null || _d === void 0 ? void 0 : _d.call(api, thisNodeId))) { const { flow, node } = aiAgentJobNode; if (answer && flow && node) { // Add Tool Call Message to Transcript const toolCallTranscriptStep = { role: transcripts_1.TranscriptRole.ASSISTANT, type: transcripts_1.TranscriptEntryType.TOOL_CALL, source: "system", payload: { name: toolCall.function.name, id: toolCall.id, input: toolCall.function.arguments, } }; await api.addTranscriptStep(toolCallTranscriptStep); // Add Tool Answer Message to Transcript const toolAnswer = { role: transcripts_1.TranscriptRole.TOOL, type: transcripts_1.TranscriptEntryType.TOOL_ANSWER, source: "system", payload: { toolCallId: toolCall.id, name: toolCall.function.name, content: answer, } }; await api.addTranscriptStep(toolAnswer); if (debugToolAnswer) { (_e = api.logDebugMessage) === null || _e === void 0 ? void 0 : _e.call(api, `<b>UI__DEBUG_MODE__AI_AGENT_ANSWER__DEBUG_ANSWER__MESSAGE</b><br>${answer}`, `${toolCall.function.name}`); } api.resetNextNodes(); // remove the call from the session state, because the call has been answered api.updateSessionStateValues({ lastToolCall: undefined }); await api.executeFlow({ flowNode: { flow, node, }, absorbContext: true, }); } else if (!answer) { (_f = api.logDebugError) === null || _f === void 0 ? void 0 : _f.call(api, "UI__DEBUG_MODE__AI_AGENT_ANSWER__MISSING_ANSWER"); } } else { throw new Error("Infinite Loop Detected"); } } } }); //# sourceMappingURL=aiAgentToolAnswer.js.map