@cognigy/rest-api-client 2025.11.0 → 2025.13.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/RestAPIClient.js +7 -0
  3. package/build/apigroups/ResourcesAPIGroup_2_0.js +4 -0
  4. package/build/apigroups/SimulationAPIGroup_2_0.js +58 -0
  5. package/build/apigroups/index.js +3 -1
  6. package/build/shared/charts/descriptors/analytics/trackGoal.js +3 -1
  7. package/build/shared/charts/descriptors/index.js +7 -1
  8. package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +4 -2
  9. package/build/shared/charts/descriptors/message/question/question.js +24 -5
  10. package/build/shared/charts/descriptors/service/GPTPrompt.js +15 -1
  11. package/build/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +32 -173
  12. package/build/shared/charts/descriptors/service/aiAgent/aiAgentJobTool.js +2 -2
  13. package/build/shared/charts/descriptors/service/aiAgent/helpers/createToolDefinitions.js +175 -0
  14. package/build/shared/charts/descriptors/service/aiAgent/loadAiAgent.js +194 -0
  15. package/build/shared/charts/descriptors/service/aiOpsCenterConnection.js +12 -0
  16. package/build/shared/charts/descriptors/service/handoverV2.js +1 -1
  17. package/build/shared/charts/descriptors/service/index.js +13 -1
  18. package/build/shared/charts/descriptors/service/llmPrompt/LLMPromptV2.js +922 -0
  19. package/build/shared/charts/descriptors/service/llmPrompt/llmPromptDefault.js +31 -0
  20. package/build/shared/charts/descriptors/service/llmPrompt/llmPromptMCPTool.js +196 -0
  21. package/build/shared/charts/descriptors/service/llmPrompt/llmPromptTool.js +139 -0
  22. package/build/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +2 -2
  23. package/build/shared/constants.js +1 -5
  24. package/build/shared/interfaces/debugEvents/IGoalCompletedEventPayload.js +3 -0
  25. package/build/shared/interfaces/debugEvents/TDebugEventType.js +1 -0
  26. package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +12 -1
  27. package/build/shared/interfaces/resources/IAuditEvent.js +3 -0
  28. package/build/shared/interfaces/resources/ILargeLanguageModel.js +1 -0
  29. package/build/shared/interfaces/resources/TResourceType.js +2 -0
  30. package/build/shared/interfaces/resources/TRestChannelType.js +5 -0
  31. package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeChunk.js +2 -1
  32. package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +5 -18
  33. package/build/shared/interfaces/restAPI/operations/generateOutput/v2.0/index.js +3 -0
  34. package/build/shared/interfaces/restAPI/opsCenter/observationConfig/IOpsCenterObservationConfig.js +1 -1
  35. package/build/shared/interfaces/restAPI/simulation/simulation/ICreateSimulationRest_2_0.js +3 -0
  36. package/build/shared/interfaces/restAPI/simulation/simulation/IDeleteSimulationRest_2_0.js +3 -0
  37. package/build/shared/interfaces/restAPI/simulation/simulation/IIndexSimulationRest_2_0.js +3 -0
  38. package/build/shared/interfaces/restAPI/simulation/simulation/IReadSimulationRest_2_0.js +3 -0
  39. package/build/shared/interfaces/restAPI/simulation/simulation/IScheduleSimulationRest_2_0.js +3 -0
  40. package/build/shared/interfaces/restAPI/simulation/simulation/ISimulationRest_2_0.js +9 -0
  41. package/build/shared/interfaces/restAPI/simulation/simulation/IUpdateSimulationRest_2_0.js +3 -0
  42. package/build/shared/interfaces/restAPI/simulation/simulationRun/IIndexSimulationRunRest_2_0.js +3 -0
  43. package/build/shared/interfaces/restAPI/simulation/simulationRun/IReadSimulationRunRest_2_0.js +3 -0
  44. package/build/shared/interfaces/restAPI/simulation/simulationRun/ISimulationRunRest_2_0.js +19 -0
  45. package/build/shared/interfaces/restAPI/simulation/simulationRunBatch/IGetAllSimulationRunBatchRest_2_0.js +3 -0
  46. package/build/shared/interfaces/restAPI/simulation/simulationRunBatch/IIndexSimulationRunBatchRest_2_0.js +3 -0
  47. package/build/shared/interfaces/restAPI/simulation/simulationRunBatch/IReadSimulationRunBatchRest_2_0.js +3 -0
  48. package/build/shared/interfaces/restAPI/simulation/simulationRunBatch/ISimulationRunBatchRest_2_0.js +9 -0
  49. package/build/shared/interfaces/security/IPermission.js +2 -0
  50. package/build/shared/interfaces/security/IRole.js +3 -1
  51. package/build/shared/interfaces/security/index.js +1 -1
  52. package/dist/esm/RestAPIClient.js +7 -0
  53. package/dist/esm/apigroups/ResourcesAPIGroup_2_0.js +4 -0
  54. package/dist/esm/apigroups/SimulationAPIGroup_2_0.js +44 -0
  55. package/dist/esm/apigroups/index.js +1 -0
  56. package/dist/esm/shared/charts/descriptors/analytics/trackGoal.js +3 -1
  57. package/dist/esm/shared/charts/descriptors/index.js +8 -2
  58. package/dist/esm/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +4 -2
  59. package/dist/esm/shared/charts/descriptors/message/question/question.js +24 -5
  60. package/dist/esm/shared/charts/descriptors/service/GPTPrompt.js +15 -1
  61. package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +33 -174
  62. package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJobTool.js +2 -2
  63. package/dist/esm/shared/charts/descriptors/service/aiAgent/helpers/createToolDefinitions.js +172 -0
  64. package/dist/esm/shared/charts/descriptors/service/aiAgent/loadAiAgent.js +192 -0
  65. package/dist/esm/shared/charts/descriptors/service/aiOpsCenterConnection.js +9 -0
  66. package/dist/esm/shared/charts/descriptors/service/handoverV2.js +1 -1
  67. package/dist/esm/shared/charts/descriptors/service/index.js +6 -0
  68. package/dist/esm/shared/charts/descriptors/service/llmPrompt/LLMPromptV2.js +909 -0
  69. package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptDefault.js +28 -0
  70. package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptMCPTool.js +193 -0
  71. package/dist/esm/shared/charts/descriptors/service/llmPrompt/llmPromptTool.js +136 -0
  72. package/dist/esm/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +2 -2
  73. package/dist/esm/shared/constants.js +1 -5
  74. package/dist/esm/shared/interfaces/debugEvents/IGoalCompletedEventPayload.js +2 -0
  75. package/dist/esm/shared/interfaces/debugEvents/TDebugEventType.js +1 -0
  76. package/dist/esm/shared/interfaces/generativeAI/IGenerativeAIModels.js +12 -1
  77. package/dist/esm/shared/interfaces/resources/IAuditEvent.js +3 -0
  78. package/dist/esm/shared/interfaces/resources/ILargeLanguageModel.js +1 -0
  79. package/dist/esm/shared/interfaces/resources/TResourceType.js +2 -0
  80. package/dist/esm/shared/interfaces/resources/TRestChannelType.js +5 -0
  81. package/dist/esm/shared/interfaces/resources/knowledgeStore/IKnowledgeChunk.js +2 -1
  82. package/dist/esm/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -17
  83. package/dist/esm/shared/interfaces/restAPI/operations/generateOutput/v2.0/index.js +2 -0
  84. package/dist/esm/shared/interfaces/restAPI/opsCenter/observationConfig/IOpsCenterObservationConfig.js +1 -1
  85. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/ICreateSimulationRest_2_0.js +2 -0
  86. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/IDeleteSimulationRest_2_0.js +2 -0
  87. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/IIndexSimulationRest_2_0.js +2 -0
  88. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/IReadSimulationRest_2_0.js +2 -0
  89. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/IScheduleSimulationRest_2_0.js +2 -0
  90. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/ISimulationRest_2_0.js +6 -0
  91. package/dist/esm/shared/interfaces/restAPI/simulation/simulation/IUpdateSimulationRest_2_0.js +2 -0
  92. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRun/IIndexSimulationRunRest_2_0.js +2 -0
  93. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRun/IReadSimulationRunRest_2_0.js +2 -0
  94. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRun/ISimulationRunRest_2_0.js +16 -0
  95. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRunBatch/IGetAllSimulationRunBatchRest_2_0.js +2 -0
  96. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRunBatch/IIndexSimulationRunBatchRest_2_0.js +2 -0
  97. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRunBatch/IReadSimulationRunBatchRest_2_0.js +2 -0
  98. package/dist/esm/shared/interfaces/restAPI/simulation/simulationRunBatch/ISimulationRunBatchRest_2_0.js +6 -0
  99. package/dist/esm/shared/interfaces/security/IPermission.js +2 -0
  100. package/dist/esm/shared/interfaces/security/IRole.js +3 -1
  101. package/dist/esm/shared/interfaces/security/index.js +1 -1
  102. package/package.json +1 -1
  103. package/types/index.d.ts +394 -45
@@ -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: "cognigyText",
82
+ type: "cognigyLLMText",
82
83
  defaultValue: "Customer Support Specialist",
83
84
  params: {
84
85
  required: true,
@@ -851,7 +852,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
851
852
  ],
852
853
  tags: ["ai", "aiAgent"],
853
854
  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, _22, _23;
855
+ 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;
855
856
  const { api, context, input, profile, flowReferenceId } = cognigy;
856
857
  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;
857
858
  try {
@@ -901,7 +902,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
901
902
  throw new Error(`[VG2] Error on AI Agent Job node. Error message: ${error.message}`);
902
903
  }
903
904
  }
904
- const _24 = profile, { profileId, accepted_gdpr, prevent_data_collection, privacy_policy } = _24, cleanedProfile = __rest(_24, ["profileId", "accepted_gdpr", "prevent_data_collection", "privacy_policy"]);
905
+ const _21 = profile, { profileId, accepted_gdpr, prevent_data_collection, privacy_policy } = _21, cleanedProfile = __rest(_21, ["profileId", "accepted_gdpr", "prevent_data_collection", "privacy_policy"]);
905
906
  const userMemory = (0, getUserMemory_1.getUserMemory)(memoryType, selectedProfileFields, aiAgent, cleanedProfile);
906
907
  /**
907
908
  * ----- Knowledge Search Section -----
@@ -1026,149 +1027,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1026
1027
  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
1028
  (_s = api.logDebugMessage) === null || _s === void 0 ? void 0 : _s.call(api, debugSystemMessage, "UI__DEBUG_MODE__AI_AGENT_JOB__SYSTEM_PROMPT__HEADER");
1028
1029
  }
1029
- // Create Tools JSON
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
- ;
1030
+ const { toolIds, toolNames, toolMap, tools } = await (0, createToolDefinitions_1.createToolDefinitions)(childConfigs, api, useStrict);
1172
1031
  // we only add this tool if at least one knowledge source is enabled
1173
1032
  if (isOnDemandKnowledgeStoreConfigured) {
1174
1033
  const knowledgeTool = {
@@ -1200,7 +1059,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1200
1059
  tools.push(knowledgeTool);
1201
1060
  }
1202
1061
  if (debugLogToolDefinitions) {
1203
- (_w = api.logDebugMessage) === null || _w === void 0 ? void 0 : _w.call(api, tools, "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_DEFINITIONS");
1062
+ (_t = api.logDebugMessage) === null || _t === void 0 ? void 0 : _t.call(api, tools, "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_DEFINITIONS");
1204
1063
  }
1205
1064
  // Optional Debug Message with the config
1206
1065
  if (debugConfig) {
@@ -1209,10 +1068,10 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1209
1068
  messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__AI_AGENT_NAME__LABEL</b> ${aiAgent.name}`);
1210
1069
  messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__JOB_NAME__LABEL</b> ${jobName}`);
1211
1070
  // Safety settings
1212
- messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_HARMFUL_CONTENT</b> ${(_x = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _x === void 0 ? void 0 : _x.avoidHarmfulContent}`);
1213
- messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_UNGROUNDED_CONTENT</b> ${(_y = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _y === void 0 ? void 0 : _y.avoidUngroundedContent}`);
1214
- messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_COPYRIGHT_INFRINGEMENTS</b> ${(_z = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _z === void 0 ? void 0 : _z.avoidCopyrightInfringements}`);
1215
- messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_PREVENT_JAILBREAK_AND_MANIPULATION</b> ${(_0 = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _0 === void 0 ? void 0 : _0.preventJailbreakAndManipulation}`);
1071
+ 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}`);
1072
+ 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}`);
1073
+ 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}`);
1074
+ 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
1075
  // Tools
1217
1076
  if (toolNames.length > 0) {
1218
1077
  messageLines.push("<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__TOOLS__LABEL</b>");
@@ -1268,7 +1127,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1268
1127
  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
1128
  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
1129
  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
- (_1 = api.logDebugMessage) === null || _1 === void 0 ? void 0 : _1.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__HEADER");
1130
+ (_y = api.logDebugMessage) === null || _y === void 0 ? void 0 : _y.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__HEADER");
1272
1131
  }
1273
1132
  const transcript = await api.getTranscript({
1274
1133
  limit: 50,
@@ -1282,14 +1141,14 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1282
1141
  transcript.length > 0 &&
1283
1142
  transcript[transcript.length - 1].role === transcripts_1.TranscriptRole.USER) {
1284
1143
  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${((_2 = userInput === null || userInput === void 0 ? void 0 : userInput.payload) === null || _2 === void 0 ? void 0 : _2.text) || input.text}`;
1144
+ 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
1145
  transcript[transcript.length - 1].payload.text = enhancedInput;
1287
1146
  }
1288
1147
  const isStreamingChannel = input.channel === "webchat3" || input.channel === "adminconsole";
1289
1148
  const _messageId = (0, crypto_1.randomUUID)();
1290
1149
  const llmPromptOptions = Object.assign(Object.assign({ prompt: "", chat: systemMessage,
1291
1150
  // Temp fix to override the transcript if needed
1292
- transcript: ((_3 = context === null || context === void 0 ? void 0 : context._cognigy) === null || _3 === void 0 ? void 0 : _3.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) => {
1151
+ 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
1152
  var _a;
1294
1153
  text = isStreamingChannel ? text : text.trim();
1295
1154
  if (text) {
@@ -1313,15 +1172,15 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1313
1172
  };
1314
1173
  }
1315
1174
  // Set understood to true so that an AI Agent interaction doesn't look false in our analytics
1316
- (_4 = api.setAnalyticsData) === null || _4 === void 0 ? void 0 : _4.call(api, "understood", "true");
1175
+ (_1 = api.setAnalyticsData) === null || _1 === void 0 ? void 0 : _1.call(api, "understood", "true");
1317
1176
  input.understood = true;
1318
- const fullLlmResult = await ((_5 = api.runGenerativeAIPrompt) === null || _5 === void 0 ? void 0 : _5.call(api, llmPromptOptions, "aiAgent"));
1177
+ const fullLlmResult = await ((_2 = api.runGenerativeAIPrompt) === null || _2 === void 0 ? void 0 : _2.call(api, llmPromptOptions, "aiAgent"));
1319
1178
  const { messages } = fullLlmResult, llmResult = __rest(fullLlmResult, ["messages"]);
1320
1179
  const llmProvider = llmResult === null || llmResult === void 0 ? void 0 : llmResult.provider;
1321
1180
  const tokenUsage = fullLlmResult.tokenUsage;
1322
1181
  // Send optional debug message with token usage
1323
1182
  if (debugLogTokenCount && tokenUsage) {
1324
- (_6 = api.logDebugMessage) === null || _6 === void 0 ? void 0 : _6.call(api, tokenUsage, "UI__DEBUG_MODE__AI_AGENT_JOB__TOKEN_USAGE__HEADER");
1183
+ (_3 = api.logDebugMessage) === null || _3 === void 0 ? void 0 : _3.call(api, tokenUsage, "UI__DEBUG_MODE__AI_AGENT_JOB__TOKEN_USAGE__HEADER");
1325
1184
  }
1326
1185
  // Identify if the result is a tool call
1327
1186
  // If response is a tool call, set next node for Tools
@@ -1336,7 +1195,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1336
1195
  isMcpToolCall = true;
1337
1196
  }
1338
1197
  if (mainToolCall.function.name !== "retrieve_knowledge" && toolChild === undefined) {
1339
- (_7 = api.logDebugError) === null || _7 === void 0 ? void 0 : _7.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");
1198
+ (_4 = api.logDebugError) === null || _4 === void 0 ? void 0 : _4.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
1199
  }
1341
1200
  // Add last tool call to session state for loading it from Tool Answer Node
1342
1201
  api.updateSessionStateValues({
@@ -1344,21 +1203,21 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1344
1203
  flow: flowReferenceId,
1345
1204
  node: nodeId,
1346
1205
  } }, (isMcpToolCall && {
1347
- mcpServerUrl: (_8 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _8 === void 0 ? void 0 : _8.mcpServerUrl,
1348
- timeout: (_9 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _9 === void 0 ? void 0 : _9.timeout,
1206
+ mcpServerUrl: (_5 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _5 === void 0 ? void 0 : _5.mcpServerUrl,
1207
+ timeout: (_6 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _6 === void 0 ? void 0 : _6.timeout,
1349
1208
  mcpToolNode: toolChild === null || toolChild === void 0 ? void 0 : toolChild.id,
1350
1209
  })), { toolCall: mainToolCall }),
1351
1210
  });
1352
1211
  // if there are any parameters/arguments, add them to the input slots
1353
1212
  if (mainToolCall.function.arguments) {
1354
- input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (_11 = (_10 = input.aiAgent) === null || _10 === void 0 ? void 0 : _10.toolArgs) !== null && _11 !== void 0 ? _11 : {}), mainToolCall.function.arguments) });
1213
+ input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (_8 = (_7 = input.aiAgent) === null || _7 === void 0 ? void 0 : _7.toolArgs) !== null && _8 !== void 0 ? _8 : {}), mainToolCall.function.arguments) });
1355
1214
  }
1356
1215
  // Debug Message for Tool Calls, configured in the Tool Node
1357
- if ((_12 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _12 === void 0 ? void 0 : _12.debugMessage) {
1216
+ if ((_9 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _9 === void 0 ? void 0 : _9.debugMessage) {
1358
1217
  const toolId = isMcpToolCall ? mainToolCall.function.name : api.parseCognigyScriptText(toolChild.config.toolId);
1359
1218
  const messageLines = [`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER:</b> ${toolId}`];
1360
1219
  // Arguments / Parameters Slots
1361
- const slots = ((_13 = mainToolCall === null || mainToolCall === void 0 ? void 0 : mainToolCall.function) === null || _13 === void 0 ? void 0 : _13.arguments) && Object.keys(mainToolCall.function.arguments);
1220
+ const slots = ((_10 = mainToolCall === null || mainToolCall === void 0 ? void 0 : mainToolCall.function) === null || _10 === void 0 ? void 0 : _10.arguments) && Object.keys(mainToolCall.function.arguments);
1362
1221
  const hasSlots = slots && slots.length > 0;
1363
1222
  messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__SLOTS</b>${hasSlots ? "" : " -"}`);
1364
1223
  if (hasSlots) {
@@ -1373,7 +1232,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1373
1232
  messageLines.push(`- ${slot}: ${slotValueAsString}`);
1374
1233
  });
1375
1234
  }
1376
- (_14 = api.logDebugMessage) === null || _14 === void 0 ? void 0 : _14.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER");
1235
+ (_11 = api.logDebugMessage) === null || _11 === void 0 ? void 0 : _11.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER");
1377
1236
  }
1378
1237
  if (toolChild) {
1379
1238
  api.setNextNode(toolChild.id);
@@ -1398,11 +1257,11 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1398
1257
  }
1399
1258
  // Optionally output the result immediately
1400
1259
  if (llmResult.result && outputImmediately && !llmPromptOptions.stream) {
1401
- await ((_15 = api.output) === null || _15 === void 0 ? void 0 : _15.call(api, llmResult.result, {}));
1260
+ await ((_12 = api.output) === null || _12 === void 0 ? void 0 : _12.call(api, llmResult.result, {}));
1402
1261
  }
1403
1262
  else if (llmResult.finishReason && llmPromptOptions.stream) {
1404
1263
  // send the finishReason as last output for a stream
1405
- (_16 = api.output) === null || _16 === void 0 ? void 0 : _16.call(api, "", {
1264
+ (_13 = api.output) === null || _13 === void 0 ? void 0 : _13.call(api, "", {
1406
1265
  _cognigy: {
1407
1266
  _preventTranscript: true,
1408
1267
  _messageId,
@@ -1425,7 +1284,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1425
1284
  }
1426
1285
  // Add response to Cognigy Input/Context for further usage
1427
1286
  if (storeLocation === "context") {
1428
- (_17 = api.addToContext) === null || _17 === void 0 ? void 0 : _17.call(api, contextKey, llmResult, "simple");
1287
+ (_14 = api.addToContext) === null || _14 === void 0 ? void 0 : _14.call(api, contextKey, llmResult, "simple");
1429
1288
  }
1430
1289
  else if (storeLocation === "input") {
1431
1290
  api.addToInput(inputKey, llmResult);
@@ -1438,14 +1297,14 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1438
1297
  const errorDetails = {
1439
1298
  name: (error === null || error === void 0 ? void 0 : error.name) || "Error",
1440
1299
  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) || ((_18 = error.originalErrorDetails) === null || _18 === void 0 ? void 0 : _18.message),
1300
+ message: (error === null || error === void 0 ? void 0 : error.message) || ((_15 = error.originalErrorDetails) === null || _15 === void 0 ? void 0 : _15.message),
1442
1301
  };
1443
- (_19 = api.emitEvent) === null || _19 === void 0 ? void 0 : _19.call(api, "nodeError", { nodeId, flowId: flowReferenceId, errorMessage: error });
1302
+ (_16 = api.emitEvent) === null || _16 === void 0 ? void 0 : _16.call(api, "nodeError", { nodeId, flowId: flowReferenceId, errorMessage: error });
1444
1303
  if (logErrorToSystem) {
1445
- (_20 = api.log) === null || _20 === void 0 ? void 0 : _20.call(api, "error", JSON.stringify(errorDetails));
1304
+ (_17 = api.log) === null || _17 === void 0 ? void 0 : _17.call(api, "error", JSON.stringify(errorDetails));
1446
1305
  }
1447
1306
  if (errorHandling !== "stop") {
1448
- (_21 = api.logDebugError) === null || _21 === void 0 ? void 0 : _21.call(api, errorDetails.message + (errorDetails.code ? ` (error code: ${errorDetails.code})` : ""), errorDetails.name);
1307
+ (_18 = api.logDebugError) === null || _18 === void 0 ? void 0 : _18.call(api, errorDetails.message + (errorDetails.code ? ` (error code: ${errorDetails.code})` : ""), errorDetails.name);
1449
1308
  }
1450
1309
  if (storeErrorInInput) {
1451
1310
  input.aiAgent = input.aiAgent || {};
@@ -1454,7 +1313,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1454
1313
  if (errorHandling === "continue") {
1455
1314
  // output the timeout message
1456
1315
  if (errorMessage) {
1457
- await ((_22 = api.output) === null || _22 === void 0 ? void 0 : _22.call(api, errorMessage, null));
1316
+ await ((_19 = api.output) === null || _19 === void 0 ? void 0 : _19.call(api, errorMessage, null));
1458
1317
  }
1459
1318
  // Set default node as next node
1460
1319
  const defaultChild = childConfigs.find(child => child.type === "aiAgentJobDefault");
@@ -1466,7 +1325,7 @@ exports.AI_AGENT_JOB = (0, createNodeDescriptor_1.createNodeDescriptor)({
1466
1325
  if (!errorHandlingGotoTarget) {
1467
1326
  throw new Error("GoTo Target is required");
1468
1327
  }
1469
- if (!((_23 = api.checkThink) === null || _23 === void 0 ? void 0 : _23.call(api, nodeId))) {
1328
+ if (!((_20 = api.checkThink) === null || _20 === void 0 ? void 0 : _20.call(api, nodeId))) {
1470
1329
  api.resetNextNodes();
1471
1330
  await api.executeFlow({
1472
1331
  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: "cognigyText",
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: "cognigyText",
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