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