@memori.ai/memori-react 7.16.0 → 7.16.2
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 +25 -0
- package/README.md +0 -1
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +73 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +25 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +166 -0
- package/dist/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
- package/dist/components/MemoriWidget/MemoriWidget.js +49 -16
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.d.ts +17 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js +69 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/MorhTargetController.js.map +1 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.d.ts +17 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js +22 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map +1 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.d.ts +26 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js +163 -0
- package/esm/components/Avatar/AvatarView/AvatarComponent/components/fullbodyAvatar.js.map +1 -0
- package/esm/components/MemoriWidget/MemoriWidget.js +49 -16
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.js +17 -12
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/MemoriWidget/MemoriWidget.tsx +78 -24
- package/src/index.tsx +15 -18
package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Vector3, Euler } from 'three';
|
|
2
|
+
export const AVATAR_POSITION = new Vector3(0, -1, 0);
|
|
3
|
+
export const AVATAR_ROTATION = new Euler(0.175, 0, 0);
|
|
4
|
+
export const AVATAR_POSITION_ZOOMED = new Vector3(0, -1.45, 0);
|
|
5
|
+
export const ANIMATION_URLS = {
|
|
6
|
+
MALE: 'https://assets.memori.ai/api/v2/asset/2c5e88a4-cf62-408b-9ef0-518b099dfcb2.glb',
|
|
7
|
+
FEMALE: 'https://assets.memori.ai/api/v2/asset/2adc934b-24b2-45bd-94ad-ffec58d3cb32.glb',
|
|
8
|
+
};
|
|
9
|
+
export const BLINK_CONFIG = {
|
|
10
|
+
minInterval: 1000,
|
|
11
|
+
maxInterval: 5000,
|
|
12
|
+
blinkDuration: 150,
|
|
13
|
+
};
|
|
14
|
+
export const DEFAULT_CONFIG = {
|
|
15
|
+
fadeInDuration: 0.8,
|
|
16
|
+
fadeOutDuration: 0.8,
|
|
17
|
+
idleCount: 5,
|
|
18
|
+
timeScale: 1.0,
|
|
19
|
+
};
|
|
20
|
+
export const EMOTION_SMOOTHING = 0.3;
|
|
21
|
+
export const VISEME_SMOOTHING = 0.5;
|
|
22
|
+
//# sourceMappingURL=constants.js.map
|
package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gFAAgF;IACtF,MAAM,EACJ,gFAAgF;CACnF,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,cAAc,EAAE,GAAG;IACnB,eAAe,EAAE,GAAG;IACpB,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,GAAG;CACf,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC"}
|
|
@@ -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,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EACL,OAAO,EACP,KAAK,EACL,cAAc,EACd,WAAW,EAEX,SAAS,EAET,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAY,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA8BxD,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9C,MAAM,eAAe,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/C,MAAM,sBAAsB,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAExD,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,gFAAgF;IACtF,MAAM,EACJ,gFAAgF;CACnF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,GAAG,EACH,GAAG,EACH,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB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AAG,CAAC,CAAC;oBACtC,UAAU,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;oBACtC,gBAAgB,CAAC,OAAO,GAAG,UAAU,CAAC;oBACtC,wBAAwB,CAAC,OAAO,GAAG,KAAK,CAAC;iBAC1C;aACF;SACF;QAED,MAAA,QAAQ,CAAC,OAAO,0CAAE,MAAM,CAAC,IAAI,CAAC,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"}
|
|
@@ -1653,7 +1653,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1653
1653
|
};
|
|
1654
1654
|
}, [sessionId, userLang, disableTextEnteredEvents]);
|
|
1655
1655
|
const onClickStart = useCallback(async (session, initialSessionExpired = false) => {
|
|
1656
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
1656
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t;
|
|
1657
1657
|
const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|
|
1658
1658
|
const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
|
|
1659
1659
|
setClickedStart(true);
|
|
@@ -1663,6 +1663,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1663
1663
|
!window.navigator.userAgent.includes('Chrome');
|
|
1664
1664
|
if (memoriAudioElement && isSafari) {
|
|
1665
1665
|
memoriAudioElement.muted = false;
|
|
1666
|
+
memoriAudioElement.play().catch((e) => {
|
|
1667
|
+
console.warn('error playing intro audio', e);
|
|
1668
|
+
});
|
|
1666
1669
|
}
|
|
1667
1670
|
let storageBirthDate = getLocalConfig('birthDate', undefined);
|
|
1668
1671
|
let birth = birthDate || storageBirthDate || undefined;
|
|
@@ -1721,8 +1724,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1721
1724
|
return;
|
|
1722
1725
|
}
|
|
1723
1726
|
else if (initialSessionID) {
|
|
1727
|
+
console.debug('[CLICK_START] Handling initial session');
|
|
1724
1728
|
const { currentState, ...response } = await getSession(sessionID);
|
|
1725
1729
|
if (response.resultCode !== 0 || !currentState) {
|
|
1730
|
+
console.debug('[CLICK_START] Session expired, opening new session');
|
|
1726
1731
|
setGotErrorInOpening(true);
|
|
1727
1732
|
setSessionId(undefined);
|
|
1728
1733
|
setClickedStart(false);
|
|
@@ -1735,8 +1740,9 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1735
1740
|
if (memori.needsDateTime)
|
|
1736
1741
|
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
1737
1742
|
if (personification &&
|
|
1738
|
-
|
|
1743
|
+
currentState.currentTag !== personification.tag) {
|
|
1739
1744
|
try {
|
|
1745
|
+
console.debug('[CLICK_START] Changing tag for personification', personification, currentState);
|
|
1740
1746
|
await changeTag(memori.engineMemoriID, sessionID, '-');
|
|
1741
1747
|
const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
|
|
1742
1748
|
if (session && session.resultCode === 0) {
|
|
@@ -1769,10 +1775,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1769
1775
|
}
|
|
1770
1776
|
}
|
|
1771
1777
|
else if (!personification &&
|
|
1772
|
-
(
|
|
1773
|
-
(
|
|
1774
|
-
(
|
|
1778
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) &&
|
|
1779
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) !== anonTag &&
|
|
1780
|
+
(currentState === null || currentState === void 0 ? void 0 : currentState.currentTag) !== '-') {
|
|
1775
1781
|
try {
|
|
1782
|
+
console.debug('[CLICK_START] Changing to anonymous tag');
|
|
1776
1783
|
await changeTag(memori.engineMemoriID, sessionID, '-');
|
|
1777
1784
|
const session = await changeTag(memori.engineMemoriID, sessionID, anonTag);
|
|
1778
1785
|
if (session && session.resultCode === 0) {
|
|
@@ -1806,6 +1813,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1806
1813
|
}
|
|
1807
1814
|
else {
|
|
1808
1815
|
try {
|
|
1816
|
+
console.debug('[CLICK_START] Getting chat history');
|
|
1809
1817
|
const { chatLogs, ...resp } = await getSessionChatLogs(sessionID, sessionID);
|
|
1810
1818
|
const messages = (_r = chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]) === null || _r === void 0 ? void 0 : _r.lines.map((l, i) => {
|
|
1811
1819
|
var _a, _b;
|
|
@@ -1821,10 +1829,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1821
1829
|
initial: i === 0,
|
|
1822
1830
|
});
|
|
1823
1831
|
});
|
|
1824
|
-
translatedMessages = messages;
|
|
1832
|
+
translatedMessages = messages !== null && messages !== void 0 ? messages : [];
|
|
1825
1833
|
if (language.toUpperCase() !== userLang.toUpperCase() &&
|
|
1826
1834
|
isMultilanguageEnabled) {
|
|
1827
1835
|
try {
|
|
1836
|
+
console.debug('[CLICK_START] Translating messages');
|
|
1828
1837
|
translatedMessages = await Promise.all(messages.map(async (m) => ({
|
|
1829
1838
|
...m,
|
|
1830
1839
|
originalText: m.text,
|
|
@@ -1835,19 +1844,42 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1835
1844
|
}
|
|
1836
1845
|
}
|
|
1837
1846
|
setHistory(translatedMessages);
|
|
1847
|
+
console.debug('[CLICK_START] props currentState:', currentState, 'userLang:', userLang, 'translatedMessages:', translatedMessages, 'history:', history);
|
|
1838
1848
|
}
|
|
1839
1849
|
catch (e) {
|
|
1850
|
+
console.log('[CLICK_START] Error retrieving chat logs:', e);
|
|
1851
|
+
}
|
|
1852
|
+
if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
|
|
1853
|
+
!initialQuestion) {
|
|
1854
|
+
translateDialogState(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length))
|
|
1855
|
+
.then(ts => {
|
|
1856
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1857
|
+
if (text) {
|
|
1858
|
+
speak(text);
|
|
1859
|
+
}
|
|
1860
|
+
})
|
|
1861
|
+
.finally(() => {
|
|
1862
|
+
setHasUserActivatedSpeak(true);
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
else {
|
|
1866
|
+
translatedMessages = [];
|
|
1867
|
+
setHistory([]);
|
|
1868
|
+
const response = await postTextEnteredEvent({
|
|
1869
|
+
sessionId: sessionID,
|
|
1870
|
+
text: initialQuestion,
|
|
1871
|
+
});
|
|
1872
|
+
translateDialogState((_t = response.currentState) !== null && _t !== void 0 ? _t : currentState, userLang, undefined, false)
|
|
1873
|
+
.then(ts => {
|
|
1874
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1875
|
+
if (text) {
|
|
1876
|
+
speak(text);
|
|
1877
|
+
}
|
|
1878
|
+
})
|
|
1879
|
+
.finally(() => {
|
|
1880
|
+
setHasUserActivatedSpeak(true);
|
|
1881
|
+
});
|
|
1840
1882
|
}
|
|
1841
|
-
translateDialogState(currentState, userLang, undefined, true)
|
|
1842
|
-
.then(ts => {
|
|
1843
|
-
let text = ts.translatedEmission || ts.emission;
|
|
1844
|
-
if (text) {
|
|
1845
|
-
speak(text);
|
|
1846
|
-
}
|
|
1847
|
-
})
|
|
1848
|
-
.finally(() => {
|
|
1849
|
-
setHasUserActivatedSpeak(true);
|
|
1850
|
-
});
|
|
1851
1883
|
}
|
|
1852
1884
|
if (position)
|
|
1853
1885
|
applyPosition(position, sessionID);
|
|
@@ -1855,6 +1887,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1855
1887
|
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
1856
1888
|
}
|
|
1857
1889
|
else {
|
|
1890
|
+
console.debug('[CLICK_START] Using existing session');
|
|
1858
1891
|
setHistory([]);
|
|
1859
1892
|
translateDialogState(dialogState, userLang)
|
|
1860
1893
|
.then(ts => {
|