@cognigy/rest-api-client 4.97.0 → 4.99.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 +14 -0
- package/build/RestAPIClient.js +7 -0
- package/build/apigroups/AIOpsCenterAPIGroup_2_0.js +22 -0
- package/build/apigroups/ResourcesAPIGroup_2_0.js +8 -8
- package/build/apigroups/index.js +3 -1
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/knowledgeAssistTemplate.js +0 -44
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage0.js +0 -45
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage1.js +0 -43
- package/build/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stageError.js +0 -45
- package/build/shared/charts/descriptors/analytics/completeGoal.js +2 -2
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/index.js +6 -2
- package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/mistralProviderConnection.js +11 -0
- package/build/shared/charts/descriptors/index.js +2 -0
- package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +10 -1
- package/build/shared/charts/descriptors/logic/think.js +2 -4
- package/build/shared/charts/descriptors/message/say.js +6 -3
- package/build/shared/charts/descriptors/service/GPTPrompt.js +14 -4
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +226 -66
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentJobCallMCPTool.js +180 -0
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentJobMCPTool.js +196 -0
- package/build/shared/charts/descriptors/service/aiAgent/aiAgentToolAnswer.js +5 -1
- package/build/shared/charts/descriptors/service/index.js +5 -1
- package/build/shared/charts/descriptors/voice/mappers/hangup.mapper.js +9 -8
- package/build/shared/charts/descriptors/voice/nodes/hangup.js +1 -1
- package/build/shared/charts/descriptors/voicegateway/nodes/hangup.js +1 -1
- package/build/shared/charts/descriptors/voicegateway2/nodes/hangup.js +24 -2
- package/build/shared/constants.js +8 -1
- package/build/shared/interfaces/IProfileSchema.js +1 -1
- package/build/shared/interfaces/amqpInterface.js +3 -0
- package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +10 -1
- package/build/shared/interfaces/messageAPI/endpoints.js +6 -1
- package/build/shared/interfaces/messageAPI/handover.js +6 -1
- package/build/shared/interfaces/resources/IAiAgent.js +3 -1
- package/build/shared/interfaces/resources/ILargeLanguageModel.js +10 -1
- package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -0
- package/build/shared/interfaces/restAPI/opsCenter/alerts/IIndexOpsCenterAlertsRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/alerts/IOpsCenterAlert.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/component/IOpsCenterComponents.js +34 -0
- package/build/shared/interfaces/restAPI/opsCenter/errors/IDeleteOpsCenterErrorRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/errors/IGetOpsCenterErrorRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/errors/IIndexOpsCenterErrorsRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/errors/IOpsCenterError.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetrics.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsConfigRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsRangeRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/metrics/IOpsCenterMetricsConfig.js +6 -0
- package/build/shared/interfaces/restAPI/opsCenter/observationConfig/IGetOpsCenterObservationConfigRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/observationConfig/IOpsCenterObservationConfig.js +4 -0
- package/build/shared/interfaces/restAPI/opsCenter/observationConfig/IPatchOpsCenterObservationConfigRest_2_0.js +3 -0
- package/build/shared/interfaces/restAPI/opsCenter/observationConfig/ISetupOpsCenterObservationConfigRest_2_0.js +3 -0
- package/build/shared/interfaces/security/IIdentityProvider.js +1 -0
- package/dist/esm/RestAPIClient.js +7 -0
- package/dist/esm/apigroups/AIOpsCenterAPIGroup_2_0.js +18 -0
- package/dist/esm/apigroups/ResourcesAPIGroup_2_0.js +8 -8
- package/dist/esm/apigroups/index.js +1 -0
- package/dist/esm/shared/charts/descriptors/agentAssist/htmlTemplates/knowledgeAssistTemplate.js +0 -44
- package/dist/esm/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage0.js +0 -45
- package/dist/esm/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stage1.js +0 -43
- package/dist/esm/shared/charts/descriptors/agentAssist/htmlTemplates/secureForms/stageError.js +0 -45
- package/dist/esm/shared/charts/descriptors/analytics/completeGoal.js +2 -2
- package/dist/esm/shared/charts/descriptors/connectionNodes/generativeAIProviders/index.js +4 -1
- package/dist/esm/shared/charts/descriptors/connectionNodes/generativeAIProviders/mistralProviderConnection.js +8 -0
- package/dist/esm/shared/charts/descriptors/index.js +3 -1
- package/dist/esm/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +12 -3
- package/dist/esm/shared/charts/descriptors/logic/think.js +2 -4
- package/dist/esm/shared/charts/descriptors/message/say.js +6 -3
- package/dist/esm/shared/charts/descriptors/service/GPTPrompt.js +18 -8
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJob.js +226 -66
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJobCallMCPTool.js +178 -0
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentJobMCPTool.js +193 -0
- package/dist/esm/shared/charts/descriptors/service/aiAgent/aiAgentToolAnswer.js +5 -1
- package/dist/esm/shared/charts/descriptors/service/index.js +2 -0
- package/dist/esm/shared/charts/descriptors/voice/mappers/hangup.mapper.js +9 -8
- package/dist/esm/shared/charts/descriptors/voice/nodes/hangup.js +1 -1
- package/dist/esm/shared/charts/descriptors/voicegateway/nodes/hangup.js +1 -1
- package/dist/esm/shared/charts/descriptors/voicegateway2/nodes/hangup.js +24 -2
- package/dist/esm/shared/constants.js +7 -0
- package/dist/esm/shared/interfaces/IProfileSchema.js +1 -1
- package/dist/esm/shared/interfaces/amqpInterface.js +3 -0
- package/dist/esm/shared/interfaces/generativeAI/IGenerativeAIModels.js +10 -1
- package/dist/esm/shared/interfaces/messageAPI/endpoints.js +6 -1
- package/dist/esm/shared/interfaces/messageAPI/handover.js +6 -1
- package/dist/esm/shared/interfaces/resources/IAiAgent.js +3 -1
- package/dist/esm/shared/interfaces/resources/ILargeLanguageModel.js +9 -0
- package/dist/esm/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/alerts/IIndexOpsCenterAlertsRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/alerts/IOpsCenterAlert.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/component/IOpsCenterComponents.js +31 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/errors/IDeleteOpsCenterErrorRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/errors/IGetOpsCenterErrorRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/errors/IIndexOpsCenterErrorsRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/errors/IOpsCenterError.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetrics.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsConfigRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsRangeRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/metrics/IGetOpsCenterMetricsRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/metrics/IOpsCenterMetricsConfig.js +5 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/observationConfig/IGetOpsCenterObservationConfigRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/observationConfig/IOpsCenterObservationConfig.js +3 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/observationConfig/IPatchOpsCenterObservationConfigRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/restAPI/opsCenter/observationConfig/ISetupOpsCenterObservationConfigRest_2_0.js +2 -0
- package/dist/esm/shared/interfaces/security/IIdentityProvider.js +1 -0
- package/package.json +2 -2
- package/types/index.d.ts +336 -7
|
@@ -540,7 +540,7 @@ export const GPT_PROMPT = createNodeDescriptor({
|
|
|
540
540
|
appearance: {},
|
|
541
541
|
tags: ["ai", "llm", "gpt", "generative ai", "openai", "azure", "prompt"],
|
|
542
542
|
function: ({ cognigy, config, nodeId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
543
|
-
var _a, _b, _c;
|
|
543
|
+
var _a, _b, _c, _d;
|
|
544
544
|
const { api, input } = cognigy;
|
|
545
545
|
const { temperature, maxTokens, topP, presencePenalty, frequencyPenalty, useStop, stop, storeLocation, contextKey, inputKey, timeout, streamStopTokens, streamStopTokenOverrides, debugLogTokenCount, debugLogRequestAndCompletion, llmProviderReferenceId, useChatMode, chatTranscriptSteps, responseFormat, streamStoreCopyInInput, detailedResults, 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.
|
|
546
546
|
errorHandlingGotoTarget, errorMessage, logErrorToSystem, } = config;
|
|
@@ -568,17 +568,17 @@ export const GPT_PROMPT = createNodeDescriptor({
|
|
|
568
568
|
}
|
|
569
569
|
// handle errors from external services, depending on the settings
|
|
570
570
|
const handleServiceError = (error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
571
|
-
var
|
|
571
|
+
var _e, _f, _g;
|
|
572
572
|
const compactError = {
|
|
573
573
|
name: error === null || error === void 0 ? void 0 : error.name,
|
|
574
574
|
code: error === null || error === void 0 ? void 0 : error.code,
|
|
575
575
|
message: (error === null || error === void 0 ? void 0 : error.message) || error
|
|
576
576
|
};
|
|
577
577
|
// return the requestId if it exist in the error obj.
|
|
578
|
-
if ((
|
|
579
|
-
compactError["requestId"] = (
|
|
578
|
+
if ((_e = error === null || error === void 0 ? void 0 : error.meta) === null || _e === void 0 ? void 0 : _e.requestId) {
|
|
579
|
+
compactError["requestId"] = (_f = error === null || error === void 0 ? void 0 : error.meta) === null || _f === void 0 ? void 0 : _f.requestId;
|
|
580
580
|
}
|
|
581
|
-
if ((
|
|
581
|
+
if ((_g = error === null || error === void 0 ? void 0 : error.originalErrorDetails) === null || _g === void 0 ? void 0 : _g.code) {
|
|
582
582
|
compactError.code = error.originalErrorDetails.code;
|
|
583
583
|
}
|
|
584
584
|
const errorResponse = {
|
|
@@ -700,19 +700,29 @@ export const GPT_PROMPT = createNodeDescriptor({
|
|
|
700
700
|
const resultToOutput = typeof ((response === null || response === void 0 ? void 0 : response.result) || response) === "object" ? JSON.stringify((response === null || response === void 0 ? void 0 : response.result) || response, undefined, 2) : (response === null || response === void 0 ? void 0 : response.result) || response;
|
|
701
701
|
yield api.output(resultToOutput, null);
|
|
702
702
|
}
|
|
703
|
+
if (storeLocation === "stream" && responseToStore.finishReason) {
|
|
704
|
+
// send the finishReason as last output for a stream
|
|
705
|
+
(_a = api.output) === null || _a === void 0 ? void 0 : _a.call(api, "", {
|
|
706
|
+
_cognigy: {
|
|
707
|
+
_preventTranscript: true,
|
|
708
|
+
_messageId,
|
|
709
|
+
_finishReason: responseToStore.finishReason,
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
703
713
|
}
|
|
704
714
|
}
|
|
705
715
|
catch (error) {
|
|
706
716
|
const errorDetailsBase = {
|
|
707
717
|
name: error === null || error === void 0 ? void 0 : error.name,
|
|
708
718
|
code: (error === null || error === void 0 ? void 0 : error.code) || (error === null || error === void 0 ? void 0 : error.httpStatusCode),
|
|
709
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || ((
|
|
719
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || ((_b = error.originalErrorDetails) === null || _b === void 0 ? void 0 : _b.message),
|
|
710
720
|
};
|
|
711
721
|
const errorDetails = Object.assign(Object.assign({}, errorDetailsBase), { originalErrorDetails: error === null || error === void 0 ? void 0 : error.originalErrorDetails });
|
|
712
722
|
// return the requestId if it exist in the error obj.
|
|
713
|
-
if ((
|
|
723
|
+
if ((_c = error.meta) === null || _c === void 0 ? void 0 : _c.requestId) {
|
|
714
724
|
errorDetails["meta"] = {
|
|
715
|
-
requestId: (
|
|
725
|
+
requestId: (_d = error.meta) === null || _d === void 0 ? void 0 : _d.requestId
|
|
716
726
|
};
|
|
717
727
|
}
|
|
718
728
|
if (logErrorToSystem) {
|
|
@@ -17,7 +17,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
17
17
|
collapsable: true,
|
|
18
18
|
placement: {
|
|
19
19
|
children: {
|
|
20
|
-
whitelist: ["aiAgentJobDefault", "aiAgentJobTool"],
|
|
20
|
+
whitelist: ["aiAgentJobDefault", "aiAgentJobTool", "aiAgentJobMCPTool"],
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
},
|
|
@@ -639,11 +639,10 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
639
639
|
defaultValue: "",
|
|
640
640
|
type: "ttsSelect",
|
|
641
641
|
label: "_unused_",
|
|
642
|
-
description: "_unused_",
|
|
643
642
|
params: {
|
|
644
643
|
languageKey: "config.ttsLanguage",
|
|
645
644
|
modelKey: "config.ttsModel",
|
|
646
|
-
voiceKey: "config.ttsVoice"
|
|
645
|
+
voiceKey: "config.ttsVoice",
|
|
647
646
|
},
|
|
648
647
|
condition: {
|
|
649
648
|
key: "voiceSetting",
|
|
@@ -668,6 +667,37 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
668
667
|
type: "ttsSelect",
|
|
669
668
|
defaultValue: "",
|
|
670
669
|
label: "_unused_",
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
key: "ttsLabel",
|
|
673
|
+
type: "cognigyText",
|
|
674
|
+
defaultValue: "",
|
|
675
|
+
label: "UI__NODE_EDITOR__VOICEGATEWAY2__SET_SESSION_CONFIG__TTS_LABEL__LABEL",
|
|
676
|
+
description: "UI__NODE_EDITOR__VOICEGATEWAY2__SET_SESSION_CONFIG__TTS_LABEL__DESCRIPTION",
|
|
677
|
+
condition: {
|
|
678
|
+
and: [
|
|
679
|
+
{
|
|
680
|
+
negate: true,
|
|
681
|
+
key: "ttsVendor",
|
|
682
|
+
value: "", // We show the field for all vendors as soon as it is defined
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
key: "voiceSetting",
|
|
686
|
+
value: "jobVoice"
|
|
687
|
+
}
|
|
688
|
+
]
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
key: "ttsDisableCache",
|
|
693
|
+
type: "toggle",
|
|
694
|
+
defaultValue: false,
|
|
695
|
+
label: "UI__NODE_EDITOR__VOICEGATEWAY2__SET_SESSION_CONFIG__TTS_DISABLE_CACHE__LABEL",
|
|
696
|
+
description: "UI__NODE_EDITOR__VOICEGATEWAY2__SET_SESSION_CONFIG__TTS_DISABLE_CACHE__DESCRIPTION",
|
|
697
|
+
condition: {
|
|
698
|
+
key: "voiceSetting",
|
|
699
|
+
value: "jobVoice"
|
|
700
|
+
},
|
|
671
701
|
}
|
|
672
702
|
],
|
|
673
703
|
sections: [
|
|
@@ -718,6 +748,8 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
718
748
|
fields: [
|
|
719
749
|
"voiceSetting",
|
|
720
750
|
"ttsVendor",
|
|
751
|
+
"ttsLabel",
|
|
752
|
+
"ttsDisableCache",
|
|
721
753
|
],
|
|
722
754
|
},
|
|
723
755
|
{
|
|
@@ -790,7 +822,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
790
822
|
],
|
|
791
823
|
tags: ["ai", "aiAgent"],
|
|
792
824
|
function: ({ cognigy, config, childConfigs, nodeId }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
793
|
-
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;
|
|
825
|
+
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;
|
|
794
826
|
const { api, context, input, profile, flowReferenceId } = cognigy;
|
|
795
827
|
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, debugResult, storeLocation, contextKey, inputKey, streamStoreCopyInInput, streamStopTokens, processImages, transcriptImageHandling, sessionParams } = config;
|
|
796
828
|
try {
|
|
@@ -806,6 +838,8 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
806
838
|
ttsLanguage: aiAgent.voiceConfigs.ttsLanguage,
|
|
807
839
|
ttsModel: aiAgent.voiceConfigs.ttsModel,
|
|
808
840
|
ttsVoice: aiAgent.voiceConfigs.ttsVoice,
|
|
841
|
+
ttsLabel: aiAgent.voiceConfigs.ttsLabel,
|
|
842
|
+
ttsDisableCache: aiAgent.voiceConfigs.ttsDisableCache,
|
|
809
843
|
});
|
|
810
844
|
}
|
|
811
845
|
else {
|
|
@@ -815,6 +849,8 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
815
849
|
ttsLanguage: "",
|
|
816
850
|
ttsModel: "",
|
|
817
851
|
ttsVoice: "",
|
|
852
|
+
ttsLabel: "",
|
|
853
|
+
ttsDisableCache: false,
|
|
818
854
|
});
|
|
819
855
|
}
|
|
820
856
|
}
|
|
@@ -826,7 +862,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
826
862
|
const voiceSettings = voiceConfigParamsToVoiceSettings(config, api);
|
|
827
863
|
const payload = setSessionConfig.handleVGInput(voiceSettings, sessionParams || {}, api);
|
|
828
864
|
if (payload && Object.keys(payload).length > 0) {
|
|
829
|
-
api.say(null, {
|
|
865
|
+
(_b = api.say) === null || _b === void 0 ? void 0 : _b.call(api, null, {
|
|
830
866
|
_cognigy: payload,
|
|
831
867
|
});
|
|
832
868
|
}
|
|
@@ -836,16 +872,16 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
836
872
|
throw new Error(`[VG2] Error on AI Agent Job node. Error message: ${error.message}`);
|
|
837
873
|
}
|
|
838
874
|
}
|
|
839
|
-
const
|
|
875
|
+
const _20 = profile, { profileId, accepted_gdpr, prevent_data_collection, privacy_policy } = _20, cleanedProfile = __rest(_20, ["profileId", "accepted_gdpr", "prevent_data_collection", "privacy_policy"]);
|
|
840
876
|
const userMemory = getUserMemory(memoryType, selectedProfileFields, aiAgent, cleanedProfile);
|
|
841
877
|
/**
|
|
842
878
|
* ----- Knowledge Search Section -----
|
|
843
879
|
*/
|
|
844
880
|
let knowledgeSearchResponseData;
|
|
845
881
|
const sessionState = yield api.loadSessionState();
|
|
846
|
-
const lastToolCall = (
|
|
882
|
+
const lastToolCall = (_c = sessionState.lastToolCall) === null || _c === void 0 ? void 0 : _c.toolCall;
|
|
847
883
|
if (knowledgeSearchBehavior === "always" ||
|
|
848
|
-
(knowledgeSearchBehavior === "onDemand" && ((
|
|
884
|
+
(knowledgeSearchBehavior === "onDemand" && ((_d = lastToolCall === null || lastToolCall === void 0 ? void 0 : lastToolCall.function) === null || _d === void 0 ? void 0 : _d.name) === "retrieve_knowledge")) {
|
|
849
885
|
const knowledgeStoreIds = [];
|
|
850
886
|
if (knowledgeSearchAiAgentKnowledge && aiAgent.knowledgeReferenceId) {
|
|
851
887
|
knowledgeStoreIds.push(aiAgent.knowledgeReferenceId);
|
|
@@ -853,8 +889,8 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
853
889
|
if (knowledgeSearchJobKnowledge && knowledgeSearchJobStore) {
|
|
854
890
|
knowledgeStoreIds.push(knowledgeSearchJobStore);
|
|
855
891
|
}
|
|
856
|
-
if (knowledgeStoreIds.length > 0 && (input.text || ((
|
|
857
|
-
let query = ((
|
|
892
|
+
if (knowledgeStoreIds.length > 0 && (input.text || ((_f = (_e = lastToolCall === null || lastToolCall === void 0 ? void 0 : lastToolCall.function) === null || _e === void 0 ? void 0 : _e.arguments) === null || _f === void 0 ? void 0 : _f.generated_prompt))) {
|
|
893
|
+
let query = ((_h = (_g = lastToolCall === null || lastToolCall === void 0 ? void 0 : lastToolCall.function) === null || _g === void 0 ? void 0 : _g.arguments) === null || _h === void 0 ? void 0 : _h.generated_prompt) || input.text;
|
|
858
894
|
if (knowledgeSearchBehavior === "always" && knowledgeSearchGenerateSearchPrompt) {
|
|
859
895
|
const generatedSearchPrompt = yield generateSearchPrompt({ api, userMemory, llmProviderReferenceId, debugLogTokenCount, memoryContextInjection });
|
|
860
896
|
if (generatedSearchPrompt === null || generatedSearchPrompt === void 0 ? void 0 : generatedSearchPrompt.generated_prompt) {
|
|
@@ -870,10 +906,10 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
870
906
|
knowledgeStoreIds,
|
|
871
907
|
};
|
|
872
908
|
if (knowledgeSearchBehavior === "onDemand") {
|
|
873
|
-
const generated_buffer_phrase = (
|
|
909
|
+
const generated_buffer_phrase = (_k = (_j = lastToolCall === null || lastToolCall === void 0 ? void 0 : lastToolCall.function) === null || _j === void 0 ? void 0 : _j.arguments) === null || _k === void 0 ? void 0 : _k.generated_buffer_phrase;
|
|
874
910
|
if (generated_buffer_phrase) {
|
|
875
911
|
// output the generated buffer phrase. Don't add it to the transcript, else the LLM will repeat it next time.
|
|
876
|
-
yield ((
|
|
912
|
+
yield ((_l = api.output) === null || _l === void 0 ? void 0 : _l.call(api, generated_buffer_phrase, {
|
|
877
913
|
_cognigy: {
|
|
878
914
|
_preventTranscript: true
|
|
879
915
|
}
|
|
@@ -903,7 +939,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
903
939
|
if (query) {
|
|
904
940
|
messageLines.push(`\n<b>UI__DEBUG_MODE__AI_AGENT_JOB__KNOWLEDGE_SEARCH__SEARCH_PROMPT</b> ${query}`);
|
|
905
941
|
}
|
|
906
|
-
if ((
|
|
942
|
+
if ((_m = knowledgeSearchResponseData === null || knowledgeSearchResponseData === void 0 ? void 0 : knowledgeSearchResponseData.topK) === null || _m === void 0 ? void 0 : _m.length) {
|
|
907
943
|
knowledgeSearchResponseData === null || knowledgeSearchResponseData === void 0 ? void 0 : knowledgeSearchResponseData.topK.forEach((result, index) => {
|
|
908
944
|
var _a;
|
|
909
945
|
messageLines.push(`\nTop ${index + 1}:`);
|
|
@@ -915,7 +951,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
915
951
|
else {
|
|
916
952
|
messageLines.push("UI__DEBUG_MODE__AI_AGENT_JOB__KNOWLEDGE_SEARCH__NO_RESULTS");
|
|
917
953
|
}
|
|
918
|
-
(
|
|
954
|
+
(_o = api.logDebugMessage) === null || _o === void 0 ? void 0 : _o.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__KNOWLEDGE_SEARCH__HEADER");
|
|
919
955
|
}
|
|
920
956
|
// Knowledge Search "onDemand" responds to a tool call
|
|
921
957
|
if (knowledgeSearchBehavior === "onDemand") {
|
|
@@ -944,7 +980,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
944
980
|
yield api.addTranscriptStep(toolAnswer);
|
|
945
981
|
}
|
|
946
982
|
}
|
|
947
|
-
if (((
|
|
983
|
+
if (((_p = lastToolCall === null || lastToolCall === void 0 ? void 0 : lastToolCall.function) === null || _p === void 0 ? void 0 : _p.name) === "retrieve_knowledge") {
|
|
948
984
|
// remove the retrieve_knowledge toolCall from session state to avoid infinite loops
|
|
949
985
|
api.updateSessionStateValues({
|
|
950
986
|
lastToolCall: undefined
|
|
@@ -956,32 +992,39 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
956
992
|
// create the system Message from the AI Agent resource and this Node's config storage
|
|
957
993
|
const systemMessage = createSystemMessage(aiAgent, input, jobName, jobDescription, jobInstructions, userMemory, memoryContextInjection, isOnDemandKnowledgeStoreConfigured ? "onDemand" : "none");
|
|
958
994
|
// Create Tools JSON
|
|
995
|
+
/** This is the list of tools that are used in the AI Agent Job */
|
|
959
996
|
const tools = [];
|
|
997
|
+
/** Array of tool IDs for deduping */
|
|
960
998
|
const toolIds = [];
|
|
961
|
-
|
|
999
|
+
/** Map of MCP tool IDs to their respective node IDs they were loaded from */
|
|
1000
|
+
const toolMap = new Map();
|
|
1001
|
+
/** Array of tool names for listing in the debug message */
|
|
1002
|
+
const toolNames = [];
|
|
1003
|
+
for (const child of childConfigs) {
|
|
962
1004
|
if (child.type === "aiAgentJobDefault") {
|
|
963
|
-
|
|
1005
|
+
continue;
|
|
964
1006
|
}
|
|
965
|
-
;
|
|
966
1007
|
const toolId = child.config.toolId;
|
|
967
|
-
if (
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1008
|
+
if (child.type === "aiAgentJobTool" &&
|
|
1009
|
+
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
1010
|
+
if (!toolId) {
|
|
1011
|
+
throw new Error(`Tool ID is missing in Tool Node configuration.`);
|
|
1012
|
+
}
|
|
1013
|
+
const parsedToolId = api.parseCognigyScriptText(toolId);
|
|
1014
|
+
if (!validateToolId(parsedToolId)) {
|
|
1015
|
+
throw new Error(`Tool ID ${parsedToolId} is not valid. Please use only alphanumeric characters, dashes and underscores.`);
|
|
1016
|
+
}
|
|
1017
|
+
if (toolIds.includes(parsedToolId)) {
|
|
1018
|
+
throw new Error(`Tool ID ${parsedToolId} is not unique. Please ensure each tool has a unique id.`);
|
|
1019
|
+
}
|
|
1020
|
+
toolIds.push(parsedToolId);
|
|
1021
|
+
toolNames.push(parsedToolId);
|
|
979
1022
|
const tool = {
|
|
980
1023
|
type: "function",
|
|
981
1024
|
function: {
|
|
982
1025
|
name: parsedToolId,
|
|
983
1026
|
description: api.parseCognigyScriptText(child.config.description),
|
|
984
|
-
}
|
|
1027
|
+
},
|
|
985
1028
|
};
|
|
986
1029
|
if (useStrict) {
|
|
987
1030
|
tool.function.strict = true;
|
|
@@ -991,7 +1034,106 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
991
1034
|
}
|
|
992
1035
|
tools.push(tool);
|
|
993
1036
|
}
|
|
994
|
-
|
|
1037
|
+
if (child.type === "aiAgentJobMCPTool" &&
|
|
1038
|
+
(!child.config.condition || !!api.parseCognigyScriptCondition(child.config.condition))) {
|
|
1039
|
+
if (!child.config.mcpServerUrl) {
|
|
1040
|
+
throw new Error(`MCP Server URL is missing in Tool Node configuration.`);
|
|
1041
|
+
}
|
|
1042
|
+
const mcpServerUrl = child.config.mcpServerUrl;
|
|
1043
|
+
const timeout = child.config.timeout;
|
|
1044
|
+
const cacheTools = child.config.cacheTools;
|
|
1045
|
+
const sendDebug = child.config.debugMessageFetchedTools;
|
|
1046
|
+
const toolFilter = child.config.toolFilter;
|
|
1047
|
+
let mcpTools = null;
|
|
1048
|
+
try {
|
|
1049
|
+
mcpTools = yield api.fetchMcpTools({
|
|
1050
|
+
mcpServerUrl,
|
|
1051
|
+
timeout,
|
|
1052
|
+
cacheTools,
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
catch (error) {
|
|
1056
|
+
const errorDetails = error instanceof Error
|
|
1057
|
+
? {
|
|
1058
|
+
name: error.name,
|
|
1059
|
+
message: error.message,
|
|
1060
|
+
}
|
|
1061
|
+
: error;
|
|
1062
|
+
(_q = api.logDebugError) === null || _q === void 0 ? void 0 : _q.call(api, `Unable to connect to MCP Server:<br>${JSON.stringify(errorDetails, null, 2)}`, child.config.name);
|
|
1063
|
+
}
|
|
1064
|
+
if (mcpTools) {
|
|
1065
|
+
if (sendDebug) {
|
|
1066
|
+
if (mcpTools.length === 0) {
|
|
1067
|
+
(_r = api.logDebugMessage) === null || _r === void 0 ? void 0 : _r.call(api, `No tools fetched from MCP Tool "${child.config.name}".`, "MCP Tool");
|
|
1068
|
+
}
|
|
1069
|
+
if (mcpTools.length > 0) {
|
|
1070
|
+
const messageLines = [`Fetched tools from MCP Tool "${child.config.name}"`];
|
|
1071
|
+
mcpTools.forEach((tool) => {
|
|
1072
|
+
messageLines.push(`<br>- <b>${tool.name}</b>: ${tool.description}`);
|
|
1073
|
+
if (child.config.debugMessageParameters && tool.inputSchema) {
|
|
1074
|
+
messageLines.push(` <b>Parameters</b>:`);
|
|
1075
|
+
Object.keys(tool.inputSchema.properties).forEach((key) => {
|
|
1076
|
+
const parameter = tool.inputSchema.properties[key];
|
|
1077
|
+
const requiredText = tool.inputSchema.required && !tool.inputSchema.required.includes(key) ? " (optional)" : "";
|
|
1078
|
+
if (parameter.description) {
|
|
1079
|
+
messageLines.push(` - ${key} (${parameter.type}): ${parameter.description}${requiredText}`);
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
messageLines.push(` - ${key}: ${parameter.type}${requiredText}`);
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
(_s = api.logDebugMessage) === null || _s === void 0 ? void 0 : _s.call(api, messageLines.join("\n"), "MCP Tool");
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const filteredMcpTools = mcpTools.filter((tool) => {
|
|
1091
|
+
if (toolFilter && toolFilter !== "none") {
|
|
1092
|
+
if (toolFilter === "whitelist" && child.config.whitelist) {
|
|
1093
|
+
const whitelist = child.config.whitelist.map((item) => item.trim());
|
|
1094
|
+
return whitelist.includes(tool.name);
|
|
1095
|
+
}
|
|
1096
|
+
else if (toolFilter === "blacklist") {
|
|
1097
|
+
// If the blacklist is falsy, all tools are allowed
|
|
1098
|
+
if (!child.config.blacklist) {
|
|
1099
|
+
return true;
|
|
1100
|
+
}
|
|
1101
|
+
const blacklist = child.config.blacklist.map((item) => item.trim());
|
|
1102
|
+
return !blacklist.includes(tool.name);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
return true;
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
const structuredMcpTools = [];
|
|
1110
|
+
filteredMcpTools.forEach((tool) => {
|
|
1111
|
+
var _a;
|
|
1112
|
+
if (toolIds.includes(tool.name)) {
|
|
1113
|
+
(_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.`);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
// add tool to the list of tool ids to prevent duplicates
|
|
1117
|
+
toolIds.push(tool.name);
|
|
1118
|
+
toolNames.push(`${tool.name} (${child.config.name})`);
|
|
1119
|
+
toolMap.set(tool.name, child.id);
|
|
1120
|
+
const structuredTool = {
|
|
1121
|
+
type: "function",
|
|
1122
|
+
function: {
|
|
1123
|
+
name: tool.name,
|
|
1124
|
+
description: tool.description,
|
|
1125
|
+
},
|
|
1126
|
+
};
|
|
1127
|
+
if (tool.inputSchema) {
|
|
1128
|
+
structuredTool.function.parameters = tool.inputSchema;
|
|
1129
|
+
}
|
|
1130
|
+
structuredMcpTools.push(structuredTool);
|
|
1131
|
+
});
|
|
1132
|
+
tools.push(...structuredMcpTools);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
;
|
|
995
1137
|
// Optional Debug Message with the config
|
|
996
1138
|
if (debugConfig) {
|
|
997
1139
|
const messageLines = [];
|
|
@@ -999,14 +1141,14 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
999
1141
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__AI_AGENT_NAME__LABEL</b> ${aiAgent.name}`);
|
|
1000
1142
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__JOB_NAME__LABEL</b> ${jobName}`);
|
|
1001
1143
|
// Safety settings
|
|
1002
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_HARMFUL_CONTENT</b> ${(
|
|
1003
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_UNGROUNDED_CONTENT</b> ${(
|
|
1004
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_COPYRIGHT_INFRINGEMENTS</b> ${(
|
|
1005
|
-
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_PREVENT_JAILBREAK_AND_MANIPULATION</b> ${(
|
|
1144
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_HARMFUL_CONTENT</b> ${(_t = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _t === void 0 ? void 0 : _t.avoidHarmfulContent}`);
|
|
1145
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_UNGROUNDED_CONTENT</b> ${(_u = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _u === void 0 ? void 0 : _u.avoidUngroundedContent}`);
|
|
1146
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_AVOID_COPYRIGHT_INFRINGEMENTS</b> ${(_v = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _v === void 0 ? void 0 : _v.avoidCopyrightInfringements}`);
|
|
1147
|
+
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__SAFETY_SETTINGS_PREVENT_JAILBREAK_AND_MANIPULATION</b> ${(_w = aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.safetySettings) === null || _w === void 0 ? void 0 : _w.preventJailbreakAndManipulation}`);
|
|
1006
1148
|
// Tools
|
|
1007
|
-
if (
|
|
1149
|
+
if (toolNames.length > 0) {
|
|
1008
1150
|
messageLines.push("<b>UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__TOOLS__LABEL</b>");
|
|
1009
|
-
|
|
1151
|
+
toolNames.forEach(toolName => messageLines.push(`- ${toolName}`));
|
|
1010
1152
|
}
|
|
1011
1153
|
// Memory
|
|
1012
1154
|
if (memoryType !== "none") {
|
|
@@ -1056,7 +1198,9 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1056
1198
|
messageLines.push(`UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__TTS_LANGUAGE ${config.ttsLanguage || 'UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__NOT_SET'}`);
|
|
1057
1199
|
messageLines.push(`UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__TTS_MODEL ${config.ttsModel || 'UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__VOICE_SETTING__NOT_SET'}`);
|
|
1058
1200
|
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'}`);
|
|
1059
|
-
(
|
|
1201
|
+
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'}`);
|
|
1202
|
+
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'}`);
|
|
1203
|
+
(_x = api.logDebugMessage) === null || _x === void 0 ? void 0 : _x.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__CONFIGURATION__HEADER");
|
|
1060
1204
|
}
|
|
1061
1205
|
// keep this after the debug message since the "retrieve_knowledge" tool is implicit
|
|
1062
1206
|
// we only add this tool if at least one knowledge source is enabled
|
|
@@ -1100,14 +1244,14 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1100
1244
|
transcript.length > 0 &&
|
|
1101
1245
|
transcript[transcript.length - 1].role === TranscriptRole.USER) {
|
|
1102
1246
|
const userInput = transcript[transcript.length - 1];
|
|
1103
|
-
const enhancedInput = `## Knowledge Source Context\nAdditional Context from the knowledge source: \n${JSON.stringify(knowledgeSearchResponseData)}\n\n\n${((
|
|
1247
|
+
const enhancedInput = `## Knowledge Source Context\nAdditional Context from the knowledge source: \n${JSON.stringify(knowledgeSearchResponseData)}\n\n\n${((_y = userInput === null || userInput === void 0 ? void 0 : userInput.payload) === null || _y === void 0 ? void 0 : _y.text) || input.text}`;
|
|
1104
1248
|
transcript[transcript.length - 1].payload.text = enhancedInput;
|
|
1105
1249
|
}
|
|
1106
1250
|
const isStreamingChannel = input.channel === "webchat3" || input.channel === "adminconsole";
|
|
1107
1251
|
const _messageId = randomUUID();
|
|
1108
1252
|
const llmPromptOptions = Object.assign(Object.assign({ prompt: "", chat: systemMessage,
|
|
1109
1253
|
// Temp fix to override the transcript if needed
|
|
1110
|
-
transcript: ((
|
|
1254
|
+
transcript: ((_z = context === null || context === void 0 ? void 0 : context._cognigy) === null || _z === void 0 ? void 0 : _z.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) => {
|
|
1111
1255
|
var _a;
|
|
1112
1256
|
text = isStreamingChannel ? text : text.trim();
|
|
1113
1257
|
if (text) {
|
|
@@ -1131,45 +1275,51 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1131
1275
|
};
|
|
1132
1276
|
}
|
|
1133
1277
|
// Set understood to true so that an AI Agent interaction doesn't look false in our analytics
|
|
1134
|
-
(
|
|
1278
|
+
(_0 = api.setAnalyticsData) === null || _0 === void 0 ? void 0 : _0.call(api, "understood", "true");
|
|
1135
1279
|
input.understood = true;
|
|
1136
|
-
const fullLlmResult = yield ((
|
|
1280
|
+
const fullLlmResult = yield ((_1 = api.runGenerativeAIPrompt) === null || _1 === void 0 ? void 0 : _1.call(api, llmPromptOptions, "aiAgent"));
|
|
1137
1281
|
const { messages } = fullLlmResult, llmResult = __rest(fullLlmResult, ["messages"]);
|
|
1138
1282
|
const llmProvider = llmResult === null || llmResult === void 0 ? void 0 : llmResult.provider;
|
|
1139
1283
|
const tokenUsage = fullLlmResult.tokenUsage;
|
|
1140
1284
|
// Send optional debug message with token usage
|
|
1141
1285
|
if (debugLogTokenCount && tokenUsage) {
|
|
1142
|
-
(
|
|
1286
|
+
(_2 = api.logDebugMessage) === null || _2 === void 0 ? void 0 : _2.call(api, tokenUsage, "UI__DEBUG_MODE__AI_AGENT_JOB__TOKEN_USAGE__HEADER");
|
|
1143
1287
|
}
|
|
1144
1288
|
// Identify if the result is a tool call
|
|
1145
1289
|
// If response is a tool call, set next node for Tools
|
|
1146
1290
|
if (llmResult.finishReason === "tool_calls" && llmResult.toolCalls.length > 0) {
|
|
1147
1291
|
const mainToolCall = llmResult.toolCalls[0];
|
|
1292
|
+
let isMcpToolCall = false;
|
|
1148
1293
|
// Find the child node with the toolId of the tool call
|
|
1149
|
-
|
|
1150
|
-
if (toolChild
|
|
1151
|
-
|
|
1294
|
+
let toolChild = childConfigs.find(child => { var _a, _b; return child.type === "aiAgentJobTool" && ((_a = child.config) === null || _a === void 0 ? void 0 : _a.toolId) && api.parseCognigyScriptText((_b = child.config) === null || _b === void 0 ? void 0 : _b.toolId) === mainToolCall.function.name; });
|
|
1295
|
+
if (!toolChild && toolMap.has(mainToolCall.function.name)) {
|
|
1296
|
+
// If the tool call is from an MCP tool, set the next node to the corresponding child node
|
|
1297
|
+
toolChild = childConfigs.find(child => child.id === toolMap.get(mainToolCall.function.name));
|
|
1298
|
+
isMcpToolCall = true;
|
|
1299
|
+
}
|
|
1300
|
+
if (mainToolCall.function.name !== "retrieve_knowledge" && toolChild === undefined) {
|
|
1301
|
+
(_3 = api.logDebugError) === null || _3 === void 0 ? void 0 : _3.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");
|
|
1152
1302
|
}
|
|
1153
1303
|
// Add last tool call to session state for loading it from Tool Answer Node
|
|
1154
1304
|
api.updateSessionStateValues({
|
|
1155
|
-
lastToolCall: {
|
|
1156
|
-
llmProvider,
|
|
1157
|
-
aiAgentJobNode: {
|
|
1305
|
+
lastToolCall: Object.assign(Object.assign({ llmProvider, aiAgentJobNode: {
|
|
1158
1306
|
flow: flowReferenceId,
|
|
1159
|
-
node: nodeId
|
|
1160
|
-
},
|
|
1161
|
-
|
|
1162
|
-
|
|
1307
|
+
node: nodeId,
|
|
1308
|
+
} }, (isMcpToolCall && {
|
|
1309
|
+
mcpServerUrl: (_4 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _4 === void 0 ? void 0 : _4.mcpServerUrl,
|
|
1310
|
+
timeout: (_5 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _5 === void 0 ? void 0 : _5.timeout,
|
|
1311
|
+
mcpToolNode: toolChild === null || toolChild === void 0 ? void 0 : toolChild.id,
|
|
1312
|
+
})), { toolCall: mainToolCall }),
|
|
1163
1313
|
});
|
|
1164
1314
|
// if there are any parameters/arguments, add them to the input slots
|
|
1165
1315
|
if (mainToolCall.function.arguments) {
|
|
1166
|
-
input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (
|
|
1316
|
+
input.aiAgent = Object.assign(Object.assign({}, input.aiAgent), { toolArgs: Object.assign(Object.assign({}, (_7 = (_6 = input.aiAgent) === null || _6 === void 0 ? void 0 : _6.toolArgs) !== null && _7 !== void 0 ? _7 : {}), mainToolCall.function.arguments) });
|
|
1167
1317
|
}
|
|
1168
1318
|
// Debug Message for Tool Calls, configured in the Tool Node
|
|
1169
|
-
if ((
|
|
1319
|
+
if ((_8 = toolChild === null || toolChild === void 0 ? void 0 : toolChild.config) === null || _8 === void 0 ? void 0 : _8.debugMessage) {
|
|
1170
1320
|
const messageLines = [`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER:</b> ${api.parseCognigyScriptText(toolChild.config.toolId)}`];
|
|
1171
1321
|
// Arguments / Parameters Slots
|
|
1172
|
-
const slots = ((
|
|
1322
|
+
const slots = ((_9 = mainToolCall === null || mainToolCall === void 0 ? void 0 : mainToolCall.function) === null || _9 === void 0 ? void 0 : _9.arguments) && Object.keys(mainToolCall.function.arguments);
|
|
1173
1323
|
const hasSlots = slots && slots.length > 0;
|
|
1174
1324
|
messageLines.push(`<b>UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__SLOTS</b>${hasSlots ? "" : " -"}`);
|
|
1175
1325
|
if (hasSlots) {
|
|
@@ -1184,7 +1334,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1184
1334
|
messageLines.push(`- ${slot}: ${slotValueAsString}`);
|
|
1185
1335
|
});
|
|
1186
1336
|
}
|
|
1187
|
-
(
|
|
1337
|
+
(_10 = api.logDebugMessage) === null || _10 === void 0 ? void 0 : _10.call(api, messageLines.join("\n"), "UI__DEBUG_MODE__AI_AGENT_JOB__TOOL_CALL__DEBUG_MESSAGE__HEADER");
|
|
1188
1338
|
}
|
|
1189
1339
|
if (toolChild) {
|
|
1190
1340
|
api.setNextNode(toolChild.id);
|
|
@@ -1209,7 +1359,17 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1209
1359
|
}
|
|
1210
1360
|
// Optionally output the result immediately
|
|
1211
1361
|
if (llmResult.result && outputImmediately && !llmPromptOptions.stream) {
|
|
1212
|
-
yield ((
|
|
1362
|
+
yield ((_11 = api.output) === null || _11 === void 0 ? void 0 : _11.call(api, llmResult.result, {}));
|
|
1363
|
+
}
|
|
1364
|
+
else if (llmResult.finishReason && llmPromptOptions.stream) {
|
|
1365
|
+
// send the finishReason as last output for a stream
|
|
1366
|
+
(_12 = api.output) === null || _12 === void 0 ? void 0 : _12.call(api, "", {
|
|
1367
|
+
_cognigy: {
|
|
1368
|
+
_preventTranscript: true,
|
|
1369
|
+
_messageId,
|
|
1370
|
+
_finishReason: llmResult.finishReason,
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1213
1373
|
}
|
|
1214
1374
|
// If we are streaming and we got a result, also store it into the transcript, since streamed chunks are not stored there
|
|
1215
1375
|
if (llmResult.result && llmPromptOptions.stream) {
|
|
@@ -1226,7 +1386,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1226
1386
|
}
|
|
1227
1387
|
// Add response to Cognigy Input/Context for further usage
|
|
1228
1388
|
if (storeLocation === "context") {
|
|
1229
|
-
(
|
|
1389
|
+
(_13 = api.addToContext) === null || _13 === void 0 ? void 0 : _13.call(api, contextKey, llmResult, "simple");
|
|
1230
1390
|
}
|
|
1231
1391
|
else if (storeLocation === "input") {
|
|
1232
1392
|
api.addToInput(inputKey, llmResult);
|
|
@@ -1239,14 +1399,14 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1239
1399
|
const errorDetails = {
|
|
1240
1400
|
name: (error === null || error === void 0 ? void 0 : error.name) || "Error",
|
|
1241
1401
|
code: (error === null || error === void 0 ? void 0 : error.code) || (error === null || error === void 0 ? void 0 : error.httpStatusCode),
|
|
1242
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || ((
|
|
1402
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || ((_14 = error.originalErrorDetails) === null || _14 === void 0 ? void 0 : _14.message),
|
|
1243
1403
|
};
|
|
1244
|
-
(
|
|
1404
|
+
(_15 = api.emitEvent) === null || _15 === void 0 ? void 0 : _15.call(api, "nodeError", { nodeId, flowId: flowReferenceId, errorMessage: error });
|
|
1245
1405
|
if (logErrorToSystem) {
|
|
1246
|
-
(
|
|
1406
|
+
(_16 = api.log) === null || _16 === void 0 ? void 0 : _16.call(api, "error", JSON.stringify(errorDetails));
|
|
1247
1407
|
}
|
|
1248
1408
|
if (errorHandling !== "stop") {
|
|
1249
|
-
(
|
|
1409
|
+
(_17 = api.logDebugError) === null || _17 === void 0 ? void 0 : _17.call(api, errorDetails.message + (errorDetails.code ? ` (error code: ${errorDetails.code})` : ""), errorDetails.name);
|
|
1250
1410
|
}
|
|
1251
1411
|
if (storeErrorInInput) {
|
|
1252
1412
|
input.aiAgent = input.aiAgent || {};
|
|
@@ -1255,7 +1415,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1255
1415
|
if (errorHandling === "continue") {
|
|
1256
1416
|
// output the timeout message
|
|
1257
1417
|
if (errorMessage) {
|
|
1258
|
-
yield ((
|
|
1418
|
+
yield ((_18 = api.output) === null || _18 === void 0 ? void 0 : _18.call(api, errorMessage, null));
|
|
1259
1419
|
}
|
|
1260
1420
|
// Set default node as next node
|
|
1261
1421
|
const defaultChild = childConfigs.find(child => child.type === "aiAgentJobDefault");
|
|
@@ -1267,7 +1427,7 @@ export const AI_AGENT_JOB = createNodeDescriptor({
|
|
|
1267
1427
|
if (!errorHandlingGotoTarget) {
|
|
1268
1428
|
throw new Error("GoTo Target is required");
|
|
1269
1429
|
}
|
|
1270
|
-
if (!((
|
|
1430
|
+
if (!((_19 = api.checkThink) === null || _19 === void 0 ? void 0 : _19.call(api, nodeId))) {
|
|
1271
1431
|
api.resetNextNodes();
|
|
1272
1432
|
yield api.executeFlow({
|
|
1273
1433
|
flowNode: {
|