@memori.ai/memori-react 9.0.0-alpha.0 → 9.0.0-alpha.10

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 (942) hide show
  1. package/CHANGELOG.md +381 -0
  2. package/dist/components/AgeVerificationModal/AgeVerificationModal.js +8 -3
  3. package/dist/components/AgeVerificationModal/AgeVerificationModal.js.map +1 -1
  4. package/dist/components/Auth/Auth.js +3 -1
  5. package/dist/components/Auth/Auth.js.map +1 -1
  6. package/dist/components/Avatar/Avatar.js +5 -10
  7. package/dist/components/Avatar/Avatar.js.map +1 -1
  8. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +8 -1
  9. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  10. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +1 -1
  11. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
  12. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +2 -0
  13. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js +14 -5
  14. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
  15. package/dist/components/Chat/Chat.css +108 -20
  16. package/dist/components/Chat/Chat.d.ts +3 -0
  17. package/dist/components/Chat/Chat.js +63 -55
  18. package/dist/components/Chat/Chat.js.map +1 -1
  19. package/dist/components/ChatBubble/ChatBubble.css +42 -14
  20. package/dist/components/ChatBubble/ChatBubble.js +24 -16
  21. package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
  22. package/dist/components/ChatHistoryDrawer/ChatHistory.css +4 -0
  23. package/dist/components/ChatHistoryDrawer/ChatHistory.js +27 -10
  24. package/dist/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
  25. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.d.ts +0 -1
  26. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js +0 -1
  27. package/dist/components/ChatHistoryDrawer/ChatResumeDrawer.js.map +1 -1
  28. package/dist/components/ChatInputs/ChatInputs.css +292 -108
  29. package/dist/components/ChatInputs/ChatInputs.d.ts +1 -0
  30. package/dist/components/ChatInputs/ChatInputs.js +2 -2
  31. package/dist/components/ChatInputs/ChatInputs.js.map +1 -1
  32. package/dist/components/ChatTextArea/ChatTextArea.css +30 -6
  33. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
  34. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  35. package/dist/components/ContentPreviewModal/ContentPreviewModal.js +3 -1
  36. package/dist/components/ContentPreviewModal/ContentPreviewModal.js.map +1 -1
  37. package/dist/components/DateSelector/DateSelector.d.ts +2 -1
  38. package/dist/components/DateSelector/DateSelector.js +17 -7
  39. package/dist/components/DateSelector/DateSelector.js.map +1 -1
  40. package/dist/components/ExpertsDrawer/ExpertsDrawer.js +3 -1
  41. package/dist/components/ExpertsDrawer/ExpertsDrawer.js.map +1 -1
  42. package/dist/components/FilePreview/FilePreview.js +22 -5
  43. package/dist/components/FilePreview/FilePreview.js.map +1 -1
  44. package/dist/components/Header/ChatConsumptionDropdown.d.ts +3 -1
  45. package/dist/components/Header/ChatConsumptionDropdown.js +4 -3
  46. package/dist/components/Header/ChatConsumptionDropdown.js.map +1 -1
  47. package/dist/components/Header/Header.css +16 -10
  48. package/dist/components/Header/Header.js +103 -22
  49. package/dist/components/Header/Header.js.map +1 -1
  50. package/dist/components/KnownFacts/KnownFacts.js +7 -5
  51. package/dist/components/KnownFacts/KnownFacts.js.map +1 -1
  52. package/dist/components/LoginDrawer/LoginDrawer.css +1 -0
  53. package/dist/components/LoginDrawer/LoginDrawer.js +3 -1
  54. package/dist/components/LoginDrawer/LoginDrawer.js.map +1 -1
  55. package/dist/components/MediaWidget/MediaItemWidget.js +14 -12
  56. package/dist/components/MediaWidget/MediaItemWidget.js.map +1 -1
  57. package/dist/components/MediaWidget/MediaItemWidget.utils.d.ts +3 -2
  58. package/dist/components/MediaWidget/MediaItemWidget.utils.js +28 -6
  59. package/dist/components/MediaWidget/MediaItemWidget.utils.js.map +1 -1
  60. package/dist/components/MediaWidget/MediaPreviewModal.js +6 -7
  61. package/dist/components/MediaWidget/MediaPreviewModal.js.map +1 -1
  62. package/dist/components/MemoriArtifactSystem/components/ArtifactActions/styles.css +5 -4
  63. package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +108 -42
  64. package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.d.ts +1 -0
  65. package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +18 -10
  66. package/dist/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
  67. package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +2 -2
  68. package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
  69. package/dist/components/MemoriWidget/MemoriWidget.css +5 -5
  70. package/dist/components/MemoriWidget/MemoriWidget.d.ts +1 -0
  71. package/dist/components/MemoriWidget/MemoriWidget.js +788 -430
  72. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  73. package/dist/components/MicrophoneButton/MicrophoneButton.css +50 -18
  74. package/dist/components/MobileSessionPanel/MobileSessionPanel.d.ts +3 -2
  75. package/dist/components/MobileSessionPanel/MobileSessionPanel.js +5 -5
  76. package/dist/components/MobileSessionPanel/MobileSessionPanel.js.map +1 -1
  77. package/dist/components/PoweredBy/PoweredBy.css +10 -2
  78. package/dist/components/SettingsDrawer/SettingsDrawer.js +3 -1
  79. package/dist/components/SettingsDrawer/SettingsDrawer.js.map +1 -1
  80. package/dist/components/ShareButton/ShareButton.js +2 -4
  81. package/dist/components/ShareButton/ShareButton.js.map +1 -1
  82. package/dist/components/StartPanel/StartPanel.js +13 -6
  83. package/dist/components/StartPanel/StartPanel.js.map +1 -1
  84. package/dist/components/UploadButton/UploadButton.js +21 -5
  85. package/dist/components/UploadButton/UploadButton.js.map +1 -1
  86. package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js +126 -60
  87. package/dist/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
  88. package/dist/components/UploadButton/UploadImages/UploadImages.js +4 -2
  89. package/dist/components/UploadButton/UploadImages/UploadImages.js.map +1 -1
  90. package/dist/components/WhyThisAnswer/WhyThisAnswer.js +3 -1
  91. package/dist/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
  92. package/dist/components/layouts/Chat.js +25 -30
  93. package/dist/components/layouts/Chat.js.map +1 -1
  94. package/dist/components/layouts/FullPage.js +36 -9
  95. package/dist/components/layouts/FullPage.js.map +1 -1
  96. package/dist/components/layouts/HiddenChat.js +12 -237
  97. package/dist/components/layouts/HiddenChat.js.map +1 -1
  98. package/dist/components/layouts/Totem.js +10 -1
  99. package/dist/components/layouts/Totem.js.map +1 -1
  100. package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js +29 -2
  101. package/dist/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +1 -1
  102. package/dist/components/layouts/WebsiteAssistant/website-assistant.css +160 -59
  103. package/dist/components/layouts/ZoomedFullBody.js +36 -9
  104. package/dist/components/layouts/ZoomedFullBody.js.map +1 -1
  105. package/dist/components/layouts/chat.css +77 -63
  106. package/dist/components/layouts/fullpage.css +229 -84
  107. package/dist/components/layouts/hidden-chat.css +148 -33
  108. package/dist/components/layouts/totem.css +151 -50
  109. package/dist/components/layouts/zoomed-full-body.css +332 -33
  110. package/dist/context/widgetSurfaceContext.d.ts +3 -0
  111. package/dist/context/widgetSurfaceContext.js +11 -0
  112. package/dist/context/widgetSurfaceContext.js.map +1 -0
  113. package/dist/helpers/constants.d.ts +3 -0
  114. package/dist/helpers/constants.js +27 -1
  115. package/dist/helpers/constants.js.map +1 -1
  116. package/dist/helpers/credits.d.ts +5 -2
  117. package/dist/helpers/credits.js +5 -1
  118. package/dist/helpers/credits.js.map +1 -1
  119. package/dist/helpers/message.d.ts +1 -1
  120. package/dist/helpers/message.js +4 -4
  121. package/dist/helpers/message.js.map +1 -1
  122. package/dist/helpers/nats/getNatsConfig.d.ts +9 -0
  123. package/dist/helpers/nats/getNatsConfig.js +65 -0
  124. package/dist/helpers/nats/getNatsConfig.js.map +1 -0
  125. package/dist/helpers/nats/isSessionExpiredError.d.ts +3 -0
  126. package/dist/helpers/nats/isSessionExpiredError.js +36 -0
  127. package/dist/helpers/nats/isSessionExpiredError.js.map +1 -0
  128. package/dist/helpers/nats/useNats.d.ts +12 -0
  129. package/dist/helpers/nats/useNats.js +75 -0
  130. package/dist/helpers/nats/useNats.js.map +1 -0
  131. package/dist/helpers/nats/useNatsSession.d.ts +28 -0
  132. package/dist/helpers/nats/useNatsSession.js +212 -0
  133. package/dist/helpers/nats/useNatsSession.js.map +1 -0
  134. package/dist/helpers/positionPopover.d.ts +1 -0
  135. package/dist/helpers/positionPopover.js +7 -0
  136. package/dist/helpers/positionPopover.js.map +1 -0
  137. package/dist/helpers/usePressTooltip.d.ts +13 -0
  138. package/dist/helpers/usePressTooltip.js +23 -0
  139. package/dist/helpers/usePressTooltip.js.map +1 -0
  140. package/dist/helpers/utils.d.ts +21 -0
  141. package/dist/helpers/utils.js +75 -4
  142. package/dist/helpers/utils.js.map +1 -1
  143. package/dist/locales/de.json +11 -1
  144. package/dist/locales/en.json +12 -2
  145. package/dist/locales/es.json +11 -1
  146. package/dist/locales/fr.json +11 -1
  147. package/dist/locales/it.json +12 -2
  148. package/dist/styles.css +1 -161
  149. package/dist/types/integration.d.ts +3 -0
  150. package/dist/types/integration.js +16 -0
  151. package/dist/types/integration.js.map +1 -0
  152. package/dist/version.d.ts +1 -1
  153. package/dist/version.js +1 -1
  154. package/dist/version.js.map +1 -1
  155. package/esm/components/AgeVerificationModal/AgeVerificationModal.js +8 -3
  156. package/esm/components/AgeVerificationModal/AgeVerificationModal.js.map +1 -1
  157. package/esm/components/Auth/Auth.js +3 -1
  158. package/esm/components/Auth/Auth.js.map +1 -1
  159. package/esm/components/Avatar/Avatar.js +5 -10
  160. package/esm/components/Avatar/Avatar.js.map +1 -1
  161. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +9 -2
  162. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  163. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +2 -2
  164. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
  165. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +2 -0
  166. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js +13 -4
  167. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
  168. package/esm/components/Chat/Chat.css +108 -20
  169. package/esm/components/Chat/Chat.d.ts +3 -0
  170. package/esm/components/Chat/Chat.js +63 -55
  171. package/esm/components/Chat/Chat.js.map +1 -1
  172. package/esm/components/ChatBubble/ChatBubble.css +42 -14
  173. package/esm/components/ChatBubble/ChatBubble.js +24 -16
  174. package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
  175. package/esm/components/ChatHistoryDrawer/ChatHistory.css +4 -0
  176. package/esm/components/ChatHistoryDrawer/ChatHistory.js +27 -10
  177. package/esm/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
  178. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.d.ts +0 -1
  179. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.js +0 -1
  180. package/esm/components/ChatHistoryDrawer/ChatResumeDrawer.js.map +1 -1
  181. package/esm/components/ChatInputs/ChatInputs.css +292 -108
  182. package/esm/components/ChatInputs/ChatInputs.d.ts +1 -0
  183. package/esm/components/ChatInputs/ChatInputs.js +2 -2
  184. package/esm/components/ChatInputs/ChatInputs.js.map +1 -1
  185. package/esm/components/ChatTextArea/ChatTextArea.css +30 -6
  186. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js +6 -3
  187. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  188. package/esm/components/ContentPreviewModal/ContentPreviewModal.js +3 -1
  189. package/esm/components/ContentPreviewModal/ContentPreviewModal.js.map +1 -1
  190. package/esm/components/DateSelector/DateSelector.d.ts +2 -1
  191. package/esm/components/DateSelector/DateSelector.js +17 -7
  192. package/esm/components/DateSelector/DateSelector.js.map +1 -1
  193. package/esm/components/ExpertsDrawer/ExpertsDrawer.js +3 -1
  194. package/esm/components/ExpertsDrawer/ExpertsDrawer.js.map +1 -1
  195. package/esm/components/FilePreview/FilePreview.js +24 -7
  196. package/esm/components/FilePreview/FilePreview.js.map +1 -1
  197. package/esm/components/Header/ChatConsumptionDropdown.d.ts +3 -1
  198. package/esm/components/Header/ChatConsumptionDropdown.js +5 -4
  199. package/esm/components/Header/ChatConsumptionDropdown.js.map +1 -1
  200. package/esm/components/Header/Header.css +16 -10
  201. package/esm/components/Header/Header.js +104 -23
  202. package/esm/components/Header/Header.js.map +1 -1
  203. package/esm/components/KnownFacts/KnownFacts.js +7 -5
  204. package/esm/components/KnownFacts/KnownFacts.js.map +1 -1
  205. package/esm/components/LoginDrawer/LoginDrawer.css +1 -0
  206. package/esm/components/LoginDrawer/LoginDrawer.js +3 -1
  207. package/esm/components/LoginDrawer/LoginDrawer.js.map +1 -1
  208. package/esm/components/MediaWidget/MediaItemWidget.js +16 -14
  209. package/esm/components/MediaWidget/MediaItemWidget.js.map +1 -1
  210. package/esm/components/MediaWidget/MediaItemWidget.utils.d.ts +3 -2
  211. package/esm/components/MediaWidget/MediaItemWidget.utils.js +27 -6
  212. package/esm/components/MediaWidget/MediaItemWidget.utils.js.map +1 -1
  213. package/esm/components/MediaWidget/MediaPreviewModal.js +6 -7
  214. package/esm/components/MediaWidget/MediaPreviewModal.js.map +1 -1
  215. package/esm/components/MemoriArtifactSystem/components/ArtifactActions/styles.css +5 -4
  216. package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +108 -42
  217. package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.d.ts +1 -0
  218. package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js +18 -10
  219. package/esm/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.js.map +1 -1
  220. package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +2 -2
  221. package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
  222. package/esm/components/MemoriWidget/MemoriWidget.css +5 -5
  223. package/esm/components/MemoriWidget/MemoriWidget.d.ts +1 -0
  224. package/esm/components/MemoriWidget/MemoriWidget.js +789 -431
  225. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  226. package/esm/components/MicrophoneButton/MicrophoneButton.css +50 -18
  227. package/esm/components/MobileSessionPanel/MobileSessionPanel.d.ts +3 -2
  228. package/esm/components/MobileSessionPanel/MobileSessionPanel.js +5 -5
  229. package/esm/components/MobileSessionPanel/MobileSessionPanel.js.map +1 -1
  230. package/esm/components/PoweredBy/PoweredBy.css +10 -2
  231. package/esm/components/SettingsDrawer/SettingsDrawer.js +3 -1
  232. package/esm/components/SettingsDrawer/SettingsDrawer.js.map +1 -1
  233. package/esm/components/ShareButton/ShareButton.js +2 -4
  234. package/esm/components/ShareButton/ShareButton.js.map +1 -1
  235. package/esm/components/StartPanel/StartPanel.js +13 -6
  236. package/esm/components/StartPanel/StartPanel.js.map +1 -1
  237. package/esm/components/UploadButton/UploadButton.js +21 -5
  238. package/esm/components/UploadButton/UploadButton.js.map +1 -1
  239. package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js +126 -60
  240. package/esm/components/UploadButton/UploadDocuments/UploadDocuments.js.map +1 -1
  241. package/esm/components/UploadButton/UploadImages/UploadImages.js +4 -2
  242. package/esm/components/UploadButton/UploadImages/UploadImages.js.map +1 -1
  243. package/esm/components/WhyThisAnswer/WhyThisAnswer.js +3 -1
  244. package/esm/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
  245. package/esm/components/layouts/Chat.js +25 -30
  246. package/esm/components/layouts/Chat.js.map +1 -1
  247. package/esm/components/layouts/FullPage.js +36 -9
  248. package/esm/components/layouts/FullPage.js.map +1 -1
  249. package/esm/components/layouts/HiddenChat.js +14 -239
  250. package/esm/components/layouts/HiddenChat.js.map +1 -1
  251. package/esm/components/layouts/Totem.js +10 -1
  252. package/esm/components/layouts/Totem.js.map +1 -1
  253. package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js +29 -2
  254. package/esm/components/layouts/WebsiteAssistant/WebsiteAssistant.js.map +1 -1
  255. package/esm/components/layouts/WebsiteAssistant/website-assistant.css +160 -59
  256. package/esm/components/layouts/ZoomedFullBody.js +36 -9
  257. package/esm/components/layouts/ZoomedFullBody.js.map +1 -1
  258. package/esm/components/layouts/chat.css +77 -63
  259. package/esm/components/layouts/fullpage.css +229 -84
  260. package/esm/components/layouts/hidden-chat.css +148 -33
  261. package/esm/components/layouts/totem.css +151 -50
  262. package/esm/components/layouts/zoomed-full-body.css +332 -33
  263. package/esm/context/widgetSurfaceContext.d.ts +3 -0
  264. package/esm/context/widgetSurfaceContext.js +7 -0
  265. package/esm/context/widgetSurfaceContext.js.map +1 -0
  266. package/esm/helpers/constants.d.ts +3 -0
  267. package/esm/helpers/constants.js +26 -0
  268. package/esm/helpers/constants.js.map +1 -1
  269. package/esm/helpers/credits.d.ts +5 -2
  270. package/esm/helpers/credits.js +5 -1
  271. package/esm/helpers/credits.js.map +1 -1
  272. package/esm/helpers/message.d.ts +1 -1
  273. package/esm/helpers/message.js +2 -2
  274. package/esm/helpers/message.js.map +1 -1
  275. package/esm/helpers/nats/getNatsConfig.d.ts +9 -0
  276. package/esm/helpers/nats/getNatsConfig.js +61 -0
  277. package/esm/helpers/nats/getNatsConfig.js.map +1 -0
  278. package/esm/helpers/nats/isSessionExpiredError.d.ts +3 -0
  279. package/esm/helpers/nats/isSessionExpiredError.js +32 -0
  280. package/esm/helpers/nats/isSessionExpiredError.js.map +1 -0
  281. package/esm/helpers/nats/useNats.d.ts +12 -0
  282. package/esm/helpers/nats/useNats.js +72 -0
  283. package/esm/helpers/nats/useNats.js.map +1 -0
  284. package/esm/helpers/nats/useNatsSession.d.ts +28 -0
  285. package/esm/helpers/nats/useNatsSession.js +208 -0
  286. package/esm/helpers/nats/useNatsSession.js.map +1 -0
  287. package/esm/helpers/positionPopover.d.ts +1 -0
  288. package/esm/helpers/positionPopover.js +4 -0
  289. package/esm/helpers/positionPopover.js.map +1 -0
  290. package/esm/helpers/usePressTooltip.d.ts +13 -0
  291. package/esm/helpers/usePressTooltip.js +20 -0
  292. package/esm/helpers/usePressTooltip.js.map +1 -0
  293. package/esm/helpers/utils.d.ts +21 -0
  294. package/esm/helpers/utils.js +68 -3
  295. package/esm/helpers/utils.js.map +1 -1
  296. package/esm/locales/de.json +11 -1
  297. package/esm/locales/en.json +12 -2
  298. package/esm/locales/es.json +11 -1
  299. package/esm/locales/fr.json +11 -1
  300. package/esm/locales/it.json +12 -2
  301. package/esm/styles.css +1 -161
  302. package/esm/types/integration.d.ts +3 -0
  303. package/esm/types/integration.js +11 -0
  304. package/esm/types/integration.js.map +1 -0
  305. package/esm/version.d.ts +1 -1
  306. package/esm/version.js +1 -1
  307. package/esm/version.js.map +1 -1
  308. package/package.json +13 -6
  309. package/src/components/AgeVerificationModal/AgeVerificationModal.tsx +9 -1
  310. package/src/components/Auth/Auth.tsx +3 -0
  311. package/src/components/Avatar/Avatar.stories.tsx +45 -28
  312. package/src/components/Avatar/Avatar.test.tsx +54 -0
  313. package/src/components/Avatar/Avatar.tsx +8 -12
  314. package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.tsx +12 -5
  315. package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.ts +2 -1
  316. package/src/components/Avatar/AvatarView/AvatarComponent/constants.ts +16 -4
  317. package/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +164 -0
  318. package/src/components/BlockedMemoriBadge/__snapshots__/BlockedMemoriBadge.test.tsx.snap +10 -10
  319. package/src/components/Chat/Chat.css +108 -20
  320. package/src/components/Chat/Chat.tsx +28 -0
  321. package/src/components/Chat/__snapshots__/Chat.test.tsx.snap +7449 -7369
  322. package/src/components/ChatBubble/ChatBubble.css +42 -14
  323. package/src/components/ChatBubble/ChatBubble.tsx +44 -12
  324. package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +90 -90
  325. package/src/components/ChatHistoryDrawer/ChatHistory.css +4 -0
  326. package/src/components/ChatHistoryDrawer/ChatHistory.test.tsx +77 -1
  327. package/src/components/ChatHistoryDrawer/ChatHistory.tsx +59 -27
  328. package/src/components/ChatHistoryDrawer/ChatResumeDrawer.tsx +0 -1
  329. package/src/components/ChatInputs/ChatInputs.css +292 -108
  330. package/src/components/ChatInputs/ChatInputs.tsx +14 -4
  331. package/src/components/ChatTextArea/ChatTextArea.css +30 -6
  332. package/src/components/CompletionProviderStatus/CompletionProviderStatus.tsx +8 -4
  333. package/src/components/CompletionProviderStatus/__snapshots__/CompletionProviderStatus.test.tsx.snap +6 -6
  334. package/src/components/ContentPreviewModal/ContentPreviewModal.tsx +3 -0
  335. package/src/components/DateSelector/DateSelector.stories.tsx +11 -2
  336. package/src/components/DateSelector/DateSelector.tsx +28 -9
  337. package/src/components/ExpertsDrawer/ExpertsDrawer.tsx +3 -0
  338. package/src/components/FeedbackButtons/__snapshots__/FeedbackButtons.test.tsx.snap +2 -2
  339. package/src/components/FilePreview/FilePreview.tsx +28 -7
  340. package/src/components/Header/ChatConsumptionDropdown.tsx +16 -5
  341. package/src/components/Header/Header.css +16 -10
  342. package/src/components/Header/Header.tsx +331 -53
  343. package/src/components/Header/__snapshots__/Header.test.tsx.snap +109 -83
  344. package/src/components/KnownFacts/KnownFacts.tsx +7 -0
  345. package/src/components/LoginDrawer/LoginDrawer.css +1 -0
  346. package/src/components/LoginDrawer/LoginDrawer.tsx +3 -0
  347. package/src/components/MediaWidget/MediaItemWidget.tsx +26 -13
  348. package/src/components/MediaWidget/MediaItemWidget.utils.test.ts +45 -2
  349. package/src/components/MediaWidget/MediaItemWidget.utils.ts +39 -6
  350. package/src/components/MediaWidget/MediaPreviewModal.tsx +9 -7
  351. package/src/components/MemoriArtifactSystem/ArtifactDrawer.stories.tsx +218 -2252
  352. package/src/components/MemoriArtifactSystem/components/ArtifactActions/styles.css +5 -4
  353. package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.css +108 -42
  354. package/src/components/MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer.tsx +35 -14
  355. package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.tsx +4 -3
  356. package/src/components/MemoriWidget/MemoriWidget.css +5 -5
  357. package/src/components/MemoriWidget/MemoriWidget.tsx +1234 -729
  358. package/src/components/MicrophoneButton/MicrophoneButton.css +50 -18
  359. package/src/components/MobileSessionPanel/MobileSessionPanel.tsx +44 -31
  360. package/src/components/PoweredBy/PoweredBy.css +10 -2
  361. package/src/components/SettingsDrawer/SettingsDrawer.tsx +3 -0
  362. package/src/components/ShareButton/ShareButton.tsx +6 -3
  363. package/src/components/ShareButton/__snapshots__/ShareButton.test.tsx.snap +27 -18
  364. package/src/components/StartPanel/StartPanel.stories.tsx +22 -0
  365. package/src/components/StartPanel/StartPanel.test.tsx +64 -1
  366. package/src/components/StartPanel/StartPanel.tsx +29 -3
  367. package/src/components/StartPanel/__snapshots__/StartPanel.test.tsx.snap +293 -32
  368. package/src/components/UploadButton/UploadButton.tsx +30 -11
  369. package/src/components/UploadButton/UploadDocuments/UploadDocuments.tsx +151 -61
  370. package/src/components/UploadButton/UploadImages/UploadImages.tsx +4 -1
  371. package/src/components/UploadButton/__snapshots__/UploadButton.test.tsx.snap +4 -4
  372. package/src/components/WhyThisAnswer/WhyThisAnswer.tsx +3 -0
  373. package/src/components/layouts/Chat.tsx +147 -148
  374. package/src/components/layouts/FullPage.tsx +92 -25
  375. package/src/components/layouts/HiddenChat.tsx +21 -413
  376. package/src/components/layouts/Totem.tsx +20 -3
  377. package/src/components/layouts/WebsiteAssistant/WebsiteAssistant.tsx +71 -15
  378. package/src/components/layouts/WebsiteAssistant/__snapshots__/WebsiteAssistant.test.tsx.snap +48 -44
  379. package/src/components/layouts/WebsiteAssistant/website-assistant.css +160 -59
  380. package/src/components/layouts/ZoomedFullBody.tsx +95 -27
  381. package/src/components/layouts/__snapshots__/Chat.test.tsx.snap +610 -582
  382. package/src/components/layouts/__snapshots__/FullPage.test.tsx.snap +1235 -1165
  383. package/src/components/layouts/__snapshots__/HiddenChat.test.tsx.snap +542 -438
  384. package/src/components/layouts/__snapshots__/Totem.test.tsx.snap +579 -602
  385. package/src/components/layouts/__snapshots__/ZoomedFullBody.test.tsx.snap +599 -564
  386. package/src/components/layouts/chat.css +77 -63
  387. package/src/components/layouts/fullpage.css +229 -84
  388. package/src/components/layouts/hidden-chat.css +148 -33
  389. package/src/components/layouts/layouts.stories.tsx +133 -13
  390. package/src/components/layouts/totem.css +151 -50
  391. package/src/components/layouts/zoomed-full-body.css +332 -33
  392. package/src/context/widgetSurfaceContext.tsx +14 -0
  393. package/src/helpers/constants.ts +32 -1
  394. package/src/helpers/credits.ts +16 -1
  395. package/src/helpers/message.test.ts +28 -1
  396. package/src/helpers/message.ts +4 -4
  397. package/src/helpers/nats/getNatsConfig.ts +145 -0
  398. package/src/helpers/nats/isSessionExpiredError.test.ts +38 -0
  399. package/src/helpers/nats/isSessionExpiredError.ts +51 -0
  400. package/src/helpers/nats/useNats.ts +124 -0
  401. package/src/helpers/nats/useNatsSession.ts +394 -0
  402. package/src/helpers/positionPopover.test.ts +33 -0
  403. package/src/helpers/positionPopover.ts +13 -0
  404. package/src/helpers/usePressTooltip.ts +29 -0
  405. package/src/helpers/utils.test.ts +162 -0
  406. package/src/helpers/utils.ts +108 -3
  407. package/src/index.stories.tsx +32 -0
  408. package/src/locales/de.json +11 -1
  409. package/src/locales/en.json +12 -2
  410. package/src/locales/es.json +11 -1
  411. package/src/locales/fr.json +11 -1
  412. package/src/locales/it.json +12 -2
  413. package/src/styles.css +98 -12
  414. package/src/types/integration.test.ts +32 -0
  415. package/src/types/integration.ts +31 -0
  416. package/src/version.ts +1 -1
  417. package/dist/components/PositionDrawer/PositionDrawer.d.ts +0 -12
  418. package/dist/components/PositionDrawer/PositionDrawer.js +0 -17
  419. package/dist/components/PositionDrawer/PositionDrawer.js.map +0 -1
  420. package/dist/components/icons/AI.d.ts +0 -6
  421. package/dist/components/icons/AI.js +0 -6
  422. package/dist/components/icons/AI.js.map +0 -1
  423. package/dist/components/icons/Alert.d.ts +0 -6
  424. package/dist/components/icons/Alert.js +0 -6
  425. package/dist/components/icons/Alert.js.map +0 -1
  426. package/dist/components/icons/ArrowUp.d.ts +0 -6
  427. package/dist/components/icons/ArrowUp.js +0 -6
  428. package/dist/components/icons/ArrowUp.js.map +0 -1
  429. package/dist/components/icons/Bug.d.ts +0 -6
  430. package/dist/components/icons/Bug.js +0 -6
  431. package/dist/components/icons/Bug.js.map +0 -1
  432. package/dist/components/icons/Chat.d.ts +0 -6
  433. package/dist/components/icons/Chat.js +0 -6
  434. package/dist/components/icons/Chat.js.map +0 -1
  435. package/dist/components/icons/ChevronDown.d.ts +0 -6
  436. package/dist/components/icons/ChevronDown.js +0 -6
  437. package/dist/components/icons/ChevronDown.js.map +0 -1
  438. package/dist/components/icons/ChevronLeft.d.ts +0 -6
  439. package/dist/components/icons/ChevronLeft.js +0 -6
  440. package/dist/components/icons/ChevronLeft.js.map +0 -1
  441. package/dist/components/icons/ChevronRight.d.ts +0 -6
  442. package/dist/components/icons/ChevronRight.js +0 -6
  443. package/dist/components/icons/ChevronRight.js.map +0 -1
  444. package/dist/components/icons/ChevronUp.d.ts +0 -6
  445. package/dist/components/icons/ChevronUp.js +0 -6
  446. package/dist/components/icons/ChevronUp.js.map +0 -1
  447. package/dist/components/icons/Clear.d.ts +0 -6
  448. package/dist/components/icons/Clear.js +0 -6
  449. package/dist/components/icons/Clear.js.map +0 -1
  450. package/dist/components/icons/Close.d.ts +0 -7
  451. package/dist/components/icons/Close.js +0 -6
  452. package/dist/components/icons/Close.js.map +0 -1
  453. package/dist/components/icons/Code.d.ts +0 -6
  454. package/dist/components/icons/Code.js +0 -6
  455. package/dist/components/icons/Code.js.map +0 -1
  456. package/dist/components/icons/Copy.d.ts +0 -6
  457. package/dist/components/icons/Copy.js +0 -6
  458. package/dist/components/icons/Copy.js.map +0 -1
  459. package/dist/components/icons/DeepThought.d.ts +0 -6
  460. package/dist/components/icons/DeepThought.js +0 -6
  461. package/dist/components/icons/DeepThought.js.map +0 -1
  462. package/dist/components/icons/Delete.d.ts +0 -6
  463. package/dist/components/icons/Delete.js +0 -6
  464. package/dist/components/icons/Delete.js.map +0 -1
  465. package/dist/components/icons/Document.d.ts +0 -5
  466. package/dist/components/icons/Document.js +0 -10
  467. package/dist/components/icons/Document.js.map +0 -1
  468. package/dist/components/icons/Download.d.ts +0 -6
  469. package/dist/components/icons/Download.js +0 -6
  470. package/dist/components/icons/Download.js.map +0 -1
  471. package/dist/components/icons/Edit.d.ts +0 -6
  472. package/dist/components/icons/Edit.js +0 -6
  473. package/dist/components/icons/Edit.js.map +0 -1
  474. package/dist/components/icons/Expand.d.ts +0 -6
  475. package/dist/components/icons/Expand.js +0 -6
  476. package/dist/components/icons/Expand.js.map +0 -1
  477. package/dist/components/icons/Eye.d.ts +0 -6
  478. package/dist/components/icons/Eye.js +0 -6
  479. package/dist/components/icons/Eye.js.map +0 -1
  480. package/dist/components/icons/EyeInvisible.d.ts +0 -6
  481. package/dist/components/icons/EyeInvisible.js +0 -6
  482. package/dist/components/icons/EyeInvisible.js.map +0 -1
  483. package/dist/components/icons/Facebook.d.ts +0 -6
  484. package/dist/components/icons/Facebook.js +0 -6
  485. package/dist/components/icons/Facebook.js.map +0 -1
  486. package/dist/components/icons/Feedback.d.ts +0 -6
  487. package/dist/components/icons/Feedback.js +0 -6
  488. package/dist/components/icons/Feedback.js.map +0 -1
  489. package/dist/components/icons/File.d.ts +0 -6
  490. package/dist/components/icons/File.js +0 -6
  491. package/dist/components/icons/File.js.map +0 -1
  492. package/dist/components/icons/FileExcel.d.ts +0 -6
  493. package/dist/components/icons/FileExcel.js +0 -6
  494. package/dist/components/icons/FileExcel.js.map +0 -1
  495. package/dist/components/icons/FilePdf.d.ts +0 -6
  496. package/dist/components/icons/FilePdf.js +0 -6
  497. package/dist/components/icons/FilePdf.js.map +0 -1
  498. package/dist/components/icons/FileWord.d.ts +0 -6
  499. package/dist/components/icons/FileWord.js +0 -6
  500. package/dist/components/icons/FileWord.js.map +0 -1
  501. package/dist/components/icons/Fullscreen.d.ts +0 -6
  502. package/dist/components/icons/Fullscreen.js +0 -6
  503. package/dist/components/icons/Fullscreen.js.map +0 -1
  504. package/dist/components/icons/FullscreenExit.d.ts +0 -6
  505. package/dist/components/icons/FullscreenExit.js +0 -6
  506. package/dist/components/icons/FullscreenExit.js.map +0 -1
  507. package/dist/components/icons/Group.d.ts +0 -6
  508. package/dist/components/icons/Group.js +0 -6
  509. package/dist/components/icons/Group.js.map +0 -1
  510. package/dist/components/icons/History.d.ts +0 -7
  511. package/dist/components/icons/History.js +0 -6
  512. package/dist/components/icons/History.js.map +0 -1
  513. package/dist/components/icons/Image.d.ts +0 -4
  514. package/dist/components/icons/Image.js +0 -9
  515. package/dist/components/icons/Image.js.map +0 -1
  516. package/dist/components/icons/Info.d.ts +0 -6
  517. package/dist/components/icons/Info.js +0 -6
  518. package/dist/components/icons/Info.js.map +0 -1
  519. package/dist/components/icons/Link.d.ts +0 -6
  520. package/dist/components/icons/Link.js +0 -6
  521. package/dist/components/icons/Link.js.map +0 -1
  522. package/dist/components/icons/Linkedin.d.ts +0 -6
  523. package/dist/components/icons/Linkedin.js +0 -6
  524. package/dist/components/icons/Linkedin.js.map +0 -1
  525. package/dist/components/icons/Loading.d.ts +0 -7
  526. package/dist/components/icons/Loading.js +0 -10
  527. package/dist/components/icons/Loading.js.map +0 -1
  528. package/dist/components/icons/Logout.d.ts +0 -6
  529. package/dist/components/icons/Logout.js +0 -6
  530. package/dist/components/icons/Logout.js.map +0 -1
  531. package/dist/components/icons/Mail.d.ts +0 -6
  532. package/dist/components/icons/Mail.js +0 -6
  533. package/dist/components/icons/Mail.js.map +0 -1
  534. package/dist/components/icons/MapMarker.d.ts +0 -6
  535. package/dist/components/icons/MapMarker.js +0 -6
  536. package/dist/components/icons/MapMarker.js.map +0 -1
  537. package/dist/components/icons/MenuHorizontal.d.ts +0 -7
  538. package/dist/components/icons/MenuHorizontal.js +0 -6
  539. package/dist/components/icons/MenuHorizontal.js.map +0 -1
  540. package/dist/components/icons/MenuVertical.d.ts +0 -7
  541. package/dist/components/icons/MenuVertical.js +0 -6
  542. package/dist/components/icons/MenuVertical.js.map +0 -1
  543. package/dist/components/icons/Message.d.ts +0 -6
  544. package/dist/components/icons/Message.js +0 -6
  545. package/dist/components/icons/Message.js.map +0 -1
  546. package/dist/components/icons/Microphone.d.ts +0 -6
  547. package/dist/components/icons/Microphone.js +0 -6
  548. package/dist/components/icons/Microphone.js.map +0 -1
  549. package/dist/components/icons/Minus.d.ts +0 -6
  550. package/dist/components/icons/Minus.js +0 -6
  551. package/dist/components/icons/Minus.js.map +0 -1
  552. package/dist/components/icons/MinusCircle.d.ts +0 -6
  553. package/dist/components/icons/MinusCircle.js +0 -6
  554. package/dist/components/icons/MinusCircle.js.map +0 -1
  555. package/dist/components/icons/PaperClip.d.ts +0 -6
  556. package/dist/components/icons/PaperClip.js +0 -6
  557. package/dist/components/icons/PaperClip.js.map +0 -1
  558. package/dist/components/icons/Picture.d.ts +0 -6
  559. package/dist/components/icons/Picture.js +0 -6
  560. package/dist/components/icons/Picture.js.map +0 -1
  561. package/dist/components/icons/Plus.d.ts +0 -6
  562. package/dist/components/icons/Plus.js +0 -6
  563. package/dist/components/icons/Plus.js.map +0 -1
  564. package/dist/components/icons/Preview.d.ts +0 -4
  565. package/dist/components/icons/Preview.js +0 -9
  566. package/dist/components/icons/Preview.js.map +0 -1
  567. package/dist/components/icons/Print.d.ts +0 -6
  568. package/dist/components/icons/Print.js +0 -6
  569. package/dist/components/icons/Print.js.map +0 -1
  570. package/dist/components/icons/QuestionHelp.d.ts +0 -6
  571. package/dist/components/icons/QuestionHelp.js +0 -6
  572. package/dist/components/icons/QuestionHelp.js.map +0 -1
  573. package/dist/components/icons/Refresh.d.ts +0 -6
  574. package/dist/components/icons/Refresh.js +0 -6
  575. package/dist/components/icons/Refresh.js.map +0 -1
  576. package/dist/components/icons/SelectIcon.d.ts +0 -6
  577. package/dist/components/icons/SelectIcon.js +0 -6
  578. package/dist/components/icons/SelectIcon.js.map +0 -1
  579. package/dist/components/icons/Send.d.ts +0 -6
  580. package/dist/components/icons/Send.js +0 -6
  581. package/dist/components/icons/Send.js.map +0 -1
  582. package/dist/components/icons/Setting.d.ts +0 -6
  583. package/dist/components/icons/Setting.js +0 -6
  584. package/dist/components/icons/Setting.js.map +0 -1
  585. package/dist/components/icons/Share.d.ts +0 -6
  586. package/dist/components/icons/Share.js +0 -6
  587. package/dist/components/icons/Share.js.map +0 -1
  588. package/dist/components/icons/Sound.d.ts +0 -6
  589. package/dist/components/icons/Sound.js +0 -6
  590. package/dist/components/icons/Sound.js.map +0 -1
  591. package/dist/components/icons/SoundDeactivated.d.ts +0 -6
  592. package/dist/components/icons/SoundDeactivated.js +0 -6
  593. package/dist/components/icons/SoundDeactivated.js.map +0 -1
  594. package/dist/components/icons/Telegram.d.ts +0 -6
  595. package/dist/components/icons/Telegram.js +0 -6
  596. package/dist/components/icons/Telegram.js.map +0 -1
  597. package/dist/components/icons/ThumbDown.d.ts +0 -6
  598. package/dist/components/icons/ThumbDown.js +0 -6
  599. package/dist/components/icons/ThumbDown.js.map +0 -1
  600. package/dist/components/icons/ThumbUp.d.ts +0 -6
  601. package/dist/components/icons/ThumbUp.js +0 -6
  602. package/dist/components/icons/ThumbUp.js.map +0 -1
  603. package/dist/components/icons/Translation.d.ts +0 -6
  604. package/dist/components/icons/Translation.js +0 -6
  605. package/dist/components/icons/Translation.js.map +0 -1
  606. package/dist/components/icons/Twitter.d.ts +0 -6
  607. package/dist/components/icons/Twitter.js +0 -6
  608. package/dist/components/icons/Twitter.js.map +0 -1
  609. package/dist/components/icons/Upload.d.ts +0 -4
  610. package/dist/components/icons/Upload.js +0 -9
  611. package/dist/components/icons/Upload.js.map +0 -1
  612. package/dist/components/icons/User.d.ts +0 -6
  613. package/dist/components/icons/User.js +0 -6
  614. package/dist/components/icons/User.js.map +0 -1
  615. package/dist/components/icons/Warning.d.ts +0 -6
  616. package/dist/components/icons/Warning.js +0 -6
  617. package/dist/components/icons/Warning.js.map +0 -1
  618. package/dist/components/icons/WhatsApp.d.ts +0 -6
  619. package/dist/components/icons/WhatsApp.js +0 -6
  620. package/dist/components/icons/WhatsApp.js.map +0 -1
  621. package/dist/components/icons/loading.css +0 -14
  622. package/dist/components/layouts/WebsiteAssistant.d.ts +0 -4
  623. package/dist/components/layouts/WebsiteAssistant.js +0 -38
  624. package/dist/components/layouts/WebsiteAssistant.js.map +0 -1
  625. package/dist/components/layouts/website-assistant.css +0 -676
  626. package/dist/components/ui/Alert.css +0 -93
  627. package/dist/components/ui/Alert.d.ts +0 -18
  628. package/dist/components/ui/Alert.js +0 -42
  629. package/dist/components/ui/Alert.js.map +0 -1
  630. package/dist/components/ui/Button.css +0 -167
  631. package/dist/components/ui/Button.d.ts +0 -27
  632. package/dist/components/ui/Button.js +0 -23
  633. package/dist/components/ui/Button.js.map +0 -1
  634. package/dist/components/ui/Card.css +0 -65
  635. package/dist/components/ui/Card.d.ts +0 -13
  636. package/dist/components/ui/Card.js +0 -14
  637. package/dist/components/ui/Card.js.map +0 -1
  638. package/dist/components/ui/Checkbox.css +0 -116
  639. package/dist/components/ui/Checkbox.d.ts +0 -11
  640. package/dist/components/ui/Checkbox.js +0 -20
  641. package/dist/components/ui/Checkbox.js.map +0 -1
  642. package/dist/components/ui/ConfirmDialog.css +0 -42
  643. package/dist/components/ui/ConfirmDialog.d.ts +0 -11
  644. package/dist/components/ui/ConfirmDialog.js +0 -12
  645. package/dist/components/ui/ConfirmDialog.js.map +0 -1
  646. package/dist/components/ui/Details.css +0 -66
  647. package/dist/components/ui/Drawer.css +0 -270
  648. package/dist/components/ui/Drawer.d.ts +0 -46
  649. package/dist/components/ui/Drawer.js +0 -60
  650. package/dist/components/ui/Drawer.js.map +0 -1
  651. package/dist/components/ui/Dropdown.css +0 -173
  652. package/dist/components/ui/Dropdown.d.ts +0 -11
  653. package/dist/components/ui/Dropdown.js +0 -33
  654. package/dist/components/ui/Dropdown.js.map +0 -1
  655. package/dist/components/ui/Expandable.css +0 -15
  656. package/dist/components/ui/Expandable.d.ts +0 -15
  657. package/dist/components/ui/Expandable.js +0 -59
  658. package/dist/components/ui/Expandable.js.map +0 -1
  659. package/dist/components/ui/Modal.css +0 -98
  660. package/dist/components/ui/Modal.d.ts +0 -16
  661. package/dist/components/ui/Modal.js +0 -24
  662. package/dist/components/ui/Modal.js.map +0 -1
  663. package/dist/components/ui/Select.css +0 -138
  664. package/dist/components/ui/Select.d.ts +0 -17
  665. package/dist/components/ui/Select.js +0 -17
  666. package/dist/components/ui/Select.js.map +0 -1
  667. package/dist/components/ui/Slider.css +0 -192
  668. package/dist/components/ui/Slider.d.ts +0 -12
  669. package/dist/components/ui/Slider.js +0 -78
  670. package/dist/components/ui/Slider.js.map +0 -1
  671. package/dist/components/ui/Spin.css +0 -31
  672. package/dist/components/ui/Spin.d.ts +0 -9
  673. package/dist/components/ui/Spin.js +0 -12
  674. package/dist/components/ui/Spin.js.map +0 -1
  675. package/dist/components/ui/Table.css +0 -132
  676. package/dist/components/ui/Tooltip.css +0 -171
  677. package/dist/components/ui/Tooltip.d.ts +0 -11
  678. package/dist/components/ui/Tooltip.js +0 -90
  679. package/dist/components/ui/Tooltip.js.map +0 -1
  680. package/esm/components/PositionDrawer/PositionDrawer.d.ts +0 -12
  681. package/esm/components/PositionDrawer/PositionDrawer.js +0 -14
  682. package/esm/components/PositionDrawer/PositionDrawer.js.map +0 -1
  683. package/esm/components/icons/AI.d.ts +0 -6
  684. package/esm/components/icons/AI.js +0 -4
  685. package/esm/components/icons/AI.js.map +0 -1
  686. package/esm/components/icons/Alert.d.ts +0 -6
  687. package/esm/components/icons/Alert.js +0 -4
  688. package/esm/components/icons/Alert.js.map +0 -1
  689. package/esm/components/icons/ArrowUp.d.ts +0 -6
  690. package/esm/components/icons/ArrowUp.js +0 -4
  691. package/esm/components/icons/ArrowUp.js.map +0 -1
  692. package/esm/components/icons/Bug.d.ts +0 -6
  693. package/esm/components/icons/Bug.js +0 -4
  694. package/esm/components/icons/Bug.js.map +0 -1
  695. package/esm/components/icons/Chat.d.ts +0 -6
  696. package/esm/components/icons/Chat.js +0 -4
  697. package/esm/components/icons/Chat.js.map +0 -1
  698. package/esm/components/icons/ChevronDown.d.ts +0 -6
  699. package/esm/components/icons/ChevronDown.js +0 -4
  700. package/esm/components/icons/ChevronDown.js.map +0 -1
  701. package/esm/components/icons/ChevronLeft.d.ts +0 -6
  702. package/esm/components/icons/ChevronLeft.js +0 -4
  703. package/esm/components/icons/ChevronLeft.js.map +0 -1
  704. package/esm/components/icons/ChevronRight.d.ts +0 -6
  705. package/esm/components/icons/ChevronRight.js +0 -4
  706. package/esm/components/icons/ChevronRight.js.map +0 -1
  707. package/esm/components/icons/ChevronUp.d.ts +0 -6
  708. package/esm/components/icons/ChevronUp.js +0 -4
  709. package/esm/components/icons/ChevronUp.js.map +0 -1
  710. package/esm/components/icons/Clear.d.ts +0 -6
  711. package/esm/components/icons/Clear.js +0 -4
  712. package/esm/components/icons/Clear.js.map +0 -1
  713. package/esm/components/icons/Close.d.ts +0 -7
  714. package/esm/components/icons/Close.js +0 -4
  715. package/esm/components/icons/Close.js.map +0 -1
  716. package/esm/components/icons/Code.d.ts +0 -6
  717. package/esm/components/icons/Code.js +0 -4
  718. package/esm/components/icons/Code.js.map +0 -1
  719. package/esm/components/icons/Copy.d.ts +0 -6
  720. package/esm/components/icons/Copy.js +0 -4
  721. package/esm/components/icons/Copy.js.map +0 -1
  722. package/esm/components/icons/DeepThought.d.ts +0 -6
  723. package/esm/components/icons/DeepThought.js +0 -4
  724. package/esm/components/icons/DeepThought.js.map +0 -1
  725. package/esm/components/icons/Delete.d.ts +0 -6
  726. package/esm/components/icons/Delete.js +0 -4
  727. package/esm/components/icons/Delete.js.map +0 -1
  728. package/esm/components/icons/Document.d.ts +0 -5
  729. package/esm/components/icons/Document.js +0 -6
  730. package/esm/components/icons/Document.js.map +0 -1
  731. package/esm/components/icons/Download.d.ts +0 -6
  732. package/esm/components/icons/Download.js +0 -4
  733. package/esm/components/icons/Download.js.map +0 -1
  734. package/esm/components/icons/Edit.d.ts +0 -6
  735. package/esm/components/icons/Edit.js +0 -4
  736. package/esm/components/icons/Edit.js.map +0 -1
  737. package/esm/components/icons/Expand.d.ts +0 -6
  738. package/esm/components/icons/Expand.js +0 -4
  739. package/esm/components/icons/Expand.js.map +0 -1
  740. package/esm/components/icons/Eye.d.ts +0 -6
  741. package/esm/components/icons/Eye.js +0 -4
  742. package/esm/components/icons/Eye.js.map +0 -1
  743. package/esm/components/icons/EyeInvisible.d.ts +0 -6
  744. package/esm/components/icons/EyeInvisible.js +0 -4
  745. package/esm/components/icons/EyeInvisible.js.map +0 -1
  746. package/esm/components/icons/Facebook.d.ts +0 -6
  747. package/esm/components/icons/Facebook.js +0 -4
  748. package/esm/components/icons/Facebook.js.map +0 -1
  749. package/esm/components/icons/Feedback.d.ts +0 -6
  750. package/esm/components/icons/Feedback.js +0 -4
  751. package/esm/components/icons/Feedback.js.map +0 -1
  752. package/esm/components/icons/File.d.ts +0 -6
  753. package/esm/components/icons/File.js +0 -4
  754. package/esm/components/icons/File.js.map +0 -1
  755. package/esm/components/icons/FileExcel.d.ts +0 -6
  756. package/esm/components/icons/FileExcel.js +0 -4
  757. package/esm/components/icons/FileExcel.js.map +0 -1
  758. package/esm/components/icons/FilePdf.d.ts +0 -6
  759. package/esm/components/icons/FilePdf.js +0 -4
  760. package/esm/components/icons/FilePdf.js.map +0 -1
  761. package/esm/components/icons/FileWord.d.ts +0 -6
  762. package/esm/components/icons/FileWord.js +0 -4
  763. package/esm/components/icons/FileWord.js.map +0 -1
  764. package/esm/components/icons/Fullscreen.d.ts +0 -6
  765. package/esm/components/icons/Fullscreen.js +0 -4
  766. package/esm/components/icons/Fullscreen.js.map +0 -1
  767. package/esm/components/icons/FullscreenExit.d.ts +0 -6
  768. package/esm/components/icons/FullscreenExit.js +0 -4
  769. package/esm/components/icons/FullscreenExit.js.map +0 -1
  770. package/esm/components/icons/Group.d.ts +0 -6
  771. package/esm/components/icons/Group.js +0 -4
  772. package/esm/components/icons/Group.js.map +0 -1
  773. package/esm/components/icons/History.d.ts +0 -7
  774. package/esm/components/icons/History.js +0 -4
  775. package/esm/components/icons/History.js.map +0 -1
  776. package/esm/components/icons/Image.d.ts +0 -4
  777. package/esm/components/icons/Image.js +0 -5
  778. package/esm/components/icons/Image.js.map +0 -1
  779. package/esm/components/icons/Info.d.ts +0 -6
  780. package/esm/components/icons/Info.js +0 -4
  781. package/esm/components/icons/Info.js.map +0 -1
  782. package/esm/components/icons/Link.d.ts +0 -6
  783. package/esm/components/icons/Link.js +0 -4
  784. package/esm/components/icons/Link.js.map +0 -1
  785. package/esm/components/icons/Linkedin.d.ts +0 -6
  786. package/esm/components/icons/Linkedin.js +0 -4
  787. package/esm/components/icons/Linkedin.js.map +0 -1
  788. package/esm/components/icons/Loading.d.ts +0 -7
  789. package/esm/components/icons/Loading.js +0 -7
  790. package/esm/components/icons/Loading.js.map +0 -1
  791. package/esm/components/icons/Logout.d.ts +0 -6
  792. package/esm/components/icons/Logout.js +0 -4
  793. package/esm/components/icons/Logout.js.map +0 -1
  794. package/esm/components/icons/Mail.d.ts +0 -6
  795. package/esm/components/icons/Mail.js +0 -4
  796. package/esm/components/icons/Mail.js.map +0 -1
  797. package/esm/components/icons/MapMarker.d.ts +0 -6
  798. package/esm/components/icons/MapMarker.js +0 -4
  799. package/esm/components/icons/MapMarker.js.map +0 -1
  800. package/esm/components/icons/MenuHorizontal.d.ts +0 -7
  801. package/esm/components/icons/MenuHorizontal.js +0 -4
  802. package/esm/components/icons/MenuHorizontal.js.map +0 -1
  803. package/esm/components/icons/MenuVertical.d.ts +0 -7
  804. package/esm/components/icons/MenuVertical.js +0 -4
  805. package/esm/components/icons/MenuVertical.js.map +0 -1
  806. package/esm/components/icons/Message.d.ts +0 -6
  807. package/esm/components/icons/Message.js +0 -4
  808. package/esm/components/icons/Message.js.map +0 -1
  809. package/esm/components/icons/Microphone.d.ts +0 -6
  810. package/esm/components/icons/Microphone.js +0 -4
  811. package/esm/components/icons/Microphone.js.map +0 -1
  812. package/esm/components/icons/Minus.d.ts +0 -6
  813. package/esm/components/icons/Minus.js +0 -4
  814. package/esm/components/icons/Minus.js.map +0 -1
  815. package/esm/components/icons/MinusCircle.d.ts +0 -6
  816. package/esm/components/icons/MinusCircle.js +0 -4
  817. package/esm/components/icons/MinusCircle.js.map +0 -1
  818. package/esm/components/icons/PaperClip.d.ts +0 -6
  819. package/esm/components/icons/PaperClip.js +0 -4
  820. package/esm/components/icons/PaperClip.js.map +0 -1
  821. package/esm/components/icons/Picture.d.ts +0 -6
  822. package/esm/components/icons/Picture.js +0 -4
  823. package/esm/components/icons/Picture.js.map +0 -1
  824. package/esm/components/icons/Plus.d.ts +0 -6
  825. package/esm/components/icons/Plus.js +0 -4
  826. package/esm/components/icons/Plus.js.map +0 -1
  827. package/esm/components/icons/Preview.d.ts +0 -4
  828. package/esm/components/icons/Preview.js +0 -5
  829. package/esm/components/icons/Preview.js.map +0 -1
  830. package/esm/components/icons/Print.d.ts +0 -6
  831. package/esm/components/icons/Print.js +0 -4
  832. package/esm/components/icons/Print.js.map +0 -1
  833. package/esm/components/icons/QuestionHelp.d.ts +0 -6
  834. package/esm/components/icons/QuestionHelp.js +0 -4
  835. package/esm/components/icons/QuestionHelp.js.map +0 -1
  836. package/esm/components/icons/Refresh.d.ts +0 -6
  837. package/esm/components/icons/Refresh.js +0 -4
  838. package/esm/components/icons/Refresh.js.map +0 -1
  839. package/esm/components/icons/SelectIcon.d.ts +0 -6
  840. package/esm/components/icons/SelectIcon.js +0 -4
  841. package/esm/components/icons/SelectIcon.js.map +0 -1
  842. package/esm/components/icons/Send.d.ts +0 -6
  843. package/esm/components/icons/Send.js +0 -4
  844. package/esm/components/icons/Send.js.map +0 -1
  845. package/esm/components/icons/Setting.d.ts +0 -6
  846. package/esm/components/icons/Setting.js +0 -4
  847. package/esm/components/icons/Setting.js.map +0 -1
  848. package/esm/components/icons/Share.d.ts +0 -6
  849. package/esm/components/icons/Share.js +0 -4
  850. package/esm/components/icons/Share.js.map +0 -1
  851. package/esm/components/icons/Sound.d.ts +0 -6
  852. package/esm/components/icons/Sound.js +0 -4
  853. package/esm/components/icons/Sound.js.map +0 -1
  854. package/esm/components/icons/SoundDeactivated.d.ts +0 -6
  855. package/esm/components/icons/SoundDeactivated.js +0 -4
  856. package/esm/components/icons/SoundDeactivated.js.map +0 -1
  857. package/esm/components/icons/Telegram.d.ts +0 -6
  858. package/esm/components/icons/Telegram.js +0 -4
  859. package/esm/components/icons/Telegram.js.map +0 -1
  860. package/esm/components/icons/ThumbDown.d.ts +0 -6
  861. package/esm/components/icons/ThumbDown.js +0 -4
  862. package/esm/components/icons/ThumbDown.js.map +0 -1
  863. package/esm/components/icons/ThumbUp.d.ts +0 -6
  864. package/esm/components/icons/ThumbUp.js +0 -4
  865. package/esm/components/icons/ThumbUp.js.map +0 -1
  866. package/esm/components/icons/Translation.d.ts +0 -6
  867. package/esm/components/icons/Translation.js +0 -4
  868. package/esm/components/icons/Translation.js.map +0 -1
  869. package/esm/components/icons/Twitter.d.ts +0 -6
  870. package/esm/components/icons/Twitter.js +0 -4
  871. package/esm/components/icons/Twitter.js.map +0 -1
  872. package/esm/components/icons/Upload.d.ts +0 -4
  873. package/esm/components/icons/Upload.js +0 -5
  874. package/esm/components/icons/Upload.js.map +0 -1
  875. package/esm/components/icons/User.d.ts +0 -6
  876. package/esm/components/icons/User.js +0 -4
  877. package/esm/components/icons/User.js.map +0 -1
  878. package/esm/components/icons/Warning.d.ts +0 -6
  879. package/esm/components/icons/Warning.js +0 -4
  880. package/esm/components/icons/Warning.js.map +0 -1
  881. package/esm/components/icons/WhatsApp.d.ts +0 -6
  882. package/esm/components/icons/WhatsApp.js +0 -4
  883. package/esm/components/icons/WhatsApp.js.map +0 -1
  884. package/esm/components/icons/loading.css +0 -14
  885. package/esm/components/layouts/WebsiteAssistant.d.ts +0 -4
  886. package/esm/components/layouts/WebsiteAssistant.js +0 -35
  887. package/esm/components/layouts/WebsiteAssistant.js.map +0 -1
  888. package/esm/components/layouts/website-assistant.css +0 -676
  889. package/esm/components/ui/Alert.css +0 -93
  890. package/esm/components/ui/Alert.d.ts +0 -18
  891. package/esm/components/ui/Alert.js +0 -39
  892. package/esm/components/ui/Alert.js.map +0 -1
  893. package/esm/components/ui/Button.css +0 -167
  894. package/esm/components/ui/Button.d.ts +0 -27
  895. package/esm/components/ui/Button.js +0 -20
  896. package/esm/components/ui/Button.js.map +0 -1
  897. package/esm/components/ui/Card.css +0 -65
  898. package/esm/components/ui/Card.d.ts +0 -13
  899. package/esm/components/ui/Card.js +0 -11
  900. package/esm/components/ui/Card.js.map +0 -1
  901. package/esm/components/ui/Checkbox.css +0 -116
  902. package/esm/components/ui/Checkbox.d.ts +0 -11
  903. package/esm/components/ui/Checkbox.js +0 -17
  904. package/esm/components/ui/Checkbox.js.map +0 -1
  905. package/esm/components/ui/ConfirmDialog.css +0 -42
  906. package/esm/components/ui/ConfirmDialog.d.ts +0 -11
  907. package/esm/components/ui/ConfirmDialog.js +0 -9
  908. package/esm/components/ui/ConfirmDialog.js.map +0 -1
  909. package/esm/components/ui/Details.css +0 -66
  910. package/esm/components/ui/Drawer.css +0 -270
  911. package/esm/components/ui/Drawer.d.ts +0 -46
  912. package/esm/components/ui/Drawer.js +0 -57
  913. package/esm/components/ui/Drawer.js.map +0 -1
  914. package/esm/components/ui/Dropdown.css +0 -173
  915. package/esm/components/ui/Dropdown.d.ts +0 -11
  916. package/esm/components/ui/Dropdown.js +0 -30
  917. package/esm/components/ui/Dropdown.js.map +0 -1
  918. package/esm/components/ui/Expandable.css +0 -15
  919. package/esm/components/ui/Expandable.d.ts +0 -15
  920. package/esm/components/ui/Expandable.js +0 -56
  921. package/esm/components/ui/Expandable.js.map +0 -1
  922. package/esm/components/ui/Modal.css +0 -98
  923. package/esm/components/ui/Modal.d.ts +0 -16
  924. package/esm/components/ui/Modal.js +0 -21
  925. package/esm/components/ui/Modal.js.map +0 -1
  926. package/esm/components/ui/Select.css +0 -138
  927. package/esm/components/ui/Select.d.ts +0 -17
  928. package/esm/components/ui/Select.js +0 -14
  929. package/esm/components/ui/Select.js.map +0 -1
  930. package/esm/components/ui/Slider.css +0 -192
  931. package/esm/components/ui/Slider.d.ts +0 -12
  932. package/esm/components/ui/Slider.js +0 -75
  933. package/esm/components/ui/Slider.js.map +0 -1
  934. package/esm/components/ui/Spin.css +0 -31
  935. package/esm/components/ui/Spin.d.ts +0 -9
  936. package/esm/components/ui/Spin.js +0 -9
  937. package/esm/components/ui/Spin.js.map +0 -1
  938. package/esm/components/ui/Table.css +0 -132
  939. package/esm/components/ui/Tooltip.css +0 -171
  940. package/esm/components/ui/Tooltip.d.ts +0 -11
  941. package/esm/components/ui/Tooltip.js +0 -87
  942. package/esm/components/ui/Tooltip.js.map +0 -1
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ArtifactAPIBridge } from '../MemoriArtifactSystem/utils/ArtifactAPI';
3
3
  import { checkPii } from '../../helpers/piiDetection';
4
+ import { shouldRestartSessionOnPositionPopoverClose } from '../../helpers/positionPopover';
4
5
  import { useState, useEffect, useCallback, useRef, useMemo, } from 'react';
5
6
  import { useTranslation } from 'react-i18next';
6
7
  import memoriApiClient from '@memori.ai/memori-api-client';
7
8
  import cx from 'classnames';
8
9
  import { DateTime } from 'luxon';
9
- import { useAlertManager, createAlertOptions } from '@memori.ai/ui';
10
+ import { useAlertManager, createAlertOptions, MemoriUIProvider, } from '@memori.ai/ui';
11
+ import { WidgetSurfaceProvider } from '../../context/widgetSurfaceContext';
10
12
  import MemoriAuth from '../Auth/Auth';
11
13
  import Chat from '../Chat/Chat';
12
14
  import StartPanel from '../StartPanel/StartPanel';
@@ -37,6 +39,8 @@ import { sanitizeText } from '../../helpers/sanitizer';
37
39
  import { useTTS } from '../../helpers/tts/useTTS';
38
40
  import ChatHistoryDrawer from '../ChatHistoryDrawer/ChatHistory';
39
41
  import { useSTT } from '../../helpers/stt/useSTT';
42
+ import { useNats } from '../../helpers/nats/useNats';
43
+ import { isSessionExpiredNatsError, isSessionExpiredNatsResponse, } from '../../helpers/nats/isSessionExpiredError';
40
44
  const getMemoriState = (integrationId) => {
41
45
  var _a, _b, _c, _d, _f;
42
46
  let widget = integrationId
@@ -58,12 +62,23 @@ const getMemoriState = (integrationId) => {
58
62
  loginToken,
59
63
  };
60
64
  };
65
+ const resolveLoginTokenValue = (loginToken, userTokenRef, callAdditionalInfoLoginToken, additionalInfoLoginToken, authTokenProp) => {
66
+ var _a, _b, _c;
67
+ 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;
68
+ };
61
69
  const NULL_PLACE_SPEC = {
62
70
  placeName: null,
63
71
  latitude: null,
64
72
  longitude: null,
65
73
  uncertaintyKm: null,
66
74
  };
75
+ const logWidgetError = (context, detail) => {
76
+ console.error(`[MemoriWidget] ${context}`, detail !== null && detail !== void 0 ? detail : '');
77
+ };
78
+ function readCorrelationID(response) {
79
+ const value = response.correlationID;
80
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
81
+ }
67
82
  const typeMessage = (message, waitForPrevious = true, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false) => {
68
83
  const e = new CustomEvent('MemoriTextEntered', {
69
84
  detail: {
@@ -159,7 +174,6 @@ window.typeMessageHidden = typeMessageHidden;
159
174
  window.typeBatchMessages = typeBatchMessages;
160
175
  let audioContext;
161
176
  let memoriPassword;
162
- let userToken;
163
177
  export function getChatStyles(config) {
164
178
  var _a;
165
179
  const primary = config === null || config === void 0 ? void 0 : config.buttonBgColor;
@@ -170,18 +184,18 @@ export function getChatStyles(config) {
170
184
  '--memori-primary-color': primary,
171
185
  '--memori-primary': primary,
172
186
  '--memori-primary-content': primaryContent,
173
- '--memori-primary-hover': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, black) 15%)',
174
- '--memori-primary-active': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, black) 25%)',
187
+ '--memori-primary-hover': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, black) 15%)',
188
+ '--memori-primary-active': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, black) 25%)',
175
189
  '--memori-primary-disabled': 'color-mix(in oklch, var(--memori-primary), transparent 60%)',
176
- '--memori-primary-subtle': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, white) 60%)',
177
- '--memori-primary-subtle-hover': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, white) 50%)',
190
+ '--memori-primary-subtle': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, white) 60%)',
191
+ '--memori-primary-subtle-hover': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, white) 50%)',
178
192
  '--memori-border-primary': 'color-mix(in oklch, var(--memori-primary), transparent 70%)',
179
193
  '--memori-border-primary-hover': 'color-mix(in oklch, var(--memori-primary), transparent 50%)',
180
194
  '--memori-focus-ring-color': 'color-mix(in oklch, var(--memori-primary), transparent 80%)',
181
195
  '--memori-focus-ring': '0 0 0 3px var(--memori-focus-ring-color)',
182
196
  '--memori-shadow-primary': '0 8px 16px -4px color-mix(in oklch, var(--memori-primary), transparent 70%)',
183
- '--memori-skeleton-base': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, white) 85%)',
184
- '--memori-skeleton-highlight': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast, white) 75%)',
197
+ '--memori-skeleton-base': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, white) 85%)',
198
+ '--memori-skeleton-highlight': 'color-mix(in oklch, var(--memori-primary), var(--memori-surface-contrast-inverse, white) 75%)',
185
199
  };
186
200
  }
187
201
  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, }) => {
@@ -193,59 +207,88 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
193
207
  setIsClient(true);
194
208
  }, []);
195
209
  const client = memoriApiClient(apiURL, engineURL);
196
- const { initSession, deleteSession, postTextEnteredEvent, postPlaceChangedEvent, postDateChangedEvent, postTagChangedEvent, getSession, getExpertReferences, getSessionChatLogs, } = client;
210
+ const { initSession, deleteSession, postEnterTextAsync, postTextEnteredEvent, postPlaceChangedEvent, postDateChangedEvent, postTagChangedEvent, getSession, getExpertReferences, getSessionChatLogs, } = client;
197
211
  const [instruct, setInstruct] = useState(false);
198
212
  const [enableFocusChatInput, setEnableFocusChatInput] = useState(true);
199
- const widgetRootRef = useRef(null);
213
+ const [widgetRootEl, setWidgetRootEl] = useState(null);
214
+ const [widgetSurfaceEl, setWidgetSurfaceEl] = useState(null);
200
215
  const [isDarkTheme, setIsDarkTheme] = useState(false);
201
216
  useEffect(() => {
202
217
  var _a;
203
- const el = widgetRootRef.current;
204
- if (!el)
218
+ if (!widgetRootEl)
205
219
  return;
206
220
  const check = () => {
207
- setIsDarkTheme(!!el.closest('[data-theme="dark"]'));
221
+ setIsDarkTheme(!!widgetRootEl.closest('[data-theme="dark"]'));
208
222
  };
209
223
  check();
210
224
  const observer = new MutationObserver(check);
211
- const parent = (_a = el.parentElement) !== null && _a !== void 0 ? _a : document.body;
225
+ const parent = (_a = widgetRootEl.parentElement) !== null && _a !== void 0 ? _a : document.body;
212
226
  observer.observe(parent, {
213
227
  attributes: true,
214
228
  attributeFilter: ['data-theme'],
215
229
  subtree: true,
216
230
  });
217
231
  return () => observer.disconnect();
218
- }, []);
232
+ }, [widgetRootEl]);
219
233
  const [loginToken, setLoginToken] = useState((_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken);
234
+ const userTokenRef = useRef((_b = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _b !== void 0 ? _b : authToken);
235
+ const prevPropsLoginTokenRef = useRef((_c = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _c !== void 0 ? _c : authToken);
220
236
  const [user, setUser] = useState({
221
237
  avatarURL: typeof userAvatar === 'string' ? userAvatar : undefined,
222
238
  });
239
+ 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]);
223
240
  useEffect(() => {
224
- if (loginToken &&
225
- !(user === null || user === void 0 ? void 0 : user.userID) &&
226
- (showLogin || memori.requireLoginToken)) {
227
- client.backend
228
- .pwlGetCurrentUser(loginToken)
229
- .then(({ user, resultCode }) => {
230
- if (user && resultCode === 0) {
231
- setUser(user);
232
- setLocalConfig('loginToken', loginToken);
233
- if (!birthDate && user.birthDate) {
234
- setBirthDate(user.birthDate);
235
- setLocalConfig('birthDate', user.birthDate);
236
- }
237
- }
238
- else {
239
- removeLocalConfig('loginToken');
240
- }
241
- });
241
+ var _a;
242
+ const incomingToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
243
+ const prevPropsToken = prevPropsLoginTokenRef.current;
244
+ prevPropsLoginTokenRef.current = incomingToken;
245
+ if (incomingToken !== prevPropsToken) {
246
+ setLoginToken(incomingToken);
247
+ userTokenRef.current = incomingToken;
248
+ if (!incomingToken) {
249
+ removeLocalConfig('loginToken');
250
+ setUser(undefined);
251
+ }
242
252
  }
243
- }, [loginToken, user === null || user === void 0 ? void 0 : user.userID]);
253
+ }, [additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
254
+ useEffect(() => {
255
+ if (!loginToken || !(showLogin || memori.requireLoginToken)) {
256
+ return;
257
+ }
258
+ let cancelled = false;
259
+ client.backend
260
+ .pwlGetCurrentUser(loginToken)
261
+ .then(({ user: fetchedUser, resultCode }) => {
262
+ if (cancelled)
263
+ return;
264
+ if (fetchedUser && resultCode === 0) {
265
+ setUser(fetchedUser);
266
+ setLocalConfig('loginToken', loginToken);
267
+ userTokenRef.current = loginToken;
268
+ if (!birthDate && fetchedUser.birthDate) {
269
+ setBirthDate(fetchedUser.birthDate);
270
+ setLocalConfig('birthDate', fetchedUser.birthDate);
271
+ }
272
+ }
273
+ else {
274
+ setLoginToken(undefined);
275
+ userTokenRef.current = undefined;
276
+ setUser(undefined);
277
+ removeLocalConfig('loginToken');
278
+ }
279
+ });
280
+ return () => {
281
+ cancelled = true;
282
+ };
283
+ }, [loginToken, showLogin, memori.requireLoginToken]);
244
284
  const [showLoginDrawer, setShowLoginDrawer] = useState(false);
245
285
  const [clickedStart, setClickedStart] = useState(false);
246
286
  const [gotErrorInOpening, setGotErrorInOpening] = useState(false);
247
- 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()) ||
248
- ((_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());
287
+ const sessionStartingRef = useRef(false);
288
+ const needsCredits = tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation;
289
+ const [hasEnoughCredits, setHasEnoughCredits] = useState(true);
290
+ 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()) ||
291
+ ((_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());
249
292
  const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
250
293
  ? JSON.parse(integration.customData)
251
294
  : null;
@@ -253,7 +296,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
253
296
  ? multilingual
254
297
  : !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.multilanguage);
255
298
  const forcedTimeout = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.forcedTimeout;
256
- 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');
299
+ 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');
257
300
  useEffect(() => {
258
301
  if (spokenLang != null) {
259
302
  setUserLang(spokenLang);
@@ -279,6 +322,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
279
322
  const [loading, setLoading] = useState(false);
280
323
  const [memoriTyping, setMemoriTyping] = useState(false);
281
324
  const [typingText, setTypingText] = useState();
325
+ const pendingEnterTextRef = useRef(new Map());
326
+ const bufferedNatsResponsesRef = useRef(new Map());
282
327
  const layoutName = typeof layout === 'string'
283
328
  ? layout
284
329
  : layout &&
@@ -289,7 +334,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
289
334
  ? layout.name
290
335
  : typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'string'
291
336
  ? integrationConfig.layout
292
- : (_q = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _q === void 0 ? void 0 : _q.name;
337
+ : (_s = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _s === void 0 ? void 0 : _s.name;
293
338
  const selectedLayout = (() => {
294
339
  if (typeof layoutName === 'string') {
295
340
  const lower = layoutName.toLowerCase();
@@ -317,14 +362,14 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
317
362
  typeof layout === 'object' &&
318
363
  layout !== null &&
319
364
  'piiDetection' in layout &&
320
- ((_r = layout.piiDetection) === null || _r === void 0 ? void 0 : _r.enabled)
365
+ ((_t = layout.piiDetection) === null || _t === void 0 ? void 0 : _t.enabled)
321
366
  ? layout.piiDetection
322
367
  : typeof (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === 'object' &&
323
368
  (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) !== null &&
324
- ((_t = (_s = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) === null || _s === void 0 ? void 0 : _s.piiDetection) === null || _t === void 0 ? void 0 : _t.enabled)
369
+ ((_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)
325
370
  ? integrationConfig.layout.piiDetection
326
371
  : undefined;
327
- const defaultEnableAudio = (_u = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _u !== void 0 ? _u : true;
372
+ const defaultEnableAudio = (_w = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _w !== void 0 ? _w : true;
328
373
  const [hasUserActivatedListening, setHasUserActivatedListening] = useState(false);
329
374
  const [hasUserTypedMessage, setHasUserTypedMessage] = useState(false);
330
375
  const [positionPopoverOpen, setPositionPopoverOpenState] = useState(false);
@@ -367,7 +412,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
367
412
  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));
368
413
  if (!(additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) && !authToken) {
369
414
  setLoginToken(getLocalConfig('loginToken', undefined));
370
- userToken = getLocalConfig('loginToken', undefined);
415
+ userTokenRef.current = getLocalConfig('loginToken', undefined);
371
416
  setBirthDate(getLocalConfig('birthDate', undefined));
372
417
  }
373
418
  if (!((_b = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _b !== void 0 ? _b : true)) {
@@ -465,8 +510,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
465
510
  });
466
511
  };
467
512
  const [chatLogID, setChatLogID] = useState(undefined);
468
- const sendMessage = async (text, media, newSessionId, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false) => {
469
- var _a, _b, _c, _d, _f, _g;
513
+ const sendMessage = async (text, media, newSessionId, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false, skipHistoryPush = false) => {
514
+ var _a, _b;
470
515
  const sessionID = newSessionId ||
471
516
  sessionId ||
472
517
  ((_a = window.getMemoriState()) === null || _a === void 0 ? void 0 : _a.sessionID);
@@ -510,7 +555,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
510
555
  return;
511
556
  }
512
557
  }
513
- if (!hidden)
558
+ if (!hidden && !skipHistoryPush)
514
559
  pushMessage({
515
560
  text: text,
516
561
  translatedText,
@@ -520,12 +565,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
520
565
  ? !!newSessionId && newSessionId !== sessionId
521
566
  : !!newSessionId,
522
567
  });
523
- setMemoriTyping(true);
524
- setTypingText(typingText);
525
568
  let gotError = false;
526
569
  try {
527
570
  const placeSpec = getPlaceSpecForEnterText(position);
528
- const { currentState, ...response } = await postTextEnteredEvent({
571
+ const response = await postEnterTextAsync({
529
572
  sessionId: sessionID,
530
573
  text: msg,
531
574
  ...(memori.needsDateTime && {
@@ -533,65 +576,37 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
533
576
  }),
534
577
  ...(placeSpec !== undefined && { place: placeSpec }),
535
578
  });
536
- if (response.resultCode === 0 && currentState) {
537
- setChatLogID(undefined);
538
- const emission = useLoaderTextAsMsg && typingText
539
- ? typingText
540
- : (_c = currentState.emission) !== null && _c !== void 0 ? _c : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
541
- if (userLang.toLowerCase() !== language.toLowerCase() &&
542
- emission &&
543
- isMultilanguageEnabled) {
544
- currentState.emission = emission;
545
- translateDialogState(currentState, userLang, msg).then(ts => {
546
- let text = ts.translatedEmission || ts.emission;
547
- if (text && shouldPlayAudio(text)) {
548
- handleSpeak(text);
549
- }
550
- });
551
- }
552
- else {
553
- setCurrentDialogState({
554
- ...currentState,
555
- emission,
556
- });
557
- if (emission) {
558
- pushMessage({
559
- text: emission,
560
- emitter: currentState.emitter,
561
- media: (_d = currentState.emittedMedia) !== null && _d !== void 0 ? _d : currentState.media,
562
- llmUsage: currentState.llmUsage,
563
- fromUser: false,
564
- questionAnswered: msg,
565
- generatedByAI: !!currentState.completion,
566
- contextVars: currentState.contextVars,
567
- date: currentState.currentDate,
568
- placeName: currentState.currentPlaceName,
569
- placeLatitude: currentState.currentLatitude,
570
- placeLongitude: currentState.currentLongitude,
571
- placeUncertaintyKm: currentState.currentUncertaintyKm,
572
- tag: currentState.currentTag,
573
- memoryTags: currentState.memoryTags,
574
- });
575
- if (emission && shouldPlayAudio(emission)) {
576
- handleSpeak(emission);
577
- }
578
- }
579
- }
579
+ const correlationID = readCorrelationID(response);
580
+ if (response.resultCode === 0 && correlationID) {
581
+ registerPendingEnterText(correlationID, {
582
+ msg,
583
+ text,
584
+ media,
585
+ translate,
586
+ translatedText,
587
+ hidden,
588
+ typingText,
589
+ useLoaderTextAsMsg,
590
+ hasBatchQueued,
591
+ });
592
+ setMemoriTyping(true);
593
+ setTypingText(typingText);
594
+ }
595
+ else if (response.resultCode === 0) {
596
+ logWidgetError('enter-text missing correlationID', response);
580
597
  }
581
598
  else if (response.resultCode === 404) {
582
- setHistory(h => [...h.slice(0, h.length - 1)]);
583
- reopenSession(true, memoriPwd || memori.secretToken, memoriTokens, undefined, undefined, {
584
- LANG: userLang,
585
- PATHNAME: window.location.pathname,
586
- ROUTE: ((_g = (_f = window.location.pathname) === null || _f === void 0 ? void 0 : _f.split('/')) === null || _g === void 0 ? void 0 : _g.pop()) || '',
587
- ...(initialContextVars || {}),
588
- }, initialQuestion, undefined, undefined, undefined, undefined, true).then(state => {
589
- console.info('session timeout');
590
- if (state === null || state === void 0 ? void 0 : state.sessionID) {
591
- setTimeout(() => {
592
- sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
593
- }, 500);
594
- }
599
+ retryAfterExpiredSessionRef.current({
600
+ text,
601
+ media,
602
+ translate,
603
+ translatedText,
604
+ hidden,
605
+ typingText,
606
+ useLoaderTextAsMsg,
607
+ hasBatchQueued,
608
+ expiredSessionID: sessionID,
609
+ continueFromChatLogID: chatLogID,
595
610
  });
596
611
  }
597
612
  else if (response.resultCode === 500 && response.resultMessage) {
@@ -608,18 +623,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
608
623
  ]);
609
624
  }
610
625
  else {
611
- console.warn('[SEND_MESSAGE]', response);
612
626
  return Promise.reject(response);
613
627
  }
614
628
  }
615
629
  catch (error) {
616
- console.log('error', error);
617
- console.error(error);
618
630
  gotError = true;
619
- setTypingText(undefined);
620
- setMemoriTyping(false);
621
- }
622
- if (!hasBatchQueued) {
631
+ logWidgetError('sendMessage failed', error);
623
632
  setTypingText(undefined);
624
633
  setMemoriTyping(false);
625
634
  }
@@ -701,7 +710,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
701
710
  }
702
711
  }
703
712
  catch (error) {
704
- console.error('[TRANSLATE] Error during translation:', error);
705
713
  translatedState = { ...state, emission };
706
714
  translatedMsg = {
707
715
  text: emission,
@@ -809,7 +817,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
809
817
  try {
810
818
  setTimeout(() => {
811
819
  var _a;
812
- console.log('snippet', s);
813
820
  new Function((_a = s.content) !== null && _a !== void 0 ? _a : '')();
814
821
  setTimeout(() => {
815
822
  var _a, _b, _c;
@@ -818,8 +825,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
818
825
  }, 400);
819
826
  }, 1000);
820
827
  }
821
- catch (e) {
822
- console.warn(e);
828
+ catch (_a) {
823
829
  }
824
830
  });
825
831
  };
@@ -830,7 +836,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
830
836
  }
831
837
  }, [initialSessionID]);
832
838
  const fetchSession = async (params) => {
833
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l;
839
+ var _a, _b, _c, _d, _f, _g, _h;
834
840
  let storageBirthDate = getLocalConfig('birthDate', undefined);
835
841
  let userBirthDate = (_a = birthDate !== null && birthDate !== void 0 ? birthDate : params.birthDate) !== null && _a !== void 0 ? _a : storageBirthDate;
836
842
  if (!userBirthDate && !!minAge) {
@@ -844,6 +850,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
844
850
  setAuthModalState('password');
845
851
  return;
846
852
  }
853
+ if (!(await checkCredits({ notify: true }))) {
854
+ return;
855
+ }
847
856
  setLoading(true);
848
857
  try {
849
858
  let referral;
@@ -852,8 +861,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
852
861
  return window.location.href;
853
862
  })();
854
863
  }
855
- catch (err) {
856
- console.debug(err);
864
+ catch (_j) {
857
865
  }
858
866
  const session = await initSession({
859
867
  ...params,
@@ -862,8 +870,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
862
870
  pin: (_c = params.pin) !== null && _c !== void 0 ? _c : personification === null || personification === void 0 ? void 0 : personification.pin,
863
871
  additionalInfo: {
864
872
  ...(params.additionalInfo || additionalInfo || {}),
865
- 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,
866
- 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(),
873
+ loginToken: resolveLoginToken((_d = params.additionalInfo) === null || _d === void 0 ? void 0 : _d.loginToken),
874
+ 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(),
867
875
  referral: referral,
868
876
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
869
877
  },
@@ -892,7 +900,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
892
900
  }));
893
901
  setGotErrorInOpening(true);
894
902
  }
895
- else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 403) {
903
+ else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 403 && memori.privacyType !== 'PUBLIC') {
896
904
  setMemoriPwd(undefined);
897
905
  setAuthModalState('password');
898
906
  return session;
@@ -904,16 +912,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
904
912
  severity: 'error',
905
913
  duration: 0,
906
914
  }));
907
- setGotErrorInOpening(true);
908
915
  return session;
909
916
  }
910
917
  }
911
918
  catch (err) {
912
- console.error(err);
919
+ logWidgetError('fetchSession failed', err);
913
920
  }
914
921
  };
915
- const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired) => {
916
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m;
922
+ const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired, suppressHistoryUpdate) => {
923
+ var _a, _b, _c, _d, _f, _g, _h, _j;
917
924
  setLoading(true);
918
925
  let storageBirthDate = getLocalConfig('birthDate', undefined);
919
926
  let userBirthDate = birthDate !== null && birthDate !== void 0 ? birthDate : storageBirthDate;
@@ -931,14 +938,17 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
931
938
  setAuthModalState('password');
932
939
  return;
933
940
  }
941
+ if (!(await checkCredits({ notify: true }))) {
942
+ setLoading(false);
943
+ return null;
944
+ }
934
945
  let referral;
935
946
  try {
936
947
  referral = (() => {
937
948
  return window.location.href;
938
949
  })();
939
950
  }
940
- catch (err) {
941
- console.debug('[REOPEN_SESSION] Error getting referral:', err);
951
+ catch (_k) {
942
952
  }
943
953
  const { sessionID, currentState, ...response } = await initSession({
944
954
  memoriID: (_a = memori.engineMemoriID) !== null && _a !== void 0 ? _a : '',
@@ -958,21 +968,32 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
958
968
  birthDate: userBirthDate,
959
969
  additionalInfo: {
960
970
  ...(additionalInfoProp || additionalInfo || {}),
961
- 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,
962
- 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(),
971
+ loginToken: resolveLoginToken(additionalInfoProp === null || additionalInfoProp === void 0 ? void 0 : additionalInfoProp.loginToken),
972
+ 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(),
963
973
  referral: referral,
964
974
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
965
975
  },
966
976
  });
967
977
  if (sessionID && currentState && response.resultCode === 0) {
968
- console.log('[REOPEN_SESSION] Session initialized successfully:', sessionID);
969
978
  setSessionId(sessionID);
970
979
  if (updateDialogState) {
971
980
  setCurrentDialogState(currentState);
972
- if (currentState.emission) {
973
- console.log('[REOPEN_SESSION] Processing emission:', currentState.emission);
974
- const initialStatus = isSessionExpired && history.length > 1
975
- ? 'Session Expired, reopening session'
981
+ const sessionExpiredStatus = isSessionExpired && history.length > 1
982
+ ? t('sessionExpiredReopening')
983
+ : null;
984
+ if (sessionExpiredStatus && suppressHistoryUpdate) {
985
+ pushMessage({
986
+ text: '',
987
+ emitter: 'system',
988
+ fromUser: false,
989
+ initial: sessionExpiredStatus,
990
+ contextVars: {},
991
+ date: new Date().toISOString(),
992
+ });
993
+ }
994
+ if (currentState.emission && !suppressHistoryUpdate) {
995
+ const initialStatus = sessionExpiredStatus
996
+ ? sessionExpiredStatus
976
997
  : history.length <= 1
977
998
  ? true
978
999
  : undefined;
@@ -981,7 +1002,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
981
1002
  {
982
1003
  text: currentState.emission,
983
1004
  emitter: currentState.emitter,
984
- media: (_l = currentState.emittedMedia) !== null && _l !== void 0 ? _l : currentState.media,
1005
+ media: (_h = currentState.emittedMedia) !== null && _h !== void 0 ? _h : currentState.media,
985
1006
  fromUser: false,
986
1007
  initial: (initialStatus === true
987
1008
  ? true
@@ -999,7 +1020,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
999
1020
  : pushMessage({
1000
1021
  text: currentState.emission,
1001
1022
  emitter: currentState.emitter,
1002
- media: (_m = currentState.emittedMedia) !== null && _m !== void 0 ? _m : currentState.media,
1023
+ media: (_j = currentState.emittedMedia) !== null && _j !== void 0 ? _j : currentState.media,
1003
1024
  fromUser: false,
1004
1025
  initial: (initialStatus === true
1005
1026
  ? true
@@ -1029,8 +1050,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1029
1050
  }));
1030
1051
  setGotErrorInOpening(true);
1031
1052
  }
1032
- else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403) {
1033
- console.error('[REOPEN_SESSION] Authentication error');
1053
+ else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403 &&
1054
+ memori.privacyType !== 'PUBLIC') {
1034
1055
  setMemoriPwd(undefined);
1035
1056
  setAuthModalState('password');
1036
1057
  }
@@ -1044,15 +1065,61 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1044
1065
  }
1045
1066
  }
1046
1067
  catch (err) {
1047
- console.error('[REOPEN_SESSION] Caught error:', err);
1068
+ logWidgetError('reopenSession failed', err);
1048
1069
  }
1049
1070
  setLoading(false);
1050
1071
  return null;
1051
1072
  };
1073
+ const retryAfterExpiredSessionRef = useRef(() => Promise.resolve(null));
1074
+ retryAfterExpiredSessionRef.current = (params) => {
1075
+ const { text, media, translate = true, translatedText, hidden = false, typingText, useLoaderTextAsMsg = false, hasBatchQueued = false, expiredSessionID, continueFromChatLogID: continueFromChatLogIDParam, } = params;
1076
+ const continueFromSessionID = expiredSessionID !== null && expiredSessionID !== void 0 ? expiredSessionID : sessionId;
1077
+ const continueFromChatLogID = continueFromChatLogIDParam !== null && continueFromChatLogIDParam !== void 0 ? continueFromChatLogIDParam : chatLogID;
1078
+ const reopenAfterExpiry = () => {
1079
+ var _a, _b;
1080
+ return reopenSession(true, memoriPwd || memori.secretToken, memoriTokens, undefined, undefined, {
1081
+ LANG: userLang,
1082
+ PATHNAME: window.location.pathname,
1083
+ ROUTE: ((_b = (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.split('/')) === null || _b === void 0 ? void 0 : _b.pop()) || '',
1084
+ ...(initialContextVars || {}),
1085
+ }, initialQuestion, undefined, undefined, continueFromChatLogID, continueFromSessionID, true, true);
1086
+ };
1087
+ const scheduleRetry = (newSessionID) => {
1088
+ setTimeout(() => {
1089
+ sendMessage(text, media, newSessionID, translate, translatedText, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued, true);
1090
+ }, 500);
1091
+ };
1092
+ const handleReopenFailure = (state) => {
1093
+ setMemoriTyping(false);
1094
+ setTypingText(undefined);
1095
+ if (state === null && text && !hidden) {
1096
+ add(createAlertOptions({
1097
+ description: t('errors.SESSION_EXPIRED'),
1098
+ severity: 'error',
1099
+ }));
1100
+ }
1101
+ };
1102
+ if (!text) {
1103
+ return reopenAfterExpiry().then(state => {
1104
+ if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
1105
+ handleReopenFailure(state);
1106
+ }
1107
+ return state;
1108
+ });
1109
+ }
1110
+ return reopenAfterExpiry().then(state => {
1111
+ if (state === null || state === void 0 ? void 0 : state.sessionID) {
1112
+ scheduleRetry(state.sessionID);
1113
+ }
1114
+ else {
1115
+ handleReopenFailure(state);
1116
+ }
1117
+ return state;
1118
+ });
1119
+ };
1052
1120
  const changeTag = async (memoriId, sessionId, tag, pin) => {
1053
- var _a, _b, _c, _d, _f, _g, _h, _j, _k;
1121
+ var _a, _b, _c, _d, _f, _g, _h;
1054
1122
  if (!memoriId || !sessionId) {
1055
- console.error('CHANGETAG/Session not found');
1056
1123
  return Promise.reject('Session not found');
1057
1124
  }
1058
1125
  try {
@@ -1084,7 +1151,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1084
1151
  }
1085
1152
  }
1086
1153
  else if ([400, 401, 403, 404, 500].includes(resultCode)) {
1087
- console.warn('[APPCONTEXT/CHANGETAG]', resultCode);
1088
1154
  let storageBirthDate = getLocalConfig('birthDate', undefined);
1089
1155
  let referral;
1090
1156
  try {
@@ -1092,8 +1158,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1092
1158
  return window.location.href;
1093
1159
  })();
1094
1160
  }
1095
- catch (err) {
1096
- console.debug(err);
1161
+ catch (_j) {
1097
1162
  }
1098
1163
  fetchSession({
1099
1164
  memoriID: (_b = memori.engineMemoriID) !== null && _b !== void 0 ? _b : '',
@@ -1110,8 +1175,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1110
1175
  birthDate: birthDate || storageBirthDate || undefined,
1111
1176
  additionalInfo: {
1112
1177
  ...(additionalInfo || {}),
1113
- 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,
1114
- 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(),
1178
+ loginToken: resolveLoginToken(),
1179
+ 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(),
1115
1180
  referral: referral,
1116
1181
  timeZoneOffset: new Date().getTimezoneOffset().toString(),
1117
1182
  },
@@ -1128,7 +1193,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1128
1193
  }
1129
1194
  catch (_e) {
1130
1195
  let err = _e;
1131
- console.warn('[APPCONTEXT/CHANGETAG]', err);
1132
1196
  return Promise.reject(err);
1133
1197
  }
1134
1198
  return null;
@@ -1149,6 +1213,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1149
1213
  return () => {
1150
1214
  setHasUserActivatedSpeak(false);
1151
1215
  setClickedStart(false);
1216
+ sessionStartingRef.current = false;
1152
1217
  clearInteractionTimeout();
1153
1218
  timeoutRef.current = undefined;
1154
1219
  };
@@ -1175,10 +1240,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1175
1240
  apiUrl: `${baseUrl}/api/tts`,
1176
1241
  continuousSpeech: continuousSpeech,
1177
1242
  preview: preview,
1178
- }, autoStart, defaultEnableAudio, (_v = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _v !== void 0 ? _v : true);
1243
+ }, autoStart, defaultEnableAudio, (_x = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _x !== void 0 ? _x : true);
1179
1244
  const shouldPlayAudio = (text) => {
1180
1245
  const currentSpeakerMuted = getLocalConfig('muteSpeaker', !defaultEnableAudio);
1181
- console.log('[MemoriWidget] shouldPlayAudio', currentSpeakerMuted);
1182
1246
  return (text &&
1183
1247
  text.trim() &&
1184
1248
  !preview &&
@@ -1191,15 +1255,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1191
1255
  }
1192
1256
  try {
1193
1257
  const message = stripDuplicates(text);
1194
- console.debug('Processing speech message:', message);
1195
1258
  if (message.length > 0) {
1196
1259
  setUserMessage('');
1197
- console.debug('Sending message:', message);
1198
1260
  sendMessage(message);
1199
1261
  }
1200
1262
  }
1201
- catch (error) {
1202
- console.error('Error in processSpeechAndSendMessage:', error);
1263
+ catch (_a) {
1203
1264
  }
1204
1265
  };
1205
1266
  const { isListening, startRecording, stopRecording, } = useSTT(sttConfig, processSpeechAndSendMessage, {
@@ -1233,8 +1294,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1233
1294
  }
1234
1295
  return translatedState;
1235
1296
  }
1236
- catch (error) {
1237
- console.error('Error in translateAndSpeak:', error);
1297
+ catch (_a) {
1238
1298
  if (!hasUserActivatedSpeak) {
1239
1299
  setHasUserActivatedSpeak(true);
1240
1300
  }
@@ -1247,6 +1307,221 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1247
1307
  setHasUserActivatedSpeak,
1248
1308
  speakerMuted,
1249
1309
  ]);
1310
+ const processEnterTextDialogResponse = useCallback((event, pending) => {
1311
+ var _a, _b;
1312
+ const { msg, typingText: pendingTypingText, useLoaderTextAsMsg, } = pending;
1313
+ const currentState = event.currentState;
1314
+ if (event.resultCode !== 0 || !currentState) {
1315
+ if (isSessionExpiredNatsResponse(event) && pending.text) {
1316
+ setMemoriTyping(false);
1317
+ setTypingText(undefined);
1318
+ retryAfterExpiredSessionRef.current({
1319
+ text: pending.text,
1320
+ media: pending.media,
1321
+ translate: pending.translate,
1322
+ translatedText: pending.translatedText,
1323
+ hidden: pending.hidden,
1324
+ typingText: pending.typingText,
1325
+ useLoaderTextAsMsg: pending.useLoaderTextAsMsg,
1326
+ hasBatchQueued: pending.hasBatchQueued,
1327
+ expiredSessionID: sessionId,
1328
+ continueFromChatLogID: chatLogID,
1329
+ });
1330
+ return;
1331
+ }
1332
+ if (event.resultCode === 500 && event.resultMessage) {
1333
+ setHistory(h => [
1334
+ ...h,
1335
+ {
1336
+ text: 'Error: ' + event.resultMessage,
1337
+ emitter: 'system',
1338
+ fromUser: false,
1339
+ initial: false,
1340
+ contextVars: {},
1341
+ date: new Date().toISOString(),
1342
+ },
1343
+ ]);
1344
+ }
1345
+ return;
1346
+ }
1347
+ if (!msg) {
1348
+ return;
1349
+ }
1350
+ setChatLogID(undefined);
1351
+ const emission = useLoaderTextAsMsg && pendingTypingText
1352
+ ? pendingTypingText
1353
+ : (_a = currentState.emission) !== null && _a !== void 0 ? _a : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
1354
+ if (userLang.toLowerCase() !== language.toLowerCase() &&
1355
+ emission &&
1356
+ isMultilanguageEnabled) {
1357
+ currentState.emission = emission;
1358
+ translateDialogState(currentState, userLang, msg).then(ts => {
1359
+ const text = ts.translatedEmission || ts.emission;
1360
+ if (text && shouldPlayAudio(text)) {
1361
+ handleSpeak(text);
1362
+ }
1363
+ });
1364
+ }
1365
+ else {
1366
+ setCurrentDialogState({
1367
+ ...currentState,
1368
+ emission,
1369
+ });
1370
+ if (emission) {
1371
+ pushMessage({
1372
+ text: emission,
1373
+ emitter: currentState.emitter,
1374
+ media: (_b = currentState.emittedMedia) !== null && _b !== void 0 ? _b : currentState.media,
1375
+ llmUsage: currentState.llmUsage,
1376
+ fromUser: false,
1377
+ questionAnswered: msg,
1378
+ generatedByAI: !!currentState.completion,
1379
+ contextVars: currentState.contextVars,
1380
+ date: currentState.currentDate,
1381
+ placeName: currentState.currentPlaceName,
1382
+ placeLatitude: currentState.currentLatitude,
1383
+ placeLongitude: currentState.currentLongitude,
1384
+ placeUncertaintyKm: currentState.currentUncertaintyKm,
1385
+ tag: currentState.currentTag,
1386
+ memoryTags: currentState.memoryTags,
1387
+ });
1388
+ if (emission && shouldPlayAudio(emission)) {
1389
+ handleSpeak(emission);
1390
+ }
1391
+ }
1392
+ }
1393
+ }, [
1394
+ userLang,
1395
+ language,
1396
+ isMultilanguageEnabled,
1397
+ currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission,
1398
+ translateDialogState,
1399
+ handleSpeak,
1400
+ shouldPlayAudio,
1401
+ ]);
1402
+ const clearEnterTextPending = useCallback((correlationID, pending) => {
1403
+ var _a;
1404
+ if ((_a = pending.waitForResponse) === null || _a === void 0 ? void 0 : _a.timeoutId) {
1405
+ clearTimeout(pending.waitForResponse.timeoutId);
1406
+ }
1407
+ pendingEnterTextRef.current.delete(correlationID);
1408
+ }, []);
1409
+ const deliverEnterTextNatsError = useCallback((event) => {
1410
+ var _a, _b, _c;
1411
+ const correlationID = event.correlationID;
1412
+ let pending;
1413
+ if (correlationID) {
1414
+ pending = pendingEnterTextRef.current.get(correlationID);
1415
+ if (pending) {
1416
+ clearEnterTextPending(correlationID, pending);
1417
+ (_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')));
1418
+ }
1419
+ }
1420
+ if (isSessionExpiredNatsError(event) && (pending === null || pending === void 0 ? void 0 : pending.text)) {
1421
+ setMemoriTyping(false);
1422
+ setTypingText(undefined);
1423
+ retryAfterExpiredSessionRef.current({
1424
+ text: pending.text,
1425
+ media: pending.media,
1426
+ translate: pending.translate,
1427
+ translatedText: pending.translatedText,
1428
+ hidden: pending.hidden,
1429
+ typingText: pending.typingText,
1430
+ useLoaderTextAsMsg: pending.useLoaderTextAsMsg,
1431
+ hasBatchQueued: pending.hasBatchQueued,
1432
+ expiredSessionID: sessionId,
1433
+ continueFromChatLogID: chatLogID,
1434
+ });
1435
+ return;
1436
+ }
1437
+ const errorText = event.errorMessage
1438
+ ? `Error: ${event.errorMessage}`
1439
+ : event.errorCode
1440
+ ? `Error: ${event.errorCode}`
1441
+ : 'Error: An unexpected error occurred';
1442
+ pushMessage({
1443
+ text: errorText,
1444
+ emitter: 'system',
1445
+ fromUser: false,
1446
+ initial: false,
1447
+ contextVars: {},
1448
+ date: new Date().toISOString(),
1449
+ });
1450
+ setMemoriTyping(false);
1451
+ setTypingText(undefined);
1452
+ }, [clearEnterTextPending]);
1453
+ const deliverEnterTextNatsResponse = useCallback((correlationID, event) => {
1454
+ const pending = pendingEnterTextRef.current.get(correlationID);
1455
+ if (!pending) {
1456
+ bufferedNatsResponsesRef.current.set(correlationID, event);
1457
+ return;
1458
+ }
1459
+ clearEnterTextPending(correlationID, pending);
1460
+ if (pending.waitForResponse) {
1461
+ pending.waitForResponse.resolve(event);
1462
+ setMemoriTyping(false);
1463
+ setTypingText(undefined);
1464
+ return;
1465
+ }
1466
+ processEnterTextDialogResponse(event, pending);
1467
+ if (!pending.hasBatchQueued) {
1468
+ setMemoriTyping(false);
1469
+ setTypingText(undefined);
1470
+ }
1471
+ }, [processEnterTextDialogResponse, clearEnterTextPending]);
1472
+ const registerPendingEnterText = useCallback((correlationID, pending) => {
1473
+ const buffered = bufferedNatsResponsesRef.current.get(correlationID);
1474
+ if (buffered) {
1475
+ bufferedNatsResponsesRef.current.delete(correlationID);
1476
+ pendingEnterTextRef.current.set(correlationID, pending);
1477
+ deliverEnterTextNatsResponse(correlationID, buffered);
1478
+ return;
1479
+ }
1480
+ pendingEnterTextRef.current.set(correlationID, pending);
1481
+ }, [deliverEnterTextNatsResponse]);
1482
+ const waitForEnterTextNatsResponse = useCallback((correlationID, timeoutMs = 120000) => new Promise((resolve, reject) => {
1483
+ const timeoutId = setTimeout(() => {
1484
+ const current = pendingEnterTextRef.current.get(correlationID);
1485
+ if (current) {
1486
+ clearEnterTextPending(correlationID, current);
1487
+ }
1488
+ logWidgetError('NATS timeout', { correlationID, timeoutMs });
1489
+ reject(new Error('NATS enter-text response timeout'));
1490
+ }, timeoutMs);
1491
+ registerPendingEnterText(correlationID, {
1492
+ waitForResponse: {
1493
+ resolve: event => {
1494
+ clearTimeout(timeoutId);
1495
+ resolve(event);
1496
+ },
1497
+ reject: error => {
1498
+ clearTimeout(timeoutId);
1499
+ reject(error);
1500
+ },
1501
+ timeoutId,
1502
+ },
1503
+ });
1504
+ }), [registerPendingEnterText, clearEnterTextPending]);
1505
+ useNats({
1506
+ baseUrl,
1507
+ sessionId,
1508
+ onProgress: useCallback((event) => {
1509
+ if (event.message) {
1510
+ setTypingText(event.message);
1511
+ }
1512
+ }, []),
1513
+ onDialogResponse: useCallback((event) => {
1514
+ const correlationID = event.correlationID;
1515
+ if (!correlationID) {
1516
+ logWidgetError('NATS dialog response missing correlationID', event);
1517
+ setMemoriTyping(false);
1518
+ setTypingText(undefined);
1519
+ return;
1520
+ }
1521
+ deliverEnterTextNatsResponse(correlationID, event);
1522
+ }, [deliverEnterTextNatsResponse]),
1523
+ onError: deliverEnterTextNatsError,
1524
+ });
1250
1525
  const focusChatInput = () => {
1251
1526
  let textarea = document.querySelector('#chat-fieldset textarea');
1252
1527
  if (textarea && enableFocusChatInput) {
@@ -1268,7 +1543,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1268
1543
  timeoutRef.current = undefined;
1269
1544
  ttsStop();
1270
1545
  }
1271
- catch (e) {
1546
+ catch (_a) {
1272
1547
  }
1273
1548
  };
1274
1549
  useEffect(() => {
@@ -1306,9 +1581,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1306
1581
  }, []);
1307
1582
  const [attachmentsMenuOpen, setAttachmentsMenuOpen] = useState();
1308
1583
  const globalBackground = integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.globalBackground;
1309
- const globalBackgroundUrl = globalBackground
1310
- ? `url(${globalBackground})`
1311
- : null;
1312
1584
  const integrationProperties = (integration ? getChatStyles(integrationConfig) : {});
1313
1585
  const integrationSelectors = [
1314
1586
  preview ? '#preview' : null,
@@ -1340,7 +1612,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1340
1612
  }`);
1341
1613
  }
1342
1614
  if (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.blurBackground) {
1343
- integrationStylesheetParts.push('.memori-widget .memori--global-background { filter: blur(5px); }');
1615
+ integrationStylesheetParts.push('.memori-widget .memori-chat--history--has-global-background::before { filter: blur(5px); }');
1344
1616
  }
1345
1617
  const integrationStylesheet = `@layer integration {
1346
1618
  ${integrationStylesheetParts.join('\n ')}
@@ -1431,7 +1703,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1431
1703
  };
1432
1704
  }, [sessionId, userLang, disableTextEnteredEvents]);
1433
1705
  const onClickStart = useCallback(async (session, initialSessionExpired = false, chatLog, targetSessionID) => {
1434
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1706
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1435
1707
  const sessionID = chatLog ? undefined : (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1436
1708
  const dialogState = chatLog
1437
1709
  ? undefined
@@ -1448,9 +1720,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1448
1720
  setPositionPopoverOpenState(true);
1449
1721
  return;
1450
1722
  }
1723
+ if (!(await checkCredits({ notify: true }))) {
1724
+ setClickedStart(false);
1725
+ setLoading(false);
1726
+ return;
1727
+ }
1451
1728
  if (!sessionID && !!minAge && !birth) {
1452
1729
  setShowAgeVerification(true);
1453
1730
  setClickedStart(false);
1731
+ return;
1454
1732
  }
1455
1733
  else if ((!sessionID &&
1456
1734
  memori.privacyType !== 'PUBLIC' &&
@@ -1463,83 +1741,95 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1463
1741
  return;
1464
1742
  }
1465
1743
  else if (!sessionID || initialSessionExpired) {
1466
- setClickedStart(false);
1467
1744
  setGotErrorInOpening(false);
1468
- const session = await fetchSession({
1469
- memoriID: memori.engineMemoriID,
1470
- password: secret || memoriPwd || memori.secretToken,
1471
- tag: personification === null || personification === void 0 ? void 0 : personification.tag,
1472
- pin: personification === null || personification === void 0 ? void 0 : personification.pin,
1473
- continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
1474
- initialContextVars: {
1475
- LANG: userLang,
1476
- PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
1477
- 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()) || '',
1478
- ...((!chatLog
1479
- ? initialContextVars
1480
- : chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
1481
- },
1482
- initialQuestion: chatLog ? undefined : initialQuestion,
1483
- birthDate: birth,
1484
- additionalInfo: {
1485
- ...(additionalInfo || {}),
1486
- 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,
1487
- 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(),
1488
- timeZoneOffset: new Date().getTimezoneOffset().toString(),
1489
- },
1490
- });
1491
- if (session === null || session === void 0 ? void 0 : session.dialogState) {
1492
- if (!chatLog) {
1493
- setHistory([]);
1494
- await translateAndSpeak(session.dialogState, userLang);
1495
- setHasUserActivatedSpeak(true);
1496
- }
1497
- else {
1498
- const messages = chatLog.lines.map((l, i) => {
1499
- var _a, _b;
1500
- return ({
1501
- text: l.text,
1502
- media: (_b = (_a = l.media) === null || _a === void 0 ? void 0 : _a.filter(m => allowedMediaTypes.includes(m.mimeType))) === null || _b === void 0 ? void 0 : _b.map(m => ({
1503
- mediumID: `${i}-${m.mimeType}`,
1504
- ...m,
1505
- })),
1506
- fromUser: l.inbound,
1507
- llmUsage: l.llmUsage,
1508
- timestamp: l.timestamp,
1509
- emitter: l.emitter,
1510
- initial: i === 0,
1511
- });
1512
- });
1513
- translatedMessages = messages !== null && messages !== void 0 ? messages : [];
1514
- if (language.toUpperCase() !== userLang.toUpperCase() &&
1515
- isMultilanguageEnabled) {
1516
- try {
1517
- translatedMessages = await Promise.all(messages.map(async (m) => {
1518
- if ('originalText' in m && m.originalText) {
1519
- return m;
1520
- }
1521
- return {
1745
+ if (sessionStartingRef.current) {
1746
+ return;
1747
+ }
1748
+ sessionStartingRef.current = true;
1749
+ try {
1750
+ const session = await fetchSession({
1751
+ memoriID: memori.engineMemoriID,
1752
+ password: secret || memoriPwd || memori.secretToken,
1753
+ tag: personification === null || personification === void 0 ? void 0 : personification.tag,
1754
+ pin: personification === null || personification === void 0 ? void 0 : personification.pin,
1755
+ continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
1756
+ initialContextVars: {
1757
+ LANG: userLang,
1758
+ PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
1759
+ 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()) ||
1760
+ '',
1761
+ ...((!chatLog
1762
+ ? initialContextVars
1763
+ : chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
1764
+ },
1765
+ initialQuestion: chatLog ? undefined : initialQuestion,
1766
+ birthDate: birth,
1767
+ additionalInfo: {
1768
+ ...(additionalInfo || {}),
1769
+ loginToken: resolveLoginToken(),
1770
+ 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(),
1771
+ timeZoneOffset: new Date().getTimezoneOffset().toString(),
1772
+ },
1773
+ });
1774
+ if (session === null || session === void 0 ? void 0 : session.dialogState) {
1775
+ if (!chatLog) {
1776
+ setHistory([]);
1777
+ await translateAndSpeak(session.dialogState, userLang);
1778
+ setHasUserActivatedSpeak(true);
1779
+ setClickedStart(false);
1780
+ }
1781
+ else {
1782
+ const messages = chatLog.lines.map((l, i) => {
1783
+ var _a, _b;
1784
+ return ({
1785
+ text: l.text,
1786
+ media: (_b = (_a = l.media) === null || _a === void 0 ? void 0 : _a.filter(m => allowedMediaTypes.includes(m.mimeType))) === null || _b === void 0 ? void 0 : _b.map(m => ({
1787
+ mediumID: `${i}-${m.mimeType}`,
1522
1788
  ...m,
1523
- originalText: m.text,
1524
- text: (await getTranslation(m.text, userLang, language, baseUrl)).text,
1525
- };
1526
- }));
1527
- }
1528
- catch (e) {
1529
- console.error('[onClickStart] Error translating messages:', e);
1789
+ })),
1790
+ fromUser: l.inbound,
1791
+ llmUsage: l.llmUsage,
1792
+ timestamp: l.timestamp,
1793
+ emitter: l.emitter,
1794
+ initial: i === 0,
1795
+ });
1796
+ });
1797
+ translatedMessages = messages !== null && messages !== void 0 ? messages : [];
1798
+ if (language.toUpperCase() !== userLang.toUpperCase() &&
1799
+ isMultilanguageEnabled) {
1800
+ try {
1801
+ translatedMessages = await Promise.all(messages.map(async (m) => {
1802
+ if ('originalText' in m && m.originalText) {
1803
+ return m;
1804
+ }
1805
+ return {
1806
+ ...m,
1807
+ originalText: m.text,
1808
+ text: (await getTranslation(m.text, userLang, language, baseUrl)).text,
1809
+ };
1810
+ }));
1811
+ }
1812
+ catch (_u) {
1813
+ }
1530
1814
  }
1815
+ setHistory(translatedMessages);
1816
+ translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
1817
+ setHasUserActivatedSpeak(true);
1818
+ setClickedStart(false);
1819
+ });
1531
1820
  }
1532
- setHistory(translatedMessages);
1533
- translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
1534
- setHasUserActivatedSpeak(true);
1535
- });
1821
+ }
1822
+ else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
1823
+ sessionStartingRef.current = false;
1824
+ await onClickStart(session || undefined);
1825
+ }
1826
+ else {
1827
+ setLoading(false);
1828
+ setClickedStart(false);
1536
1829
  }
1537
1830
  }
1538
- else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
1539
- await onClickStart(session || undefined);
1540
- }
1541
- else {
1542
- setLoading(false);
1831
+ finally {
1832
+ sessionStartingRef.current = false;
1543
1833
  }
1544
1834
  return;
1545
1835
  }
@@ -1548,9 +1838,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1548
1838
  const { currentState, ...response } = await getSession(sessionID);
1549
1839
  if (response.resultCode !== 0 || !currentState) {
1550
1840
  const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
1551
- setGotErrorInOpening(true);
1552
1841
  setSessionId(undefined);
1553
- setClickedStart(false);
1554
1842
  await onClickStart(undefined, true, chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]);
1555
1843
  return;
1556
1844
  }
@@ -1562,21 +1850,22 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1562
1850
  const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
1563
1851
  if (session && session.resultCode === 0) {
1564
1852
  await translateAndSpeak(session.currentState, userLang);
1853
+ setClickedStart(false);
1565
1854
  }
1566
1855
  else {
1567
1856
  throw new Error('No session');
1568
1857
  }
1569
1858
  }
1570
- catch (e) {
1571
- console.error('[onClickStart] Error changing tag:', e);
1859
+ catch (_v) {
1572
1860
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, personification.tag, personification.pin, {
1573
1861
  LANG: userLang,
1574
- PATHNAME: (_l = window.location.pathname) === null || _l === void 0 ? void 0 : _l.toUpperCase(),
1575
- 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()) ||
1862
+ PATHNAME: (_j = window.location.pathname) === null || _j === void 0 ? void 0 : _j.toUpperCase(),
1863
+ 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()) ||
1576
1864
  '',
1577
1865
  ...(initialContextVars || {}),
1578
1866
  }, initialQuestion, birth).then(() => {
1579
1867
  setHasUserActivatedSpeak(true);
1868
+ setClickedStart(false);
1580
1869
  });
1581
1870
  }
1582
1871
  }
@@ -1589,6 +1878,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1589
1878
  const session = await changeTag(memori.engineMemoriID, sessionID, anonTag);
1590
1879
  if (session && session.resultCode === 0) {
1591
1880
  await translateAndSpeak(session.currentState, userLang);
1881
+ setClickedStart(false);
1592
1882
  }
1593
1883
  else {
1594
1884
  throw new Error('No session');
@@ -1597,19 +1887,20 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1597
1887
  catch (e) {
1598
1888
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, undefined, undefined, {
1599
1889
  LANG: userLang,
1600
- PATHNAME: (_q = window.location.pathname) === null || _q === void 0 ? void 0 : _q.toUpperCase(),
1601
- 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()) ||
1890
+ PATHNAME: (_o = window.location.pathname) === null || _o === void 0 ? void 0 : _o.toUpperCase(),
1891
+ 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()) ||
1602
1892
  '',
1603
1893
  ...(initialContextVars || {}),
1604
1894
  }, initialQuestion, birth).then(() => {
1605
1895
  setHasUserActivatedSpeak(true);
1896
+ setClickedStart(false);
1606
1897
  });
1607
1898
  }
1608
1899
  }
1609
1900
  else {
1610
1901
  try {
1611
1902
  const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
1612
- const messages = (_u = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _u === void 0 ? void 0 : _u.lines.map((l, i) => {
1903
+ const messages = (_s = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _s === void 0 ? void 0 : _s.lines.map((l, i) => {
1613
1904
  var _a, _b;
1614
1905
  return ({
1615
1906
  text: l.text,
@@ -1634,31 +1925,28 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1634
1925
  text: (await getTranslation(m.text, userLang, language, baseUrl)).text,
1635
1926
  })));
1636
1927
  }
1637
- catch (e) {
1638
- console.error('[onClickStart] Error translating messages:', e);
1928
+ catch (_w) {
1639
1929
  }
1640
1930
  }
1641
1931
  setHistory(translatedMessages);
1642
1932
  }
1643
- catch (e) {
1644
- console.error('[onClickStart] Error retrieving chat logs:', e);
1933
+ catch (_x) {
1645
1934
  }
1646
1935
  if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
1647
1936
  !initialQuestion) {
1648
1937
  setHasUserActivatedSpeak(true);
1938
+ setClickedStart(false);
1649
1939
  await translateAndSpeak(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length));
1650
1940
  }
1651
1941
  else {
1652
- console.log('[onClickStart] Starting with initial question');
1653
1942
  translatedMessages = [];
1654
1943
  setHistory([]);
1655
- setMemoriTyping(true);
1656
1944
  const placeSpec = getPlaceSpecForEnterText(position);
1657
- const response = await postTextEnteredEvent({
1945
+ const response = await postEnterTextAsync({
1658
1946
  sessionId: sessionID,
1659
1947
  text: initialQuestion,
1660
1948
  ...(memori.needsDateTime && {
1661
- dateUTC: (_v = DateTime.utc().toISO()) !== null && _v !== void 0 ? _v : undefined,
1949
+ dateUTC: (_t = DateTime.utc().toISO()) !== null && _t !== void 0 ? _t : undefined,
1662
1950
  }),
1663
1951
  ...(placeSpec !== undefined && { place: placeSpec }),
1664
1952
  });
@@ -1674,51 +1962,93 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1674
1962
  date: new Date().toISOString(),
1675
1963
  },
1676
1964
  ]);
1677
- setMemoriTyping(false);
1678
1965
  return;
1679
1966
  }
1680
- await translateAndSpeak((_w = response.currentState) !== null && _w !== void 0 ? _w : currentState, userLang, undefined, false);
1967
+ const onClickStartCorrelationID = readCorrelationID(response);
1968
+ if (response.resultCode === 0 && onClickStartCorrelationID) {
1969
+ setMemoriTyping(true);
1970
+ try {
1971
+ const natsEvent = await waitForEnterTextNatsResponse(onClickStartCorrelationID);
1972
+ if (natsEvent.resultCode === 0 && natsEvent.currentState) {
1973
+ await translateAndSpeak(natsEvent.currentState, userLang, undefined, false);
1974
+ setClickedStart(false);
1975
+ }
1976
+ }
1977
+ catch (err) {
1978
+ logWidgetError('onClickStart NATS wait failed', err);
1979
+ setMemoriTyping(false);
1980
+ setTypingText(undefined);
1981
+ }
1982
+ }
1983
+ else if (response.resultCode === 0) {
1984
+ logWidgetError('onClickStart enter-text missing correlationID', response);
1985
+ }
1681
1986
  }
1682
1987
  }
1683
1988
  }
1684
1989
  else {
1685
1990
  setHistory([]);
1686
1991
  await translateAndSpeak(dialogState, userLang);
1992
+ setClickedStart(false);
1687
1993
  }
1688
1994
  }, [memoriPwd, memori, memoriTokens, birthDate, sessionId, userLang, position]);
1689
1995
  const setPositionPopoverOpen = useCallback((open) => {
1690
- setPositionPopoverOpenState(open);
1691
- if (!open && autoStart) {
1692
- onClickStart();
1693
- }
1996
+ setPositionPopoverOpenState(wasOpen => {
1997
+ if (shouldRestartSessionOnPositionPopoverClose(wasOpen, open, autoStart)) {
1998
+ queueMicrotask(() => {
1999
+ onClickStart();
2000
+ });
2001
+ }
2002
+ return open;
2003
+ });
1694
2004
  }, [autoStart, onClickStart]);
1695
2005
  useEffect(() => {
1696
- if (!clickedStart && autoStart && selectedLayout !== 'HIDDEN_CHAT') {
2006
+ if (!clickedStart &&
2007
+ !sessionStartingRef.current &&
2008
+ !sessionId &&
2009
+ autoStart &&
2010
+ selectedLayout !== 'HIDDEN_CHAT' &&
2011
+ (!needsCredits || hasEnoughCredits)) {
1697
2012
  onClickStart();
1698
2013
  }
1699
- }, [clickedStart, autoStart, selectedLayout]);
2014
+ }, [
2015
+ clickedStart,
2016
+ autoStart,
2017
+ selectedLayout,
2018
+ sessionId,
2019
+ needsCredits,
2020
+ hasEnoughCredits,
2021
+ ]);
1700
2022
  useEffect(() => {
2023
+ var _a;
1701
2024
  const targetNode = document.querySelector(`memori-client[memoriname="${memori.name}"]`) ||
1702
2025
  document.querySelector(`memori-client[memoriid="${memori.memoriID}"]`) ||
1703
2026
  document.querySelector('memori-client');
1704
2027
  if (!targetNode) {
1705
2028
  return;
1706
2029
  }
2030
+ const propsToken = (_a = additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _a !== void 0 ? _a : authToken;
2031
+ const initialDomToken = targetNode.getAttribute('authtoken') || undefined;
2032
+ if (initialDomToken && !propsToken) {
2033
+ setLoginToken(initialDomToken);
2034
+ userTokenRef.current = initialDomToken;
2035
+ }
2036
+ const applyAuthTokenFromElement = (element) => {
2037
+ var _a;
2038
+ const clientNode = element.nodeName === 'MEMORI-CLIENT'
2039
+ ? element
2040
+ : (_a = element.closest('memori-client')) !== null && _a !== void 0 ? _a : element.parentElement;
2041
+ const token = (clientNode === null || clientNode === void 0 ? void 0 : clientNode.getAttribute('authtoken')) || undefined;
2042
+ setLoginToken(token);
2043
+ userTokenRef.current = token;
2044
+ };
1707
2045
  const config = { attributes: true, childList: false, subtree: false };
1708
- const callback = (mutationList, _observer) => {
1709
- var _a, _b, _c;
2046
+ const callback = mutationList => {
2047
+ var _a;
1710
2048
  for (const mutation of mutationList) {
1711
2049
  if (mutation.type === 'attributes' &&
1712
2050
  ((_a = mutation.attributeName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authtoken') {
1713
- if (mutation.target.nodeName === 'MEMORI-CLIENT') {
1714
- setLoginToken(mutation.target.getAttribute('authtoken') || undefined);
1715
- userToken = mutation.target.getAttribute('authtoken') || undefined;
1716
- }
1717
- else {
1718
- setLoginToken(((_c = (_b = mutation.target) === null || _b === void 0 ? void 0 : _b.parentElement) === null || _c === void 0 ? void 0 : _c.getAttribute('authtoken')) ||
1719
- undefined);
1720
- userToken = mutation.target.getAttribute('authtoken') || undefined;
1721
- }
2051
+ applyAuthTokenFromElement(mutation.target);
1722
2052
  }
1723
2053
  }
1724
2054
  };
@@ -1727,7 +2057,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1727
2057
  return () => {
1728
2058
  observer.disconnect();
1729
2059
  };
1730
- }, []);
2060
+ }, [memori.name, memori.memoriID, additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken, authToken]);
1731
2061
  const [experts, setExperts] = useState();
1732
2062
  const fetchExperts = useCallback(async () => {
1733
2063
  if (!sessionId || !(memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts))
@@ -1737,12 +2067,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1737
2067
  if (resp.resultCode === 0) {
1738
2068
  setExperts(experts);
1739
2069
  }
1740
- else {
1741
- console.warn('Error fetching experts', resp);
1742
- }
1743
2070
  }
1744
- catch (err) {
1745
- console.warn(err);
2071
+ catch (_a) {
1746
2072
  }
1747
2073
  }, [sessionId, memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts]);
1748
2074
  useEffect(() => {
@@ -1752,11 +2078,26 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1752
2078
  !!loginToken &&
1753
2079
  !!(user === null || user === void 0 ? void 0 : user.userID) &&
1754
2080
  (user === null || user === void 0 ? void 0 : user.pAndCUAccepted);
1755
- const needsCredits = tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation;
1756
- const [hasEnoughCredits, setHasEnoughCredits] = useState(true);
1757
- const checkCredits = useCallback(async () => {
2081
+ const handleNotEnoughCredits = useCallback(() => {
2082
+ setHasEnoughCredits(false);
2083
+ setAuthModalState(null);
2084
+ add(createAlertOptions({
2085
+ description: t('notEnoughCredits'),
2086
+ severity: 'error',
2087
+ }));
2088
+ }, [add, t]);
2089
+ const checkCredits = useCallback(async (options) => {
1758
2090
  if (!(tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation))
1759
- return;
2091
+ return true;
2092
+ if (!ownerUserID && !ownerUserName) {
2093
+ if (options === null || options === void 0 ? void 0 : options.notify) {
2094
+ handleNotEnoughCredits();
2095
+ }
2096
+ else {
2097
+ setHasEnoughCredits(false);
2098
+ }
2099
+ return false;
2100
+ }
1760
2101
  try {
1761
2102
  const resp = await getCredits({
1762
2103
  operation: deepThoughtEnabled
@@ -1769,22 +2110,36 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1769
2110
  });
1770
2111
  if (resp.enough) {
1771
2112
  setHasEnoughCredits(true);
2113
+ return true;
1772
2114
  }
1773
2115
  else {
1774
- setHasEnoughCredits(false);
1775
- console.warn('Not enough credits. Required:', resp.required);
2116
+ if (options === null || options === void 0 ? void 0 : options.notify) {
2117
+ handleNotEnoughCredits();
2118
+ }
2119
+ else {
2120
+ setHasEnoughCredits(false);
2121
+ }
2122
+ return false;
1776
2123
  }
1777
2124
  }
1778
- catch (e) {
1779
- let err = e;
1780
- console.debug(err);
2125
+ catch (err) {
2126
+ logWidgetError('checkCredits failed', err);
2127
+ return true;
1781
2128
  }
1782
- }, [tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation, deepThoughtEnabled]);
2129
+ }, [
2130
+ baseUrl,
2131
+ deepThoughtEnabled,
2132
+ handleNotEnoughCredits,
2133
+ ownerUserID,
2134
+ ownerUserName,
2135
+ tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation,
2136
+ tenantID,
2137
+ ]);
1783
2138
  useEffect(() => {
1784
2139
  if (tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation) {
1785
2140
  checkCredits();
1786
2141
  }
1787
- }, [tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation, deepThoughtEnabled]);
2142
+ }, [tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation, deepThoughtEnabled, checkCredits]);
1788
2143
  useEffect(() => {
1789
2144
  if (__WEBCOMPONENT__)
1790
2145
  return;
@@ -1803,16 +2158,16 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1803
2158
  ? selectedLayout !== 'TOTEM' && selectedLayout !== 'WEBSITE_ASSISTANT'
1804
2159
  : !showOnlyLastMessages;
1805
2160
  const canShowLoginButton = !(tenant === null || tenant === void 0 ? void 0 : tenant.ssoLogin) &&
1806
- ((_w = showLogin !== null && showLogin !== void 0 ? showLogin : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showLogin) !== null && _w !== void 0 ? _w : memori.requireLoginToken);
2161
+ ((_y = showLogin !== null && showLogin !== void 0 ? showLogin : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showLogin) !== null && _y !== void 0 ? _y : memori.requireLoginToken);
1807
2162
  const headerProps = {
1808
2163
  memori: {
1809
2164
  ...memori,
1810
- ownerUserID: (_y = (_x = memori.ownerUserID) !== null && _x !== void 0 ? _x : ownerUserID) !== null && _y !== void 0 ? _y : undefined,
2165
+ ownerUserID: (_0 = (_z = memori.ownerUserID) !== null && _z !== void 0 ? _z : ownerUserID) !== null && _0 !== void 0 ? _0 : undefined,
1811
2166
  },
1812
2167
  apiClient: client,
1813
2168
  tenant,
1814
2169
  history,
1815
- showShare: (_z = showShare !== null && showShare !== void 0 ? showShare : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showShare) !== null && _z !== void 0 ? _z : true,
2170
+ showShare: (_1 = showShare !== null && showShare !== void 0 ? showShare : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showShare) !== null && _1 !== void 0 ? _1 : true,
1816
2171
  position,
1817
2172
  layout: selectedLayout,
1818
2173
  additionalSettings,
@@ -1822,18 +2177,18 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1822
2177
  setShowSettingsDrawer,
1823
2178
  setShowKnownFactsDrawer,
1824
2179
  setShowExpertsDrawer,
1825
- enableAudio: (_0 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _0 !== void 0 ? _0 : true,
2180
+ enableAudio: (_2 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _2 !== void 0 ? _2 : true,
1826
2181
  speakerMuted: speakerMuted !== null && speakerMuted !== void 0 ? speakerMuted : false,
1827
2182
  setSpeakerMuted: (mute) => {
1828
2183
  toggleMute(mute);
1829
2184
  },
1830
2185
  setShowChatHistoryDrawer,
1831
- showSettings: (_1 = showSettings !== null && showSettings !== void 0 ? showSettings : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showSettings) !== null && _1 !== void 0 ? _1 : true,
1832
- showChatHistory: (_2 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _2 !== void 0 ? _2 : true,
2186
+ showSettings: (_3 = showSettings !== null && showSettings !== void 0 ? showSettings : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showSettings) !== null && _3 !== void 0 ? _3 : true,
2187
+ showChatHistory: (_4 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _4 !== void 0 ? _4 : true,
1833
2188
  showMessageConsumption: enableMessageConsumption,
1834
2189
  hasUserActivatedSpeak,
1835
2190
  showReload: selectedLayout === 'TOTEM',
1836
- showClear: (_3 = showClear !== null && showClear !== void 0 ? showClear : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showClear) !== null && _3 !== void 0 ? _3 : false,
2191
+ showClear: (_5 = showClear !== null && showClear !== void 0 ? showClear : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showClear) !== null && _5 !== void 0 ? _5 : false,
1837
2192
  clearHistory: () => setHistory(h => h.slice(-1)),
1838
2193
  showLogin: canShowLoginButton,
1839
2194
  setShowLoginDrawer,
@@ -1848,7 +2203,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1848
2203
  setShowLoginDrawer(false);
1849
2204
  setUser(undefined);
1850
2205
  setLoginToken(undefined);
1851
- userToken = undefined;
2206
+ userTokenRef.current = undefined;
1852
2207
  removeLocalConfig('loginToken');
1853
2208
  });
1854
2209
  },
@@ -1864,7 +2219,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1864
2219
  hasUserActivatedSpeak,
1865
2220
  isPlayingAudio: isPlayingAudio &&
1866
2221
  !speakerMuted &&
1867
- ((_4 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _4 !== void 0 ? _4 : true),
2222
+ ((_6 = enableAudio !== null && enableAudio !== void 0 ? enableAudio : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.enableAudio) !== null && _6 !== void 0 ? _6 : true),
1868
2223
  loading: !!memoriTyping,
1869
2224
  baseUrl,
1870
2225
  apiUrl: client.constants.BACKEND_URL,
@@ -1894,7 +2249,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1894
2249
  notEnoughCredits: needsCredits && !hasEnoughCredits,
1895
2250
  showLogin: canShowLoginButton,
1896
2251
  setShowLoginDrawer,
1897
- showChatHistory: (_5 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _5 !== void 0 ? _5 : true,
2252
+ showChatHistory: (_7 = showChatHistory !== null && showChatHistory !== void 0 ? showChatHistory : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showChatHistory) !== null && _7 !== void 0 ? _7 : true,
1898
2253
  setShowChatHistoryDrawer,
1899
2254
  user,
1900
2255
  };
@@ -1904,7 +2259,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1904
2259
  tenant,
1905
2260
  translateTo: isMultilanguageEnabled &&
1906
2261
  userLang.toUpperCase() !==
1907
- ((_10 = ((_9 = (_8 = (_7 = (_6 = memori.culture) === null || _6 === void 0 ? void 0 : _6.split('-')) === null || _7 === void 0 ? void 0 : _7[0]) !== null && _8 !== void 0 ? _8 : i18n.language) !== null && _9 !== void 0 ? _9 : 'IT')) === null || _10 === void 0 ? void 0 : _10.toUpperCase())
2262
+ ((_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())
1908
2263
  ? userLang
1909
2264
  : undefined,
1910
2265
  baseUrl,
@@ -1912,9 +2267,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1912
2267
  layout,
1913
2268
  memoriTyping,
1914
2269
  typingText,
1915
- showTypingText: (_11 = showTypingText !== null && showTypingText !== void 0 ? showTypingText : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showTypingText) !== null && _11 !== void 0 ? _11 : false,
2270
+ showTypingText: (_13 = showTypingText !== null && showTypingText !== void 0 ? showTypingText : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.showTypingText) !== null && _13 !== void 0 ? _13 : false,
1916
2271
  history: showFullHistory ? history : history.slice(-2),
1917
- authToken: (_13 = (_12 = loginToken !== null && loginToken !== void 0 ? loginToken : userToken) !== null && _12 !== void 0 ? _12 : additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.loginToken) !== null && _13 !== void 0 ? _13 : authToken,
2272
+ authToken: resolveLoginToken(),
1918
2273
  dialogState: currentDialogState,
1919
2274
  pushMessage,
1920
2275
  simulateUserPrompt,
@@ -1964,8 +2319,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1964
2319
  maxTotalMessagePayload,
1965
2320
  maxTextareaCharacters,
1966
2321
  isChatlogPanel: (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.artifactChatLogPanel) === true,
2322
+ globalBackground: globalBackground || undefined,
1967
2323
  };
1968
- const integrationBackground = integration && globalBackgroundUrl ? (_jsx("div", { className: "memori--global-background", children: _jsx("div", { className: "memori--global-background-image", style: { backgroundImage: globalBackgroundUrl } }) })) : (_jsx("div", { className: "memori--global-background no-background-image" }));
2324
+ const integrationBackground = (_jsx("div", { className: "memori--global-background no-background-image" }));
1969
2325
  const integrationStyle = integration &&
1970
2326
  (Object.keys(integrationProperties).length > 0 ||
1971
2327
  (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.blurBackground)) ? (_jsx("style", { dangerouslySetInnerHTML: { __html: integrationStylesheet } })) : null;
@@ -1985,7 +2341,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1985
2341
  : selectedLayout === 'ZOOMED_FULL_BODY'
1986
2342
  ? ZoomedFullBodyLayout
1987
2343
  : FullPageLayout;
1988
- return (_jsxs("div", { ref: widgetRootRef, className: cx('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'}`, {
2344
+ const widgetTheme = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'light' || (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'dark'
2345
+ ? integrationConfig.theme
2346
+ : isDarkTheme
2347
+ ? 'dark'
2348
+ : undefined;
2349
+ return (_jsx("div", { ref: setWidgetRootEl, className: cx('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'}`, {
1989
2350
  'memori--auto-start': autoStart,
1990
2351
  'memori--preview': preview,
1991
2352
  'memori--embed': embed,
@@ -1994,138 +2355,135 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1994
2355
  'memori--active': hasUserActivatedSpeak,
1995
2356
  'memori--hide-emissions': hideEmissions,
1996
2357
  'memori--has-active-session': !!sessionId,
1997
- }), "data-theme": (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'light' ||
1998
- (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.theme) === 'dark'
1999
- ? integrationConfig.theme
2000
- : undefined, "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({
2358
+ }), "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({
2001
2359
  ...currentDialogState,
2002
2360
  sessionID: sessionId,
2003
- }), style: { height }, children: [_jsx(Layout, { Header: Header, headerProps: headerProps, Avatar: Avatar, avatarProps: avatarProps, Chat: Chat, chatProps: chatProps, StartPanel: StartPanel, 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 }), _jsx(ArtifactAPIBridge, { pushMessage: (message) => {
2004
- setHistory(history => {
2005
- if (!history.length)
2006
- return history;
2007
- const lastMessage = history[history.length - 1];
2008
- if (!lastMessage || lastMessage.fromUser)
2009
- return history;
2010
- const updatedLastMessage = {
2011
- ...lastMessage,
2012
- text: lastMessage.text + message.text,
2013
- };
2014
- return [...history.slice(0, -1), updatedLastMessage];
2015
- });
2016
- } }), _jsx("audio", { id: "memori-audio", style: { display: 'none' }, src: "https://aisuru.com/intro.mp3" }), isClient && (_jsx(MemoriAuth, { withModal: true, pwdOrTokens: authModalState, openModal: !!authModalState, setPwdOrTokens: setAuthModalState, showTokens: memori.privacyType === 'SECRET', onFinish: (values) => {
2017
- var _a, _b, _c, _d;
2018
- if (values['password'])
2019
- setMemoriPwd(values['password']);
2020
- if (values['password'])
2021
- memoriPassword = values['password'];
2022
- if (values['tokens'])
2023
- setMemoriTokens(values['tokens']);
2024
- 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, {
2025
- LANG: userLang,
2026
- PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2027
- 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()) ||
2028
- '',
2029
- ...(initialContextVars || {}),
2030
- }, initialQuestion, birthDate)
2031
- .then(state => {
2032
- if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
2033
- throw new Error('AUTH_FAILED');
2034
- }
2035
- setAuthModalState(null);
2036
- if (state === null || state === void 0 ? void 0 : state.dialogState) {
2037
- setHasUserActivatedSpeak(true);
2038
- }
2039
- else {
2040
- onClickStart(state);
2041
- }
2042
- })
2043
- .catch(error => {
2044
- if (!(error instanceof Error) ||
2045
- error.message !== 'AUTH_FAILED') {
2046
- setGotErrorInOpening(true);
2047
- }
2048
- throw error;
2049
- });
2050
- }, minimumNumberOfRecoveryTokens: (_17 = memori === null || memori === void 0 ? void 0 : memori.minimumNumberOfRecoveryTokens) !== null && _17 !== void 0 ? _17 : 1 })), isClient && (_jsx(AgeVerificationModal, { visible: showAgeVerification, minAge: minAge, onClose: birthDate => {
2051
- var _a, _b, _c, _d;
2052
- if (birthDate) {
2053
- setBirthDate(birthDate);
2054
- setLocalConfig('birthDate', birthDate);
2055
- 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, {
2056
- LANG: userLang,
2057
- PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2058
- 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()) || '',
2059
- ...(initialContextVars || {}),
2060
- }, initialQuestion, birthDate)
2061
- .then(state => {
2062
- setShowAgeVerification(false);
2063
- setAuthModalState(null);
2064
- onClickStart(state || undefined);
2065
- })
2066
- .catch(() => {
2067
- setShowAgeVerification(false);
2068
- setGotErrorInOpening(true);
2069
- });
2070
- }
2071
- else {
2072
- setShowAgeVerification(false);
2073
- setClickedStart(false);
2074
- }
2075
- } })), showSettingsDrawer && (_jsx(SettingsDrawer, { 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 && (_jsx(ChatHistoryDrawer, { open: !!showChatHistoryDrawer, onClose: () => setShowChatHistoryDrawer(false), resumeSession: chatLog => {
2076
- setChatLogID(chatLog.chatLogID);
2077
- onClickStart(undefined, false, chatLog);
2078
- setShowChatHistoryDrawer(false);
2079
- }, 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 && (_jsx(KnownFacts, { apiClient: client, memori: memori, sessionID: sessionId, visible: showKnownFactsDrawer, closeDrawer: () => setShowKnownFactsDrawer(false) })), showExpertsDrawer && !!experts && (_jsx(ExpertsDrawer, { 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) && (_jsx(LoginDrawer, { tenant: tenant, apiClient: client, open: !!showLoginDrawer, user: user, loginToken: loginToken, onClose: () => setShowLoginDrawer(false), drawerClassName: selectedLayout === 'WEBSITE_ASSISTANT'
2080
- ? 'memori-drawer--above-website-assistant'
2081
- : undefined, onLogin: (user, token) => {
2082
- var _a, _b, _c, _d;
2083
- 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, {
2084
- LANG: userLang,
2085
- PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2086
- 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()) ||
2087
- '',
2088
- ...(initialContextVars || {}),
2089
- }, undefined, birthDate, { loginToken: token }, undefined, sessionId).then(state => {
2090
- var _a, _b;
2091
- setShowLoginDrawer(false);
2092
- setUser(user);
2093
- setLoginToken(token);
2094
- userToken = token;
2095
- setLocalConfig('loginToken', token);
2096
- if ((state === null || state === void 0 ? void 0 : state.sessionID) &&
2097
- state.sessionID !== sessionId &&
2098
- (state === null || state === void 0 ? void 0 : state.dialogState)) {
2099
- const username = (user === null || user === void 0 ? void 0 : user.userName) || t('login.user');
2100
- pushMessage({
2101
- text: '',
2102
- emitter: state.dialogState.emitter,
2103
- media: (_b = (_a = state.dialogState.emittedMedia) !== null && _a !== void 0 ? _a : state.dialogState.media) !== null && _b !== void 0 ? _b : [],
2104
- fromUser: false,
2105
- initial: t('login.successfullyLoggedIn', { username }),
2106
- contextVars: state.dialogState.contextVars,
2107
- date: state.dialogState.currentDate,
2108
- placeName: state.dialogState.currentPlaceName,
2109
- placeLatitude: state.dialogState.currentLatitude,
2110
- placeLongitude: state.dialogState.currentLongitude,
2111
- placeUncertaintyKm: state.dialogState.currentUncertaintyKm,
2112
- tag: state.dialogState.currentTag,
2113
- memoryTags: state.dialogState.memoryTags,
2114
- });
2115
- setCurrentDialogState(state.dialogState);
2116
- }
2117
- });
2118
- }, setUser: setUser, onLogout: () => {
2119
- if (!loginToken)
2120
- return;
2121
- client.backend.pwlUserLogout(loginToken).then(() => {
2122
- setShowLoginDrawer(false);
2123
- setUser(undefined);
2124
- setLoginToken(undefined);
2125
- userToken = undefined;
2126
- removeLocalConfig('loginToken');
2127
- });
2128
- } }))] }));
2361
+ }), style: { height }, children: _jsx(MemoriUIProvider, { container: widgetRootEl, theme: widgetTheme, children: _jsx(WidgetSurfaceProvider, { value: widgetSurfaceEl, children: _jsxs("div", { ref: setWidgetSurfaceEl, className: "memori-widget__surface", children: [_jsx(Layout, { Header: Header, headerProps: headerProps, Avatar: Avatar, avatarProps: avatarProps, Chat: Chat, chatProps: chatProps, StartPanel: StartPanel, 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, totemContentMaxWidth: integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.totemContentMaxWidth }), _jsx(ArtifactAPIBridge, { pushMessage: (message) => {
2362
+ setHistory(history => {
2363
+ if (!history.length)
2364
+ return history;
2365
+ const lastMessage = history[history.length - 1];
2366
+ if (!lastMessage || lastMessage.fromUser)
2367
+ return history;
2368
+ const updatedLastMessage = {
2369
+ ...lastMessage,
2370
+ text: lastMessage.text + message.text,
2371
+ };
2372
+ return [...history.slice(0, -1), updatedLastMessage];
2373
+ });
2374
+ } }), _jsx("audio", { id: "memori-audio", style: { display: 'none' }, src: "https://aisuru.com/intro.mp3" }), isClient && (_jsx(MemoriAuth, { withModal: true, pwdOrTokens: authModalState, openModal: !!authModalState, setPwdOrTokens: setAuthModalState, showTokens: memori.privacyType === 'SECRET', onFinish: (values) => {
2375
+ var _a, _b, _c, _d;
2376
+ if (values['password'])
2377
+ setMemoriPwd(values['password']);
2378
+ if (values['password'])
2379
+ memoriPassword = values['password'];
2380
+ if (values['tokens'])
2381
+ setMemoriTokens(values['tokens']);
2382
+ 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, {
2383
+ LANG: userLang,
2384
+ PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2385
+ 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()) || '',
2386
+ ...(initialContextVars || {}),
2387
+ }, initialQuestion, birthDate)
2388
+ .then(state => {
2389
+ if (!(state === null || state === void 0 ? void 0 : state.sessionID)) {
2390
+ throw new Error('AUTH_FAILED');
2391
+ }
2392
+ setAuthModalState(null);
2393
+ if (state === null || state === void 0 ? void 0 : state.dialogState) {
2394
+ setHasUserActivatedSpeak(true);
2395
+ }
2396
+ else {
2397
+ onClickStart(state);
2398
+ }
2399
+ })
2400
+ .catch(error => {
2401
+ if (!(error instanceof Error) ||
2402
+ error.message !== 'AUTH_FAILED') {
2403
+ setGotErrorInOpening(true);
2404
+ }
2405
+ throw error;
2406
+ });
2407
+ }, minimumNumberOfRecoveryTokens: (_17 = memori === null || memori === void 0 ? void 0 : memori.minimumNumberOfRecoveryTokens) !== null && _17 !== void 0 ? _17 : 1 })), isClient && (_jsx(AgeVerificationModal, { visible: showAgeVerification, minAge: minAge, onClose: birthDate => {
2408
+ var _a, _b, _c, _d;
2409
+ if (birthDate) {
2410
+ setBirthDate(birthDate);
2411
+ setLocalConfig('birthDate', birthDate);
2412
+ 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, {
2413
+ LANG: userLang,
2414
+ PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2415
+ 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()) || '',
2416
+ ...(initialContextVars || {}),
2417
+ }, initialQuestion, birthDate)
2418
+ .then(state => {
2419
+ setShowAgeVerification(false);
2420
+ setAuthModalState(null);
2421
+ onClickStart(state || undefined);
2422
+ })
2423
+ .catch(() => {
2424
+ setShowAgeVerification(false);
2425
+ setGotErrorInOpening(true);
2426
+ });
2427
+ }
2428
+ else {
2429
+ setShowAgeVerification(false);
2430
+ setClickedStart(false);
2431
+ }
2432
+ } })), showSettingsDrawer && (_jsx(SettingsDrawer, { 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 && (_jsx(ChatHistoryDrawer, { open: !!showChatHistoryDrawer, onClose: () => setShowChatHistoryDrawer(false), resumeSession: chatLog => {
2433
+ setChatLogID(chatLog.chatLogID);
2434
+ onClickStart(undefined, false, chatLog);
2435
+ setShowChatHistoryDrawer(false);
2436
+ }, 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 && (_jsx(KnownFacts, { apiClient: client, memori: memori, sessionID: sessionId, visible: showKnownFactsDrawer, closeDrawer: () => setShowKnownFactsDrawer(false) })), showExpertsDrawer && !!experts && (_jsx(ExpertsDrawer, { 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) && (_jsx(LoginDrawer, { tenant: tenant, apiClient: client, open: !!showLoginDrawer, user: user, loginToken: loginToken, onClose: () => setShowLoginDrawer(false), drawerClassName: selectedLayout === 'WEBSITE_ASSISTANT'
2437
+ ? 'memori-drawer--above-website-assistant'
2438
+ : undefined, onLogin: (user, token) => {
2439
+ var _a, _b, _c, _d;
2440
+ 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, {
2441
+ LANG: userLang,
2442
+ PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
2443
+ 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()) || '',
2444
+ ...(initialContextVars || {}),
2445
+ }, undefined, birthDate, { loginToken: token }, undefined, sessionId).then(state => {
2446
+ var _a, _b;
2447
+ setShowLoginDrawer(false);
2448
+ setUser(user);
2449
+ setLoginToken(token);
2450
+ userTokenRef.current = token;
2451
+ setLocalConfig('loginToken', token);
2452
+ if ((state === null || state === void 0 ? void 0 : state.sessionID) &&
2453
+ state.sessionID !== sessionId &&
2454
+ (state === null || state === void 0 ? void 0 : state.dialogState)) {
2455
+ const username = (user === null || user === void 0 ? void 0 : user.userName) || t('login.user');
2456
+ pushMessage({
2457
+ text: '',
2458
+ emitter: state.dialogState.emitter,
2459
+ media: (_b = (_a = state.dialogState.emittedMedia) !== null && _a !== void 0 ? _a : state.dialogState.media) !== null && _b !== void 0 ? _b : [],
2460
+ fromUser: false,
2461
+ initial: t('login.successfullyLoggedIn', {
2462
+ username,
2463
+ }),
2464
+ contextVars: state.dialogState.contextVars,
2465
+ date: state.dialogState.currentDate,
2466
+ placeName: state.dialogState.currentPlaceName,
2467
+ placeLatitude: state.dialogState.currentLatitude,
2468
+ placeLongitude: state.dialogState.currentLongitude,
2469
+ placeUncertaintyKm: state.dialogState.currentUncertaintyKm,
2470
+ tag: state.dialogState.currentTag,
2471
+ memoryTags: state.dialogState.memoryTags,
2472
+ });
2473
+ setCurrentDialogState(state.dialogState);
2474
+ }
2475
+ });
2476
+ }, setUser: setUser, onLogout: () => {
2477
+ if (!loginToken)
2478
+ return;
2479
+ client.backend.pwlUserLogout(loginToken).then(() => {
2480
+ setShowLoginDrawer(false);
2481
+ setUser(undefined);
2482
+ setLoginToken(undefined);
2483
+ userTokenRef.current = undefined;
2484
+ removeLocalConfig('loginToken');
2485
+ });
2486
+ } }))] }) }) }) }));
2129
2487
  };
2130
2488
  export default MemoriWidget;
2131
2489
  //# sourceMappingURL=MemoriWidget.js.map