@cognigy/rest-api-client 2025.12.0 → 2025.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/build/apigroups/ResourcesAPIGroup_2_0.js +8 -1
- package/build/apigroups/SimulationAPIGroup_2_0.js +4 -1
- package/build/shared/charts/descriptors/analytics/trackGoal.js +3 -1
- package/build/shared/charts/descriptors/connectionNodes/internalStorageProviders/amazonStorageProviderConnection.js +7 -1
- package/build/shared/charts/descriptors/index.js +5 -0
- package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +10 -6
- package/build/shared/charts/descriptors/message/question/question.js +12 -1
- package/build/shared/charts/descriptors/nlu/generativeSlotFiller/prompt.js +11 -3
- package/build/shared/charts/descriptors/service/GPTPrompt.js +21 -1
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +71 -175
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentJobTool.js +2 -2
- package/build/shared/charts/descriptors/service/aiAgent/helpers/createToolDefinitions.js +175 -0
- package/build/shared/charts/descriptors/service/aiAgent/loadAiAgent.js +194 -0
- package/build/shared/charts/descriptors/service/handoverV2.js +1 -1
- package/build/shared/charts/descriptors/service/index.js +11 -1
- package/build/shared/charts/descriptors/service/llmPrompt/LLMPromptV2.js +959 -0
- package/build/shared/charts/descriptors/service/llmPrompt/llmPromptDefault.js +31 -0
- package/build/shared/charts/descriptors/service/llmPrompt/llmPromptMCPTool.js +196 -0
- package/build/shared/charts/descriptors/service/llmPrompt/llmPromptTool.js +139 -0
- package/build/shared/constants.js +1 -5
- package/build/shared/interfaces/debugEvents/IGoalCompletedEventPayload.js +3 -0
- package/build/shared/interfaces/debugEvents/TDebugEventType.js +1 -0
- package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +12 -1
- package/build/shared/interfaces/messageAPI/handover.js +6 -0
- package/build/shared/interfaces/resources/ISimulation.js +9 -0
- package/build/shared/interfaces/resources/TResourceType.js +3 -0
- package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeChunk.js +2 -1
- package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +5 -18
- package/build/shared/interfaces/restAPI/operations/generateOutput/v2.0/index.js +3 -0
- package/build/shared/interfaces/restAPI/resources/chart/v2.0/IReadFlowChartAiAgentsRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/simulation/persona/IGeneratePersonaRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/simulation/persona/IGetPersonaOptionsRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/simulation/persona/IRegeneratePersonaFieldRest_2_0.js +3 -0
- package/build/shared/interfaces/security/IPermission.js +4 -0
- package/build/shared/interfaces/security/IRole.js +5 -1
- package/build/shared/interfaces/security/index.js +1 -1
- package/dist/esm/apigroups/ResourcesAPIGroup_2_0.js +8 -1
- package/dist/esm/apigroups/SimulationAPIGroup_2_0.js +4 -1
- package/dist/esm/shared/charts/descriptors/analytics/trackGoal.js +3 -1
- package/dist/esm/shared/charts/descriptors/connectionNodes/internalStorageProviders/amazonStorageProviderConnection.js +7 -1
- package/dist/esm/shared/charts/descriptors/index.js +6 -1
- package/dist/esm/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +10 -6
- package/dist/esm/shared/charts/descriptors/message/question/question.js +12 -1
- package/dist/esm/shared/charts/descriptors/nlu/generativeSlotFiller/prompt.js +11 -3
- package/dist/esm/shared/charts/descriptors/service/GPTPrompt.js +21 -1
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +72 -176
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJobTool.js +2 -2
- package/dist/esm/shared/charts/descriptors/service/aiAgent/helpers/createToolDefinitions.js +172 -0
- package/dist/esm/shared/charts/descriptors/service/aiAgent/loadAiAgent.js +192 -0
- package/dist/esm/shared/charts/descriptors/service/handoverV2.js +1 -1
- package/dist/esm/shared/charts/descriptors/service/index.js +5 -0
- package/dist/esm/shared/charts/descriptors/service/llmPrompt/LLMPromptV2.js +946 -0
- package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptDefault.js +28 -0
- package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptMCPTool.js +193 -0
- package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptTool.js +136 -0
- package/dist/esm/shared/constants.js +1 -5
- package/dist/esm/shared/interfaces/debugEvents/IGoalCompletedEventPayload.js +2 -0
- package/dist/esm/shared/interfaces/debugEvents/TDebugEventType.js +1 -0
- package/dist/esm/shared/interfaces/generativeAI/IGenerativeAIModels.js +12 -1
- package/dist/esm/shared/interfaces/messageAPI/handover.js +6 -0
- package/dist/esm/shared/interfaces/resources/ISimulation.js +6 -0
- package/dist/esm/shared/interfaces/resources/TResourceType.js +3 -0
- package/dist/esm/shared/interfaces/resources/knowledgeStore/IKnowledgeChunk.js +2 -1
- package/dist/esm/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -17
- package/dist/esm/shared/interfaces/restAPI/operations/generateOutput/v2.0/index.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/resources/chart/v2.0/IReadFlowChartAiAgentsRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/simulation/persona/IGeneratePersonaRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/simulation/persona/IGetPersonaOptionsRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/simulation/persona/IRegeneratePersonaFieldRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/security/IPermission.js +4 -0
- package/dist/esm/shared/interfaces/security/IRole.js +5 -1
- package/dist/esm/shared/interfaces/security/index.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +2093 -1927
|
@@ -21,6 +21,7 @@ const logFullConfigToDebugMode_1 = require("../../../../helper/logFullConfigToDe
|
|
|
21
21
|
const createSystemMessage_1 = require("./helpers/createSystemMessage");
|
|
22
22
|
const generateSearchPrompt_1 = require("./helpers/generateSearchPrompt");
|
|
23
23
|
const getUserMemory_1 = require("./helpers/getUserMemory");
|
|
24
|
+
const createToolDefinitions_1 = require("./helpers/createToolDefinitions");
|
|
24
25
|
const transcripts_1 = require("../../../../interfaces/transcripts/transcripts");
|
|
25
26
|
exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
26
27
|
type: "aiAgentJob",
|
|
@@ -78,7 +79,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
78
79
|
{
|
|
79
80
|
key: "name",
|
|
80
81
|
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__JOB_NAME__LABEL",
|
|
81
|
-
type: "
|
|
82
|
+
type: "cognigyLLMText",
|
|
82
83
|
defaultValue: "Customer Support Specialist",
|
|
83
84
|
params: {
|
|
84
85
|
required: true,
|
|
@@ -511,6 +512,13 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
511
512
|
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_CONFIG__DESCRIPTION",
|
|
512
513
|
defaultValue: true
|
|
513
514
|
},
|
|
515
|
+
{
|
|
516
|
+
key: "debugLogLLMLatency",
|
|
517
|
+
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_LLM_LATENCY__LABEL",
|
|
518
|
+
type: "toggle",
|
|
519
|
+
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_JOB__FIELDS__LOG_LLM_LATENCY__DESCRIPTION",
|
|
520
|
+
defaultValue: false
|
|
521
|
+
},
|
|
514
522
|
{
|
|
515
523
|
key: "storeLocation",
|
|
516
524
|
type: "select",
|
|
@@ -830,7 +838,8 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
830
838
|
"debugResult",
|
|
831
839
|
"debugLogTokenCount",
|
|
832
840
|
"debugLogSystemPrompt",
|
|
833
|
-
"debugLogToolDefinitions"
|
|
841
|
+
"debugLogToolDefinitions",
|
|
842
|
+
"debugLogLLMLatency"
|
|
834
843
|
],
|
|
835
844
|
}
|
|
836
845
|
],
|
|
@@ -851,9 +860,9 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
851
860
|
],
|
|
852
861
|
tags: ["ai", "aiAgent"],
|
|
853
862
|
function: async ({ cognigy, config, childConfigs, nodeId }) => {
|
|
854
|
-
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, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21
|
|
863
|
+
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, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
|
|
855
864
|
const { api, context, input, profile, flowReferenceId } = cognigy;
|
|
856
|
-
const { aiAgent, llmProviderReferenceId, name: jobName, description: jobDescription, instructions: jobInstructions, outputImmediately, toolChoice, useStrict, memoryType, selectedProfileFields, memoryContextInjection, knowledgeSearchBehavior, knowledgeSearchTags, knowledgeSearchTagsFilterOp, knowledgeSearchAiAgentKnowledge, knowledgeSearchJobKnowledge, knowledgeSearchJobStore, knowledgeSearchGenerateSearchPrompt, knowledgeSearchTopK, timeoutInMs, maxTokens, temperature, logErrorToSystem, storeErrorInInput, errorHandling, errorHandlingGotoTarget, errorMessage, debugConfig, debugLogTokenCount, debugLogSystemPrompt, debugLogToolDefinitions, debugResult, storeLocation, contextKey, inputKey, streamStoreCopyInInput, streamStopTokens, processImages, transcriptImageHandling, sessionParams } = config;
|
|
865
|
+
const { aiAgent, llmProviderReferenceId, name: jobName, description: jobDescription, instructions: jobInstructions, outputImmediately, toolChoice, useStrict, memoryType, selectedProfileFields, memoryContextInjection, knowledgeSearchBehavior, knowledgeSearchTags, knowledgeSearchTagsFilterOp, knowledgeSearchAiAgentKnowledge, knowledgeSearchJobKnowledge, knowledgeSearchJobStore, knowledgeSearchGenerateSearchPrompt, knowledgeSearchTopK, timeoutInMs, maxTokens, temperature, logErrorToSystem, storeErrorInInput, errorHandling, errorHandlingGotoTarget, errorMessage, debugConfig, debugLogTokenCount, debugLogSystemPrompt, debugLogToolDefinitions, debugResult, debugLogLLMLatency, storeLocation, contextKey, inputKey, streamStoreCopyInInput, streamStopTokens, processImages, transcriptImageHandling, sessionParams } = config;
|
|
857
866
|
try {
|
|
858
867
|
if (!aiAgent) {
|
|
859
868
|
throw new Error("Could not resolve AI Agent reference in AI Agent Node");
|
|
@@ -901,7 +910,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
901
910
|
throw new Error(`[VG2] Error on AI Agent Job node. Error message: ${error.message}`);
|
|
902
911
|
}
|
|
903
912
|
}
|
|
904
|
-
const
|
|
913
|
+
const _22 = profile, { profileId, accepted_gdpr, prevent_data_collection, privacy_policy } = _22, cleanedProfile = __rest(_22, ["profileId", "accepted_gdpr", "prevent_data_collection", "privacy_policy"]);
|
|
905
914
|
const userMemory = (0, getUserMemory_1.getUserMemory)(memoryType, selectedProfileFields, aiAgent, cleanedProfile);
|
|
906
915
|
/**
|
|
907
916
|
* ----- Knowledge Search Section -----
|
|
@@ -1026,149 +1035,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1026
1035
|
const debugSystemMessage = (_r = (_q = systemMessage[0]) === null || _q === void 0 ? void 0 : _q.content) === null || _r === void 0 ? void 0 : _r.replace(`${(0, createSystemMessage_1.getCognigyBrandMessage)()}\n`, "");
|
|
1027
1036
|
(_s = api.logDebugMessage) === null || _s === void 0 ? void 0 : _s.call(api, debugSystemMessage, "UI__DEBUG_MODE__AI_AGENT_JOB__SYSTEM_PROMPT__HEADER");
|
|
1028
1037
|
}
|
|
1029
|
-
|
|
1030
|
-
/** This is the list of tools that are used in the AI Agent Job */
|
|
1031
|
-
const tools = [];
|
|
1032
|
-
/** Array of tool IDs for deduping */
|
|
1033
|
-
const toolIds = [];
|
|
1034
|
-
/** Map of MCP tool IDs to their respective node IDs they were loaded from */
|
|
1035
|
-
const toolMap = new Map();
|
|
1036
|
-
/** Array of tool names for listing in the debug message */
|
|
1037
|
-
const toolNames = [];
|
|
1038
|
-
for (const child of childConfigs) {
|
|
1039
|
-
if (child.type === "aiAgentJobDefault") {
|
|
1040
|
-
continue;
|
|
1041
|
-
}
|
|
1042
|
-
const toolId = child.config.toolId;
|
|
1043
|
-
if (child.type === "aiAgentJobTool" &&
|
|
1044
|
-
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
1045
|
-
if (!toolId) {
|
|
1046
|
-
throw new Error(`Tool ID is missing in Tool Node configuration.`);
|
|
1047
|
-
}
|
|
1048
|
-
const parsedToolId = api.parseCognigyScriptText(toolId);
|
|
1049
|
-
if (!(0, createSystemMessage_1.validateToolId)(parsedToolId)) {
|
|
1050
|
-
throw new Error(`Tool ID ${parsedToolId} is not valid. Please use only alphanumeric characters, dashes and underscores.`);
|
|
1051
|
-
}
|
|
1052
|
-
if (toolIds.includes(parsedToolId)) {
|
|
1053
|
-
throw new Error(`Tool ID ${parsedToolId} is not unique. Please ensure each tool has a unique id.`);
|
|
1054
|
-
}
|
|
1055
|
-
toolIds.push(parsedToolId);
|
|
1056
|
-
toolNames.push(parsedToolId);
|
|
1057
|
-
const tool = {
|
|
1058
|
-
type: "function",
|
|
1059
|
-
function: {
|
|
1060
|
-
name: parsedToolId,
|
|
1061
|
-
description: api.parseCognigyScriptText(child.config.description),
|
|
1062
|
-
},
|
|
1063
|
-
};
|
|
1064
|
-
if (useStrict) {
|
|
1065
|
-
tool.function.strict = true;
|
|
1066
|
-
}
|
|
1067
|
-
if (child.config.useParameters) {
|
|
1068
|
-
tool.function.parameters = child.config.parameters;
|
|
1069
|
-
}
|
|
1070
|
-
tools.push(tool);
|
|
1071
|
-
}
|
|
1072
|
-
if (child.type === "aiAgentJobMCPTool" &&
|
|
1073
|
-
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
1074
|
-
if (!child.config.mcpServerUrl) {
|
|
1075
|
-
throw new Error(`MCP Server URL is missing in Tool Node configuration.`);
|
|
1076
|
-
}
|
|
1077
|
-
const mcpServerUrl = child.config.mcpServerUrl;
|
|
1078
|
-
const timeout = child.config.timeout;
|
|
1079
|
-
const cacheTools = child.config.cacheTools;
|
|
1080
|
-
const sendDebug = child.config.debugMessageFetchedTools;
|
|
1081
|
-
const toolFilter = child.config.toolFilter;
|
|
1082
|
-
let mcpTools = null;
|
|
1083
|
-
try {
|
|
1084
|
-
mcpTools = await api.fetchMcpTools({
|
|
1085
|
-
mcpServerUrl,
|
|
1086
|
-
timeout,
|
|
1087
|
-
cacheTools,
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
catch (error) {
|
|
1091
|
-
const errorDetails = error instanceof Error
|
|
1092
|
-
? {
|
|
1093
|
-
name: error.name,
|
|
1094
|
-
message: error.message,
|
|
1095
|
-
}
|
|
1096
|
-
: error;
|
|
1097
|
-
(_t = api.logDebugError) === null || _t === void 0 ? void 0 : _t.call(api, `Unable to connect to MCP Server:<br>${JSON.stringify(errorDetails, null, 2)}`, child.config.name);
|
|
1098
|
-
}
|
|
1099
|
-
if (mcpTools) {
|
|
1100
|
-
if (sendDebug) {
|
|
1101
|
-
if (mcpTools.length === 0) {
|
|
1102
|
-
(_u = api.logDebugMessage) === null || _u === void 0 ? void 0 : _u.call(api, `No tools fetched from MCP Tool "${child.config.name}".`, "MCP Tool");
|
|
1103
|
-
}
|
|
1104
|
-
if (mcpTools.length > 0) {
|
|
1105
|
-
const messageLines = [`Fetched tools from MCP Tool "${child.config.name}"`];
|
|
1106
|
-
mcpTools.forEach((tool) => {
|
|
1107
|
-
messageLines.push(`<br>- <b>${tool.name}</b>: ${tool.description}`);
|
|
1108
|
-
if (child.config.debugMessageParameters && tool.inputSchema) {
|
|
1109
|
-
messageLines.push(` <b>Parameters</b>:`);
|
|
1110
|
-
Object.keys(tool.inputSchema.properties).forEach((key) => {
|
|
1111
|
-
const parameter = tool.inputSchema.properties[key];
|
|
1112
|
-
const requiredText = tool.inputSchema.required && !tool.inputSchema.required.includes(key) ? " (optional)" : "";
|
|
1113
|
-
if (parameter.description) {
|
|
1114
|
-
messageLines.push(` - ${key} (${parameter.type}): ${parameter.description}${requiredText}`);
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
messageLines.push(` - ${key}: ${parameter.type}${requiredText}`);
|
|
1118
|
-
}
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
|
-
});
|
|
1122
|
-
(_v = api.logDebugMessage) === null || _v === void 0 ? void 0 : _v.call(api, messageLines.join("\n"), "MCP Tool");
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
const filteredMcpTools = mcpTools.filter((tool) => {
|
|
1126
|
-
if (toolFilter && toolFilter !== "none") {
|
|
1127
|
-
if (toolFilter === "whitelist" && child.config.whitelist) {
|
|
1128
|
-
const whitelist = child.config.whitelist.map((item) => item.trim());
|
|
1129
|
-
return whitelist.includes(tool.name);
|
|
1130
|
-
}
|
|
1131
|
-
else if (toolFilter === "blacklist") {
|
|
1132
|
-
// If the blacklist is falsy, all tools are allowed
|
|
1133
|
-
if (!child.config.blacklist) {
|
|
1134
|
-
return true;
|
|
1135
|
-
}
|
|
1136
|
-
const blacklist = child.config.blacklist.map((item) => item.trim());
|
|
1137
|
-
return !blacklist.includes(tool.name);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
else {
|
|
1141
|
-
return true;
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
|
-
const structuredMcpTools = [];
|
|
1145
|
-
filteredMcpTools.forEach((tool) => {
|
|
1146
|
-
var _a;
|
|
1147
|
-
if (toolIds.includes(tool.name)) {
|
|
1148
|
-
(_a = api.logDebugError) === null || _a === void 0 ? void 0 : _a.call(api, `Tool "${tool.name}" from MCP Tool "${child.config.name}" is not unique and will not be added. Please ensure each tool has a unique id.`);
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
// add tool to the list of tool ids to prevent duplicates
|
|
1152
|
-
toolIds.push(tool.name);
|
|
1153
|
-
toolNames.push(`${tool.name} (${child.config.name})`);
|
|
1154
|
-
toolMap.set(tool.name, child.id);
|
|
1155
|
-
const structuredTool = {
|
|
1156
|
-
type: "function",
|
|
1157
|
-
function: {
|
|
1158
|
-
name: tool.name,
|
|
1159
|
-
description: tool.description,
|
|
1160
|
-
},
|
|
1161
|
-
};
|
|
1162
|
-
if (tool.inputSchema) {
|
|
1163
|
-
structuredTool.function.parameters = tool.inputSchema;
|
|
1164
|
-
}
|
|
1165
|
-
structuredMcpTools.push(structuredTool);
|
|
1166
|
-
});
|
|
1167
|
-
tools.push(...structuredMcpTools);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
;
|
|
1038
|
+
const { toolIds, toolNames, toolMap, tools } = await (0, createToolDefinitions_1.createToolDefinitions)(childConfigs, api, useStrict);
|
|
1172
1039
|
// we only add this tool if at least one knowledge source is enabled
|
|
1173
1040
|
if (isOnDemandKnowledgeStoreConfigured) {
|
|
1174
1041
|
const knowledgeTool = {
|
|
@@ -1200,7 +1067,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1200
1067
|
tools.push(knowledgeTool);
|
|
1201
1068
|
}
|
|
1202
1069
|
if (debugLogToolDefinitions) {
|
|
1203
|
-
(
|
|
1070
|
+
(_t = api.logDebugMessage) === null || _t === void 0 ? void 0 : _t.call(api, tools, "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_DEFINITIONS");
|
|
1204
1071
|
}
|
|
1205
1072
|
// Optional Debug Message with the config
|
|
1206
1073
|
if (debugConfig) {
|
|
@@ -1209,10 +1076,10 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1209
1076
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__AI_AGENT_NAME__LABEL</b> ${aiAgent.name}`);
|
|
1210
1077
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__JOB_NAME__LABEL</b> ${jobName}`);
|
|
1211
1078
|
// Safety settings
|
|
1212
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_HARMFUL_CONTENT</b> ${(
|
|
1213
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_UNGROUNDED_CONTENT</b> ${(
|
|
1214
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_COPYRIGHT_INFRINGEMENTS</b> ${(
|
|
1215
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_PREVENT_JAILBREAK_AND_MANIPULATION</b> ${(
|
|
1079
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_HARMFUL_CONTENT</b> ${(_u = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _u === void 0 ? void 0 : _u.avoidHarmfulContent}`);
|
|
1080
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_UNGROUNDED_CONTENT</b> ${(_v = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _v === void 0 ? void 0 : _v.avoidUngroundedContent}`);
|
|
1081
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_COPYRIGHT_INFRINGEMENTS</b> ${(_w = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _w === void 0 ? void 0 : _w.avoidCopyrightInfringements}`);
|
|
1082
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_PREVENT_JAILBREAK_AND_MANIPULATION</b> ${(_x = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _x === void 0 ? void 0 : _x.preventJailbreakAndManipulation}`);
|
|
1216
1083
|
// Tools
|
|
1217
1084
|
if (toolNames.length > 0) {
|
|
1218
1085
|
messageLines.push("<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__TOOLS__LABEL</b>");
|
|
@@ -1268,7 +1135,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1268
1135
|
messageLines.push(`UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__TTS_VOICE ${config.ttsVoice || 'UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__NOT_SET'}`);
|
|
1269
1136
|
messageLines.push(`UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__TTS_LABEL ${config.ttsLabel || 'UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__NOT_SET'}`);
|
|
1270
1137
|
messageLines.push(`UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__TTS_DISABLE_CACHE ${config.ttsDisableCache || 'UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__NOT_SET'}`);
|
|
1271
|
-
(
|
|
1138
|
+
(_y = api.logDebugMessage) === null || _y === void 0 ? void 0 : _y.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__HEADER");
|
|
1272
1139
|
}
|
|
1273
1140
|
const transcript = await api.getTranscript({
|
|
1274
1141
|
limit: 50,
|
|
@@ -1282,17 +1149,21 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1282
1149
|
transcript.length > 0 &&
|
|
1283
1150
|
transcript[transcript.length - 1].role === transcripts_1.TranscriptRole.USER) {
|
|
1284
1151
|
const userInput = transcript[transcript.length - 1];
|
|
1285
|
-
const enhancedInput = `## Knowledge Source Context\nAdditional Context from the knowledge source: \n${JSON.stringify(knowledgeSearchResponseData)}\n\n\n${((
|
|
1152
|
+
const enhancedInput = `## Knowledge Source Context\nAdditional Context from the knowledge source: \n${JSON.stringify(knowledgeSearchResponseData)}\n\n\n${((_z = userInput === null || userInput === void 0 ? void 0 : userInput.payload) === null || _z === void 0 ? void 0 : _z.text) || input.text}`;
|
|
1286
1153
|
transcript[transcript.length - 1].payload.text = enhancedInput;
|
|
1287
1154
|
}
|
|
1288
1155
|
const isStreamingChannel = input.channel === "webchat3" || input.channel === "adminconsole";
|
|
1289
1156
|
const _messageId = (0, crypto_1.randomUUID)();
|
|
1290
1157
|
const llmPromptOptions = Object.assign(Object.assign({ prompt: "", chat: systemMessage,
|
|
1291
1158
|
// Temp fix to override the transcript if needed
|
|
1292
|
-
transcript: ((
|
|
1159
|
+
transcript: ((_0 = context === null || context === void 0 ? void 0 : context._cognigy) === null || _0 === void 0 ? void 0 : _0.transcript) ? [...context._cognigy.transcript] : transcript, detailedResults: true, timeoutInMs: timeoutInMs !== null && timeoutInMs !== void 0 ? timeoutInMs : 8000, maxTokens: maxTokens !== null && maxTokens !== void 0 ? maxTokens : 4000, temperature: temperature !== null && temperature !== void 0 ? temperature : 0.7, topP: 1, frequencyPenalty: 0, presencePenalty: 0, responseFormat: "text", stream: storeLocation === "stream", streamOnDataHandler: (text) => {
|
|
1293
1160
|
var _a;
|
|
1294
1161
|
text = isStreamingChannel ? text : text.trim();
|
|
1295
1162
|
if (text) {
|
|
1163
|
+
// Record first output time for debugging if not already recorded
|
|
1164
|
+
if (debugLogLLMLatency && firstOutputTime === null) {
|
|
1165
|
+
firstOutputTime = Date.now();
|
|
1166
|
+
}
|
|
1296
1167
|
// if we got text, we output it, but prevent it from being added to the transcript
|
|
1297
1168
|
(_a = api.output) === null || _a === void 0 ? void 0 : _a.call(api, text, {
|
|
1298
1169
|
_cognigy: {
|
|
@@ -1313,15 +1184,40 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1313
1184
|
};
|
|
1314
1185
|
}
|
|
1315
1186
|
// Set understood to true so that an AI Agent interaction doesn't look false in our analytics
|
|
1316
|
-
(
|
|
1187
|
+
(_1 = api.setAnalyticsData) === null || _1 === void 0 ? void 0 : _1.call(api, "understood", "true");
|
|
1317
1188
|
input.understood = true;
|
|
1318
|
-
|
|
1189
|
+
// Start measuring LLM latency and time to first output if debug flag is enabled
|
|
1190
|
+
const llmStartTime = debugLogLLMLatency ? Date.now() : 0;
|
|
1191
|
+
let firstOutputTime = null;
|
|
1192
|
+
const fullLlmResult = await ((_2 = api.runGenerativeAIPrompt) === null || _2 === void 0 ? void 0 : _2.call(api, llmPromptOptions, "aiAgent"));
|
|
1193
|
+
// End measuring times and log if debug flag is enabled
|
|
1194
|
+
if (debugLogLLMLatency) {
|
|
1195
|
+
const llmEndTime = Date.now();
|
|
1196
|
+
const debugMessages = [];
|
|
1197
|
+
const llmLatencyMs = llmEndTime - llmStartTime;
|
|
1198
|
+
let timeToFirstOutputLabel;
|
|
1199
|
+
if (fullLlmResult.finishReason === "tool_calls" && fullLlmResult.toolCalls.length > 0) {
|
|
1200
|
+
timeToFirstOutputLabel = " - (tool call)";
|
|
1201
|
+
}
|
|
1202
|
+
else if (firstOutputTime === null) {
|
|
1203
|
+
timeToFirstOutputLabel = " - (no output)";
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
firstOutputTime = firstOutputTime || llmEndTime;
|
|
1207
|
+
timeToFirstOutputLabel = `${firstOutputTime - llmStartTime}ms`;
|
|
1208
|
+
}
|
|
1209
|
+
if (storeLocation === "stream") {
|
|
1210
|
+
debugMessages.push(`UI__DEBUG_MODE__AI_AGENT_JOB__TIME_TO_FIRST_OUTPUT__LABEL: ${timeToFirstOutputLabel}`);
|
|
1211
|
+
}
|
|
1212
|
+
debugMessages.push(`UI__DEBUG_MODE__AI_AGENT_JOB__LLM_LATENCY__LABEL: ${llmLatencyMs}ms`);
|
|
1213
|
+
(_3 = api.logDebugMessage) === null || _3 === void 0 ? void 0 : _3.call(api, debugMessages.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TIMING__HEADER");
|
|
1214
|
+
}
|
|
1319
1215
|
const { messages } = fullLlmResult, llmResult = __rest(fullLlmResult, ["messages"]);
|
|
1320
1216
|
const llmProvider = llmResult === null || llmResult === void 0 ? void 0 : llmResult.provider;
|
|
1321
1217
|
const tokenUsage = fullLlmResult.tokenUsage;
|
|
1322
1218
|
// Send optional debug message with token usage
|
|
1323
1219
|
if (debugLogTokenCount && tokenUsage) {
|
|
1324
|
-
(
|
|
1220
|
+
(_4 = api.logDebugMessage) === null || _4 === void 0 ? void 0 : _4.call(api, tokenUsage, "UI__DEBUG_MODE__AI_AGENT_JOB__TOKEN_USAGE__HEADER");
|
|
1325
1221
|
}
|
|
1326
1222
|
// Identify if the result is a tool call
|
|
1327
1223
|
// If response is a tool call, set next node for Tools
|
|
@@ -1336,7 +1232,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1336
1232
|
isMcpToolCall = true;
|
|
1337
1233
|
}
|
|
1338
1234
|
if (mainToolCall.function.name !== "retrieve_knowledge" && toolChild === undefined) {
|
|
1339
|
-
(
|
|
1235
|
+
(_5 = api.logDebugError) === null || _5 === void 0 ? void 0 : _5.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");
|
|
1340
1236
|
}
|
|
1341
1237
|
// Add last tool call to session state for loading it from Tool Answer Node
|
|
1342
1238
|
api.updateSessionStateValues({
|
|
@@ -1344,21 +1240,21 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1344
1240
|
flow: flowReferenceId,
|
|
1345
1241
|
node: nodeId,
|
|
1346
1242
|
} }, (isMcpToolCall && {
|
|
1347
|
-
mcpServerUrl: (
|
|
1348
|
-
timeout: (
|
|
1243
|
+
mcpServerUrl: (_6 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _6 === void 0 ? void 0 : _6.mcpServerUrl,
|
|
1244
|
+
timeout: (_7 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _7 === void 0 ? void 0 : _7.timeout,
|
|
1349
1245
|
mcpToolNode: toolChild === null || toolChild === void 0 ? void 0 : toolChild.id,
|
|
1350
1246
|
})), { toolCall: mainToolCall }),
|
|
1351
1247
|
});
|
|
1352
1248
|
// if there are any parameters/arguments, add them to the input slots
|
|
1353
1249
|
if (mainToolCall.function.arguments) {
|
|
1354
|
-
input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (
|
|
1250
|
+
input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (_9 = (_8 = input.aiAgent) === null || _8 === void 0 ? void 0 : _8.toolArgs) !== null && _9 !== void 0 ? _9 : {}), mainToolCall.function.arguments) });
|
|
1355
1251
|
}
|
|
1356
1252
|
// Debug Message for Tool Calls, configured in the Tool Node
|
|
1357
|
-
if ((
|
|
1253
|
+
if ((_10 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _10 === void 0 ? void 0 : _10.debugMessage) {
|
|
1358
1254
|
const toolId = isMcpToolCall ? mainToolCall.function.name : api.parseCognigyScriptText(toolChild.config.toolId);
|
|
1359
1255
|
const messageLines = [`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER:</b> ${toolId}`];
|
|
1360
1256
|
// Arguments / Parameters Slots
|
|
1361
|
-
const slots = ((
|
|
1257
|
+
const slots = ((_11 = mainToolCall === null || mainToolCall === void 0 ? void 0 : mainToolCall.function) === null || _11 === void 0 ? void 0 : _11.arguments) && Object.keys(mainToolCall.function.arguments);
|
|
1362
1258
|
const hasSlots = slots && slots.length > 0;
|
|
1363
1259
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__SLOTS</b>${hasSlots ? "" : " -"}`);
|
|
1364
1260
|
if (hasSlots) {
|
|
@@ -1373,7 +1269,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1373
1269
|
messageLines.push(`- ${slot}: ${slotValueAsString}`);
|
|
1374
1270
|
});
|
|
1375
1271
|
}
|
|
1376
|
-
(
|
|
1272
|
+
(_12 = api.logDebugMessage) === null || _12 === void 0 ? void 0 : _12.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER");
|
|
1377
1273
|
}
|
|
1378
1274
|
if (toolChild) {
|
|
1379
1275
|
api.setNextNode(toolChild.id);
|
|
@@ -1398,11 +1294,11 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1398
1294
|
}
|
|
1399
1295
|
// Optionally output the result immediately
|
|
1400
1296
|
if (llmResult.result && outputImmediately && !llmPromptOptions.stream) {
|
|
1401
|
-
await ((
|
|
1297
|
+
await ((_13 = api.output) === null || _13 === void 0 ? void 0 : _13.call(api, llmResult.result, {}));
|
|
1402
1298
|
}
|
|
1403
1299
|
else if (llmResult.finishReason && llmPromptOptions.stream) {
|
|
1404
1300
|
// send the finishReason as last output for a stream
|
|
1405
|
-
(
|
|
1301
|
+
(_14 = api.output) === null || _14 === void 0 ? void 0 : _14.call(api, "", {
|
|
1406
1302
|
_cognigy: {
|
|
1407
1303
|
_preventTranscript: true,
|
|
1408
1304
|
_messageId,
|
|
@@ -1425,7 +1321,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1425
1321
|
}
|
|
1426
1322
|
// Add response to Cognigy Input/Context for further usage
|
|
1427
1323
|
if (storeLocation === "context") {
|
|
1428
|
-
(
|
|
1324
|
+
(_15 = api.addToContext) === null || _15 === void 0 ? void 0 : _15.call(api, contextKey, llmResult, "simple");
|
|
1429
1325
|
}
|
|
1430
1326
|
else if (storeLocation === "input") {
|
|
1431
1327
|
api.addToInput(inputKey, llmResult);
|
|
@@ -1438,14 +1334,14 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1438
1334
|
const errorDetails = {
|
|
1439
1335
|
name: (error === null || error === void 0 ? void 0 : error.name) || "Error",
|
|
1440
1336
|
code: (error === null || error === void 0 ? void 0 : error.code) || (error === null || error === void 0 ? void 0 : error.httpStatusCode),
|
|
1441
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || ((
|
|
1337
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || ((_16 = error.originalErrorDetails) === null || _16 === void 0 ? void 0 : _16.message),
|
|
1442
1338
|
};
|
|
1443
|
-
(
|
|
1339
|
+
(_17 = api.emitEvent) === null || _17 === void 0 ? void 0 : _17.call(api, "nodeError", { nodeId, flowId: flowReferenceId, errorMessage: error });
|
|
1444
1340
|
if (logErrorToSystem) {
|
|
1445
|
-
(
|
|
1341
|
+
(_18 = api.log) === null || _18 === void 0 ? void 0 : _18.call(api, "error", JSON.stringify(errorDetails));
|
|
1446
1342
|
}
|
|
1447
1343
|
if (errorHandling !== "stop") {
|
|
1448
|
-
(
|
|
1344
|
+
(_19 = api.logDebugError) === null || _19 === void 0 ? void 0 : _19.call(api, errorDetails.message + (errorDetails.code ? ` (error code: ${errorDetails.code})` : ""), errorDetails.name);
|
|
1449
1345
|
}
|
|
1450
1346
|
if (storeErrorInInput) {
|
|
1451
1347
|
input.aiAgent = input.aiAgent || {};
|
|
@@ -1454,7 +1350,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1454
1350
|
if (errorHandling === "continue") {
|
|
1455
1351
|
// output the timeout message
|
|
1456
1352
|
if (errorMessage) {
|
|
1457
|
-
await ((
|
|
1353
|
+
await ((_20 = api.output) === null || _20 === void 0 ? void 0 : _20.call(api, errorMessage, null));
|
|
1458
1354
|
}
|
|
1459
1355
|
// Set default node as next node
|
|
1460
1356
|
const defaultChild = childConfigs.find(child => child.type === "aiAgentJobDefault");
|
|
@@ -1466,7 +1362,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
1466
1362
|
if (!errorHandlingGotoTarget) {
|
|
1467
1363
|
throw new Error("GoTo Target is required");
|
|
1468
1364
|
}
|
|
1469
|
-
if (!((
|
|
1365
|
+
if (!((_21 = api.checkThink) === null || _21 === void 0 ? void 0 : _21.call(api, nodeId))) {
|
|
1470
1366
|
api.resetNextNodes();
|
|
1471
1367
|
await api.executeFlow({
|
|
1472
1368
|
flowNode: {
|
|
@@ -29,7 +29,7 @@ exports.AI_AGENT_JOB_TOOL = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
29
29
|
key: "toolId",
|
|
30
30
|
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__TOOL_ID__LABEL",
|
|
31
31
|
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__TOOL_ID__DESCRIPTION",
|
|
32
|
-
type: "
|
|
32
|
+
type: "cognigyLLMText",
|
|
33
33
|
defaultValue: "unlock_account",
|
|
34
34
|
params: {
|
|
35
35
|
required: true,
|
|
@@ -42,7 +42,7 @@ exports.AI_AGENT_JOB_TOOL = (0, createNodeDescriptor_1.createNodeDescriptor)({
|
|
|
42
42
|
key: "description",
|
|
43
43
|
label: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DESCRIPTION__LABEL",
|
|
44
44
|
description: "UI__NODE_EDITOR__SERVICE__AI_AGENT_TOOL__FIELDS__DESCRIPTION__DESCRIPTION",
|
|
45
|
-
type: "
|
|
45
|
+
type: "cognigyLLMText",
|
|
46
46
|
defaultValue: "This tool unlocks a locked user account.",
|
|
47
47
|
params: {
|
|
48
48
|
required: true,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createToolDefinitions = void 0;
|
|
4
|
+
const createSystemMessage_1 = require("./createSystemMessage");
|
|
5
|
+
/**
|
|
6
|
+
* Creates the tool definitions for the AI Agent Job and LLM Prompt v2 Nodes
|
|
7
|
+
* @param childConfigs Child node configurations
|
|
8
|
+
* @param api Cognigy API
|
|
9
|
+
* @param useStrict Whether to use strict mode for the tools
|
|
10
|
+
* @returns An object containing the tool definitions
|
|
11
|
+
*/
|
|
12
|
+
const createToolDefinitions = async (childConfigs, api, useStrict) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
// Create Tools JSON
|
|
15
|
+
/** This is the list of tools that are used in the AI Agent Job */
|
|
16
|
+
const tools = [];
|
|
17
|
+
/** Array of tool IDs for deduping */
|
|
18
|
+
const toolIds = [];
|
|
19
|
+
/** Map of MCP tool IDs to their respective node IDs they were loaded from */
|
|
20
|
+
const toolMap = new Map();
|
|
21
|
+
/** Array of tool names for listing in the debug message */
|
|
22
|
+
const toolNames = [];
|
|
23
|
+
// if no child configs are provided, return empty tool definitions
|
|
24
|
+
if (!childConfigs || childConfigs.length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
toolIds: [],
|
|
27
|
+
toolNames: [],
|
|
28
|
+
toolMap: new Map(),
|
|
29
|
+
tools: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Loop through all child nodes and create the tools
|
|
33
|
+
for (const child of childConfigs) {
|
|
34
|
+
if (child.type === "aiAgentJobDefault" || child.type === "llmPromptDefault") {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const toolId = child.config.toolId;
|
|
38
|
+
if ((child.type === "aiAgentJobTool" || child.type === "llmPromptTool") &&
|
|
39
|
+
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
40
|
+
if (!toolId) {
|
|
41
|
+
throw new Error(`Tool ID is missing in Tool Node configuration.`);
|
|
42
|
+
}
|
|
43
|
+
const parsedToolId = api.parseCognigyScriptText(toolId);
|
|
44
|
+
if (!(0, createSystemMessage_1.validateToolId)(parsedToolId)) {
|
|
45
|
+
throw new Error(`Tool ID ${parsedToolId} is not valid. Please use only alphanumeric characters, dashes and underscores.`);
|
|
46
|
+
}
|
|
47
|
+
if (toolIds.includes(parsedToolId)) {
|
|
48
|
+
throw new Error(`Tool ID ${parsedToolId} is not unique. Please ensure each tool has a unique id.`);
|
|
49
|
+
}
|
|
50
|
+
toolIds.push(parsedToolId);
|
|
51
|
+
toolNames.push(parsedToolId);
|
|
52
|
+
const tool = {
|
|
53
|
+
type: "function",
|
|
54
|
+
function: {
|
|
55
|
+
name: parsedToolId,
|
|
56
|
+
description: api.parseCognigyScriptText(child.config.description),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
if (useStrict) {
|
|
60
|
+
tool.function.strict = true;
|
|
61
|
+
}
|
|
62
|
+
if (child.config.useParameters) {
|
|
63
|
+
tool.function.parameters = child.config.parameters;
|
|
64
|
+
}
|
|
65
|
+
tools.push(tool);
|
|
66
|
+
}
|
|
67
|
+
if ((child.type === "aiAgentJobMCPTool" || child.type === "llmPromptMCPTool") &&
|
|
68
|
+
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
69
|
+
if (!child.config.mcpServerUrl) {
|
|
70
|
+
throw new Error(`MCP Server URL is missing in Tool Node configuration.`);
|
|
71
|
+
}
|
|
72
|
+
const mcpServerUrl = child.config.mcpServerUrl;
|
|
73
|
+
const timeout = child.config.timeout;
|
|
74
|
+
const cacheTools = child.config.cacheTools;
|
|
75
|
+
const sendDebug = child.config.debugMessageFetchedTools;
|
|
76
|
+
const toolFilter = child.config.toolFilter;
|
|
77
|
+
let mcpTools = null;
|
|
78
|
+
try {
|
|
79
|
+
mcpTools = await api.fetchMcpTools({
|
|
80
|
+
mcpServerUrl,
|
|
81
|
+
timeout,
|
|
82
|
+
cacheTools,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const errorDetails = error instanceof Error
|
|
87
|
+
? {
|
|
88
|
+
name: error.name,
|
|
89
|
+
message: error.message,
|
|
90
|
+
}
|
|
91
|
+
: error;
|
|
92
|
+
(_a = api.logDebugError) === null || _a === void 0 ? void 0 : _a.call(api, `Unable to connect to MCP Server:<br>${JSON.stringify(errorDetails, null, 2)}`, child.config.name);
|
|
93
|
+
}
|
|
94
|
+
if (mcpTools) {
|
|
95
|
+
if (sendDebug) {
|
|
96
|
+
if (mcpTools.length === 0) {
|
|
97
|
+
(_b = api.logDebugMessage) === null || _b === void 0 ? void 0 : _b.call(api, `No tools fetched from MCP Tool "${child.config.name}".`, "MCP Tool");
|
|
98
|
+
}
|
|
99
|
+
if (mcpTools.length > 0) {
|
|
100
|
+
const messageLines = [`Fetched tools from MCP Tool "${child.config.name}"`];
|
|
101
|
+
mcpTools.forEach((tool) => {
|
|
102
|
+
messageLines.push(`<br>- <b>${tool.name}</b>: ${tool.description}`);
|
|
103
|
+
if (child.config.debugMessageParameters && tool.inputSchema) {
|
|
104
|
+
messageLines.push(` <b>Parameters</b>:`);
|
|
105
|
+
Object.keys(tool.inputSchema.properties).forEach((key) => {
|
|
106
|
+
const parameter = tool.inputSchema.properties[key];
|
|
107
|
+
const requiredText = tool.inputSchema.required && !tool.inputSchema.required.includes(key) ? " (optional)" : "";
|
|
108
|
+
if (parameter.description) {
|
|
109
|
+
messageLines.push(` - ${key} (${parameter.type}): ${parameter.description}${requiredText}`);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
messageLines.push(` - ${key}: ${parameter.type}${requiredText}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
(_c = api.logDebugMessage) === null || _c === void 0 ? void 0 : _c.call(api, messageLines.join("\n"), "MCP Tool");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const filteredMcpTools = mcpTools.filter((tool) => {
|
|
121
|
+
if (toolFilter && toolFilter !== "none") {
|
|
122
|
+
if (toolFilter === "whitelist" && child.config.whitelist) {
|
|
123
|
+
const whitelist = child.config.whitelist.map((item) => item.trim());
|
|
124
|
+
return whitelist.includes(tool.name);
|
|
125
|
+
}
|
|
126
|
+
else if (toolFilter === "blacklist") {
|
|
127
|
+
// If the blacklist is falsy, all tools are allowed
|
|
128
|
+
if (!child.config.blacklist) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
const blacklist = child.config.blacklist.map((item) => item.trim());
|
|
132
|
+
return !blacklist.includes(tool.name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const structuredMcpTools = [];
|
|
140
|
+
filteredMcpTools.forEach((tool) => {
|
|
141
|
+
var _a;
|
|
142
|
+
if (toolIds.includes(tool.name)) {
|
|
143
|
+
(_a = api.logDebugError) === null || _a === void 0 ? void 0 : _a.call(api, `Tool "${tool.name}" from MCP Tool "${child.config.name}" is not unique and will not be added. Please ensure each tool has a unique id.`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// add tool to the list of tool ids to prevent duplicates
|
|
147
|
+
toolIds.push(tool.name);
|
|
148
|
+
toolNames.push(`${tool.name} (${child.config.name})`);
|
|
149
|
+
toolMap.set(tool.name, child.id);
|
|
150
|
+
const structuredTool = {
|
|
151
|
+
type: "function",
|
|
152
|
+
function: {
|
|
153
|
+
name: tool.name,
|
|
154
|
+
description: tool.description,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
if (tool.inputSchema) {
|
|
158
|
+
structuredTool.function.parameters = tool.inputSchema;
|
|
159
|
+
}
|
|
160
|
+
structuredMcpTools.push(structuredTool);
|
|
161
|
+
});
|
|
162
|
+
tools.push(...structuredMcpTools);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
;
|
|
167
|
+
return {
|
|
168
|
+
toolIds,
|
|
169
|
+
toolNames,
|
|
170
|
+
toolMap,
|
|
171
|
+
tools,
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
exports.createToolDefinitions = createToolDefinitions;
|
|
175
|
+
//# sourceMappingURL=createToolDefinitions.js.map
|