@cognigy/rest-api-client
Version:
Cognigy REST-Client
1,046 lines • 51.1 kB
JavaScript
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LLM_PROMPT_V2 = void 0;
/* Npm modules */
const crypto = require("crypto");
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
const logic_1 = require("../../logic");
const createToolDefinitions_1 = require("../aiAgent/helpers/createToolDefinitions");
const parseMcpHeaders_1 = require("../aiAgent/helpers/parseMcpHeaders");
const prompt_1 = require("../../nlu/generativeSlotFiller/prompt");
const errors_1 = require("../../../../errors");
const transcripts_1 = require("../../../../interfaces/transcripts/transcripts");
exports.LLM_PROMPT_V2 = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "llmPromptV2",
defaultLabel: "LLM Prompt",
summary: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__DESCRIPTION",
constraints: {
collapsable: true,
placement: {
children: {
whitelist: ["llmPromptDefault", "llmPromptTool", "llmPromptMCPTool", "knowledgeTool", "handoverToAiAgentTool", "handoverToHumanAgentTool", "sendEmailTool", "executeWorkflowTool"],
},
},
},
behavior: {
entrypoint: true
},
dependencies: {
children: ["llmPromptDefault", "llmPromptTool"]
},
preview: {
type: "text",
key: "prompt",
},
fields: [
{
key: "llmProviderReferenceId",
type: "llmSelect",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__LLM_SELECT__LABEL",
defaultValue: "default",
params: {
required: true
}
},
{
key: "prompt",
label: "UI__NODE_EDITOR__SERVICE__LLM_PROMPT__FIELDS__PROMPT__LABEL",
type: "cognigyLLMText",
description: "UI__NODE_EDITOR__SERVICE__LLM_PROMPT__FIELDS__PROMPT__DESCRIPTION",
params: {
multiline: true,
rows: 5,
required: false
},
defaultValue: ""
},
{
key: "chatTranscriptSteps",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TRANSCRIPT_STEPS__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TRANSCRIPT_STEPS__DESCRIPTION",
defaultValue: 50,
params: {
min: 0,
max: 50,
step: 1
},
condition: {
key: "usePromptMode",
value: false,
}
},
{
key: "usePromptMode",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_PROMPT__LABEL",
type: "toggle",
params: {
required: true
},
defaultValue: false
},
{
key: "samplingMethod",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__SAMPLING_METHOD__LABEL",
type: "select",
defaultValue: "temperature",
params: {
options: [
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__SAMPLING_METHOD__OPTIONS__TEMPERATURE__LABEL",
value: "temperature"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__SAMPLING_METHOD__OPTIONS__TOP_PERCENTATGE__LABEL",
value: "topP"
}
]
}
},
{
key: "temperature",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TEMPERATURE__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TEMPERATURE__DESCRIPTION",
defaultValue: 0.7,
params: {
min: 0,
max: 1,
step: 0.1
},
condition: {
key: "samplingMethod",
value: "temperature",
}
},
{
key: "topP",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TOP_P__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TOP_P__DESCRIPTION",
defaultValue: 1,
params: {
min: 0,
max: 1,
step: 0.1
},
condition: {
key: "samplingMethod",
value: "topP",
}
},
{
key: "maxTokens",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__MAX_TOKENS__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__MAX_TOKENS__DESCRIPTION",
defaultValue: 1000,
params: {
min: 100,
max: 16000,
step: 100
}
},
{
key: "frequencyPenalty",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__FREQUENCY_PENALTY__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__FREQUENCY_PENALTY__DESCRIPTION",
defaultValue: 0,
params: {
min: -2,
max: 2,
step: 0.1
}
},
{
key: "presencePenalty",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PRESENCE_PENALTY__LABEL",
type: "slider",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__PRESENCE_PENALTY__DESCRIPTION",
defaultValue: 0,
params: {
min: -2,
max: 2,
step: 0.1
}
},
{
key: "useStop",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__DESCRIPTION",
defaultValue: false
},
{
key: "stop",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STOP__LABEL",
type: "textArray",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STOP__DESCRIPTION",
condition: {
key: "useStop",
value: true
}
},
{
key: "timeout",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__LABEL",
defaultValue: 8000,
type: "number",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__DESCRIPTION",
},
{
key: "storeLocation",
type: "select",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STORE_LOCATION__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STORE_LOCATION__DESCRIPTION",
defaultValue: "stream",
params: {
options: [
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STORE_LOCATION__OPTIONS__INPUT__LABEL",
value: "input"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STORE_LOCATION__OPTIONS__CONTEXT__LABEL",
value: "context"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STORE_LOCATION__OPTIONS__STREAM__LABEL",
value: "stream"
}
],
required: true
},
},
{
key: "immediateOutput",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__IMMEDIATEOUTPUT__LABEL",
type: "toggle",
defaultValue: true,
condition: {
or: [
{
key: "storeLocation",
value: "input",
},
{
key: "storeLocation",
value: "context",
}
]
}
},
{
key: "inputKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__INPUT_KEY__LABEL",
defaultValue: "promptResult",
condition: {
or: [
{
key: "storeLocation",
value: "input",
},
{
and: [
{
key: "storeLocation",
value: "stream",
},
{
key: "streamStoreCopyInInput",
value: true,
}
]
}
]
}
},
{
key: "contextKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__CONTEXT_KEY__LABEL",
defaultValue: "promptResult",
condition: {
key: "storeLocation",
value: "context",
}
},
{
key: "streamStopTokens",
type: "textArray",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STOP_TOKENS__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STOP_TOKENS__DESCRIPTION",
defaultValue: [".", "!", "?", "\\n"],
condition: {
key: "storeLocation",
value: "stream",
}
},
{
key: "streamStopTokenOverrides",
type: "textArray",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STOP_TOKEN_OVERRIDES__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STOP_TOKEN_OVERRIDES__DESCRIPTION",
defaultValue: ["\d+\."],
condition: {
key: "storeLocation",
value: "stream",
}
},
{
key: "streamDescription",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_DESCRIPTION__TEXT"
},
condition: {
key: "storeLocation",
value: "stream",
}
},
{
key: "streamStoreCopyInInput",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STORE_COPY__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STREAM_STORE_COPY__DESCRIPTION",
defaultValue: false,
condition: {
key: "storeLocation",
value: "stream",
}
},
{
key: "debugLogTokenCount",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__DEBUGLOGTOKENCOUNT__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__DEBUGLOGTOKENCOUNT__DESCRIPTION",
defaultValue: false
},
{
key: "debugLogRequestAndCompletion",
label: "UI__NODE_EDITOR__SERVICE__LLM_PROMPT__FIELDS__LOG_SYSTEM_PROMPT_AND_COMPLETION__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__LLM_PROMPT__FIELDS__LOG_SYSTEM_PROMPT_AND_COMPLETION__DESCRIPTION",
defaultValue: false
},
{
key: "debugLogLLMLatency",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_LLM_LATENCY__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_LLM_LATENCY__DESCRIPTION",
defaultValue: false
},
{
key: "debugDescription",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__DEBUG_DESCRIPTION__TEXT"
}
},
{
key: "responseFormat",
type: "select",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__RESPONSE_FORMAT__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__RESPONSE_FORMAT__DESCRIPTION",
defaultValue: "default",
params: {
options: [
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__RESPONSE_FORMAT__OPTIONS__DEFAULT__LABEL",
value: "default"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__RESPONSE_FORMAT__OPTIONS__TEXT__LABEL",
value: "text"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__RESPONSE_FORMAT__OPTIONS__JSON__LABEL",
value: "json_object"
}
]
},
},
{
key: "seed",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__SEED__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__SEED__DESCRIPTION",
type: "cognigyText",
defaultValue: ""
},
{
key: "jsonStreamWarning",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__JSONSTREAMWARNING__PARAM"
},
condition: {
and: [
{
key: "responseFormat",
value: "json_object"
},
{
key: "storeLocation",
value: "stream",
}
]
}
},
{
key: "useTextAlternativeForLLM",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__INCLUDE_ALL_OUTPUT_TYPES__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__INCLUDE_ALL_OUTPUT_TYPES__DESCRIPTION",
defaultValue: true,
},
{
key: "advancedLogging",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__ADVANCED_LOGGING__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__ADVANCED_LOGGING__DESCRIPTION",
defaultValue: false,
},
{
key: "loggingWebhookUrl",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOGGING_WEBHOOK_URL__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOGGING_WEBHOOK_URL__DESCRIPTION",
defaultValue: "",
condition: {
key: "advancedLogging",
value: true
}
},
{
key: "loggingCustomData",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__CUSTOM_LOGGING_DATA__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__CUSTOM_LOGGING_DATA__DESCRIPTION",
defaultValue: "",
condition: {
key: "advancedLogging",
value: true
}
},
{
key: "loggingHeaders",
type: "keyValuePairs",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOGGING_HEADERS__LABEL",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOGGING_HEADERS__DESCRIPTION",
defaultValue: "{}",
condition: {
key: "advancedLogging",
value: true
}
},
{
key: "conditionForLogging",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__CONDITION_FOR_LOGGING__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__CONDITION_FOR_LOGGING__DESCRIPTION",
defaultValue: "",
condition: {
key: "advancedLogging",
value: true
}
},
{
key: "customModelOptions",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__CUSTOM_MODEL_OPTIONS__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__CUSTOM_MODEL_OPTIONS__DESCRIPTION",
type: "json",
defaultValue: {}
},
{
key: "customRequestOptions",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__CUSTOM_REQUEST_OPTIONS__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__CUSTOM_REQUEST_OPTIONS__DESCRIPTION",
type: "json",
defaultValue: {}
},
{
key: "logErrorToSystem",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__LOG_ERROR_TO_SYSTEM__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__LOG_ERROR_TO_SYSTEM__DESCRIPTION",
type: "toggle",
defaultValue: false,
},
{
key: "errorHandling",
type: "select",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__HANDLE_SERVICE_ERROR__LABEL",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__HANDLE_SERVICE_ERROR__DESCRIPTION",
defaultValue: "continue",
params: {
options: [
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__STOP__LABEL",
value: "stop"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__CONTINUE__LABEL",
value: "continue"
},
{
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__GOTO__LABEL",
value: "goto"
},
]
}
},
{
key: "errorMessage",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__ERROR_MESSAGE__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__ERROR_MESSAGE__DESCRIPTION",
defaultValue: "",
condition: {
key: "errorHandling",
value: "continue"
}
},
{
key: "errorHandlingGotoTarget",
type: "flowNode",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__ERROR__GOTO_NODE__LABEL",
condition: {
key: "errorHandling",
value: "goto"
}
},
{
key: "toolChoice",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TOOL_CHOICE__LABEL",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TOOL_CHOICE__DESCRIPTION",
type: "select",
defaultValue: "auto",
params: {
options: [
{
label: 'UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TOOL_CHOICE__OPTIONS__AUTO__LABEL',
value: 'auto'
},
{
label: 'UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TOOL_CHOICE__OPTIONS__REQUIRED__LABEL',
value: 'required'
},
{
label: 'UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TOOL_CHOICE__OPTIONS__NONE__LABEL',
value: 'none'
}
]
}
},
{
key: "useStrict",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__USE_STRICT__LABEL",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__USE_STRICT__DESCRIPTION",
type: "toggle",
defaultValue: false
},
{
key: "processImages",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__PROCESS_IMAGES__LABEL",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__PROCESS_IMAGES__DESCRIPTION",
type: "toggle",
defaultValue: false
},
{
key: "transcriptImageHandling",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TRANSCRIPT_IMAGES__LABEL",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TRANSCRIPT_IMAGES__DESCRIPTION",
type: "select",
defaultValue: "minify",
params: {
options: [
{
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TRANSCRIPT_IMAGES__OPTIONS__MINIFY__LABEL",
value: "minify"
},
{
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TRANSCRIPT_IMAGES__OPTIONS__DROP__LABEL",
value: "drop"
},
{
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__TRANSCRIPT_IMAGES__OPTIONS__KEEP__LABEL",
value: "keep"
}
],
},
},
{
key: "debugLogToolDefinitions",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_TOOL_DEFINITIONS__LABEL",
type: "toggle",
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_TOOL_DEFINITIONS__DESCRIPTION",
defaultValue: false
},
],
sections: [
{
key: "advanced",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__SECTIONS__ADVANCED__LABEL",
defaultCollapsed: true,
fields: [
"maxTokens",
"usePromptMode",
"chatTranscriptSteps",
"responseFormat",
"jsonStreamWarning",
"timeout",
"samplingMethod",
"temperature",
"topP",
"presencePenalty",
"frequencyPenalty",
"useStop",
"stop",
"seed",
"useTextAlternativeForLLM",
]
},
{
key: "storage",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__SECTIONS__STORAGE__LABEL",
defaultCollapsed: true,
fields: [
"storeLocation",
"jsonStreamWarning",
"streamDescription",
"inputKey",
"contextKey",
"immediateOutput",
"streamStopTokens",
"streamStopTokenOverrides",
"streamStoreCopyInInput"
]
},
{
key: "errorHandling",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__SECTIONS__ERROR_HANDLING__LABEL",
defaultCollapsed: true,
fields: [
"logErrorToSystem",
"errorHandling",
"errorMessage",
"errorHandlingGotoTarget",
]
},
{
key: "customOptions",
label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__SECTIONS__CUSTOM_OPTIONS__LABEL",
defaultCollapsed: true,
fields: [
"customModelOptions",
"customRequestOptions"
]
},
{
key: "debugging",
label: "UI__NODE_EDITOR__SECTIONS__DEBUG_SETTINGS__LABEL",
defaultCollapsed: true,
fields: [
"debugDescription",
"debugLogTokenCount",
"debugLogRequestAndCompletion",
"debugLogLLMLatency",
"debugLogToolDefinitions",
"advancedLogging",
"loggingWebhookUrl",
"loggingCustomData",
"conditionForLogging",
"loggingHeaders",
]
},
{
key: "toolSettings",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__SECTIONS__TOOL_SETTINGS__LABEL",
defaultCollapsed: true,
fields: [
"toolChoice",
"useStrict",
],
},
{
key: "imageHandling",
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__SECTIONS__IMAGE_HANDLING__LABEL",
defaultCollapsed: true,
fields: [
"processImages",
"transcriptImageHandling"
]
},
],
form: [
{ type: "field", key: "llmProviderReferenceId" },
{ type: "field", key: "prompt" },
{ type: "section", key: "advanced" },
{ type: "section", key: "storage" },
{ type: "section", key: "toolSettings" },
{ type: "section", key: "imageHandling" },
{ type: "section", key: "errorHandling" },
{ type: "section", key: "customOptions" },
{ type: "section", key: "debugging" },
],
appearance: {
color: "#252525",
},
tags: ["ai", "llm", "gpt", "generative ai", "openai", "azure", "prompt"],
mocking: {
defaultMockCode: `input.llmResponse = {response: "Mock response"};`
},
function: async ({ cognigy, config, childConfigs, nodeId }) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
const { api, input, flowReferenceId } = cognigy;
const { temperature, maxTokens, topP, presencePenalty, frequencyPenalty, useStop, stop, storeLocation, contextKey, inputKey, timeout, streamStopTokens, streamStopTokenOverrides, debugLogTokenCount, debugLogRequestAndCompletion, debugLogLLMLatency, debugLogToolDefinitions, llmProviderReferenceId, usePromptMode, chatTranscriptSteps, responseFormat, streamStoreCopyInInput, seed, immediateOutput, customModelOptions, customRequestOptions, errorHandling = "continue", // default behavior for LLM Prompt node was, continue its execution even though an error occurred (deviating it from the SEO node) & do not output an error message on UI explicitly. However, error is always stored in the input or context object. We can use an extra "say" node to output it.
errorHandlingGotoTarget, errorMessage, useTextAlternativeForLLM, advancedLogging, loggingWebhookUrl, loggingCustomData, loggingHeaders, conditionForLogging, logErrorToSystem, processImages, transcriptImageHandling, toolChoice, useStrict } = config;
let prompt = config.prompt || "";
const { traceId } = input;
// check if custom variables are used and if they have a length modifier
// works only for a single variable per prompt
if (prompt.includes("@cognigyRecentConversation")) {
let turnLimit;
if (prompt.match(/@cognigyRecentConversation:(\d+)/)) {
// @cognigyRecentConversation has a length modifier (e.g. @cognigyRecentConversation:5), so we just want to return the top 5 turns
turnLimit = Number((_a = prompt.match(/@cognigyRecentConversation:(\d+)/)) === null || _a === void 0 ? void 0 : _a[1]);
}
const recentConversation = (0, prompt_1.createLastConverationString)(cognigy.lastConversationEntries, turnLimit) + "\n";
prompt = prompt.replace(/@cognigyRecentConversation(:\d+)?/, recentConversation);
}
if (prompt.includes("@cognigyRecentUserInputs")) {
let turnLimit;
if (prompt.match(/@cognigyRecentUserInputs:(\d+)/)) {
// @cognigyRecentUserInputs has a length modifier (e.g. @cognigyRecentUserInputs:5), so we just want to return the top 5 entries
turnLimit = Number((_b = prompt.match(/@cognigyRecentUserInputs:(\d+)/)) === null || _b === void 0 ? void 0 : _b[1]);
}
const recentUserInputs = (0, prompt_1.createLastUserInputString)(cognigy.lastConversationEntries, turnLimit) + "\n";
prompt = prompt.replace(/@cognigyRecentUserInputs(:\d+)?/, recentUserInputs);
}
// handle errors from external services, depending on the settings
const handleServiceError = async (error) => {
var _a, _b, _c, _d, _e, _f;
const compactError = {
name: error === null || error === void 0 ? void 0 : error.name,
code: error === null || error === void 0 ? void 0 : error.code,
message: (error === null || error === void 0 ? void 0 : error.message) || error
};
// return the requestId if it exist in the error obj.
if ((_a = error === null || error === void 0 ? void 0 : error.meta) === null || _a === void 0 ? void 0 : _a.requestId) {
compactError["requestId"] = (_b = error === null || error === void 0 ? void 0 : error.meta) === null || _b === void 0 ? void 0 : _b.requestId;
}
if ((_c = error === null || error === void 0 ? void 0 : error.originalErrorDetails) === null || _c === void 0 ? void 0 : _c.code) {
compactError.code = error.originalErrorDetails.code;
}
const errorResponse = {
error: compactError,
};
// add error to context or input
switch (storeLocation) {
case "context":
(_d = api.addToContext) === null || _d === void 0 ? void 0 : _d.call(api, contextKey, errorResponse, "simple");
break;
default:
api.addToInput(inputKey, errorResponse);
}
if (errorHandling === "continue") {
// output the timeout message
if (errorMessage) {
await ((_e = api.output) === null || _e === void 0 ? void 0 : _e.call(api, errorMessage, null));
}
// Continue with default node as next node
const defaultChild = childConfigs === null || childConfigs === void 0 ? void 0 : childConfigs.find(child => child.type === "llmPromptDefault");
if (defaultChild) {
api.setNextNode(defaultChild.id);
}
}
else if (errorHandling === "goto") {
if (!errorHandlingGotoTarget) {
throw new Error("GoTo Target is required");
}
const gotoParams = {
cognigy,
childConfigs: [],
nodeId,
config: {
flowNode: {
flow: errorHandlingGotoTarget.flow,
node: errorHandlingGotoTarget.node,
},
injectedText: input.text,
injectedData: input.data,
executionMode: "continue",
absorbContext: false
}
};
await ((_f = logic_1.GO_TO.function) === null || _f === void 0 ? void 0 : _f.call(logic_1.GO_TO, gotoParams));
}
else {
throw new errors_1.InternalServerError(error === null || error === void 0 ? void 0 : error.message, { traceId });
}
};
try {
const isStreamingChannel = input.endpointType === "webchat3" || input.channel === "adminconsole";
const _messageId = crypto.randomUUID();
// Start measuring LLM latency and time to first output if debug flag is enabled
let firstOutputTime = null;
/**
* Retrieve the tool definitions from the child nodes
*/
const { toolIds, toolNames, toolMap, tools } = await (0, createToolDefinitions_1.createToolDefinitions)(childConfigs, api, useStrict);
const enableAdvancedLogging = advancedLogging && loggingWebhookUrl && (conditionForLogging === "" || !!conditionForLogging);
/**
* Generate Prompt Options
*/
const llmPromptOptions = Object.assign(Object.assign(Object.assign(Object.assign({ prompt,
temperature,
maxTokens,
topP,
presencePenalty,
frequencyPenalty, timeoutInMs: timeout, useCase: "promptNode", stream: storeLocation === "stream", streamOnDataHandler: (text) => {
var _a;
text = isStreamingChannel ? text : text.trim();
if (text) {
// Record first output time for debugging if not already recorded
if (debugLogLLMLatency && firstOutputTime === null) {
firstOutputTime = Date.now();
}
// if we got text, we output it, but prevent it from being added to the transcript
(_a = api.output) === null || _a === void 0 ? void 0 : _a.call(api, text, {
_cognigy: {
_preventTranscript: true,
_messageId,
}
});
}
}, streamStopTokens: streamStopTokens || [".", "!", "?", "\\n"], streamStopTokenOverrides, preventNewLineRemoval: isStreamingChannel ? true : false,
// set to true in order to get token usage
detailedResults: true, seed: Number(seed) ? Number(seed) : undefined }, (tools.length > 0 && { tools })), (tools.length > 0 && { toolChoice: toolChoice })), (enableAdvancedLogging && {
logging: Object.assign(Object.assign({ webhookUrl: loggingWebhookUrl }, (loggingCustomData && { customData: loggingCustomData })), (loggingHeaders && { headers: loggingHeaders }))
})), { customModelOptions,
customRequestOptions });
if (useStop) {
llmPromptOptions["stop"] = stop;
}
// llmProviderReferenceId `default` value is not a responseFormat, rather it is LLM Model default selection.
if (llmProviderReferenceId && llmProviderReferenceId !== "default") {
llmPromptOptions["llmProviderReferenceId"] = llmProviderReferenceId;
}
if (processImages) {
llmPromptOptions["imageOptions"] = {
processImages,
transcriptImageHandling
};
}
if (responseFormat && responseFormat !== "default") {
llmPromptOptions["responseFormat"] = responseFormat;
}
let debugPrompt = prompt;
// if we're not using prompt mode, we need to add the system message and the transcript
// this is the equivalent of the old "useChat" mode
if (!usePromptMode) {
// Two-phase transcript fetch:
// 1. Current tool cycle (all entries from current user input onward) — never truncated
// 2. Previous conversation history — limited by chatTranscriptSteps as before
const historySteps = chatTranscriptSteps !== null && chatTranscriptSteps !== void 0 ? chatTranscriptSteps : 50;
const allRecentEntries = await api.getTranscript({
limit: historySteps + 100,
rolesWhiteList: [transcripts_1.TranscriptRole.USER, transcripts_1.TranscriptRole.ASSISTANT, transcripts_1.TranscriptRole.TOOL],
excludeDataOnlyMessagesFilter: [transcripts_1.TranscriptRole.ASSISTANT],
useTextAlternativeForLLM,
excludeUserEventMessages: true,
});
// Find where the current tool cycle starts by matching the current request's traceId.
// All entries from the current user input share the same traceId.
const currentCycleStartIndex = allRecentEntries.findIndex(e => e.traceId === traceId);
const previousEntries = currentCycleStartIndex > 0 ? allRecentEntries.slice(0, currentCycleStartIndex) : [];
const currentCycleEntries = currentCycleStartIndex >= 0 ? allRecentEntries.slice(currentCycleStartIndex) : allRecentEntries;
// Limit previous history by chatTranscriptSteps (current user input is already in currentCycleEntries via traceId)
const limitedHistory = historySteps > 0 ? previousEntries.slice(-historySteps) : [];
const transcript = [...limitedHistory, ...currentCycleEntries];
llmPromptOptions["transcript"] = transcript;
llmPromptOptions["chat"] = [{
role: "system",
content: prompt
}];
}
if (llmPromptOptions.transcript && !llmPromptOptions.transcript.some(c => c.role === 'user' && c.source === 'user' && c.payload.text)) {
// Fill a default message to LLM
(_c = llmPromptOptions.chat) === null || _c === void 0 ? void 0 : _c.push({
role: 'user',
content: "<NO_USER_INPUT>",
});
}
const llmStartTime = debugLogLLMLatency ? Date.now() : 0;
// Run the LLM Query
const fullLlmResult = await api.runGenerativeAIPrompt(llmPromptOptions, "gptPromptNode");
// End measuring times and log if debug flag is enabled
if (debugLogLLMLatency) {
const llmEndTime = Date.now();
const debugMessages = [];
const llmLatencyMs = llmEndTime - llmStartTime;
let timeToFirstOutputLabel;
if (fullLlmResult.finishReason === "tool_calls" && fullLlmResult.toolCalls.length > 0) {
timeToFirstOutputLabel = " - (tool call)";
}
else if (firstOutputTime === null) {
timeToFirstOutputLabel = " - (no output)";
}
else {
firstOutputTime = firstOutputTime || llmEndTime;
timeToFirstOutputLabel = `${firstOutputTime - llmStartTime}ms`;
}
if (storeLocation === "stream") {
debugMessages.push(`UI__DEBUG_MODE__AI_AGENT_JOB__TIME_TO_FIRST_OUTPUT__LABEL: ${timeToFirstOutputLabel}`);
}
debugMessages.push(`UI__DEBUG_MODE__AI_AGENT_JOB__LLM_LATENCY__LABEL: ${llmLatencyMs}ms`);
(_d = api.logDebugMessage) === null || _d === void 0 ? void 0 : _d.call(api, debugMessages.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TIMING__HEADER");
}
const { messages } = fullLlmResult, llmResult = __rest(fullLlmResult, ["messages"]);
const isFollowSessionActive = api.getMetadata().isFollowSessionActive;
if (debugLogToolDefinitions) {
(_e = api.logDebugMessage) === null || _e === void 0 ? void 0 : _e.call(api, tools, "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_DEFINITIONS");
}
// if we're in adminconsole or following a session, process debugging options
(input.endpointType === "adminconsole" || isFollowSessionActive) && (0, prompt_1.writeLLMDebugLogs)("LLM Prompt", debugPrompt, llmResult, debugLogTokenCount, debugLogRequestAndCompletion, cognigy, "llmPromptV2");
if (llmResult.finishReason === "tool_calls" && llmResult.toolCalls.length > 0) {
const mainToolCall = llmResult.toolCalls[0];
let isMcpToolCall = false;
// Find the child node with the toolId of the tool call
let toolChild = undefined;
for (const child of childConfigs) {
if (!["llmPromptDefault", "llmPromptMCPTool"].includes(child.type) && ((_f = child.config) === null || _f === void 0 ? void 0 : _f.toolId) && await api.parseCognigyScriptText((_g = child.config) === null || _g === void 0 ? void 0 : _g.toolId) === mainToolCall.function.name) {
toolChild = child;
break;
}
}
let mcpHeaders = (_h = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _h === void 0 ? void 0 : _h.mcpHeaders;
if (!toolChild && toolMap.has(mainToolCall.function.name)) {
// If the tool call is from an MCP tool, set the next node to the corresponding child node
toolChild = childConfigs.find(child => child.id === toolMap.get(mainToolCall.function.name));
isMcpToolCall = true;
// Parse mcpHeaders values if present and resolve any Cognigy script expressions
mcpHeaders = await (0, parseMcpHeaders_1.parseMcpHeaders)(toolChild === null || toolChild === void 0 ? void 0 : toolChild.config.mcpHeaders, api);
}
if (mainToolCall.function.name !== "retrieve_knowledge" && toolChild === undefined) {
(_j = api.logDebugError) === null || _j === void 0 ? void 0 : _j.call(api, `UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__ERROR__BODY <b>${mainToolCall.function.name}</b>`, "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__ERROR__HEADER");
}
// Add last tool call to session state for loading it from Tool Answer Node
api.updateSessionStateValues({
lastToolCall: Object.assign(Object.assign({ llmProvider: fullLlmResult.llmProvider, aiAgentJobNode: {
flow: flowReferenceId,
node: nodeId,
} }, (isMcpToolCall && {
mcpServerUrl: (_k = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _k === void 0 ? void 0 : _k.mcpServerUrl,
mcpHeaders,
timeout: (_l = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _l === void 0 ? void 0 : _l.timeout,
mcpToolNode: toolChild === null || toolChild === void 0 ? void 0 : toolChild.id,
authType: (_m = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _m === void 0 ? void 0 : _m.authType,
oAuth2Connection: (_o = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _o === void 0 ? void 0 : _o.oAuth2Connection,
})), { toolCall: mainToolCall }),
});
// if there are any parameters/arguments, add them to the input slots
if (mainToolCall.function.arguments) {
input.llmPrompt = Object.assign(Object.assign({}, input.llmPrompt), { toolArgs: Object.assign(Object.assign({}, (_q = (_p = input.llmPrompt) === null || _p === void 0 ? void 0 : _p.toolArgs) !== null && _q !== void 0 ? _q : {}), mainToolCall.function.arguments) });
}
// Debug Message for Tool Calls, configured in the Tool Node
if ((_r = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _r === void 0 ? void 0 : _r.debugMessage) {
const messageLines = [`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER:</b> ${await api.parseCognigyScriptText(toolChild.config.toolId)}`];
// Arguments / Parameters Slots
const slots = ((_s = mainToolCall === null || mainToolCall === void 0 ? void 0 : mainToolCall.function) === null || _s === void 0 ? void 0 : _s.arguments) && Object.keys(mainToolCall.function.arguments);
const hasSlots = slots && 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 slotValueAsString = mainToolCall.function.arguments[slot];
if (typeof slotValueAsString === "object" && slotValueAsString !== null) {
slotValueAsString = JSON.stringify(slotValueAsString, null, 2);
}
else {
String(slotValueAsString);
}
messageLines.push(`- ${slot}: ${slotValueAsString}`);
});
}
(_t = api.logDebugMessage) === null || _t === void 0 ? void 0 : _t.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER");
}
if (toolChild) {
api.setNextNode(toolChild.id);
}
else {
const defaultChild = childConfigs === null || childConfigs === void 0 ? void 0 : childConfigs.find(child => child.type === "llmPromptDefault");
if (defaultChild) {
api.setNextNode(defaultChild.id);
}
}
}
else {
// Default case
const defaultChild = childConfigs === null || childConfigs === void 0 ? void 0 : childConfigs.find(child => child.type === "llmPromptDefault");
if (defaultChild) {
api.setNextNode(defaultChild.id);
}
}
// Optionally output the result immediately
// This will also store it into the output
if (llmResult.result && immediateOutput && !llmPromptOptions.stream) {
// we stringify objects (e.g. results coming from JSON Mode)
// so that the transcript only contains text
const resultToOutput = typeof ((llmResult === null || llmResult === void 0 ? void 0 : llmResult.result) || llmResult) === "object" ? JSON.stringify((llmResult === null || llmResult === void 0 ? void 0 : llmResult.result) || llmResult, undefined, 2) : (llmResult === null || llmResult === void 0 ? void 0 : llmResult.result) || llmResult;
await ((_u = api.output) === null || _u === void 0 ? void 0 : _u.call(api, resultToOutput, {}));
}
else if (llmResult.finishReason && llmPromptOptions.stream) {
// send the finishReason as last output for a stream
(_v = api.output) === null || _v === void 0 ? void 0 : _v.call(api, "", {
_cognigy: {
_preventTranscript: true,
_messageId,
_finishReason: llmResult.finishReason,
}
});
}
// If we are streaming and we got a result, also store it into the transcript, since streamed chunks are not stored there
if (llmResult.result && llmPromptOptions.stream) {
const transcriptContent = {
role: transcripts_1.TranscriptRole.ASSISTANT,
type: transcripts_1.TranscriptEntryType.OUTPUT,
source: "assistant",
payload: {
text: ((llmResult === null || llmResult === void 0 ? void 0 : llmResult.result) || llmResult),
data: {},
}
};
await api.addTranscriptStep(transcriptContent);
}
// Add response to Cognigy Input/Context for further usage
if (storeLocation === "context") {
(_w = api.addToContext) === null || _w === void 0 ? void 0 : _w.call(api, contextKey, llmResult, "simple");
}
else if (storeLocation === "input") {
api.addToInput(inputKey, llmResult);
}
else if (storeLocation === "stream" && streamStoreCopyInInput) {
api.addToInput(inputKey, llmResult);
}
}
catch (error) {
const errorDetailsBase = {
name: error === null || error === void 0 ? void 0 : error.name,
code: (error === null || error === void 0 ? void 0 : error.code) || (error === null || error === void 0 ? void 0 : error.httpStatusCode),
message: (error === null ||