@memori.ai/memori-react 7.14.1 → 7.15.0

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 (39) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
  3. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +73 -0
  4. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
  5. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
  6. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +25 -0
  7. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
  8. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +5 -3
  9. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  10. package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
  11. package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +166 -0
  12. package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
  13. package/dist/components/MemoriWidget/MemoriWidget.js +24 -25
  14. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  15. package/dist/components/layouts/FullPage.js +1 -1
  16. package/dist/components/layouts/FullPage.js.map +1 -1
  17. package/dist/components/layouts/website-assistant.css +2 -2
  18. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
  19. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +69 -0
  20. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
  21. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
  22. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +22 -0
  23. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
  24. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +5 -3
  25. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  26. package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
  27. package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +163 -0
  28. package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
  29. package/esm/components/MemoriWidget/MemoriWidget.js +24 -25
  30. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  31. package/esm/components/layouts/FullPage.js +1 -1
  32. package/esm/components/layouts/FullPage.js.map +1 -1
  33. package/esm/components/layouts/website-assistant.css +2 -2
  34. package/package.json +1 -1
  35. package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.tsx +5 -4
  36. package/src/components/MemoriWidget/MemoriWidget.tsx +135 -49
  37. package/src/components/layouts/FullPage.tsx +1 -1
  38. package/src/components/layouts/website-assistant.css +2 -2
  39. package/src/index.stories.tsx +18 -0
@@ -0,0 +1,26 @@
1
+ interface FullbodyAvatarProps {
2
+ url: string;
3
+ sex: 'MALE' | 'FEMALE';
4
+ onLoaded?: () => void;
5
+ currentBaseAction: {
6
+ action: string;
7
+ weight: number;
8
+ };
9
+ timeScale: number;
10
+ isZoomed?: boolean;
11
+ eyeBlink?: boolean;
12
+ stopProcessing: () => void;
13
+ resetVisemeQueue: () => void;
14
+ updateCurrentViseme: (currentTime: number) => {
15
+ name: string;
16
+ weight: number;
17
+ } | null;
18
+ smoothMorphTarget?: boolean;
19
+ morphTargetSmoothing?: number;
20
+ morphTargetInfluences: Record<string, number>;
21
+ setMorphTargetDictionary: (morphTargetDictionary: Record<string, number>) => void;
22
+ setMorphTargetInfluences: (morphTargetInfluences: Record<string, number>) => void;
23
+ emotionMorphTargets: Record<string, number>;
24
+ }
25
+ export default function FullbodyAvatar({ url, sex, currentBaseAction, timeScale, isZoomed, eyeBlink, updateCurrentViseme, setMorphTargetDictionary, setMorphTargetInfluences, emotionMorphTargets, }: FullbodyAvatarProps): JSX.Element;
26
+ export {};
@@ -0,0 +1,163 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useMemo, useCallback } from 'react';
3
+ import { Vector3, Euler, AnimationMixer, SkinnedMesh, MathUtils, LoopOnce, } from 'three';
4
+ import { useAnimations, useGLTF } from '@react-three/drei';
5
+ import { useFrame } from '@react-three/fiber';
6
+ const AVATAR_POSITION = new Vector3(0, -1, 0);
7
+ const AVATAR_ROTATION = new Euler(0.175, 0, 0);
8
+ const AVATAR_POSITION_ZOOMED = new Vector3(0, -1.45, 0);
9
+ const ANIMATION_URLS = {
10
+ MALE: 'https://assets.memori.ai/api/v2/asset/2c5e88a4-cf62-408b-9ef0-518b099dfcb2.glb',
11
+ FEMALE: 'https://assets.memori.ai/api/v2/asset/8d1a5853-f05a-4a34-9f99-6eff64986081.glb',
12
+ };
13
+ const BLINK_CONFIG = {
14
+ minInterval: 1000,
15
+ maxInterval: 5000,
16
+ blinkDuration: 150,
17
+ };
18
+ const EMOTION_SMOOTHING = 0.3;
19
+ const VISME_SMOOTHING = 0.5;
20
+ export default function FullbodyAvatar({ url, sex, currentBaseAction, timeScale, isZoomed, eyeBlink, updateCurrentViseme, setMorphTargetDictionary, setMorphTargetInfluences, emotionMorphTargets, }) {
21
+ const { scene } = useGLTF(url);
22
+ const { animations } = useGLTF(ANIMATION_URLS[sex]);
23
+ const { actions } = useAnimations(animations, scene);
24
+ const mixerRef = useRef();
25
+ const headMeshRef = useRef();
26
+ const currentActionRef = useRef(null);
27
+ const isTransitioningToIdleRef = useRef(false);
28
+ const lastBlinkTimeRef = useRef(0);
29
+ const nextBlinkTimeRef = useRef(0);
30
+ const isBlinkingRef = useRef(false);
31
+ const blinkStartTimeRef = useRef(0);
32
+ const currentEmotionRef = useRef({});
33
+ const previousEmotionKeysRef = useRef(new Set());
34
+ const headMesh = useMemo(() => {
35
+ let foundMesh;
36
+ scene.traverse((object) => {
37
+ if (object instanceof SkinnedMesh &&
38
+ (object.name === 'GBNL__Head' || object.name === 'Wolf3D_Avatar')) {
39
+ foundMesh = object;
40
+ }
41
+ });
42
+ return foundMesh;
43
+ }, [scene]);
44
+ useEffect(() => {
45
+ if (headMesh) {
46
+ headMeshRef.current = headMesh;
47
+ if (headMesh.morphTargetDictionary && headMesh.morphTargetInfluences) {
48
+ setMorphTargetDictionary(headMesh.morphTargetDictionary);
49
+ const initialInfluences = Object.keys(headMesh.morphTargetDictionary).reduce((acc, key) => ({ ...acc, [key]: 0 }), {});
50
+ setMorphTargetInfluences(initialInfluences);
51
+ }
52
+ }
53
+ mixerRef.current = new AnimationMixer(scene);
54
+ }, [headMesh, scene, setMorphTargetDictionary, setMorphTargetInfluences]);
55
+ const handleAnimationChange = useCallback(() => {
56
+ if (!actions || !currentBaseAction.action)
57
+ return;
58
+ const newAction = actions[currentBaseAction.action];
59
+ if (!newAction) {
60
+ console.warn(`Animation "${currentBaseAction.action}" not found in actions.`);
61
+ return;
62
+ }
63
+ const fadeOutDuration = 0.8;
64
+ const fadeInDuration = 0.8;
65
+ if (currentActionRef.current) {
66
+ currentActionRef.current.fadeOut(fadeOutDuration);
67
+ }
68
+ newAction.reset().fadeIn(fadeInDuration).play();
69
+ currentActionRef.current = newAction;
70
+ newAction.timeScale = timeScale;
71
+ if (currentBaseAction.action.startsWith('Gioia') ||
72
+ currentBaseAction.action.startsWith('Rabbia') ||
73
+ currentBaseAction.action.startsWith('Sorpresa') ||
74
+ currentBaseAction.action.startsWith('Timore') ||
75
+ currentBaseAction.action.startsWith('Tristezza')) {
76
+ newAction.setLoop(LoopOnce, 1);
77
+ newAction.clampWhenFinished = true;
78
+ isTransitioningToIdleRef.current = true;
79
+ }
80
+ }, [actions, currentBaseAction, timeScale]);
81
+ useEffect(() => {
82
+ handleAnimationChange();
83
+ }, [handleAnimationChange]);
84
+ const updateFrame = useCallback((currentTime) => {
85
+ var _a;
86
+ if (!headMeshRef.current ||
87
+ !headMeshRef.current.morphTargetDictionary ||
88
+ !headMeshRef.current.morphTargetInfluences)
89
+ return;
90
+ let blinkValue = 0;
91
+ if (eyeBlink) {
92
+ if (currentTime >= nextBlinkTimeRef.current && !isBlinkingRef.current) {
93
+ isBlinkingRef.current = true;
94
+ blinkStartTimeRef.current = currentTime;
95
+ lastBlinkTimeRef.current = currentTime;
96
+ nextBlinkTimeRef.current =
97
+ currentTime +
98
+ Math.random() *
99
+ (BLINK_CONFIG.maxInterval - BLINK_CONFIG.minInterval) +
100
+ BLINK_CONFIG.minInterval;
101
+ }
102
+ if (isBlinkingRef.current) {
103
+ const blinkProgress = (currentTime - blinkStartTimeRef.current) /
104
+ BLINK_CONFIG.blinkDuration;
105
+ if (blinkProgress <= 0.5) {
106
+ blinkValue = blinkProgress * 2;
107
+ }
108
+ else if (blinkProgress <= 1) {
109
+ blinkValue = 2 - blinkProgress * 2;
110
+ }
111
+ else {
112
+ isBlinkingRef.current = false;
113
+ blinkValue = 0;
114
+ }
115
+ }
116
+ }
117
+ const currentViseme = updateCurrentViseme(currentTime / 1000);
118
+ const currentEmotionKeys = new Set(Object.keys(emotionMorphTargets));
119
+ Object.entries(headMeshRef.current.morphTargetDictionary).forEach(([key, index]) => {
120
+ if (typeof index === 'number') {
121
+ let targetValue = 0;
122
+ if (currentEmotionKeys.has(key)) {
123
+ const targetEmotionValue = emotionMorphTargets[key];
124
+ const currentEmotionValue = currentEmotionRef.current[key] || 0;
125
+ const newEmotionValue = MathUtils.lerp(currentEmotionValue, targetEmotionValue * 2.5, EMOTION_SMOOTHING);
126
+ currentEmotionRef.current[key] = newEmotionValue;
127
+ targetValue += newEmotionValue;
128
+ }
129
+ if (currentViseme && key === currentViseme.name) {
130
+ targetValue += currentViseme.weight;
131
+ }
132
+ if (key === 'eyesClosed' && eyeBlink) {
133
+ targetValue += blinkValue;
134
+ }
135
+ targetValue = MathUtils.clamp(targetValue, 0, 1);
136
+ if (headMeshRef.current &&
137
+ headMeshRef.current.morphTargetInfluences) {
138
+ headMeshRef.current.morphTargetInfluences[index] = MathUtils.lerp(headMeshRef.current.morphTargetInfluences[index], targetValue, VISME_SMOOTHING);
139
+ }
140
+ }
141
+ });
142
+ previousEmotionKeysRef.current = currentEmotionKeys;
143
+ if (isTransitioningToIdleRef.current && currentActionRef.current) {
144
+ if (currentActionRef.current.time >=
145
+ currentActionRef.current.getClip().duration) {
146
+ const idleNumber = Math.floor(Math.random() * 5) + 1;
147
+ const idleAction = actions[`Idle${idleNumber === 3 ? 4 : idleNumber}`];
148
+ if (idleAction) {
149
+ currentActionRef.current.fadeOut(0.5);
150
+ idleAction.reset().fadeIn(0.5).play();
151
+ currentActionRef.current = idleAction;
152
+ isTransitioningToIdleRef.current = false;
153
+ }
154
+ }
155
+ }
156
+ (_a = mixerRef.current) === null || _a === void 0 ? void 0 : _a.update(0.01);
157
+ }, [actions, emotionMorphTargets, eyeBlink, updateCurrentViseme]);
158
+ useFrame(state => {
159
+ updateFrame(state.clock.elapsedTime * 1000);
160
+ });
161
+ return (_jsx("group", { position: isZoomed ? AVATAR_POSITION_ZOOMED : AVATAR_POSITION, rotation: AVATAR_ROTATION, children: _jsx("primitive", { object: scene }) }));
162
+ }
163
+ //# sourceMappingURL=fullbodyAvatar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fullbodyAvatar.js","sourceRoot":"","sources":["../../../../../../src/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.tsx"],"names":[],"mappings":";AAAA,OAAc,EAA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AAC,CAAC;IACjC,CAAC,EACD,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAC9D,CAAC;IAEF,QAAQ,CAAC,KAAK,CAAC,EAAE;QACf,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,gBACE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,eAAe,EAC7D,QAAQ,EAAE,eAAe,YAEzB,oBAAW,MAAM,EAAE,KAAK,GAAI,GACtB,CACT,CAAC;AACJ,CAAC"}
@@ -434,14 +434,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
434
434
  setMemoriTyping(false);
435
435
  }
436
436
  };
437
- const translateDialogState = async (state, userLang, msg) => {
437
+ const translateDialogState = async (state, userLang, msg, avoidPushingMessage = false) => {
438
438
  var _a, _b, _c;
439
439
  const emission = (_a = state === null || state === void 0 ? void 0 : state.emission) !== null && _a !== void 0 ? _a : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
440
440
  let translatedState = { ...state };
441
441
  let translatedMsg = null;
442
442
  if (!emission ||
443
443
  language.toUpperCase() === userLang.toUpperCase() ||
444
- !isMultilanguageEnabled) {
444
+ !isMultilanguageEnabled ||
445
+ avoidPushingMessage) {
445
446
  translatedState = { ...state, emission };
446
447
  if (emission) {
447
448
  translatedMsg = {
@@ -487,7 +488,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
487
488
  hints: (_c = state.hints) !== null && _c !== void 0 ? _c : (state.state === 'G1' ? currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.hints : []),
488
489
  };
489
490
  }
490
- if (t.text.length > 0)
491
+ if (t.text.length > 0) {
491
492
  translatedMsg = {
492
493
  text: emission,
493
494
  translatedText: t.text,
@@ -505,9 +506,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
505
506
  tag: state.currentTag,
506
507
  memoryTags: state.memoryTags,
507
508
  };
509
+ }
508
510
  }
509
511
  catch (error) {
510
- console.error(error);
512
+ console.error('[TRANSLATE] Error during translation:', error);
511
513
  translatedState = { ...state, emission };
512
514
  translatedMsg = {
513
515
  text: emission,
@@ -527,7 +529,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
527
529
  }
528
530
  }
529
531
  setCurrentDialogState(translatedState);
530
- if (translatedMsg) {
532
+ if (!avoidPushingMessage && translatedMsg) {
531
533
  pushMessage(translatedMsg);
532
534
  }
533
535
  return translatedState;
@@ -667,9 +669,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
667
669
  referral = (() => {
668
670
  return window.location.href;
669
671
  })();
672
+ console.log('[REOPEN_SESSION] Got referral:', referral);
670
673
  }
671
674
  catch (err) {
672
- console.debug(err);
675
+ console.debug('[REOPEN_SESSION] Error getting referral:', err);
673
676
  }
674
677
  const { sessionID, currentState, ...response } = await initSession({
675
678
  memoriID: (_a = memori.engineMemoriID) !== null && _a !== void 0 ? _a : '',
@@ -732,10 +735,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
732
735
  });
733
736
  }
734
737
  }
735
- if (position)
738
+ if (position) {
736
739
  applyPosition(position, sessionID);
737
- if (memori.needsDateTime)
740
+ }
741
+ if (memori.needsDateTime) {
738
742
  sendDateChangedEvent({ sessionID: sessionID, state: currentState });
743
+ }
739
744
  setLoading(false);
740
745
  return {
741
746
  dialogState: currentState,
@@ -743,22 +748,23 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
743
748
  };
744
749
  }
745
750
  else if (response === null || response === void 0 ? void 0 : response.resultMessage.startsWith('This Memori is aged restricted')) {
746
- console.error(response);
751
+ console.error('[REOPEN_SESSION] Age restriction error:', response);
747
752
  toast.error(t('underageTwinSession', { age: minAge }));
748
753
  setGotErrorInOpening(true);
749
754
  }
750
755
  else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403) {
756
+ console.error('[REOPEN_SESSION] Authentication error');
751
757
  setMemoriPwd(undefined);
752
758
  setAuthModalState('password');
753
759
  }
754
760
  else {
755
- console.error(response);
761
+ console.error('[REOPEN_SESSION] Other error:', response);
756
762
  toast.error(t(getErrori18nKey(response.resultCode)));
757
763
  setGotErrorInOpening(true);
758
764
  }
759
765
  }
760
766
  catch (err) {
761
- console.error(err);
767
+ console.error('[REOPEN_SESSION] Caught error:', err);
762
768
  }
763
769
  setLoading(false);
764
770
  return null;
@@ -1651,14 +1657,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1651
1657
  const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
1652
1658
  const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
1653
1659
  setClickedStart(true);
1660
+ let translatedMessages = [];
1654
1661
  let memoriAudioElement = document.getElementById('memori-audio');
1655
1662
  let isSafari = window.navigator.userAgent.includes('Safari') &&
1656
1663
  !window.navigator.userAgent.includes('Chrome');
1657
1664
  if (memoriAudioElement && isSafari) {
1658
1665
  memoriAudioElement.muted = false;
1659
- memoriAudioElement.play().catch((e) => {
1660
- console.warn('error playing intro audio', e);
1661
- });
1662
1666
  }
1663
1667
  let storageBirthDate = getLocalConfig('birthDate', undefined);
1664
1668
  let birth = birthDate || storageBirthDate || undefined;
@@ -1719,7 +1723,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1719
1723
  else if (initialSessionID) {
1720
1724
  const { currentState, ...response } = await getSession(sessionID);
1721
1725
  if (response.resultCode !== 0 || !currentState) {
1722
- console.debug('session expired, opening new session');
1723
1726
  setGotErrorInOpening(true);
1724
1727
  setSessionId(undefined);
1725
1728
  setClickedStart(false);
@@ -1734,7 +1737,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1734
1737
  if (personification &&
1735
1738
  (currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.currentTag) !== personification.tag) {
1736
1739
  try {
1737
- console.debug('change tag #3');
1738
1740
  await changeTag(memori.engineMemoriID, sessionID, '-');
1739
1741
  const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
1740
1742
  if (session && session.resultCode === 0) {
@@ -1750,12 +1752,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1750
1752
  });
1751
1753
  }
1752
1754
  else {
1753
- console.error('session #4', session);
1755
+ console.error('[CLICK_START] Session error:', session);
1754
1756
  throw new Error('No session');
1755
1757
  }
1756
1758
  }
1757
1759
  catch (e) {
1758
- console.error('session #5', e);
1760
+ console.error('[CLICK_START] Error changing tag:', e);
1759
1761
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, personification.tag, personification.pin, {
1760
1762
  PATHNAME: (_h = window.location.pathname) === null || _h === void 0 ? void 0 : _h.toUpperCase(),
1761
1763
  ROUTE: ((_l = (_k = (_j = window.location.pathname) === null || _j === void 0 ? void 0 : _j.split('/')) === null || _k === void 0 ? void 0 : _k.pop()) === null || _l === void 0 ? void 0 : _l.toUpperCase()) ||
@@ -1771,7 +1773,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1771
1773
  (currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.currentTag) !== anonTag &&
1772
1774
  (currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.currentTag) !== '-') {
1773
1775
  try {
1774
- console.debug('change tag #6');
1775
1776
  await changeTag(memori.engineMemoriID, sessionID, '-');
1776
1777
  const session = await changeTag(memori.engineMemoriID, sessionID, anonTag);
1777
1778
  if (session && session.resultCode === 0) {
@@ -1787,12 +1788,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1787
1788
  });
1788
1789
  }
1789
1790
  else {
1790
- console.error('session #7', session);
1791
+ console.error('[CLICK_START] Session error:', session);
1791
1792
  throw new Error('No session');
1792
1793
  }
1793
1794
  }
1794
1795
  catch (e) {
1795
- console.error('session #8', e);
1796
+ console.error('[CLICK_START] Error changing tag:', e);
1796
1797
  reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, undefined, undefined, {
1797
1798
  PATHNAME: (_m = window.location.pathname) === null || _m === void 0 ? void 0 : _m.toUpperCase(),
1798
1799
  ROUTE: ((_q = (_p = (_o = window.location.pathname) === null || _o === void 0 ? void 0 : _o.split('/')) === null || _p === void 0 ? void 0 : _p.pop()) === null || _q === void 0 ? void 0 : _q.toUpperCase()) ||
@@ -1820,7 +1821,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1820
1821
  initial: i === 0,
1821
1822
  });
1822
1823
  });
1823
- let translatedMessages = messages.slice(0, -1);
1824
+ translatedMessages = messages;
1824
1825
  if (language.toUpperCase() !== userLang.toUpperCase() &&
1825
1826
  isMultilanguageEnabled) {
1826
1827
  try {
@@ -1831,15 +1832,13 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
1831
1832
  })));
1832
1833
  }
1833
1834
  catch (e) {
1834
- console.log('Error translating messages', e);
1835
1835
  }
1836
1836
  }
1837
1837
  setHistory(translatedMessages);
1838
1838
  }
1839
1839
  catch (e) {
1840
- console.log('Error retrieving chat logs', e);
1841
1840
  }
1842
- translateDialogState(currentState, userLang)
1841
+ translateDialogState(currentState, userLang, undefined, true)
1843
1842
  .then(ts => {
1844
1843
  let text = ts.translatedEmission || ts.emission;
1845
1844
  if (text) {