@cognigy/rest-api-client 0.17.0 → 0.19.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 (191) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/GenericTusFn.js +6 -1
  3. package/build/GenericUploadFn.js +3 -5
  4. package/build/apigroups/AdministrationAPIGroup_2_0.js +3 -1
  5. package/build/apigroups/MetricsAPIGroup_2_0.js +5 -0
  6. package/build/apigroups/ResourcesAPIGroup_2_0.js +21 -7
  7. package/build/connector/AxiosAdapter.js +35 -15
  8. package/build/shared/charts/createNodeDescriptor.js +5 -5
  9. package/build/shared/charts/descriptors/agentAssist/constants/constants.js +16 -1
  10. package/build/shared/charts/descriptors/agentAssist/helpers/agentAssistTranslator.helper.js +19 -0
  11. package/build/shared/charts/descriptors/agentAssist/helpers/determineMetadata.js +15 -0
  12. package/build/shared/charts/descriptors/agentAssist/helpers/getFontSizeFieldOptions.js +84 -0
  13. package/build/shared/charts/descriptors/agentAssist/helpers/getLanguageName.helper.js +33 -0
  14. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/answerExtraction.helper.js +59 -0
  15. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/configValidator.helper.js +20 -0
  16. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/errorHandler.helper.js +64 -0
  17. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/followUpDetection.helper.js +72 -0
  18. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/knowledgeSearch.helper.js +58 -0
  19. package/build/shared/charts/descriptors/agentAssist/helpers/sentiment.helper.js +7 -13
  20. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/identityAssistTemplate.js +17 -18
  21. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/knowledgeAssistTemplate.js +330 -153
  22. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/nextActionWidgetTemplate.js +212 -80
  23. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/sentimentAnalysisTemplate.js +11 -6
  24. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/transcriptAssistTemplate.js +15 -13
  25. package/build/shared/charts/descriptors/agentAssist/identityAssist.js +88 -15
  26. package/build/shared/charts/descriptors/agentAssist/knowledgeAssist.js +192 -327
  27. package/build/shared/charts/descriptors/agentAssist/locales/cs.locale.js +11 -0
  28. package/build/shared/charts/descriptors/agentAssist/locales/de.locale.js +11 -0
  29. package/build/shared/charts/descriptors/agentAssist/locales/en.locale.js +11 -0
  30. package/build/shared/charts/descriptors/agentAssist/locales/es.locale.js +11 -0
  31. package/build/shared/charts/descriptors/agentAssist/locales/fr.locale.js +11 -0
  32. package/build/shared/charts/descriptors/agentAssist/locales/index.js +22 -0
  33. package/build/shared/charts/descriptors/agentAssist/locales/ja.locale.js +11 -0
  34. package/build/shared/charts/descriptors/agentAssist/locales/ko.locale.js +11 -0
  35. package/build/shared/charts/descriptors/agentAssist/locales/pt.locale.js +11 -0
  36. package/build/shared/charts/descriptors/agentAssist/nextActionAssist.js +484 -10
  37. package/build/shared/charts/descriptors/agentAssist/sentimentAssist.js +32 -9
  38. package/build/shared/charts/descriptors/agentAssist/setAdaptiveCardTile.js +2 -0
  39. package/build/shared/charts/descriptors/agentAssist/setAgentAssistGrid.js +2 -1
  40. package/build/shared/charts/descriptors/agentAssist/setHtmlTile.js +5 -3
  41. package/build/shared/charts/descriptors/agentAssist/setIframeTile.js +5 -3
  42. package/build/shared/charts/descriptors/agentAssist/setSecureFormsTile.js +2 -2
  43. package/build/shared/charts/descriptors/agentAssist/transcriptAssist.js +42 -3
  44. package/build/shared/charts/descriptors/analytics/activateProfile.js +1 -0
  45. package/build/shared/charts/descriptors/analytics/blindMode.js +2 -0
  46. package/build/shared/charts/descriptors/analytics/completeGoal.js +1 -0
  47. package/build/shared/charts/descriptors/analytics/deactivateProfile.js +1 -0
  48. package/build/shared/charts/descriptors/analytics/deleteProfile.js +1 -0
  49. package/build/shared/charts/descriptors/analytics/index.js +3 -1
  50. package/build/shared/charts/descriptors/analytics/mergeProfile.js +1 -0
  51. package/build/shared/charts/descriptors/analytics/overwriteAnalytics.js +9 -0
  52. package/build/shared/charts/descriptors/analytics/requestRating.js +56 -2
  53. package/build/shared/charts/descriptors/analytics/setRating.js +4 -2
  54. package/build/shared/charts/descriptors/analytics/trackMilestone.js +95 -0
  55. package/build/shared/charts/descriptors/analytics/updateProfile.js +1 -0
  56. package/build/shared/charts/descriptors/apps/initAppSession.js +1 -0
  57. package/build/shared/charts/descriptors/apps/setAdaptiveCardAppState.js +35 -10
  58. package/build/shared/charts/descriptors/apps/setHtmlAppState.js +25 -2
  59. package/build/shared/charts/descriptors/apps/utils/getXAppsOverlaySettings.js +54 -0
  60. package/build/shared/charts/descriptors/connectionNodes/documentParserProviders/azureAIDocumentIntelligenceConnection.js +12 -0
  61. package/build/shared/charts/descriptors/connectionNodes/documentParserProviders/index.js +13 -0
  62. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/awsBedrockProviderConnection.js +12 -0
  63. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/azureOpenAIProviderConnection.js +4 -3
  64. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/azureOpenAIProviderConnectionV2.js +3 -3
  65. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/azureOpenAIProviderOauth2Connection.js +14 -0
  66. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/index.js +16 -8
  67. package/build/shared/charts/descriptors/connectionNodes/generativeAIProviders/openAIProviderConnection.js +3 -3
  68. package/build/shared/charts/descriptors/data/addToContext.js +7 -0
  69. package/build/shared/charts/descriptors/data/copyDataToContext.js +3 -0
  70. package/build/shared/charts/descriptors/data/copySlotsToContext.js +3 -0
  71. package/build/shared/charts/descriptors/data/debugMessage.js +73 -0
  72. package/build/shared/charts/descriptors/data/index.js +3 -1
  73. package/build/shared/charts/descriptors/data/removeFromContext.js +9 -1
  74. package/build/shared/charts/descriptors/data/resetContext.js +1 -0
  75. package/build/shared/charts/descriptors/index.js +8 -4
  76. package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +36 -11
  77. package/build/shared/charts/descriptors/logic/resetState.js +1 -0
  78. package/build/shared/charts/descriptors/logic/setState.js +2 -1
  79. package/build/shared/charts/descriptors/logic/setTranslation.js +3 -1
  80. package/build/shared/charts/descriptors/logic/switchLocale.js +1 -0
  81. package/build/shared/charts/descriptors/logic/think.js +3 -1
  82. package/build/shared/charts/descriptors/logic/thinkV2.js +2 -0
  83. package/build/shared/charts/descriptors/message/question/optionalQuestion.js +1 -1
  84. package/build/shared/charts/descriptors/message/question/question.js +173 -7
  85. package/build/shared/charts/descriptors/message/question/utils/evaluateQuestionAnswer.js +44 -3
  86. package/build/shared/charts/descriptors/message/question/utils/validateQuestionAnswer.js +4 -2
  87. package/build/shared/charts/descriptors/nlu/cleanText.js +1 -0
  88. package/build/shared/charts/descriptors/nlu/fuzzySearch.js +23 -1
  89. package/build/shared/charts/descriptors/nlu/generativeSlotFiller/prompt.js +45 -19
  90. package/build/shared/charts/descriptors/nlu/index.js +1 -3
  91. package/build/shared/charts/descriptors/service/GPTPrompt.js +362 -29
  92. package/build/shared/charts/descriptors/service/LLMEntityExtract.js +283 -0
  93. package/build/shared/charts/descriptors/service/handoverV2.js +84 -1
  94. package/build/shared/charts/descriptors/service/httpRequest.js +68 -3
  95. package/build/shared/charts/descriptors/service/index.js +3 -1
  96. package/build/shared/charts/descriptors/voice/mappers/setSessionConfig.mapper.js +110 -27
  97. package/build/shared/charts/descriptors/voice/mappers/transfer.mapper.js +4 -4
  98. package/build/shared/charts/descriptors/voice/nodes/bargeIn.js +2 -0
  99. package/build/shared/charts/descriptors/voice/nodes/continuousAsr.js +2 -0
  100. package/build/shared/charts/descriptors/voice/nodes/dtmf.js +2 -0
  101. package/build/shared/charts/descriptors/voice/nodes/muteSpeechInput.js +1 -0
  102. package/build/shared/charts/descriptors/voice/nodes/noUserInput.js +2 -0
  103. package/build/shared/charts/descriptors/voice/nodes/play.js +8 -1
  104. package/build/shared/charts/descriptors/voice/nodes/sessionSpeechParameters.js +46 -45
  105. package/build/shared/charts/descriptors/voice/nodes/transfer.js +2 -0
  106. package/build/shared/charts/descriptors/voicegateway2/nodes/dtmf.js +2 -0
  107. package/build/shared/charts/descriptors/voicegateway2/nodes/hangup.js +2 -0
  108. package/build/shared/charts/descriptors/voicegateway2/nodes/muteSpeechInput.js +3 -0
  109. package/build/shared/charts/descriptors/voicegateway2/nodes/play.js +1 -1
  110. package/build/shared/charts/descriptors/voicegateway2/nodes/record.js +1 -0
  111. package/build/shared/charts/descriptors/voicegateway2/nodes/refer.js +1 -0
  112. package/build/shared/charts/descriptors/voicegateway2/nodes/sendMetadata.js +1 -0
  113. package/build/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +329 -47
  114. package/build/shared/charts/descriptors/voicegateway2/nodes/transfer.js +27 -31
  115. package/build/shared/charts/descriptors/voicegateway2/utils/helper.js +2 -2
  116. package/build/shared/charts/helpers/generativeAI/generativeAIPrompts.js +55 -0
  117. package/build/shared/charts/helpers/generativeAI/rephraseSentenceWithAi.js +4 -2
  118. package/build/shared/constants.js +10 -1
  119. package/build/shared/handoverClients/interfaces/THandoverEventType.js +1 -0
  120. package/build/shared/helper/logFullConfigToDebugMode.js +30 -0
  121. package/build/shared/helper/nlu/textCleaner.js +3 -1
  122. package/build/shared/interfaces/IOrganisation.js +1 -0
  123. package/build/shared/interfaces/IProfile.js +1 -0
  124. package/build/shared/interfaces/IProfileSchema.js +3 -0
  125. package/build/shared/interfaces/analytics/IAnalyticsSourceData.js +20 -20
  126. package/build/shared/interfaces/{restAPI/resources/journey/v2.0/IJourneyProgress_2_0.js → analytics/IMilestoneAnalytics.js} +1 -1
  127. package/build/shared/interfaces/{restAPI/resources/journey/v2.0/IJourney_2_0.js → appsession/IAppSession.js} +1 -1
  128. package/build/shared/interfaces/{restAPI/resources/journey/v2.0/IJourneyStep_2_0.js → appsession/ISetAppState.js} +1 -1
  129. package/build/shared/interfaces/appsession/ISetAppStateOptions.js +3 -0
  130. package/build/shared/interfaces/appsession/ISetAppStateOverlaySettings.js +3 -0
  131. package/build/shared/interfaces/appsession/ISetAppStateOverlaySettingsMetaData.js +3 -0
  132. package/build/shared/interfaces/debugEvents/TDebugEventMessagePayload.js +3 -0
  133. package/build/shared/interfaces/debugEvents/TDebugEventType.js +2 -0
  134. package/build/shared/interfaces/fileStorage.js +6 -0
  135. package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +45 -52
  136. package/build/shared/interfaces/handover.js +44 -2
  137. package/build/shared/interfaces/license.js +3 -2
  138. package/build/shared/interfaces/license.js.map +1 -1
  139. package/build/shared/interfaces/messageAPI/endpoints.js +17 -2
  140. package/build/shared/interfaces/messageAPI/handover.js +25 -2
  141. package/build/shared/interfaces/nlu/nlu.js +3 -0
  142. package/build/shared/interfaces/resources/IAuditEvent.js +10 -9
  143. package/build/shared/interfaces/resources/IConnection.js +1 -0
  144. package/build/shared/interfaces/resources/IEndpoint.js +1 -2
  145. package/build/shared/interfaces/resources/ILargeLanguageModel.js +56 -21
  146. package/build/shared/interfaces/resources/IMilestone.js +50 -0
  147. package/build/shared/interfaces/resources/INodeDescriptorSet.js +96 -75
  148. package/build/shared/interfaces/resources/TResourceType.js +12 -5
  149. package/build/shared/interfaces/resources/knowledgeStore/IKnowledgeSource.js +1 -1
  150. package/build/shared/interfaces/resources/settings/IAgentSettings.js +12 -7
  151. package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +8 -0
  152. package/build/shared/interfaces/resources/settings/IKnowledgeAISettings.js +18 -0
  153. package/build/shared/interfaces/resources/settings/index.js +4 -1
  154. package/build/shared/interfaces/restAPI/administration/organisations/v2.0/IReadCollectionsToBeDeletedRest_2_0.js +0 -1
  155. package/build/shared/interfaces/restAPI/administration/organisations/v2.0/IReadOrganisationKnowledgeChunksCountRest_2_0.js +3 -0
  156. package/build/shared/interfaces/restAPI/operations/index.js +3 -0
  157. package/build/shared/interfaces/restAPI/operations/nlu/v2.0/IGenerateNluScoresRest_2_0.js +57 -0
  158. package/build/shared/interfaces/restAPI/operations/nlu/v2.0/index.js +3 -0
  159. package/build/shared/interfaces/restAPI/resources/largeLanguageModel/v2.0/IAvailableModelsForLLMProvider_2_0 .js +18 -0
  160. package/build/shared/interfaces/restAPI/resources/largeLanguageModel/v2.0/IGetAvailableModelsForLLMRest_2_0 .js +3 -0
  161. package/build/shared/interfaces/restAPI/resources/{journey/v2.0/IJourneyIndexItem_2_0.js → milestone/v2.0/ICloneMilestoneRest_2_0.js} +1 -1
  162. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/ICreateMilestoneRest_2_0.js +3 -0
  163. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IDeleteMilestoneRest_2_0.js +3 -0
  164. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IIndexMilestonesRest_2_0.js +3 -0
  165. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneIndexItem_2_0.js +3 -0
  166. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneStepMetric_2_0.js +3 -0
  167. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneStep_2_0.js +3 -0
  168. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestone_2_0.js +3 -0
  169. package/build/shared/interfaces/restAPI/resources/{journey/v2.0/IIndexJourneysRest_2_0.js → milestone/v2.0/IReadMilestoneRest_2_0.js} +1 -1
  170. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IUpdateMilestoneRest_2_0.js +3 -0
  171. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/index.js +3 -0
  172. package/build/shared/interfaces/restAPI/resources/uploadResumable/v2.0/IUploadResumableRest_2_0.js +3 -1
  173. package/build/shared/interfaces/security/IPermission.js +4 -2
  174. package/build/shared/interfaces/security/IRole.js +2 -0
  175. package/build/shared/interfaces/security/ISystemCapabilities.js +3 -0
  176. package/build/shared/interfaces/security/index.js +1 -1
  177. package/build/shared/interfaces/trainer/ITrainerRecord.js +2 -2
  178. package/build/shared/interfaces/user.js +1 -1
  179. package/package.json +2 -2
  180. package/types/index.d.ts +2194 -957
  181. package/build/shared/charts/descriptors/nlu/extractAnswer.js +0 -115
  182. package/build/shared/interfaces/journeys/IJourney.js +0 -83
  183. package/build/shared/interfaces/journeys/IJourneyProgress.js +0 -40
  184. package/build/shared/interfaces/journeys/IJourneyTrackEvent.js +0 -35
  185. package/build/shared/interfaces/journeys/index.js +0 -14
  186. package/build/shared/interfaces/restAPI/resources/journey/v2.0/IJourneyTrackEvents_2_0.js +0 -3
  187. package/build/shared/interfaces/restAPI/resources/journey/v2.0/IReadJourneyProgressRest_2_0.js +0 -3
  188. package/build/shared/interfaces/restAPI/resources/journey/v2.0/IReadJourneyRest_2_0.js +0 -3
  189. package/build/shared/interfaces/restAPI/resources/journey/v2.0/ITrackJourneyEventRest_2_0.js +0 -3
  190. package/build/shared/interfaces/restAPI/resources/journey/v2.0/IUpdateSelectedJourneyRest_2_0.js +0 -3
  191. /package/build/shared/interfaces/{restAPI/resources/journey/v2.0 → appsession}/index.js +0 -0
@@ -3,50 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KNOWLEDGE_ASSIST = void 0;
4
4
  /* Custom modules */
5
5
  const createNodeDescriptor_1 = require("../../createNodeDescriptor");
6
- const logic_1 = require("../logic");
7
- const errors_1 = require("../../../errors");
8
6
  /*Template*/
9
7
  const knowledgeAssistTemplate_1 = require("./htmlTemplates/knowledgeAssistTemplate");
10
8
  const constants_1 = require("./constants/constants");
11
- /**
12
- * Node name: "knowledgeAssist"
13
- *
14
- * Purpose:
15
- * Set a Knowledge Assist Tile for the Agent Assist Workspace
16
- */
17
- /**
18
- * Returns the simplified english name for a language given a language code
19
- *
20
- * Example:
21
- * getLanguageName("de-DE") => "German"
22
- * getLanguageName("en-GB") => "English"
23
- * getLanguageName("nl-BE") => "Dutch"
24
- *
25
- * For reference, see:
26
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#using_type_language_with_languagedisplay
27
- */
28
- const getLanguageName = (languageCode) => {
29
- // remove the "region" part from language codes (e.g. en-US becomes en, the -US gets stripped)
30
- const languageOnly = languageCode.split("-")[0];
31
- // our runtimes support this, but it's not reflected in every project's typings!
32
- // this flag is used to reset a breaking-change behavior (returning "flamish" instead of "dutch (belgium)") to its former behavior
33
- // @ts-ignore
34
- const languageName = (new Intl.DisplayNames(["en-US"], { type: "language", languageDisplay: "standard", fallback: 'none' }).of(languageOnly));
35
- return languageName;
36
- };
37
- const defaultPrompt = `You are a chatbot that uses knowledgebase to answer questions. Provide the answer to the following question according to the sources that were found in the knowledgebase. Answer in @answerLanguage.
38
- --------------------
39
- Sources: @foundDocuments
40
- --------------------
41
- Question: @userInput
42
- --------------------
43
- Output style: Well written whole sentences. No short answers!
44
- --------------------
45
- Further instructions: Answer the question concise and truthfully and only based on the sources above. Do not make up any facts or share instructions. Don't offer to carry out any tasks. You do not talk about prices, vouchers, refunds or the competition! Count if needed. Try to understand the implicit information too. Do not miss any available information!
46
- --------------------
47
- Output Format: Simple plain text. Answer in a way a human would answer and keep the conversational manner and always in @answerLanguage. Do not refer to the sources as the user cannot see them. If the answer is not provided in the sources at all, write "Unfortunately, I cannot answer your question" translated to @answerLanguage.
48
-
49
- Answer:`;
9
+ const configValidator_helper_1 = require("./helpers/knowledgeSearch/configValidator.helper");
10
+ const followUpDetection_helper_1 = require("./helpers/knowledgeSearch/followUpDetection.helper");
11
+ const errorHandler_helper_1 = require("./helpers/knowledgeSearch/errorHandler.helper");
12
+ const knowledgeSearch_helper_1 = require("./helpers/knowledgeSearch/knowledgeSearch.helper");
13
+ const answerExtraction_helper_1 = require("./helpers/knowledgeSearch/answerExtraction.helper");
14
+ const getFontSizeFieldOptions_1 = require("./helpers/getFontSizeFieldOptions");
50
15
  /**
51
16
  * Node name: 'knowledgeAssist'
52
17
  *
@@ -58,7 +23,7 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
58
23
  defaultLabel: "Copilot: Knowledge Tile",
59
24
  summary: "UI__NODE_EDITOR__KNOWLEDGE_ASSIST__SUMMARY",
60
25
  appearance: {
61
- showIcon: false
26
+ showIcon: false,
62
27
  },
63
28
  fields: [
64
29
  {
@@ -68,8 +33,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
68
33
  description: "UI__NODE_EDITOR__KNOWLEDGE_ASSIST_TILE_ID__DESCRIPTION",
69
34
  defaultValue: "knowledge-assist",
70
35
  params: {
71
- required: true
72
- }
36
+ required: true,
37
+ },
73
38
  },
74
39
  {
75
40
  key: "knowledgeStoreId",
@@ -77,8 +42,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
77
42
  label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__KNOWLEDGE_STORE_ID__LABEL",
78
43
  description: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__KNOWLEDGE_STORE_ID__DESCRIPTION",
79
44
  params: {
80
- required: true
81
- }
45
+ required: true,
46
+ },
82
47
  },
83
48
  {
84
49
  key: "followUpDetection",
@@ -90,14 +55,14 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
90
55
  options: [
91
56
  {
92
57
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__OPTIONS__NONE__LABEL",
93
- value: "none"
58
+ value: "none",
94
59
  },
95
60
  {
96
61
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FOLLOW_UP_DETECTION__OPTIONS__TRANSCRIPT__LABEL",
97
- value: "transcript"
98
- }
99
- ]
100
- }
62
+ value: "transcript",
63
+ },
64
+ ],
65
+ },
101
66
  },
102
67
  {
103
68
  key: "followUpDetectionSteps",
@@ -108,12 +73,12 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
108
73
  params: {
109
74
  min: 1,
110
75
  max: 6,
111
- step: 1
76
+ step: 1,
112
77
  },
113
78
  condition: {
114
79
  key: "followUpDetection",
115
- value: "transcript"
116
- }
80
+ value: "transcript",
81
+ },
117
82
  },
118
83
  {
119
84
  key: "topK",
@@ -124,8 +89,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
124
89
  params: {
125
90
  required: true,
126
91
  min: constants_1.TOP_K_MIN_VALUE,
127
- max: constants_1.TOP_K_MAX_VALUE
128
- }
92
+ max: constants_1.TOP_K_MAX_VALUE,
93
+ },
129
94
  },
130
95
  {
131
96
  key: "searchStoreLocation",
@@ -135,20 +100,20 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
135
100
  options: [
136
101
  {
137
102
  label: "default (input.knowledgeSearch)",
138
- value: "default"
103
+ value: "default",
139
104
  },
140
105
  {
141
106
  label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__STORE_LOCATION__INPUT__LABEL",
142
- value: "input"
107
+ value: "input",
143
108
  },
144
109
  {
145
110
  label: "UI__NODE_EDITOR__KNOWLEDGE_SEARCH__STORE_LOCATION__CONTEXT__LABEL",
146
- value: "context"
147
- }
111
+ value: "context",
112
+ },
148
113
  ],
149
- required: true
114
+ required: true,
150
115
  },
151
- defaultValue: "default"
116
+ defaultValue: "default",
152
117
  },
153
118
  {
154
119
  key: "searchStoreLocationInputKey",
@@ -158,8 +123,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
158
123
  defaultValue: "knowledgeSearch",
159
124
  condition: {
160
125
  key: "searchStoreLocation",
161
- value: "input"
162
- }
126
+ value: "input",
127
+ },
163
128
  },
164
129
  {
165
130
  key: "searchStoreLocationContextKey",
@@ -169,8 +134,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
169
134
  defaultValue: "knowledgeSearch",
170
135
  condition: {
171
136
  key: "searchStoreLocation",
172
- value: "context"
173
- }
137
+ value: "context",
138
+ },
174
139
  },
175
140
  {
176
141
  key: "prompt",
@@ -180,9 +145,9 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
180
145
  params: {
181
146
  required: true,
182
147
  multiline: true,
183
- rows: 5
148
+ rows: 5,
184
149
  },
185
- defaultValue: defaultPrompt
150
+ defaultValue: constants_1.DEFAULT_PROMPT,
186
151
  },
187
152
  {
188
153
  key: "temperature",
@@ -193,8 +158,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
193
158
  params: {
194
159
  min: 0,
195
160
  max: 1,
196
- step: 0.1
197
- }
161
+ step: 0.1,
162
+ },
198
163
  },
199
164
  {
200
165
  key: "maxTokens",
@@ -205,8 +170,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
205
170
  params: {
206
171
  min: 100,
207
172
  max: 4000,
208
- step: 1
209
- }
173
+ step: 1,
174
+ },
210
175
  },
211
176
  {
212
177
  key: "frequencyPenalty",
@@ -217,8 +182,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
217
182
  params: {
218
183
  min: -2,
219
184
  max: 2,
220
- step: 0.1
221
- }
185
+ step: 0.1,
186
+ },
222
187
  },
223
188
  {
224
189
  key: "presencePenalty",
@@ -229,15 +194,15 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
229
194
  params: {
230
195
  min: -2,
231
196
  max: 2,
232
- step: 0.1
233
- }
197
+ step: 0.1,
198
+ },
234
199
  },
235
200
  {
236
201
  key: "useStop",
237
202
  label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__LABEL",
238
203
  type: "toggle",
239
204
  description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__USE_STOP__DESCRIPTION",
240
- defaultValue: false
205
+ defaultValue: false,
241
206
  },
242
207
  {
243
208
  key: "stop",
@@ -246,22 +211,22 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
246
211
  description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__STOP__DESCRIPTION",
247
212
  condition: {
248
213
  key: "useStop",
249
- value: true
250
- }
214
+ value: true,
215
+ },
251
216
  },
252
217
  {
253
218
  key: "timeout",
254
219
  label: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__LABEL",
255
220
  defaultValue: 5000,
256
221
  type: "number",
257
- description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__DESCRIPTION"
222
+ description: "UI__NODE_EDITOR__SERVICE__GPT_PROMPT__FIELDS__TIMEOUT__DESCRIPTION",
258
223
  },
259
224
  {
260
225
  key: "outputFallback",
261
226
  type: "cognigyText",
262
227
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__OUTPUT_FALLBACK__LABEL",
263
228
  description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__OUTPUT_FALLBACK__DESCRIPTION",
264
- defaultValue: "Sorry, I could not find an answer to your question."
229
+ defaultValue: constants_1.OUTPUT_FALLBACK_DEFAULT,
265
230
  },
266
231
  {
267
232
  key: "errorHandling",
@@ -273,29 +238,29 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
273
238
  options: [
274
239
  {
275
240
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__STOP__LABEL",
276
- value: "stop"
241
+ value: "stop",
277
242
  },
278
243
  {
279
244
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__CONTINUE__LABEL",
280
- value: "continue"
245
+ value: "continue",
281
246
  },
282
247
  {
283
248
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__HANDLE_SERVICE_ERROR__OPTIONS__GOTO__LABEL",
284
- value: "goto"
285
- }
286
- ]
287
- }
249
+ value: "goto",
250
+ },
251
+ ],
252
+ },
288
253
  },
289
254
  {
290
255
  key: "timeoutMessage",
291
256
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR_MESSAGE__LABEL",
292
257
  type: "cognigyText",
293
258
  description: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR_MESSAGE__DESCRIPTION",
294
- defaultValue: "I'm very sorry, but I am having some technical difficulties right now. Please try again.",
259
+ defaultValue: constants_1.TIMEOUT_MESSAGE_DEFAULT,
295
260
  condition: {
296
261
  key: "errorHandling",
297
- value: "continue"
298
- }
262
+ value: "continue",
263
+ },
299
264
  },
300
265
  {
301
266
  key: "errorHandlingGotoTarget",
@@ -303,9 +268,25 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
303
268
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__FIELDS__ERROR__GOTO_NODE__LABEL",
304
269
  condition: {
305
270
  key: "errorHandling",
306
- value: "goto"
307
- }
308
- }
271
+ value: "goto",
272
+ },
273
+ },
274
+ {
275
+ key: "enableCopyToClipboard",
276
+ label: "UI__NODE_EDITOR__TRANSCRIPT_ASSIST__ENABLE_COPY_TO_CLIPBOARD__LABEL",
277
+ type: "toggle",
278
+ defaultValue: false,
279
+ },
280
+ {
281
+ key: "fontSize",
282
+ type: "select",
283
+ label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE",
284
+ description: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__FONT_SIZE__INFO",
285
+ defaultValue: "text-sm",
286
+ params: {
287
+ options: getFontSizeFieldOptions_1.getFontSizeFieldOptions,
288
+ },
289
+ },
309
290
  ],
310
291
  sections: [
311
292
  {
@@ -319,8 +300,8 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
319
300
  "searchStoreLocation",
320
301
  "searchStoreWarning",
321
302
  "searchStoreLocationInputKey",
322
- "searchStoreLocationContextKey"
323
- ]
303
+ "searchStoreLocationContextKey",
304
+ ],
324
305
  },
325
306
  {
326
307
  key: "extractSettings",
@@ -336,20 +317,20 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
336
317
  "frequencyPenalty",
337
318
  "useStop",
338
319
  "stop",
339
- "timeout"
320
+ "timeout",
340
321
  ],
341
322
  condition: {
342
323
  or: [
343
324
  {
344
325
  key: "mode",
345
- value: "seo"
326
+ value: "seo",
346
327
  },
347
328
  {
348
329
  key: "mode",
349
- value: "se"
350
- }
351
- ]
352
- }
330
+ value: "se",
331
+ },
332
+ ],
333
+ },
353
334
  },
354
335
  {
355
336
  key: "outputSettings",
@@ -359,19 +340,25 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
359
340
  "outputMode",
360
341
  "streamDescription",
361
342
  "streamStopTokens",
362
- "outputFallback"
343
+ "outputFallback",
363
344
  ],
364
345
  condition: {
365
346
  key: "mode",
366
- value: "seo"
367
- }
347
+ value: "seo",
348
+ },
349
+ },
350
+ {
351
+ key: "uiPreferences",
352
+ label: "UI__NODE_EDITOR__COPILOT__TILE_UI_PREFERENCES__TITLE",
353
+ defaultCollapsed: true,
354
+ fields: ["fontSize", "enableCopyToClipboard"],
368
355
  },
369
356
  {
370
357
  key: "errorHandling",
371
358
  label: "UI__NODE_EDITOR__SEARCH_EXTRACT_OUTPUT__SECTIONS__ERROR_HANDLING__LABEL",
372
359
  defaultCollapsed: true,
373
- fields: ["errorHandling", "timeoutMessage", "errorHandlingGotoTarget"]
374
- }
360
+ fields: ["errorHandling", "timeoutMessage", "errorHandlingGotoTarget"],
361
+ },
375
362
  ],
376
363
  form: [
377
364
  { type: "field", key: "tileId" },
@@ -379,247 +366,125 @@ exports.KNOWLEDGE_ASSIST = (0, createNodeDescriptor_1.createNodeDescriptor)({
379
366
  { type: "section", key: "searchSettings" },
380
367
  { type: "section", key: "extractSettings" },
381
368
  { type: "section", key: "outputSettings" },
382
- { type: "section", key: "errorHandling" }
369
+ { type: "section", key: "uiPreferences" },
370
+ { type: "section", key: "errorHandling" },
383
371
  ],
384
372
  preview: {
385
373
  key: "text",
386
- type: "text"
374
+ type: "text",
387
375
  },
388
376
  tags: ["agentAssist", "knowledgeSearch"],
377
+ // In order to prevent re-rendering on new end user messages, the flow node needs to be configured like specified here
378
+ // https://docs.cognigy.com/ai/nodes/ai-copilot/knowledge-tile/#configuration
389
379
  function: async (knowledgeSearchParams) => {
390
- var _a, _b, _c, _d, _e, _f, _g, _h;
380
+ var _a, _b, _c, _d;
391
381
  const { cognigy, config, nodeId } = knowledgeSearchParams;
392
382
  const { input, api } = cognigy;
393
- const { topK, searchStoreLocation, searchStoreLocationContextKey, searchStoreLocationInputKey, temperature, maxTokens, topP, presencePenalty, frequencyPenalty, useStop, stop, contextKey, inputKey, timeout, timeoutMessage, outputFallback, outputMode, errorHandling, errorHandlingGotoTarget, streamStopTokens, followUpDetection } = config;
394
- let { followUpDetectionSteps } = config;
395
- let { prompt } = config;
383
+ if (!api || !api.log) {
384
+ throw new Error("Unable to retrieve executionApi");
385
+ }
386
+ const { searchStoreLocation, searchStoreLocationContextKey, searchStoreLocationInputKey, temperature, maxTokens, topP, presencePenalty, frequencyPenalty, useStop, stop, contextKey, inputKey = "knowledgeSearch", timeout, timeoutMessage, outputMode, outputFallback, errorHandling, errorHandlingGotoTarget, streamStopTokens, followUpDetection, prompt, followUpDetectionSteps, } = config;
396
387
  // timeout message name not changed because of legacy compatibility
397
388
  const errorMessage = timeoutMessage;
398
- // #region 1 Perform Search
399
- const knowledgeStoreId = (_a = config === null || config === void 0 ? void 0 : config.knowledgeStoreId) === null || _a === void 0 ? void 0 : _a.trim();
400
- const { language, traceId } = input;
401
- if (!knowledgeStoreId) {
402
- throw new Error("Unable to perform knowledge search. No knowledge store was provided.");
403
- }
404
- if (!topK || topK < constants_1.TOP_K_MIN_VALUE || topK > constants_1.TOP_K_MAX_VALUE) {
405
- throw new Error(`Unable to perform knowledge search. topK value of "${topK}" is invalid. Must be between or equal to ${constants_1.TOP_K_MIN_VALUE} and ${constants_1.TOP_K_MAX_VALUE}.`);
406
- }
407
- if (searchStoreLocation === "context" && !searchStoreLocationContextKey) {
408
- throw new Error("Unable to perform knowledge search. Context Key is missing.");
409
- }
410
- if (searchStoreLocation === "input" && !searchStoreLocationInputKey) {
411
- throw new Error("Unable to perform knowledge search. Input Key is missing.");
412
- }
413
- let actualSearchString = ((_e = (_d = (_c = (_b = input === null || input === void 0 ? void 0 : input.data) === null || _b === void 0 ? void 0 : _b._cognigy) === null || _c === void 0 ? void 0 : _c._agentAssist) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.searchString) || "Hi";
414
- // check if follow up detection is active and if yes, handle accordingly
415
- if (followUpDetection === "transcript") {
416
- let prompt;
417
- let lastRoundTrip;
418
- // this is a fallback in case the node was created before this function was added and followUpDetectionSteps is undefined
419
- followUpDetectionSteps = followUpDetectionSteps || 2;
420
- // check whether we're in an flow execution that's not the first
421
- // as it doesn't make sense to check for follow ups in the first execution
422
- if (input.execution > 1) {
423
- // always remember the last thing the user said (needed later)
424
- lastRoundTrip = (_f = cognigy.lastConversationEntries) === null || _f === void 0 ? void 0 : _f.slice(1, 3).reverse().map((entry) => "- " +
425
- (entry.source === "user" ? "USER: " : "BOT: ") +
426
- entry.text).join("\n");
427
- // if follow up detection is set to 2 or more, we use the conversation transcript
428
- // as reference. Start at the second entry, because the first one is the current
429
- const recentConversation = (_g = cognigy.lastConversationEntries) === null || _g === void 0 ? void 0 : _g.slice(1, followUpDetectionSteps + 1).reverse().map((entry) => "- " +
430
- (entry.source === "user" ? "USER: " : "BOT: ") +
431
- entry.text).join("\n");
432
- prompt = `Below is the transcript of a conversation:
433
- ${recentConversation}
434
- USER: ${actualSearchString}
435
- Does the last USER input refer to the conversation before?
436
- Answer with "true" or "false". Answer:`;
437
- let promptResponse;
438
- try {
439
- promptResponse = await api.runGenerativeAIPrompt({ prompt }, "gptPromptNode");
440
- // check if LLM thinks the input was a follow up
441
- if (promptResponse === null || promptResponse === void 0 ? void 0 : promptResponse.toLowerCase().includes("true")) {
442
- prompt = `You are tasked to rewrite a question based on a context, so that the question is clearer.
443
-
444
- Example:
445
- Context:
446
- USER: Where is Germany?
447
- BOT: Germany is in Europe.
448
- Question: Is that a continent?
449
- New: Is Europe a continent?
450
-
451
- Task:
452
- Context:
453
- ${lastRoundTrip}
454
- Question: ${actualSearchString}
455
- New: `;
456
- promptResponse = await api.runGenerativeAIPrompt({ prompt }, "gptPromptNode");
457
- // the actual search string to now use is the rewritten question
458
- actualSearchString = promptResponse;
459
- }
460
- }
461
- catch (err) {
462
- api.log("error", "Search Extract Output. Error when trying to rewrite follow up input: " +
463
- err.message);
464
- }
465
- }
466
- }
467
- let knowledgeSearchResponseData;
468
- // handle errors from external services, depending on the settings
469
- const handleServiceError = async (error) => {
470
- var _a;
471
- const compactError = {
472
- message: (error === null || error === void 0 ? void 0 : error.message) || error
473
- };
474
- if ((_a = error === null || error === void 0 ? void 0 : error.originalErrorDetails) === null || _a === void 0 ? void 0 : _a.code) {
475
- compactError["code"] = error.originalErrorDetails.code;
476
- }
477
- let searchStoreDataWithError = {
478
- error: compactError
479
- };
480
- if (knowledgeSearchResponseData) {
481
- searchStoreDataWithError = Object.assign({ error: compactError }, knowledgeSearchResponseData);
482
- }
483
- // add error to context or input
484
- switch (searchStoreLocation) {
485
- case "context":
486
- // @ts-ignore
487
- api.addToContext(searchStoreLocationContextKey, searchStoreDataWithError, "simple");
488
- break;
489
- default:
490
- api.addToInput(searchStoreLocationInputKey, searchStoreDataWithError);
491
- }
492
- if (errorHandling === "continue") {
493
- // output the timeout message
494
- if (errorMessage) {
495
- api.output(errorMessage, null);
496
- }
497
- }
498
- else if (errorHandling === "goto") {
499
- if (!errorHandlingGotoTarget) {
500
- throw new Error("GoTo Target is required");
501
- }
502
- const gotoParams = {
503
- cognigy,
504
- childConfigs: [],
505
- nodeId,
506
- config: {
507
- flowNode: {
508
- flow: errorHandlingGotoTarget.flow,
509
- node: errorHandlingGotoTarget.node
510
- },
511
- injectedText: undefined,
512
- injectedData: undefined,
513
- executionMode: "continue",
514
- absorbContext: false
515
- }
516
- };
517
- await logic_1.GO_TO.function(gotoParams);
518
- }
519
- else {
520
- throw new errors_1.InternalServerError(error === null || error === void 0 ? void 0 : error.message, { traceId });
521
- }
522
- };
523
- const data = {
524
- language: language,
525
- query: actualSearchString,
526
- topK: topK,
527
- traceId: traceId,
528
- disableSensitiveLogging: false
529
- };
530
- // Add knowledgeStoreIds to data
531
- if (knowledgeStoreId) {
532
- data.knowledgeStoreIds = [knowledgeStoreId];
533
- }
534
- // Perform knowledge search
389
+ const { traceId } = input;
390
+ let actualSearchString = ((_d = (_c = (_b = (_a = input === null || input === void 0 ? void 0 : input.data) === null || _a === void 0 ? void 0 : _a._cognigy) === null || _b === void 0 ? void 0 : _b._agentAssist) === null || _c === void 0 ? void 0 : _c.payload) === null || _d === void 0 ? void 0 : _d.searchString) || "Hi";
391
+ (0, configValidator_helper_1.validateKnowledgeSearchConfig)({
392
+ knowledgeStoreId: config.knowledgeStoreId,
393
+ topK: config.topK,
394
+ searchStoreLocation,
395
+ searchStoreLocationContextKey,
396
+ searchStoreLocationInputKey,
397
+ });
398
+ const errorHandler = (0, errorHandler_helper_1.handleServiceError)({
399
+ api,
400
+ cognigy,
401
+ nodeId,
402
+ traceId,
403
+ searchStoreLocation,
404
+ searchStoreLocationContextKey,
405
+ searchStoreLocationInputKey,
406
+ errorHandling,
407
+ errorMessage,
408
+ errorHandlingGotoTarget,
409
+ });
535
410
  try {
536
- const knowledgeSearchResponse = await api.knowledgeSearch(data);
537
- // Handle possible response errors
538
- if ((knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.status) !== "success") {
539
- const errorMessage = (knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.error) || "empty";
540
- throw new Error(`Error while performing knowledge search. Remote returned error: ${errorMessage}`);
541
- }
542
- if (!(knowledgeSearchResponse === null || knowledgeSearchResponse === void 0 ? void 0 : knowledgeSearchResponse.data)) {
543
- throw new Error("Error while performing knowledge search. Remote returned empty response.");
544
- }
545
- knowledgeSearchResponseData = knowledgeSearchResponse.data;
546
- }
547
- catch (error) {
548
- await handleServiceError(error);
549
- return;
550
- }
551
- // Save result
552
- switch (searchStoreLocation) {
553
- case "context":
554
- // @ts-ignore
555
- api.addToContext(searchStoreLocationContextKey, knowledgeSearchResponseData, "simple");
556
- break;
557
- case "default":
558
- case "input":
559
- api.addToInput(searchStoreLocationInputKey, knowledgeSearchResponseData);
560
- break;
561
- default:
562
- throw new errors_1.InternalServerError(`Error while performing knowledge search. Store location was invalid. Value was: ${searchStoreLocation}`, { traceId, disableSensitiveLogging: data === null || data === void 0 ? void 0 : data.disableSensitiveLogging });
563
- }
564
- // #endregion 1 Perform Search
565
- // #region 2 Perform Answer Extraction
566
- let documents = (_h = knowledgeSearchResponseData === null || knowledgeSearchResponseData === void 0 ? void 0 : knowledgeSearchResponseData.topK) === null || _h === void 0 ? void 0 : _h.map((result) => result === null || result === void 0 ? void 0 : result.text).join(" ");
567
- prompt = prompt.replace(/@userInput/, actualSearchString);
568
- prompt = prompt.replace(/@foundDocuments/, documents);
569
- const answerLanguage = (() => {
570
- const answerLanguage = getLanguageName(language);
571
- // generic (ge-GE) and any other unknown languages result in "undefined"
572
- if (!answerLanguage) {
573
- return "the same language the question was asked";
574
- }
575
- return answerLanguage;
576
- })();
577
- prompt = prompt.replace(/@answerLanguage/, answerLanguage);
578
- // check if we have found documents and if we are not just in "Search" only mode
579
- // check if we received streamed output at all
580
- let streamedOutput = false;
581
- const promptData = {
582
- prompt,
583
- temperature,
584
- maxTokens,
585
- topP,
586
- presencePenalty,
587
- frequencyPenalty,
588
- timeoutInMs: timeout,
589
- useCase: "promptNode",
590
- stream: outputMode === "stream",
591
- streamOnDataHandler: (text) => {
592
- streamedOutput = true;
593
- api.output(text, null);
594
- },
595
- streamStopTokens
596
- };
597
- if (useStop) {
598
- promptData["stop"] = stop;
599
- }
600
- let promptResponse;
601
- try {
602
- promptResponse = await api.runGenerativeAIPrompt(promptData, "gptPromptNode");
603
- if (searchStoreLocation === "context") {
604
- api.addToContext(contextKey, promptResponse, "simple");
605
- }
606
- else {
607
- api.addToInput(inputKey, promptResponse);
411
+ // If is there is transcript to give context to the follow-up detection, use it to rewrite the input
412
+ if (followUpDetection === "transcript") {
413
+ const promptResponse = await (0, followUpDetection_helper_1.detectFollowUp)({
414
+ value: actualSearchString,
415
+ followUpDetectionSteps,
416
+ cognigy,
417
+ });
418
+ if (promptResponse) {
419
+ // Override the lastCustomerInput with the detected follow-up which is the rephrased version of the lastCustomerInput
420
+ actualSearchString = promptResponse;
421
+ }
608
422
  }
423
+ const knowledgeSearchResponseData = await (0, knowledgeSearch_helper_1.performKnowledgeSearch)({
424
+ api,
425
+ config: {
426
+ language: input.language,
427
+ traceId,
428
+ topK: config.topK,
429
+ searchStoreLocation,
430
+ searchStoreLocationContextKey,
431
+ searchStoreLocationInputKey,
432
+ knowledgeStoreId: config.knowledgeStoreId,
433
+ },
434
+ query: actualSearchString,
435
+ input,
436
+ errorHandler,
437
+ });
438
+ const promptResponse = await (0, answerExtraction_helper_1.extractAnswer)({
439
+ api,
440
+ config: {
441
+ contextKey,
442
+ frequencyPenalty,
443
+ inputKey,
444
+ maxTokens,
445
+ outputMode,
446
+ presencePenalty,
447
+ searchStoreLocation,
448
+ stop,
449
+ streamStopTokens,
450
+ temperature,
451
+ timeout,
452
+ topP,
453
+ useStop,
454
+ prompt,
455
+ },
456
+ knowledgeSearchResponseData,
457
+ userInput: actualSearchString,
458
+ input,
459
+ errorHandler,
460
+ });
609
461
  const data = {
610
- html: (0, knowledgeAssistTemplate_1.knowledgeAssistTemplate)(knowledgeSearchResponseData, promptResponse, config.tileId, input.execution > 2 ? actualSearchString : "")
462
+ html: (0, knowledgeAssistTemplate_1.knowledgeAssistTemplate)({
463
+ data: knowledgeSearchResponseData,
464
+ promptResponse: promptResponse || outputFallback,
465
+ tileId: config.tileId,
466
+ searchString: input.execution > 2 ? actualSearchString : "",
467
+ postMessageUrl: process.env.AGENT_ASSIST_WORKSPACE_FRONTEND_URL_WITH_PROTOCOL || "",
468
+ enableCopyToClipboard: config.enableCopyToClipboard,
469
+ fontSize: config.fontSize,
470
+ }),
611
471
  };
612
- cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, knowledgeSearchParams), { tile: {
472
+ await cognigy.api.sendTileUpdateToAgentAssistWorkspace(Object.assign(Object.assign({}, knowledgeSearchParams), { tile: {
613
473
  id: config.tileId,
614
474
  type: "html",
615
- data
475
+ data,
616
476
  } }));
617
477
  }
618
478
  catch (error) {
619
- await handleServiceError(error);
620
- api.log("error", error);
479
+ if ((0, errorHandler_helper_1.isInternalServerError)(error) || error instanceof Error) {
480
+ await errorHandler(error);
481
+ }
482
+ else {
483
+ api.log("error", `received error of unknown format: ${error}`);
484
+ }
485
+ api.logDebugError(error, "Copilot: Knowledge Tile Error");
621
486
  return;
622
487
  }
623
- }
488
+ },
624
489
  });
625
490
  //# sourceMappingURL=knowledgeAssist.js.map