@memori.ai/memori-react 8.40.0 → 8.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
 
2
2
 
3
+ ## [8.40.1](https://github.com/memori-ai/memori-react/compare/v8.40.0...v8.40.1) (2026-06-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * add session management improvements in MemoriWidget ([a055776](https://github.com/memori-ai/memori-react/commit/a05577666d53c5ee8becf51954f6abdf9f2bd864))
9
+
3
10
  ## [8.40.0](https://github.com/memori-ai/memori-react/compare/v8.39.0...v8.40.0) (2026-06-17)
4
11
 
5
12
 
@@ -208,6 +208,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
208
208
  }, [loginToken, user === null || user === void 0 ? void 0 : user.userID]);
209
209
  const [showLoginDrawer, setShowLoginDrawer] = (0, react_1.useState)(false);
210
210
  const [clickedStart, setClickedStart] = (0, react_1.useState)(false);
211
+ const sessionStartingRef = (0, react_1.useRef)(false);
211
212
  const language = ((_d = (_c = (_b = memori.culture) === null || _b === void 0 ? void 0 : _b.split('-')) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.toUpperCase()) ||
212
213
  ((_j = (_h = (_g = (_f = memoriConfigs === null || memoriConfigs === void 0 ? void 0 : memoriConfigs.find(c => c.memoriConfigID === memori.memoriConfigurationID)) === null || _f === void 0 ? void 0 : _f.culture) === null || _g === void 0 ? void 0 : _g.split('-')) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.toUpperCase());
213
214
  const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
@@ -1046,6 +1047,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1046
1047
  return () => {
1047
1048
  setHasUserActivatedSpeak(false);
1048
1049
  setClickedStart(false);
1050
+ sessionStartingRef.current = false;
1049
1051
  clearInteractionTimeout();
1050
1052
  timeoutRef.current = undefined;
1051
1053
  };
@@ -1634,6 +1636,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1634
1636
  if (!sessionID && !!minAge && !birth) {
1635
1637
  setShowAgeVerification(true);
1636
1638
  setClickedStart(false);
1639
+ return;
1637
1640
  }
1638
1641
  else if (!sessionID &&
1639
1642
  memori.privacyType !== 'PUBLIC' &&
@@ -1645,82 +1648,95 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1645
1648
  return;
1646
1649
  }
1647
1650
  else if (!sessionID || initialSessionExpired) {
1648
- setClickedStart(false);
1649
- const session = await fetchSession({
1650
- memoriID: memori.engineMemoriID,
1651
- password: secret || memoriPwd || memori.secretToken,
1652
- tag: personification === null || personification === void 0 ? void 0 : personification.tag,
1653
- pin: personification === null || personification === void 0 ? void 0 : personification.pin,
1654
- continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
1655
- initialContextVars: {
1656
- LANG: userLang,
1657
- PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
1658
- 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()) || '',
1659
- ...((!chatLog
1660
- ? initialContextVars
1661
- : chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
1662
- },
1663
- initialQuestion: chatLog ? undefined : initialQuestion,
1664
- birthDate: birth,
1665
- additionalInfo: {
1666
- ...(additionalInfo || {}),
1667
- 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,
1668
- 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(),
1669
- timeZoneOffset: new Date().getTimezoneOffset().toString(),
1670
- },
1671
- });
1672
- if (session === null || session === void 0 ? void 0 : session.dialogState) {
1673
- if (!chatLog) {
1674
- setHistory([]);
1675
- await translateAndSpeak(session.dialogState, userLang);
1676
- setHasUserActivatedSpeak(true);
1677
- }
1678
- else {
1679
- const messages = chatLog.lines.map((l, i) => {
1680
- var _a, _b;
1681
- return ({
1682
- text: l.text,
1683
- media: (_b = (_a = l.media) === null || _a === void 0 ? void 0 : _a.filter(m => constants_1.allowedMediaTypes.includes(m.mimeType))) === null || _b === void 0 ? void 0 : _b.map(m => ({
1684
- mediumID: `${i}-${m.mimeType}`,
1685
- ...m,
1686
- })),
1687
- fromUser: l.inbound,
1688
- llmUsage: l.llmUsage,
1689
- timestamp: l.timestamp,
1690
- emitter: l.emitter,
1691
- initial: i === 0,
1692
- });
1693
- });
1694
- translatedMessages = messages !== null && messages !== void 0 ? messages : [];
1695
- if (language.toUpperCase() !== userLang.toUpperCase() &&
1696
- isMultilanguageEnabled) {
1697
- try {
1698
- translatedMessages = await Promise.all(messages.map(async (m) => {
1699
- if ('originalText' in m && m.originalText) {
1700
- return m;
1701
- }
1702
- return {
1651
+ if (sessionStartingRef.current) {
1652
+ return;
1653
+ }
1654
+ sessionStartingRef.current = true;
1655
+ try {
1656
+ const session = await fetchSession({
1657
+ memoriID: memori.engineMemoriID,
1658
+ password: secret || memoriPwd || memori.secretToken,
1659
+ tag: personification === null || personification === void 0 ? void 0 : personification.tag,
1660
+ pin: personification === null || personification === void 0 ? void 0 : personification.pin,
1661
+ continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
1662
+ initialContextVars: {
1663
+ LANG: userLang,
1664
+ PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
1665
+ 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()) ||
1666
+ '',
1667
+ ...((!chatLog
1668
+ ? initialContextVars
1669
+ : chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
1670
+ },
1671
+ initialQuestion: chatLog ? undefined : initialQuestion,
1672
+ birthDate: birth,
1673
+ additionalInfo: {
1674
+ ...(additionalInfo || {}),
1675
+ 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,
1676
+ 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(),
1677
+ timeZoneOffset: new Date().getTimezoneOffset().toString(),
1678
+ },
1679
+ });
1680
+ if (session === null || session === void 0 ? void 0 : session.dialogState) {
1681
+ if (!chatLog) {
1682
+ setHistory([]);
1683
+ await translateAndSpeak(session.dialogState, userLang);
1684
+ setHasUserActivatedSpeak(true);
1685
+ setClickedStart(false);
1686
+ }
1687
+ else {
1688
+ const messages = chatLog.lines.map((l, i) => {
1689
+ var _a, _b;
1690
+ return ({
1691
+ text: l.text,
1692
+ media: (_b = (_a = l.media) === null || _a === void 0 ? void 0 : _a.filter(m => constants_1.allowedMediaTypes.includes(m.mimeType))) === null || _b === void 0 ? void 0 : _b.map(m => ({
1693
+ mediumID: `${i}-${m.mimeType}`,
1703
1694
  ...m,
1704
- originalText: m.text,
1705
- text: (await (0, translations_1.getTranslation)(m.text, userLang, language, baseUrl)).text,
1706
- };
1707
- }));
1708
- }
1709
- catch (e) {
1710
- console.error('[onClickStart] Error translating messages:', e);
1695
+ })),
1696
+ fromUser: l.inbound,
1697
+ llmUsage: l.llmUsage,
1698
+ timestamp: l.timestamp,
1699
+ emitter: l.emitter,
1700
+ initial: i === 0,
1701
+ });
1702
+ });
1703
+ translatedMessages = messages !== null && messages !== void 0 ? messages : [];
1704
+ if (language.toUpperCase() !== userLang.toUpperCase() &&
1705
+ isMultilanguageEnabled) {
1706
+ try {
1707
+ translatedMessages = await Promise.all(messages.map(async (m) => {
1708
+ if ('originalText' in m && m.originalText) {
1709
+ return m;
1710
+ }
1711
+ return {
1712
+ ...m,
1713
+ originalText: m.text,
1714
+ text: (await (0, translations_1.getTranslation)(m.text, userLang, language, baseUrl)).text,
1715
+ };
1716
+ }));
1717
+ }
1718
+ catch (e) {
1719
+ console.error('[onClickStart] Error translating messages:', e);
1720
+ }
1711
1721
  }
1722
+ setHistory(translatedMessages);
1723
+ translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
1724
+ setHasUserActivatedSpeak(true);
1725
+ setClickedStart(false);
1726
+ });
1712
1727
  }
1713
- setHistory(translatedMessages);
1714
- translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
1715
- setHasUserActivatedSpeak(true);
1716
- });
1728
+ }
1729
+ else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
1730
+ sessionStartingRef.current = false;
1731
+ await onClickStart(session || undefined);
1732
+ }
1733
+ else {
1734
+ setLoading(false);
1735
+ setClickedStart(false);
1717
1736
  }
1718
1737
  }
1719
- else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
1720
- await onClickStart(session || undefined);
1721
- }
1722
- else {
1723
- setLoading(false);
1738
+ finally {
1739
+ sessionStartingRef.current = false;
1724
1740
  }
1725
1741
  return;
1726
1742
  }
@@ -1757,6 +1773,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1757
1773
  ...(initialContextVars || {}),
1758
1774
  }, initialQuestion, birth).then(() => {
1759
1775
  setHasUserActivatedSpeak(true);
1776
+ setClickedStart(false);
1760
1777
  });
1761
1778
  }
1762
1779
  }
@@ -1896,10 +1913,13 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1896
1913
  }
1897
1914
  }, [memoriPwd, memori, memoriTokens, birthDate, sessionId, userLang, position]);
1898
1915
  (0, react_1.useEffect)(() => {
1899
- if (!clickedStart && autoStart && selectedLayout !== 'HIDDEN_CHAT') {
1916
+ if (!clickedStart &&
1917
+ !sessionStartingRef.current &&
1918
+ autoStart &&
1919
+ selectedLayout !== 'HIDDEN_CHAT') {
1900
1920
  onClickStart();
1901
1921
  }
1902
- }, [clickedStart, autoStart, selectedLayout]);
1922
+ }, [clickedStart, autoStart, selectedLayout, sessionId]);
1903
1923
  (0, react_1.useEffect)(() => {
1904
1924
  const targetNode = document.querySelector(`memori-client[memoriname="${memori.name}"]`) ||
1905
1925
  document.querySelector(`memori-client[memoriid="${memori.memoriID}"]`) ||