@streamoji/avatar-widget 0.4.2 → 0.4.3
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/dist/avatar-widget.cjs +6 -6
- package/dist/avatar-widget.css +1 -1
- package/dist/avatar-widget.js +805 -789
- package/dist/avatar-widget.umd.js +53 -53
- package/dist/avatar-widget.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,100 +1,90 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useGLTF as
|
|
3
|
-
import { useFrame as
|
|
4
|
-
import { memo as
|
|
5
|
-
import * as
|
|
6
|
-
import { GLTFLoader as
|
|
7
|
-
const
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
const y =
|
|
1
|
+
import { jsx as l, jsxs as be } from "react/jsx-runtime";
|
|
2
|
+
import { useGLTF as Mt, Environment as Ln } from "@react-three/drei";
|
|
3
|
+
import { useFrame as vn, Canvas as kn, useThree as Rn } from "@react-three/fiber";
|
|
4
|
+
import { memo as xn, useMemo as Ct, useRef as a, useState as S, useEffect as W, useCallback as et, useLayoutEffect as Tn, Suspense as An } from "react";
|
|
5
|
+
import * as at from "three";
|
|
6
|
+
import { GLTFLoader as En } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
|
+
const tt = "https://ai.streamoji.com", U = (...p) => {
|
|
8
|
+
}, Mn = (...p) => {
|
|
9
|
+
}, zt = ({ analyser: p }) => {
|
|
10
|
+
const E = a(null), w = a(null);
|
|
11
|
+
return W(() => {
|
|
12
|
+
const y = E.current;
|
|
13
13
|
if (!y) return;
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
(!
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
for (let
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
for (let
|
|
34
|
-
const
|
|
35
|
-
|
|
14
|
+
const j = y.getContext("2d", { alpha: !0 });
|
|
15
|
+
if (!j) return;
|
|
16
|
+
let Z, ee = null;
|
|
17
|
+
p && (p.fftSize = 128, ee = new Uint8Array(p.frequencyBinCount));
|
|
18
|
+
const nt = () => {
|
|
19
|
+
Z = requestAnimationFrame(nt), (y.width !== y.offsetWidth || y.height !== y.offsetHeight) && (y.width = y.offsetWidth, y.height = y.offsetHeight);
|
|
20
|
+
const Be = y.width, F = y.height;
|
|
21
|
+
if (Be === 0 || F === 0) return;
|
|
22
|
+
const rt = F / 2;
|
|
23
|
+
j.clearRect(0, 0, Be, F), j.fillStyle = "#1e293b";
|
|
24
|
+
const Te = 2, J = Te + 2, Ae = Be * 0.95, q = Math.floor(Ae / J);
|
|
25
|
+
(!w.current || w.current.length !== q) && (w.current = new Float32Array(q).fill(2));
|
|
26
|
+
const se = q * J, M = (Be - se) / 2;
|
|
27
|
+
p && ee && p.getByteFrequencyData(ee);
|
|
28
|
+
const _e = ee ? ee.length : 0, b = Math.floor(_e * 0.7) / q, ae = new Float32Array(q);
|
|
29
|
+
for (let f = 0; f < q; f++) {
|
|
30
|
+
let O = 0;
|
|
31
|
+
if (ee && b > 0) {
|
|
32
|
+
const I = Math.floor(f * b), N = Math.floor((f + 1) * b);
|
|
33
|
+
for (let Y = I; Y < N; Y++) {
|
|
34
|
+
const Q = ee[Y] || 0;
|
|
35
|
+
Q > O && (O = Q);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
38
|
+
O < 10 && (O = 0);
|
|
39
|
+
const z = O / 255, T = O > 0 ? Math.max(2, Math.pow(z, 1.4) * F * 0.25) : 2;
|
|
40
|
+
ae[f] = T;
|
|
41
41
|
}
|
|
42
|
-
for (let
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
42
|
+
for (let f = 0; f < q; f++) {
|
|
43
|
+
const O = q - 1 - f, z = Math.max(ae[f], ae[O]), T = w.current[f] + (z - w.current[f]) * 0.3;
|
|
44
|
+
w.current[f] = T;
|
|
45
|
+
const I = M + f * J, N = rt - T / 2;
|
|
46
|
+
j.beginPath(), j.roundRect ? j.roundRect(I, N, Te, T, 4) : j.fillRect(I, N, Te, T), j.fill();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
return
|
|
50
|
-
cancelAnimationFrame(
|
|
49
|
+
return nt(), () => {
|
|
50
|
+
cancelAnimationFrame(Z);
|
|
51
51
|
};
|
|
52
|
-
}, [
|
|
52
|
+
}, [p]), /* @__PURE__ */ l(
|
|
53
53
|
"canvas",
|
|
54
54
|
{
|
|
55
|
-
ref:
|
|
55
|
+
ref: E,
|
|
56
56
|
style: { width: "100%", height: "100%", display: "block" }
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return Array.from(new Uint8Array(C)).map((E) => E.toString(16).padStart(2, "0")).join("");
|
|
66
|
-
}
|
|
67
|
-
function xn(m) {
|
|
68
|
-
const [C, E] = x(null);
|
|
69
|
-
return j(() => {
|
|
70
|
-
if (!m) {
|
|
71
|
-
E(null);
|
|
59
|
+
}, In = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Yt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
|
|
60
|
+
function Dn(p) {
|
|
61
|
+
const [E, w] = S(null);
|
|
62
|
+
return W(() => {
|
|
63
|
+
if (!p) {
|
|
64
|
+
w(null);
|
|
72
65
|
return;
|
|
73
66
|
}
|
|
74
67
|
let y = !1;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}).catch(() => {
|
|
81
|
-
y || E(qt);
|
|
82
|
-
});
|
|
68
|
+
const j = `${In}/${p}.glb`;
|
|
69
|
+
return fetch(j, { method: "HEAD" }).then((Z) => {
|
|
70
|
+
y || w(Z.ok ? j : Yt);
|
|
71
|
+
}).catch(() => {
|
|
72
|
+
y || w(Yt);
|
|
83
73
|
}), () => {
|
|
84
74
|
y = !0;
|
|
85
75
|
};
|
|
86
|
-
}, [
|
|
76
|
+
}, [p]), E;
|
|
87
77
|
}
|
|
88
|
-
const
|
|
78
|
+
const On = [
|
|
89
79
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
|
|
90
80
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
|
|
91
81
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
|
|
92
82
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
|
|
93
|
-
],
|
|
83
|
+
], Cn = [
|
|
94
84
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb",
|
|
95
85
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb",
|
|
96
86
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"
|
|
97
|
-
],
|
|
87
|
+
], Un = [
|
|
98
88
|
{
|
|
99
89
|
id: "m_expr_01",
|
|
100
90
|
name: "Friendly Wave",
|
|
@@ -260,23 +250,23 @@ const Tn = [
|
|
|
260
250
|
name: "Take It Easy",
|
|
261
251
|
url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
|
|
262
252
|
}
|
|
263
|
-
],
|
|
253
|
+
], Fn = [
|
|
264
254
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
|
|
265
255
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
|
|
266
256
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"
|
|
267
|
-
],
|
|
257
|
+
], Nn = [
|
|
268
258
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb",
|
|
269
259
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb",
|
|
270
260
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb",
|
|
271
261
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"
|
|
272
|
-
],
|
|
262
|
+
], Pn = {
|
|
273
263
|
zoom: 0.85,
|
|
274
264
|
position: [0.15, -0.8, 0],
|
|
275
265
|
scale: 1.5,
|
|
276
266
|
rotation: [0.15, 0.02, 0]
|
|
277
|
-
},
|
|
267
|
+
}, Bn = [-0.45, 1.9, 0.1], Wn = [-0.45, 1.75, 0.1], Vn = {
|
|
278
268
|
browInnerUp: 0.2
|
|
279
|
-
},
|
|
269
|
+
}, It = 0.18, $n = 1, Hn = 0.5, Kt = 3, bt = 0.55, Dt = 0.12, Qt = 2, Xt = 2, _t = 4, Zt = 8, jn = 1, en = 0.38, tn = 0.32, nn = "__branding__", wt = {
|
|
280
270
|
neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
|
|
281
271
|
happy: {
|
|
282
272
|
mouthSmileLeft: 0.2,
|
|
@@ -358,7 +348,7 @@ const Tn = [
|
|
|
358
348
|
mouthUpperUpLeft: 0.1,
|
|
359
349
|
mouthUpperUpRight: 0.1
|
|
360
350
|
}
|
|
361
|
-
},
|
|
351
|
+
}, Jn = [
|
|
362
352
|
{
|
|
363
353
|
key: "viseme_aa",
|
|
364
354
|
mix: { jawOpen: 0.4, mouthSmileLeft: 0.15, mouthSmileRight: 0.15 },
|
|
@@ -593,7 +583,7 @@ const Tn = [
|
|
|
593
583
|
}
|
|
594
584
|
},
|
|
595
585
|
{ key: "viseme_sil", mix: {} }
|
|
596
|
-
],
|
|
586
|
+
], Gn = {
|
|
597
587
|
aei: [
|
|
598
588
|
{ v: "E", w: 0.8 },
|
|
599
589
|
{ v: "I", w: 0.2 }
|
|
@@ -622,507 +612,533 @@ const Tn = [
|
|
|
622
612
|
],
|
|
623
613
|
sil: [{ v: "sil", w: 1 }]
|
|
624
614
|
};
|
|
625
|
-
function
|
|
626
|
-
if (!
|
|
627
|
-
const
|
|
628
|
-
return
|
|
615
|
+
function qn(p) {
|
|
616
|
+
if (!p) return [{ v: "sil", w: 1 }];
|
|
617
|
+
const E = p.toLowerCase();
|
|
618
|
+
return Gn[E] ?? [{ v: "sil", w: 1 }];
|
|
629
619
|
}
|
|
630
|
-
function
|
|
631
|
-
const { camera:
|
|
632
|
-
return
|
|
633
|
-
|
|
634
|
-
}, [
|
|
620
|
+
function zn({ target: p }) {
|
|
621
|
+
const { camera: E } = Rn();
|
|
622
|
+
return W(() => {
|
|
623
|
+
E.lookAt(...p);
|
|
624
|
+
}, [E, p]), null;
|
|
635
625
|
}
|
|
636
|
-
function c(
|
|
637
|
-
if (!
|
|
626
|
+
function c(p, E, w) {
|
|
627
|
+
if (!p || !p.morphTargetDictionary)
|
|
638
628
|
return;
|
|
639
|
-
const y =
|
|
640
|
-
if (
|
|
641
|
-
for (const
|
|
642
|
-
|
|
629
|
+
const y = p, j = y.morphTargetDictionary, Z = y.morphTargetInfluences;
|
|
630
|
+
if (Z)
|
|
631
|
+
for (const ee in j)
|
|
632
|
+
ee.toLowerCase() === E.toLowerCase() && (Z[j[ee]] = w);
|
|
643
633
|
}
|
|
644
|
-
function
|
|
645
|
-
if (!
|
|
646
|
-
const
|
|
647
|
-
if (
|
|
648
|
-
for (let y = 0; y <
|
|
649
|
-
|
|
634
|
+
function Ot(p, E = 0.97) {
|
|
635
|
+
if (!p) return;
|
|
636
|
+
const w = p;
|
|
637
|
+
if (w.morphTargetInfluences)
|
|
638
|
+
for (let y = 0; y < w.morphTargetInfluences.length; y++)
|
|
639
|
+
w.morphTargetInfluences[y] *= E;
|
|
650
640
|
}
|
|
651
|
-
const
|
|
641
|
+
const Yn = xn(
|
|
652
642
|
({
|
|
653
|
-
avatarUrl:
|
|
654
|
-
isPlayingRef:
|
|
655
|
-
visemeQueueRef:
|
|
643
|
+
avatarUrl: p,
|
|
644
|
+
isPlayingRef: E,
|
|
645
|
+
visemeQueueRef: w,
|
|
656
646
|
audioContextRef: y,
|
|
657
|
-
responseAudioStartTimeRef:
|
|
658
|
-
adjustments:
|
|
659
|
-
mood:
|
|
660
|
-
expression:
|
|
661
|
-
agentResponse:
|
|
662
|
-
isSpeaking:
|
|
663
|
-
nextStartTimeRef:
|
|
664
|
-
stopPlayback:
|
|
665
|
-
setIsSpeaking:
|
|
666
|
-
expressionUrl:
|
|
667
|
-
onExpressionFinished:
|
|
668
|
-
isNudgeResponse:
|
|
669
|
-
avatarGender:
|
|
647
|
+
responseAudioStartTimeRef: j,
|
|
648
|
+
adjustments: Z,
|
|
649
|
+
mood: ee,
|
|
650
|
+
expression: nt,
|
|
651
|
+
agentResponse: Be,
|
|
652
|
+
isSpeaking: F,
|
|
653
|
+
nextStartTimeRef: rt,
|
|
654
|
+
stopPlayback: Te,
|
|
655
|
+
setIsSpeaking: We,
|
|
656
|
+
expressionUrl: J,
|
|
657
|
+
onExpressionFinished: Ae,
|
|
658
|
+
isNudgeResponse: q,
|
|
659
|
+
avatarGender: se
|
|
670
660
|
}) => {
|
|
671
|
-
const { scene:
|
|
672
|
-
() =>
|
|
673
|
-
[
|
|
674
|
-
),
|
|
675
|
-
() =>
|
|
676
|
-
[
|
|
677
|
-
),
|
|
678
|
-
|
|
679
|
-
if (!(!
|
|
680
|
-
if (
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
683
|
-
const
|
|
684
|
-
|
|
661
|
+
const { scene: M } = Mt(p), H = Mt(se === "female" ? Cn : On), b = Ct(
|
|
662
|
+
() => H.flatMap((m) => m.animations),
|
|
663
|
+
[H]
|
|
664
|
+
), f = Mt(se === "female" ? Nn : Fn), O = Ct(
|
|
665
|
+
() => f.flatMap((m) => m.animations),
|
|
666
|
+
[f]
|
|
667
|
+
), z = a(null), T = a(null), I = a(null), N = a(null), Y = a(null), Q = a(null), yt = a([]), [te] = S(() => new at.AnimationMixer(M)), G = a({}), V = a(null), Ee = a(0), Xe = a(!1), Ve = a(0), Me = a(!1), we = a(null), Ie = a(Kt), ct = a(-1), De = a("left"), $e = a(_t + Math.random() * (Zt - _t)), de = a(0), Oe = a("smile");
|
|
668
|
+
W(() => {
|
|
669
|
+
if (!(!b || !M)) {
|
|
670
|
+
if (b.forEach((m, h) => {
|
|
671
|
+
const s = `idle_${h}`;
|
|
672
|
+
if (!G.current[s]) {
|
|
673
|
+
const o = te.clipAction(m, M);
|
|
674
|
+
o.name = s, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[s] = o;
|
|
685
675
|
}
|
|
686
|
-
}),
|
|
687
|
-
const
|
|
688
|
-
if (!
|
|
689
|
-
const
|
|
690
|
-
|
|
676
|
+
}), O.forEach((m, h) => {
|
|
677
|
+
const s = `talk_${h}`;
|
|
678
|
+
if (!G.current[s]) {
|
|
679
|
+
const o = te.clipAction(m, M);
|
|
680
|
+
o.name = s, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[s] = o;
|
|
691
681
|
}
|
|
692
|
-
}),
|
|
693
|
-
const
|
|
694
|
-
|
|
682
|
+
}), b.length > 0) {
|
|
683
|
+
const m = G.current.idle_0, h = V.current && te.existingAction(V.current.getClip());
|
|
684
|
+
m && !h && (m.reset().fadeIn(0.5).play(), V.current = m);
|
|
695
685
|
}
|
|
696
686
|
return () => {
|
|
697
|
-
|
|
687
|
+
te.stopAllAction(), G.current = {}, V.current = null;
|
|
698
688
|
};
|
|
699
689
|
}
|
|
700
|
-
}, [
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
if (!
|
|
704
|
-
|
|
705
|
-
|
|
690
|
+
}, [b, O, M, te]);
|
|
691
|
+
const ve = a("");
|
|
692
|
+
W(() => {
|
|
693
|
+
if (!J || !M || J === ve.current) return;
|
|
694
|
+
ve.current = J, we.current = J, new En().load(
|
|
695
|
+
J,
|
|
706
696
|
(h) => {
|
|
707
697
|
if (h.animations && h.animations.length > 0) {
|
|
708
|
-
const
|
|
709
|
-
if (
|
|
710
|
-
const
|
|
711
|
-
|
|
698
|
+
const s = h.animations[0], o = te.clipAction(s, M);
|
|
699
|
+
if (o.name = `EXPR_${J}`, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[`EXPR_${J}`] = o, F && we.current === J) {
|
|
700
|
+
const d = V.current;
|
|
701
|
+
o.reset().fadeIn(0.3).play(), d && d !== o && d.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
|
|
712
702
|
}
|
|
713
703
|
}
|
|
714
704
|
},
|
|
715
705
|
void 0,
|
|
716
706
|
(h) => {
|
|
717
|
-
console.error(`[ANIMATION] Failed to load ${
|
|
707
|
+
console.error(`[ANIMATION] Failed to load ${J}`, h);
|
|
718
708
|
}
|
|
719
709
|
);
|
|
720
|
-
}, [
|
|
721
|
-
const
|
|
722
|
-
const
|
|
723
|
-
if (
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
} else if (
|
|
727
|
-
if (
|
|
728
|
-
const
|
|
729
|
-
Math.random() *
|
|
730
|
-
),
|
|
731
|
-
|
|
710
|
+
}, [J, M, te, F]), W(() => {
|
|
711
|
+
const m = (h) => {
|
|
712
|
+
const s = h.action, o = s.name || "";
|
|
713
|
+
if (o.startsWith("idle_")) {
|
|
714
|
+
const D = (parseInt(o.split("_")[1]) + 1) % b.length, ne = G.current[`idle_${D}`];
|
|
715
|
+
ne && (ne.reset().fadeIn(0.5).play(), s.crossFadeTo(ne, 0.5, !0), V.current = ne);
|
|
716
|
+
} else if (o.startsWith("EXPR_")) {
|
|
717
|
+
if (F) {
|
|
718
|
+
const d = Math.floor(
|
|
719
|
+
Math.random() * O.length
|
|
720
|
+
), D = G.current[`talk_${d}`];
|
|
721
|
+
D && (D.reset().fadeIn(0.5).play(), s.crossFadeTo(D, 0.5, !0), V.current = D);
|
|
732
722
|
} else {
|
|
733
|
-
const
|
|
734
|
-
|
|
723
|
+
const d = G.current.idle_0;
|
|
724
|
+
d && (d.reset().fadeIn(0.5).play(), s.crossFadeTo(d, 0.5, !0), V.current = d);
|
|
735
725
|
}
|
|
736
|
-
|
|
737
|
-
} else if (
|
|
738
|
-
if (
|
|
739
|
-
const
|
|
740
|
-
|
|
726
|
+
Ae && Ae();
|
|
727
|
+
} else if (o.startsWith("talk_"))
|
|
728
|
+
if (F && !q) {
|
|
729
|
+
const D = (parseInt(o.split("_")[1]) + 1) % O.length, ne = G.current[`talk_${D}`];
|
|
730
|
+
ne && (ne.reset().fadeIn(0.3).play(), s.crossFadeTo(ne, 0.3, !0), V.current = ne);
|
|
741
731
|
} else {
|
|
742
|
-
const
|
|
743
|
-
|
|
732
|
+
const d = G.current.idle_0;
|
|
733
|
+
d && (d.reset().fadeIn(0.5).play(), s.crossFadeTo(d, 0.5, !0), V.current = d);
|
|
744
734
|
}
|
|
745
735
|
};
|
|
746
|
-
return
|
|
736
|
+
return te.addEventListener("finished", m), () => te.removeEventListener("finished", m);
|
|
747
737
|
}, [
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
]),
|
|
755
|
-
if (
|
|
756
|
-
const
|
|
738
|
+
te,
|
|
739
|
+
b,
|
|
740
|
+
O,
|
|
741
|
+
F,
|
|
742
|
+
q,
|
|
743
|
+
Ae
|
|
744
|
+
]), W(() => {
|
|
745
|
+
if (F && M) {
|
|
746
|
+
const m = V.current, h = m?.name || "";
|
|
757
747
|
if (h.startsWith("idle_") || h.startsWith("talk_") || h === "") {
|
|
758
|
-
const
|
|
759
|
-
if (
|
|
760
|
-
const
|
|
761
|
-
if (
|
|
762
|
-
|
|
748
|
+
const s = we.current;
|
|
749
|
+
if (s) {
|
|
750
|
+
const o = G.current[`EXPR_${s}`];
|
|
751
|
+
if (o) {
|
|
752
|
+
o.reset().fadeIn(0.3).play(), m && m !== o && m.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
|
|
763
753
|
return;
|
|
764
754
|
}
|
|
765
755
|
}
|
|
766
756
|
if (h.startsWith("idle_") || h === "") {
|
|
767
|
-
const
|
|
768
|
-
Math.random() *
|
|
769
|
-
),
|
|
770
|
-
|
|
757
|
+
const o = Math.floor(
|
|
758
|
+
Math.random() * O.length
|
|
759
|
+
), d = G.current[`talk_${o}`];
|
|
760
|
+
d && (d.reset().fadeIn(0.5).play(), m && m.crossFadeTo(d, 0.5, !0), V.current = d);
|
|
771
761
|
}
|
|
772
762
|
}
|
|
773
|
-
} else if (!
|
|
774
|
-
const
|
|
763
|
+
} else if (!F && M) {
|
|
764
|
+
const m = V.current, h = m?.name || "";
|
|
775
765
|
if (h.startsWith("talk_") || h.startsWith("EXPR_")) {
|
|
776
|
-
const
|
|
777
|
-
|
|
766
|
+
const s = G.current.idle_0;
|
|
767
|
+
s && (s.reset().fadeIn(0.5).play(), m && m.crossFadeTo(s, 0.5, !0), V.current = s);
|
|
778
768
|
}
|
|
779
769
|
}
|
|
780
|
-
}, [
|
|
781
|
-
if (!
|
|
782
|
-
|
|
783
|
-
if (
|
|
784
|
-
const
|
|
785
|
-
(
|
|
770
|
+
}, [F, M, J]), W(() => {
|
|
771
|
+
if (!M) return;
|
|
772
|
+
M.traverse((s) => {
|
|
773
|
+
if (s.isMesh && s.morphTargetDictionary) {
|
|
774
|
+
const o = s.name.toLowerCase();
|
|
775
|
+
(o.includes("head") || o.includes("avatar")) && (T.current = s, U(`[ANIMATION] Found head mesh: ${s.name}`)), o.includes("teeth") && (I.current = s, U(`[ANIMATION] Found teeth mesh: ${s.name}`)), o.includes("beard") && (N.current = s, U(`[ANIMATION] Found beard mesh: ${s.name}`)), o.includes("eyeleft") && (Y.current = s, U(`[ANIMATION] Found eye left mesh: ${s.name}`)), o.includes("eyeright") && (Q.current = s, U(`[ANIMATION] Found eye right mesh: ${s.name}`));
|
|
786
776
|
}
|
|
787
777
|
});
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
(
|
|
778
|
+
const m = T.current?.morphTargetDictionary;
|
|
779
|
+
m && Object.keys(m).filter(
|
|
780
|
+
(s) => s.toLowerCase().includes("brow")
|
|
791
781
|
);
|
|
792
782
|
const h = [];
|
|
793
|
-
|
|
794
|
-
if (
|
|
795
|
-
const
|
|
796
|
-
|
|
783
|
+
M.traverse((s) => {
|
|
784
|
+
if (s.isMesh) {
|
|
785
|
+
const d = s.morphTargetDictionary;
|
|
786
|
+
d && Object.keys(d).some((D) => D.toLowerCase().includes("brow")) && h.push(s);
|
|
797
787
|
}
|
|
798
|
-
}),
|
|
799
|
-
}, [
|
|
800
|
-
const
|
|
801
|
-
const
|
|
802
|
-
if (
|
|
803
|
-
for (const
|
|
804
|
-
const
|
|
805
|
-
c(
|
|
788
|
+
}), yt.current = h, h.length > 0 && U("[ANIMATION] Meshes with brow morphs:", h.length);
|
|
789
|
+
}, [M]);
|
|
790
|
+
const ot = (m, h = 1) => {
|
|
791
|
+
const s = `viseme_${m}`.toLowerCase(), o = Jn.find((d) => d.key.toLowerCase() === s);
|
|
792
|
+
if (o) {
|
|
793
|
+
for (const d in o.mix) {
|
|
794
|
+
const D = o.mix[d] * h;
|
|
795
|
+
c(T.current, d, D), c(N.current, d, D), (!o.teethMix || !(d in o.teethMix)) && c(I.current, d, D);
|
|
806
796
|
}
|
|
807
|
-
if (
|
|
808
|
-
for (const
|
|
809
|
-
const
|
|
810
|
-
c(
|
|
797
|
+
if (o.teethMix)
|
|
798
|
+
for (const d in o.teethMix) {
|
|
799
|
+
const D = o.teethMix[d] * h;
|
|
800
|
+
c(I.current, d, D);
|
|
811
801
|
}
|
|
812
802
|
}
|
|
813
|
-
},
|
|
814
|
-
const h =
|
|
815
|
-
for (const
|
|
816
|
-
c(
|
|
803
|
+
}, it = (m) => {
|
|
804
|
+
const h = wt[m] ?? wt.neutral;
|
|
805
|
+
for (const s in h)
|
|
806
|
+
c(T.current, s, h[s]), c(I.current, s, h[s]), c(N.current, s, h[s]);
|
|
817
807
|
};
|
|
818
|
-
return
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
const
|
|
822
|
-
let
|
|
823
|
-
if (Math.floor(
|
|
824
|
-
let
|
|
825
|
-
|
|
826
|
-
|
|
808
|
+
return vn((m, h) => {
|
|
809
|
+
const s = Math.pow(0.88, 60 * h);
|
|
810
|
+
Ot(T.current, s), Ot(I.current, s), Ot(N.current, s), it(ee);
|
|
811
|
+
const o = m.clock.elapsedTime;
|
|
812
|
+
let d = 0;
|
|
813
|
+
if (Math.floor(o) % 5 === 0 && Math.floor((o - h) % 5) !== 0) {
|
|
814
|
+
let _ = null;
|
|
815
|
+
M.traverse((P) => {
|
|
816
|
+
P.name.toLowerCase().includes("hips") && (_ = P);
|
|
827
817
|
});
|
|
828
|
-
const
|
|
829
|
-
|
|
818
|
+
const K = _ ? `Hips Y: ${_.position.y.toFixed(4)}` : "Hips not found";
|
|
819
|
+
U(`[ANIMATION] Mixer Time: ${te.time.toFixed(2)}, ${K}`);
|
|
830
820
|
}
|
|
831
|
-
if (
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
if (
|
|
835
|
-
const
|
|
836
|
-
|
|
821
|
+
if (te.update(h), o > Ee.current && !Xe.current && (Xe.current = !0, Ve.current = o), Xe.current) {
|
|
822
|
+
const _ = F ? 0.2 : 0.3, K = (o - Ve.current) / _;
|
|
823
|
+
if (K >= 1)
|
|
824
|
+
if (Xe.current = !1, Me.current) {
|
|
825
|
+
const P = F ? 1 : 2.5;
|
|
826
|
+
Ee.current = o + P, Me.current = !1;
|
|
837
827
|
} else
|
|
838
|
-
|
|
828
|
+
Ee.current = o + 0.12, Me.current = !0;
|
|
839
829
|
else {
|
|
840
|
-
const
|
|
841
|
-
c(
|
|
830
|
+
const P = K < 0.5 ? K * 2 : (1 - K) * 2;
|
|
831
|
+
c(T.current, "eyeBlinkLeft", P), c(T.current, "eyeBlinkRight", P), c(I.current, "eyeBlinkLeft", P), c(I.current, "eyeBlinkRight", P), c(N.current, "eyeBlinkLeft", P), c(N.current, "eyeBlinkRight", P), d = P * Vn.browInnerUp;
|
|
842
832
|
}
|
|
843
833
|
}
|
|
844
|
-
const
|
|
845
|
-
c(
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
const
|
|
849
|
-
(
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
|
|
853
|
-
const
|
|
854
|
-
|
|
834
|
+
const D = wt[ee] ?? wt.neutral, ne = D.browInnerUp ?? 0, St = D.browOuterUpLeft ?? 0, He = D.browOuterUpRight ?? 0, re = o * $n, ut = It * Math.sin(re), Ce = It * 0.7 * Math.sin(re + 0.7), je = It * 0.7 * Math.sin(re + 1.3), L = (_) => Math.max(0, Math.min(1, _)), lt = L(ne + ut), Je = L(St + Ce), Ge = L(He + je), ht = L(lt + d);
|
|
835
|
+
c(T.current, "browInnerUp", ht), c(I.current, "browInnerUp", ht), c(N.current, "browInnerUp", ht), c(T.current, "browOuterUpLeft", Je), c(I.current, "browOuterUpLeft", Je), c(N.current, "browOuterUpLeft", Je), c(T.current, "browOuterUpRight", Ge), c(I.current, "browOuterUpRight", Ge), c(N.current, "browOuterUpRight", Ge);
|
|
836
|
+
const qe = Ie.current, Ue = qe + bt, fe = Ue + Dt;
|
|
837
|
+
o > fe && (Ie.current += bt + Dt + Kt);
|
|
838
|
+
const ye = !F && o >= qe && o < Ue, Fe = !F && o >= Ue && o < fe;
|
|
839
|
+
(ye || Fe) && ct.current !== qe && (ct.current = qe, De.current = Math.random() < 0.7 ? "left" : "up");
|
|
840
|
+
const dt = ye ? o - qe : Fe ? bt : 0, oe = ye || Fe ? Math.min(1, dt / bt) : 0, ze = oe <= 0 ? 0 : Math.sin(oe * Math.PI), ft = Fe ? 1 - (o - Ue) / Dt : 1, Lt = ye ? ze : Fe ? ze * ft : 0, Ne = Hn * Lt, k = (_) => D[_] ?? 0;
|
|
841
|
+
if (De.current === "up" ? (c(Y.current, "eyeLookUpLeft", L(k("eyeLookUpLeft") + Ne)), c(Y.current, "eyeLookDownLeft", L(k("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", L(k("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", L(k("eyeLookInLeft"))), c(Q.current, "eyeLookUpRight", L(k("eyeLookUpRight") + Ne)), c(Q.current, "eyeLookDownRight", L(k("eyeLookDownRight"))), c(Q.current, "eyeLookOutRight", L(k("eyeLookOutRight"))), c(Q.current, "eyeLookInRight", L(k("eyeLookInRight")))) : (c(Y.current, "eyeLookUpLeft", L(k("eyeLookUpLeft"))), c(Y.current, "eyeLookDownLeft", L(k("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", L(k("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", L(k("eyeLookInLeft") + Ne)), c(Q.current, "eyeLookUpRight", L(k("eyeLookUpRight"))), c(Q.current, "eyeLookDownRight", L(k("eyeLookDownRight"))), c(Q.current, "eyeLookOutRight", L(k("eyeLookOutRight") + Ne)), c(Q.current, "eyeLookInRight", L(k("eyeLookInRight")))), !F && o >= $e.current) {
|
|
842
|
+
de.current = o, Oe.current = Math.random() < 0.5 ? "pucker" : "smile";
|
|
843
|
+
const _ = Oe.current === "pucker" ? Xt : Qt;
|
|
844
|
+
$e.current = o + _ + _t + Math.random() * (Zt - _t);
|
|
855
845
|
}
|
|
856
|
-
const
|
|
857
|
-
const
|
|
858
|
-
return 1 -
|
|
859
|
-
})(),
|
|
860
|
-
if (
|
|
861
|
-
if (
|
|
862
|
-
const
|
|
863
|
-
c(
|
|
846
|
+
const ce = Oe.current === "pucker" ? Xt : Qt, ue = !F && o >= de.current && o < de.current + ce, Ye = ue ? (o - de.current) / ce : 0, ke = Ye <= 0 ? 0 : Ye < 0.5 ? Ye * 2 : (() => {
|
|
847
|
+
const _ = (Ye - 0.5) * 2;
|
|
848
|
+
return 1 - _ * _ * (3 - 2 * _);
|
|
849
|
+
})(), me = (_) => D[_] ?? 0;
|
|
850
|
+
if (ue)
|
|
851
|
+
if (Oe.current === "pucker") {
|
|
852
|
+
const _ = L(me("mouthPucker") + jn * ke);
|
|
853
|
+
c(T.current, "mouthPucker", _), c(I.current, "mouthPucker", _), c(N.current, "mouthPucker", _);
|
|
864
854
|
} else {
|
|
865
|
-
const
|
|
866
|
-
c(
|
|
855
|
+
const _ = L(me("mouthSmileLeft") + en * ke), K = L(me("mouthSmileRight") + en * ke), P = L(me("mouthDimpleLeft") + tn * ke), Re = L(me("mouthDimpleRight") + tn * ke);
|
|
856
|
+
c(T.current, "mouthSmileLeft", _), c(T.current, "mouthSmileRight", K), c(T.current, "mouthDimpleLeft", P), c(T.current, "mouthDimpleRight", Re), c(I.current, "mouthSmileLeft", _), c(I.current, "mouthSmileRight", K), c(I.current, "mouthDimpleLeft", P), c(I.current, "mouthDimpleRight", Re), c(N.current, "mouthSmileLeft", _), c(N.current, "mouthSmileRight", K), c(N.current, "mouthDimpleLeft", P), c(N.current, "mouthDimpleRight", Re);
|
|
867
857
|
}
|
|
868
|
-
if (
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
858
|
+
if (z.current) {
|
|
859
|
+
const _ = E.current ? 0 : Z.rotation[1];
|
|
860
|
+
z.current.rotation.y = at.MathUtils.lerp(
|
|
861
|
+
z.current.rotation.y,
|
|
862
|
+
_,
|
|
873
863
|
0.1
|
|
874
|
-
),
|
|
864
|
+
), z.current.position.set(...Z.position), z.current.scale.setScalar(Z.scale), z.current.rotation.x = Z.rotation[0], z.current.rotation.z = Z.rotation[2];
|
|
875
865
|
}
|
|
876
|
-
if (
|
|
877
|
-
const
|
|
878
|
-
for (let
|
|
879
|
-
const
|
|
880
|
-
|
|
866
|
+
if (E.current && y.current) {
|
|
867
|
+
const _ = y.current.currentTime, Re = (_ - j.current) * 1e3 - -150;
|
|
868
|
+
for (let le = 0; le < w.current.length; le++) {
|
|
869
|
+
const he = w.current[le];
|
|
870
|
+
Re >= he.vtime && Re < he.vtime + he.vduration && ot(he.viseme, he.weight ?? 1);
|
|
881
871
|
}
|
|
882
|
-
|
|
872
|
+
_ > rt.current + 0.5 && (Te(), We(!1));
|
|
883
873
|
}
|
|
884
|
-
}), /* @__PURE__ */
|
|
874
|
+
}), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: M }) });
|
|
885
875
|
}
|
|
886
876
|
);
|
|
887
|
-
function
|
|
888
|
-
return
|
|
877
|
+
function Kn(p) {
|
|
878
|
+
return p ? p.charAt(0).toUpperCase() + p.slice(1).toLowerCase() : "";
|
|
889
879
|
}
|
|
890
|
-
function
|
|
891
|
-
return
|
|
880
|
+
function rn(p) {
|
|
881
|
+
return p.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
|
|
892
882
|
}
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
883
|
+
const Qn = ({
|
|
884
|
+
onNavigationRequested: p,
|
|
885
|
+
agentId: E,
|
|
886
|
+
presetUserDetails: w,
|
|
887
|
+
onAvatarReady: y
|
|
888
|
+
}) => {
|
|
889
|
+
const [j, Z] = S(""), [ee, nt] = S("male"), [Be, F] = S(""), [rt, Te] = S(!1), We = j, J = ee;
|
|
890
|
+
W(() => {
|
|
891
|
+
if (!E) {
|
|
892
|
+
Te(!0);
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
let e = !1;
|
|
896
|
+
return (async () => {
|
|
897
|
+
try {
|
|
898
|
+
const r = { agentId: E }, i = await fetch(`${tt}/visitedWebsite`, {
|
|
899
|
+
method: "POST",
|
|
900
|
+
headers: { "Content-Type": "application/json" },
|
|
901
|
+
body: JSON.stringify(r)
|
|
902
|
+
});
|
|
903
|
+
if (i.ok) {
|
|
904
|
+
const t = await i.json();
|
|
905
|
+
if (e) return;
|
|
906
|
+
t.encryptedAgentToken && Z(t.encryptedAgentToken), t.avatarGender && nt(t.avatarGender), t.agent_id && F(t.agent_id);
|
|
907
|
+
}
|
|
908
|
+
} catch (r) {
|
|
909
|
+
console.error("Failed to fetch avatar config:", r);
|
|
910
|
+
} finally {
|
|
911
|
+
e || Te(!0);
|
|
912
|
+
}
|
|
913
|
+
})(), () => {
|
|
914
|
+
e = !0;
|
|
915
|
+
};
|
|
916
|
+
}, [E]);
|
|
917
|
+
const Ae = Dn(E ?? Be), [q, se] = S(""), [M, _e] = S(""), [H, b] = S("Ready"), [ae, f] = S(!1), [O, z] = S(!1), [T, I] = S([]), [N, Y] = S(""), Q = a(null), [yt, te] = S(
|
|
902
918
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
903
919
|
);
|
|
904
|
-
|
|
905
|
-
const e = window.matchMedia("(max-width: 480px)"),
|
|
906
|
-
return e.addEventListener("change",
|
|
920
|
+
W(() => {
|
|
921
|
+
const e = window.matchMedia("(max-width: 480px)"), n = () => te(e.matches);
|
|
922
|
+
return e.addEventListener("change", n), () => e.removeEventListener("change", n);
|
|
907
923
|
}, []);
|
|
908
|
-
const
|
|
924
|
+
const G = yt ? 80 : 600, V = a(!1), Ee = a([]), Xe = a(0), Ve = a(!1), Me = a([]), we = a(null), Ie = a([]);
|
|
909
925
|
a([]);
|
|
910
|
-
const
|
|
926
|
+
const ct = a([]), De = a(0), $e = a(0), de = a(0), Oe = a(0), ve = a(!1), [ot, it] = S(
|
|
911
927
|
null
|
|
912
|
-
),
|
|
928
|
+
), m = a(null), [h, s] = S("neutral"), [o, d] = S(""), [D, ne] = S(""), [St, He] = S("Chat with us"), [re, ut] = S(
|
|
913
929
|
null
|
|
914
|
-
), [
|
|
915
|
-
|
|
916
|
-
const [
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
if (
|
|
921
|
-
|
|
930
|
+
), [Ce, je] = S("hidden"), [L, lt] = S(""), Je = a(null), Ge = a(Ce);
|
|
931
|
+
Ge.current = Ce;
|
|
932
|
+
const [ht, qe] = S(null), Ue = a(null), fe = a(null), [ye, Fe] = S(!1), dt = a(null), [oe, ze] = S("hidden"), [ft, Lt] = S(""), Ne = a(oe);
|
|
933
|
+
Ne.current = oe;
|
|
934
|
+
const k = a(""), ce = a(!1), ue = a(""), Ye = a(Date.now()), ke = a([]), me = a(!1), [_, K] = S(!1), [P, Re] = S(!1), le = a(null), he = Ct(() => ye ? "Try again" : H === "Busy" ? "Busy" : H === "Thinking..." || H === "Processing Voice..." ? H : re != null && re !== "" && re !== "none" && re !== "<none>" ? `Enter ${Kn(re)}` : oe !== "hidden" || !P ? null : nn, [H, re, ye, oe, P]), Ut = !ye && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (re == null || re === "" || re === "none" || re === "<none>");
|
|
935
|
+
W(() => {
|
|
936
|
+
if (oe !== "hidden" || !Ut) {
|
|
937
|
+
Re(!1), le.current != null && (clearTimeout(le.current), le.current = null);
|
|
922
938
|
return;
|
|
923
939
|
}
|
|
924
|
-
return
|
|
925
|
-
|
|
940
|
+
return le.current = setTimeout(() => {
|
|
941
|
+
le.current = null, Re(!0);
|
|
926
942
|
}, 400), () => {
|
|
927
|
-
|
|
943
|
+
le.current != null && (clearTimeout(le.current), le.current = null);
|
|
928
944
|
};
|
|
929
|
-
}, [
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
const e =
|
|
945
|
+
}, [oe, Ut]);
|
|
946
|
+
const mt = he != null && he !== "";
|
|
947
|
+
W(() => {
|
|
948
|
+
const e = Ge.current;
|
|
933
949
|
if (!(e === "exiting" || e === "entering")) {
|
|
934
950
|
if (e === "hidden") {
|
|
935
|
-
|
|
951
|
+
mt && (lt(he ?? ""), je("entering"));
|
|
936
952
|
return;
|
|
937
953
|
}
|
|
938
|
-
e === "visible" && (!
|
|
954
|
+
e === "visible" && (!mt || he !== L) && (Je.current = mt ? he : null, je("exiting"));
|
|
939
955
|
}
|
|
940
956
|
}, [
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
]),
|
|
946
|
-
if (
|
|
947
|
-
|
|
957
|
+
mt,
|
|
958
|
+
he,
|
|
959
|
+
Ce,
|
|
960
|
+
L
|
|
961
|
+
]), W(() => {
|
|
962
|
+
if (H !== "Busy") {
|
|
963
|
+
fe.current != null && (clearTimeout(fe.current), fe.current = null);
|
|
948
964
|
return;
|
|
949
965
|
}
|
|
950
|
-
return
|
|
951
|
-
|
|
966
|
+
return fe.current = setTimeout(() => {
|
|
967
|
+
fe.current = null, b("Ready"), Fe(!0);
|
|
952
968
|
}, 12e3), () => {
|
|
953
|
-
|
|
969
|
+
fe.current != null && (clearTimeout(fe.current), fe.current = null);
|
|
954
970
|
};
|
|
955
|
-
}, [
|
|
956
|
-
if (!
|
|
957
|
-
const e = setTimeout(() =>
|
|
971
|
+
}, [H]), W(() => {
|
|
972
|
+
if (!ye) return;
|
|
973
|
+
const e = setTimeout(() => Fe(!1), 2500);
|
|
958
974
|
return () => clearTimeout(e);
|
|
959
|
-
}, [
|
|
960
|
-
const
|
|
961
|
-
const e =
|
|
975
|
+
}, [ye]);
|
|
976
|
+
const on = et(() => {
|
|
977
|
+
const e = Ge.current;
|
|
962
978
|
if (e === "exiting") {
|
|
963
|
-
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
} else e === "entering" &&
|
|
967
|
-
}, []),
|
|
979
|
+
je("hidden");
|
|
980
|
+
const n = Je.current;
|
|
981
|
+
Je.current = null, n != null && n !== "" && (lt(n), je("entering"));
|
|
982
|
+
} else e === "entering" && je("visible");
|
|
983
|
+
}, []), sn = (e) => {
|
|
968
984
|
if (!e) return;
|
|
969
985
|
if (e.mood != null) {
|
|
970
|
-
const
|
|
971
|
-
|
|
986
|
+
const t = String(e.mood).toLowerCase();
|
|
987
|
+
s(t);
|
|
972
988
|
}
|
|
973
989
|
if (e.expression != null) {
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
const u =
|
|
977
|
-
(
|
|
990
|
+
const t = String(e.expression).trim();
|
|
991
|
+
d(t);
|
|
992
|
+
const u = Un.find(
|
|
993
|
+
(g) => g.name.toLowerCase() === t.toLowerCase()
|
|
978
994
|
);
|
|
979
|
-
|
|
980
|
-
`[STREAM] Animation match for "${
|
|
981
|
-
),
|
|
995
|
+
U(
|
|
996
|
+
`[STREAM] Animation match for "${t}": ${u ? u.name : "NONE"}`
|
|
997
|
+
), ne(u?.url ?? "");
|
|
982
998
|
}
|
|
983
999
|
if (e.navigation != null) {
|
|
984
|
-
const
|
|
985
|
-
|
|
1000
|
+
const t = String(e.navigation).trim();
|
|
1001
|
+
t !== "" && (p ? p(t) : window.open(t, "_blank"));
|
|
986
1002
|
}
|
|
987
|
-
const
|
|
988
|
-
if (
|
|
989
|
-
const
|
|
990
|
-
if (
|
|
1003
|
+
const n = e.ask_for || e.lead_capture?.ask_for, r = n ? String(n).trim().toLowerCase() : "", i = r === "none" || r === "<none>";
|
|
1004
|
+
if (n && !i) {
|
|
1005
|
+
const t = r;
|
|
1006
|
+
if (w && (t === "email" && w.email || t === "name" && w.name || t === "phone" && w.phone))
|
|
991
1007
|
return;
|
|
992
|
-
|
|
993
|
-
} else (
|
|
1008
|
+
ut(t || null), He(t === "email" ? "Enter your email" : t === "name" ? "Enter your name" : t === "phone" ? "Enter your phone number" : "Chat with us");
|
|
1009
|
+
} else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (ut(null), St !== "Chat with us" && He("Chat with us"));
|
|
994
1010
|
e.collected, e.valid;
|
|
995
|
-
},
|
|
996
|
-
const
|
|
997
|
-
if (!
|
|
998
|
-
if (
|
|
1011
|
+
}, an = (e) => {
|
|
1012
|
+
const n = e.trim();
|
|
1013
|
+
if (!n) return null;
|
|
1014
|
+
if (n.startsWith("{"))
|
|
999
1015
|
try {
|
|
1000
|
-
return JSON.parse(
|
|
1016
|
+
return JSON.parse(n);
|
|
1001
1017
|
} catch {
|
|
1002
1018
|
return null;
|
|
1003
1019
|
}
|
|
1004
|
-
if (
|
|
1005
|
-
const r =
|
|
1006
|
-
return { [
|
|
1020
|
+
if (n.includes(":")) {
|
|
1021
|
+
const r = n.split(":"), i = r[0].trim().toLowerCase(), t = r.slice(1).join(":").trim();
|
|
1022
|
+
return { [i]: t };
|
|
1007
1023
|
}
|
|
1008
1024
|
return null;
|
|
1009
|
-
},
|
|
1010
|
-
}, []),
|
|
1011
|
-
for (;
|
|
1025
|
+
}, cn = et(() => {
|
|
1026
|
+
}, []), Pe = "§", vt = () => {
|
|
1027
|
+
for (; k.current.includes(`
|
|
1012
1028
|
`); ) {
|
|
1013
|
-
const e =
|
|
1014
|
-
`),
|
|
1015
|
-
|
|
1016
|
-
const r =
|
|
1017
|
-
r &&
|
|
1029
|
+
const e = k.current.indexOf(`
|
|
1030
|
+
`), n = k.current.slice(0, e).trim();
|
|
1031
|
+
k.current = k.current.slice(e + 1);
|
|
1032
|
+
const r = an(n);
|
|
1033
|
+
r && sn(r);
|
|
1018
1034
|
}
|
|
1019
|
-
},
|
|
1020
|
-
if (
|
|
1021
|
-
if (e.includes(
|
|
1022
|
-
const
|
|
1023
|
-
r && (
|
|
1024
|
-
} else e ===
|
|
1025
|
-
else if (e.includes(
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
} else if (e ===
|
|
1029
|
-
|
|
1035
|
+
}, Ft = (e) => {
|
|
1036
|
+
if (ce.current)
|
|
1037
|
+
if (e.includes(Pe)) {
|
|
1038
|
+
const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
|
|
1039
|
+
r && (ue.current += r, _e((t) => t + r)), ce.current = !1, i && (k.current += i, vt());
|
|
1040
|
+
} else e === Pe ? ce.current = !1 : (ue.current += e, _e((n) => n + e));
|
|
1041
|
+
else if (e.includes(Pe)) {
|
|
1042
|
+
const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
|
|
1043
|
+
k.current += r, vt(), ce.current = !0, i && (ue.current += i, _e((t) => t + i));
|
|
1044
|
+
} else if (e === Pe) {
|
|
1045
|
+
ce.current = !0;
|
|
1030
1046
|
return;
|
|
1031
1047
|
} else
|
|
1032
|
-
|
|
1048
|
+
k.current += e, vt();
|
|
1033
1049
|
};
|
|
1034
|
-
|
|
1050
|
+
W(() => {
|
|
1035
1051
|
(async () => {
|
|
1036
1052
|
if (!sessionStorage.getItem(
|
|
1037
1053
|
"STREAMOJI_LEADS_SESSION_LEAD_ID"
|
|
1038
1054
|
)) {
|
|
1039
|
-
const
|
|
1055
|
+
const t = "secret", u = Math.floor(Date.now() / 1e3).toString();
|
|
1040
1056
|
try {
|
|
1041
|
-
const
|
|
1057
|
+
const g = new TextEncoder(), v = await crypto.subtle.importKey(
|
|
1042
1058
|
"raw",
|
|
1043
|
-
|
|
1059
|
+
g.encode(t),
|
|
1044
1060
|
{ name: "HMAC", hash: "SHA-256" },
|
|
1045
1061
|
!1,
|
|
1046
1062
|
["sign"]
|
|
1047
|
-
),
|
|
1063
|
+
), x = await crypto.subtle.sign(
|
|
1048
1064
|
"HMAC",
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
),
|
|
1052
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",
|
|
1053
|
-
} catch (
|
|
1054
|
-
console.error("[SESSION] HMAC generation failed:",
|
|
1055
|
-
const
|
|
1056
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",
|
|
1065
|
+
v,
|
|
1066
|
+
g.encode(u)
|
|
1067
|
+
), R = Array.from(new Uint8Array(x)).map((C) => C.toString(16).padStart(2, "0")).join("");
|
|
1068
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", R), U("[SESSION] New HMAC UID generated and saved:", R);
|
|
1069
|
+
} catch (g) {
|
|
1070
|
+
console.error("[SESSION] HMAC generation failed:", g);
|
|
1071
|
+
const v = Math.random().toString(36) + Date.now().toString();
|
|
1072
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", v);
|
|
1057
1073
|
}
|
|
1058
1074
|
}
|
|
1059
1075
|
const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
|
|
1060
|
-
let
|
|
1076
|
+
let i = [];
|
|
1061
1077
|
if (r)
|
|
1062
1078
|
try {
|
|
1063
|
-
|
|
1079
|
+
i = JSON.parse(r);
|
|
1064
1080
|
} catch {
|
|
1065
|
-
|
|
1081
|
+
i = [];
|
|
1066
1082
|
}
|
|
1067
|
-
|
|
1083
|
+
i.length === 0 && w && (w.name || w.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${w.name || ""}" , Email is "${w.email || ""}"` }], sessionStorage.setItem(
|
|
1068
1084
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1069
|
-
JSON.stringify(
|
|
1085
|
+
JSON.stringify(i)
|
|
1070
1086
|
)) : r || sessionStorage.setItem(
|
|
1071
1087
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1072
1088
|
JSON.stringify([])
|
|
1073
1089
|
);
|
|
1074
1090
|
})();
|
|
1075
|
-
}, [
|
|
1091
|
+
}, [w]), W(() => {
|
|
1076
1092
|
const e = () => {
|
|
1077
|
-
|
|
1093
|
+
Ye.current = Date.now(), me.current && (me.current = !1, K(!1), I([]), Y(""), _e(""), z(!1));
|
|
1078
1094
|
};
|
|
1079
1095
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
1080
|
-
const
|
|
1081
|
-
if (Date.now() -
|
|
1082
|
-
if (
|
|
1083
|
-
|
|
1096
|
+
const n = setInterval(async () => {
|
|
1097
|
+
if (Date.now() - Ye.current >= 3e4 && !O && !ae && H === "Ready" && !me.current)
|
|
1098
|
+
if (me.current = !0, ke.current.length > 0)
|
|
1099
|
+
K(!0), I(ke.current);
|
|
1084
1100
|
else
|
|
1085
1101
|
try {
|
|
1086
|
-
const
|
|
1102
|
+
const t = `${tt}/nudgeUser`, u = {
|
|
1087
1103
|
navigationUrl: window.location.href,
|
|
1088
|
-
token:
|
|
1089
|
-
},
|
|
1104
|
+
token: We
|
|
1105
|
+
}, g = await fetch(t, {
|
|
1090
1106
|
method: "POST",
|
|
1091
1107
|
headers: {
|
|
1092
1108
|
"Content-Type": "application/json"
|
|
1093
1109
|
},
|
|
1094
1110
|
body: JSON.stringify(u)
|
|
1095
1111
|
});
|
|
1096
|
-
if (
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1112
|
+
if (g.ok) {
|
|
1113
|
+
const x = (await g.json()).nudge_questions;
|
|
1114
|
+
x && x.length > 0 && (U("[NUDGE] Received nudge questions from API:", x), ke.current = x, K(!0), I(x));
|
|
1099
1115
|
}
|
|
1100
|
-
} catch (
|
|
1101
|
-
console.error("[NUDGE] Error calling /nudgeUser:",
|
|
1116
|
+
} catch (t) {
|
|
1117
|
+
console.error("[NUDGE] Error calling /nudgeUser:", t), me.current = !1;
|
|
1102
1118
|
}
|
|
1103
1119
|
}, 1e3);
|
|
1104
1120
|
return () => {
|
|
1105
|
-
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(
|
|
1121
|
+
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(n);
|
|
1106
1122
|
};
|
|
1107
|
-
}, [
|
|
1108
|
-
if (
|
|
1109
|
-
let e = 0,
|
|
1110
|
-
const
|
|
1111
|
-
const u =
|
|
1123
|
+
}, [We, O, ae, H]), W(() => {
|
|
1124
|
+
if (T.length === 0) return;
|
|
1125
|
+
let e = 0, n = 0, r = !1, i = 100;
|
|
1126
|
+
const t = () => {
|
|
1127
|
+
const u = T[e];
|
|
1112
1128
|
if (r) {
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1129
|
+
const g = u.substring(0, n - 1);
|
|
1130
|
+
Y(g), n--, i = 50;
|
|
1115
1131
|
} else {
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1132
|
+
const g = u.substring(0, n + 1);
|
|
1133
|
+
Y(g), n++, i = 100;
|
|
1118
1134
|
}
|
|
1119
|
-
!r &&
|
|
1135
|
+
!r && n === u.length ? (r = !0, i = 3e3) : r && n === 0 && (r = !1, e = (e + 1) % T.length, i = 500), Q.current = setTimeout(t, i);
|
|
1120
1136
|
};
|
|
1121
|
-
return
|
|
1122
|
-
|
|
1137
|
+
return t(), () => {
|
|
1138
|
+
Q.current && clearTimeout(Q.current);
|
|
1123
1139
|
};
|
|
1124
|
-
}, [
|
|
1125
|
-
const
|
|
1140
|
+
}, [T]);
|
|
1141
|
+
const Nt = () => {
|
|
1126
1142
|
try {
|
|
1127
1143
|
return JSON.parse(
|
|
1128
1144
|
sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
|
|
@@ -1130,232 +1146,233 @@ const Jn = ({
|
|
|
1130
1146
|
} catch {
|
|
1131
1147
|
return [];
|
|
1132
1148
|
}
|
|
1133
|
-
},
|
|
1149
|
+
}, un = (e) => {
|
|
1134
1150
|
sessionStorage.setItem(
|
|
1135
1151
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1136
1152
|
JSON.stringify(e)
|
|
1137
1153
|
);
|
|
1138
|
-
}, [
|
|
1154
|
+
}, [kt, Rt] = S(!1), [Pt, xt] = S(0), Se = a(null), pt = a([]), Bt = a(0), [Wt, ln] = S(
|
|
1139
1155
|
null
|
|
1140
|
-
), [
|
|
1156
|
+
), [hn, Tt] = S(
|
|
1141
1157
|
null
|
|
1142
|
-
),
|
|
1158
|
+
), xe = a(null), Ke = a(
|
|
1143
1159
|
null
|
|
1144
|
-
),
|
|
1145
|
-
e && (
|
|
1160
|
+
), st = et((e = !1) => {
|
|
1161
|
+
e && (ve.current = !0, f(!1), b("Ready")), Me.current = [], Ee.current = [], Ve.current = !1, z(!1), De.current = 0, $e.current = 0, de.current = 0, Ie.current.forEach((n) => {
|
|
1146
1162
|
try {
|
|
1147
|
-
|
|
1163
|
+
n.stop();
|
|
1148
1164
|
} catch {
|
|
1149
1165
|
}
|
|
1150
|
-
}),
|
|
1151
|
-
}, []),
|
|
1166
|
+
}), Ue.current && (clearTimeout(Ue.current), Ue.current = null), qe(null), ne(""), Ie.current = [];
|
|
1167
|
+
}, []), dn = async () => {
|
|
1152
1168
|
try {
|
|
1153
|
-
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }),
|
|
1154
|
-
|
|
1169
|
+
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), n = window.AudioContext || window.webkitAudioContext, r = new n(), i = r.createMediaStreamSource(e), t = r.createAnalyser();
|
|
1170
|
+
t.fftSize = 64, i.connect(t), xe.current = r, Ke.current = i, Tt(t);
|
|
1155
1171
|
const u = new MediaRecorder(e);
|
|
1156
|
-
|
|
1157
|
-
|
|
1172
|
+
Se.current = u, pt.current = [], u.ondataavailable = (g) => {
|
|
1173
|
+
g.data.size > 0 && pt.current.push(g.data);
|
|
1158
1174
|
}, u.onstop = async () => {
|
|
1159
|
-
const
|
|
1160
|
-
if (
|
|
1161
|
-
|
|
1175
|
+
const g = Date.now() - Bt.current;
|
|
1176
|
+
if (Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), g < 1e3) {
|
|
1177
|
+
b("Recording too short. Hold or click longer."), f(!1);
|
|
1162
1178
|
return;
|
|
1163
1179
|
}
|
|
1164
|
-
const
|
|
1180
|
+
const v = new Blob(pt.current, {
|
|
1165
1181
|
type: "audio/wav"
|
|
1166
1182
|
});
|
|
1167
|
-
await
|
|
1168
|
-
},
|
|
1183
|
+
await gn(v);
|
|
1184
|
+
}, Bt.current = Date.now(), u.start(100), Rt(!0), b("Listening...");
|
|
1169
1185
|
} catch (e) {
|
|
1170
|
-
console.error("Error accessing microphone:", e),
|
|
1186
|
+
console.error("Error accessing microphone:", e), b("Mic Access Error");
|
|
1171
1187
|
}
|
|
1172
|
-
},
|
|
1173
|
-
|
|
1174
|
-
},
|
|
1175
|
-
|
|
1188
|
+
}, fn = () => {
|
|
1189
|
+
Se.current && Se.current.state !== "inactive" && (Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Rt(!1));
|
|
1190
|
+
}, mn = () => {
|
|
1191
|
+
Se.current && Se.current.state !== "inactive" && (Se.current.onstop = null, Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), Rt(!1), pt.current = [], b("Ready"));
|
|
1176
1192
|
};
|
|
1177
|
-
|
|
1178
|
-
if (!
|
|
1193
|
+
W(() => {
|
|
1194
|
+
if (!O) return;
|
|
1179
1195
|
const e = () => {
|
|
1180
|
-
const
|
|
1181
|
-
if (
|
|
1182
|
-
const r =
|
|
1196
|
+
const n = de.current;
|
|
1197
|
+
if (n <= 0) return;
|
|
1198
|
+
const r = we.current, i = De.current;
|
|
1183
1199
|
if (!r) return;
|
|
1184
|
-
const
|
|
1185
|
-
if (
|
|
1186
|
-
const
|
|
1187
|
-
Math.round(u /
|
|
1188
|
-
|
|
1200
|
+
const t = r.currentTime - i, u = Math.min(Math.max(0, t), n), v = rn(M).trim().length;
|
|
1201
|
+
if (v <= 0) return;
|
|
1202
|
+
const x = Math.min(
|
|
1203
|
+
Math.round(u / n * v),
|
|
1204
|
+
v
|
|
1189
1205
|
);
|
|
1190
|
-
|
|
1206
|
+
it(x);
|
|
1191
1207
|
};
|
|
1192
|
-
return clearInterval(
|
|
1193
|
-
}, [
|
|
1208
|
+
return clearInterval(m.current ?? void 0), m.current = setInterval(e, 90), () => clearInterval(m.current ?? void 0);
|
|
1209
|
+
}, [O, M, de.current]), W(() => {
|
|
1194
1210
|
let e;
|
|
1195
|
-
return
|
|
1196
|
-
|
|
1197
|
-
}, 1e3)) :
|
|
1198
|
-
}, [
|
|
1199
|
-
const
|
|
1200
|
-
const
|
|
1211
|
+
return kt ? (xt(0), e = window.setInterval(() => {
|
|
1212
|
+
xt((n) => n + 1);
|
|
1213
|
+
}, 1e3)) : xt(0), () => clearInterval(e);
|
|
1214
|
+
}, [kt]);
|
|
1215
|
+
const pn = (e) => {
|
|
1216
|
+
const n = e.numberOfChannels, r = e.length * n * 2 + 44, i = new ArrayBuffer(r), t = new DataView(i);
|
|
1201
1217
|
let u = 0;
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
},
|
|
1205
|
-
|
|
1218
|
+
const g = (R) => {
|
|
1219
|
+
t.setUint16(u, R, !0), u += 2;
|
|
1220
|
+
}, v = (R) => {
|
|
1221
|
+
t.setUint32(u, R, !0), u += 4;
|
|
1206
1222
|
};
|
|
1207
|
-
|
|
1208
|
-
const
|
|
1209
|
-
for (let
|
|
1210
|
-
let
|
|
1223
|
+
v(1179011410), v(r - 8), v(1163280727), v(544501094), v(16), g(1), g(n), v(e.sampleRate), v(e.sampleRate * 2 * n), g(n * 2), g(16), v(1635017060), v(r - u - 4);
|
|
1224
|
+
const x = [];
|
|
1225
|
+
for (let R = 0; R < n; R++) x.push(e.getChannelData(R));
|
|
1226
|
+
let A = 0;
|
|
1211
1227
|
for (; u < r; ) {
|
|
1212
|
-
for (let
|
|
1213
|
-
let
|
|
1214
|
-
|
|
1228
|
+
for (let R = 0; R < n; R++) {
|
|
1229
|
+
let C = Math.max(-1, Math.min(1, x[R][A]));
|
|
1230
|
+
C = C < 0 ? C * 32768 : C * 32767, t.setInt16(u, C, !0), u += 2;
|
|
1215
1231
|
}
|
|
1216
|
-
|
|
1232
|
+
A++;
|
|
1217
1233
|
}
|
|
1218
|
-
return new Blob([
|
|
1219
|
-
},
|
|
1220
|
-
if (!
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1234
|
+
return new Blob([i], { type: "audio/wav" });
|
|
1235
|
+
}, At = async (e, n, r = !1) => {
|
|
1236
|
+
if (!ve.current) {
|
|
1237
|
+
if (V.current) {
|
|
1238
|
+
Ee.current.push({
|
|
1223
1239
|
audio: e,
|
|
1224
|
-
visemes:
|
|
1240
|
+
visemes: n,
|
|
1225
1241
|
isNewSegment: r
|
|
1226
1242
|
});
|
|
1227
1243
|
return;
|
|
1228
1244
|
}
|
|
1229
|
-
|
|
1245
|
+
V.current = !0;
|
|
1230
1246
|
try {
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
const u = window.atob(e),
|
|
1234
|
-
for (let
|
|
1235
|
-
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
const
|
|
1239
|
-
let
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
let
|
|
1245
|
-
if ((!
|
|
1246
|
-
|
|
1247
|
+
const i = window.AudioContext || window.webkitAudioContext, t = we.current ?? new i();
|
|
1248
|
+
t.state === "suspended" && await t.resume(), we.current = t;
|
|
1249
|
+
const u = window.atob(e), g = new Uint8Array(u.length);
|
|
1250
|
+
for (let $ = 0; $ < u.length; $++)
|
|
1251
|
+
g[$] = u.charCodeAt($);
|
|
1252
|
+
const v = await t.decodeAudioData(g.buffer.slice(0));
|
|
1253
|
+
de.current += v.duration;
|
|
1254
|
+
const x = t.currentTime;
|
|
1255
|
+
let A = $e.current;
|
|
1256
|
+
const R = !Ve.current;
|
|
1257
|
+
A < x && (A = x + 0.1), $e.current = A + v.duration;
|
|
1258
|
+
const C = t.createBufferSource();
|
|
1259
|
+
C.buffer = v;
|
|
1260
|
+
let X = Wt;
|
|
1261
|
+
if ((!X || X.context !== t) && (X = t.createAnalyser(), X.fftSize = 64, X.connect(t.destination), ln(X)), C.connect(X), Ie.current.push(C), ve.current) {
|
|
1262
|
+
Ie.current = Ie.current.filter(($) => $ !== C);
|
|
1247
1263
|
return;
|
|
1248
1264
|
}
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
1251
|
-
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${
|
|
1265
|
+
if (R) {
|
|
1266
|
+
Ve.current = !0, z(!0), U(
|
|
1267
|
+
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${A.toFixed(
|
|
1252
1268
|
3
|
|
1253
1269
|
)}`
|
|
1254
|
-
),
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
`[AUDIO] Response started. Initial startTime: ${
|
|
1270
|
+
), De.current = A;
|
|
1271
|
+
const $ = (A - x) * 1e3;
|
|
1272
|
+
Xe.current = performance.now() + $, U(
|
|
1273
|
+
`[AUDIO] Response started. Initial startTime: ${A.toFixed(
|
|
1258
1274
|
3
|
|
1259
|
-
)}, CT: ${
|
|
1275
|
+
)}, CT: ${x.toFixed(3)}`
|
|
1260
1276
|
);
|
|
1261
1277
|
}
|
|
1262
|
-
|
|
1263
|
-
const
|
|
1264
|
-
r && (
|
|
1265
|
-
`[AUDIO] New segment detected at +${
|
|
1278
|
+
C.start(A);
|
|
1279
|
+
const ie = (A - De.current) * 1e3;
|
|
1280
|
+
r && (Oe.current = ie, U(
|
|
1281
|
+
`[AUDIO] New segment detected at +${ie.toFixed(
|
|
1266
1282
|
0
|
|
1267
1283
|
)}ms. Resetting segment offset.`
|
|
1268
|
-
)),
|
|
1269
|
-
const
|
|
1270
|
-
if (
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
`[AUDIO] Viseme "${
|
|
1284
|
+
)), n.forEach(($, pe) => {
|
|
1285
|
+
const B = $.symbol ?? "";
|
|
1286
|
+
if (B) {
|
|
1287
|
+
const ge = qn(B), Le = Math.round($.start * 1e3), Qe = Math.round(($.duration ?? 0) * 1e3), Gt = Oe.current + Le;
|
|
1288
|
+
pe < 3 && U(
|
|
1289
|
+
`[AUDIO] Viseme "${B}": segment_relative=${Le}ms, segment_offset=${Oe.current.toFixed(
|
|
1274
1290
|
0
|
|
1275
|
-
)}ms => vtime=${
|
|
1276
|
-
),
|
|
1277
|
-
|
|
1278
|
-
viseme:
|
|
1279
|
-
weight:
|
|
1280
|
-
vtime:
|
|
1281
|
-
vduration:
|
|
1291
|
+
)}ms => vtime=${Gt}ms`
|
|
1292
|
+
), ge.forEach((qt) => {
|
|
1293
|
+
Me.current.push({
|
|
1294
|
+
viseme: qt.v,
|
|
1295
|
+
weight: qt.w,
|
|
1296
|
+
vtime: Gt,
|
|
1297
|
+
vduration: Qe
|
|
1282
1298
|
});
|
|
1283
1299
|
});
|
|
1284
1300
|
}
|
|
1285
|
-
}),
|
|
1301
|
+
}), b("Speaking...");
|
|
1286
1302
|
} finally {
|
|
1287
|
-
if (
|
|
1288
|
-
const
|
|
1289
|
-
|
|
1303
|
+
if (V.current = !1, Ee.current.length > 0) {
|
|
1304
|
+
const i = Ee.current.shift();
|
|
1305
|
+
i && At(i.audio, i.visemes, i.isNewSegment);
|
|
1290
1306
|
}
|
|
1291
1307
|
}
|
|
1292
1308
|
}
|
|
1293
|
-
},
|
|
1309
|
+
}, gn = async (e) => {
|
|
1294
1310
|
try {
|
|
1295
|
-
|
|
1296
|
-
const
|
|
1297
|
-
u.readAsDataURL(
|
|
1298
|
-
const
|
|
1299
|
-
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
)}`,
|
|
1311
|
+
f(!0), K(!1), ue.current = "", _e(""), b("Processing Voice...");
|
|
1312
|
+
const n = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(n), t = pn(i), u = new FileReader();
|
|
1313
|
+
u.readAsDataURL(t), u.onloadend = async () => {
|
|
1314
|
+
const g = u.result.split(",")[1];
|
|
1315
|
+
st(), se(""), k.current = "", ce.current = !1;
|
|
1316
|
+
const v = `${tt}/stt?token=${encodeURIComponent(
|
|
1317
|
+
We
|
|
1318
|
+
)}`, x = await fetch(v, {
|
|
1303
1319
|
method: "POST",
|
|
1304
1320
|
headers: { "Content-Type": "application/json" },
|
|
1305
1321
|
body: JSON.stringify({
|
|
1306
|
-
audio_base64:
|
|
1307
|
-
audio_format: "wav"
|
|
1322
|
+
audio_base64: g,
|
|
1323
|
+
audio_format: "wav",
|
|
1324
|
+
agentId: E
|
|
1308
1325
|
})
|
|
1309
1326
|
});
|
|
1310
|
-
if (
|
|
1327
|
+
if (x.status === 429) {
|
|
1311
1328
|
try {
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1329
|
+
const pe = await x.text(), B = JSON.parse(pe);
|
|
1330
|
+
U("[STT] 429 agent at capacity:", B?.detail);
|
|
1314
1331
|
} catch {
|
|
1315
1332
|
}
|
|
1316
|
-
|
|
1333
|
+
se(""), b("Busy"), f(!1);
|
|
1317
1334
|
return;
|
|
1318
1335
|
}
|
|
1319
|
-
if (!
|
|
1320
|
-
const
|
|
1321
|
-
let
|
|
1336
|
+
if (!x.ok) {
|
|
1337
|
+
const pe = await x.text();
|
|
1338
|
+
let B = "STT Failed";
|
|
1322
1339
|
try {
|
|
1323
|
-
|
|
1340
|
+
B = JSON.parse(pe).error || B;
|
|
1324
1341
|
} catch {
|
|
1325
|
-
|
|
1342
|
+
pe && (B = pe.slice(0, 200));
|
|
1326
1343
|
}
|
|
1327
|
-
throw new Error(
|
|
1344
|
+
throw new Error(B);
|
|
1328
1345
|
}
|
|
1329
|
-
const
|
|
1330
|
-
if (
|
|
1331
|
-
|
|
1346
|
+
const A = x.body;
|
|
1347
|
+
if (U("this is body" + A), !A) {
|
|
1348
|
+
b("STT Failed"), f(!1);
|
|
1332
1349
|
return;
|
|
1333
1350
|
}
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
const
|
|
1337
|
-
let
|
|
1338
|
-
const
|
|
1339
|
-
switch (
|
|
1351
|
+
const R = A.getReader();
|
|
1352
|
+
ve.current = !1;
|
|
1353
|
+
const C = new TextDecoder();
|
|
1354
|
+
let X = "", ie = !1;
|
|
1355
|
+
const $ = async (pe, B) => {
|
|
1356
|
+
switch (pe) {
|
|
1340
1357
|
case "transcript":
|
|
1341
|
-
|
|
1358
|
+
B.transcript != null && se(String(B.transcript));
|
|
1342
1359
|
break;
|
|
1343
1360
|
case "text": {
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1361
|
+
const ge = B.delta ?? B.text ?? "";
|
|
1362
|
+
ge && Ft(ge);
|
|
1346
1363
|
break;
|
|
1347
1364
|
}
|
|
1348
1365
|
case "audio": {
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1366
|
+
const ge = B.chunk, Le = B.visemes ?? [], Qe = !!B.is_new_segment;
|
|
1367
|
+
ge && await At(ge, Le, Qe);
|
|
1351
1368
|
break;
|
|
1352
1369
|
}
|
|
1353
1370
|
case "done": {
|
|
1354
|
-
|
|
1371
|
+
ie = !0, b("Ready"), f(!1);
|
|
1355
1372
|
break;
|
|
1356
1373
|
}
|
|
1357
1374
|
case "error": {
|
|
1358
|
-
|
|
1375
|
+
ie = !0, b("STT Failed"), f(!1);
|
|
1359
1376
|
break;
|
|
1360
1377
|
}
|
|
1361
1378
|
default:
|
|
@@ -1363,226 +1380,227 @@ const Jn = ({
|
|
|
1363
1380
|
}
|
|
1364
1381
|
};
|
|
1365
1382
|
for (; ; ) {
|
|
1366
|
-
const { done:
|
|
1367
|
-
|
|
1368
|
-
const
|
|
1383
|
+
const { done: pe, value: B } = await R.read();
|
|
1384
|
+
B && (X += C.decode(B, { stream: !0 }));
|
|
1385
|
+
const ge = X.split(`
|
|
1369
1386
|
|
|
1370
1387
|
`);
|
|
1371
|
-
|
|
1372
|
-
for (const
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1388
|
+
X = ge.pop() ?? "";
|
|
1389
|
+
for (const Le of ge) {
|
|
1390
|
+
const Qe = Ze(Le);
|
|
1391
|
+
Qe && await $(Qe.event, Qe.data);
|
|
1375
1392
|
}
|
|
1376
|
-
if (
|
|
1377
|
-
if (
|
|
1378
|
-
const
|
|
1379
|
-
|
|
1393
|
+
if (pe) {
|
|
1394
|
+
if (X.trim()) {
|
|
1395
|
+
const Le = Ze(X.trim());
|
|
1396
|
+
Le && await $(Le.event, Le.data);
|
|
1380
1397
|
}
|
|
1381
|
-
|
|
1398
|
+
ie || (b("Ready"), f(!1));
|
|
1382
1399
|
break;
|
|
1383
1400
|
}
|
|
1384
1401
|
}
|
|
1385
1402
|
};
|
|
1386
|
-
} catch (
|
|
1387
|
-
console.error("Audio Submission Error:",
|
|
1403
|
+
} catch (n) {
|
|
1404
|
+
console.error("Audio Submission Error:", n), b("STT Failed"), f(!1);
|
|
1388
1405
|
}
|
|
1389
|
-
},
|
|
1390
|
-
e && e.preventDefault(),
|
|
1391
|
-
},
|
|
1392
|
-
const
|
|
1393
|
-
let r = "",
|
|
1394
|
-
for (const u of
|
|
1395
|
-
u.startsWith("event:") ? r = u.slice(6).trim() : u.startsWith("data:") && (
|
|
1406
|
+
}, bn = async (e) => {
|
|
1407
|
+
e && e.preventDefault(), K(!1), ue.current = "", _e(""), !(!q || ae) && await _n(q);
|
|
1408
|
+
}, Ze = (e) => {
|
|
1409
|
+
const n = e.split(/\r?\n/);
|
|
1410
|
+
let r = "", i = "";
|
|
1411
|
+
for (const u of n)
|
|
1412
|
+
u.startsWith("event:") ? r = u.slice(6).trim() : u.startsWith("data:") && (i = u.slice(5).trim());
|
|
1396
1413
|
if (!r) return null;
|
|
1397
|
-
let
|
|
1398
|
-
if (
|
|
1414
|
+
let t = {};
|
|
1415
|
+
if (i)
|
|
1399
1416
|
try {
|
|
1400
|
-
|
|
1417
|
+
t = JSON.parse(i);
|
|
1401
1418
|
} catch {
|
|
1402
|
-
|
|
1419
|
+
t = { raw: i };
|
|
1403
1420
|
}
|
|
1404
|
-
return { event: r, data:
|
|
1405
|
-
},
|
|
1421
|
+
return { event: r, data: t };
|
|
1422
|
+
}, gt = (e, n) => {
|
|
1406
1423
|
switch (e) {
|
|
1407
1424
|
case "connected":
|
|
1408
|
-
|
|
1425
|
+
k.current = "", ce.current = !1;
|
|
1409
1426
|
break;
|
|
1410
1427
|
case "text": {
|
|
1411
|
-
const r =
|
|
1412
|
-
r &&
|
|
1428
|
+
const r = n.delta ?? "";
|
|
1429
|
+
r && Ft(r);
|
|
1413
1430
|
break;
|
|
1414
1431
|
}
|
|
1415
1432
|
case "audio": {
|
|
1416
|
-
const r =
|
|
1417
|
-
r &&
|
|
1433
|
+
const r = n.chunk, i = n.visemes ?? [];
|
|
1434
|
+
r && At(r, i);
|
|
1418
1435
|
break;
|
|
1419
1436
|
}
|
|
1420
1437
|
case "done": {
|
|
1421
|
-
const r =
|
|
1438
|
+
const r = Nt(), i = ue.current.trim(), t = [
|
|
1422
1439
|
...r,
|
|
1423
|
-
{ role: "user", content:
|
|
1424
|
-
{ role: "assistant", content:
|
|
1440
|
+
{ role: "user", content: q || "..." },
|
|
1441
|
+
{ role: "assistant", content: i }
|
|
1425
1442
|
];
|
|
1426
|
-
|
|
1443
|
+
un(t), ct.current = [...Me.current], b("Ready"), f(!1), se("");
|
|
1427
1444
|
break;
|
|
1428
1445
|
}
|
|
1429
1446
|
case "error": {
|
|
1430
|
-
const r =
|
|
1431
|
-
|
|
1447
|
+
const r = n.message ?? "Unknown error";
|
|
1448
|
+
ue.current = r, _e(r), b("Agent Failed"), f(!1);
|
|
1432
1449
|
break;
|
|
1433
1450
|
}
|
|
1434
1451
|
}
|
|
1435
|
-
},
|
|
1436
|
-
|
|
1452
|
+
}, Vt = async (e, n) => {
|
|
1453
|
+
f(!0), b("Thinking..."), ue.current = "", k.current = "", ce.current = !1, st(), de.current = 0, it(0);
|
|
1437
1454
|
try {
|
|
1438
1455
|
const r = await fetch(e, {
|
|
1439
1456
|
method: "POST",
|
|
1440
1457
|
headers: { "Content-Type": "application/json" },
|
|
1441
|
-
body: JSON.stringify(
|
|
1458
|
+
body: JSON.stringify(n)
|
|
1442
1459
|
});
|
|
1443
1460
|
if (r.status === 429) {
|
|
1444
|
-
|
|
1461
|
+
b("Busy"), f(!1);
|
|
1445
1462
|
return;
|
|
1446
1463
|
}
|
|
1447
1464
|
if (!r.ok) throw new Error("Request failed");
|
|
1448
|
-
const
|
|
1449
|
-
if (!
|
|
1450
|
-
|
|
1465
|
+
const i = r.body;
|
|
1466
|
+
if (!i) {
|
|
1467
|
+
b("Failed"), f(!1);
|
|
1451
1468
|
return;
|
|
1452
1469
|
}
|
|
1453
|
-
const
|
|
1454
|
-
|
|
1470
|
+
const t = i.getReader();
|
|
1471
|
+
ve.current = !1;
|
|
1455
1472
|
const u = new TextDecoder();
|
|
1456
|
-
let
|
|
1473
|
+
let g = "";
|
|
1457
1474
|
for (; ; ) {
|
|
1458
|
-
const { done:
|
|
1459
|
-
|
|
1460
|
-
const
|
|
1475
|
+
const { done: v, value: x } = await t.read();
|
|
1476
|
+
x && (g += u.decode(x, { stream: !0 }));
|
|
1477
|
+
const A = g.split(`
|
|
1461
1478
|
|
|
1462
1479
|
`);
|
|
1463
|
-
|
|
1464
|
-
for (const
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1480
|
+
g = A.pop() ?? "";
|
|
1481
|
+
for (const R of A) {
|
|
1482
|
+
const C = Ze(R);
|
|
1483
|
+
C && gt(C.event, C.data);
|
|
1467
1484
|
}
|
|
1468
|
-
if (
|
|
1469
|
-
if (
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1485
|
+
if (v) {
|
|
1486
|
+
if (g.trim()) {
|
|
1487
|
+
const R = Ze(g.trim());
|
|
1488
|
+
R && gt(R.event, R.data);
|
|
1472
1489
|
}
|
|
1473
|
-
|
|
1490
|
+
b("Ready"), f(!1);
|
|
1474
1491
|
break;
|
|
1475
1492
|
}
|
|
1476
1493
|
}
|
|
1477
1494
|
} catch (r) {
|
|
1478
|
-
console.error("Streaming Error:", r),
|
|
1495
|
+
console.error("Streaming Error:", r), b("Failed"), f(!1);
|
|
1479
1496
|
}
|
|
1480
|
-
},
|
|
1481
|
-
const
|
|
1482
|
-
await
|
|
1483
|
-
}, []),
|
|
1484
|
-
const
|
|
1485
|
-
await
|
|
1486
|
-
}, []),
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
}, [
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
const
|
|
1493
|
-
|
|
1497
|
+
}, $t = et(async (e, n, r) => {
|
|
1498
|
+
const i = `${tt}/avatar_tts`;
|
|
1499
|
+
await Vt(i, { text: e, userQuery: n, llmPrompt: r });
|
|
1500
|
+
}, []), Ht = et(async (e, n, r, i) => {
|
|
1501
|
+
const t = `${tt}/avatar_ttsWithKnowledge`;
|
|
1502
|
+
await Vt(t, { userQuery: e, llmPrompt: n, knowledge: r, history: i });
|
|
1503
|
+
}, []), jt = a(!1);
|
|
1504
|
+
W(() => {
|
|
1505
|
+
y && !jt.current && (y({ avatarSpeak: $t, avatarRespond: Ht }), jt.current = !0);
|
|
1506
|
+
}, [y, $t, Ht]);
|
|
1507
|
+
const _n = async (e) => {
|
|
1508
|
+
f(!0), b("Thinking..."), ue.current = "", k.current = "", ce.current = !1, st(), de.current = 0, it(0);
|
|
1509
|
+
const n = `${tt}/agent/chat?token=${encodeURIComponent(
|
|
1510
|
+
We
|
|
1494
1511
|
)}`;
|
|
1495
1512
|
try {
|
|
1496
|
-
const r =
|
|
1497
|
-
let
|
|
1498
|
-
|
|
1513
|
+
const r = Nt();
|
|
1514
|
+
let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
|
|
1515
|
+
i || (Mn(
|
|
1499
1516
|
"[CHAT] Session UID missing at send time! Generating emergency backup."
|
|
1500
|
-
),
|
|
1501
|
-
const
|
|
1517
|
+
), i = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i));
|
|
1518
|
+
const t = {
|
|
1502
1519
|
history: r,
|
|
1503
1520
|
question: e,
|
|
1504
|
-
lead_id:
|
|
1521
|
+
lead_id: i,
|
|
1522
|
+
agentId: E
|
|
1505
1523
|
};
|
|
1506
|
-
|
|
1507
|
-
const u = await fetch(
|
|
1524
|
+
U("[CHAT] Sending payload:", t);
|
|
1525
|
+
const u = await fetch(n, {
|
|
1508
1526
|
method: "POST",
|
|
1509
1527
|
headers: {
|
|
1510
1528
|
"Content-Type": "application/json"
|
|
1511
1529
|
},
|
|
1512
|
-
body: JSON.stringify(
|
|
1530
|
+
body: JSON.stringify(t),
|
|
1513
1531
|
cache: "default"
|
|
1514
1532
|
});
|
|
1515
1533
|
if (u.status === 429) {
|
|
1516
1534
|
try {
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1535
|
+
const R = await u.json();
|
|
1536
|
+
U("[CHAT] 429 agent at capacity:", R?.detail);
|
|
1519
1537
|
} catch {
|
|
1520
1538
|
}
|
|
1521
|
-
|
|
1539
|
+
se(""), b("Busy"), f(!1);
|
|
1522
1540
|
return;
|
|
1523
1541
|
}
|
|
1524
1542
|
if (!u.ok)
|
|
1525
1543
|
throw new Error("Agent request failed");
|
|
1526
|
-
const
|
|
1527
|
-
if (!
|
|
1528
|
-
|
|
1544
|
+
const g = u.body;
|
|
1545
|
+
if (!g) {
|
|
1546
|
+
b("Agent Failed"), f(!1);
|
|
1529
1547
|
return;
|
|
1530
1548
|
}
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1534
|
-
let
|
|
1549
|
+
const v = g.getReader();
|
|
1550
|
+
ve.current = !1;
|
|
1551
|
+
const x = new TextDecoder();
|
|
1552
|
+
let A = "";
|
|
1535
1553
|
for (; ; ) {
|
|
1536
|
-
const { done:
|
|
1537
|
-
|
|
1538
|
-
`[SSE] Chunk received. done=${
|
|
1539
|
-
),
|
|
1540
|
-
const
|
|
1554
|
+
const { done: R, value: C } = await v.read();
|
|
1555
|
+
U(
|
|
1556
|
+
`[SSE] Chunk received. done=${R}, length=${C?.length || 0}`
|
|
1557
|
+
), C && (A += x.decode(C, { stream: !0 }));
|
|
1558
|
+
const X = A.split(`
|
|
1541
1559
|
|
|
1542
1560
|
`);
|
|
1543
|
-
|
|
1544
|
-
for (const
|
|
1545
|
-
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1561
|
+
A = X.pop() ?? "";
|
|
1562
|
+
for (const ie of X) {
|
|
1563
|
+
U(`[SSE] Processing block: ${ie.slice(0, 50)}...`);
|
|
1564
|
+
const $ = Ze(ie);
|
|
1565
|
+
$ && (U(`[SSE] Event: ${$.event}`), gt($.event, $.data));
|
|
1548
1566
|
}
|
|
1549
|
-
if (
|
|
1550
|
-
if (
|
|
1551
|
-
const
|
|
1552
|
-
|
|
1567
|
+
if (R) {
|
|
1568
|
+
if (U("[SSE] Stream finished"), A.trim()) {
|
|
1569
|
+
const ie = Ze(A.trim());
|
|
1570
|
+
ie && gt(ie.event, ie.data);
|
|
1553
1571
|
}
|
|
1554
|
-
|
|
1572
|
+
b("Ready"), f(!1), se("");
|
|
1555
1573
|
break;
|
|
1556
1574
|
}
|
|
1557
1575
|
}
|
|
1558
1576
|
} catch (r) {
|
|
1559
|
-
console.error("Chat Error:", r),
|
|
1577
|
+
console.error("Chat Error:", r), b("Agent Failed"), f(!1);
|
|
1560
1578
|
}
|
|
1561
|
-
},
|
|
1579
|
+
}, wn = M.trim(), Jt = rn(wn), Et = Jt && O ? Jt.slice(
|
|
1562
1580
|
0,
|
|
1563
|
-
|
|
1581
|
+
ot != null && ot > 0 ? ot : 0
|
|
1564
1582
|
) : "";
|
|
1565
|
-
|
|
1566
|
-
const e =
|
|
1567
|
-
e !== "exiting" && (
|
|
1568
|
-
}, [
|
|
1569
|
-
const
|
|
1570
|
-
const e =
|
|
1571
|
-
e === "entering" ?
|
|
1583
|
+
W(() => {
|
|
1584
|
+
const e = Ne.current;
|
|
1585
|
+
e !== "exiting" && (Et ? (Lt(Et), e === "hidden" && ze("entering")) : (e === "visible" || e === "entering") && ze("exiting"));
|
|
1586
|
+
}, [Et, oe]);
|
|
1587
|
+
const yn = et(() => {
|
|
1588
|
+
const e = Ne.current;
|
|
1589
|
+
e === "entering" ? ze("visible") : e === "exiting" && ze("hidden");
|
|
1572
1590
|
}, []);
|
|
1573
|
-
|
|
1574
|
-
const e =
|
|
1591
|
+
Tn(() => {
|
|
1592
|
+
const e = dt.current;
|
|
1575
1593
|
e && (e.scrollTop = e.scrollHeight);
|
|
1576
|
-
}, [
|
|
1577
|
-
const
|
|
1578
|
-
return /* @__PURE__ */
|
|
1579
|
-
/* @__PURE__ */
|
|
1580
|
-
|
|
1594
|
+
}, [ft]);
|
|
1595
|
+
const Sn = J === "female" ? Wn : Bn;
|
|
1596
|
+
return rt ? /* @__PURE__ */ be("div", { className: "avatar-widget-container", children: [
|
|
1597
|
+
/* @__PURE__ */ be("div", { className: "avatar-input-area", children: [
|
|
1598
|
+
Ce !== "hidden" ? /* @__PURE__ */ l(
|
|
1581
1599
|
"div",
|
|
1582
1600
|
{
|
|
1583
|
-
className: `avatar-thinking-tab${
|
|
1584
|
-
onAnimationEnd:
|
|
1585
|
-
children:
|
|
1601
|
+
className: `avatar-thinking-tab${Ce === "exiting" ? " avatar-thinking-tab--exiting" : Ce === "entering" ? " avatar-thinking-tab--entering" : ""}`,
|
|
1602
|
+
onAnimationEnd: on,
|
|
1603
|
+
children: L === nn ? /* @__PURE__ */ l(
|
|
1586
1604
|
"a",
|
|
1587
1605
|
{
|
|
1588
1606
|
href: "https://leads.streamoji.com",
|
|
@@ -1590,10 +1608,10 @@ const Jn = ({
|
|
|
1590
1608
|
rel: "noopener noreferrer",
|
|
1591
1609
|
children: "Made by Streamoji Leads"
|
|
1592
1610
|
}
|
|
1593
|
-
) :
|
|
1611
|
+
) : L
|
|
1594
1612
|
}
|
|
1595
1613
|
) : null,
|
|
1596
|
-
/* @__PURE__ */
|
|
1614
|
+
/* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
|
|
1597
1615
|
"div",
|
|
1598
1616
|
{
|
|
1599
1617
|
style: {
|
|
@@ -1602,15 +1620,15 @@ const Jn = ({
|
|
|
1602
1620
|
width: "100%",
|
|
1603
1621
|
height: "100%"
|
|
1604
1622
|
},
|
|
1605
|
-
children:
|
|
1606
|
-
/* @__PURE__ */
|
|
1623
|
+
children: kt ? /* @__PURE__ */ be("div", { className: "avatar-input-recording", children: [
|
|
1624
|
+
/* @__PURE__ */ l(
|
|
1607
1625
|
"button",
|
|
1608
1626
|
{
|
|
1609
1627
|
type: "button",
|
|
1610
1628
|
className: "avatar-recording-cancel",
|
|
1611
|
-
onClick:
|
|
1629
|
+
onClick: mn,
|
|
1612
1630
|
title: "Cancel",
|
|
1613
|
-
children: /* @__PURE__ */
|
|
1631
|
+
children: /* @__PURE__ */ be(
|
|
1614
1632
|
"svg",
|
|
1615
1633
|
{
|
|
1616
1634
|
width: "18",
|
|
@@ -1623,14 +1641,14 @@ const Jn = ({
|
|
|
1623
1641
|
strokeLinejoin: "round",
|
|
1624
1642
|
style: { display: "block" },
|
|
1625
1643
|
children: [
|
|
1626
|
-
/* @__PURE__ */
|
|
1627
|
-
/* @__PURE__ */
|
|
1644
|
+
/* @__PURE__ */ l("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
1645
|
+
/* @__PURE__ */ l("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
1628
1646
|
]
|
|
1629
1647
|
}
|
|
1630
1648
|
)
|
|
1631
1649
|
}
|
|
1632
1650
|
),
|
|
1633
|
-
/* @__PURE__ */
|
|
1651
|
+
/* @__PURE__ */ be(
|
|
1634
1652
|
"div",
|
|
1635
1653
|
{
|
|
1636
1654
|
style: {
|
|
@@ -1642,8 +1660,8 @@ const Jn = ({
|
|
|
1642
1660
|
minWidth: 0
|
|
1643
1661
|
},
|
|
1644
1662
|
children: [
|
|
1645
|
-
/* @__PURE__ */
|
|
1646
|
-
/* @__PURE__ */
|
|
1663
|
+
/* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(zt, { analyser: hn }) }),
|
|
1664
|
+
/* @__PURE__ */ be(
|
|
1647
1665
|
"span",
|
|
1648
1666
|
{
|
|
1649
1667
|
style: {
|
|
@@ -1656,23 +1674,23 @@ const Jn = ({
|
|
|
1656
1674
|
fontVariantNumeric: "tabular-nums"
|
|
1657
1675
|
},
|
|
1658
1676
|
children: [
|
|
1659
|
-
Math.floor(
|
|
1677
|
+
Math.floor(Pt / 60),
|
|
1660
1678
|
":",
|
|
1661
|
-
String(
|
|
1679
|
+
String(Pt % 60).padStart(2, "0")
|
|
1662
1680
|
]
|
|
1663
1681
|
}
|
|
1664
1682
|
)
|
|
1665
1683
|
]
|
|
1666
1684
|
}
|
|
1667
1685
|
),
|
|
1668
|
-
/* @__PURE__ */
|
|
1686
|
+
/* @__PURE__ */ l(
|
|
1669
1687
|
"button",
|
|
1670
1688
|
{
|
|
1671
1689
|
type: "button",
|
|
1672
1690
|
className: "avatar-recording-confirm",
|
|
1673
|
-
onClick:
|
|
1691
|
+
onClick: fn,
|
|
1674
1692
|
title: "Send",
|
|
1675
|
-
children: /* @__PURE__ */
|
|
1693
|
+
children: /* @__PURE__ */ l(
|
|
1676
1694
|
"svg",
|
|
1677
1695
|
{
|
|
1678
1696
|
width: "18",
|
|
@@ -1684,13 +1702,13 @@ const Jn = ({
|
|
|
1684
1702
|
strokeLinecap: "round",
|
|
1685
1703
|
strokeLinejoin: "round",
|
|
1686
1704
|
style: { display: "block" },
|
|
1687
|
-
children: /* @__PURE__ */
|
|
1705
|
+
children: /* @__PURE__ */ l("polyline", { points: "20 6 9 17 4 12" })
|
|
1688
1706
|
}
|
|
1689
1707
|
)
|
|
1690
1708
|
}
|
|
1691
1709
|
)
|
|
1692
|
-
] }) :
|
|
1693
|
-
/* @__PURE__ */
|
|
1710
|
+
] }) : O && !_ ? /* @__PURE__ */ be("div", { className: "avatar-input-speaking", children: [
|
|
1711
|
+
/* @__PURE__ */ l(
|
|
1694
1712
|
"div",
|
|
1695
1713
|
{
|
|
1696
1714
|
style: {
|
|
@@ -1700,20 +1718,20 @@ const Jn = ({
|
|
|
1700
1718
|
alignItems: "center",
|
|
1701
1719
|
paddingRight: "8px"
|
|
1702
1720
|
},
|
|
1703
|
-
children: /* @__PURE__ */
|
|
1721
|
+
children: /* @__PURE__ */ l(zt, { analyser: Wt })
|
|
1704
1722
|
}
|
|
1705
1723
|
),
|
|
1706
|
-
/* @__PURE__ */
|
|
1724
|
+
/* @__PURE__ */ l(
|
|
1707
1725
|
"button",
|
|
1708
1726
|
{
|
|
1709
1727
|
type: "button",
|
|
1710
1728
|
className: "avatar-speaking-stop",
|
|
1711
|
-
onClick: () =>
|
|
1729
|
+
onClick: () => st(!0),
|
|
1712
1730
|
title: "Stop",
|
|
1713
|
-
children: /* @__PURE__ */
|
|
1731
|
+
children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
|
|
1714
1732
|
}
|
|
1715
1733
|
)
|
|
1716
|
-
] }) :
|
|
1734
|
+
] }) : ae ? /* @__PURE__ */ l(
|
|
1717
1735
|
"div",
|
|
1718
1736
|
{
|
|
1719
1737
|
style: {
|
|
@@ -1723,12 +1741,12 @@ const Jn = ({
|
|
|
1723
1741
|
alignItems: "center",
|
|
1724
1742
|
justifyContent: "center"
|
|
1725
1743
|
},
|
|
1726
|
-
children: /* @__PURE__ */
|
|
1744
|
+
children: /* @__PURE__ */ l("div", { className: "avatar-input-loader" })
|
|
1727
1745
|
}
|
|
1728
|
-
) : /* @__PURE__ */
|
|
1746
|
+
) : /* @__PURE__ */ be(
|
|
1729
1747
|
"form",
|
|
1730
1748
|
{
|
|
1731
|
-
onSubmit:
|
|
1749
|
+
onSubmit: bn,
|
|
1732
1750
|
style: {
|
|
1733
1751
|
flex: 1,
|
|
1734
1752
|
display: "flex",
|
|
@@ -1736,20 +1754,20 @@ const Jn = ({
|
|
|
1736
1754
|
alignItems: "center"
|
|
1737
1755
|
},
|
|
1738
1756
|
children: [
|
|
1739
|
-
/* @__PURE__ */
|
|
1757
|
+
/* @__PURE__ */ l(
|
|
1740
1758
|
"input",
|
|
1741
1759
|
{
|
|
1742
1760
|
id: "avatar-text-input",
|
|
1743
1761
|
type: "text",
|
|
1744
|
-
value:
|
|
1745
|
-
onChange: (e) =>
|
|
1746
|
-
placeholder:
|
|
1747
|
-
disabled:
|
|
1762
|
+
value: q,
|
|
1763
|
+
onChange: (e) => se(e.target.value),
|
|
1764
|
+
placeholder: H === "Busy" ? "Assisting another user" : N || "Ask me anything",
|
|
1765
|
+
disabled: ae || H === "Busy",
|
|
1748
1766
|
autoComplete: "off",
|
|
1749
1767
|
style: { width: "100%", height: "100%" }
|
|
1750
1768
|
}
|
|
1751
1769
|
),
|
|
1752
|
-
|
|
1770
|
+
H === "Busy" ? /* @__PURE__ */ l(
|
|
1753
1771
|
"button",
|
|
1754
1772
|
{
|
|
1755
1773
|
type: "button",
|
|
@@ -1757,7 +1775,7 @@ const Jn = ({
|
|
|
1757
1775
|
disabled: !0,
|
|
1758
1776
|
style: { backgroundColor: "#1e4a5e" },
|
|
1759
1777
|
title: "Agent at capacity",
|
|
1760
|
-
children: /* @__PURE__ */
|
|
1778
|
+
children: /* @__PURE__ */ l(
|
|
1761
1779
|
"svg",
|
|
1762
1780
|
{
|
|
1763
1781
|
width: "24",
|
|
@@ -1766,7 +1784,7 @@ const Jn = ({
|
|
|
1766
1784
|
fill: "none",
|
|
1767
1785
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1768
1786
|
"aria-hidden": "true",
|
|
1769
|
-
children: /* @__PURE__ */
|
|
1787
|
+
children: /* @__PURE__ */ l(
|
|
1770
1788
|
"path",
|
|
1771
1789
|
{
|
|
1772
1790
|
d: "M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",
|
|
@@ -1776,15 +1794,15 @@ const Jn = ({
|
|
|
1776
1794
|
}
|
|
1777
1795
|
)
|
|
1778
1796
|
}
|
|
1779
|
-
) :
|
|
1797
|
+
) : q.trim() === "" ? /* @__PURE__ */ l(
|
|
1780
1798
|
"button",
|
|
1781
1799
|
{
|
|
1782
1800
|
type: "button",
|
|
1783
1801
|
className: "mic-button",
|
|
1784
|
-
onClick:
|
|
1785
|
-
disabled:
|
|
1802
|
+
onClick: dn,
|
|
1803
|
+
disabled: ae,
|
|
1786
1804
|
style: { backgroundColor: "#1e4a5e" },
|
|
1787
|
-
children: /* @__PURE__ */
|
|
1805
|
+
children: /* @__PURE__ */ be(
|
|
1788
1806
|
"svg",
|
|
1789
1807
|
{
|
|
1790
1808
|
width: "28",
|
|
@@ -1793,14 +1811,14 @@ const Jn = ({
|
|
|
1793
1811
|
fill: "none",
|
|
1794
1812
|
xmlns: "http://www.w3.org/2000/svg",
|
|
1795
1813
|
children: [
|
|
1796
|
-
/* @__PURE__ */
|
|
1814
|
+
/* @__PURE__ */ l(
|
|
1797
1815
|
"path",
|
|
1798
1816
|
{
|
|
1799
1817
|
d: "M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z",
|
|
1800
1818
|
fill: "white"
|
|
1801
1819
|
}
|
|
1802
1820
|
),
|
|
1803
|
-
/* @__PURE__ */
|
|
1821
|
+
/* @__PURE__ */ l(
|
|
1804
1822
|
"path",
|
|
1805
1823
|
{
|
|
1806
1824
|
d: "M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z",
|
|
@@ -1811,15 +1829,15 @@ const Jn = ({
|
|
|
1811
1829
|
}
|
|
1812
1830
|
)
|
|
1813
1831
|
}
|
|
1814
|
-
) : /* @__PURE__ */
|
|
1832
|
+
) : /* @__PURE__ */ l(
|
|
1815
1833
|
"button",
|
|
1816
1834
|
{
|
|
1817
1835
|
type: "submit",
|
|
1818
1836
|
className: "mic-button",
|
|
1819
|
-
disabled:
|
|
1837
|
+
disabled: ae,
|
|
1820
1838
|
style: { backgroundColor: "#1e4a5e" },
|
|
1821
1839
|
title: "Send",
|
|
1822
|
-
children: /* @__PURE__ */
|
|
1840
|
+
children: /* @__PURE__ */ l(
|
|
1823
1841
|
"svg",
|
|
1824
1842
|
{
|
|
1825
1843
|
width: 24,
|
|
@@ -1827,7 +1845,7 @@ const Jn = ({
|
|
|
1827
1845
|
viewBox: "0 0 24 24",
|
|
1828
1846
|
fill: "none",
|
|
1829
1847
|
"aria-hidden": "true",
|
|
1830
|
-
children: /* @__PURE__ */
|
|
1848
|
+
children: /* @__PURE__ */ l(
|
|
1831
1849
|
"path",
|
|
1832
1850
|
{
|
|
1833
1851
|
d: "M19 12H5M19 12L14 17M19 12L14 7",
|
|
@@ -1847,22 +1865,22 @@ const Jn = ({
|
|
|
1847
1865
|
}
|
|
1848
1866
|
) })
|
|
1849
1867
|
] }),
|
|
1850
|
-
/* @__PURE__ */
|
|
1851
|
-
|
|
1868
|
+
/* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ be("div", { className: "avatar-scene-wrapper", children: [
|
|
1869
|
+
oe !== "hidden" && /* @__PURE__ */ l(
|
|
1852
1870
|
"div",
|
|
1853
1871
|
{
|
|
1854
|
-
className: `avatar-bubble${
|
|
1855
|
-
onAnimationEnd:
|
|
1856
|
-
children: /* @__PURE__ */
|
|
1872
|
+
className: `avatar-bubble${oe === "entering" ? " avatar-bubble--entering" : oe === "exiting" ? " avatar-bubble--exiting" : ""}`,
|
|
1873
|
+
onAnimationEnd: yn,
|
|
1874
|
+
children: /* @__PURE__ */ l("div", { ref: dt, className: `avatar-bubble__content${_ ? " avatar-bubble__content--nudge" : ""}`, children: ft })
|
|
1857
1875
|
}
|
|
1858
1876
|
),
|
|
1859
|
-
/* @__PURE__ */
|
|
1877
|
+
/* @__PURE__ */ l(
|
|
1860
1878
|
"div",
|
|
1861
1879
|
{
|
|
1862
1880
|
className: "avatar-canvas-layer",
|
|
1863
|
-
style: { width:
|
|
1864
|
-
children: /* @__PURE__ */
|
|
1865
|
-
|
|
1881
|
+
style: { width: G, height: G },
|
|
1882
|
+
children: /* @__PURE__ */ be(
|
|
1883
|
+
kn,
|
|
1866
1884
|
{
|
|
1867
1885
|
shadows: !0,
|
|
1868
1886
|
camera: { position: [0.2, 1.4, 3], fov: 42 },
|
|
@@ -1870,30 +1888,30 @@ const Jn = ({
|
|
|
1870
1888
|
dpr: 1.8,
|
|
1871
1889
|
style: { pointerEvents: "none", width: "100%", height: "100%" },
|
|
1872
1890
|
children: [
|
|
1873
|
-
/* @__PURE__ */
|
|
1874
|
-
/* @__PURE__ */
|
|
1875
|
-
/* @__PURE__ */
|
|
1876
|
-
/* @__PURE__ */
|
|
1877
|
-
/* @__PURE__ */
|
|
1878
|
-
|
|
1891
|
+
/* @__PURE__ */ l(zn, { target: Sn }),
|
|
1892
|
+
/* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
|
|
1893
|
+
/* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
|
|
1894
|
+
/* @__PURE__ */ l(Ln, { preset: "city" }),
|
|
1895
|
+
/* @__PURE__ */ l(An, { fallback: null, children: Ae !== null && /* @__PURE__ */ l(
|
|
1896
|
+
Yn,
|
|
1879
1897
|
{
|
|
1880
|
-
avatarUrl:
|
|
1881
|
-
isPlayingRef:
|
|
1882
|
-
visemeQueueRef:
|
|
1883
|
-
audioContextRef:
|
|
1884
|
-
responseAudioStartTimeRef:
|
|
1885
|
-
adjustments:
|
|
1886
|
-
mood:
|
|
1887
|
-
expression:
|
|
1888
|
-
agentResponse:
|
|
1889
|
-
isSpeaking:
|
|
1890
|
-
nextStartTimeRef:
|
|
1891
|
-
stopPlayback:
|
|
1892
|
-
setIsSpeaking:
|
|
1893
|
-
expressionUrl:
|
|
1894
|
-
onExpressionFinished:
|
|
1895
|
-
isNudgeResponse:
|
|
1896
|
-
avatarGender:
|
|
1898
|
+
avatarUrl: Ae,
|
|
1899
|
+
isPlayingRef: Ve,
|
|
1900
|
+
visemeQueueRef: Me,
|
|
1901
|
+
audioContextRef: we,
|
|
1902
|
+
responseAudioStartTimeRef: De,
|
|
1903
|
+
adjustments: Pn,
|
|
1904
|
+
mood: h,
|
|
1905
|
+
expression: o,
|
|
1906
|
+
agentResponse: M,
|
|
1907
|
+
isSpeaking: O,
|
|
1908
|
+
nextStartTimeRef: $e,
|
|
1909
|
+
stopPlayback: st,
|
|
1910
|
+
setIsSpeaking: z,
|
|
1911
|
+
expressionUrl: D,
|
|
1912
|
+
onExpressionFinished: cn,
|
|
1913
|
+
isNudgeResponse: _,
|
|
1914
|
+
avatarGender: J
|
|
1897
1915
|
}
|
|
1898
1916
|
) })
|
|
1899
1917
|
]
|
|
@@ -1902,23 +1920,21 @@ const Jn = ({
|
|
|
1902
1920
|
}
|
|
1903
1921
|
)
|
|
1904
1922
|
] }) })
|
|
1905
|
-
] });
|
|
1906
|
-
},
|
|
1907
|
-
|
|
1908
|
-
avatarGender: C,
|
|
1923
|
+
] }) : null;
|
|
1924
|
+
}, rr = ({
|
|
1925
|
+
agentId: p,
|
|
1909
1926
|
onNavigationRequested: E,
|
|
1910
|
-
presetUserDetails:
|
|
1911
|
-
onAvatarReady:
|
|
1912
|
-
}) => /* @__PURE__ */
|
|
1913
|
-
|
|
1927
|
+
presetUserDetails: w,
|
|
1928
|
+
onAvatarReady: y
|
|
1929
|
+
}) => /* @__PURE__ */ l(
|
|
1930
|
+
Qn,
|
|
1914
1931
|
{
|
|
1915
|
-
|
|
1932
|
+
agentId: p,
|
|
1916
1933
|
onNavigationRequested: E,
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
onAvatarReady: v
|
|
1934
|
+
presetUserDetails: w,
|
|
1935
|
+
onAvatarReady: y
|
|
1920
1936
|
}
|
|
1921
1937
|
);
|
|
1922
1938
|
export {
|
|
1923
|
-
|
|
1939
|
+
rr as AvatarWidget
|
|
1924
1940
|
};
|