@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 +7 -0
- package/dist/components/MemoriWidget/MemoriWidget.js +93 -73
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +96 -74
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +1 -1
- package/src/components/MemoriWidget/MemoriWidget.tsx +68 -41
- package/src/components/layouts/layouts.stories.tsx +1 -1
- package/src/version.ts +1 -1
|
@@ -205,6 +205,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
205
205
|
}, [loginToken, user === null || user === void 0 ? void 0 : user.userID]);
|
|
206
206
|
const [showLoginDrawer, setShowLoginDrawer] = useState(false);
|
|
207
207
|
const [clickedStart, setClickedStart] = useState(false);
|
|
208
|
+
const sessionStartingRef = useRef(false);
|
|
208
209
|
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()) ||
|
|
209
210
|
((_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());
|
|
210
211
|
const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
|
|
@@ -1043,6 +1044,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1043
1044
|
return () => {
|
|
1044
1045
|
setHasUserActivatedSpeak(false);
|
|
1045
1046
|
setClickedStart(false);
|
|
1047
|
+
sessionStartingRef.current = false;
|
|
1046
1048
|
clearInteractionTimeout();
|
|
1047
1049
|
timeoutRef.current = undefined;
|
|
1048
1050
|
};
|
|
@@ -1631,6 +1633,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1631
1633
|
if (!sessionID && !!minAge && !birth) {
|
|
1632
1634
|
setShowAgeVerification(true);
|
|
1633
1635
|
setClickedStart(false);
|
|
1636
|
+
return;
|
|
1634
1637
|
}
|
|
1635
1638
|
else if (!sessionID &&
|
|
1636
1639
|
memori.privacyType !== 'PUBLIC' &&
|
|
@@ -1642,82 +1645,95 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1642
1645
|
return;
|
|
1643
1646
|
}
|
|
1644
1647
|
else if (!sessionID || initialSessionExpired) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
:
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
initial: i === 0,
|
|
1689
|
-
});
|
|
1690
|
-
});
|
|
1691
|
-
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1692
|
-
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1693
|
-
isMultilanguageEnabled) {
|
|
1694
|
-
try {
|
|
1695
|
-
translatedMessages = await Promise.all(messages.map(async (m) => {
|
|
1696
|
-
if ('originalText' in m && m.originalText) {
|
|
1697
|
-
return m;
|
|
1698
|
-
}
|
|
1699
|
-
return {
|
|
1648
|
+
if (sessionStartingRef.current) {
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
sessionStartingRef.current = true;
|
|
1652
|
+
try {
|
|
1653
|
+
const session = await fetchSession({
|
|
1654
|
+
memoriID: memori.engineMemoriID,
|
|
1655
|
+
password: secret || memoriPwd || memori.secretToken,
|
|
1656
|
+
tag: personification === null || personification === void 0 ? void 0 : personification.tag,
|
|
1657
|
+
pin: personification === null || personification === void 0 ? void 0 : personification.pin,
|
|
1658
|
+
continueFromChatLogID: chatLog === null || chatLog === void 0 ? void 0 : chatLog.chatLogID,
|
|
1659
|
+
initialContextVars: {
|
|
1660
|
+
LANG: userLang,
|
|
1661
|
+
PATHNAME: (_a = window.location.pathname) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
1662
|
+
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()) ||
|
|
1663
|
+
'',
|
|
1664
|
+
...((!chatLog
|
|
1665
|
+
? initialContextVars
|
|
1666
|
+
: chatLog.lines[chatLog.lines.length - 1].contextVars) || {}),
|
|
1667
|
+
},
|
|
1668
|
+
initialQuestion: chatLog ? undefined : initialQuestion,
|
|
1669
|
+
birthDate: birth,
|
|
1670
|
+
additionalInfo: {
|
|
1671
|
+
...(additionalInfo || {}),
|
|
1672
|
+
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,
|
|
1673
|
+
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(),
|
|
1674
|
+
timeZoneOffset: new Date().getTimezoneOffset().toString(),
|
|
1675
|
+
},
|
|
1676
|
+
});
|
|
1677
|
+
if (session === null || session === void 0 ? void 0 : session.dialogState) {
|
|
1678
|
+
if (!chatLog) {
|
|
1679
|
+
setHistory([]);
|
|
1680
|
+
await translateAndSpeak(session.dialogState, userLang);
|
|
1681
|
+
setHasUserActivatedSpeak(true);
|
|
1682
|
+
setClickedStart(false);
|
|
1683
|
+
}
|
|
1684
|
+
else {
|
|
1685
|
+
const messages = chatLog.lines.map((l, i) => {
|
|
1686
|
+
var _a, _b;
|
|
1687
|
+
return ({
|
|
1688
|
+
text: l.text,
|
|
1689
|
+
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 => ({
|
|
1690
|
+
mediumID: `${i}-${m.mimeType}`,
|
|
1700
1691
|
...m,
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1692
|
+
})),
|
|
1693
|
+
fromUser: l.inbound,
|
|
1694
|
+
llmUsage: l.llmUsage,
|
|
1695
|
+
timestamp: l.timestamp,
|
|
1696
|
+
emitter: l.emitter,
|
|
1697
|
+
initial: i === 0,
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1701
|
+
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1702
|
+
isMultilanguageEnabled) {
|
|
1703
|
+
try {
|
|
1704
|
+
translatedMessages = await Promise.all(messages.map(async (m) => {
|
|
1705
|
+
if ('originalText' in m && m.originalText) {
|
|
1706
|
+
return m;
|
|
1707
|
+
}
|
|
1708
|
+
return {
|
|
1709
|
+
...m,
|
|
1710
|
+
originalText: m.text,
|
|
1711
|
+
text: (await getTranslation(m.text, userLang, language, baseUrl)).text,
|
|
1712
|
+
};
|
|
1713
|
+
}));
|
|
1714
|
+
}
|
|
1715
|
+
catch (e) {
|
|
1716
|
+
console.error('[onClickStart] Error translating messages:', e);
|
|
1717
|
+
}
|
|
1708
1718
|
}
|
|
1719
|
+
setHistory(translatedMessages);
|
|
1720
|
+
translateDialogState(session.dialogState, userLang, undefined, true).finally(() => {
|
|
1721
|
+
setHasUserActivatedSpeak(true);
|
|
1722
|
+
setClickedStart(false);
|
|
1723
|
+
});
|
|
1709
1724
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1725
|
+
}
|
|
1726
|
+
else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 0) {
|
|
1727
|
+
sessionStartingRef.current = false;
|
|
1728
|
+
await onClickStart(session || undefined);
|
|
1729
|
+
}
|
|
1730
|
+
else {
|
|
1731
|
+
setLoading(false);
|
|
1732
|
+
setClickedStart(false);
|
|
1714
1733
|
}
|
|
1715
1734
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
}
|
|
1719
|
-
else {
|
|
1720
|
-
setLoading(false);
|
|
1735
|
+
finally {
|
|
1736
|
+
sessionStartingRef.current = false;
|
|
1721
1737
|
}
|
|
1722
1738
|
return;
|
|
1723
1739
|
}
|
|
@@ -1727,7 +1743,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1727
1743
|
if (response.resultCode !== 0 || !currentState) {
|
|
1728
1744
|
const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
|
|
1729
1745
|
setSessionId(undefined);
|
|
1730
|
-
setClickedStart(false);
|
|
1731
1746
|
await onClickStart(undefined, true, chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]);
|
|
1732
1747
|
return;
|
|
1733
1748
|
}
|
|
@@ -1754,6 +1769,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1754
1769
|
...(initialContextVars || {}),
|
|
1755
1770
|
}, initialQuestion, birth).then(() => {
|
|
1756
1771
|
setHasUserActivatedSpeak(true);
|
|
1772
|
+
setClickedStart(false);
|
|
1757
1773
|
});
|
|
1758
1774
|
}
|
|
1759
1775
|
}
|
|
@@ -1780,6 +1796,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1780
1796
|
...(initialContextVars || {}),
|
|
1781
1797
|
}, initialQuestion, birth).then(() => {
|
|
1782
1798
|
setHasUserActivatedSpeak(true);
|
|
1799
|
+
setClickedStart(false);
|
|
1783
1800
|
});
|
|
1784
1801
|
}
|
|
1785
1802
|
}
|
|
@@ -1823,6 +1840,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1823
1840
|
if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
|
|
1824
1841
|
!initialQuestion) {
|
|
1825
1842
|
setHasUserActivatedSpeak(true);
|
|
1843
|
+
setClickedStart(false);
|
|
1826
1844
|
await translateAndSpeak(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length));
|
|
1827
1845
|
}
|
|
1828
1846
|
else {
|
|
@@ -1893,10 +1911,14 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1893
1911
|
}
|
|
1894
1912
|
}, [memoriPwd, memori, memoriTokens, birthDate, sessionId, userLang, position]);
|
|
1895
1913
|
useEffect(() => {
|
|
1896
|
-
if (!clickedStart &&
|
|
1914
|
+
if (!clickedStart &&
|
|
1915
|
+
!sessionStartingRef.current &&
|
|
1916
|
+
!sessionId &&
|
|
1917
|
+
autoStart &&
|
|
1918
|
+
selectedLayout !== 'HIDDEN_CHAT') {
|
|
1897
1919
|
onClickStart();
|
|
1898
1920
|
}
|
|
1899
|
-
}, [clickedStart, autoStart, selectedLayout]);
|
|
1921
|
+
}, [clickedStart, autoStart, selectedLayout, sessionId]);
|
|
1900
1922
|
useEffect(() => {
|
|
1901
1923
|
const targetNode = document.querySelector(`memori-client[memoriname="${memori.name}"]`) ||
|
|
1902
1924
|
document.querySelector(`memori-client[memoriid="${memori.memoriID}"]`) ||
|