@memori.ai/memori-react 8.41.3 → 8.41.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
  3. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  4. package/dist/components/FilePreview/FilePreview.js +1 -3
  5. package/dist/components/FilePreview/FilePreview.js.map +1 -1
  6. package/dist/components/MediaWidget/MediaItemWidget.js +1 -3
  7. package/dist/components/MediaWidget/MediaItemWidget.js.map +1 -1
  8. package/dist/components/MediaWidget/MediaPreviewModal.js +2 -6
  9. package/dist/components/MediaWidget/MediaPreviewModal.js.map +1 -1
  10. package/dist/components/MemoriArtifactSystem/utils/applyEdits.d.ts +8 -0
  11. package/dist/components/MemoriArtifactSystem/utils/applyEdits.js +117 -0
  12. package/dist/components/MemoriArtifactSystem/utils/applyEdits.js.map +1 -0
  13. package/dist/components/MemoriWidget/MemoriWidget.js +121 -84
  14. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  15. package/dist/helpers/constants.d.ts +1 -1
  16. package/dist/helpers/constants.js +0 -1
  17. package/dist/helpers/constants.js.map +1 -1
  18. package/dist/helpers/message.d.ts +1 -1
  19. package/dist/helpers/message.js +4 -4
  20. package/dist/helpers/message.js.map +1 -1
  21. package/dist/helpers/nats/natsBundled.js +13224 -0
  22. package/dist/helpers/utils.d.ts +1 -1
  23. package/dist/helpers/utils.js +9 -3
  24. package/dist/helpers/utils.js.map +1 -1
  25. package/dist/version.d.ts +1 -1
  26. package/dist/version.js +1 -1
  27. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
  28. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  29. package/esm/components/FilePreview/FilePreview.js +1 -3
  30. package/esm/components/FilePreview/FilePreview.js.map +1 -1
  31. package/esm/components/MediaWidget/MediaItemWidget.js +2 -4
  32. package/esm/components/MediaWidget/MediaItemWidget.js.map +1 -1
  33. package/esm/components/MediaWidget/MediaPreviewModal.js +2 -6
  34. package/esm/components/MediaWidget/MediaPreviewModal.js.map +1 -1
  35. package/esm/components/MemoriArtifactSystem/utils/applyEdits.d.ts +8 -0
  36. package/esm/components/MemoriArtifactSystem/utils/applyEdits.js +112 -0
  37. package/esm/components/MemoriArtifactSystem/utils/applyEdits.js.map +1 -0
  38. package/esm/components/MemoriWidget/MemoriWidget.js +121 -84
  39. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  40. package/esm/helpers/constants.d.ts +1 -1
  41. package/esm/helpers/constants.js +0 -1
  42. package/esm/helpers/constants.js.map +1 -1
  43. package/esm/helpers/message.d.ts +1 -1
  44. package/esm/helpers/message.js +2 -2
  45. package/esm/helpers/message.js.map +1 -1
  46. package/esm/helpers/nats/natsBundled.js +13225 -0
  47. package/esm/helpers/utils.d.ts +1 -1
  48. package/esm/helpers/utils.js +9 -3
  49. package/esm/helpers/utils.js.map +1 -1
  50. package/esm/version.d.ts +1 -1
  51. package/esm/version.js +1 -1
  52. package/package.json +1 -1
  53. package/src/components/CompletionProviderStatus/CompletionProviderStatus.tsx +8 -4
  54. package/src/components/FilePreview/FilePreview.tsx +1 -3
  55. package/src/components/MediaWidget/MediaItemWidget.tsx +2 -3
  56. package/src/components/MediaWidget/MediaPreviewModal.tsx +2 -6
  57. package/src/components/MemoriWidget/MemoriWidget.tsx +110 -68
  58. package/src/components/UploadButton/__snapshots__/UploadButton.test.tsx.snap +2 -2
  59. package/src/helpers/constants.ts +0 -1
  60. package/src/helpers/message.test.ts +28 -1
  61. package/src/helpers/message.ts +4 -4
  62. package/src/helpers/utils.test.ts +50 -1
  63. package/src/helpers/utils.ts +16 -3
  64. package/src/version.ts +1 -1
  65. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.css +0 -367
  66. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.d.ts +0 -36
  67. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js +0 -116
  68. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js.map +0 -1
  69. package/dist/components/DrawerFooter/DrawerFooter.css +0 -62
  70. package/dist/components/DrawerFooter/DrawerFooter.d.ts +0 -12
  71. package/dist/components/DrawerFooter/DrawerFooter.js +0 -10
  72. package/dist/components/DrawerFooter/DrawerFooter.js.map +0 -1
  73. package/dist/components/MobileSessionPanel/MobileSessionPanel.css +0 -437
  74. package/dist/components/MobileSessionPanel/MobileSessionPanel.d.ts +0 -62
  75. package/dist/components/MobileSessionPanel/MobileSessionPanel.js +0 -292
  76. package/dist/components/MobileSessionPanel/MobileSessionPanel.js.map +0 -1
  77. package/dist/components/PositionPopover/PositionPopover.css +0 -219
  78. package/dist/components/PositionPopover/PositionPopover.d.ts +0 -20
  79. package/dist/components/PositionPopover/PositionPopover.js +0 -187
  80. package/dist/components/PositionPopover/PositionPopover.js.map +0 -1
  81. package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.d.ts +0 -4
  82. package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js +0 -41
  83. package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +0 -1
  84. package/dist/components/layouts/WebsiteAssistant/website-assistant.css +0 -690
  85. package/dist/components/layouts/fullpage.css +0 -396
  86. package/dist/helpers/usePressTooltip.d.ts +0 -13
  87. package/dist/helpers/usePressTooltip.js +0 -23
  88. package/dist/helpers/usePressTooltip.js.map +0 -1
  89. package/dist/icons/FacebookIcon.d.ts +0 -3
  90. package/dist/icons/FacebookIcon.js +0 -6
  91. package/dist/icons/FacebookIcon.js.map +0 -1
  92. package/dist/icons/LinkedinIcon.d.ts +0 -3
  93. package/dist/icons/LinkedinIcon.js +0 -6
  94. package/dist/icons/LinkedinIcon.js.map +0 -1
  95. package/dist/icons/MemoriIcon.d.ts +0 -3
  96. package/dist/icons/MemoriIcon.js +0 -8
  97. package/dist/icons/MemoriIcon.js.map +0 -1
  98. package/dist/icons/TelegramIcon.d.ts +0 -3
  99. package/dist/icons/TelegramIcon.js +0 -6
  100. package/dist/icons/TelegramIcon.js.map +0 -1
  101. package/dist/icons/TwitterIcon.d.ts +0 -3
  102. package/dist/icons/TwitterIcon.js +0 -6
  103. package/dist/icons/TwitterIcon.js.map +0 -1
  104. package/dist/icons/WhatsappIcon.d.ts +0 -3
  105. package/dist/icons/WhatsappIcon.js +0 -6
  106. package/dist/icons/WhatsappIcon.js.map +0 -1
  107. package/dist/icons/artifacts/DocumentIcon.d.ts +0 -3
  108. package/dist/icons/artifacts/DocumentIcon.js +0 -6
  109. package/dist/icons/artifacts/DocumentIcon.js.map +0 -1
  110. package/dist/icons/artifacts/HtmlIcon.d.ts +0 -3
  111. package/dist/icons/artifacts/HtmlIcon.js +0 -6
  112. package/dist/icons/artifacts/HtmlIcon.js.map +0 -1
  113. package/dist/icons/artifacts/JavascriptIcon.d.ts +0 -3
  114. package/dist/icons/artifacts/JavascriptIcon.js +0 -6
  115. package/dist/icons/artifacts/JavascriptIcon.js.map +0 -1
  116. package/dist/icons/artifacts/MarkdownIcon.d.ts +0 -3
  117. package/dist/icons/artifacts/MarkdownIcon.js +0 -6
  118. package/dist/icons/artifacts/MarkdownIcon.js.map +0 -1
  119. package/dist/icons/artifacts/PythonIcon.d.ts +0 -3
  120. package/dist/icons/artifacts/PythonIcon.js +0 -6
  121. package/dist/icons/artifacts/PythonIcon.js.map +0 -1
  122. package/dist/icons/artifacts/SvgIcon.d.ts +0 -3
  123. package/dist/icons/artifacts/SvgIcon.js +0 -6
  124. package/dist/icons/artifacts/SvgIcon.js.map +0 -1
  125. package/dist/icons/artifacts/XmlIcon.d.ts +0 -3
  126. package/dist/icons/artifacts/XmlIcon.js +0 -6
  127. package/dist/icons/artifacts/XmlIcon.js.map +0 -1
  128. package/dist/icons/artifacts/cssIcon.d.ts +0 -3
  129. package/dist/icons/artifacts/cssIcon.js +0 -6
  130. package/dist/icons/artifacts/cssIcon.js.map +0 -1
  131. package/dist/testUtils.d.ts +0 -5
  132. package/dist/testUtils.js +0 -18
  133. package/dist/testUtils.js.map +0 -1
  134. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.css +0 -367
  135. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.d.ts +0 -36
  136. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.js +0 -113
  137. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.js.map +0 -1
  138. package/esm/components/DrawerFooter/DrawerFooter.css +0 -62
  139. package/esm/components/DrawerFooter/DrawerFooter.d.ts +0 -12
  140. package/esm/components/DrawerFooter/DrawerFooter.js +0 -8
  141. package/esm/components/DrawerFooter/DrawerFooter.js.map +0 -1
  142. package/esm/components/MobileSessionPanel/MobileSessionPanel.css +0 -437
  143. package/esm/components/MobileSessionPanel/MobileSessionPanel.d.ts +0 -62
  144. package/esm/components/MobileSessionPanel/MobileSessionPanel.js +0 -289
  145. package/esm/components/MobileSessionPanel/MobileSessionPanel.js.map +0 -1
  146. package/esm/components/PositionPopover/PositionPopover.css +0 -219
  147. package/esm/components/PositionPopover/PositionPopover.d.ts +0 -20
  148. package/esm/components/PositionPopover/PositionPopover.js +0 -182
  149. package/esm/components/PositionPopover/PositionPopover.js.map +0 -1
  150. package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.d.ts +0 -4
  151. package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js +0 -38
  152. package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +0 -1
  153. package/esm/components/layouts/WebsiteAssistant/website-assistant.css +0 -690
  154. package/esm/components/layouts/fullpage.css +0 -396
  155. package/esm/helpers/usePressTooltip.d.ts +0 -13
  156. package/esm/helpers/usePressTooltip.js +0 -20
  157. package/esm/helpers/usePressTooltip.js.map +0 -1
  158. package/esm/icons/FacebookIcon.d.ts +0 -3
  159. package/esm/icons/FacebookIcon.js +0 -4
  160. package/esm/icons/FacebookIcon.js.map +0 -1
  161. package/esm/icons/LinkedinIcon.d.ts +0 -3
  162. package/esm/icons/LinkedinIcon.js +0 -4
  163. package/esm/icons/LinkedinIcon.js.map +0 -1
  164. package/esm/icons/MemoriIcon.d.ts +0 -3
  165. package/esm/icons/MemoriIcon.js +0 -6
  166. package/esm/icons/MemoriIcon.js.map +0 -1
  167. package/esm/icons/TelegramIcon.d.ts +0 -3
  168. package/esm/icons/TelegramIcon.js +0 -4
  169. package/esm/icons/TelegramIcon.js.map +0 -1
  170. package/esm/icons/TwitterIcon.d.ts +0 -3
  171. package/esm/icons/TwitterIcon.js +0 -4
  172. package/esm/icons/TwitterIcon.js.map +0 -1
  173. package/esm/icons/WhatsappIcon.d.ts +0 -3
  174. package/esm/icons/WhatsappIcon.js +0 -4
  175. package/esm/icons/WhatsappIcon.js.map +0 -1
  176. package/esm/icons/artifacts/DocumentIcon.d.ts +0 -3
  177. package/esm/icons/artifacts/DocumentIcon.js +0 -4
  178. package/esm/icons/artifacts/DocumentIcon.js.map +0 -1
  179. package/esm/icons/artifacts/HtmlIcon.d.ts +0 -3
  180. package/esm/icons/artifacts/HtmlIcon.js +0 -4
  181. package/esm/icons/artifacts/HtmlIcon.js.map +0 -1
  182. package/esm/icons/artifacts/JavascriptIcon.d.ts +0 -3
  183. package/esm/icons/artifacts/JavascriptIcon.js +0 -4
  184. package/esm/icons/artifacts/JavascriptIcon.js.map +0 -1
  185. package/esm/icons/artifacts/MarkdownIcon.d.ts +0 -3
  186. package/esm/icons/artifacts/MarkdownIcon.js +0 -4
  187. package/esm/icons/artifacts/MarkdownIcon.js.map +0 -1
  188. package/esm/icons/artifacts/PythonIcon.d.ts +0 -3
  189. package/esm/icons/artifacts/PythonIcon.js +0 -4
  190. package/esm/icons/artifacts/PythonIcon.js.map +0 -1
  191. package/esm/icons/artifacts/SvgIcon.d.ts +0 -3
  192. package/esm/icons/artifacts/SvgIcon.js +0 -4
  193. package/esm/icons/artifacts/SvgIcon.js.map +0 -1
  194. package/esm/icons/artifacts/XmlIcon.d.ts +0 -3
  195. package/esm/icons/artifacts/XmlIcon.js +0 -4
  196. package/esm/icons/artifacts/XmlIcon.js.map +0 -1
  197. package/esm/icons/artifacts/cssIcon.d.ts +0 -3
  198. package/esm/icons/artifacts/cssIcon.js +0 -4
  199. package/esm/icons/artifacts/cssIcon.js.map +0 -1
  200. package/esm/testUtils.d.ts +0 -5
  201. package/esm/testUtils.js +0 -15
  202. package/esm/testUtils.js.map +0 -1
@@ -61,6 +61,10 @@ const getMemoriState = (integrationId) => {
61
61
  loginToken,
62
62
  };
63
63
  };
64
+ const resolveLoginTokenValue = (loginToken, userTokenRef, callAdditionalInfoLoginToken, additionalInfoLoginToken, authTokenProp) => {
65
+ var _a, _b, _c;
66
+ 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;
67
+ };
64
68
  const NULL_PLACE_SPEC = {
65
69
  placeName: null,
66
70
  latitude: null,
@@ -169,7 +173,6 @@ window.typeMessageHidden = typeMessageHidden;
169
173
  window.typeBatchMessages = typeBatchMessages;
170
174
  let audioContext;
171
175
  let memoriPassword;
172
- let userToken;
173
176
  const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenantID, memoriLang, uiLang, spokenLang, multilingual, integration, layout, customLayout, showShare, preview = false, embed = false, showCopyButton = true, showTranslationOriginal = false, showInputs = true, showDates = false, showContextPerLine = false, showMessageConsumption = false, showSettings, showTypingText = false, showClear = false, showLogin = false, showUpload, showOnlyLastMessages, showChatHistory, showReasoning, avatar3dHidden, height = '100vh', secret, baseUrl = 'https://aisuru-staging.aclambda.online', apiURL = 'https://backend-staging.memori.ai', engineURL = 'https://engine-staging.memori.ai', initialContextVars, initialQuestion, ttsProvider, ogImage, sessionID: initialSessionID, tenant, personification, authToken, enableAudio, defaultSpeakerActive = true, disableTextEnteredEvents = false, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, userAvatar, __WEBCOMPONENT__ = false, useMathFormatting = false, autoStart = false, applyVarsToRoot = false, showFunctionCache = false, maxTotalMessagePayload, maxTextareaCharacters, }) => {
174
177
  var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
175
178
  const { t, i18n } = useTranslation();
@@ -182,35 +185,61 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
182
185
  const [instruct, setInstruct] = useState(false);
183
186
  const [enableFocusChatInput, setEnableFocusChatInput] = useState(true);
184
187
  const [loginToken, setLoginToken] = useState((_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken);
188
+ const userTokenRef = useRef((_b = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _b !== void 0 ? _b : authToken);
189
+ const prevPropsLoginTokenRef = useRef((_c = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _c !== void 0 ? _c : authToken);
185
190
  const [user, setUser] = useState({
186
191
  avatarURL: typeof userAvatar === 'string' ? userAvatar : undefined,
187
192
  });
193
+ const resolveLoginToken = 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]);
188
194
  useEffect(() => {
189
- if (loginToken &&
190
- !(user === null || user === void 0 ? void 0 : user.userID) &&
191
- (showLogin || memori.requireLoginToken)) {
192
- client.backend
193
- .pwlGetCurrentUser(loginToken)
194
- .then(({ user, resultCode }) => {
195
- if (user && resultCode === 0) {
196
- setUser(user);
197
- setLocalConfig('loginToken', loginToken);
198
- if (!birthDate && user.birthDate) {
199
- setBirthDate(user.birthDate);
200
- setLocalConfig('birthDate', user.birthDate);
201
- }
202
- }
203
- else {
204
- removeLocalConfig('loginToken');
205
- }
206
- });
195
+ var _a;
196
+ const incomingToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
197
+ const prevPropsToken = prevPropsLoginTokenRef.current;
198
+ prevPropsLoginTokenRef.current = incomingToken;
199
+ if (incomingToken !== prevPropsToken) {
200
+ setLoginToken(incomingToken);
201
+ userTokenRef.current = incomingToken;
202
+ if (!incomingToken) {
203
+ removeLocalConfig('loginToken');
204
+ setUser(undefined);
205
+ }
206
+ }
207
+ }, [additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
208
+ useEffect(() => {
209
+ if (!loginToken || !(showLogin || memori.requireLoginToken)) {
210
+ return;
207
211
  }
208
- }, [loginToken, user === null || user === void 0 ? void 0 : user.userID]);
212
+ let cancelled = false;
213
+ client.backend
214
+ .pwlGetCurrentUser(loginToken)
215
+ .then(({ user: fetchedUser, resultCode }) => {
216
+ if (cancelled)
217
+ return;
218
+ if (fetchedUser && resultCode === 0) {
219
+ setUser(fetchedUser);
220
+ setLocalConfig('loginToken', loginToken);
221
+ userTokenRef.current = loginToken;
222
+ if (!birthDate && fetchedUser.birthDate) {
223
+ setBirthDate(fetchedUser.birthDate);
224
+ setLocalConfig('birthDate', fetchedUser.birthDate);
225
+ }
226
+ }
227
+ else {
228
+ setLoginToken(undefined);
229
+ userTokenRef.current = undefined;
230
+ setUser(undefined);
231
+ removeLocalConfig('loginToken');
232
+ }
233
+ });
234
+ return () => {
235
+ cancelled = true;
236
+ };
237
+ }, [loginToken, showLogin, memori.requireLoginToken]);
209
238
  const [showLoginDrawer, setShowLoginDrawer] = useState(false);
210
239
  const [clickedStart, setClickedStart] = useState(false);
211
240
  const sessionStartingRef = useRef(false);
212
- const language = ((_d = (_c = (_b = memori.culture) === null || _b === void 0 ? void 0 : _b.split('-')) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.toUpperCase()) ||
213
- ((_j = (_h = (_g = (_f = memoriConfigs === null || memoriConfigs === void 0 ? void 0 : memoriConfigs.find(c => c.memoriConfigID === memori.memoriConfigurationID)) === null || _f === void 0 ? void 0 : _f.culture) === null || _g === void 0 ? void 0 : _g.split('-')) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.toUpperCase());
241
+ 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()) ||
242
+ ((_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());
214
243
  const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
215
244
  ? JSON.parse(integration.customData)
216
245
  : null;
@@ -218,7 +247,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
218
247
  ? multilingual
219
248
  : !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.multilanguage);
220
249
  const forcedTimeout = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.forcedTimeout;
221
- const [userLang, setUserLang] = useState((_p = (_o = (_m = (_l = (_k = spokenLang !== null && spokenLang !== void 0 ? spokenLang : memoriLang) !== null && _k !== void 0 ? _k : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.lang) !== null && _l !== void 0 ? _l : language) !== null && _m !== void 0 ? _m : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.uiLang) !== null && _o !== void 0 ? _o : i18n.language) !== null && _p !== void 0 ? _p : 'IT');
250
+ const [userLang, setUserLang] = 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');
222
251
  useEffect(() => {
223
252
  if (spokenLang != null) {
224
253
  setUserLang(spokenLang);
@@ -250,14 +279,14 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
250
279
  ? layout
251
280
  : typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'string'
252
281
  ? integrationConfig.layout
253
- : (_q = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _q === void 0 ? void 0 : _q.name;
282
+ : (_s = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _s === void 0 ? void 0 : _s.name;
254
283
  const selectedLayout = layoutName || 'DEFAULT';
255
284
  const piiDetection = typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'object' &&
256
285
  (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) !== null &&
257
- ((_s = (_r = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _r === void 0 ? void 0 : _r.piiDetection) === null || _s === void 0 ? void 0 : _s.enabled)
286
+ ((_u = (_t = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _t === void 0 ? void 0 : _t.piiDetection) === null || _u === void 0 ? void 0 : _u.enabled)
258
287
  ? integrationConfig.layout.piiDetection
259
288
  : undefined;
260
- const defaultEnableAudio = (_t = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _t !== void 0 ? _t : true;
289
+ const defaultEnableAudio = (_v = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _v !== void 0 ? _v : true;
261
290
  const [hasUserActivatedListening, setHasUserActivatedListening] = useState(false);
262
291
  const [hasUserTypedMessage, setHasUserTypedMessage] = useState(false);
263
292
  const [showPositionDrawer, setShowPositionDrawer] = useState(false);
@@ -300,7 +329,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
300
329
  setRuntimeShowMessageConsumption(getLocalConfig('showMessageConsumption', (_a = showMessageConsumption !== null && showMessageConsumption !== void 0 ? showMessageConsumption : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showMessageConsumption) !== null && _a !== void 0 ? _a : false));
301
330
  if (!(additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) && !authToken) {
302
331
  setLoginToken(getLocalConfig('loginToken', undefined));
303
- userToken = getLocalConfig('loginToken', undefined);
332
+ userTokenRef.current = getLocalConfig('loginToken', undefined);
304
333
  setBirthDate(getLocalConfig('birthDate', undefined));
305
334
  }
306
335
  if (!((_b = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _b !== void 0 ? _b : true)) {
@@ -719,7 +748,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
719
748
  }
720
749
  }, [initialSessionID]);
721
750
  const fetchSession = async (params) => {
722
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l;
751
+ var _a, _b, _c, _d, _f, _g, _h;
723
752
  let storageBirthDate = getLocalConfig('birthDate', undefined);
724
753
  let userBirthDate = (_a = birthDate !== null && birthDate !== void 0 ? birthDate : params.birthDate) !== null && _a !== void 0 ? _a : storageBirthDate;
725
754
  if (!userBirthDate && !!minAge) {
@@ -744,7 +773,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
744
773
  return window.location.href;
745
774
  })();
746
775
  }
747
- catch (_m) {
776
+ catch (_j) {
748
777
  }
749
778
  const session = await initSession({
750
779
  ...params,
@@ -753,8 +782,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
753
782
  pin: (_c = params.pin) !== null && _c !== void 0 ? _c : personification === null || personification === void 0 ? void 0 : personification.pin,
754
783
  additionalInfo: {
755
784
  ...(params.additionalInfo || additionalInfo || {}),
756
- loginToken: (_h = (_g = (_d = userToken !== null && userToken !== void 0 ? userToken : loginToken) !== null && _d !== void 0 ? _d : (_f = params.additionalInfo) === null || _f === void 0 ? void 0 : _f.loginToken) !== null && _g !== void 0 ? _g : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _h !== void 0 ? _h : authToken,
757
- language: ((_l = userLang !== null && userLang !== void 0 ? userLang : (_k = (_j = memori.culture) === null || _j === void 0 ? void 0 : _j.split('-')) === null || _k === void 0 ? void 0 : _k[0]) !== null && _l !== void 0 ? _l : 'IT').toLowerCase(),
785
+ loginToken: resolveLoginToken((_d = params.additionalInfo) === null || _d === void 0 ? void 0 : _d.loginToken),
786
+ 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(),
758
787
  referral: referral,
759
788
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
760
789
  },
@@ -795,7 +824,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
795
824
  }
796
825
  };
797
826
  const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired, suppressHistoryUpdate) => {
798
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m;
827
+ var _a, _b, _c, _d, _f, _g, _h, _j;
799
828
  setLoading(true);
800
829
  let storageBirthDate = getLocalConfig('birthDate', undefined);
801
830
  let userBirthDate = birthDate !== null && birthDate !== void 0 ? birthDate : storageBirthDate;
@@ -823,7 +852,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
823
852
  return window.location.href;
824
853
  })();
825
854
  }
826
- catch (_o) {
855
+ catch (_k) {
827
856
  }
828
857
  const { sessionID, currentState, ...response } = await initSession({
829
858
  memoriID: (_a = memori.engineMemoriID) !== null && _a !== void 0 ? _a : '',
@@ -843,8 +872,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
843
872
  birthDate: userBirthDate,
844
873
  additionalInfo: {
845
874
  ...(additionalInfoProp || additionalInfo || {}),
846
- loginToken: (_g = (_f = (_d = userToken !== null && userToken !== void 0 ? userToken : loginToken) !== null && _d !== void 0 ? _d : additionalInfoProp === null || additionalInfoProp === void 0 ? void 0 : additionalInfoProp.loginToken) !== null && _f !== void 0 ? _f : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _g !== void 0 ? _g : authToken,
847
- language: ((_k = userLang !== null && userLang !== void 0 ? userLang : (_j = (_h = memori.culture) === null || _h === void 0 ? void 0 : _h.split('-')) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : 'IT').toLowerCase(),
875
+ loginToken: resolveLoginToken(additionalInfoProp === null || additionalInfoProp === void 0 ? void 0 : additionalInfoProp.loginToken),
876
+ 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(),
848
877
  referral: referral,
849
878
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
850
879
  },
@@ -877,7 +906,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
877
906
  {
878
907
  text: currentState.emission,
879
908
  emitter: currentState.emitter,
880
- media: (_l = currentState.emittedMedia) !== null && _l !== void 0 ? _l : currentState.media,
909
+ media: (_h = currentState.emittedMedia) !== null && _h !== void 0 ? _h : currentState.media,
881
910
  fromUser: false,
882
911
  initial: (initialStatus === true
883
912
  ? true
@@ -895,7 +924,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
895
924
  : pushMessage({
896
925
  text: currentState.emission,
897
926
  emitter: currentState.emitter,
898
- media: (_m = currentState.emittedMedia) !== null && _m !== void 0 ? _m : currentState.media,
927
+ media: (_j = currentState.emittedMedia) !== null && _j !== void 0 ? _j : currentState.media,
899
928
  fromUser: false,
900
929
  initial: (initialStatus === true
901
930
  ? true
@@ -980,7 +1009,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
980
1009
  });
981
1010
  };
982
1011
  const changeTag = async (memoriId, sessionId, tag, pin) => {
983
- var _a, _b, _c, _d, _f, _g, _h, _j, _k;
1012
+ var _a, _b, _c, _d, _f, _g, _h;
984
1013
  if (!memoriId || !sessionId) {
985
1014
  return Promise.reject('Session not found');
986
1015
  }
@@ -1020,7 +1049,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1020
1049
  return window.location.href;
1021
1050
  })();
1022
1051
  }
1023
- catch (_l) {
1052
+ catch (_j) {
1024
1053
  }
1025
1054
  fetchSession({
1026
1055
  memoriID: (_b = memori.engineMemoriID) !== null && _b !== void 0 ? _b : '',
@@ -1037,8 +1066,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1037
1066
  birthDate: birthDate || storageBirthDate || undefined,
1038
1067
  additionalInfo: {
1039
1068
  ...(additionalInfo || {}),
1040
- loginToken: (_g = (_f = userToken !== null && userToken !== void 0 ? userToken : loginToken) !== null && _f !== void 0 ? _f : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _g !== void 0 ? _g : authToken,
1041
- language: ((_k = userLang !== null && userLang !== void 0 ? userLang : (_j = (_h = memori.culture) === null || _h === void 0 ? void 0 : _h.split('-')) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : 'IT').toLowerCase(),
1069
+ loginToken: resolveLoginToken(),
1070
+ 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(),
1042
1071
  referral: referral,
1043
1072
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
1044
1073
  },
@@ -1102,7 +1131,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1102
1131
  apiUrl: `${baseUrl}/api/tts`,
1103
1132
  continuousSpeech: continuousSpeech,
1104
1133
  preview: preview,
1105
- }, autoStart, defaultEnableAudio, (_u = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _u !== void 0 ? _u : true);
1134
+ }, autoStart, defaultEnableAudio, (_w = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _w !== void 0 ? _w : true);
1106
1135
  const shouldPlayAudio = (text) => {
1107
1136
  const currentSpeakerMuted = getLocalConfig('muteSpeaker', !defaultEnableAudio);
1108
1137
  return (text &&
@@ -1450,7 +1479,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1450
1479
  ? {
1451
1480
  '--memori-chat-bubble-bg': '#fff',
1452
1481
  ...(integrationConfig && !instruct
1453
- ? { '--memori-text-color': (_v = integrationConfig.textColor) !== null && _v !== void 0 ? _v : '#000' }
1482
+ ? { '--memori-text-color': (_x = integrationConfig.textColor) !== null && _x !== void 0 ? _x : '#000' }
1454
1483
  : {}),
1455
1484
  ...((integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.buttonBgColor)
1456
1485
  ? {
@@ -1474,12 +1503,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1474
1503
  ? {
1475
1504
  '--memori-inner-bg': `rgba(${integrationConfig.innerBgColor === 'dark'
1476
1505
  ? '0, 0, 0'
1477
- : '255, 255, 255'}, ${(_w = integrationConfig.innerBgAlpha) !== null && _w !== void 0 ? _w : 0.4})`,
1506
+ : '255, 255, 255'}, ${(_y = integrationConfig.innerBgAlpha) !== null && _y !== void 0 ? _y : 0.4})`,
1478
1507
  '--memori-inner-content-pad': '1.5rem',
1479
1508
  '--memori-nav-bg-image': 'none',
1480
1509
  '--memori-nav-bg': `rgba(${integrationConfig.innerBgColor === 'dark'
1481
1510
  ? '0, 0, 0'
1482
- : '255, 255, 255'}, ${(_x = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.innerBgAlpha) !== null && _x !== void 0 ? _x : 0.4})`,
1511
+ : '255, 255, 255'}, ${(_z = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.innerBgAlpha) !== null && _z !== void 0 ? _z : 0.4})`,
1483
1512
  }
1484
1513
  : {
1485
1514
  '--memori-inner-content-pad': '0px',
@@ -1578,7 +1607,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1578
1607
  };
1579
1608
  }, [sessionId, userLang, disableTextEnteredEvents]);
1580
1609
  const onClickStart = useCallback(async (session, initialSessionExpired = false, chatLog, targetSessionID) => {
1581
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
1610
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1582
1611
  const sessionID = chatLog ? undefined : (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1583
1612
  const dialogState = chatLog
1584
1613
  ? undefined
@@ -1639,8 +1668,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1639
1668
  birthDate: birth,
1640
1669
  additionalInfo: {
1641
1670
  ...(additionalInfo || {}),
1642
- loginToken: (_g = (_f = userToken !== null && userToken !== void 0 ? userToken : loginToken) !== null && _f !== void 0 ? _f : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _g !== void 0 ? _g : authToken,
1643
- language: ((_k = userLang !== null && userLang !== void 0 ? userLang : (_j = (_h = memori.culture) === null || _h === void 0 ? void 0 : _h.split('-')) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : 'IT').toLowerCase(),
1671
+ loginToken: resolveLoginToken(),
1672
+ 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(),
1644
1673
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
1645
1674
  },
1646
1675
  });
@@ -1682,7 +1711,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1682
1711
  };
1683
1712
  }));
1684
1713
  }
1685
- catch (_w) {
1714
+ catch (_u) {
1686
1715
  }
1687
1716
  }
1688
1717
  setHistory(translatedMessages);
@@ -1729,11 +1758,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1729
1758
  throw new Error('No session');
1730
1759
  }
1731
1760
  }
1732
- catch (_x) {
1761
+ catch (_v) {
1733
1762
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, personification.tag, personification.pin, {
1734
1763
  LANG: userLang,
1735
- PATHNAME: (_l = window.location.pathname) === null || _l === void 0 ? void 0 : _l.toUpperCase(),
1736
- ROUTE: ((_p = (_o = (_m = window.location.pathname) === null || _m === void 0 ? void 0 : _m.split('/')) === null || _o === void 0 ? void 0 : _o.pop()) === null || _p === void 0 ? void 0 : _p.toUpperCase()) ||
1764
+ PATHNAME: (_j = window.location.pathname) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
1765
+ 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()) ||
1737
1766
  '',
1738
1767
  ...(initialContextVars || {}),
1739
1768
  }, initialQuestion, birth).then(() => {
@@ -1760,8 +1789,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1760
1789
  catch (e) {
1761
1790
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, undefined, undefined, {
1762
1791
  LANG: userLang,
1763
- PATHNAME: (_q = window.location.pathname) === null || _q === void 0 ? void 0 : _q.toUpperCase(),
1764
- ROUTE: ((_t = (_s = (_r = window.location.pathname) === null || _r === void 0 ? void 0 : _r.split('/')) === null || _s === void 0 ? void 0 : _s.pop()) === null || _t === void 0 ? void 0 : _t.toUpperCase()) ||
1792
+ PATHNAME: (_o = window.location.pathname) === null || _o === void 0 ? void 0 : _o.toUpperCase(),
1793
+ 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()) ||
1765
1794
  '',
1766
1795
  ...(initialContextVars || {}),
1767
1796
  }, initialQuestion, birth).then(() => {
@@ -1773,7 +1802,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1773
1802
  else {
1774
1803
  try {
1775
1804
  const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
1776
- const messages = (_u = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _u === void 0 ? void 0 : _u.lines.map((l, i) => {
1805
+ const messages = (_s = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _s === void 0 ? void 0 : _s.lines.map((l, i) => {
1777
1806
  var _a, _b;
1778
1807
  return ({
1779
1808
  text: l.text,
@@ -1798,12 +1827,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1798
1827
  text: (await getTranslation(m.text, userLang, language, baseUrl)).text,
1799
1828
  })));
1800
1829
  }
1801
- catch (_y) {
1830
+ catch (_w) {
1802
1831
  }
1803
1832
  }
1804
1833
  setHistory(translatedMessages);
1805
1834
  }
1806
- catch (_z) {
1835
+ catch (_x) {
1807
1836
  }
1808
1837
  if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
1809
1838
  !initialQuestion) {
@@ -1819,7 +1848,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1819
1848
  sessionId: sessionID,
1820
1849
  text: initialQuestion,
1821
1850
  ...(memori.needsDateTime && {
1822
- dateUTC: (_v = DateTime.utc().toISO()) !== null && _v !== void 0 ? _v : undefined,
1851
+ dateUTC: (_t = DateTime.utc().toISO()) !== null && _t !== void 0 ? _t : undefined,
1823
1852
  }),
1824
1853
  ...(placeSpec !== undefined && { place: placeSpec }),
1825
1854
  });
@@ -1885,27 +1914,35 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1885
1914
  hasEnoughCredits,
1886
1915
  ]);
1887
1916
  useEffect(() => {
1917
+ var _a;
1888
1918
  const targetNode = document.querySelector(`memori-client[memoriname="${memori.name}"]`) ||
1889
1919
  document.querySelector(`memori-client[memoriid="${memori.memoriID}"]`) ||
1890
1920
  document.querySelector('memori-client');
1891
1921
  if (!targetNode) {
1892
1922
  return;
1893
1923
  }
1924
+ const propsToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
1925
+ const initialDomToken = targetNode.getAttribute('authtoken') || undefined;
1926
+ if (initialDomToken && !propsToken) {
1927
+ setLoginToken(initialDomToken);
1928
+ userTokenRef.current = initialDomToken;
1929
+ }
1930
+ const applyAuthTokenFromElement = (element) => {
1931
+ var _a;
1932
+ const clientNode = element.nodeName === 'MEMORI-CLIENT'
1933
+ ? element
1934
+ : (_a = element.closest('memori-client')) !== null && _a !== void 0 ? _a : element.parentElement;
1935
+ const token = (clientNode === null || clientNode === void 0 ? void 0 : clientNode.getAttribute('authtoken')) || undefined;
1936
+ setLoginToken(token);
1937
+ userTokenRef.current = token;
1938
+ };
1894
1939
  const config = { attributes: true, childList: false, subtree: false };
1895
- const callback = (mutationList, _observer) => {
1896
- var _a, _b, _c;
1940
+ const callback = mutationList => {
1941
+ var _a;
1897
1942
  for (const mutation of mutationList) {
1898
1943
  if (mutation.type === 'attributes' &&
1899
1944
  ((_a = mutation.attributeName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authtoken') {
1900
- if (mutation.target.nodeName === 'MEMORI-CLIENT') {
1901
- setLoginToken(mutation.target.getAttribute('authtoken') || undefined);
1902
- userToken = mutation.target.getAttribute('authtoken') || undefined;
1903
- }
1904
- else {
1905
- setLoginToken(((_c = (_b = mutation.target) === null || _b === void 0 ? void 0 : _b.parentElement) === null || _c === void 0 ? void 0 : _c.getAttribute('authtoken')) ||
1906
- undefined);
1907
- userToken = mutation.target.getAttribute('authtoken') || undefined;
1908
- }
1945
+ applyAuthTokenFromElement(mutation.target);
1909
1946
  }
1910
1947
  }
1911
1948
  };
@@ -1914,7 +1951,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1914
1951
  return () => {
1915
1952
  observer.disconnect();
1916
1953
  };
1917
- }, []);
1954
+ }, [memori.name, memori.memoriID, additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
1918
1955
  const [experts, setExperts] = useState();
1919
1956
  const fetchExperts = useCallback(async () => {
1920
1957
  if (!sessionId || !(memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts))
@@ -2012,16 +2049,16 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2012
2049
  ? selectedLayout !== 'TOTEM' && selectedLayout !== 'WEBSITE_ASSISTANT'
2013
2050
  : !showOnlyLastMessages;
2014
2051
  const canShowLoginButton = !(tenant === null || tenant === void 0 ? void 0 : tenant.ssoLogin) &&
2015
- ((_y = showLogin !== null && showLogin !== void 0 ? showLogin : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showLogin) !== null && _y !== void 0 ? _y : memori.requireLoginToken);
2052
+ ((_0 = showLogin !== null && showLogin !== void 0 ? showLogin : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showLogin) !== null && _0 !== void 0 ? _0 : memori.requireLoginToken);
2016
2053
  const headerProps = {
2017
2054
  memori: {
2018
2055
  ...memori,
2019
- ownerUserID: (_0 = (_z = memori.ownerUserID) !== null && _z !== void 0 ? _z : ownerUserID) !== null && _0 !== void 0 ? _0 : undefined,
2056
+ ownerUserID: (_2 = (_1 = memori.ownerUserID) !== null && _1 !== void 0 ? _1 : ownerUserID) !== null && _2 !== void 0 ? _2 : undefined,
2020
2057
  },
2021
2058
  apiClient: client,
2022
2059
  tenant,
2023
2060
  history,
2024
- showShare: (_1 = showShare !== null && showShare !== void 0 ? showShare : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showShare) !== null && _1 !== void 0 ? _1 : true,
2061
+ showShare: (_3 = showShare !== null && showShare !== void 0 ? showShare : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showShare) !== null && _3 !== void 0 ? _3 : true,
2025
2062
  position,
2026
2063
  layout: selectedLayout,
2027
2064
  additionalSettings,
@@ -2029,18 +2066,18 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2029
2066
  setShowSettingsDrawer,
2030
2067
  setShowKnownFactsDrawer,
2031
2068
  setShowExpertsDrawer,
2032
- enableAudio: (_2 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _2 !== void 0 ? _2 : true,
2069
+ enableAudio: (_4 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _4 !== void 0 ? _4 : true,
2033
2070
  speakerMuted: speakerMuted !== null && speakerMuted !== void 0 ? speakerMuted : false,
2034
2071
  setSpeakerMuted: (mute) => {
2035
2072
  toggleMute(mute);
2036
2073
  },
2037
2074
  setShowChatHistoryDrawer,
2038
- showSettings: (_3 = showSettings !== null && showSettings !== void 0 ? showSettings : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showSettings) !== null && _3 !== void 0 ? _3 : true,
2039
- showChatHistory: (_4 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _4 !== void 0 ? _4 : true,
2075
+ showSettings: (_5 = showSettings !== null && showSettings !== void 0 ? showSettings : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showSettings) !== null && _5 !== void 0 ? _5 : true,
2076
+ showChatHistory: (_6 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _6 !== void 0 ? _6 : true,
2040
2077
  showMessageConsumption: enableMessageConsumption,
2041
2078
  hasUserActivatedSpeak,
2042
2079
  showReload: selectedLayout === 'TOTEM',
2043
- showClear: (_5 = showClear !== null && showClear !== void 0 ? showClear : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showClear) !== null && _5 !== void 0 ? _5 : false,
2080
+ showClear: (_7 = showClear !== null && showClear !== void 0 ? showClear : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showClear) !== null && _7 !== void 0 ? _7 : false,
2044
2081
  clearHistory: () => setHistory(h => h.slice(-1)),
2045
2082
  showLogin: canShowLoginButton,
2046
2083
  setShowLoginDrawer,
@@ -2055,7 +2092,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2055
2092
  setShowLoginDrawer(false);
2056
2093
  setUser(undefined);
2057
2094
  setLoginToken(undefined);
2058
- userToken = undefined;
2095
+ userTokenRef.current = undefined;
2059
2096
  removeLocalConfig('loginToken');
2060
2097
  });
2061
2098
  },
@@ -2071,7 +2108,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2071
2108
  hasUserActivatedSpeak,
2072
2109
  isPlayingAudio: isPlayingAudio &&
2073
2110
  !speakerMuted &&
2074
- ((_6 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _6 !== void 0 ? _6 : true),
2111
+ ((_8 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _8 !== void 0 ? _8 : true),
2075
2112
  loading: !!memoriTyping,
2076
2113
  baseUrl,
2077
2114
  apiUrl: client.constants.BACKEND_URL,
@@ -2108,7 +2145,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2108
2145
  tenant,
2109
2146
  translateTo: isMultilanguageEnabled &&
2110
2147
  userLang.toUpperCase() !==
2111
- ((_11 = ((_10 = (_9 = (_8 = (_7 = memori.culture) === null || _7 === void 0 ? void 0 : _7.split('-')) === null || _8 === void 0 ? void 0 : _8[0]) !== null && _9 !== void 0 ? _9 : i18n.language) !== null && _10 !== void 0 ? _10 : 'IT')) === null || _11 === void 0 ? void 0 : _11.toUpperCase())
2148
+ ((_13 = ((_12 = (_11 = (_10 = (_9 = memori.culture) === null || _9 === void 0 ? void 0 : _9.split('-')) === null || _10 === void 0 ? void 0 : _10[0]) !== null && _11 !== void 0 ? _11 : i18n.language) !== null && _12 !== void 0 ? _12 : 'IT')) === null || _13 === void 0 ? void 0 : _13.toUpperCase())
2112
2149
  ? userLang
2113
2150
  : undefined,
2114
2151
  baseUrl,
@@ -2116,9 +2153,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2116
2153
  layout,
2117
2154
  memoriTyping,
2118
2155
  typingText,
2119
- showTypingText: (_12 = showTypingText !== null && showTypingText !== void 0 ? showTypingText : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showTypingText) !== null && _12 !== void 0 ? _12 : false,
2156
+ showTypingText: (_14 = showTypingText !== null && showTypingText !== void 0 ? showTypingText : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showTypingText) !== null && _14 !== void 0 ? _14 : false,
2120
2157
  history: showFullHistory ? history : history.slice(-2),
2121
- authToken: (_14 = (_13 = loginToken !== null && loginToken !== void 0 ? loginToken : userToken) !== null && _13 !== void 0 ? _13 : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _14 !== void 0 ? _14 : authToken,
2158
+ authToken: resolveLoginToken(),
2122
2159
  dialogState: currentDialogState,
2123
2160
  pushMessage,
2124
2161
  simulateUserPrompt,
@@ -2291,7 +2328,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2291
2328
  setShowLoginDrawer(false);
2292
2329
  setUser(user);
2293
2330
  setLoginToken(token);
2294
- userToken = token;
2331
+ userTokenRef.current = token;
2295
2332
  setLocalConfig('loginToken', token);
2296
2333
  if ((state === null || state === void 0 ? void 0 : state.sessionID) &&
2297
2334
  state.sessionID !== sessionId &&
@@ -2322,7 +2359,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
2322
2359
  setShowLoginDrawer(false);
2323
2360
  setUser(undefined);
2324
2361
  setLoginToken(undefined);
2325
- userToken = undefined;
2362
+ userTokenRef.current = undefined;
2326
2363
  removeLocalConfig('loginToken');
2327
2364
  });
2328
2365
  } }))] }));