@memori.ai/memori-react 9.0.0-alpha.5 → 9.0.0-alpha.7
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 +56 -0
- package/dist/components/AgeVerificationModal/AgeVerificationModal.js +8 -3
- package/dist/components/AgeVerificationModal/AgeVerificationModal.js.map +1 -1
- package/dist/components/Auth/Auth.js +3 -1
- package/dist/components/Auth/Auth.js.map +1 -1
- package/dist/components/Avatar/Avatar.js +5 -10
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +8 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +1 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +2 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js +14 -5
- package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
- package/dist/components/Chat/Chat.js +3 -1
- package/dist/components/Chat/Chat.js.map +1 -1
- package/dist/components/ChatBubble/ChatBubble.js +21 -15
- package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
- package/dist/components/ChatHistoryDrawer/ChatHistory.js +3 -1
- package/dist/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
- package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
- package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
- package/dist/components/ContentPreviewModal/ContentPreviewModal.js +3 -1
- package/dist/components/ContentPreviewModal/ContentPreviewModal.js.map +1 -1
- package/dist/components/DateSelector/DateSelector.d.ts +2 -1
- package/dist/components/DateSelector/DateSelector.js +17 -7
- package/dist/components/DateSelector/DateSelector.js.map +1 -1
- package/dist/components/ExpertsDrawer/ExpertsDrawer.js +3 -1
- package/dist/components/ExpertsDrawer/ExpertsDrawer.js.map +1 -1
- package/dist/components/FilePreview/FilePreview.js +22 -5
- package/dist/components/FilePreview/FilePreview.js.map +1 -1
- package/dist/components/KnownFacts/KnownFacts.js +5 -3
- package/dist/components/KnownFacts/KnownFacts.js.map +1 -1
- package/dist/components/LoginDrawer/LoginDrawer.js +3 -1
- package/dist/components/LoginDrawer/LoginDrawer.js.map +1 -1
- package/dist/components/MediaWidget/MediaItemWidget.js +14 -12
- package/dist/components/MediaWidget/MediaItemWidget.js.map +1 -1
- package/dist/components/MediaWidget/MediaItemWidget.utils.d.ts +3 -2
- package/dist/components/MediaWidget/MediaItemWidget.utils.js +28 -6
- package/dist/components/MediaWidget/MediaItemWidget.utils.js.map +1 -1
- package/dist/components/MediaWidget/MediaPreviewModal.js +6 -7
- package/dist/components/MediaWidget/MediaPreviewModal.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +19 -5
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +4 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.css +4 -2
- package/dist/components/MemoriWidget/MemoriWidget.js +760 -404
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/SettingsDrawer/SettingsDrawer.js +3 -1
- package/dist/components/SettingsDrawer/SettingsDrawer.js.map +1 -1
- package/dist/components/StartPanel/StartPanel.js +3 -1
- package/dist/components/StartPanel/StartPanel.js.map +1 -1
- package/dist/components/UploadButton/UploadButton.js +21 -5
- package/dist/components/UploadButton/UploadButton.js.map +1 -1
- package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js +126 -60
- package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
- package/dist/components/UploadButton/UploadImages/UploadImages.js +3 -1
- package/dist/components/UploadButton/UploadImages/UploadImages.js.map +1 -1
- package/dist/components/WhyThisAnswer/WhyThisAnswer.js +3 -1
- package/dist/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
- package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js +3 -1
- package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +1 -1
- package/dist/components/layouts/WebsiteAssistant/website-assistant.css +21 -1
- package/dist/components/layouts/chat.css +2 -1
- package/dist/components/layouts/fullpage.css +31 -8
- package/dist/components/layouts/hidden-chat.css +1 -0
- package/dist/components/layouts/totem.css +2 -1
- package/dist/components/layouts/zoomed-full-body.css +32 -7
- package/dist/context/widgetSurfaceContext.d.ts +3 -0
- package/dist/context/widgetSurfaceContext.js +11 -0
- package/dist/context/widgetSurfaceContext.js.map +1 -0
- package/dist/helpers/constants.d.ts +3 -0
- package/dist/helpers/constants.js +27 -1
- package/dist/helpers/constants.js.map +1 -1
- package/dist/helpers/credits.d.ts +5 -2
- package/dist/helpers/credits.js +5 -1
- package/dist/helpers/credits.js.map +1 -1
- package/dist/helpers/message.d.ts +1 -1
- package/dist/helpers/message.js +4 -4
- package/dist/helpers/message.js.map +1 -1
- package/dist/helpers/nats/getNatsConfig.d.ts +9 -0
- package/dist/helpers/nats/getNatsConfig.js +65 -0
- package/dist/helpers/nats/getNatsConfig.js.map +1 -0
- package/dist/helpers/nats/isSessionExpiredError.d.ts +3 -0
- package/dist/helpers/nats/isSessionExpiredError.js +36 -0
- package/dist/helpers/nats/isSessionExpiredError.js.map +1 -0
- package/dist/helpers/nats/useNats.d.ts +12 -0
- package/dist/helpers/nats/useNats.js +75 -0
- package/dist/helpers/nats/useNats.js.map +1 -0
- package/dist/helpers/nats/useNatsSession.d.ts +28 -0
- package/dist/helpers/nats/useNatsSession.js +212 -0
- package/dist/helpers/nats/useNatsSession.js.map +1 -0
- package/dist/helpers/utils.d.ts +21 -0
- package/dist/helpers/utils.js +75 -4
- package/dist/helpers/utils.js.map +1 -1
- package/dist/locales/de.json +1 -0
- package/dist/locales/en.json +1 -0
- package/dist/locales/es.json +1 -0
- package/dist/locales/fr.json +1 -0
- package/dist/locales/it.json +1 -0
- package/dist/styles.css +1 -1
- package/dist/types/integration.d.ts +3 -0
- package/dist/types/integration.js +16 -0
- package/dist/types/integration.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/esm/components/AgeVerificationModal/AgeVerificationModal.js +8 -3
- package/esm/components/AgeVerificationModal/AgeVerificationModal.js.map +1 -1
- package/esm/components/Auth/Auth.js +3 -1
- package/esm/components/Auth/Auth.js.map +1 -1
- package/esm/components/Avatar/Avatar.js +5 -10
- package/esm/components/Avatar/Avatar.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +9 -2
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +2 -2
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +2 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js +13 -4
- package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
- package/esm/components/Chat/Chat.js +3 -1
- package/esm/components/Chat/Chat.js.map +1 -1
- package/esm/components/ChatBubble/ChatBubble.js +21 -15
- package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
- package/esm/components/ChatHistoryDrawer/ChatHistory.js +3 -1
- package/esm/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
- package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
- package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
- package/esm/components/ContentPreviewModal/ContentPreviewModal.js +3 -1
- package/esm/components/ContentPreviewModal/ContentPreviewModal.js.map +1 -1
- package/esm/components/DateSelector/DateSelector.d.ts +2 -1
- package/esm/components/DateSelector/DateSelector.js +17 -7
- package/esm/components/DateSelector/DateSelector.js.map +1 -1
- package/esm/components/ExpertsDrawer/ExpertsDrawer.js +3 -1
- package/esm/components/ExpertsDrawer/ExpertsDrawer.js.map +1 -1
- package/esm/components/FilePreview/FilePreview.js +24 -7
- package/esm/components/FilePreview/FilePreview.js.map +1 -1
- package/esm/components/KnownFacts/KnownFacts.js +5 -3
- package/esm/components/KnownFacts/KnownFacts.js.map +1 -1
- package/esm/components/LoginDrawer/LoginDrawer.js +3 -1
- package/esm/components/LoginDrawer/LoginDrawer.js.map +1 -1
- package/esm/components/MediaWidget/MediaItemWidget.js +16 -14
- package/esm/components/MediaWidget/MediaItemWidget.js.map +1 -1
- package/esm/components/MediaWidget/MediaItemWidget.utils.d.ts +3 -2
- package/esm/components/MediaWidget/MediaItemWidget.utils.js +27 -6
- package/esm/components/MediaWidget/MediaItemWidget.utils.js.map +1 -1
- package/esm/components/MediaWidget/MediaPreviewModal.js +6 -7
- package/esm/components/MediaWidget/MediaPreviewModal.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +19 -5
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +4 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.css +4 -2
- package/esm/components/MemoriWidget/MemoriWidget.js +760 -404
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/SettingsDrawer/SettingsDrawer.js +3 -1
- package/esm/components/SettingsDrawer/SettingsDrawer.js.map +1 -1
- package/esm/components/StartPanel/StartPanel.js +3 -1
- package/esm/components/StartPanel/StartPanel.js.map +1 -1
- package/esm/components/UploadButton/UploadButton.js +21 -5
- package/esm/components/UploadButton/UploadButton.js.map +1 -1
- package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js +126 -60
- package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
- package/esm/components/UploadButton/UploadImages/UploadImages.js +3 -1
- package/esm/components/UploadButton/UploadImages/UploadImages.js.map +1 -1
- package/esm/components/WhyThisAnswer/WhyThisAnswer.js +3 -1
- package/esm/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
- package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js +3 -1
- package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +1 -1
- package/esm/components/layouts/WebsiteAssistant/website-assistant.css +21 -1
- package/esm/components/layouts/chat.css +2 -1
- package/esm/components/layouts/fullpage.css +31 -8
- package/esm/components/layouts/hidden-chat.css +1 -0
- package/esm/components/layouts/totem.css +2 -1
- package/esm/components/layouts/zoomed-full-body.css +32 -7
- package/esm/context/widgetSurfaceContext.d.ts +3 -0
- package/esm/context/widgetSurfaceContext.js +7 -0
- package/esm/context/widgetSurfaceContext.js.map +1 -0
- package/esm/helpers/constants.d.ts +3 -0
- package/esm/helpers/constants.js +26 -0
- package/esm/helpers/constants.js.map +1 -1
- package/esm/helpers/credits.d.ts +5 -2
- package/esm/helpers/credits.js +5 -1
- package/esm/helpers/credits.js.map +1 -1
- package/esm/helpers/message.d.ts +1 -1
- package/esm/helpers/message.js +2 -2
- package/esm/helpers/message.js.map +1 -1
- package/esm/helpers/nats/getNatsConfig.d.ts +9 -0
- package/esm/helpers/nats/getNatsConfig.js +61 -0
- package/esm/helpers/nats/getNatsConfig.js.map +1 -0
- package/esm/helpers/nats/isSessionExpiredError.d.ts +3 -0
- package/esm/helpers/nats/isSessionExpiredError.js +32 -0
- package/esm/helpers/nats/isSessionExpiredError.js.map +1 -0
- package/esm/helpers/nats/useNats.d.ts +12 -0
- package/esm/helpers/nats/useNats.js +72 -0
- package/esm/helpers/nats/useNats.js.map +1 -0
- package/esm/helpers/nats/useNatsSession.d.ts +28 -0
- package/esm/helpers/nats/useNatsSession.js +208 -0
- package/esm/helpers/nats/useNatsSession.js.map +1 -0
- package/esm/helpers/utils.d.ts +21 -0
- package/esm/helpers/utils.js +68 -3
- package/esm/helpers/utils.js.map +1 -1
- package/esm/locales/de.json +1 -0
- package/esm/locales/en.json +1 -0
- package/esm/locales/es.json +1 -0
- package/esm/locales/fr.json +1 -0
- package/esm/locales/it.json +1 -0
- package/esm/styles.css +1 -1
- package/esm/types/integration.d.ts +3 -0
- package/esm/types/integration.js +11 -0
- package/esm/types/integration.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +5 -3
- package/src/components/AgeVerificationModal/AgeVerificationModal.tsx +9 -1
- package/src/components/Auth/Auth.tsx +3 -0
- package/src/components/Avatar/Avatar.stories.tsx +45 -28
- package/src/components/Avatar/Avatar.test.tsx +54 -0
- package/src/components/Avatar/Avatar.tsx +8 -12
- package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.tsx +12 -5
- package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.ts +2 -1
- package/src/components/Avatar/AvatarView/AvatarComponent/constants.ts +16 -4
- package/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +164 -0
- package/src/components/Chat/Chat.tsx +3 -0
- package/src/components/ChatBubble/ChatBubble.tsx +40 -12
- package/src/components/ChatHistoryDrawer/ChatHistory.tsx +3 -0
- package/src/components/CompletionProviderStatus/CompletionProviderStatus.tsx +8 -4
- package/src/components/ContentPreviewModal/ContentPreviewModal.tsx +3 -0
- package/src/components/DateSelector/DateSelector.stories.tsx +11 -2
- package/src/components/DateSelector/DateSelector.tsx +28 -9
- package/src/components/ExpertsDrawer/ExpertsDrawer.tsx +3 -0
- package/src/components/FilePreview/FilePreview.tsx +28 -7
- package/src/components/KnownFacts/KnownFacts.tsx +5 -0
- package/src/components/LoginDrawer/LoginDrawer.tsx +3 -0
- package/src/components/MediaWidget/MediaItemWidget.tsx +26 -13
- package/src/components/MediaWidget/MediaItemWidget.utils.test.ts +45 -2
- package/src/components/MediaWidget/MediaItemWidget.utils.ts +39 -6
- package/src/components/MediaWidget/MediaPreviewModal.tsx +9 -7
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +19 -5
- package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.tsx +4 -0
- package/src/components/MemoriWidget/MemoriWidget.css +4 -2
- package/src/components/MemoriWidget/MemoriWidget.tsx +818 -349
- package/src/components/SettingsDrawer/SettingsDrawer.tsx +3 -0
- package/src/components/StartPanel/StartPanel.stories.tsx +22 -0
- package/src/components/StartPanel/StartPanel.test.tsx +64 -1
- package/src/components/StartPanel/StartPanel.tsx +3 -0
- package/src/components/StartPanel/__snapshots__/StartPanel.test.tsx.snap +261 -0
- package/src/components/UploadButton/UploadButton.tsx +30 -11
- package/src/components/UploadButton/UploadDocuments/UploadDocuments.tsx +151 -61
- package/src/components/UploadButton/UploadImages/UploadImages.tsx +3 -0
- package/src/components/UploadButton/__snapshots__/UploadButton.test.tsx.snap +2 -2
- package/src/components/WhyThisAnswer/WhyThisAnswer.tsx +3 -0
- package/src/components/layouts/WebsiteAssistant/WebsiteAssistant.tsx +4 -0
- package/src/components/layouts/WebsiteAssistant/__snapshots__/WebsiteAssistant.test.tsx.snap +48 -44
- package/src/components/layouts/WebsiteAssistant/website-assistant.css +21 -1
- package/src/components/layouts/__snapshots__/Chat.test.tsx.snap +533 -529
- package/src/components/layouts/__snapshots__/FullPage.test.tsx.snap +1058 -1050
- package/src/components/layouts/__snapshots__/HiddenChat.test.tsx.snap +443 -439
- package/src/components/layouts/__snapshots__/Totem.test.tsx.snap +584 -580
- package/src/components/layouts/__snapshots__/ZoomedFullBody.test.tsx.snap +528 -524
- package/src/components/layouts/chat.css +2 -1
- package/src/components/layouts/fullpage.css +31 -8
- package/src/components/layouts/hidden-chat.css +1 -0
- package/src/components/layouts/layouts.stories.tsx +131 -12
- package/src/components/layouts/totem.css +2 -1
- package/src/components/layouts/zoomed-full-body.css +32 -7
- package/src/context/widgetSurfaceContext.tsx +14 -0
- package/src/helpers/constants.ts +32 -1
- package/src/helpers/credits.ts +16 -1
- package/src/helpers/message.test.ts +28 -1
- package/src/helpers/message.ts +4 -4
- package/src/helpers/nats/getNatsConfig.ts +145 -0
- package/src/helpers/nats/isSessionExpiredError.test.ts +38 -0
- package/src/helpers/nats/isSessionExpiredError.ts +51 -0
- package/src/helpers/nats/useNats.ts +124 -0
- package/src/helpers/nats/useNatsSession.ts +394 -0
- package/src/helpers/utils.test.ts +162 -0
- package/src/helpers/utils.ts +108 -3
- package/src/index.stories.tsx +32 -0
- package/src/locales/de.json +1 -0
- package/src/locales/en.json +1 -0
- package/src/locales/es.json +1 -0
- package/src/locales/fr.json +1 -0
- package/src/locales/it.json +1 -0
- package/src/styles.css +61 -1
- package/src/types/integration.test.ts +32 -0
- package/src/types/integration.ts +31 -0
- package/src/version.ts +1 -1
|
@@ -11,6 +11,7 @@ const memori_api_client_1 = tslib_1.__importDefault(require("@memori.ai/memori-a
|
|
|
11
11
|
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
12
12
|
const luxon_1 = require("luxon");
|
|
13
13
|
const ui_1 = require("@memori.ai/ui");
|
|
14
|
+
const widgetSurfaceContext_1 = require("../../context/widgetSurfaceContext");
|
|
14
15
|
const Auth_1 = tslib_1.__importDefault(require("../Auth/Auth"));
|
|
15
16
|
const Chat_1 = tslib_1.__importDefault(require("../Chat/Chat"));
|
|
16
17
|
const StartPanel_1 = tslib_1.__importDefault(require("../StartPanel/StartPanel"));
|
|
@@ -41,6 +42,8 @@ const sanitizer_1 = require("../../helpers/sanitizer");
|
|
|
41
42
|
const useTTS_1 = require("../../helpers/tts/useTTS");
|
|
42
43
|
const ChatHistory_1 = tslib_1.__importDefault(require("../ChatHistoryDrawer/ChatHistory"));
|
|
43
44
|
const useSTT_1 = require("../../helpers/stt/useSTT");
|
|
45
|
+
const useNats_1 = require("../../helpers/nats/useNats");
|
|
46
|
+
const isSessionExpiredError_1 = require("../../helpers/nats/isSessionExpiredError");
|
|
44
47
|
const getMemoriState = (integrationId) => {
|
|
45
48
|
var _a, _b, _c, _d, _f;
|
|
46
49
|
let widget = integrationId
|
|
@@ -62,12 +65,23 @@ const getMemoriState = (integrationId) => {
|
|
|
62
65
|
loginToken,
|
|
63
66
|
};
|
|
64
67
|
};
|
|
68
|
+
const resolveLoginTokenValue = (loginToken, userTokenRef, callAdditionalInfoLoginToken, additionalInfoLoginToken, authTokenProp) => {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
return (_c = (_b = (_a = loginToken !== null && loginToken !== void 0 ? loginToken : userTokenRef) !== null && _a !== void 0 ? _a : callAdditionalInfoLoginToken) !== null && _b !== void 0 ? _b : additionalInfoLoginToken) !== null && _c !== void 0 ? _c : authTokenProp;
|
|
71
|
+
};
|
|
65
72
|
const NULL_PLACE_SPEC = {
|
|
66
73
|
placeName: null,
|
|
67
74
|
latitude: null,
|
|
68
75
|
longitude: null,
|
|
69
76
|
uncertaintyKm: null,
|
|
70
77
|
};
|
|
78
|
+
const logWidgetError = (context, detail) => {
|
|
79
|
+
console.error(`[MemoriWidget] ${context}`, detail !== null && detail !== void 0 ? detail : '');
|
|
80
|
+
};
|
|
81
|
+
function readCorrelationID(response) {
|
|
82
|
+
const value = response.correlationID;
|
|
83
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
84
|
+
}
|
|
71
85
|
const typeMessage = (message, waitForPrevious = true, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false) => {
|
|
72
86
|
const e = new CustomEvent('MemoriTextEntered', {
|
|
73
87
|
detail: {
|
|
@@ -163,7 +177,6 @@ window.typeMessageHidden = typeMessageHidden;
|
|
|
163
177
|
window.typeBatchMessages = typeBatchMessages;
|
|
164
178
|
let audioContext;
|
|
165
179
|
let memoriPassword;
|
|
166
|
-
let userToken;
|
|
167
180
|
function getChatStyles(config) {
|
|
168
181
|
var _a;
|
|
169
182
|
const primary = config === null || config === void 0 ? void 0 : config.buttonBgColor;
|
|
@@ -197,10 +210,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
197
210
|
setIsClient(true);
|
|
198
211
|
}, []);
|
|
199
212
|
const client = (0, memori_api_client_1.default)(apiURL, engineURL);
|
|
200
|
-
const { initSession, deleteSession, postTextEnteredEvent, postPlaceChangedEvent, postDateChangedEvent, postTagChangedEvent, getSession, getExpertReferences, getSessionChatLogs, } = client;
|
|
213
|
+
const { initSession, deleteSession, postEnterTextAsync, postTextEnteredEvent, postPlaceChangedEvent, postDateChangedEvent, postTagChangedEvent, getSession, getExpertReferences, getSessionChatLogs, } = client;
|
|
201
214
|
const [instruct, setInstruct] = (0, react_1.useState)(false);
|
|
202
215
|
const [enableFocusChatInput, setEnableFocusChatInput] = (0, react_1.useState)(true);
|
|
203
216
|
const [widgetRootEl, setWidgetRootEl] = (0, react_1.useState)(null);
|
|
217
|
+
const [widgetSurfaceEl, setWidgetSurfaceEl] = (0, react_1.useState)(null);
|
|
204
218
|
const [isDarkTheme, setIsDarkTheme] = (0, react_1.useState)(false);
|
|
205
219
|
(0, react_1.useEffect)(() => {
|
|
206
220
|
var _a;
|
|
@@ -220,35 +234,64 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
220
234
|
return () => observer.disconnect();
|
|
221
235
|
}, [widgetRootEl]);
|
|
222
236
|
const [loginToken, setLoginToken] = (0, react_1.useState)((_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken);
|
|
237
|
+
const userTokenRef = (0, react_1.useRef)((_b = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _b !== void 0 ? _b : authToken);
|
|
238
|
+
const prevPropsLoginTokenRef = (0, react_1.useRef)((_c = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _c !== void 0 ? _c : authToken);
|
|
223
239
|
const [user, setUser] = (0, react_1.useState)({
|
|
224
240
|
avatarURL: typeof userAvatar === 'string' ? userAvatar : undefined,
|
|
225
241
|
});
|
|
242
|
+
const resolveLoginToken = (0, react_1.useCallback)((callAdditionalInfoLoginToken) => resolveLoginTokenValue(loginToken, userTokenRef.current, callAdditionalInfoLoginToken, additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken), [loginToken, additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
|
|
226
243
|
(0, react_1.useEffect)(() => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
(0, configuration_1.setLocalConfig)('birthDate', user.birthDate);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
(0, configuration_1.removeLocalConfig)('loginToken');
|
|
243
|
-
}
|
|
244
|
-
});
|
|
244
|
+
var _a;
|
|
245
|
+
const incomingToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
|
|
246
|
+
const prevPropsToken = prevPropsLoginTokenRef.current;
|
|
247
|
+
prevPropsLoginTokenRef.current = incomingToken;
|
|
248
|
+
if (incomingToken !== prevPropsToken) {
|
|
249
|
+
setLoginToken(incomingToken);
|
|
250
|
+
userTokenRef.current = incomingToken;
|
|
251
|
+
if (!incomingToken) {
|
|
252
|
+
(0, configuration_1.removeLocalConfig)('loginToken');
|
|
253
|
+
setUser(undefined);
|
|
254
|
+
}
|
|
245
255
|
}
|
|
246
|
-
}, [
|
|
256
|
+
}, [additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
|
|
257
|
+
(0, react_1.useEffect)(() => {
|
|
258
|
+
if (!loginToken || !(showLogin || memori.requireLoginToken)) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
let cancelled = false;
|
|
262
|
+
client.backend
|
|
263
|
+
.pwlGetCurrentUser(loginToken)
|
|
264
|
+
.then(({ user: fetchedUser, resultCode }) => {
|
|
265
|
+
if (cancelled)
|
|
266
|
+
return;
|
|
267
|
+
if (fetchedUser && resultCode === 0) {
|
|
268
|
+
setUser(fetchedUser);
|
|
269
|
+
(0, configuration_1.setLocalConfig)('loginToken', loginToken);
|
|
270
|
+
userTokenRef.current = loginToken;
|
|
271
|
+
if (!birthDate && fetchedUser.birthDate) {
|
|
272
|
+
setBirthDate(fetchedUser.birthDate);
|
|
273
|
+
(0, configuration_1.setLocalConfig)('birthDate', fetchedUser.birthDate);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
setLoginToken(undefined);
|
|
278
|
+
userTokenRef.current = undefined;
|
|
279
|
+
setUser(undefined);
|
|
280
|
+
(0, configuration_1.removeLocalConfig)('loginToken');
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return () => {
|
|
284
|
+
cancelled = true;
|
|
285
|
+
};
|
|
286
|
+
}, [loginToken, showLogin, memori.requireLoginToken]);
|
|
247
287
|
const [showLoginDrawer, setShowLoginDrawer] = (0, react_1.useState)(false);
|
|
248
288
|
const [clickedStart, setClickedStart] = (0, react_1.useState)(false);
|
|
249
289
|
const [gotErrorInOpening, setGotErrorInOpening] = (0, react_1.useState)(false);
|
|
250
|
-
const
|
|
251
|
-
|
|
290
|
+
const sessionStartingRef = (0, react_1.useRef)(false);
|
|
291
|
+
const needsCredits = tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation;
|
|
292
|
+
const [hasEnoughCredits, setHasEnoughCredits] = (0, react_1.useState)(true);
|
|
293
|
+
const language = ((_g = (_f = (_d = memori.culture) === null || _d === void 0 ? void 0 : _d.split('-')) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.toUpperCase()) ||
|
|
294
|
+
((_l = (_k = (_j = (_h = memoriConfigs === null || memoriConfigs === void 0 ? void 0 : memoriConfigs.find(c => c.memoriConfigID === memori.memoriConfigurationID)) === null || _h === void 0 ? void 0 : _h.culture) === null || _j === void 0 ? void 0 : _j.split('-')) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.toUpperCase());
|
|
252
295
|
const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
|
|
253
296
|
? JSON.parse(integration.customData)
|
|
254
297
|
: null;
|
|
@@ -256,7 +299,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
256
299
|
? multilingual
|
|
257
300
|
: !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.multilanguage);
|
|
258
301
|
const forcedTimeout = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.forcedTimeout;
|
|
259
|
-
const [userLang, setUserLang] = (0, react_1.useState)((
|
|
302
|
+
const [userLang, setUserLang] = (0, react_1.useState)((_r = (_q = (_p = (_o = (_m = spokenLang !== null && spokenLang !== void 0 ? spokenLang : memoriLang) !== null && _m !== void 0 ? _m : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.lang) !== null && _o !== void 0 ? _o : language) !== null && _p !== void 0 ? _p : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.uiLang) !== null && _q !== void 0 ? _q : i18n.language) !== null && _r !== void 0 ? _r : 'IT');
|
|
260
303
|
(0, react_1.useEffect)(() => {
|
|
261
304
|
if (spokenLang != null) {
|
|
262
305
|
setUserLang(spokenLang);
|
|
@@ -282,6 +325,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
282
325
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
283
326
|
const [memoriTyping, setMemoriTyping] = (0, react_1.useState)(false);
|
|
284
327
|
const [typingText, setTypingText] = (0, react_1.useState)();
|
|
328
|
+
const pendingEnterTextRef = (0, react_1.useRef)(new Map());
|
|
329
|
+
const bufferedNatsResponsesRef = (0, react_1.useRef)(new Map());
|
|
285
330
|
const layoutName = typeof layout === 'string'
|
|
286
331
|
? layout
|
|
287
332
|
: layout &&
|
|
@@ -292,7 +337,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
292
337
|
? layout.name
|
|
293
338
|
: typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'string'
|
|
294
339
|
? integrationConfig.layout
|
|
295
|
-
: (
|
|
340
|
+
: (_s = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _s === void 0 ? void 0 : _s.name;
|
|
296
341
|
const selectedLayout = (() => {
|
|
297
342
|
if (typeof layoutName === 'string') {
|
|
298
343
|
const lower = layoutName.toLowerCase();
|
|
@@ -320,14 +365,14 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
320
365
|
typeof layout === 'object' &&
|
|
321
366
|
layout !== null &&
|
|
322
367
|
'piiDetection' in layout &&
|
|
323
|
-
((
|
|
368
|
+
((_t = layout.piiDetection) === null || _t === void 0 ? void 0 : _t.enabled)
|
|
324
369
|
? layout.piiDetection
|
|
325
370
|
: typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'object' &&
|
|
326
371
|
(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) !== null &&
|
|
327
|
-
((
|
|
372
|
+
((_v = (_u = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _u === void 0 ? void 0 : _u.piiDetection) === null || _v === void 0 ? void 0 : _v.enabled)
|
|
328
373
|
? integrationConfig.layout.piiDetection
|
|
329
374
|
: undefined;
|
|
330
|
-
const defaultEnableAudio = (
|
|
375
|
+
const defaultEnableAudio = (_w = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _w !== void 0 ? _w : true;
|
|
331
376
|
const [hasUserActivatedListening, setHasUserActivatedListening] = (0, react_1.useState)(false);
|
|
332
377
|
const [hasUserTypedMessage, setHasUserTypedMessage] = (0, react_1.useState)(false);
|
|
333
378
|
const [positionPopoverOpen, setPositionPopoverOpenState] = (0, react_1.useState)(false);
|
|
@@ -370,7 +415,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
370
415
|
setRuntimeShowMessageConsumption((0, configuration_1.getLocalConfig)('showMessageConsumption', (_a = showMessageConsumption !== null && showMessageConsumption !== void 0 ? showMessageConsumption : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showMessageConsumption) !== null && _a !== void 0 ? _a : false));
|
|
371
416
|
if (!(additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) && !authToken) {
|
|
372
417
|
setLoginToken((0, configuration_1.getLocalConfig)('loginToken', undefined));
|
|
373
|
-
|
|
418
|
+
userTokenRef.current = (0, configuration_1.getLocalConfig)('loginToken', undefined);
|
|
374
419
|
setBirthDate((0, configuration_1.getLocalConfig)('birthDate', undefined));
|
|
375
420
|
}
|
|
376
421
|
if (!((_b = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _b !== void 0 ? _b : true)) {
|
|
@@ -468,8 +513,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
468
513
|
});
|
|
469
514
|
};
|
|
470
515
|
const [chatLogID, setChatLogID] = (0, react_1.useState)(undefined);
|
|
471
|
-
const sendMessage = async (text, media, newSessionId, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false) => {
|
|
472
|
-
var _a, _b
|
|
516
|
+
const sendMessage = async (text, media, newSessionId, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false, skipHistoryPush = false) => {
|
|
517
|
+
var _a, _b;
|
|
473
518
|
const sessionID = newSessionId ||
|
|
474
519
|
sessionId ||
|
|
475
520
|
((_a = window.getMemoriState()) === null || _a === void 0 ? void 0 : _a.sessionID);
|
|
@@ -513,7 +558,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
513
558
|
return;
|
|
514
559
|
}
|
|
515
560
|
}
|
|
516
|
-
if (!hidden)
|
|
561
|
+
if (!hidden && !skipHistoryPush)
|
|
517
562
|
pushMessage({
|
|
518
563
|
text: text,
|
|
519
564
|
translatedText,
|
|
@@ -523,12 +568,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
523
568
|
? !!newSessionId && newSessionId !== sessionId
|
|
524
569
|
: !!newSessionId,
|
|
525
570
|
});
|
|
526
|
-
setMemoriTyping(true);
|
|
527
|
-
setTypingText(typingText);
|
|
528
571
|
let gotError = false;
|
|
529
572
|
try {
|
|
530
573
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
531
|
-
const
|
|
574
|
+
const response = await postEnterTextAsync({
|
|
532
575
|
sessionId: sessionID,
|
|
533
576
|
text: msg,
|
|
534
577
|
...(memori.needsDateTime && {
|
|
@@ -536,65 +579,37 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
536
579
|
}),
|
|
537
580
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
538
581
|
});
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
...currentState,
|
|
558
|
-
emission,
|
|
559
|
-
});
|
|
560
|
-
if (emission) {
|
|
561
|
-
pushMessage({
|
|
562
|
-
text: emission,
|
|
563
|
-
emitter: currentState.emitter,
|
|
564
|
-
media: (_d = currentState.emittedMedia) !== null && _d !== void 0 ? _d : currentState.media,
|
|
565
|
-
llmUsage: currentState.llmUsage,
|
|
566
|
-
fromUser: false,
|
|
567
|
-
questionAnswered: msg,
|
|
568
|
-
generatedByAI: !!currentState.completion,
|
|
569
|
-
contextVars: currentState.contextVars,
|
|
570
|
-
date: currentState.currentDate,
|
|
571
|
-
placeName: currentState.currentPlaceName,
|
|
572
|
-
placeLatitude: currentState.currentLatitude,
|
|
573
|
-
placeLongitude: currentState.currentLongitude,
|
|
574
|
-
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
575
|
-
tag: currentState.currentTag,
|
|
576
|
-
memoryTags: currentState.memoryTags,
|
|
577
|
-
});
|
|
578
|
-
if (emission && shouldPlayAudio(emission)) {
|
|
579
|
-
handleSpeak(emission);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
}
|
|
582
|
+
const correlationID = readCorrelationID(response);
|
|
583
|
+
if (response.resultCode === 0 && correlationID) {
|
|
584
|
+
registerPendingEnterText(correlationID, {
|
|
585
|
+
msg,
|
|
586
|
+
text,
|
|
587
|
+
media,
|
|
588
|
+
translate,
|
|
589
|
+
translatedText,
|
|
590
|
+
hidden,
|
|
591
|
+
typingText,
|
|
592
|
+
useLoaderTextAsMsg,
|
|
593
|
+
hasBatchQueued,
|
|
594
|
+
});
|
|
595
|
+
setMemoriTyping(true);
|
|
596
|
+
setTypingText(typingText);
|
|
597
|
+
}
|
|
598
|
+
else if (response.resultCode === 0) {
|
|
599
|
+
logWidgetError('enter-text missing correlationID', response);
|
|
583
600
|
}
|
|
584
601
|
else if (response.resultCode === 404) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}, 500);
|
|
597
|
-
}
|
|
602
|
+
retryAfterExpiredSessionRef.current({
|
|
603
|
+
text,
|
|
604
|
+
media,
|
|
605
|
+
translate,
|
|
606
|
+
translatedText,
|
|
607
|
+
hidden,
|
|
608
|
+
typingText,
|
|
609
|
+
useLoaderTextAsMsg,
|
|
610
|
+
hasBatchQueued,
|
|
611
|
+
expiredSessionID: sessionID,
|
|
612
|
+
continueFromChatLogID: chatLogID,
|
|
598
613
|
});
|
|
599
614
|
}
|
|
600
615
|
else if (response.resultCode === 500 && response.resultMessage) {
|
|
@@ -611,18 +626,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
611
626
|
]);
|
|
612
627
|
}
|
|
613
628
|
else {
|
|
614
|
-
console.warn('[SEND_MESSAGE]', response);
|
|
615
629
|
return Promise.reject(response);
|
|
616
630
|
}
|
|
617
631
|
}
|
|
618
632
|
catch (error) {
|
|
619
|
-
console.log('error', error);
|
|
620
|
-
console.error(error);
|
|
621
633
|
gotError = true;
|
|
622
|
-
|
|
623
|
-
setMemoriTyping(false);
|
|
624
|
-
}
|
|
625
|
-
if (!hasBatchQueued) {
|
|
634
|
+
logWidgetError('sendMessage failed', error);
|
|
626
635
|
setTypingText(undefined);
|
|
627
636
|
setMemoriTyping(false);
|
|
628
637
|
}
|
|
@@ -704,7 +713,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
704
713
|
}
|
|
705
714
|
}
|
|
706
715
|
catch (error) {
|
|
707
|
-
console.error('[TRANSLATE] Error during translation:', error);
|
|
708
716
|
translatedState = { ...state, emission };
|
|
709
717
|
translatedMsg = {
|
|
710
718
|
text: emission,
|
|
@@ -812,7 +820,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
812
820
|
try {
|
|
813
821
|
setTimeout(() => {
|
|
814
822
|
var _a;
|
|
815
|
-
console.log('snippet', s);
|
|
816
823
|
new Function((_a = s.content) !== null && _a !== void 0 ? _a : '')();
|
|
817
824
|
setTimeout(() => {
|
|
818
825
|
var _a, _b, _c;
|
|
@@ -821,8 +828,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
821
828
|
}, 400);
|
|
822
829
|
}, 1000);
|
|
823
830
|
}
|
|
824
|
-
catch (
|
|
825
|
-
console.warn(e);
|
|
831
|
+
catch (_a) {
|
|
826
832
|
}
|
|
827
833
|
});
|
|
828
834
|
};
|
|
@@ -833,7 +839,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
833
839
|
}
|
|
834
840
|
}, [initialSessionID]);
|
|
835
841
|
const fetchSession = async (params) => {
|
|
836
|
-
var _a, _b, _c, _d, _f, _g, _h
|
|
842
|
+
var _a, _b, _c, _d, _f, _g, _h;
|
|
837
843
|
let storageBirthDate = (0, configuration_1.getLocalConfig)('birthDate', undefined);
|
|
838
844
|
let userBirthDate = (_a = birthDate !== null && birthDate !== void 0 ? birthDate : params.birthDate) !== null && _a !== void 0 ? _a : storageBirthDate;
|
|
839
845
|
if (!userBirthDate && !!minAge) {
|
|
@@ -847,6 +853,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
847
853
|
setAuthModalState('password');
|
|
848
854
|
return;
|
|
849
855
|
}
|
|
856
|
+
if (!(await checkCredits({ notify: true }))) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
850
859
|
setLoading(true);
|
|
851
860
|
try {
|
|
852
861
|
let referral;
|
|
@@ -855,8 +864,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
855
864
|
return window.location.href;
|
|
856
865
|
})();
|
|
857
866
|
}
|
|
858
|
-
catch (
|
|
859
|
-
console.debug(err);
|
|
867
|
+
catch (_j) {
|
|
860
868
|
}
|
|
861
869
|
const session = await initSession({
|
|
862
870
|
...params,
|
|
@@ -865,8 +873,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
865
873
|
pin: (_c = params.pin) !== null && _c !== void 0 ? _c : personification === null || personification === void 0 ? void 0 : personification.pin,
|
|
866
874
|
additionalInfo: {
|
|
867
875
|
...(params.additionalInfo || additionalInfo || {}),
|
|
868
|
-
loginToken: (
|
|
869
|
-
language: ((
|
|
876
|
+
loginToken: resolveLoginToken((_d = params.additionalInfo) === null || _d === void 0 ? void 0 : _d.loginToken),
|
|
877
|
+
language: ((_h = userLang !== null && userLang !== void 0 ? userLang : (_g = (_f = memori.culture) === null || _f === void 0 ? void 0 : _f.split('-')) === null || _g === void 0 ? void 0 : _g[0]) !== null && _h !== void 0 ? _h : 'IT').toLowerCase(),
|
|
870
878
|
referral: referral,
|
|
871
879
|
timeZoneOffset: new Date().getTimezoneOffset().toString(),
|
|
872
880
|
},
|
|
@@ -895,7 +903,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
895
903
|
}));
|
|
896
904
|
setGotErrorInOpening(true);
|
|
897
905
|
}
|
|
898
|
-
else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 403) {
|
|
906
|
+
else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 403 && memori.privacyType !== 'PUBLIC') {
|
|
899
907
|
setMemoriPwd(undefined);
|
|
900
908
|
setAuthModalState('password');
|
|
901
909
|
return session;
|
|
@@ -907,16 +915,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
907
915
|
severity: 'error',
|
|
908
916
|
duration: 0,
|
|
909
917
|
}));
|
|
910
|
-
setGotErrorInOpening(true);
|
|
911
918
|
return session;
|
|
912
919
|
}
|
|
913
920
|
}
|
|
914
921
|
catch (err) {
|
|
915
|
-
|
|
922
|
+
logWidgetError('fetchSession failed', err);
|
|
916
923
|
}
|
|
917
924
|
};
|
|
918
|
-
const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired) => {
|
|
919
|
-
var _a, _b, _c, _d, _f, _g, _h, _j
|
|
925
|
+
const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired, suppressHistoryUpdate) => {
|
|
926
|
+
var _a, _b, _c, _d, _f, _g, _h, _j;
|
|
920
927
|
setLoading(true);
|
|
921
928
|
let storageBirthDate = (0, configuration_1.getLocalConfig)('birthDate', undefined);
|
|
922
929
|
let userBirthDate = birthDate !== null && birthDate !== void 0 ? birthDate : storageBirthDate;
|
|
@@ -934,14 +941,17 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
934
941
|
setAuthModalState('password');
|
|
935
942
|
return;
|
|
936
943
|
}
|
|
944
|
+
if (!(await checkCredits({ notify: true }))) {
|
|
945
|
+
setLoading(false);
|
|
946
|
+
return null;
|
|
947
|
+
}
|
|
937
948
|
let referral;
|
|
938
949
|
try {
|
|
939
950
|
referral = (() => {
|
|
940
951
|
return window.location.href;
|
|
941
952
|
})();
|
|
942
953
|
}
|
|
943
|
-
catch (
|
|
944
|
-
console.debug('[REOPEN_SESSION] Error getting referral:', err);
|
|
954
|
+
catch (_k) {
|
|
945
955
|
}
|
|
946
956
|
const { sessionID, currentState, ...response } = await initSession({
|
|
947
957
|
memoriID: (_a = memori.engineMemoriID) !== null && _a !== void 0 ? _a : '',
|
|
@@ -961,21 +971,32 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
961
971
|
birthDate: userBirthDate,
|
|
962
972
|
additionalInfo: {
|
|
963
973
|
...(additionalInfoProp || additionalInfo || {}),
|
|
964
|
-
loginToken: (
|
|
965
|
-
language: ((
|
|
974
|
+
loginToken: resolveLoginToken(additionalInfoProp === null || additionalInfoProp === void 0 ? void 0 : additionalInfoProp.loginToken),
|
|
975
|
+
language: ((_g = userLang !== null && userLang !== void 0 ? userLang : (_f = (_d = memori.culture) === null || _d === void 0 ? void 0 : _d.split('-')) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : 'IT').toLowerCase(),
|
|
966
976
|
referral: referral,
|
|
967
977
|
timeZoneOffset: new Date().getTimezoneOffset().toString(),
|
|
968
978
|
},
|
|
969
979
|
});
|
|
970
980
|
if (sessionID && currentState && response.resultCode === 0) {
|
|
971
|
-
console.log('[REOPEN_SESSION] Session initialized successfully:', sessionID);
|
|
972
981
|
setSessionId(sessionID);
|
|
973
982
|
if (updateDialogState) {
|
|
974
983
|
setCurrentDialogState(currentState);
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
984
|
+
const sessionExpiredStatus = isSessionExpired && history.length > 1
|
|
985
|
+
? t('sessionExpiredReopening')
|
|
986
|
+
: null;
|
|
987
|
+
if (sessionExpiredStatus && suppressHistoryUpdate) {
|
|
988
|
+
pushMessage({
|
|
989
|
+
text: '',
|
|
990
|
+
emitter: 'system',
|
|
991
|
+
fromUser: false,
|
|
992
|
+
initial: sessionExpiredStatus,
|
|
993
|
+
contextVars: {},
|
|
994
|
+
date: new Date().toISOString(),
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
if (currentState.emission && !suppressHistoryUpdate) {
|
|
998
|
+
const initialStatus = sessionExpiredStatus
|
|
999
|
+
? sessionExpiredStatus
|
|
979
1000
|
: history.length <= 1
|
|
980
1001
|
? true
|
|
981
1002
|
: undefined;
|
|
@@ -984,7 +1005,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
984
1005
|
{
|
|
985
1006
|
text: currentState.emission,
|
|
986
1007
|
emitter: currentState.emitter,
|
|
987
|
-
media: (
|
|
1008
|
+
media: (_h = currentState.emittedMedia) !== null && _h !== void 0 ? _h : currentState.media,
|
|
988
1009
|
fromUser: false,
|
|
989
1010
|
initial: (initialStatus === true
|
|
990
1011
|
? true
|
|
@@ -1002,7 +1023,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1002
1023
|
: pushMessage({
|
|
1003
1024
|
text: currentState.emission,
|
|
1004
1025
|
emitter: currentState.emitter,
|
|
1005
|
-
media: (
|
|
1026
|
+
media: (_j = currentState.emittedMedia) !== null && _j !== void 0 ? _j : currentState.media,
|
|
1006
1027
|
fromUser: false,
|
|
1007
1028
|
initial: (initialStatus === true
|
|
1008
1029
|
? true
|
|
@@ -1032,8 +1053,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1032
1053
|
}));
|
|
1033
1054
|
setGotErrorInOpening(true);
|
|
1034
1055
|
}
|
|
1035
|
-
else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403
|
|
1036
|
-
|
|
1056
|
+
else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403 &&
|
|
1057
|
+
memori.privacyType !== 'PUBLIC') {
|
|
1037
1058
|
setMemoriPwd(undefined);
|
|
1038
1059
|
setAuthModalState('password');
|
|
1039
1060
|
}
|
|
@@ -1047,15 +1068,61 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1047
1068
|
}
|
|
1048
1069
|
}
|
|
1049
1070
|
catch (err) {
|
|
1050
|
-
|
|
1071
|
+
logWidgetError('reopenSession failed', err);
|
|
1051
1072
|
}
|
|
1052
1073
|
setLoading(false);
|
|
1053
1074
|
return null;
|
|
1054
1075
|
};
|
|
1076
|
+
const retryAfterExpiredSessionRef = (0, react_1.useRef)(() => Promise.resolve(null));
|
|
1077
|
+
retryAfterExpiredSessionRef.current = (params) => {
|
|
1078
|
+
const { text, media, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false, expiredSessionID, continueFromChatLogID: continueFromChatLogIDParam, } = params;
|
|
1079
|
+
const continueFromSessionID = expiredSessionID !== null && expiredSessionID !== void 0 ? expiredSessionID : sessionId;
|
|
1080
|
+
const continueFromChatLogID = continueFromChatLogIDParam !== null && continueFromChatLogIDParam !== void 0 ? continueFromChatLogIDParam : chatLogID;
|
|
1081
|
+
const reopenAfterExpiry = () => {
|
|
1082
|
+
var _a, _b;
|
|
1083
|
+
return reopenSession(true, memoriPwd || memori.secretToken, memoriTokens, undefined, undefined, {
|
|
1084
|
+
LANG: userLang,
|
|
1085
|
+
PATHNAME: window.location.pathname,
|
|
1086
|
+
ROUTE: ((_b = (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.split('/')) === null || _b === void 0 ? void 0 : _b.pop()) || '',
|
|
1087
|
+
...(initialContextVars || {}),
|
|
1088
|
+
}, initialQuestion, undefined, undefined, continueFromChatLogID, continueFromSessionID, true, true);
|
|
1089
|
+
};
|
|
1090
|
+
const scheduleRetry = (newSessionID) => {
|
|
1091
|
+
setTimeout(() => {
|
|
1092
|
+
sendMessage(text, media, newSessionID, translate, translatedText, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued, true);
|
|
1093
|
+
}, 500);
|
|
1094
|
+
};
|
|
1095
|
+
const handleReopenFailure = (state) => {
|
|
1096
|
+
setMemoriTyping(false);
|
|
1097
|
+
setTypingText(undefined);
|
|
1098
|
+
if (state === null && text && !hidden) {
|
|
1099
|
+
add((0, ui_1.createAlertOptions)({
|
|
1100
|
+
description: t('errors.SESSION_EXPIRED'),
|
|
1101
|
+
severity: 'error',
|
|
1102
|
+
}));
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
if (!text) {
|
|
1106
|
+
return reopenAfterExpiry().then(state => {
|
|
1107
|
+
if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
|
|
1108
|
+
handleReopenFailure(state);
|
|
1109
|
+
}
|
|
1110
|
+
return state;
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
return reopenAfterExpiry().then(state => {
|
|
1114
|
+
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
1115
|
+
scheduleRetry(state.sessionID);
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
handleReopenFailure(state);
|
|
1119
|
+
}
|
|
1120
|
+
return state;
|
|
1121
|
+
});
|
|
1122
|
+
};
|
|
1055
1123
|
const changeTag = async (memoriId, sessionId, tag, pin) => {
|
|
1056
|
-
var _a, _b, _c, _d, _f, _g, _h
|
|
1124
|
+
var _a, _b, _c, _d, _f, _g, _h;
|
|
1057
1125
|
if (!memoriId || !sessionId) {
|
|
1058
|
-
console.error('CHANGETAG/Session not found');
|
|
1059
1126
|
return Promise.reject('Session not found');
|
|
1060
1127
|
}
|
|
1061
1128
|
try {
|
|
@@ -1087,7 +1154,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1087
1154
|
}
|
|
1088
1155
|
}
|
|
1089
1156
|
else if ([400, 401, 403, 404, 500].includes(resultCode)) {
|
|
1090
|
-
console.warn('[APPCONTEXT/CHANGETAG]', resultCode);
|
|
1091
1157
|
let storageBirthDate = (0, configuration_1.getLocalConfig)('birthDate', undefined);
|
|
1092
1158
|
let referral;
|
|
1093
1159
|
try {
|
|
@@ -1095,8 +1161,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1095
1161
|
return window.location.href;
|
|
1096
1162
|
})();
|
|
1097
1163
|
}
|
|
1098
|
-
catch (
|
|
1099
|
-
console.debug(err);
|
|
1164
|
+
catch (_j) {
|
|
1100
1165
|
}
|
|
1101
1166
|
fetchSession({
|
|
1102
1167
|
memoriID: (_b = memori.engineMemoriID) !== null && _b !== void 0 ? _b : '',
|
|
@@ -1113,8 +1178,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1113
1178
|
birthDate: birthDate || storageBirthDate || undefined,
|
|
1114
1179
|
additionalInfo: {
|
|
1115
1180
|
...(additionalInfo || {}),
|
|
1116
|
-
loginToken: (
|
|
1117
|
-
language: ((
|
|
1181
|
+
loginToken: resolveLoginToken(),
|
|
1182
|
+
language: ((_h = userLang !== null && userLang !== void 0 ? userLang : (_g = (_f = memori.culture) === null || _f === void 0 ? void 0 : _f.split('-')) === null || _g === void 0 ? void 0 : _g[0]) !== null && _h !== void 0 ? _h : 'IT').toLowerCase(),
|
|
1118
1183
|
referral: referral,
|
|
1119
1184
|
timeZoneOffset: new Date().getTimezoneOffset().toString(),
|
|
1120
1185
|
},
|
|
@@ -1131,7 +1196,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1131
1196
|
}
|
|
1132
1197
|
catch (_e) {
|
|
1133
1198
|
let err = _e;
|
|
1134
|
-
console.warn('[APPCONTEXT/CHANGETAG]', err);
|
|
1135
1199
|
return Promise.reject(err);
|
|
1136
1200
|
}
|
|
1137
1201
|
return null;
|
|
@@ -1152,6 +1216,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1152
1216
|
return () => {
|
|
1153
1217
|
setHasUserActivatedSpeak(false);
|
|
1154
1218
|
setClickedStart(false);
|
|
1219
|
+
sessionStartingRef.current = false;
|
|
1155
1220
|
clearInteractionTimeout();
|
|
1156
1221
|
timeoutRef.current = undefined;
|
|
1157
1222
|
};
|
|
@@ -1178,10 +1243,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1178
1243
|
apiUrl: `${baseUrl}/api/tts`,
|
|
1179
1244
|
continuousSpeech: continuousSpeech,
|
|
1180
1245
|
preview: preview,
|
|
1181
|
-
}, autoStart, defaultEnableAudio, (
|
|
1246
|
+
}, autoStart, defaultEnableAudio, (_x = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _x !== void 0 ? _x : true);
|
|
1182
1247
|
const shouldPlayAudio = (text) => {
|
|
1183
1248
|
const currentSpeakerMuted = (0, configuration_1.getLocalConfig)('muteSpeaker', !defaultEnableAudio);
|
|
1184
|
-
console.log('[MemoriWidget] shouldPlayAudio', currentSpeakerMuted);
|
|
1185
1249
|
return (text &&
|
|
1186
1250
|
text.trim() &&
|
|
1187
1251
|
!preview &&
|
|
@@ -1194,15 +1258,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1194
1258
|
}
|
|
1195
1259
|
try {
|
|
1196
1260
|
const message = (0, utils_1.stripDuplicates)(text);
|
|
1197
|
-
console.debug('Processing speech message:', message);
|
|
1198
1261
|
if (message.length > 0) {
|
|
1199
1262
|
setUserMessage('');
|
|
1200
|
-
console.debug('Sending message:', message);
|
|
1201
1263
|
sendMessage(message);
|
|
1202
1264
|
}
|
|
1203
1265
|
}
|
|
1204
|
-
catch (
|
|
1205
|
-
console.error('Error in processSpeechAndSendMessage:', error);
|
|
1266
|
+
catch (_a) {
|
|
1206
1267
|
}
|
|
1207
1268
|
};
|
|
1208
1269
|
const { isListening, startRecording, stopRecording, } = (0, useSTT_1.useSTT)(sttConfig, processSpeechAndSendMessage, {
|
|
@@ -1236,8 +1297,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1236
1297
|
}
|
|
1237
1298
|
return translatedState;
|
|
1238
1299
|
}
|
|
1239
|
-
catch (
|
|
1240
|
-
console.error('Error in translateAndSpeak:', error);
|
|
1300
|
+
catch (_a) {
|
|
1241
1301
|
if (!hasUserActivatedSpeak) {
|
|
1242
1302
|
setHasUserActivatedSpeak(true);
|
|
1243
1303
|
}
|
|
@@ -1250,6 +1310,221 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1250
1310
|
setHasUserActivatedSpeak,
|
|
1251
1311
|
speakerMuted,
|
|
1252
1312
|
]);
|
|
1313
|
+
const processEnterTextDialogResponse = (0, react_1.useCallback)((event, pending) => {
|
|
1314
|
+
var _a, _b;
|
|
1315
|
+
const { msg, typingText: pendingTypingText, useLoaderTextAsMsg, } = pending;
|
|
1316
|
+
const currentState = event.currentState;
|
|
1317
|
+
if (event.resultCode !== 0 || !currentState) {
|
|
1318
|
+
if ((0, isSessionExpiredError_1.isSessionExpiredNatsResponse)(event) && pending.text) {
|
|
1319
|
+
setMemoriTyping(false);
|
|
1320
|
+
setTypingText(undefined);
|
|
1321
|
+
retryAfterExpiredSessionRef.current({
|
|
1322
|
+
text: pending.text,
|
|
1323
|
+
media: pending.media,
|
|
1324
|
+
translate: pending.translate,
|
|
1325
|
+
translatedText: pending.translatedText,
|
|
1326
|
+
hidden: pending.hidden,
|
|
1327
|
+
typingText: pending.typingText,
|
|
1328
|
+
useLoaderTextAsMsg: pending.useLoaderTextAsMsg,
|
|
1329
|
+
hasBatchQueued: pending.hasBatchQueued,
|
|
1330
|
+
expiredSessionID: sessionId,
|
|
1331
|
+
continueFromChatLogID: chatLogID,
|
|
1332
|
+
});
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
if (event.resultCode === 500 && event.resultMessage) {
|
|
1336
|
+
setHistory(h => [
|
|
1337
|
+
...h,
|
|
1338
|
+
{
|
|
1339
|
+
text: 'Error: ' + event.resultMessage,
|
|
1340
|
+
emitter: 'system',
|
|
1341
|
+
fromUser: false,
|
|
1342
|
+
initial: false,
|
|
1343
|
+
contextVars: {},
|
|
1344
|
+
date: new Date().toISOString(),
|
|
1345
|
+
},
|
|
1346
|
+
]);
|
|
1347
|
+
}
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
if (!msg) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
setChatLogID(undefined);
|
|
1354
|
+
const emission = useLoaderTextAsMsg && pendingTypingText
|
|
1355
|
+
? pendingTypingText
|
|
1356
|
+
: (_a = currentState.emission) !== null && _a !== void 0 ? _a : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
1357
|
+
if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
1358
|
+
emission &&
|
|
1359
|
+
isMultilanguageEnabled) {
|
|
1360
|
+
currentState.emission = emission;
|
|
1361
|
+
translateDialogState(currentState, userLang, msg).then(ts => {
|
|
1362
|
+
const text = ts.translatedEmission || ts.emission;
|
|
1363
|
+
if (text && shouldPlayAudio(text)) {
|
|
1364
|
+
handleSpeak(text);
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
else {
|
|
1369
|
+
setCurrentDialogState({
|
|
1370
|
+
...currentState,
|
|
1371
|
+
emission,
|
|
1372
|
+
});
|
|
1373
|
+
if (emission) {
|
|
1374
|
+
pushMessage({
|
|
1375
|
+
text: emission,
|
|
1376
|
+
emitter: currentState.emitter,
|
|
1377
|
+
media: (_b = currentState.emittedMedia) !== null && _b !== void 0 ? _b : currentState.media,
|
|
1378
|
+
llmUsage: currentState.llmUsage,
|
|
1379
|
+
fromUser: false,
|
|
1380
|
+
questionAnswered: msg,
|
|
1381
|
+
generatedByAI: !!currentState.completion,
|
|
1382
|
+
contextVars: currentState.contextVars,
|
|
1383
|
+
date: currentState.currentDate,
|
|
1384
|
+
placeName: currentState.currentPlaceName,
|
|
1385
|
+
placeLatitude: currentState.currentLatitude,
|
|
1386
|
+
placeLongitude: currentState.currentLongitude,
|
|
1387
|
+
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
1388
|
+
tag: currentState.currentTag,
|
|
1389
|
+
memoryTags: currentState.memoryTags,
|
|
1390
|
+
});
|
|
1391
|
+
if (emission && shouldPlayAudio(emission)) {
|
|
1392
|
+
handleSpeak(emission);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}, [
|
|
1397
|
+
userLang,
|
|
1398
|
+
language,
|
|
1399
|
+
isMultilanguageEnabled,
|
|
1400
|
+
currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission,
|
|
1401
|
+
translateDialogState,
|
|
1402
|
+
handleSpeak,
|
|
1403
|
+
shouldPlayAudio,
|
|
1404
|
+
]);
|
|
1405
|
+
const clearEnterTextPending = (0, react_1.useCallback)((correlationID, pending) => {
|
|
1406
|
+
var _a;
|
|
1407
|
+
if ((_a = pending.waitForResponse) === null || _a === void 0 ? void 0 : _a.timeoutId) {
|
|
1408
|
+
clearTimeout(pending.waitForResponse.timeoutId);
|
|
1409
|
+
}
|
|
1410
|
+
pendingEnterTextRef.current.delete(correlationID);
|
|
1411
|
+
}, []);
|
|
1412
|
+
const deliverEnterTextNatsError = (0, react_1.useCallback)((event) => {
|
|
1413
|
+
var _a, _b, _c;
|
|
1414
|
+
const correlationID = event.correlationID;
|
|
1415
|
+
let pending;
|
|
1416
|
+
if (correlationID) {
|
|
1417
|
+
pending = pendingEnterTextRef.current.get(correlationID);
|
|
1418
|
+
if (pending) {
|
|
1419
|
+
clearEnterTextPending(correlationID, pending);
|
|
1420
|
+
(_a = pending.waitForResponse) === null || _a === void 0 ? void 0 : _a.reject(new Error((_b = event.errorMessage) !== null && _b !== void 0 ? _b : String((_c = event.errorCode) !== null && _c !== void 0 ? _c : 'NATS error')));
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
if ((0, isSessionExpiredError_1.isSessionExpiredNatsError)(event) && (pending === null || pending === void 0 ? void 0 : pending.text)) {
|
|
1424
|
+
setMemoriTyping(false);
|
|
1425
|
+
setTypingText(undefined);
|
|
1426
|
+
retryAfterExpiredSessionRef.current({
|
|
1427
|
+
text: pending.text,
|
|
1428
|
+
media: pending.media,
|
|
1429
|
+
translate: pending.translate,
|
|
1430
|
+
translatedText: pending.translatedText,
|
|
1431
|
+
hidden: pending.hidden,
|
|
1432
|
+
typingText: pending.typingText,
|
|
1433
|
+
useLoaderTextAsMsg: pending.useLoaderTextAsMsg,
|
|
1434
|
+
hasBatchQueued: pending.hasBatchQueued,
|
|
1435
|
+
expiredSessionID: sessionId,
|
|
1436
|
+
continueFromChatLogID: chatLogID,
|
|
1437
|
+
});
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
const errorText = event.errorMessage
|
|
1441
|
+
? `Error: ${event.errorMessage}`
|
|
1442
|
+
: event.errorCode
|
|
1443
|
+
? `Error: ${event.errorCode}`
|
|
1444
|
+
: 'Error: An unexpected error occurred';
|
|
1445
|
+
pushMessage({
|
|
1446
|
+
text: errorText,
|
|
1447
|
+
emitter: 'system',
|
|
1448
|
+
fromUser: false,
|
|
1449
|
+
initial: false,
|
|
1450
|
+
contextVars: {},
|
|
1451
|
+
date: new Date().toISOString(),
|
|
1452
|
+
});
|
|
1453
|
+
setMemoriTyping(false);
|
|
1454
|
+
setTypingText(undefined);
|
|
1455
|
+
}, [clearEnterTextPending]);
|
|
1456
|
+
const deliverEnterTextNatsResponse = (0, react_1.useCallback)((correlationID, event) => {
|
|
1457
|
+
const pending = pendingEnterTextRef.current.get(correlationID);
|
|
1458
|
+
if (!pending) {
|
|
1459
|
+
bufferedNatsResponsesRef.current.set(correlationID, event);
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
clearEnterTextPending(correlationID, pending);
|
|
1463
|
+
if (pending.waitForResponse) {
|
|
1464
|
+
pending.waitForResponse.resolve(event);
|
|
1465
|
+
setMemoriTyping(false);
|
|
1466
|
+
setTypingText(undefined);
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
processEnterTextDialogResponse(event, pending);
|
|
1470
|
+
if (!pending.hasBatchQueued) {
|
|
1471
|
+
setMemoriTyping(false);
|
|
1472
|
+
setTypingText(undefined);
|
|
1473
|
+
}
|
|
1474
|
+
}, [processEnterTextDialogResponse, clearEnterTextPending]);
|
|
1475
|
+
const registerPendingEnterText = (0, react_1.useCallback)((correlationID, pending) => {
|
|
1476
|
+
const buffered = bufferedNatsResponsesRef.current.get(correlationID);
|
|
1477
|
+
if (buffered) {
|
|
1478
|
+
bufferedNatsResponsesRef.current.delete(correlationID);
|
|
1479
|
+
pendingEnterTextRef.current.set(correlationID, pending);
|
|
1480
|
+
deliverEnterTextNatsResponse(correlationID, buffered);
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
pendingEnterTextRef.current.set(correlationID, pending);
|
|
1484
|
+
}, [deliverEnterTextNatsResponse]);
|
|
1485
|
+
const waitForEnterTextNatsResponse = (0, react_1.useCallback)((correlationID, timeoutMs = 120000) => new Promise((resolve, reject) => {
|
|
1486
|
+
const timeoutId = setTimeout(() => {
|
|
1487
|
+
const current = pendingEnterTextRef.current.get(correlationID);
|
|
1488
|
+
if (current) {
|
|
1489
|
+
clearEnterTextPending(correlationID, current);
|
|
1490
|
+
}
|
|
1491
|
+
logWidgetError('NATS timeout', { correlationID, timeoutMs });
|
|
1492
|
+
reject(new Error('NATS enter-text response timeout'));
|
|
1493
|
+
}, timeoutMs);
|
|
1494
|
+
registerPendingEnterText(correlationID, {
|
|
1495
|
+
waitForResponse: {
|
|
1496
|
+
resolve: event => {
|
|
1497
|
+
clearTimeout(timeoutId);
|
|
1498
|
+
resolve(event);
|
|
1499
|
+
},
|
|
1500
|
+
reject: error => {
|
|
1501
|
+
clearTimeout(timeoutId);
|
|
1502
|
+
reject(error);
|
|
1503
|
+
},
|
|
1504
|
+
timeoutId,
|
|
1505
|
+
},
|
|
1506
|
+
});
|
|
1507
|
+
}), [registerPendingEnterText, clearEnterTextPending]);
|
|
1508
|
+
(0, useNats_1.useNats)({
|
|
1509
|
+
baseUrl,
|
|
1510
|
+
sessionId,
|
|
1511
|
+
onProgress: (0, react_1.useCallback)((event) => {
|
|
1512
|
+
if (event.message) {
|
|
1513
|
+
setTypingText(event.message);
|
|
1514
|
+
}
|
|
1515
|
+
}, []),
|
|
1516
|
+
onDialogResponse: (0, react_1.useCallback)((event) => {
|
|
1517
|
+
const correlationID = event.correlationID;
|
|
1518
|
+
if (!correlationID) {
|
|
1519
|
+
logWidgetError('NATS dialog response missing correlationID', event);
|
|
1520
|
+
setMemoriTyping(false);
|
|
1521
|
+
setTypingText(undefined);
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
deliverEnterTextNatsResponse(correlationID, event);
|
|
1525
|
+
}, [deliverEnterTextNatsResponse]),
|
|
1526
|
+
onError: deliverEnterTextNatsError,
|
|
1527
|
+
});
|
|
1253
1528
|
const focusChatInput = () => {
|
|
1254
1529
|
let textarea = document.querySelector('#chat-fieldset textarea');
|
|
1255
1530
|
if (textarea && enableFocusChatInput) {
|
|
@@ -1271,7 +1546,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1271
1546
|
timeoutRef.current = undefined;
|
|
1272
1547
|
ttsStop();
|
|
1273
1548
|
}
|
|
1274
|
-
catch (
|
|
1549
|
+
catch (_a) {
|
|
1275
1550
|
}
|
|
1276
1551
|
};
|
|
1277
1552
|
(0, react_1.useEffect)(() => {
|
|
@@ -1434,7 +1709,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1434
1709
|
};
|
|
1435
1710
|
}, [sessionId, userLang, disableTextEnteredEvents]);
|
|
1436
1711
|
const onClickStart = (0, react_1.useCallback)(async (session, initialSessionExpired = false, chatLog, targetSessionID) => {
|
|
1437
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t
|
|
1712
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1438
1713
|
const sessionID = chatLog ? undefined : (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|
|
1439
1714
|
const dialogState = chatLog
|
|
1440
1715
|
? undefined
|
|
@@ -1451,9 +1726,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1451
1726
|
setPositionPopoverOpenState(true);
|
|
1452
1727
|
return;
|
|
1453
1728
|
}
|
|
1729
|
+
if (!(await checkCredits({ notify: true }))) {
|
|
1730
|
+
setClickedStart(false);
|
|
1731
|
+
setLoading(false);
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1454
1734
|
if (!sessionID && !!minAge && !birth) {
|
|
1455
1735
|
setShowAgeVerification(true);
|
|
1456
1736
|
setClickedStart(false);
|
|
1737
|
+
return;
|
|
1457
1738
|
}
|
|
1458
1739
|
else if ((!sessionID &&
|
|
1459
1740
|
memori.privacyType !== 'PUBLIC' &&
|
|
@@ -1466,83 +1747,95 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1466
1747
|
return;
|
|
1467
1748
|
}
|
|
1468
1749
|
else if (!sessionID || initialSessionExpired) {
|
|
1469
|
-
setClickedStart(false);
|
|
1470
1750
|
setGotErrorInOpening(false);
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
:
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
});
|
|
1515
|
-
});
|
|
1516
|
-
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1517
|
-
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1518
|
-
isMultilanguageEnabled) {
|
|
1519
|
-
try {
|
|
1520
|
-
translatedMessages = await Promise.all(messages.map(async (m) => {
|
|
1521
|
-
if ('originalText' in m && m.originalText) {
|
|
1522
|
-
return m;
|
|
1523
|
-
}
|
|
1524
|
-
return {
|
|
1751
|
+
if (sessionStartingRef.current) {
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
sessionStartingRef.current = true;
|
|
1755
|
+
try {
|
|
1756
|
+
const session = await fetchSession({
|
|
1757
|
+
memoriID: memori.engineMemoriID,
|
|
1758
|
+
password: secret || memoriPwd || memori.secretToken,
|
|
1759
|
+
tag: personification === null || personification === void 0 ? void 0 : personification.tag,
|
|
1760
|
+
pin: personification === null || personification === void 0 ? void 0 : personification.pin,
|
|
1761
|
+
continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
|
|
1762
|
+
initialContextVars: {
|
|
1763
|
+
LANG: userLang,
|
|
1764
|
+
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
1765
|
+
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) ||
|
|
1766
|
+
'',
|
|
1767
|
+
...((!chatLog
|
|
1768
|
+
? initialContextVars
|
|
1769
|
+
: chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
|
|
1770
|
+
},
|
|
1771
|
+
initialQuestion: chatLog ? undefined : initialQuestion,
|
|
1772
|
+
birthDate: birth,
|
|
1773
|
+
additionalInfo: {
|
|
1774
|
+
...(additionalInfo || {}),
|
|
1775
|
+
loginToken: resolveLoginToken(),
|
|
1776
|
+
language: ((_h = userLang !== null && userLang !== void 0 ? userLang : (_g = (_f = memori.culture) === null || _f === void 0 ? void 0 : _f.split('-')) === null || _g === void 0 ? void 0 : _g[0]) !== null && _h !== void 0 ? _h : 'IT').toLowerCase(),
|
|
1777
|
+
timeZoneOffset: new Date().getTimezoneOffset().toString(),
|
|
1778
|
+
},
|
|
1779
|
+
});
|
|
1780
|
+
if (session === null || session === void 0 ? void 0 : session.dialogState) {
|
|
1781
|
+
if (!chatLog) {
|
|
1782
|
+
setHistory([]);
|
|
1783
|
+
await translateAndSpeak(session.dialogState, userLang);
|
|
1784
|
+
setHasUserActivatedSpeak(true);
|
|
1785
|
+
setClickedStart(false);
|
|
1786
|
+
}
|
|
1787
|
+
else {
|
|
1788
|
+
const messages = chatLog.lines.map((l, i) => {
|
|
1789
|
+
var _a, _b;
|
|
1790
|
+
return ({
|
|
1791
|
+
text: l.text,
|
|
1792
|
+
media: (_b = (_a = l.media) === null || _a === void 0 ? void 0 : _a.filter(m => constants_1.allowedMediaTypes.includes(m.mimeType))) === null || _b === void 0 ? void 0 : _b.map(m => ({
|
|
1793
|
+
mediumID: `${i}-${m.mimeType}`,
|
|
1525
1794
|
...m,
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1795
|
+
})),
|
|
1796
|
+
fromUser: l.inbound,
|
|
1797
|
+
llmUsage: l.llmUsage,
|
|
1798
|
+
timestamp: l.timestamp,
|
|
1799
|
+
emitter: l.emitter,
|
|
1800
|
+
initial: i === 0,
|
|
1801
|
+
});
|
|
1802
|
+
});
|
|
1803
|
+
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1804
|
+
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1805
|
+
isMultilanguageEnabled) {
|
|
1806
|
+
try {
|
|
1807
|
+
translatedMessages = await Promise.all(messages.map(async (m) => {
|
|
1808
|
+
if ('originalText' in m && m.originalText) {
|
|
1809
|
+
return m;
|
|
1810
|
+
}
|
|
1811
|
+
return {
|
|
1812
|
+
...m,
|
|
1813
|
+
originalText: m.text,
|
|
1814
|
+
text: (await (0, translations_1.getTranslation)(m.text, userLang, language, baseUrl)).text,
|
|
1815
|
+
};
|
|
1816
|
+
}));
|
|
1817
|
+
}
|
|
1818
|
+
catch (_u) {
|
|
1819
|
+
}
|
|
1533
1820
|
}
|
|
1821
|
+
setHistory(translatedMessages);
|
|
1822
|
+
translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
|
|
1823
|
+
setHasUserActivatedSpeak(true);
|
|
1824
|
+
setClickedStart(false);
|
|
1825
|
+
});
|
|
1534
1826
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1827
|
+
}
|
|
1828
|
+
else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
|
|
1829
|
+
sessionStartingRef.current = false;
|
|
1830
|
+
await onClickStart(session || undefined);
|
|
1831
|
+
}
|
|
1832
|
+
else {
|
|
1833
|
+
setLoading(false);
|
|
1834
|
+
setClickedStart(false);
|
|
1539
1835
|
}
|
|
1540
1836
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
}
|
|
1544
|
-
else {
|
|
1545
|
-
setLoading(false);
|
|
1837
|
+
finally {
|
|
1838
|
+
sessionStartingRef.current = false;
|
|
1546
1839
|
}
|
|
1547
1840
|
return;
|
|
1548
1841
|
}
|
|
@@ -1551,9 +1844,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1551
1844
|
const { currentState, ...response } = await getSession(sessionID);
|
|
1552
1845
|
if (response.resultCode !== 0 || !currentState) {
|
|
1553
1846
|
const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
|
|
1554
|
-
setGotErrorInOpening(true);
|
|
1555
1847
|
setSessionId(undefined);
|
|
1556
|
-
setClickedStart(false);
|
|
1557
1848
|
await onClickStart(undefined, true, chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]);
|
|
1558
1849
|
return;
|
|
1559
1850
|
}
|
|
@@ -1565,21 +1856,22 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1565
1856
|
const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
|
|
1566
1857
|
if (session && session.resultCode === 0) {
|
|
1567
1858
|
await translateAndSpeak(session.currentState, userLang);
|
|
1859
|
+
setClickedStart(false);
|
|
1568
1860
|
}
|
|
1569
1861
|
else {
|
|
1570
1862
|
throw new Error('No session');
|
|
1571
1863
|
}
|
|
1572
1864
|
}
|
|
1573
|
-
catch (
|
|
1574
|
-
console.error('[onClickStart] Error changing tag:', e);
|
|
1865
|
+
catch (_v) {
|
|
1575
1866
|
reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, personification.tag, personification.pin, {
|
|
1576
1867
|
LANG: userLang,
|
|
1577
|
-
PATHNAME: (
|
|
1578
|
-
ROUTE: ((
|
|
1868
|
+
PATHNAME: (_j = window.location.pathname) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
|
|
1869
|
+
ROUTE: ((_m = (_l = (_k = window.location.pathname) === null || _k === void 0 ? void 0 : _k.split('/')) === null || _l === void 0 ? void 0 : _l.pop()) === null || _m === void 0 ? void 0 : _m.toUpperCase()) ||
|
|
1579
1870
|
'',
|
|
1580
1871
|
...(initialContextVars || {}),
|
|
1581
1872
|
}, initialQuestion, birth).then(() => {
|
|
1582
1873
|
setHasUserActivatedSpeak(true);
|
|
1874
|
+
setClickedStart(false);
|
|
1583
1875
|
});
|
|
1584
1876
|
}
|
|
1585
1877
|
}
|
|
@@ -1592,6 +1884,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1592
1884
|
const session = await changeTag(memori.engineMemoriID, sessionID, constants_1.anonTag);
|
|
1593
1885
|
if (session && session.resultCode === 0) {
|
|
1594
1886
|
await translateAndSpeak(session.currentState, userLang);
|
|
1887
|
+
setClickedStart(false);
|
|
1595
1888
|
}
|
|
1596
1889
|
else {
|
|
1597
1890
|
throw new Error('No session');
|
|
@@ -1600,19 +1893,20 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1600
1893
|
catch (e) {
|
|
1601
1894
|
reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, undefined, undefined, {
|
|
1602
1895
|
LANG: userLang,
|
|
1603
|
-
PATHNAME: (
|
|
1604
|
-
ROUTE: ((
|
|
1896
|
+
PATHNAME: (_o = window.location.pathname) === null || _o === void 0 ? void 0 : _o.toUpperCase(),
|
|
1897
|
+
ROUTE: ((_r = (_q = (_p = window.location.pathname) === null || _p === void 0 ? void 0 : _p.split('/')) === null || _q === void 0 ? void 0 : _q.pop()) === null || _r === void 0 ? void 0 : _r.toUpperCase()) ||
|
|
1605
1898
|
'',
|
|
1606
1899
|
...(initialContextVars || {}),
|
|
1607
1900
|
}, initialQuestion, birth).then(() => {
|
|
1608
1901
|
setHasUserActivatedSpeak(true);
|
|
1902
|
+
setClickedStart(false);
|
|
1609
1903
|
});
|
|
1610
1904
|
}
|
|
1611
1905
|
}
|
|
1612
1906
|
else {
|
|
1613
1907
|
try {
|
|
1614
1908
|
const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
|
|
1615
|
-
const messages = (
|
|
1909
|
+
const messages = (_s = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _s === void 0 ? void 0 : _s.lines.map((l, i) => {
|
|
1616
1910
|
var _a, _b;
|
|
1617
1911
|
return ({
|
|
1618
1912
|
text: l.text,
|
|
@@ -1637,31 +1931,28 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1637
1931
|
text: (await (0, translations_1.getTranslation)(m.text, userLang, language, baseUrl)).text,
|
|
1638
1932
|
})));
|
|
1639
1933
|
}
|
|
1640
|
-
catch (
|
|
1641
|
-
console.error('[onClickStart] Error translating messages:', e);
|
|
1934
|
+
catch (_w) {
|
|
1642
1935
|
}
|
|
1643
1936
|
}
|
|
1644
1937
|
setHistory(translatedMessages);
|
|
1645
1938
|
}
|
|
1646
|
-
catch (
|
|
1647
|
-
console.error('[onClickStart] Error retrieving chat logs:', e);
|
|
1939
|
+
catch (_x) {
|
|
1648
1940
|
}
|
|
1649
1941
|
if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
|
|
1650
1942
|
!initialQuestion) {
|
|
1651
1943
|
setHasUserActivatedSpeak(true);
|
|
1944
|
+
setClickedStart(false);
|
|
1652
1945
|
await translateAndSpeak(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length));
|
|
1653
1946
|
}
|
|
1654
1947
|
else {
|
|
1655
|
-
console.log('[onClickStart] Starting with initial question');
|
|
1656
1948
|
translatedMessages = [];
|
|
1657
1949
|
setHistory([]);
|
|
1658
|
-
setMemoriTyping(true);
|
|
1659
1950
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
1660
|
-
const response = await
|
|
1951
|
+
const response = await postEnterTextAsync({
|
|
1661
1952
|
sessionId: sessionID,
|
|
1662
1953
|
text: initialQuestion,
|
|
1663
1954
|
...(memori.needsDateTime && {
|
|
1664
|
-
dateUTC: (
|
|
1955
|
+
dateUTC: (_t = luxon_1.DateTime.utc().toISO()) !== null && _t !== void 0 ? _t : undefined,
|
|
1665
1956
|
}),
|
|
1666
1957
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
1667
1958
|
});
|
|
@@ -1677,16 +1968,34 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1677
1968
|
date: new Date().toISOString(),
|
|
1678
1969
|
},
|
|
1679
1970
|
]);
|
|
1680
|
-
setMemoriTyping(false);
|
|
1681
1971
|
return;
|
|
1682
1972
|
}
|
|
1683
|
-
|
|
1973
|
+
const onClickStartCorrelationID = readCorrelationID(response);
|
|
1974
|
+
if (response.resultCode === 0 && onClickStartCorrelationID) {
|
|
1975
|
+
setMemoriTyping(true);
|
|
1976
|
+
try {
|
|
1977
|
+
const natsEvent = await waitForEnterTextNatsResponse(onClickStartCorrelationID);
|
|
1978
|
+
if (natsEvent.resultCode === 0 && natsEvent.currentState) {
|
|
1979
|
+
await translateAndSpeak(natsEvent.currentState, userLang, undefined, false);
|
|
1980
|
+
setClickedStart(false);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
catch (err) {
|
|
1984
|
+
logWidgetError('onClickStart NATS wait failed', err);
|
|
1985
|
+
setMemoriTyping(false);
|
|
1986
|
+
setTypingText(undefined);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
else if (response.resultCode === 0) {
|
|
1990
|
+
logWidgetError('onClickStart enter-text missing correlationID', response);
|
|
1991
|
+
}
|
|
1684
1992
|
}
|
|
1685
1993
|
}
|
|
1686
1994
|
}
|
|
1687
1995
|
else {
|
|
1688
1996
|
setHistory([]);
|
|
1689
1997
|
await translateAndSpeak(dialogState, userLang);
|
|
1998
|
+
setClickedStart(false);
|
|
1690
1999
|
}
|
|
1691
2000
|
}, [memoriPwd, memori, memoriTokens, birthDate, sessionId, userLang, position]);
|
|
1692
2001
|
const setPositionPopoverOpen = (0, react_1.useCallback)((open) => {
|
|
@@ -1696,32 +2005,52 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1696
2005
|
}
|
|
1697
2006
|
}, [autoStart, onClickStart]);
|
|
1698
2007
|
(0, react_1.useEffect)(() => {
|
|
1699
|
-
if (!clickedStart &&
|
|
2008
|
+
if (!clickedStart &&
|
|
2009
|
+
!sessionStartingRef.current &&
|
|
2010
|
+
!sessionId &&
|
|
2011
|
+
autoStart &&
|
|
2012
|
+
selectedLayout !== 'HIDDEN_CHAT' &&
|
|
2013
|
+
(!needsCredits || hasEnoughCredits)) {
|
|
1700
2014
|
onClickStart();
|
|
1701
2015
|
}
|
|
1702
|
-
}, [
|
|
2016
|
+
}, [
|
|
2017
|
+
clickedStart,
|
|
2018
|
+
autoStart,
|
|
2019
|
+
selectedLayout,
|
|
2020
|
+
sessionId,
|
|
2021
|
+
needsCredits,
|
|
2022
|
+
hasEnoughCredits,
|
|
2023
|
+
]);
|
|
1703
2024
|
(0, react_1.useEffect)(() => {
|
|
2025
|
+
var _a;
|
|
1704
2026
|
const targetNode = document.querySelector(`memori-client[memoriname="${memori.name}"]`) ||
|
|
1705
2027
|
document.querySelector(`memori-client[memoriid="${memori.memoriID}"]`) ||
|
|
1706
2028
|
document.querySelector('memori-client');
|
|
1707
2029
|
if (!targetNode) {
|
|
1708
2030
|
return;
|
|
1709
2031
|
}
|
|
2032
|
+
const propsToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
|
|
2033
|
+
const initialDomToken = targetNode.getAttribute('authtoken') || undefined;
|
|
2034
|
+
if (initialDomToken && !propsToken) {
|
|
2035
|
+
setLoginToken(initialDomToken);
|
|
2036
|
+
userTokenRef.current = initialDomToken;
|
|
2037
|
+
}
|
|
2038
|
+
const applyAuthTokenFromElement = (element) => {
|
|
2039
|
+
var _a;
|
|
2040
|
+
const clientNode = element.nodeName === 'MEMORI-CLIENT'
|
|
2041
|
+
? element
|
|
2042
|
+
: (_a = element.closest('memori-client')) !== null && _a !== void 0 ? _a : element.parentElement;
|
|
2043
|
+
const token = (clientNode === null || clientNode === void 0 ? void 0 : clientNode.getAttribute('authtoken')) || undefined;
|
|
2044
|
+
setLoginToken(token);
|
|
2045
|
+
userTokenRef.current = token;
|
|
2046
|
+
};
|
|
1710
2047
|
const config = { attributes: true, childList: false, subtree: false };
|
|
1711
|
-
const callback =
|
|
1712
|
-
var _a
|
|
2048
|
+
const callback = mutationList => {
|
|
2049
|
+
var _a;
|
|
1713
2050
|
for (const mutation of mutationList) {
|
|
1714
2051
|
if (mutation.type === 'attributes' &&
|
|
1715
2052
|
((_a = mutation.attributeName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authtoken') {
|
|
1716
|
-
|
|
1717
|
-
setLoginToken(mutation.target.getAttribute('authtoken') || undefined);
|
|
1718
|
-
userToken = mutation.target.getAttribute('authtoken') || undefined;
|
|
1719
|
-
}
|
|
1720
|
-
else {
|
|
1721
|
-
setLoginToken(((_c = (_b = mutation.target) === null || _b === void 0 ? void 0 : _b.parentElement) === null || _c === void 0 ? void 0 : _c.getAttribute('authtoken')) ||
|
|
1722
|
-
undefined);
|
|
1723
|
-
userToken = mutation.target.getAttribute('authtoken') || undefined;
|
|
1724
|
-
}
|
|
2053
|
+
applyAuthTokenFromElement(mutation.target);
|
|
1725
2054
|
}
|
|
1726
2055
|
}
|
|
1727
2056
|
};
|
|
@@ -1730,7 +2059,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1730
2059
|
return () => {
|
|
1731
2060
|
observer.disconnect();
|
|
1732
2061
|
};
|
|
1733
|
-
}, []);
|
|
2062
|
+
}, [memori.name, memori.memoriID, additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
|
|
1734
2063
|
const [experts, setExperts] = (0, react_1.useState)();
|
|
1735
2064
|
const fetchExperts = (0, react_1.useCallback)(async () => {
|
|
1736
2065
|
if (!sessionId || !(memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts))
|
|
@@ -1740,12 +2069,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1740
2069
|
if (resp.resultCode === 0) {
|
|
1741
2070
|
setExperts(experts);
|
|
1742
2071
|
}
|
|
1743
|
-
else {
|
|
1744
|
-
console.warn('Error fetching experts', resp);
|
|
1745
|
-
}
|
|
1746
2072
|
}
|
|
1747
|
-
catch (
|
|
1748
|
-
console.warn(err);
|
|
2073
|
+
catch (_a) {
|
|
1749
2074
|
}
|
|
1750
2075
|
}, [sessionId, memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts]);
|
|
1751
2076
|
(0, react_1.useEffect)(() => {
|
|
@@ -1755,11 +2080,26 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1755
2080
|
!!loginToken &&
|
|
1756
2081
|
!!(user === null || user === void 0 ? void 0 : user.userID) &&
|
|
1757
2082
|
(user === null || user === void 0 ? void 0 : user.pAndCUAccepted);
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1760
|
-
|
|
2083
|
+
const handleNotEnoughCredits = (0, react_1.useCallback)(() => {
|
|
2084
|
+
setHasEnoughCredits(false);
|
|
2085
|
+
setAuthModalState(null);
|
|
2086
|
+
add((0, ui_1.createAlertOptions)({
|
|
2087
|
+
description: t('notEnoughCredits'),
|
|
2088
|
+
severity: 'error',
|
|
2089
|
+
}));
|
|
2090
|
+
}, [add, t]);
|
|
2091
|
+
const checkCredits = (0, react_1.useCallback)(async (options) => {
|
|
1761
2092
|
if (!(tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation))
|
|
1762
|
-
return;
|
|
2093
|
+
return true;
|
|
2094
|
+
if (!ownerUserID && !ownerUserName) {
|
|
2095
|
+
if (options === null || options === void 0 ? void 0 : options.notify) {
|
|
2096
|
+
handleNotEnoughCredits();
|
|
2097
|
+
}
|
|
2098
|
+
else {
|
|
2099
|
+
setHasEnoughCredits(false);
|
|
2100
|
+
}
|
|
2101
|
+
return false;
|
|
2102
|
+
}
|
|
1763
2103
|
try {
|
|
1764
2104
|
const resp = await (0, credits_1.getCredits)({
|
|
1765
2105
|
operation: deepThoughtEnabled
|
|
@@ -1772,22 +2112,36 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1772
2112
|
});
|
|
1773
2113
|
if (resp.enough) {
|
|
1774
2114
|
setHasEnoughCredits(true);
|
|
2115
|
+
return true;
|
|
1775
2116
|
}
|
|
1776
2117
|
else {
|
|
1777
|
-
|
|
1778
|
-
|
|
2118
|
+
if (options === null || options === void 0 ? void 0 : options.notify) {
|
|
2119
|
+
handleNotEnoughCredits();
|
|
2120
|
+
}
|
|
2121
|
+
else {
|
|
2122
|
+
setHasEnoughCredits(false);
|
|
2123
|
+
}
|
|
2124
|
+
return false;
|
|
1779
2125
|
}
|
|
1780
2126
|
}
|
|
1781
|
-
catch (
|
|
1782
|
-
|
|
1783
|
-
|
|
2127
|
+
catch (err) {
|
|
2128
|
+
logWidgetError('checkCredits failed', err);
|
|
2129
|
+
return true;
|
|
1784
2130
|
}
|
|
1785
|
-
}, [
|
|
2131
|
+
}, [
|
|
2132
|
+
baseUrl,
|
|
2133
|
+
deepThoughtEnabled,
|
|
2134
|
+
handleNotEnoughCredits,
|
|
2135
|
+
ownerUserID,
|
|
2136
|
+
ownerUserName,
|
|
2137
|
+
tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation,
|
|
2138
|
+
tenantID,
|
|
2139
|
+
]);
|
|
1786
2140
|
(0, react_1.useEffect)(() => {
|
|
1787
2141
|
if (tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation) {
|
|
1788
2142
|
checkCredits();
|
|
1789
2143
|
}
|
|
1790
|
-
}, [tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation, deepThoughtEnabled]);
|
|
2144
|
+
}, [tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation, deepThoughtEnabled, checkCredits]);
|
|
1791
2145
|
(0, react_1.useEffect)(() => {
|
|
1792
2146
|
if (__WEBCOMPONENT__)
|
|
1793
2147
|
return;
|
|
@@ -1806,16 +2160,16 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1806
2160
|
? selectedLayout !== 'TOTEM' && selectedLayout !== 'WEBSITE_ASSISTANT'
|
|
1807
2161
|
: !showOnlyLastMessages;
|
|
1808
2162
|
const canShowLoginButton = !(tenant === null || tenant === void 0 ? void 0 : tenant.ssoLogin) &&
|
|
1809
|
-
((
|
|
2163
|
+
((_y = showLogin !== null && showLogin !== void 0 ? showLogin : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showLogin) !== null && _y !== void 0 ? _y : memori.requireLoginToken);
|
|
1810
2164
|
const headerProps = {
|
|
1811
2165
|
memori: {
|
|
1812
2166
|
...memori,
|
|
1813
|
-
ownerUserID: (
|
|
2167
|
+
ownerUserID: (_0 = (_z = memori.ownerUserID) !== null && _z !== void 0 ? _z : ownerUserID) !== null && _0 !== void 0 ? _0 : undefined,
|
|
1814
2168
|
},
|
|
1815
2169
|
apiClient: client,
|
|
1816
2170
|
tenant,
|
|
1817
2171
|
history,
|
|
1818
|
-
showShare: (
|
|
2172
|
+
showShare: (_1 = showShare !== null && showShare !== void 0 ? showShare : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showShare) !== null && _1 !== void 0 ? _1 : true,
|
|
1819
2173
|
position,
|
|
1820
2174
|
layout: selectedLayout,
|
|
1821
2175
|
additionalSettings,
|
|
@@ -1825,18 +2179,18 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1825
2179
|
setShowSettingsDrawer,
|
|
1826
2180
|
setShowKnownFactsDrawer,
|
|
1827
2181
|
setShowExpertsDrawer,
|
|
1828
|
-
enableAudio: (
|
|
2182
|
+
enableAudio: (_2 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _2 !== void 0 ? _2 : true,
|
|
1829
2183
|
speakerMuted: speakerMuted !== null && speakerMuted !== void 0 ? speakerMuted : false,
|
|
1830
2184
|
setSpeakerMuted: (mute) => {
|
|
1831
2185
|
toggleMute(mute);
|
|
1832
2186
|
},
|
|
1833
2187
|
setShowChatHistoryDrawer,
|
|
1834
|
-
showSettings: (
|
|
1835
|
-
showChatHistory: (
|
|
2188
|
+
showSettings: (_3 = showSettings !== null && showSettings !== void 0 ? showSettings : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showSettings) !== null && _3 !== void 0 ? _3 : true,
|
|
2189
|
+
showChatHistory: (_4 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _4 !== void 0 ? _4 : true,
|
|
1836
2190
|
showMessageConsumption: enableMessageConsumption,
|
|
1837
2191
|
hasUserActivatedSpeak,
|
|
1838
2192
|
showReload: selectedLayout === 'TOTEM',
|
|
1839
|
-
showClear: (
|
|
2193
|
+
showClear: (_5 = showClear !== null && showClear !== void 0 ? showClear : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showClear) !== null && _5 !== void 0 ? _5 : false,
|
|
1840
2194
|
clearHistory: () => setHistory(h => h.slice(-1)),
|
|
1841
2195
|
showLogin: canShowLoginButton,
|
|
1842
2196
|
setShowLoginDrawer,
|
|
@@ -1851,7 +2205,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1851
2205
|
setShowLoginDrawer(false);
|
|
1852
2206
|
setUser(undefined);
|
|
1853
2207
|
setLoginToken(undefined);
|
|
1854
|
-
|
|
2208
|
+
userTokenRef.current = undefined;
|
|
1855
2209
|
(0, configuration_1.removeLocalConfig)('loginToken');
|
|
1856
2210
|
});
|
|
1857
2211
|
},
|
|
@@ -1867,7 +2221,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1867
2221
|
hasUserActivatedSpeak,
|
|
1868
2222
|
isPlayingAudio: isPlayingAudio &&
|
|
1869
2223
|
!speakerMuted &&
|
|
1870
|
-
((
|
|
2224
|
+
((_6 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _6 !== void 0 ? _6 : true),
|
|
1871
2225
|
loading: !!memoriTyping,
|
|
1872
2226
|
baseUrl,
|
|
1873
2227
|
apiUrl: client.constants.BACKEND_URL,
|
|
@@ -1897,7 +2251,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1897
2251
|
notEnoughCredits: needsCredits && !hasEnoughCredits,
|
|
1898
2252
|
showLogin: canShowLoginButton,
|
|
1899
2253
|
setShowLoginDrawer,
|
|
1900
|
-
showChatHistory: (
|
|
2254
|
+
showChatHistory: (_7 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _7 !== void 0 ? _7 : true,
|
|
1901
2255
|
setShowChatHistoryDrawer,
|
|
1902
2256
|
user,
|
|
1903
2257
|
};
|
|
@@ -1907,7 +2261,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1907
2261
|
tenant,
|
|
1908
2262
|
translateTo: isMultilanguageEnabled &&
|
|
1909
2263
|
userLang.toUpperCase() !==
|
|
1910
|
-
((
|
|
2264
|
+
((_12 = ((_11 = (_10 = (_9 = (_8 = memori.culture) === null || _8 === void 0 ? void 0 : _8.split('-')) === null || _9 === void 0 ? void 0 : _9[0]) !== null && _10 !== void 0 ? _10 : i18n.language) !== null && _11 !== void 0 ? _11 : 'IT')) === null || _12 === void 0 ? void 0 : _12.toUpperCase())
|
|
1911
2265
|
? userLang
|
|
1912
2266
|
: undefined,
|
|
1913
2267
|
baseUrl,
|
|
@@ -1915,9 +2269,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1915
2269
|
layout,
|
|
1916
2270
|
memoriTyping,
|
|
1917
2271
|
typingText,
|
|
1918
|
-
showTypingText: (
|
|
2272
|
+
showTypingText: (_13 = showTypingText !== null && showTypingText !== void 0 ? showTypingText : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showTypingText) !== null && _13 !== void 0 ? _13 : false,
|
|
1919
2273
|
history: showFullHistory ? history : history.slice(-2),
|
|
1920
|
-
authToken: (
|
|
2274
|
+
authToken: resolveLoginToken(),
|
|
1921
2275
|
dialogState: currentDialogState,
|
|
1922
2276
|
pushMessage,
|
|
1923
2277
|
simulateUserPrompt,
|
|
@@ -1990,7 +2344,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1990
2344
|
: FullPage_1.default;
|
|
1991
2345
|
const widgetTheme = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'light' || (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'dark'
|
|
1992
2346
|
? integrationConfig.theme
|
|
1993
|
-
:
|
|
2347
|
+
: isDarkTheme
|
|
2348
|
+
? 'dark'
|
|
2349
|
+
: undefined;
|
|
1994
2350
|
return ((0, jsx_runtime_1.jsx)("div", { ref: setWidgetRootEl, className: (0, classnames_1.default)('memori', 'memori-widget', `memori-layout-${String(selectedLayout).toLowerCase()}`, `memori-controls-${String(controlsPosition).toLowerCase()}`, `memori--avatar-${(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.avatar) || 'default'}`, {
|
|
1995
2351
|
'memori--auto-start': autoStart,
|
|
1996
2352
|
'memori--preview': preview,
|
|
@@ -2003,132 +2359,132 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
2003
2359
|
}), "data-theme": widgetTheme, "data-memori-name": memori === null || memori === void 0 ? void 0 : memori.name, "data-memori-id": memori === null || memori === void 0 ? void 0 : memori.engineMemoriID, "data-memori-secondary-id": memori === null || memori === void 0 ? void 0 : memori.memoriID, "data-memori-session-id": sessionId, "data-memori-integration": integration === null || integration === void 0 ? void 0 : integration.integrationID, "data-memori-engine-state": JSON.stringify({
|
|
2004
2360
|
...currentDialogState,
|
|
2005
2361
|
sessionID: sessionId,
|
|
2006
|
-
}), style: { height }, children: (0, jsx_runtime_1.
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
});
|
|
2019
|
-
} }), (0, jsx_runtime_1.jsx)("audio", { id: "memori-audio", style: { display: 'none' }, src: "https://aisuru.com/intro.mp3" }), isClient && ((0, jsx_runtime_1.jsx)(Auth_1.default, { withModal: true, pwdOrTokens: authModalState, openModal: !!authModalState, setPwdOrTokens: setAuthModalState, showTokens: memori.privacyType === 'SECRET', onFinish: (values) => {
|
|
2020
|
-
var _a, _b, _c, _d;
|
|
2021
|
-
if (values['password'])
|
|
2022
|
-
setMemoriPwd(values['password']);
|
|
2023
|
-
if (values['password'])
|
|
2024
|
-
memoriPassword = values['password'];
|
|
2025
|
-
if (values['tokens'])
|
|
2026
|
-
setMemoriTokens(values['tokens']);
|
|
2027
|
-
return reopenSession(!sessionId, values['password'], values['tokens'], personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2028
|
-
LANG: userLang,
|
|
2029
|
-
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2030
|
-
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2031
|
-
...(initialContextVars || {}),
|
|
2032
|
-
}, initialQuestion, birthDate)
|
|
2033
|
-
.then(state => {
|
|
2034
|
-
if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
|
|
2035
|
-
throw new Error('AUTH_FAILED');
|
|
2036
|
-
}
|
|
2037
|
-
setAuthModalState(null);
|
|
2038
|
-
if (state === null || state === void 0 ? void 0 : state.dialogState) {
|
|
2039
|
-
setHasUserActivatedSpeak(true);
|
|
2040
|
-
}
|
|
2041
|
-
else {
|
|
2042
|
-
onClickStart(state);
|
|
2043
|
-
}
|
|
2044
|
-
})
|
|
2045
|
-
.catch(error => {
|
|
2046
|
-
if (!(error instanceof Error) ||
|
|
2047
|
-
error.message !== 'AUTH_FAILED') {
|
|
2048
|
-
setGotErrorInOpening(true);
|
|
2049
|
-
}
|
|
2050
|
-
throw error;
|
|
2051
|
-
});
|
|
2052
|
-
}, minimumNumberOfRecoveryTokens: (_17 = memori === null || memori === void 0 ? void 0 : memori.minimumNumberOfRecoveryTokens) !== null && _17 !== void 0 ? _17 : 1 })), isClient && ((0, jsx_runtime_1.jsx)(AgeVerificationModal_1.default, { visible: showAgeVerification, minAge: minAge, onClose: birthDate => {
|
|
2053
|
-
var _a, _b, _c, _d;
|
|
2054
|
-
if (birthDate) {
|
|
2055
|
-
setBirthDate(birthDate);
|
|
2056
|
-
(0, configuration_1.setLocalConfig)('birthDate', birthDate);
|
|
2057
|
-
reopenSession(!sessionId, memoriPassword || memoriPwd || (memori === null || memori === void 0 ? void 0 : memori.secretToken), memoriTokens, personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2058
|
-
LANG: userLang,
|
|
2059
|
-
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2060
|
-
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2061
|
-
...(initialContextVars || {}),
|
|
2062
|
-
}, initialQuestion, birthDate)
|
|
2063
|
-
.then(state => {
|
|
2064
|
-
setShowAgeVerification(false);
|
|
2065
|
-
setAuthModalState(null);
|
|
2066
|
-
onClickStart(state || undefined);
|
|
2067
|
-
})
|
|
2068
|
-
.catch(() => {
|
|
2069
|
-
setShowAgeVerification(false);
|
|
2070
|
-
setGotErrorInOpening(true);
|
|
2071
|
-
});
|
|
2072
|
-
}
|
|
2073
|
-
else {
|
|
2074
|
-
setShowAgeVerification(false);
|
|
2075
|
-
setClickedStart(false);
|
|
2076
|
-
}
|
|
2077
|
-
} })), showSettingsDrawer && ((0, jsx_runtime_1.jsx)(SettingsDrawer_1.default, { layout: selectedLayout, open: !!showSettingsDrawer, onClose: () => setShowSettingsDrawer(false), microphoneMode: continuousSpeech ? 'CONTINUOUS' : 'HOLD_TO_TALK', continuousSpeechTimeout: continuousSpeechTimeout, setMicrophoneMode: mode => setContinuousSpeech(mode === 'CONTINUOUS'), setContinuousSpeechTimeout: setContinuousSpeechTimeout, controlsPosition: controlsPosition, setControlsPosition: setControlsPosition, hideEmissions: hideEmissions, setHideEmissions: setHideEmissions, avatarType: avatarType, setAvatarType: setAvatarType, enablePositionControls: enablePositionControls, setEnablePositionControls: setEnablePositionControls, isAvatar3d: !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.avatarURL), additionalSettings: additionalSettings, speakerMuted: speakerMuted })), showChatHistoryDrawer && ((0, jsx_runtime_1.jsx)(ChatHistory_1.default, { open: !!showChatHistoryDrawer, onClose: () => setShowChatHistoryDrawer(false), resumeSession: chatLog => {
|
|
2078
|
-
setChatLogID(chatLog.chatLogID);
|
|
2079
|
-
onClickStart(undefined, false, chatLog);
|
|
2080
|
-
setShowChatHistoryDrawer(false);
|
|
2081
|
-
}, apiClient: client, sessionId: sessionId || '', memori: memori, baseUrl: baseUrl, history: history, apiUrl: client.constants.BACKEND_URL, loginToken: loginToken, language: language, userLang: userLang, isMultilanguageEnabled: isMultilanguageEnabled })), showKnownFactsDrawer && sessionId && ((0, jsx_runtime_1.jsx)(KnownFacts_1.default, { apiClient: client, memori: memori, sessionID: sessionId, visible: showKnownFactsDrawer, closeDrawer: () => setShowKnownFactsDrawer(false) })), showExpertsDrawer && !!experts && ((0, jsx_runtime_1.jsx)(ExpertsDrawer_1.default, { apiUrl: client.constants.BACKEND_URL, baseUrl: baseUrl, tenant: tenant, experts: experts, open: showExpertsDrawer, onClose: () => setShowExpertsDrawer(false) })), showLoginDrawer && (tenant === null || tenant === void 0 ? void 0 : tenant.name) && ((0, jsx_runtime_1.jsx)(LoginDrawer_1.default, { tenant: tenant, apiClient: client, open: !!showLoginDrawer, user: user, loginToken: loginToken, onClose: () => setShowLoginDrawer(false), drawerClassName: selectedLayout === 'WEBSITE_ASSISTANT'
|
|
2082
|
-
? 'memori-drawer--above-website-assistant'
|
|
2083
|
-
: undefined, onLogin: (user, token) => {
|
|
2084
|
-
var _a, _b, _c, _d;
|
|
2085
|
-
reopenSession(false, memoriPassword || memoriPwd || (memori === null || memori === void 0 ? void 0 : memori.secretToken), [], personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2086
|
-
LANG: userLang,
|
|
2087
|
-
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2088
|
-
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2089
|
-
...(initialContextVars || {}),
|
|
2090
|
-
}, undefined, birthDate, { loginToken: token }, undefined, sessionId).then(state => {
|
|
2091
|
-
var _a, _b;
|
|
2092
|
-
setShowLoginDrawer(false);
|
|
2093
|
-
setUser(user);
|
|
2094
|
-
setLoginToken(token);
|
|
2095
|
-
userToken = token;
|
|
2096
|
-
(0, configuration_1.setLocalConfig)('loginToken', token);
|
|
2097
|
-
if ((state === null || state === void 0 ? void 0 : state.sessionID) &&
|
|
2098
|
-
state.sessionID !== sessionId &&
|
|
2099
|
-
(state === null || state === void 0 ? void 0 : state.dialogState)) {
|
|
2100
|
-
const username = (user === null || user === void 0 ? void 0 : user.userName) || t('login.user');
|
|
2101
|
-
pushMessage({
|
|
2102
|
-
text: '',
|
|
2103
|
-
emitter: state.dialogState.emitter,
|
|
2104
|
-
media: (_b = (_a = state.dialogState.emittedMedia) !== null && _a !== void 0 ? _a : state.dialogState.media) !== null && _b !== void 0 ? _b : [],
|
|
2105
|
-
fromUser: false,
|
|
2106
|
-
initial: t('login.successfullyLoggedIn', {
|
|
2107
|
-
username,
|
|
2108
|
-
}),
|
|
2109
|
-
contextVars: state.dialogState.contextVars,
|
|
2110
|
-
date: state.dialogState.currentDate,
|
|
2111
|
-
placeName: state.dialogState.currentPlaceName,
|
|
2112
|
-
placeLatitude: state.dialogState.currentLatitude,
|
|
2113
|
-
placeLongitude: state.dialogState.currentLongitude,
|
|
2114
|
-
placeUncertaintyKm: state.dialogState.currentUncertaintyKm,
|
|
2115
|
-
tag: state.dialogState.currentTag,
|
|
2116
|
-
memoryTags: state.dialogState.memoryTags,
|
|
2362
|
+
}), style: { height }, children: (0, jsx_runtime_1.jsx)(ui_1.MemoriUIProvider, { container: widgetRootEl, theme: widgetTheme, children: (0, jsx_runtime_1.jsx)(widgetSurfaceContext_1.WidgetSurfaceProvider, { value: widgetSurfaceEl, children: (0, jsx_runtime_1.jsxs)("div", { ref: setWidgetSurfaceEl, className: "memori-widget__surface", children: [(0, jsx_runtime_1.jsx)(Layout, { Header: Header_1.default, headerProps: headerProps, Avatar: Avatar_1.default, avatarProps: avatarProps, Chat: Chat_1.default, chatProps: chatProps, StartPanel: StartPanel_1.default, startPanelProps: startPanelProps, integrationStyle: integrationStyle, integrationBackground: integrationBackground, poweredBy: poweredBy, autoStart: autoStart, sessionId: sessionId, hasUserActivatedSpeak: hasUserActivatedSpeak, loading: loading, avatar3dHidden: avatar3dHidden !== null && avatar3dHidden !== void 0 ? avatar3dHidden : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.avatar_3d_hidden }), (0, jsx_runtime_1.jsx)(ArtifactAPI_1.ArtifactAPIBridge, { pushMessage: (message) => {
|
|
2363
|
+
setHistory(history => {
|
|
2364
|
+
if (!history.length)
|
|
2365
|
+
return history;
|
|
2366
|
+
const lastMessage = history[history.length - 1];
|
|
2367
|
+
if (!lastMessage || lastMessage.fromUser)
|
|
2368
|
+
return history;
|
|
2369
|
+
const updatedLastMessage = {
|
|
2370
|
+
...lastMessage,
|
|
2371
|
+
text: lastMessage.text + message.text,
|
|
2372
|
+
};
|
|
2373
|
+
return [...history.slice(0, -1), updatedLastMessage];
|
|
2117
2374
|
});
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2375
|
+
} }), (0, jsx_runtime_1.jsx)("audio", { id: "memori-audio", style: { display: 'none' }, src: "https://aisuru.com/intro.mp3" }), isClient && ((0, jsx_runtime_1.jsx)(Auth_1.default, { withModal: true, pwdOrTokens: authModalState, openModal: !!authModalState, setPwdOrTokens: setAuthModalState, showTokens: memori.privacyType === 'SECRET', onFinish: (values) => {
|
|
2376
|
+
var _a, _b, _c, _d;
|
|
2377
|
+
if (values['password'])
|
|
2378
|
+
setMemoriPwd(values['password']);
|
|
2379
|
+
if (values['password'])
|
|
2380
|
+
memoriPassword = values['password'];
|
|
2381
|
+
if (values['tokens'])
|
|
2382
|
+
setMemoriTokens(values['tokens']);
|
|
2383
|
+
return reopenSession(!sessionId, values['password'], values['tokens'], personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2384
|
+
LANG: userLang,
|
|
2385
|
+
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2386
|
+
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2387
|
+
...(initialContextVars || {}),
|
|
2388
|
+
}, initialQuestion, birthDate)
|
|
2389
|
+
.then(state => {
|
|
2390
|
+
if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
|
|
2391
|
+
throw new Error('AUTH_FAILED');
|
|
2392
|
+
}
|
|
2393
|
+
setAuthModalState(null);
|
|
2394
|
+
if (state === null || state === void 0 ? void 0 : state.dialogState) {
|
|
2395
|
+
setHasUserActivatedSpeak(true);
|
|
2396
|
+
}
|
|
2397
|
+
else {
|
|
2398
|
+
onClickStart(state);
|
|
2399
|
+
}
|
|
2400
|
+
})
|
|
2401
|
+
.catch(error => {
|
|
2402
|
+
if (!(error instanceof Error) ||
|
|
2403
|
+
error.message !== 'AUTH_FAILED') {
|
|
2404
|
+
setGotErrorInOpening(true);
|
|
2405
|
+
}
|
|
2406
|
+
throw error;
|
|
2407
|
+
});
|
|
2408
|
+
}, minimumNumberOfRecoveryTokens: (_17 = memori === null || memori === void 0 ? void 0 : memori.minimumNumberOfRecoveryTokens) !== null && _17 !== void 0 ? _17 : 1 })), isClient && ((0, jsx_runtime_1.jsx)(AgeVerificationModal_1.default, { visible: showAgeVerification, minAge: minAge, onClose: birthDate => {
|
|
2409
|
+
var _a, _b, _c, _d;
|
|
2410
|
+
if (birthDate) {
|
|
2411
|
+
setBirthDate(birthDate);
|
|
2412
|
+
(0, configuration_1.setLocalConfig)('birthDate', birthDate);
|
|
2413
|
+
reopenSession(!sessionId, memoriPassword || memoriPwd || (memori === null || memori === void 0 ? void 0 : memori.secretToken), memoriTokens, personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2414
|
+
LANG: userLang,
|
|
2415
|
+
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2416
|
+
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2417
|
+
...(initialContextVars || {}),
|
|
2418
|
+
}, initialQuestion, birthDate)
|
|
2419
|
+
.then(state => {
|
|
2420
|
+
setShowAgeVerification(false);
|
|
2421
|
+
setAuthModalState(null);
|
|
2422
|
+
onClickStart(state || undefined);
|
|
2423
|
+
})
|
|
2424
|
+
.catch(() => {
|
|
2425
|
+
setShowAgeVerification(false);
|
|
2426
|
+
setGotErrorInOpening(true);
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
else {
|
|
2430
|
+
setShowAgeVerification(false);
|
|
2431
|
+
setClickedStart(false);
|
|
2432
|
+
}
|
|
2433
|
+
} })), showSettingsDrawer && ((0, jsx_runtime_1.jsx)(SettingsDrawer_1.default, { layout: selectedLayout, open: !!showSettingsDrawer, onClose: () => setShowSettingsDrawer(false), microphoneMode: continuousSpeech ? 'CONTINUOUS' : 'HOLD_TO_TALK', continuousSpeechTimeout: continuousSpeechTimeout, setMicrophoneMode: mode => setContinuousSpeech(mode === 'CONTINUOUS'), setContinuousSpeechTimeout: setContinuousSpeechTimeout, controlsPosition: controlsPosition, setControlsPosition: setControlsPosition, hideEmissions: hideEmissions, setHideEmissions: setHideEmissions, avatarType: avatarType, setAvatarType: setAvatarType, enablePositionControls: enablePositionControls, setEnablePositionControls: setEnablePositionControls, isAvatar3d: !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.avatarURL), additionalSettings: additionalSettings, speakerMuted: speakerMuted })), showChatHistoryDrawer && ((0, jsx_runtime_1.jsx)(ChatHistory_1.default, { open: !!showChatHistoryDrawer, onClose: () => setShowChatHistoryDrawer(false), resumeSession: chatLog => {
|
|
2434
|
+
setChatLogID(chatLog.chatLogID);
|
|
2435
|
+
onClickStart(undefined, false, chatLog);
|
|
2436
|
+
setShowChatHistoryDrawer(false);
|
|
2437
|
+
}, apiClient: client, sessionId: sessionId || '', memori: memori, baseUrl: baseUrl, history: history, apiUrl: client.constants.BACKEND_URL, loginToken: loginToken, language: language, userLang: userLang, isMultilanguageEnabled: isMultilanguageEnabled })), showKnownFactsDrawer && sessionId && ((0, jsx_runtime_1.jsx)(KnownFacts_1.default, { apiClient: client, memori: memori, sessionID: sessionId, visible: showKnownFactsDrawer, closeDrawer: () => setShowKnownFactsDrawer(false) })), showExpertsDrawer && !!experts && ((0, jsx_runtime_1.jsx)(ExpertsDrawer_1.default, { apiUrl: client.constants.BACKEND_URL, baseUrl: baseUrl, tenant: tenant, experts: experts, open: showExpertsDrawer, onClose: () => setShowExpertsDrawer(false) })), showLoginDrawer && (tenant === null || tenant === void 0 ? void 0 : tenant.name) && ((0, jsx_runtime_1.jsx)(LoginDrawer_1.default, { tenant: tenant, apiClient: client, open: !!showLoginDrawer, user: user, loginToken: loginToken, onClose: () => setShowLoginDrawer(false), drawerClassName: selectedLayout === 'WEBSITE_ASSISTANT'
|
|
2438
|
+
? 'memori-drawer--above-website-assistant'
|
|
2439
|
+
: undefined, onLogin: (user, token) => {
|
|
2440
|
+
var _a, _b, _c, _d;
|
|
2441
|
+
reopenSession(false, memoriPassword || memoriPwd || (memori === null || memori === void 0 ? void 0 : memori.secretToken), [], personification === null || personification === void 0 ? void 0 : personification.tag, personification === null || personification === void 0 ? void 0 : personification.pin, {
|
|
2442
|
+
LANG: userLang,
|
|
2443
|
+
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
2444
|
+
ROUTE: ((_d = (_c = (_b = window.location.pathname) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop()) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || '',
|
|
2445
|
+
...(initialContextVars || {}),
|
|
2446
|
+
}, undefined, birthDate, { loginToken: token }, undefined, sessionId).then(state => {
|
|
2447
|
+
var _a, _b;
|
|
2448
|
+
setShowLoginDrawer(false);
|
|
2449
|
+
setUser(user);
|
|
2450
|
+
setLoginToken(token);
|
|
2451
|
+
userTokenRef.current = token;
|
|
2452
|
+
(0, configuration_1.setLocalConfig)('loginToken', token);
|
|
2453
|
+
if ((state === null || state === void 0 ? void 0 : state.sessionID) &&
|
|
2454
|
+
state.sessionID !== sessionId &&
|
|
2455
|
+
(state === null || state === void 0 ? void 0 : state.dialogState)) {
|
|
2456
|
+
const username = (user === null || user === void 0 ? void 0 : user.userName) || t('login.user');
|
|
2457
|
+
pushMessage({
|
|
2458
|
+
text: '',
|
|
2459
|
+
emitter: state.dialogState.emitter,
|
|
2460
|
+
media: (_b = (_a = state.dialogState.emittedMedia) !== null && _a !== void 0 ? _a : state.dialogState.media) !== null && _b !== void 0 ? _b : [],
|
|
2461
|
+
fromUser: false,
|
|
2462
|
+
initial: t('login.successfullyLoggedIn', {
|
|
2463
|
+
username,
|
|
2464
|
+
}),
|
|
2465
|
+
contextVars: state.dialogState.contextVars,
|
|
2466
|
+
date: state.dialogState.currentDate,
|
|
2467
|
+
placeName: state.dialogState.currentPlaceName,
|
|
2468
|
+
placeLatitude: state.dialogState.currentLatitude,
|
|
2469
|
+
placeLongitude: state.dialogState.currentLongitude,
|
|
2470
|
+
placeUncertaintyKm: state.dialogState.currentUncertaintyKm,
|
|
2471
|
+
tag: state.dialogState.currentTag,
|
|
2472
|
+
memoryTags: state.dialogState.memoryTags,
|
|
2473
|
+
});
|
|
2474
|
+
setCurrentDialogState(state.dialogState);
|
|
2475
|
+
}
|
|
2476
|
+
});
|
|
2477
|
+
}, setUser: setUser, onLogout: () => {
|
|
2478
|
+
if (!loginToken)
|
|
2479
|
+
return;
|
|
2480
|
+
client.backend.pwlUserLogout(loginToken).then(() => {
|
|
2481
|
+
setShowLoginDrawer(false);
|
|
2482
|
+
setUser(undefined);
|
|
2483
|
+
setLoginToken(undefined);
|
|
2484
|
+
userTokenRef.current = undefined;
|
|
2485
|
+
(0, configuration_1.removeLocalConfig)('loginToken');
|
|
2486
|
+
});
|
|
2487
|
+
} }))] }) }) }) }));
|
|
2132
2488
|
};
|
|
2133
2489
|
exports.default = MemoriWidget;
|
|
2134
2490
|
//# sourceMappingURL=MemoriWidget.js.map
|