@cognigy/rest-api-client 0.17.0 → 0.18.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 (87) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/GenericTusFn.js +6 -1
  3. package/build/GenericUploadFn.js +3 -5
  4. package/build/apigroups/ResourcesAPIGroup_2_0.js +12 -1
  5. package/build/connector/AxiosAdapter.js +35 -15
  6. package/build/shared/charts/createNodeDescriptor.js +5 -5
  7. package/build/shared/charts/descriptors/agentAssist/constants/constants.js +16 -1
  8. package/build/shared/charts/descriptors/agentAssist/helpers/agentAssistTranslator.helper.js +19 -0
  9. package/build/shared/charts/descriptors/agentAssist/helpers/getFontSizeFieldOptions.js +84 -0
  10. package/build/shared/charts/descriptors/agentAssist/helpers/getLanguageName.helper.js +33 -0
  11. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/answerExtraction.helper.js +59 -0
  12. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/configValidator.helper.js +20 -0
  13. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/errorHandler.helper.js +64 -0
  14. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/followUpDetection.helper.js +72 -0
  15. package/build/shared/charts/descriptors/agentAssist/helpers/knowledgeSearch/knowledgeSearch.helper.js +58 -0
  16. package/build/shared/charts/descriptors/agentAssist/helpers/sentiment.helper.js +7 -13
  17. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/identityAssistTemplate.js +17 -18
  18. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/knowledgeAssistTemplate.js +330 -153
  19. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/nextActionWidgetTemplate.js +212 -80
  20. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/sentimentAnalysisTemplate.js +11 -6
  21. package/build/shared/charts/descriptors/agentAssist/htmlTemplates/transcriptAssistTemplate.js +15 -13
  22. package/build/shared/charts/descriptors/agentAssist/identityAssist.js +87 -14
  23. package/build/shared/charts/descriptors/agentAssist/knowledgeAssist.js +192 -327
  24. package/build/shared/charts/descriptors/agentAssist/locales/cs.locale.js +11 -0
  25. package/build/shared/charts/descriptors/agentAssist/locales/de.locale.js +11 -0
  26. package/build/shared/charts/descriptors/agentAssist/locales/en.locale.js +11 -0
  27. package/build/shared/charts/descriptors/agentAssist/locales/es.locale.js +11 -0
  28. package/build/shared/charts/descriptors/agentAssist/locales/fr.locale.js +11 -0
  29. package/build/shared/charts/descriptors/agentAssist/locales/index.js +22 -0
  30. package/build/shared/charts/descriptors/agentAssist/locales/ja.locale.js +11 -0
  31. package/build/shared/charts/descriptors/agentAssist/locales/ko.locale.js +11 -0
  32. package/build/shared/charts/descriptors/agentAssist/locales/pt.locale.js +11 -0
  33. package/build/shared/charts/descriptors/agentAssist/nextActionAssist.js +485 -10
  34. package/build/shared/charts/descriptors/agentAssist/sentimentAssist.js +31 -8
  35. package/build/shared/charts/descriptors/agentAssist/transcriptAssist.js +40 -2
  36. package/build/shared/charts/descriptors/analytics/requestRating.js +56 -2
  37. package/build/shared/charts/descriptors/index.js +1 -3
  38. package/build/shared/charts/descriptors/knowledgeSearch/searchExtractOutput.js +1 -1
  39. package/build/shared/charts/descriptors/message/question/optionalQuestion.js +1 -1
  40. package/build/shared/charts/descriptors/message/question/question.js +123 -2
  41. package/build/shared/charts/descriptors/message/question/utils/evaluateQuestionAnswer.js +44 -3
  42. package/build/shared/charts/descriptors/nlu/generativeSlotFiller/prompt.js +28 -12
  43. package/build/shared/charts/descriptors/nlu/index.js +1 -3
  44. package/build/shared/charts/descriptors/service/GPTPrompt.js +320 -22
  45. package/build/shared/charts/descriptors/service/LLMEntityExtract.js +274 -0
  46. package/build/shared/charts/descriptors/service/httpRequest.js +33 -1
  47. package/build/shared/charts/descriptors/service/index.js +3 -1
  48. package/build/shared/charts/descriptors/voice/mappers/setSessionConfig.mapper.js +17 -13
  49. package/build/shared/charts/descriptors/voice/mappers/transfer.mapper.js +4 -4
  50. package/build/shared/charts/descriptors/voice/nodes/play.js +8 -1
  51. package/build/shared/charts/descriptors/voice/nodes/sessionSpeechParameters.js +44 -45
  52. package/build/shared/charts/descriptors/voicegateway2/nodes/play.js +0 -1
  53. package/build/shared/charts/descriptors/voicegateway2/nodes/setSessionConfig.js +31 -39
  54. package/build/shared/charts/descriptors/voicegateway2/nodes/transfer.js +17 -25
  55. package/build/shared/charts/helpers/generativeAI/generativeAIPrompts.js +55 -0
  56. package/build/shared/interfaces/appsession/IAppSession.js +3 -0
  57. package/build/shared/interfaces/appsession/ISetAppState.js +3 -0
  58. package/build/shared/interfaces/appsession/index.js +3 -0
  59. package/build/shared/interfaces/fileStorage.js +6 -0
  60. package/build/shared/interfaces/generativeAI/IGenerativeAIModels.js +32 -3
  61. package/build/shared/interfaces/handover.js +2 -1
  62. package/build/shared/interfaces/messageAPI/endpoints.js +15 -2
  63. package/build/shared/interfaces/messageAPI/handover.js +5 -1
  64. package/build/shared/interfaces/nlu/nlu.js +3 -0
  65. package/build/shared/interfaces/resources/IAuditEvent.js +10 -9
  66. package/build/shared/interfaces/resources/ILargeLanguageModel.js +34 -20
  67. package/build/shared/interfaces/resources/IMilestone.js +50 -0
  68. package/build/shared/interfaces/resources/INodeDescriptorSet.js +84 -75
  69. package/build/shared/interfaces/resources/TResourceType.js +12 -5
  70. package/build/shared/interfaces/resources/settings/IGenerativeAISettings.js +4 -0
  71. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/ICloneMilestoneRest_2_0.js +3 -0
  72. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/ICreateMilestoneRest_2_0.js +3 -0
  73. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IDeleteMilestoneRest_2_0.js +3 -0
  74. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IIndexMilestonesRest_2_0.js +3 -0
  75. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneIndexItem_2_0.js +3 -0
  76. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneStepMetric_2_0.js +3 -0
  77. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestoneStep_2_0.js +3 -0
  78. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IMilestone_2_0.js +3 -0
  79. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IReadMilestoneRest_2_0.js +3 -0
  80. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/IUpdateMilestoneRest_2_0.js +3 -0
  81. package/build/shared/interfaces/restAPI/resources/milestone/v2.0/index.js +3 -0
  82. package/build/shared/interfaces/restAPI/resources/uploadResumable/v2.0/IUploadResumableRest_2_0.js +3 -1
  83. package/build/shared/interfaces/security/IPermission.js +4 -2
  84. package/build/shared/interfaces/security/index.js +1 -1
  85. package/package.json +2 -2
  86. package/types/index.d.ts +938 -285
  87. package/build/shared/charts/descriptors/nlu/extractAnswer.js +0 -115
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sentimentAnalysis = void 0;
4
+ const sentimentList = ["Positive", "Neutral", "Negative"];
4
5
  /**
5
6
  * This method is used to analyze the sentiment based on the given prompt string.
6
7
  * It returns either the detected sentiment or 'Neutral' if the sentiment could not be detected or was not clear.
@@ -9,18 +10,16 @@ exports.sentimentAnalysis = void 0;
9
10
  * @param prompt The prompt to be analyzed
10
11
  */
11
12
  const sentimentAnalysis = async (api, prompt) => {
12
- let sentiment = "";
13
+ var _a;
13
14
  const payload = {
14
15
  prompt,
15
16
  useCase: "sentimentAnalysis",
16
17
  };
17
- const llmResponse = await api.runGenerativeAIPrompt(payload, "sentimentAnalysis");
18
- //TODO: remove if the lookup works
19
- api.log("info", `Sentiment: ${llmResponse}`);
18
+ const llmResponse = await ((_a = api.runGenerativeAIPrompt) === null || _a === void 0 ? void 0 : _a.call(api, payload, "sentimentAnalysis"));
20
19
  if (llmResponse) {
21
- sentiment = getSentiment(llmResponse);
20
+ return getSentiment(llmResponse);
22
21
  }
23
- return sentiment;
22
+ return "";
24
23
  };
25
24
  exports.sentimentAnalysis = sentimentAnalysis;
26
25
  /**
@@ -30,12 +29,7 @@ exports.sentimentAnalysis = sentimentAnalysis;
30
29
  * @param text The text to be analyzed
31
30
  */
32
31
  function getSentiment(text) {
33
- const sentimentList = ["Positive", "Neutral", "Negative"];
34
- for (let sentiment of sentimentList) {
35
- if (text.includes(sentiment) || text.includes(sentiment.toLowerCase())) {
36
- return sentiment;
37
- }
38
- }
39
- return sentimentList[1];
32
+ var _a;
33
+ return (_a = sentimentList.find((sentiment) => text.toLowerCase().includes(sentiment.toLowerCase()))) !== null && _a !== void 0 ? _a : "Neutral";
40
34
  }
41
35
  //# sourceMappingURL=sentiment.helper.js.map
@@ -1,27 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const identityAssistTemplate = ({ widgetLayout = "horizontal", imageShape = "round", imageUrl, customer, customerData, }) => {
3
+ const identityAssistTemplate = ({ widgetLayout = "horizontal", imageShape = "round", imageUrl, customer, customerData, fontSize, profileFontSize, keyValueFontSize, showProfileImage, profileImageSize }) => {
4
4
  const imageClass = imageShape === "round" ? "rounded-full" : "rounded-none";
5
5
  let layoutClass = "";
6
6
  let marginClass = "";
7
7
  let textClass = "";
8
8
  let imageHTML = "";
9
9
  let customerDataHTML = "";
10
- layoutClass +=
11
- widgetLayout === "horizontal"
12
- ? ""
13
- : "flex-col";
10
+ layoutClass += widgetLayout === "horizontal" ? "" : "flex-col";
14
11
  marginClass = widgetLayout === "horizontal" ? "ml-2" : "";
15
12
  imageHTML = `
16
- <div class="mt-6 flex justify-center" style="min-width: 130px;">
17
- <img class="h-32 w-32 object-cover ${marginClass} ${imageClass}" src="${imageUrl || 'https://cdn-icons-png.flaticon.com/512/149/149071.png'}" alt="User Avatar" />
13
+ <div class="mt-6 flex justify-center">
14
+ <img class="${profileImageSize} object-cover ${marginClass} ${imageClass}" src="${imageUrl || "https://cdn-icons-png.flaticon.com/512/149/149071.png"}" alt="User Avatar" />
18
15
  </div>
19
16
  `;
20
17
  if (widgetLayout === "horizontal") {
21
18
  textClass = "flex-grow";
22
19
  }
23
20
  for (const [key, value] of Object.entries(customerData)) {
24
- customerDataHTML += `<p class="mt-1 text-gray-500">${key}: ${value}</p>`;
21
+ customerDataHTML += `<p class="mt-1 ${keyValueFontSize} text-gray-500">${key}: ${value}</p>`;
25
22
  }
26
23
  return `
27
24
  <!DOCTYPE html>
@@ -34,18 +31,20 @@ const identityAssistTemplate = ({ widgetLayout = "horizontal", imageShape = "rou
34
31
  </head>
35
32
  <body>
36
33
  <div class="flex h-screen items-center justify-center bg-gray-100">
37
- <div class="h-full w-full rounded-lg bg-white shadow-md overflow-hidden">
38
- <div class="flex h-full ${layoutClass}">
39
- ${imageHTML}
40
- <div class="mt-2 pl-4 pt-4 pb-4 flex flex-col h-full break-all overflow-hidden ${textClass}">
41
- <div class="text-sm pl-4 font-semibold uppercase tracking-wide text-indigo-500">User Profile</div>
42
- <div class="mt-2 pl-4 text-xl font-semibold">${customer}</div>
43
- <div class="flex-grow overflow-auto p-4 h-full break-words">
44
- ${customerDataHTML}
34
+ <div class="h-full w-full rounded-lg bg-white shadow-md overflow-hidden">
35
+ <div class="flex h-full ${layoutClass}">
36
+ ${showProfileImage ? imageHTML : ''}
37
+ <div class="mt-2 pl-4 pt-4 pb-4 flex flex-col h-full break-all overflow-hidden ${textClass}">
38
+ <div class="${fontSize} pl-4 font-semibold uppercase tracking-wide text-indigo-500">User Profile</div>
39
+ <div class="mt-2 pl-4 ${profileFontSize} font-semibold">
40
+ ${customer}
41
+ </div>
42
+ <div class="flex-grow overflow-auto p-4 h-full break-words">
43
+ ${customerDataHTML}
44
+ </div>
45
+ </div>
45
46
  </div>
46
47
  </div>
47
- </div>
48
- </div>
49
48
  </div>
50
49
  </body>
51
50
  </html>`;
@@ -1,203 +1,380 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.knowledgeAssistTemplate = void 0;
4
- const knowledgeAssistTemplate = (data, promptResponse, tileId, searchString) => {
5
- return `
6
- <!DOCTYPE html>
7
- <html lang="en">
8
- <head>
9
- <meta charset="UTF-8">
10
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
11
- <title>Search Knowledge Base</title>
12
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
13
- </head>
14
- <body>
15
- <div class="flex h-screen items-center justify-center bg-gray-100">
16
- <div class="flex h-full w-full flex-col overflow-auto rounded-xl bg-white p-6 shadow-md">
17
- <div class="flex items-center">
18
- <div class="text-sm font-semibold uppercase tracking-wide text-indigo-500">Search</div>
19
- <input id="searchInput" type="text" class="w-full rounded-l-md border p-2 ml-2" placeholder="Search your knowledge base" />
20
- <button id="postbackButton" class="flex items-center rounded-r-md bg-indigo-100 px-4 py-2">
21
- <img src="https://cdn-icons-png.flaticon.com/128/7047/7047900.png" alt="Search Icon" class="h-6 w-8 text-white" />
22
- </button>
23
- </div>
24
- ${postbackScript(tileId)}
25
- <div class="text-sm mt-5 tracking-wide text-indigo-500">${searchString}</div>
26
- ${renderResults(data, promptResponse)}
27
- </div>
28
- </div>
29
- </body>
30
- </html>
31
- `;
32
- };
33
- exports.knowledgeAssistTemplate = knowledgeAssistTemplate;
34
- const renderResults = (data, promptResponse) => {
35
- let currentResultIndex = 0;
36
- const navigate = (direction) => {
37
- var _a, _b, _c, _d;
38
- currentResultIndex = currentResultIndex + direction;
39
- if (((_a = data === null || data === void 0 ? void 0 : data.topK) === null || _a === void 0 ? void 0 : _a.length) && currentResultIndex >= ((_b = data === null || data === void 0 ? void 0 : data.topK) === null || _b === void 0 ? void 0 : _b.length)) {
40
- currentResultIndex = 0;
4
+ const knowledgeAssistTemplate = ({ data, promptResponse, tileId, searchString, postMessageUrl, enableCopyToClipboard, fontSize, }) => `
5
+ <!doctype html>
6
+ <html lang="en" class="h-full">
7
+ <head>
8
+ <meta charset="UTF-8" />
9
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
+ <title>Search Knowledge Base</title>
11
+ <link
12
+ rel="stylesheet"
13
+ href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
14
+ />
15
+ <style>
16
+ .min-w-20 {
17
+ min-width: 5rem
18
+ }
19
+ @keyframes blinkGreen {
20
+ 50% {
21
+ background-color: #10b981;
41
22
  }
42
- if (((_c = data === null || data === void 0 ? void 0 : data.topK) === null || _c === void 0 ? void 0 : _c.length) && currentResultIndex < 0) {
43
- currentResultIndex = ((_d = data === null || data === void 0 ? void 0 : data.topK) === null || _d === void 0 ? void 0 : _d.length) - 1;
44
- }
45
- };
46
- const generateResultHTML = (resultIndex) => {
47
- const result = data === null || data === void 0 ? void 0 : data.topK[resultIndex];
48
- const hasSource = result.sourceMetaData.sourceName;
49
- return `
50
- <div class="flex-grow">
51
- <div id="resultContainer" class="flex items-center justify-center mt-2 h-full">
52
- <textarea id="textArea" class="w-full h-full rounded-md border p-2" rows="5" placeholder="Your search results will be displayed here">${promptResponse}</textarea>
53
- <div id="loader" class="w-2 hidden h-30 rounded-full border-t-4 border-gray-300 border-solid animate-spin" style="border-width: 16px; border-top-color: #3498db;"></div>
54
- </div>
23
+ }
24
+
25
+ .blink-green {
26
+ animation: blinkGreen 0.5s ease-in-out;
27
+ }
28
+ .knowledgeContainer {
29
+ display: grid;
30
+ grid-auto-rows: 1fr;
31
+ grid-template-columns: 1fr;
32
+ grid-template-rows: 0.5fr 2fr 0.5fr;
33
+ grid-template-areas:
34
+ "search"
35
+ "content"
36
+ "footer";
37
+ }
38
+ .search { grid-area: search; }
39
+ .content {
40
+ grid-area: content;
41
+ overflow: auto;
42
+ }
43
+ .footer { grid-area: footer; }
44
+ </style>
45
+ ${postbackScript(tileId, postMessageUrl, enableCopyToClipboard)}
46
+ </head>
47
+ <body class="h-full">
48
+ <div
49
+ class="h-full items-center bg-white rounded-xl shadow-md p-4 knowledgeContainer overflow-auto"
50
+ data-cognigy-copilot-tile-ka
51
+ data-cognigy-copilot-tile
52
+ >
53
+ <div class="flex flex-wrap items-center w-full h-auto search">
54
+ <div
55
+ class="${fontSize} font-semibold uppercase tracking-wide text-indigo-500"
56
+ >
57
+ Search
58
+ </div>
59
+ <div class="flex flex-grow rounded-md border ml-2 min-w-20">
60
+ <input
61
+ id="searchInput"
62
+ type="text"
63
+ class="w-full rounded-md p-2 focus:outline-none ${fontSize}"
64
+ placeholder="Search your knowledge base"
65
+ />
55
66
  <button
56
- id="liveAgentForwardButton"
57
- onclick="sendPostMessage()"
58
- class="hidden absolute bottom-0 right-0 flex items-center justify-center"
67
+ id="postbackButton"
68
+ class="flex items-center rounded-r-md px-4 py-2"
59
69
  >
60
- <svg
61
- width="45px"
62
- height="auto"
63
- viewBox="0 0 45 35"
64
- xmlns="http://www.w3.org/2000/svg"
65
- >
66
- <path
67
- d="M 18.17 19.653 C 18.538 19.338 16.6 12.9 30.995 15.028 L 30.968 18.05 L 39.7 12.4 L 31.021 6.619 L 31.021 9.326 C 30.1 10.2 16.042 8.143 18.118 19.627"
68
- fill="#0b3694"
69
- transform="scale(-1, 1) translate(-50, 0)"
70
- />
71
- </svg>
70
+ <img
71
+ src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5A6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5S14 7.01 14 9.5S11.99 14 9.5 14'/%3E%3C/svg%3E"
72
+ alt="Search Icon"
73
+ class="h-6 w-8 text-white"
74
+ />
72
75
  </button>
73
- </div>
74
- ${hasSource ? sourcesElements(result.sourceMetaData) : ""}
75
- `;
76
- };
77
- let resultHTML = generateResultHTML(currentResultIndex);
78
- return resultHTML;
76
+ </div>
77
+ </div>
78
+
79
+ <div class="flex flex-col w-full h-full content overflow-auto">
80
+ <div class="${fontSize} mt-5 tracking-wide text-indigo-500">
81
+ ${searchString}
82
+ </div>
83
+ ${renderPrompt(promptResponse, fontSize)} ${renderSourceElements(data, fontSize)}
84
+ </div>
85
+ <div class="flex mt-auto justify-between w-full py-2 footer">
86
+ ${renderButtons(enableCopyToClipboard, fontSize)}
87
+ </div>
88
+ </div>
89
+ </body>
90
+ </html>
91
+ `;
92
+ exports.knowledgeAssistTemplate = knowledgeAssistTemplate;
93
+ const renderPrompt = (promptResponse, fontSize) => `
94
+ <div class="flex-grow">
95
+ <div
96
+ id="resultContainer"
97
+ class="flex items-center justify-center mt-2 h-full"
98
+ >
99
+ <textarea
100
+ id="textArea"
101
+ class="w-full h-full rounded-md border p-2 ${fontSize} focus:outline-none"
102
+ placeholder="Your search results will be displayed here"
103
+ data-cognigy-content
104
+ >
105
+ ${promptResponse}
106
+ </textarea>
107
+ <div
108
+ id="loader"
109
+ class="w-2 hidden h-30 rounded-full border-t-4 border-gray-300 border-solid animate-spin"
110
+ style="border-width: 16px; border-top-color: #3498db"
111
+ ></div>
112
+ </div>
113
+ </div>
114
+ `;
115
+ const renderSourceElements = (data, fontSize) => {
116
+ const result = data === null || data === void 0 ? void 0 : data.topK[0];
117
+ const hasSource = result === null || result === void 0 ? void 0 : result.sourceMetaData.sourceName;
118
+ return hasSource ? sourcesElements(fontSize, result === null || result === void 0 ? void 0 : result.sourceMetaData) : "";
79
119
  };
120
+ const renderButtons = (enableCopyToClipboard, fontSize) => `
121
+ ${enableCopyToClipboard
122
+ ? `
123
+ <button
124
+ class="min-w-20 bg-blue-500 hover:bg-blue-700 text-white font-bold rounded focus:ring-4 focus:outline-none focus:ring-blue-300 ${fontSize} py-2 items-center inline-flex justify-center hidden"
125
+ data-cognigy-clipboard-button
126
+ disabled
127
+ >
128
+ <span class="default-message">Copy</span>
129
+ <span class="success-message hidden inline-flex items-center gap-1">
130
+ <svg
131
+ class="w-3 h-3 text-white me-1.5"
132
+ aria-hidden="true"
133
+ xmlns="http://www.w3.org/2000/svg"
134
+ fill="none"
135
+ viewBox="0 0 16 12"
136
+ >
137
+ <path
138
+ stroke="currentColor"
139
+ stroke-linecap="round"
140
+ stroke-linejoin="round"
141
+ stroke-width="2"
142
+ d="M1 5.917 5.724 10.5 15 1.5"
143
+ />
144
+ </svg>
145
+ Copied!
146
+ </span>
147
+ </button>
148
+ `
149
+ : "<div></div>"}
150
+ <button
151
+ id="liveAgentForwardButton"
152
+ class="hidden"
153
+ disabled
154
+ >
155
+ <svg
156
+ width="45px"
157
+ height="auto"
158
+ viewBox="0 0 45 35"
159
+ xmlns="http://www.w3.org/2000/svg"
160
+ >
161
+ <path
162
+ d="M 18.17 19.653 C 18.538 19.338 16.6 12.9 30.995 15.028 L 30.968 18.05 L 39.7 12.4 L 31.021 6.619 L 31.021 9.326 C 30.1 10.2 16.042 8.143 18.118 19.627"
163
+ fill="#0b3694"
164
+ transform="scale(-1, 1) translate(-50, 0)"
165
+ />
166
+ </svg>
167
+ </button>
168
+ `;
80
169
  /**
81
170
  * Helper function to dynamically render the sources section based on the data provided by the search.
82
171
  *
83
172
  * @param source
84
173
  * @returns
85
174
  */
86
- const sourcesElements = (source) => {
175
+ const sourcesElements = (fontSize, source) => {
87
176
  var _a;
88
177
  if (!source || !source.url) {
89
178
  return "";
90
179
  }
91
180
  return `
92
181
  <div class="mt-4">
93
- <div class="text-sm font-semibold uppercase tracking-wide text-indigo-500">Source</div>
182
+ <div class="${fontSize} font-semibold uppercase tracking-wide text-indigo-500">Source</div>
94
183
  <div class="mt-2">
95
184
  <div class="flex flex-col flex-wrap gap-2">
96
- <a href="${source.url}" target="_blank" class="text-indigo-500 hover:text-indigo-600">${(_a = source.title) !== null && _a !== void 0 ? _a : source.url}</a>
97
- ${source.sourceType ? `<p>${source.sourceType}</p>` : ""}
185
+ <a href="${source.url}" target="_blank" class="break-all text-indigo-500 ${fontSize} hover:text-indigo-600">${(_a = source.title) !== null && _a !== void 0 ? _a : source.url}</a>
186
+ ${source.sourceType
187
+ ? `<p class="${fontSize} break-all">${source.sourceType}</p>`
188
+ : ""}
98
189
  </div>
99
190
  </div>
100
191
  </div>
101
192
  `;
102
193
  };
103
- const postbackScript = (tileId) => `
194
+ const postbackScript = (tileId, postMessageUrl, enableCopyToClipboard) => `
104
195
  <script>
196
+ (function () {
105
197
  const u = (o) => ({ __INTER_FRAME_SOCKET_MESSAGE: !0, workspaceEvent: o }),
106
- h = (o, e) => ({ type: o, payload: e }),
107
- w = (o) => {
108
- var e;
109
- return !!((e = o.data) != null && e.__INTER_FRAME_SOCKET_MESSAGE);
110
- };
198
+ h = (o, e) => ({ type: o, payload: e }),
199
+ w = (o) => {
200
+ var e;
201
+ return !!((e = o.data) != null && e.__INTER_FRAME_SOCKET_MESSAGE);
202
+ };
111
203
  class b {
112
- constructor(e, a, d) {
113
- (this.sourceWindow = e),
114
- (this.targetWindow = a),
115
- (this.targetOrigin = d),
116
- (this.emit = (s, r) => {
117
- const t = h(s, r),
118
- i = u(t);
119
- this.targetWindow.postMessage(i, this.targetOrigin);
120
- });
121
- }
204
+ constructor(e, a, d) {
205
+ (this.sourceWindow = e),
206
+ (this.targetWindow = a),
207
+ (this.targetOrigin = d),
208
+ (this.emit = (s, r) => {
209
+ const t = h(s, r),
210
+ i = u(t);
211
+ this.targetWindow.postMessage(i, this.targetOrigin);
212
+ });
213
+ }
122
214
  }
123
215
  class c {
124
- constructor() {
125
- console.log(document.referrer ?? window.origin)
216
+ constructor() {
217
+ console.log(document.referrer ?? window.origin);
126
218
 
127
- this.socket = new b(
128
- window,
129
- window.parent,
130
- new URL(document?.referrer || window?.origin || "https://agent-assist-dev.cognigy.ai").origin
131
- );
132
- c.log("initialized");
133
- return this; // Return this object.
134
- }
135
- postback(e) {
136
- this.socket.emit("postback", e); // Send the postback event immediately.
137
- return this; // Return this object for chaining.
138
- }
139
- static log(...e) {
140
- console.log("[AgentAssistWorkspaceSDK]", ...e);
141
- }
219
+ this.socket = new b(
220
+ window,
221
+ window.parent,
222
+ new URL(
223
+ document?.referrer ||
224
+ window?.origin ||
225
+ "https://agent-assist-dev.cognigy.ai",
226
+ ).origin,
227
+ );
228
+ c.log("initialized");
229
+ return this; // Return this object.
230
+ }
231
+ postback(e) {
232
+ this.socket.emit("postback", e); // Send the postback event immediately.
233
+ return this; // Return this object for chaining.
234
+ }
235
+ static log(...e) {
236
+ console.log("[AgentAssistWorkspaceSDK]", ...e);
237
+ }
142
238
  }
143
239
  window.SDK = new c();
144
240
 
145
241
  const triggerSearch = () => {
146
- const input = document.getElementById('searchInput').value;
147
- const data = {searchString: input, tileId: '${tileId}'};
148
- window.SDK.postback(data);
242
+ const input = document.getElementById("searchInput").value;
243
+ const data = { searchString: input, tileId: "${tileId}" };
244
+ window.SDK.postback(data);
149
245
 
150
- document.getElementById('searchInput').value = '';
151
- document.getElementById('loader').style.display = 'block';
152
- document.getElementById('textArea').style.display = 'none';
246
+ document.getElementById("searchInput").value = "";
247
+ document.getElementById("loader").style.display = "block";
248
+ document.getElementById("textArea").style.display = "none";
153
249
  };
154
250
 
155
- document.getElementById('postbackButton').onclick = () => {
156
- triggerSearch();
157
- };
251
+ let showButton = false;
252
+ let showCopyButton = true;
253
+
254
+ function updateButtonVisibility() {
255
+ const elements = document.querySelectorAll(
256
+ "[data-cognigy-copilot-tile-ka]",
257
+ );
158
258
 
159
- document.getElementById('searchInput').addEventListener('keypress', (event) => {
160
- if (event.key === 'Enter') {
161
- event.preventDefault();
162
- triggerSearch();
163
- }
164
- });
259
+ elements.forEach((element) => {
260
+ const button = element.querySelector("#liveAgentForwardButton");
261
+ if (button) {
262
+ button.className = showButton
263
+ ? "justify-self-end col-start-8"
264
+ : "hidden";
265
+ }
266
+ });
267
+ }
268
+
269
+ function updateCopyButtonVisibility() {
270
+ const elements = document.querySelectorAll(
271
+ "[data-cognigy-copilot-tile-ka]",
272
+ );
165
273
 
166
- let showButton = false;
274
+ elements.forEach((element) => {
275
+ const button = element.querySelector("[data-cognigy-clipboard-button]");
276
+ if(!button) return;
277
+
278
+ if (showCopyButton) {
279
+ button.classList.remove("hidden");
280
+ } else {
281
+ button.classList.add("hidden");
282
+ }
283
+ });
284
+ }
167
285
 
168
- function updateButtonVisibility() {
169
- const button = document.getElementById("liveAgentForwardButton");
170
- const resultContainer = document.getElementById("resultContainer");
286
+ window.addEventListener("message", (event) => {
287
+ const message = event.data;
171
288
 
172
- if (button) {
173
- if (showButton) {
174
- button.className = "absolute bottom-0 right-0 flex items-center justify-center";
175
- resultContainer.classList.add("pb-5");
176
- } else {
177
- button.className = "hidden";
178
- resultContainer.classList.remove("pb-5");
179
- }
180
- }
181
- }
289
+ if (message.type === "toggleButton") {
290
+ showButton = message.show;
291
+ updateButtonVisibility();
292
+ }
293
+ if (message.type === "toggleCopyButton") {
294
+ showCopyButton = message.show;
295
+ updateCopyButtonVisibility();
296
+ }
297
+ });
182
298
 
299
+ function sendPostMessage() {
300
+ const wrapper = event.target.closest("[data-cognigy-copilot-tile]");
301
+ const contentElement = wrapper.querySelector(
302
+ "[data-cognigy-content]",
303
+ );
304
+ const content = contentElement.value.trim();
305
+ window.parent.postMessage(
306
+ { type: "replyBoxContent", content },
307
+ "${postMessageUrl}",
308
+ );
309
+ }
310
+
311
+ ${enableCopyToClipboard
312
+ ? ` async function copyToClipboard(event) {
313
+ const wrapper = event.target.closest("[data-cognigy-copilot-tile]");
314
+ const contentElement = wrapper.querySelector(
315
+ "[data-cognigy-content]",
316
+ );
317
+ const button = wrapper.querySelector(
318
+ "[data-cognigy-clipboard-button]",
319
+ );
320
+ button.classList.add("blink-green");
321
+ button.addEventListener(
322
+ "animationend",
323
+ function () {
324
+ button.classList.remove("blink-green");
325
+ },
326
+ { once: true },
327
+ );
183
328
 
184
- window.addEventListener("message", (event) => {
185
- const message = event.data;
329
+ const defaultMessage = button.querySelector(".default-message");
330
+ const successMessage = button.querySelector(".success-message");
186
331
 
187
- if (message.type === "toggleButton") {
188
- showButton = message.show;
189
- updateButtonVisibility();
190
- }
191
- });
332
+ try {
333
+ await navigator.clipboard.writeText(contentElement.value.trim());
334
+ defaultMessage.classList.add("hidden");
335
+ successMessage.classList.remove("hidden");
192
336
 
193
- function sendPostMessage() {
194
- const content = document.getElementById("textArea").value;
195
- window.parent.postMessage(
196
- { type: "replyBoxContent", content },
197
- "${process.env.AGENT_ASSIST_WORKSPACE_FRONTEND_URL_WITH_PROTOCOL}"
198
- );
199
- }
337
+ // reset to default state
338
+ setTimeout(() => {
339
+ defaultMessage.classList.remove("hidden");
340
+ successMessage.classList.add("hidden");
341
+ }, 2000);
342
+ } catch (err) {
343
+ console.error("Failed to copy: ", err);
344
+ }
345
+ }`
346
+ : ""}
200
347
 
201
- document.addEventListener("DOMContentLoaded", updateButtonVisibility);
202
- </script>`;
348
+ document.addEventListener("DOMContentLoaded", updateButtonVisibility);
349
+ document.addEventListener("DOMContentLoaded", updateCopyButtonVisibility);
350
+ document.addEventListener("DOMContentLoaded", () => {
351
+ document
352
+ .getElementById("searchInput")
353
+ .addEventListener("keypress", (event) => {
354
+ if (event.key === "Enter") {
355
+ event.preventDefault();
356
+ triggerSearch();
357
+ }
358
+ });
359
+ document.querySelector("#postbackButton").addEventListener("click", triggerSearch);
360
+ document
361
+ .querySelector("[data-cognigy-copilot-tile-ka] #liveAgentForwardButton")
362
+ .addEventListener("click", sendPostMessage);
363
+ ${enableCopyToClipboard
364
+ ? `document
365
+ .querySelector("[data-cognigy-copilot-tile-ka] [data-cognigy-clipboard-button]")
366
+ .addEventListener("click", copyToClipboard);
367
+
368
+ document
369
+ .querySelector("[data-cognigy-copilot-tile-ka] [data-cognigy-clipboard-button]")
370
+ .removeAttribute("disabled");`
371
+ : ""}
372
+
373
+ document
374
+ .querySelector("[data-cognigy-copilot-tile-ka] #liveAgentForwardButton")
375
+ .removeAttribute("disabled");
376
+ });
377
+ })();
378
+ </script>
379
+ `;
203
380
  //# sourceMappingURL=knowledgeAssistTemplate.js.map