@streamoji/avatar-widget 0.3.2 → 0.3.4
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 +5 -5
- package/dist/avatar-widget.js +531 -521
- package/dist/avatar-widget.umd.js +29 -29
- package/dist/avatar-widget.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
import { jsx as l, jsxs as ae } from "react/jsx-runtime";
|
|
2
2
|
import { useGLTF as lt, Environment as Yt } from "@react-three/drei";
|
|
3
3
|
import { useFrame as Qt, Canvas as Kt, useThree as Xt } from "@react-three/fiber";
|
|
4
|
-
import { memo as Zt, useMemo as ft, useRef as a, useState as g, useEffect as
|
|
5
|
-
import * as
|
|
4
|
+
import { memo as Zt, useMemo as ft, useRef as a, useState as g, useEffect as H, useCallback as Ke, useLayoutEffect as en, Suspense as tn } from "react";
|
|
5
|
+
import * as He from "three";
|
|
6
6
|
import { GLTFLoader as nn } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
|
-
const ut = "https://ai.streamoji.com",
|
|
7
|
+
const ut = "https://ai.streamoji.com", $ = (...f) => {
|
|
8
8
|
}, rn = (...f) => {
|
|
9
9
|
}, Et = ({ analyser: f }) => {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
const p =
|
|
10
|
+
const L = a(null), b = a(null);
|
|
11
|
+
return H(() => {
|
|
12
|
+
const p = L.current;
|
|
13
13
|
if (!p) return;
|
|
14
14
|
const _ = p.getContext("2d", { alpha: !0 });
|
|
15
15
|
if (!_) return;
|
|
16
|
-
let
|
|
17
|
-
f && (f.fftSize = 128,
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const K = p.width,
|
|
21
|
-
if (K === 0 ||
|
|
22
|
-
const
|
|
23
|
-
_.clearRect(0, 0, K,
|
|
24
|
-
const
|
|
16
|
+
let D, j = null;
|
|
17
|
+
f && (f.fftSize = 128, j = new Uint8Array(f.frequencyBinCount));
|
|
18
|
+
const fe = () => {
|
|
19
|
+
D = requestAnimationFrame(fe), (p.width !== p.offsetWidth || p.height !== p.offsetHeight) && (p.width = p.offsetWidth, p.height = p.offsetHeight);
|
|
20
|
+
const K = p.width, N = p.height;
|
|
21
|
+
if (K === 0 || N === 0) return;
|
|
22
|
+
const he = N / 2;
|
|
23
|
+
_.clearRect(0, 0, K, N), _.fillStyle = "#1e293b";
|
|
24
|
+
const E = 2, S = E + 2, R = K * 0.95, U = Math.floor(R / S);
|
|
25
25
|
(!b.current || b.current.length !== U) && (b.current = new Float32Array(U).fill(2));
|
|
26
|
-
const
|
|
27
|
-
f &&
|
|
28
|
-
const Ie =
|
|
29
|
-
for (let
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
for (let
|
|
34
|
-
const x =
|
|
35
|
-
x >
|
|
26
|
+
const me = U * S, y = (K - me) / 2;
|
|
27
|
+
f && j && f.getByteFrequencyData(j);
|
|
28
|
+
const Ie = j ? j.length : 0, Y = Math.floor(Ie * 0.7) / U, be = new Float32Array(U);
|
|
29
|
+
for (let B = 0; B < U; B++) {
|
|
30
|
+
let J = 0;
|
|
31
|
+
if (j && Y > 0) {
|
|
32
|
+
const P = Math.floor(B * Y), _e = Math.floor((B + 1) * Y);
|
|
33
|
+
for (let M = P; M < _e; M++) {
|
|
34
|
+
const x = j[M] || 0;
|
|
35
|
+
x > J && (J = x);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
38
|
+
J < 10 && (J = 0);
|
|
39
|
+
const z = J / 255, I = J > 0 ? Math.max(2, Math.pow(z, 1.4) * N * 0.25) : 2;
|
|
40
|
+
be[B] = I;
|
|
41
41
|
}
|
|
42
|
-
for (let
|
|
43
|
-
const
|
|
44
|
-
b.current[
|
|
45
|
-
const
|
|
46
|
-
_.beginPath(), _.roundRect ? _.roundRect(
|
|
42
|
+
for (let B = 0; B < U; B++) {
|
|
43
|
+
const J = U - 1 - B, z = Math.max(be[B], be[J]), I = b.current[B] + (z - b.current[B]) * 0.3;
|
|
44
|
+
b.current[B] = I;
|
|
45
|
+
const P = y + B * S, _e = he - I / 2;
|
|
46
|
+
_.beginPath(), _.roundRect ? _.roundRect(P, _e, E, I, 4) : _.fillRect(P, _e, E, I), _.fill();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
return
|
|
50
|
-
cancelAnimationFrame(
|
|
49
|
+
return fe(), () => {
|
|
50
|
+
cancelAnimationFrame(D);
|
|
51
51
|
};
|
|
52
52
|
}, [f]), /* @__PURE__ */ l(
|
|
53
53
|
"canvas",
|
|
54
54
|
{
|
|
55
|
-
ref:
|
|
55
|
+
ref: L,
|
|
56
56
|
style: { width: "100%", height: "100%", display: "block" }
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
|
-
}, sn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", It = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-
|
|
59
|
+
}, sn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", It = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
|
|
60
60
|
async function on(f) {
|
|
61
|
-
const
|
|
61
|
+
const L = await crypto.subtle.digest(
|
|
62
62
|
"SHA-256",
|
|
63
63
|
new TextEncoder().encode(f)
|
|
64
64
|
);
|
|
65
|
-
return Array.from(new Uint8Array(
|
|
65
|
+
return Array.from(new Uint8Array(L)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
66
66
|
}
|
|
67
67
|
function an(f) {
|
|
68
|
-
const [
|
|
69
|
-
return
|
|
68
|
+
const [L, b] = g(null);
|
|
69
|
+
return H(() => {
|
|
70
70
|
if (!f) {
|
|
71
71
|
b(null);
|
|
72
72
|
return;
|
|
@@ -74,16 +74,16 @@ function an(f) {
|
|
|
74
74
|
let p = !1;
|
|
75
75
|
return on(f).then((_) => {
|
|
76
76
|
if (p) return;
|
|
77
|
-
const
|
|
78
|
-
fetch(
|
|
79
|
-
p || b(
|
|
77
|
+
const D = `${sn}/${_}.glb`;
|
|
78
|
+
fetch(D, { method: "HEAD" }).then((j) => {
|
|
79
|
+
p || b(j.ok ? D : It);
|
|
80
80
|
}).catch(() => {
|
|
81
81
|
p || b(It);
|
|
82
82
|
});
|
|
83
83
|
}), () => {
|
|
84
84
|
p = !0;
|
|
85
85
|
};
|
|
86
|
-
}, [f]),
|
|
86
|
+
}, [f]), L;
|
|
87
87
|
}
|
|
88
88
|
const cn = [
|
|
89
89
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
|
|
@@ -262,15 +262,21 @@ const cn = [
|
|
|
262
262
|
}
|
|
263
263
|
], dn = [
|
|
264
264
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
|
|
265
|
-
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"
|
|
266
|
-
|
|
265
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
|
|
266
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"
|
|
267
|
+
], fn = [
|
|
268
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
|
|
269
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
|
|
270
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb",
|
|
271
|
+
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"
|
|
272
|
+
], hn = {
|
|
267
273
|
zoom: 0.85,
|
|
268
274
|
position: [0.15, -0.8, 0],
|
|
269
275
|
scale: 1.5,
|
|
270
276
|
rotation: [0.15, 0.02, 0]
|
|
271
|
-
},
|
|
277
|
+
}, mn = [-0.45, 1.9, 0.1], pn = {
|
|
272
278
|
browInnerUp: 0.2
|
|
273
|
-
}, dt = 0.18,
|
|
279
|
+
}, dt = 0.18, gn = 1, Mt = "__branding__", Xe = {
|
|
274
280
|
neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
|
|
275
281
|
happy: {
|
|
276
282
|
mouthSmileLeft: 0.2,
|
|
@@ -352,7 +358,7 @@ const cn = [
|
|
|
352
358
|
mouthUpperUpLeft: 0.1,
|
|
353
359
|
mouthUpperUpRight: 0.1
|
|
354
360
|
}
|
|
355
|
-
},
|
|
361
|
+
}, bn = [
|
|
356
362
|
{ key: "viseme_aa", mix: { jawOpen: 0.6 } },
|
|
357
363
|
{
|
|
358
364
|
key: "viseme_E",
|
|
@@ -448,7 +454,7 @@ const cn = [
|
|
|
448
454
|
}
|
|
449
455
|
},
|
|
450
456
|
{ key: "viseme_sil", mix: {} }
|
|
451
|
-
],
|
|
457
|
+
], _n = {
|
|
452
458
|
aei: [
|
|
453
459
|
{ v: "E", w: 0.8 },
|
|
454
460
|
{ v: "I", w: 0.2 }
|
|
@@ -477,336 +483,340 @@ const cn = [
|
|
|
477
483
|
],
|
|
478
484
|
sil: [{ v: "sil", w: 1 }]
|
|
479
485
|
};
|
|
480
|
-
function
|
|
486
|
+
function wn(f) {
|
|
481
487
|
if (!f) return [{ v: "sil", w: 1 }];
|
|
482
|
-
const
|
|
483
|
-
return
|
|
488
|
+
const L = f.toLowerCase();
|
|
489
|
+
return _n[L] ?? [{ v: "sil", w: 1 }];
|
|
484
490
|
}
|
|
485
|
-
function
|
|
486
|
-
const { camera:
|
|
487
|
-
return
|
|
488
|
-
|
|
489
|
-
}, [
|
|
491
|
+
function vn({ target: f }) {
|
|
492
|
+
const { camera: L } = Xt();
|
|
493
|
+
return H(() => {
|
|
494
|
+
L.lookAt(...f);
|
|
495
|
+
}, [L, f]), null;
|
|
490
496
|
}
|
|
491
|
-
function Q(f,
|
|
497
|
+
function Q(f, L, b) {
|
|
492
498
|
if (!f || !f.morphTargetDictionary)
|
|
493
499
|
return;
|
|
494
|
-
const p = f, _ = p.morphTargetDictionary,
|
|
495
|
-
if (
|
|
496
|
-
for (const
|
|
497
|
-
|
|
500
|
+
const p = f, _ = p.morphTargetDictionary, D = p.morphTargetInfluences;
|
|
501
|
+
if (D)
|
|
502
|
+
for (const j in _)
|
|
503
|
+
j.toLowerCase() === L.toLowerCase() && (D[_[j]] = b);
|
|
498
504
|
}
|
|
499
|
-
function Ct(f,
|
|
505
|
+
function Ct(f, L = 0.97) {
|
|
500
506
|
if (!f) return;
|
|
501
507
|
const b = f;
|
|
502
508
|
if (b.morphTargetInfluences)
|
|
503
509
|
for (let p = 0; p < b.morphTargetInfluences.length; p++)
|
|
504
|
-
b.morphTargetInfluences[p] *=
|
|
510
|
+
b.morphTargetInfluences[p] *= L;
|
|
505
511
|
}
|
|
506
|
-
const
|
|
512
|
+
const yn = Zt(
|
|
507
513
|
({
|
|
508
514
|
avatarUrl: f,
|
|
509
|
-
isPlayingRef:
|
|
515
|
+
isPlayingRef: L,
|
|
510
516
|
visemeQueueRef: b,
|
|
511
517
|
audioContextRef: p,
|
|
512
518
|
responseAudioStartTimeRef: _,
|
|
513
|
-
adjustments:
|
|
514
|
-
mood:
|
|
515
|
-
expression:
|
|
519
|
+
adjustments: D,
|
|
520
|
+
mood: j,
|
|
521
|
+
expression: fe,
|
|
516
522
|
agentResponse: K,
|
|
517
|
-
isSpeaking:
|
|
518
|
-
nextStartTimeRef:
|
|
519
|
-
stopPlayback:
|
|
523
|
+
isSpeaking: N,
|
|
524
|
+
nextStartTimeRef: he,
|
|
525
|
+
stopPlayback: E,
|
|
520
526
|
setIsSpeaking: v,
|
|
521
|
-
expressionUrl:
|
|
522
|
-
onExpressionFinished:
|
|
527
|
+
expressionUrl: S,
|
|
528
|
+
onExpressionFinished: R,
|
|
523
529
|
isNudgeResponse: U,
|
|
524
|
-
avatarGender:
|
|
530
|
+
avatarGender: me
|
|
525
531
|
}) => {
|
|
526
|
-
const { scene: y } = lt(f),
|
|
527
|
-
() =>
|
|
528
|
-
[
|
|
529
|
-
),
|
|
530
|
-
() =>
|
|
531
|
-
[
|
|
532
|
-
),
|
|
533
|
-
|
|
534
|
-
if (!(!
|
|
535
|
-
if (
|
|
536
|
-
const
|
|
537
|
-
if (!
|
|
538
|
-
const
|
|
539
|
-
|
|
532
|
+
const { scene: y } = lt(f), Ue = lt(me === "female" ? ln : cn), Y = ft(
|
|
533
|
+
() => Ue.flatMap((d) => d.animations),
|
|
534
|
+
[Ue]
|
|
535
|
+
), B = lt(me === "female" ? fn : dn), J = ft(
|
|
536
|
+
() => B.flatMap((d) => d.animations),
|
|
537
|
+
[B]
|
|
538
|
+
), z = a(null), I = a(null), P = a(null), _e = a([]), [M] = g(() => new He.AnimationMixer(y)), x = a({}), C = a(null), we = a(0), Me = a(!1), ve = a(0), ce = a(null);
|
|
539
|
+
H(() => {
|
|
540
|
+
if (!(!Y || !y)) {
|
|
541
|
+
if (Y.forEach((d, u) => {
|
|
542
|
+
const i = `idle_${u}`;
|
|
543
|
+
if (!x.current[i]) {
|
|
544
|
+
const s = M.clipAction(d, y);
|
|
545
|
+
s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[i] = s;
|
|
540
546
|
}
|
|
541
|
-
}),
|
|
542
|
-
const
|
|
543
|
-
if (!
|
|
544
|
-
const
|
|
545
|
-
|
|
547
|
+
}), J.forEach((d, u) => {
|
|
548
|
+
const i = `talk_${u}`;
|
|
549
|
+
if (!x.current[i]) {
|
|
550
|
+
const s = M.clipAction(d, y);
|
|
551
|
+
s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[i] = s;
|
|
546
552
|
}
|
|
547
|
-
}),
|
|
548
|
-
const
|
|
549
|
-
|
|
553
|
+
}), Y.length > 0) {
|
|
554
|
+
const d = x.current.idle_0, u = C.current && M.existingAction(C.current.getClip());
|
|
555
|
+
d && !u && (d.reset().fadeIn(0.5).play(), C.current = d);
|
|
550
556
|
}
|
|
551
557
|
return () => {
|
|
552
|
-
|
|
558
|
+
M.stopAllAction(), x.current = {}, C.current = null;
|
|
553
559
|
};
|
|
554
560
|
}
|
|
555
|
-
}, [
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
if (!
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
(
|
|
562
|
-
if (
|
|
563
|
-
const
|
|
564
|
-
if (
|
|
565
|
-
const
|
|
566
|
-
|
|
561
|
+
}, [Y, J, y, M]);
|
|
562
|
+
const ye = a("");
|
|
563
|
+
H(() => {
|
|
564
|
+
if (!S || !y || S === ye.current) return;
|
|
565
|
+
ye.current = S, ce.current = S, new nn().load(
|
|
566
|
+
S,
|
|
567
|
+
(u) => {
|
|
568
|
+
if (u.animations && u.animations.length > 0) {
|
|
569
|
+
const i = u.animations[0], s = M.clipAction(i, y);
|
|
570
|
+
if (s.name = `EXPR_${S}`, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[`EXPR_${S}`] = s, N && ce.current === S) {
|
|
571
|
+
const h = C.current;
|
|
572
|
+
s.reset().fadeIn(0.3).play(), h && h !== s && h.crossFadeTo(s, 0.3, !0), C.current = s, ce.current = null;
|
|
567
573
|
}
|
|
568
574
|
}
|
|
569
575
|
},
|
|
570
576
|
void 0,
|
|
571
|
-
(
|
|
572
|
-
console.error(`[ANIMATION] Failed to load ${
|
|
577
|
+
(u) => {
|
|
578
|
+
console.error(`[ANIMATION] Failed to load ${S}`, u);
|
|
573
579
|
}
|
|
574
580
|
);
|
|
575
|
-
}, [
|
|
576
|
-
const
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
579
|
-
const
|
|
580
|
-
X && (X.reset().fadeIn(0.5).play(),
|
|
581
|
-
} else if (
|
|
582
|
-
if (
|
|
583
|
-
const
|
|
584
|
-
|
|
581
|
+
}, [S, y, M, N]), H(() => {
|
|
582
|
+
const d = (u) => {
|
|
583
|
+
const i = u.action, s = i.name || "";
|
|
584
|
+
if (s.startsWith("idle_")) {
|
|
585
|
+
const W = (parseInt(s.split("_")[1]) + 1) % Y.length, X = x.current[`idle_${W}`];
|
|
586
|
+
X && (X.reset().fadeIn(0.5).play(), i.crossFadeTo(X, 0.5, !0), C.current = X);
|
|
587
|
+
} else if (s.startsWith("EXPR_")) {
|
|
588
|
+
if (N) {
|
|
589
|
+
const h = Math.floor(
|
|
590
|
+
Math.random() * J.length
|
|
591
|
+
), W = x.current[`talk_${h}`];
|
|
592
|
+
W && (W.reset().fadeIn(0.5).play(), i.crossFadeTo(W, 0.5, !0), C.current = W);
|
|
585
593
|
} else {
|
|
586
|
-
const
|
|
587
|
-
|
|
594
|
+
const h = x.current.idle_0;
|
|
595
|
+
h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
|
|
588
596
|
}
|
|
589
|
-
|
|
590
|
-
} else if (
|
|
591
|
-
if (
|
|
592
|
-
const
|
|
593
|
-
X && (X.reset().fadeIn(0.3).play(),
|
|
597
|
+
R && R();
|
|
598
|
+
} else if (s.startsWith("talk_"))
|
|
599
|
+
if (N && !U) {
|
|
600
|
+
const W = (parseInt(s.split("_")[1]) + 1) % J.length, X = x.current[`talk_${W}`];
|
|
601
|
+
X && (X.reset().fadeIn(0.3).play(), i.crossFadeTo(X, 0.3, !0), C.current = X);
|
|
594
602
|
} else {
|
|
595
|
-
const
|
|
596
|
-
|
|
603
|
+
const h = x.current.idle_0;
|
|
604
|
+
h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
|
|
597
605
|
}
|
|
598
606
|
};
|
|
599
|
-
return
|
|
607
|
+
return M.addEventListener("finished", d), () => M.removeEventListener("finished", d);
|
|
600
608
|
}, [
|
|
601
|
-
P,
|
|
602
|
-
G,
|
|
603
609
|
M,
|
|
604
|
-
|
|
610
|
+
Y,
|
|
611
|
+
J,
|
|
612
|
+
N,
|
|
605
613
|
U,
|
|
606
|
-
|
|
607
|
-
]),
|
|
608
|
-
if (
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
611
|
-
const
|
|
612
|
-
if (
|
|
613
|
-
const
|
|
614
|
-
if (
|
|
615
|
-
|
|
614
|
+
R
|
|
615
|
+
]), H(() => {
|
|
616
|
+
if (N && y) {
|
|
617
|
+
const d = C.current, u = d?.name || "";
|
|
618
|
+
if (u.startsWith("idle_") || u.startsWith("talk_") || u === "") {
|
|
619
|
+
const i = ce.current;
|
|
620
|
+
if (i) {
|
|
621
|
+
const s = x.current[`EXPR_${i}`];
|
|
622
|
+
if (s) {
|
|
623
|
+
s.reset().fadeIn(0.3).play(), d && d !== s && d.crossFadeTo(s, 0.3, !0), C.current = s, ce.current = null;
|
|
616
624
|
return;
|
|
617
625
|
}
|
|
618
626
|
}
|
|
619
|
-
if (
|
|
620
|
-
const
|
|
621
|
-
|
|
627
|
+
if (u.startsWith("idle_") || u === "") {
|
|
628
|
+
const s = Math.floor(
|
|
629
|
+
Math.random() * J.length
|
|
630
|
+
), h = x.current[`talk_${s}`];
|
|
631
|
+
h && (h.reset().fadeIn(0.5).play(), d && d.crossFadeTo(h, 0.5, !0), C.current = h);
|
|
622
632
|
}
|
|
623
633
|
}
|
|
624
|
-
} else if (!
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
627
|
-
const
|
|
628
|
-
|
|
634
|
+
} else if (!N && y) {
|
|
635
|
+
const d = C.current, u = d?.name || "";
|
|
636
|
+
if (u.startsWith("talk_") || u.startsWith("EXPR_")) {
|
|
637
|
+
const i = x.current.idle_0;
|
|
638
|
+
i && (i.reset().fadeIn(0.5).play(), d && d.crossFadeTo(i, 0.5, !0), C.current = i);
|
|
629
639
|
}
|
|
630
640
|
}
|
|
631
|
-
}, [
|
|
641
|
+
}, [N, y, S]), H(() => {
|
|
632
642
|
if (!y) return;
|
|
633
|
-
y.traverse((
|
|
634
|
-
if (
|
|
635
|
-
const
|
|
636
|
-
(
|
|
643
|
+
y.traverse((i) => {
|
|
644
|
+
if (i.isMesh && i.morphTargetDictionary) {
|
|
645
|
+
const s = i.name.toLowerCase();
|
|
646
|
+
(s.includes("head") || s.includes("avatar")) && (I.current = i, $(`[ANIMATION] Found head mesh: ${i.name}`)), s.includes("teeth") && (P.current = i, $(`[ANIMATION] Found teeth mesh: ${i.name}`));
|
|
637
647
|
}
|
|
638
648
|
});
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
(
|
|
649
|
+
const d = I.current?.morphTargetDictionary;
|
|
650
|
+
d && Object.keys(d).filter(
|
|
651
|
+
(i) => i.toLowerCase().includes("brow")
|
|
642
652
|
);
|
|
643
|
-
const
|
|
644
|
-
y.traverse((
|
|
645
|
-
if (
|
|
646
|
-
const
|
|
647
|
-
|
|
653
|
+
const u = [];
|
|
654
|
+
y.traverse((i) => {
|
|
655
|
+
if (i.isMesh) {
|
|
656
|
+
const h = i.morphTargetDictionary;
|
|
657
|
+
h && Object.keys(h).some((W) => W.toLowerCase().includes("brow")) && u.push(i);
|
|
648
658
|
}
|
|
649
|
-
}),
|
|
659
|
+
}), _e.current = u, u.length > 0 && $("[ANIMATION] Meshes with brow morphs:", u.length);
|
|
650
660
|
}, [y]);
|
|
651
|
-
const
|
|
652
|
-
const
|
|
653
|
-
if (
|
|
654
|
-
for (const
|
|
655
|
-
const
|
|
656
|
-
Q(
|
|
661
|
+
const Be = (d, u = 1) => {
|
|
662
|
+
const i = `viseme_${d}`.toLowerCase(), s = bn.find((h) => h.key.toLowerCase() === i);
|
|
663
|
+
if (s)
|
|
664
|
+
for (const h in s.mix) {
|
|
665
|
+
const W = s.mix[h] * u;
|
|
666
|
+
Q(I.current, h, W), Q(P.current, h, W);
|
|
657
667
|
}
|
|
658
|
-
},
|
|
659
|
-
const
|
|
660
|
-
for (const
|
|
661
|
-
Q(
|
|
668
|
+
}, ke = (d) => {
|
|
669
|
+
const u = Xe[d] ?? Xe.neutral;
|
|
670
|
+
for (const i in u)
|
|
671
|
+
Q(I.current, i, u[i]), Q(P.current, i, u[i]);
|
|
662
672
|
};
|
|
663
|
-
return Qt((
|
|
664
|
-
const
|
|
665
|
-
Ct(
|
|
666
|
-
const
|
|
667
|
-
let
|
|
668
|
-
if (Math.floor(
|
|
669
|
-
let
|
|
670
|
-
y.traverse((
|
|
671
|
-
|
|
673
|
+
return Qt((d, u) => {
|
|
674
|
+
const i = Math.pow(0.88, 60 * u);
|
|
675
|
+
Ct(I.current, i), Ct(P.current, i), ke(j);
|
|
676
|
+
const s = d.clock.elapsedTime;
|
|
677
|
+
let h = 0;
|
|
678
|
+
if (Math.floor(s) % 5 === 0 && Math.floor((s - u) % 5) !== 0) {
|
|
679
|
+
let q = null;
|
|
680
|
+
y.traverse((Z) => {
|
|
681
|
+
Z.name.toLowerCase().includes("hips") && (q = Z);
|
|
672
682
|
});
|
|
673
|
-
const
|
|
674
|
-
|
|
683
|
+
const Se = q ? `Hips Y: ${q.position.y.toFixed(4)}` : "Hips not found";
|
|
684
|
+
$(`[ANIMATION] Mixer Time: ${M.time.toFixed(2)}, ${Se}`);
|
|
675
685
|
}
|
|
676
|
-
if (
|
|
677
|
-
const
|
|
678
|
-
if (
|
|
679
|
-
|
|
680
|
-
const
|
|
681
|
-
|
|
686
|
+
if (M.update(u), s > we.current && !Me.current && (Me.current = !0, ve.current = s), Me.current) {
|
|
687
|
+
const q = N ? 0.2 : 0.3, Se = (s - ve.current) / q;
|
|
688
|
+
if (Se >= 1) {
|
|
689
|
+
Me.current = !1;
|
|
690
|
+
const Z = N ? 1 : 2.5;
|
|
691
|
+
we.current = s + Z;
|
|
682
692
|
} else {
|
|
683
|
-
const
|
|
684
|
-
Q(
|
|
693
|
+
const Z = Se < 0.5 ? Se * 2 : (1 - Se) * 2;
|
|
694
|
+
Q(I.current, "eyeBlinkLeft", Z), Q(I.current, "eyeBlinkRight", Z), Q(P.current, "eyeBlinkLeft", Z), Q(P.current, "eyeBlinkRight", Z), h = Z * pn.browInnerUp;
|
|
685
695
|
}
|
|
686
696
|
}
|
|
687
|
-
const
|
|
688
|
-
if (Q(
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
697
|
+
const W = Xe[j] ?? Xe.neutral, X = W.browInnerUp ?? 0, Ze = W.browOuterUpLeft ?? 0, je = W.browOuterUpRight ?? 0, Pe = s * gn, Ae = dt * Math.sin(Pe), te = dt * 0.7 * Math.sin(Pe + 0.7), Je = dt * 0.7 * Math.sin(Pe + 1.3), re = (q) => Math.max(0, Math.min(1, q)), Te = re(X + Ae), Le = re(Ze + te), We = re(je + Je), Ce = re(Te + h);
|
|
698
|
+
if (Q(I.current, "browInnerUp", Ce), Q(P.current, "browInnerUp", Ce), Q(I.current, "browOuterUpLeft", Le), Q(P.current, "browOuterUpLeft", Le), Q(I.current, "browOuterUpRight", We), Q(P.current, "browOuterUpRight", We), z.current) {
|
|
699
|
+
const q = L.current ? 0 : D.rotation[1];
|
|
700
|
+
z.current.rotation.y = He.MathUtils.lerp(
|
|
701
|
+
z.current.rotation.y,
|
|
702
|
+
q,
|
|
693
703
|
0.1
|
|
694
|
-
),
|
|
704
|
+
), z.current.position.set(...D.position), z.current.scale.setScalar(D.scale), z.current.rotation.x = D.rotation[0], z.current.rotation.z = D.rotation[2];
|
|
695
705
|
}
|
|
696
|
-
if (
|
|
697
|
-
const
|
|
698
|
-
for (let
|
|
699
|
-
const
|
|
700
|
-
|
|
706
|
+
if (L.current && p.current) {
|
|
707
|
+
const q = p.current.currentTime, Oe = (q - _.current) * 1e3 - -150;
|
|
708
|
+
for (let ne = 0; ne < b.current.length; ne++) {
|
|
709
|
+
const ie = b.current[ne];
|
|
710
|
+
Oe >= ie.vtime && Oe < ie.vtime + ie.vduration && Be(ie.viseme, ie.weight ?? 1);
|
|
701
711
|
}
|
|
702
|
-
|
|
712
|
+
q > he.current + 0.5 && (E(), v(!1));
|
|
703
713
|
}
|
|
704
|
-
}), /* @__PURE__ */ l("group", { ref:
|
|
714
|
+
}), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: y }) });
|
|
705
715
|
}
|
|
706
716
|
);
|
|
707
|
-
function
|
|
717
|
+
function Sn(f) {
|
|
708
718
|
return f ? f.charAt(0).toUpperCase() + f.slice(1).toLowerCase() : "";
|
|
709
719
|
}
|
|
710
|
-
const
|
|
720
|
+
const xn = ({
|
|
711
721
|
token: f,
|
|
712
|
-
agentToken:
|
|
722
|
+
agentToken: L,
|
|
713
723
|
onNavigationRequested: b,
|
|
714
724
|
avatarGender: p,
|
|
715
725
|
presetUserDetails: _
|
|
716
726
|
} = {}) => {
|
|
717
|
-
const
|
|
727
|
+
const D = f ?? L ?? "", j = an(D || void 0), [fe, K] = g(""), [N, he] = g(""), [E, v] = g("Ready"), [S, R] = g(!1), [U, me] = g(!1), [y, Ie] = g([]), [Ue, Y] = g(""), be = a(null), [B, J] = g(
|
|
718
728
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
719
729
|
);
|
|
720
|
-
|
|
721
|
-
const e = window.matchMedia("(max-width: 480px)"), t = () =>
|
|
730
|
+
H(() => {
|
|
731
|
+
const e = window.matchMedia("(max-width: 480px)"), t = () => J(e.matches);
|
|
722
732
|
return e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
723
733
|
}, []);
|
|
724
|
-
const
|
|
734
|
+
const z = B ? 80 : 600, I = a(!1), P = a([]), _e = a(0), M = a(!1), x = a([]), C = a(null), we = a([]);
|
|
725
735
|
a([]);
|
|
726
|
-
const
|
|
736
|
+
const Me = a([]), ve = a(0), ce = a(0), ye = a(0), Be = a(0), ke = a(!1), [d, u] = g(
|
|
727
737
|
null
|
|
728
|
-
),
|
|
738
|
+
), i = a(null), [s, h] = g("neutral"), [W, X] = g(""), [Ze, je] = g(""), [Pe, Ae] = g("Chat with us"), [te, Je] = g(
|
|
729
739
|
null
|
|
730
|
-
), [
|
|
731
|
-
|
|
732
|
-
const [
|
|
733
|
-
et.current =
|
|
734
|
-
const pe = a(""),
|
|
735
|
-
|
|
736
|
-
if (
|
|
737
|
-
_t(!1),
|
|
740
|
+
), [re, Te] = g("hidden"), [Le, We] = g(""), Ce = a(null), q = a(re);
|
|
741
|
+
q.current = re;
|
|
742
|
+
const [Se, Z] = g(null), Oe = a(null), ne = a(null), [ie, ht] = g(!1), mt = a(null), [le, qe] = g("hidden"), [pt, Ot] = g(""), et = a(le);
|
|
743
|
+
et.current = le;
|
|
744
|
+
const pe = a(""), De = a(!1), Ne = a(""), gt = a(Date.now()), tt = a([]), Ve = a(!1), [nt, $e] = g(!1), [bt, _t] = g(!1), xe = a(null), Fe = ft(() => ie ? "Try again" : E === "Busy" ? "Busy" : E === "Thinking..." || E === "Processing Voice..." ? E : te != null && te !== "" && te !== "none" && te !== "<none>" ? `Enter ${Sn(te)}` : le !== "hidden" || !bt ? null : Mt, [E, te, ie, le, bt]), wt = !ie && E !== "Busy" && E !== "Thinking..." && E !== "Processing Voice..." && (te == null || te === "" || te === "none" || te === "<none>");
|
|
745
|
+
H(() => {
|
|
746
|
+
if (le !== "hidden" || !wt) {
|
|
747
|
+
_t(!1), xe.current != null && (clearTimeout(xe.current), xe.current = null);
|
|
738
748
|
return;
|
|
739
749
|
}
|
|
740
|
-
return
|
|
741
|
-
|
|
750
|
+
return xe.current = setTimeout(() => {
|
|
751
|
+
xe.current = null, _t(!0);
|
|
742
752
|
}, 400), () => {
|
|
743
|
-
|
|
753
|
+
xe.current != null && (clearTimeout(xe.current), xe.current = null);
|
|
744
754
|
};
|
|
745
|
-
}, [
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
const e =
|
|
755
|
+
}, [le, wt]);
|
|
756
|
+
const Ge = Fe != null && Fe !== "";
|
|
757
|
+
H(() => {
|
|
758
|
+
const e = q.current;
|
|
749
759
|
if (!(e === "exiting" || e === "entering")) {
|
|
750
760
|
if (e === "hidden") {
|
|
751
|
-
|
|
761
|
+
Ge && (We(Fe ?? ""), Te("entering"));
|
|
752
762
|
return;
|
|
753
763
|
}
|
|
754
|
-
e === "visible" && (!
|
|
764
|
+
e === "visible" && (!Ge || Fe !== Le) && (Ce.current = Ge ? Fe : null, Te("exiting"));
|
|
755
765
|
}
|
|
756
766
|
}, [
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
]),
|
|
762
|
-
if (
|
|
763
|
-
|
|
767
|
+
Ge,
|
|
768
|
+
Fe,
|
|
769
|
+
re,
|
|
770
|
+
Le
|
|
771
|
+
]), H(() => {
|
|
772
|
+
if (E !== "Busy") {
|
|
773
|
+
ne.current != null && (clearTimeout(ne.current), ne.current = null);
|
|
764
774
|
return;
|
|
765
775
|
}
|
|
766
|
-
return
|
|
767
|
-
|
|
776
|
+
return ne.current = setTimeout(() => {
|
|
777
|
+
ne.current = null, v("Ready"), ht(!0);
|
|
768
778
|
}, 12e3), () => {
|
|
769
|
-
|
|
779
|
+
ne.current != null && (clearTimeout(ne.current), ne.current = null);
|
|
770
780
|
};
|
|
771
|
-
}, [
|
|
772
|
-
if (!
|
|
781
|
+
}, [E]), H(() => {
|
|
782
|
+
if (!ie) return;
|
|
773
783
|
const e = setTimeout(() => ht(!1), 2500);
|
|
774
784
|
return () => clearTimeout(e);
|
|
775
|
-
}, [
|
|
776
|
-
const Dt =
|
|
777
|
-
const e =
|
|
785
|
+
}, [ie]);
|
|
786
|
+
const Dt = Ke(() => {
|
|
787
|
+
const e = q.current;
|
|
778
788
|
if (e === "exiting") {
|
|
779
|
-
|
|
780
|
-
const t =
|
|
781
|
-
|
|
782
|
-
} else e === "entering" &&
|
|
789
|
+
Te("hidden");
|
|
790
|
+
const t = Ce.current;
|
|
791
|
+
Ce.current = null, t != null && t !== "" && (We(t), Te("entering"));
|
|
792
|
+
} else e === "entering" && Te("visible");
|
|
783
793
|
}, []), Nt = (e) => {
|
|
784
794
|
if (!e) return;
|
|
785
795
|
if (e.mood != null) {
|
|
786
796
|
const n = String(e.mood).toLowerCase();
|
|
787
|
-
|
|
797
|
+
h(n);
|
|
788
798
|
}
|
|
789
799
|
if (e.expression != null) {
|
|
790
800
|
const n = String(e.expression).trim();
|
|
791
|
-
|
|
801
|
+
X(n);
|
|
792
802
|
const c = un.find(
|
|
793
|
-
(
|
|
803
|
+
(m) => m.name.toLowerCase() === n.toLowerCase()
|
|
794
804
|
);
|
|
795
|
-
|
|
805
|
+
$(
|
|
796
806
|
`[STREAM] Animation match for "${n}": ${c ? c.name : "NONE"}`
|
|
797
|
-
),
|
|
807
|
+
), je(c?.url ?? "");
|
|
798
808
|
}
|
|
799
809
|
if (e.navigation != null) {
|
|
800
810
|
const n = String(e.navigation).trim();
|
|
801
811
|
n !== "" && (b ? b(n) : window.open(n, "_blank"));
|
|
802
812
|
}
|
|
803
|
-
const t = e.ask_for || e.lead_capture?.ask_for,
|
|
813
|
+
const t = e.ask_for || e.lead_capture?.ask_for, r = t ? String(t).trim().toLowerCase() : "", o = r === "none" || r === "<none>";
|
|
804
814
|
if (t && !o) {
|
|
805
|
-
const n =
|
|
815
|
+
const n = r;
|
|
806
816
|
if (_ && (n === "email" && _.email || n === "name" && _.name || n === "phone" && _.phone))
|
|
807
817
|
return;
|
|
808
|
-
|
|
809
|
-
} else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (
|
|
818
|
+
Je(n || null), Ae(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
|
|
819
|
+
} else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Je(null), Pe !== "Chat with us" && Ae("Chat with us"));
|
|
810
820
|
e.collected, e.valid;
|
|
811
821
|
}, Ft = (e) => {
|
|
812
822
|
const t = e.trim();
|
|
@@ -818,116 +828,116 @@ const Sn = ({
|
|
|
818
828
|
return null;
|
|
819
829
|
}
|
|
820
830
|
if (t.includes(":")) {
|
|
821
|
-
const
|
|
831
|
+
const r = t.split(":"), o = r[0].trim().toLowerCase(), n = r.slice(1).join(":").trim();
|
|
822
832
|
return { [o]: n };
|
|
823
833
|
}
|
|
824
834
|
return null;
|
|
825
|
-
}, Ut =
|
|
835
|
+
}, Ut = Ke(() => {
|
|
826
836
|
}, []), vt = (e) => {
|
|
827
|
-
if (
|
|
828
|
-
e === "§" ?
|
|
837
|
+
if (De.current)
|
|
838
|
+
e === "§" ? De.current = !1 : (Ne.current += e, he((t) => t + e));
|
|
829
839
|
else if (e === "§") {
|
|
830
|
-
|
|
840
|
+
De.current = !0;
|
|
831
841
|
return;
|
|
832
842
|
} else
|
|
833
843
|
for (pe.current += e; pe.current.includes(`
|
|
834
844
|
`); ) {
|
|
835
845
|
const t = pe.current.indexOf(`
|
|
836
|
-
`),
|
|
846
|
+
`), r = pe.current.slice(0, t).trim();
|
|
837
847
|
pe.current = pe.current.slice(t + 1);
|
|
838
|
-
const o = Ft(
|
|
848
|
+
const o = Ft(r);
|
|
839
849
|
o && Nt(o);
|
|
840
850
|
}
|
|
841
851
|
};
|
|
842
|
-
|
|
852
|
+
H(() => {
|
|
843
853
|
(async () => {
|
|
844
854
|
if (!sessionStorage.getItem(
|
|
845
855
|
"STREAMOJI_LEADS_SESSION_LEAD_ID"
|
|
846
856
|
)) {
|
|
847
857
|
const n = "secret", c = Math.floor(Date.now() / 1e3).toString();
|
|
848
858
|
try {
|
|
849
|
-
const
|
|
859
|
+
const m = new TextEncoder(), w = await crypto.subtle.importKey(
|
|
850
860
|
"raw",
|
|
851
|
-
|
|
861
|
+
m.encode(n),
|
|
852
862
|
{ name: "HMAC", hash: "SHA-256" },
|
|
853
863
|
!1,
|
|
854
864
|
["sign"]
|
|
855
|
-
),
|
|
865
|
+
), k = await crypto.subtle.sign(
|
|
856
866
|
"HMAC",
|
|
857
867
|
w,
|
|
858
|
-
|
|
859
|
-
),
|
|
860
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",
|
|
861
|
-
} catch (
|
|
862
|
-
console.error("[SESSION] HMAC generation failed:",
|
|
868
|
+
m.encode(c)
|
|
869
|
+
), T = Array.from(new Uint8Array(k)).map((V) => V.toString(16).padStart(2, "0")).join("");
|
|
870
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", T), $("[SESSION] New HMAC UID generated and saved:", T);
|
|
871
|
+
} catch (m) {
|
|
872
|
+
console.error("[SESSION] HMAC generation failed:", m);
|
|
863
873
|
const w = Math.random().toString(36) + Date.now().toString();
|
|
864
874
|
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
|
|
865
875
|
}
|
|
866
876
|
}
|
|
867
|
-
const
|
|
877
|
+
const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
|
|
868
878
|
let o = [];
|
|
869
|
-
if (
|
|
879
|
+
if (r)
|
|
870
880
|
try {
|
|
871
|
-
o = JSON.parse(
|
|
881
|
+
o = JSON.parse(r);
|
|
872
882
|
} catch {
|
|
873
883
|
o = [];
|
|
874
884
|
}
|
|
875
885
|
o.length === 0 && _ && (_.name || _.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${_.name || ""}" , Email is "${_.email || ""}"` }], sessionStorage.setItem(
|
|
876
886
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
877
887
|
JSON.stringify(o)
|
|
878
|
-
)) :
|
|
888
|
+
)) : r || sessionStorage.setItem(
|
|
879
889
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
880
890
|
JSON.stringify([])
|
|
881
891
|
);
|
|
882
892
|
})();
|
|
883
|
-
}, [_]),
|
|
893
|
+
}, [_]), H(() => {
|
|
884
894
|
const e = () => {
|
|
885
|
-
gt.current = Date.now(),
|
|
895
|
+
gt.current = Date.now(), Ve.current && (Ve.current = !1, $e(!1), Ie([]), Y(""), he(""), me(!1));
|
|
886
896
|
};
|
|
887
897
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
888
898
|
const t = setInterval(async () => {
|
|
889
|
-
if (Date.now() - gt.current >= 3e4 && !U && !
|
|
890
|
-
if (
|
|
891
|
-
|
|
899
|
+
if (Date.now() - gt.current >= 3e4 && !U && !S && E === "Ready" && !Ve.current)
|
|
900
|
+
if (Ve.current = !0, tt.current.length > 0)
|
|
901
|
+
$e(!0), Ie(tt.current);
|
|
892
902
|
else
|
|
893
903
|
try {
|
|
894
904
|
const n = `${ut}/nudgeUser`, c = {
|
|
895
905
|
navigationUrl: window.location.href,
|
|
896
|
-
token:
|
|
897
|
-
},
|
|
906
|
+
token: D
|
|
907
|
+
}, m = await fetch(n, {
|
|
898
908
|
method: "POST",
|
|
899
909
|
headers: {
|
|
900
910
|
"Content-Type": "application/json"
|
|
901
911
|
},
|
|
902
912
|
body: JSON.stringify(c)
|
|
903
913
|
});
|
|
904
|
-
if (
|
|
905
|
-
const
|
|
906
|
-
|
|
914
|
+
if (m.ok) {
|
|
915
|
+
const k = (await m.json()).nudge_questions;
|
|
916
|
+
k && k.length > 0 && ($("[NUDGE] Received nudge questions from API:", k), tt.current = k, $e(!0), Ie(k));
|
|
907
917
|
}
|
|
908
918
|
} catch (n) {
|
|
909
|
-
console.error("[NUDGE] Error calling /nudgeUser:", n),
|
|
919
|
+
console.error("[NUDGE] Error calling /nudgeUser:", n), Ve.current = !1;
|
|
910
920
|
}
|
|
911
921
|
}, 1e3);
|
|
912
922
|
return () => {
|
|
913
923
|
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(t);
|
|
914
924
|
};
|
|
915
|
-
}, [
|
|
925
|
+
}, [D, U, S, E]), H(() => {
|
|
916
926
|
if (y.length === 0) return;
|
|
917
|
-
let e = 0, t = 0,
|
|
927
|
+
let e = 0, t = 0, r = !1, o = 100;
|
|
918
928
|
const n = () => {
|
|
919
929
|
const c = y[e];
|
|
920
|
-
if (
|
|
921
|
-
const
|
|
922
|
-
|
|
930
|
+
if (r) {
|
|
931
|
+
const m = c.substring(0, t - 1);
|
|
932
|
+
Y(m), t--, o = 50;
|
|
923
933
|
} else {
|
|
924
|
-
const
|
|
925
|
-
|
|
934
|
+
const m = c.substring(0, t + 1);
|
|
935
|
+
Y(m), t++, o = 100;
|
|
926
936
|
}
|
|
927
|
-
!
|
|
937
|
+
!r && t === c.length ? (r = !0, o = 3e3) : r && t === 0 && (r = !1, e = (e + 1) % y.length, o = 500), be.current = setTimeout(n, o);
|
|
928
938
|
};
|
|
929
939
|
return n(), () => {
|
|
930
|
-
|
|
940
|
+
be.current && clearTimeout(be.current);
|
|
931
941
|
};
|
|
932
942
|
}, [y]);
|
|
933
943
|
const yt = () => {
|
|
@@ -943,33 +953,33 @@ const Sn = ({
|
|
|
943
953
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
944
954
|
JSON.stringify(e)
|
|
945
955
|
);
|
|
946
|
-
}, [rt, it] = g(!1), [St, st] = g(0),
|
|
956
|
+
}, [rt, it] = g(!1), [St, st] = g(0), ue = a(null), ze = a([]), xt = a(0), [kt, Pt] = g(
|
|
947
957
|
null
|
|
948
958
|
), [Wt, ot] = g(
|
|
949
959
|
null
|
|
950
|
-
), ge = a(null),
|
|
960
|
+
), ge = a(null), Re = a(
|
|
951
961
|
null
|
|
952
|
-
),
|
|
953
|
-
e && (
|
|
962
|
+
), Ye = Ke((e = !1) => {
|
|
963
|
+
e && (ke.current = !0, R(!1), v("Ready")), x.current = [], P.current = [], M.current = !1, me(!1), ve.current = 0, ce.current = 0, ye.current = 0, we.current.forEach((t) => {
|
|
954
964
|
try {
|
|
955
965
|
t.stop();
|
|
956
966
|
} catch {
|
|
957
967
|
}
|
|
958
|
-
}),
|
|
968
|
+
}), Oe.current && (clearTimeout(Oe.current), Oe.current = null), Z(null), je(""), we.current = [];
|
|
959
969
|
}, []), Vt = async () => {
|
|
960
970
|
try {
|
|
961
|
-
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext,
|
|
962
|
-
n.fftSize = 64, o.connect(n), ge.current =
|
|
971
|
+
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, r = new t(), o = r.createMediaStreamSource(e), n = r.createAnalyser();
|
|
972
|
+
n.fftSize = 64, o.connect(n), ge.current = r, Re.current = o, ot(n);
|
|
963
973
|
const c = new MediaRecorder(e);
|
|
964
|
-
|
|
965
|
-
|
|
974
|
+
ue.current = c, ze.current = [], c.ondataavailable = (m) => {
|
|
975
|
+
m.data.size > 0 && ze.current.push(m.data);
|
|
966
976
|
}, c.onstop = async () => {
|
|
967
|
-
const
|
|
968
|
-
if (ot(null),
|
|
969
|
-
v("Recording too short. Hold or click longer."),
|
|
977
|
+
const m = Date.now() - xt.current;
|
|
978
|
+
if (ot(null), Re.current && (Re.current.disconnect(), Re.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), m < 1e3) {
|
|
979
|
+
v("Recording too short. Hold or click longer."), R(!1);
|
|
970
980
|
return;
|
|
971
981
|
}
|
|
972
|
-
const w = new Blob(
|
|
982
|
+
const w = new Blob(ze.current, {
|
|
973
983
|
type: "audio/wav"
|
|
974
984
|
});
|
|
975
985
|
await Jt(w);
|
|
@@ -978,113 +988,113 @@ const Sn = ({
|
|
|
978
988
|
console.error("Error accessing microphone:", e), v("Mic Access Error");
|
|
979
989
|
}
|
|
980
990
|
}, $t = () => {
|
|
981
|
-
|
|
991
|
+
ue.current && ue.current.state !== "inactive" && (ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), it(!1));
|
|
982
992
|
}, Ht = () => {
|
|
983
|
-
|
|
993
|
+
ue.current && ue.current.state !== "inactive" && (ue.current.onstop = null, ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), ot(null), Re.current && (Re.current.disconnect(), Re.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), it(!1), ze.current = [], v("Ready"));
|
|
984
994
|
};
|
|
985
|
-
|
|
995
|
+
H(() => {
|
|
986
996
|
if (!U) return;
|
|
987
997
|
const e = () => {
|
|
988
|
-
const t =
|
|
998
|
+
const t = ye.current;
|
|
989
999
|
if (t <= 0) return;
|
|
990
|
-
const
|
|
991
|
-
if (!
|
|
992
|
-
const n =
|
|
993
|
-
if (
|
|
1000
|
+
const r = C.current, o = ve.current;
|
|
1001
|
+
if (!r) return;
|
|
1002
|
+
const n = r.currentTime - o, c = Math.min(Math.max(0, n), t), m = N.trim().length;
|
|
1003
|
+
if (m <= 0) return;
|
|
994
1004
|
const w = Math.min(
|
|
995
|
-
Math.round(c / t *
|
|
996
|
-
|
|
1005
|
+
Math.round(c / t * m),
|
|
1006
|
+
m
|
|
997
1007
|
);
|
|
998
|
-
|
|
1008
|
+
u(w);
|
|
999
1009
|
};
|
|
1000
|
-
return clearInterval(
|
|
1001
|
-
}, [U,
|
|
1010
|
+
return clearInterval(i.current ?? void 0), i.current = setInterval(e, 90), () => clearInterval(i.current ?? void 0);
|
|
1011
|
+
}, [U, N, ye.current]), H(() => {
|
|
1002
1012
|
let e;
|
|
1003
1013
|
return rt ? (st(0), e = window.setInterval(() => {
|
|
1004
1014
|
st((t) => t + 1);
|
|
1005
1015
|
}, 1e3)) : st(0), () => clearInterval(e);
|
|
1006
1016
|
}, [rt]);
|
|
1007
1017
|
const jt = (e) => {
|
|
1008
|
-
const t = e.numberOfChannels,
|
|
1018
|
+
const t = e.numberOfChannels, r = e.length * t * 2 + 44, o = new ArrayBuffer(r), n = new DataView(o);
|
|
1009
1019
|
let c = 0;
|
|
1010
|
-
const
|
|
1011
|
-
n.setUint16(c,
|
|
1012
|
-
}, w = (
|
|
1013
|
-
n.setUint32(c,
|
|
1020
|
+
const m = (T) => {
|
|
1021
|
+
n.setUint16(c, T, !0), c += 2;
|
|
1022
|
+
}, w = (T) => {
|
|
1023
|
+
n.setUint32(c, T, !0), c += 4;
|
|
1014
1024
|
};
|
|
1015
|
-
w(1179011410), w(
|
|
1016
|
-
const
|
|
1017
|
-
for (let
|
|
1018
|
-
let
|
|
1019
|
-
for (; c <
|
|
1020
|
-
for (let
|
|
1021
|
-
let
|
|
1022
|
-
|
|
1025
|
+
w(1179011410), w(r - 8), w(1163280727), w(544501094), w(16), m(1), m(t), w(e.sampleRate), w(e.sampleRate * 2 * t), m(t * 2), m(16), w(1635017060), w(r - c - 4);
|
|
1026
|
+
const k = [];
|
|
1027
|
+
for (let T = 0; T < t; T++) k.push(e.getChannelData(T));
|
|
1028
|
+
let A = 0;
|
|
1029
|
+
for (; c < r; ) {
|
|
1030
|
+
for (let T = 0; T < t; T++) {
|
|
1031
|
+
let V = Math.max(-1, Math.min(1, k[T][A]));
|
|
1032
|
+
V = V < 0 ? V * 32768 : V * 32767, n.setInt16(c, V, !0), c += 2;
|
|
1023
1033
|
}
|
|
1024
|
-
|
|
1034
|
+
A++;
|
|
1025
1035
|
}
|
|
1026
1036
|
return new Blob([o], { type: "audio/wav" });
|
|
1027
|
-
}, at = async (e, t,
|
|
1028
|
-
if (!
|
|
1029
|
-
if (
|
|
1030
|
-
|
|
1037
|
+
}, at = async (e, t, r = !1) => {
|
|
1038
|
+
if (!ke.current) {
|
|
1039
|
+
if (I.current) {
|
|
1040
|
+
P.current.push({
|
|
1031
1041
|
audio: e,
|
|
1032
1042
|
visemes: t,
|
|
1033
|
-
isNewSegment:
|
|
1043
|
+
isNewSegment: r
|
|
1034
1044
|
});
|
|
1035
1045
|
return;
|
|
1036
1046
|
}
|
|
1037
|
-
|
|
1047
|
+
I.current = !0;
|
|
1038
1048
|
try {
|
|
1039
|
-
const o = window.AudioContext || window.webkitAudioContext, n =
|
|
1040
|
-
n.state === "suspended" && await n.resume(),
|
|
1041
|
-
const c = window.atob(e),
|
|
1049
|
+
const o = window.AudioContext || window.webkitAudioContext, n = C.current ?? new o();
|
|
1050
|
+
n.state === "suspended" && await n.resume(), C.current = n;
|
|
1051
|
+
const c = window.atob(e), m = new Uint8Array(c.length);
|
|
1042
1052
|
for (let F = 0; F < c.length; F++)
|
|
1043
|
-
|
|
1044
|
-
const w = await n.decodeAudioData(
|
|
1045
|
-
|
|
1046
|
-
const
|
|
1047
|
-
let
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
let
|
|
1053
|
-
if ((!
|
|
1054
|
-
|
|
1053
|
+
m[F] = c.charCodeAt(F);
|
|
1054
|
+
const w = await n.decodeAudioData(m.buffer.slice(0));
|
|
1055
|
+
ye.current += w.duration;
|
|
1056
|
+
const k = n.currentTime;
|
|
1057
|
+
let A = ce.current;
|
|
1058
|
+
const T = !M.current;
|
|
1059
|
+
A < k && (A = k + 0.1), ce.current = A + w.duration;
|
|
1060
|
+
const V = n.createBufferSource();
|
|
1061
|
+
V.buffer = w;
|
|
1062
|
+
let G = kt;
|
|
1063
|
+
if ((!G || G.context !== n) && (G = n.createAnalyser(), G.fftSize = 64, G.connect(n.destination), Pt(G)), V.connect(G), we.current.push(V), ke.current) {
|
|
1064
|
+
we.current = we.current.filter((F) => F !== V);
|
|
1055
1065
|
return;
|
|
1056
1066
|
}
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
1059
|
-
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${
|
|
1067
|
+
if (T) {
|
|
1068
|
+
M.current = !0, me(!0), $(
|
|
1069
|
+
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${A.toFixed(
|
|
1060
1070
|
3
|
|
1061
1071
|
)}`
|
|
1062
|
-
),
|
|
1063
|
-
const F = (
|
|
1064
|
-
|
|
1065
|
-
`[AUDIO] Response started. Initial startTime: ${
|
|
1072
|
+
), ve.current = A;
|
|
1073
|
+
const F = (A - k) * 1e3;
|
|
1074
|
+
_e.current = performance.now() + F, $(
|
|
1075
|
+
`[AUDIO] Response started. Initial startTime: ${A.toFixed(
|
|
1066
1076
|
3
|
|
1067
|
-
)}, CT: ${
|
|
1077
|
+
)}, CT: ${k.toFixed(3)}`
|
|
1068
1078
|
);
|
|
1069
1079
|
}
|
|
1070
|
-
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
`[AUDIO] New segment detected at +${
|
|
1080
|
+
V.start(A);
|
|
1081
|
+
const ee = (A - ve.current) * 1e3;
|
|
1082
|
+
r && (Be.current = ee, $(
|
|
1083
|
+
`[AUDIO] New segment detected at +${ee.toFixed(
|
|
1074
1084
|
0
|
|
1075
1085
|
)}ms. Resetting segment offset.`
|
|
1076
1086
|
)), t.forEach((F, se) => {
|
|
1077
|
-
const
|
|
1078
|
-
if (
|
|
1079
|
-
const oe =
|
|
1080
|
-
se < 3 &&
|
|
1081
|
-
`[AUDIO] Viseme "${
|
|
1087
|
+
const O = F.symbol ?? "";
|
|
1088
|
+
if (O) {
|
|
1089
|
+
const oe = wn(O), de = Math.round(F.start * 1e3), Ee = Math.round((F.duration ?? 0) * 1e3), Lt = Be.current + de;
|
|
1090
|
+
se < 3 && $(
|
|
1091
|
+
`[AUDIO] Viseme "${O}": segment_relative=${de}ms, segment_offset=${Be.current.toFixed(
|
|
1082
1092
|
0
|
|
1083
1093
|
)}ms => vtime=${Lt}ms`
|
|
1084
|
-
), oe.forEach((
|
|
1094
|
+
), oe.forEach((Rt) => {
|
|
1085
1095
|
x.current.push({
|
|
1086
|
-
viseme:
|
|
1087
|
-
weight:
|
|
1096
|
+
viseme: Rt.v,
|
|
1097
|
+
weight: Rt.w,
|
|
1088
1098
|
vtime: Lt,
|
|
1089
1099
|
vduration: Ee
|
|
1090
1100
|
});
|
|
@@ -1092,78 +1102,78 @@ const Sn = ({
|
|
|
1092
1102
|
}
|
|
1093
1103
|
}), v("Speaking...");
|
|
1094
1104
|
} finally {
|
|
1095
|
-
if (
|
|
1096
|
-
const o =
|
|
1105
|
+
if (I.current = !1, P.current.length > 0) {
|
|
1106
|
+
const o = P.current.shift();
|
|
1097
1107
|
o && at(o.audio, o.visemes, o.isNewSegment);
|
|
1098
1108
|
}
|
|
1099
1109
|
}
|
|
1100
1110
|
}
|
|
1101
1111
|
}, Jt = async (e) => {
|
|
1102
1112
|
try {
|
|
1103
|
-
|
|
1113
|
+
R(!0), $e(!1), Ne.current = "", he(""), v("Processing Voice...");
|
|
1104
1114
|
const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = jt(o), c = new FileReader();
|
|
1105
1115
|
c.readAsDataURL(n), c.onloadend = async () => {
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1116
|
+
const m = c.result.split(",")[1];
|
|
1117
|
+
Ye(), K(""), pe.current = "", De.current = !1;
|
|
1108
1118
|
const w = `${ut}/stt?token=${encodeURIComponent(
|
|
1109
|
-
|
|
1110
|
-
)}`,
|
|
1119
|
+
D
|
|
1120
|
+
)}`, k = await fetch(w, {
|
|
1111
1121
|
method: "POST",
|
|
1112
1122
|
headers: { "Content-Type": "application/json" },
|
|
1113
1123
|
body: JSON.stringify({
|
|
1114
|
-
audio_base64:
|
|
1124
|
+
audio_base64: m,
|
|
1115
1125
|
audio_format: "wav"
|
|
1116
1126
|
})
|
|
1117
1127
|
});
|
|
1118
|
-
if (
|
|
1128
|
+
if (k.status === 429) {
|
|
1119
1129
|
try {
|
|
1120
|
-
const se = await
|
|
1121
|
-
|
|
1130
|
+
const se = await k.text(), O = JSON.parse(se);
|
|
1131
|
+
$("[STT] 429 agent at capacity:", O?.detail);
|
|
1122
1132
|
} catch {
|
|
1123
1133
|
}
|
|
1124
|
-
K(""), v("Busy"),
|
|
1134
|
+
K(""), v("Busy"), R(!1);
|
|
1125
1135
|
return;
|
|
1126
1136
|
}
|
|
1127
|
-
if (!
|
|
1128
|
-
const se = await
|
|
1129
|
-
let
|
|
1137
|
+
if (!k.ok) {
|
|
1138
|
+
const se = await k.text();
|
|
1139
|
+
let O = "STT Failed";
|
|
1130
1140
|
try {
|
|
1131
|
-
|
|
1141
|
+
O = JSON.parse(se).error || O;
|
|
1132
1142
|
} catch {
|
|
1133
|
-
se && (
|
|
1143
|
+
se && (O = se.slice(0, 200));
|
|
1134
1144
|
}
|
|
1135
|
-
throw new Error(
|
|
1145
|
+
throw new Error(O);
|
|
1136
1146
|
}
|
|
1137
|
-
const
|
|
1138
|
-
if (
|
|
1139
|
-
v("STT Failed"),
|
|
1147
|
+
const A = k.body;
|
|
1148
|
+
if ($("this is body" + A), !A) {
|
|
1149
|
+
v("STT Failed"), R(!1);
|
|
1140
1150
|
return;
|
|
1141
1151
|
}
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1144
|
-
const
|
|
1145
|
-
let
|
|
1146
|
-
const F = async (se,
|
|
1152
|
+
const T = A.getReader();
|
|
1153
|
+
ke.current = !1;
|
|
1154
|
+
const V = new TextDecoder();
|
|
1155
|
+
let G = "", ee = !1;
|
|
1156
|
+
const F = async (se, O) => {
|
|
1147
1157
|
switch (se) {
|
|
1148
1158
|
case "transcript":
|
|
1149
|
-
|
|
1159
|
+
O.transcript != null && K(String(O.transcript));
|
|
1150
1160
|
break;
|
|
1151
1161
|
case "text": {
|
|
1152
|
-
const oe =
|
|
1162
|
+
const oe = O.delta ?? O.text ?? "";
|
|
1153
1163
|
oe && vt(oe);
|
|
1154
1164
|
break;
|
|
1155
1165
|
}
|
|
1156
1166
|
case "audio": {
|
|
1157
|
-
const oe =
|
|
1158
|
-
oe && await at(oe,
|
|
1167
|
+
const oe = O.chunk, de = O.visemes ?? [], Ee = !!O.is_new_segment;
|
|
1168
|
+
oe && await at(oe, de, Ee);
|
|
1159
1169
|
break;
|
|
1160
1170
|
}
|
|
1161
1171
|
case "done": {
|
|
1162
|
-
|
|
1172
|
+
ee = !0, v("Ready"), R(!1);
|
|
1163
1173
|
break;
|
|
1164
1174
|
}
|
|
1165
1175
|
case "error": {
|
|
1166
|
-
|
|
1176
|
+
ee = !0, v("STT Failed"), R(!1);
|
|
1167
1177
|
break;
|
|
1168
1178
|
}
|
|
1169
1179
|
default:
|
|
@@ -1171,37 +1181,37 @@ const Sn = ({
|
|
|
1171
1181
|
}
|
|
1172
1182
|
};
|
|
1173
1183
|
for (; ; ) {
|
|
1174
|
-
const { done: se, value:
|
|
1175
|
-
|
|
1176
|
-
const oe =
|
|
1184
|
+
const { done: se, value: O } = await T.read();
|
|
1185
|
+
O && (G += V.decode(O, { stream: !0 }));
|
|
1186
|
+
const oe = G.split(`
|
|
1177
1187
|
|
|
1178
1188
|
`);
|
|
1179
|
-
|
|
1180
|
-
for (const
|
|
1181
|
-
const Ee =
|
|
1189
|
+
G = oe.pop() ?? "";
|
|
1190
|
+
for (const de of oe) {
|
|
1191
|
+
const Ee = Qe(de);
|
|
1182
1192
|
Ee && await F(Ee.event, Ee.data);
|
|
1183
1193
|
}
|
|
1184
1194
|
if (se) {
|
|
1185
|
-
if (
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1195
|
+
if (G.trim()) {
|
|
1196
|
+
const de = Qe(G.trim());
|
|
1197
|
+
de && await F(de.event, de.data);
|
|
1188
1198
|
}
|
|
1189
|
-
|
|
1199
|
+
ee || (v("Ready"), R(!1));
|
|
1190
1200
|
break;
|
|
1191
1201
|
}
|
|
1192
1202
|
}
|
|
1193
1203
|
};
|
|
1194
1204
|
} catch (t) {
|
|
1195
|
-
console.error("Audio Submission Error:", t), v("STT Failed"),
|
|
1205
|
+
console.error("Audio Submission Error:", t), v("STT Failed"), R(!1);
|
|
1196
1206
|
}
|
|
1197
1207
|
}, qt = async (e) => {
|
|
1198
|
-
e && e.preventDefault(),
|
|
1199
|
-
},
|
|
1208
|
+
e && e.preventDefault(), $e(!1), Ne.current = "", he(""), !(!fe || S) && await Gt(fe);
|
|
1209
|
+
}, Qe = (e) => {
|
|
1200
1210
|
const t = e.split(/\r?\n/);
|
|
1201
|
-
let
|
|
1211
|
+
let r = "", o = "";
|
|
1202
1212
|
for (const c of t)
|
|
1203
|
-
c.startsWith("event:") ?
|
|
1204
|
-
if (!
|
|
1213
|
+
c.startsWith("event:") ? r = c.slice(6).trim() : c.startsWith("data:") && (o = c.slice(5).trim());
|
|
1214
|
+
if (!r) return null;
|
|
1205
1215
|
let n = {};
|
|
1206
1216
|
if (o)
|
|
1207
1217
|
try {
|
|
@@ -1209,54 +1219,54 @@ const Sn = ({
|
|
|
1209
1219
|
} catch {
|
|
1210
1220
|
n = { raw: o };
|
|
1211
1221
|
}
|
|
1212
|
-
return { event:
|
|
1222
|
+
return { event: r, data: n };
|
|
1213
1223
|
}, At = (e, t) => {
|
|
1214
1224
|
switch (e) {
|
|
1215
1225
|
case "connected":
|
|
1216
|
-
pe.current = "",
|
|
1226
|
+
pe.current = "", De.current = !1;
|
|
1217
1227
|
break;
|
|
1218
1228
|
case "text": {
|
|
1219
|
-
const
|
|
1220
|
-
|
|
1229
|
+
const r = t.delta ?? "";
|
|
1230
|
+
r && vt(r);
|
|
1221
1231
|
break;
|
|
1222
1232
|
}
|
|
1223
1233
|
case "audio": {
|
|
1224
|
-
const
|
|
1225
|
-
|
|
1234
|
+
const r = t.chunk, o = t.visemes ?? [];
|
|
1235
|
+
r && at(r, o);
|
|
1226
1236
|
break;
|
|
1227
1237
|
}
|
|
1228
1238
|
case "done": {
|
|
1229
|
-
const
|
|
1230
|
-
...
|
|
1231
|
-
{ role: "user", content:
|
|
1239
|
+
const r = yt(), o = Ne.current.trim(), n = [
|
|
1240
|
+
...r,
|
|
1241
|
+
{ role: "user", content: fe || "..." },
|
|
1232
1242
|
{ role: "assistant", content: o }
|
|
1233
1243
|
];
|
|
1234
|
-
Bt(n),
|
|
1244
|
+
Bt(n), Me.current = [...x.current], v("Ready"), R(!1), K("");
|
|
1235
1245
|
break;
|
|
1236
1246
|
}
|
|
1237
1247
|
case "error": {
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1248
|
+
const r = t.message ?? "Unknown error";
|
|
1249
|
+
Ne.current = r, he(r), v("Agent Failed"), R(!1);
|
|
1240
1250
|
break;
|
|
1241
1251
|
}
|
|
1242
1252
|
}
|
|
1243
1253
|
}, Gt = async (e) => {
|
|
1244
|
-
|
|
1254
|
+
R(!0), v("Thinking..."), Ne.current = "", pe.current = "", De.current = !1, Ye(), ye.current = 0, u(0);
|
|
1245
1255
|
const t = `${ut}/agent/chat?token=${encodeURIComponent(
|
|
1246
|
-
|
|
1256
|
+
D
|
|
1247
1257
|
)}`;
|
|
1248
1258
|
try {
|
|
1249
|
-
const
|
|
1259
|
+
const r = yt();
|
|
1250
1260
|
let o = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
|
|
1251
1261
|
o || (rn(
|
|
1252
1262
|
"[CHAT] Session UID missing at send time! Generating emergency backup."
|
|
1253
1263
|
), o = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", o));
|
|
1254
1264
|
const n = {
|
|
1255
|
-
history:
|
|
1265
|
+
history: r,
|
|
1256
1266
|
question: e,
|
|
1257
1267
|
lead_id: o
|
|
1258
1268
|
};
|
|
1259
|
-
|
|
1269
|
+
$("[CHAT] Sending payload:", n);
|
|
1260
1270
|
const c = await fetch(t, {
|
|
1261
1271
|
method: "POST",
|
|
1262
1272
|
headers: {
|
|
@@ -1267,73 +1277,73 @@ const Sn = ({
|
|
|
1267
1277
|
});
|
|
1268
1278
|
if (c.status === 429) {
|
|
1269
1279
|
try {
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1280
|
+
const T = await c.json();
|
|
1281
|
+
$("[CHAT] 429 agent at capacity:", T?.detail);
|
|
1272
1282
|
} catch {
|
|
1273
1283
|
}
|
|
1274
|
-
K(""), v("Busy"),
|
|
1284
|
+
K(""), v("Busy"), R(!1);
|
|
1275
1285
|
return;
|
|
1276
1286
|
}
|
|
1277
1287
|
if (!c.ok)
|
|
1278
1288
|
throw new Error("Agent request failed");
|
|
1279
|
-
const
|
|
1280
|
-
if (!
|
|
1281
|
-
v("Agent Failed"),
|
|
1289
|
+
const m = c.body;
|
|
1290
|
+
if (!m) {
|
|
1291
|
+
v("Agent Failed"), R(!1);
|
|
1282
1292
|
return;
|
|
1283
1293
|
}
|
|
1284
|
-
const w =
|
|
1285
|
-
|
|
1286
|
-
const
|
|
1287
|
-
let
|
|
1294
|
+
const w = m.getReader();
|
|
1295
|
+
ke.current = !1;
|
|
1296
|
+
const k = new TextDecoder();
|
|
1297
|
+
let A = "";
|
|
1288
1298
|
for (; ; ) {
|
|
1289
|
-
const { done:
|
|
1290
|
-
|
|
1291
|
-
`[SSE] Chunk received. done=${
|
|
1292
|
-
),
|
|
1293
|
-
const
|
|
1299
|
+
const { done: T, value: V } = await w.read();
|
|
1300
|
+
$(
|
|
1301
|
+
`[SSE] Chunk received. done=${T}, length=${V?.length || 0}`
|
|
1302
|
+
), V && (A += k.decode(V, { stream: !0 }));
|
|
1303
|
+
const G = A.split(`
|
|
1294
1304
|
|
|
1295
1305
|
`);
|
|
1296
|
-
|
|
1297
|
-
for (const
|
|
1298
|
-
|
|
1299
|
-
const F =
|
|
1300
|
-
F && (
|
|
1306
|
+
A = G.pop() ?? "";
|
|
1307
|
+
for (const ee of G) {
|
|
1308
|
+
$(`[SSE] Processing block: ${ee.slice(0, 50)}...`);
|
|
1309
|
+
const F = Qe(ee);
|
|
1310
|
+
F && ($(`[SSE] Event: ${F.event}`), At(F.event, F.data));
|
|
1301
1311
|
}
|
|
1302
|
-
if (
|
|
1303
|
-
if (
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1312
|
+
if (T) {
|
|
1313
|
+
if ($("[SSE] Stream finished"), A.trim()) {
|
|
1314
|
+
const ee = Qe(A.trim());
|
|
1315
|
+
ee && At(ee.event, ee.data);
|
|
1306
1316
|
}
|
|
1307
|
-
v("Ready"),
|
|
1317
|
+
v("Ready"), R(!1), K("");
|
|
1308
1318
|
break;
|
|
1309
1319
|
}
|
|
1310
1320
|
}
|
|
1311
|
-
} catch (
|
|
1312
|
-
console.error("Chat Error:",
|
|
1321
|
+
} catch (r) {
|
|
1322
|
+
console.error("Chat Error:", r), v("Agent Failed"), R(!1);
|
|
1313
1323
|
}
|
|
1314
|
-
},
|
|
1324
|
+
}, Tt = N.trim(), ct = Tt && U ? Tt.slice(
|
|
1315
1325
|
0,
|
|
1316
1326
|
d != null && d > 0 ? d : 0
|
|
1317
1327
|
) : "";
|
|
1318
|
-
|
|
1328
|
+
H(() => {
|
|
1319
1329
|
const e = et.current;
|
|
1320
|
-
e !== "exiting" && (ct ? (Ot(ct), e === "hidden" &&
|
|
1321
|
-
}, [ct,
|
|
1322
|
-
const zt =
|
|
1330
|
+
e !== "exiting" && (ct ? (Ot(ct), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
|
|
1331
|
+
}, [ct, le]);
|
|
1332
|
+
const zt = Ke(() => {
|
|
1323
1333
|
const e = et.current;
|
|
1324
|
-
e === "entering" ?
|
|
1334
|
+
e === "entering" ? qe("visible") : e === "exiting" && qe("hidden");
|
|
1325
1335
|
}, []);
|
|
1326
1336
|
return en(() => {
|
|
1327
1337
|
const e = mt.current;
|
|
1328
1338
|
e && (e.scrollTop = e.scrollHeight);
|
|
1329
1339
|
}, [pt]), /* @__PURE__ */ ae("div", { className: "avatar-widget-container", children: [
|
|
1330
1340
|
/* @__PURE__ */ ae("div", { className: "avatar-input-area", children: [
|
|
1331
|
-
|
|
1341
|
+
re !== "hidden" ? /* @__PURE__ */ l(
|
|
1332
1342
|
"div",
|
|
1333
1343
|
{
|
|
1334
|
-
className: `avatar-thinking-tab${
|
|
1344
|
+
className: `avatar-thinking-tab${re === "exiting" ? " avatar-thinking-tab--exiting" : re === "entering" ? " avatar-thinking-tab--entering" : ""}`,
|
|
1335
1345
|
onAnimationEnd: Dt,
|
|
1336
|
-
children:
|
|
1346
|
+
children: Le === Mt ? /* @__PURE__ */ l(
|
|
1337
1347
|
"a",
|
|
1338
1348
|
{
|
|
1339
1349
|
href: "https://leads.streamoji.com",
|
|
@@ -1341,7 +1351,7 @@ const Sn = ({
|
|
|
1341
1351
|
rel: "noopener noreferrer",
|
|
1342
1352
|
children: "Made by Streamoji Leads"
|
|
1343
1353
|
}
|
|
1344
|
-
) :
|
|
1354
|
+
) : Le
|
|
1345
1355
|
}
|
|
1346
1356
|
) : null,
|
|
1347
1357
|
/* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
|
|
@@ -1459,12 +1469,12 @@ const Sn = ({
|
|
|
1459
1469
|
{
|
|
1460
1470
|
type: "button",
|
|
1461
1471
|
className: "avatar-speaking-stop",
|
|
1462
|
-
onClick: () =>
|
|
1472
|
+
onClick: () => Ye(!0),
|
|
1463
1473
|
title: "Stop",
|
|
1464
1474
|
children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
|
|
1465
1475
|
}
|
|
1466
1476
|
)
|
|
1467
|
-
] }) :
|
|
1477
|
+
] }) : S ? /* @__PURE__ */ l(
|
|
1468
1478
|
"div",
|
|
1469
1479
|
{
|
|
1470
1480
|
style: {
|
|
@@ -1492,15 +1502,15 @@ const Sn = ({
|
|
|
1492
1502
|
{
|
|
1493
1503
|
id: "avatar-text-input",
|
|
1494
1504
|
type: "text",
|
|
1495
|
-
value:
|
|
1505
|
+
value: fe,
|
|
1496
1506
|
onChange: (e) => K(e.target.value),
|
|
1497
|
-
placeholder:
|
|
1498
|
-
disabled:
|
|
1507
|
+
placeholder: E === "Busy" ? "Assisting another user" : Ue || "Ask me anything",
|
|
1508
|
+
disabled: S || E === "Busy",
|
|
1499
1509
|
autoComplete: "off",
|
|
1500
1510
|
style: { width: "100%", height: "100%" }
|
|
1501
1511
|
}
|
|
1502
1512
|
),
|
|
1503
|
-
|
|
1513
|
+
E === "Busy" ? /* @__PURE__ */ l(
|
|
1504
1514
|
"button",
|
|
1505
1515
|
{
|
|
1506
1516
|
type: "button",
|
|
@@ -1527,13 +1537,13 @@ const Sn = ({
|
|
|
1527
1537
|
}
|
|
1528
1538
|
)
|
|
1529
1539
|
}
|
|
1530
|
-
) :
|
|
1540
|
+
) : fe.trim() === "" ? /* @__PURE__ */ l(
|
|
1531
1541
|
"button",
|
|
1532
1542
|
{
|
|
1533
1543
|
type: "button",
|
|
1534
1544
|
className: "mic-button",
|
|
1535
1545
|
onClick: Vt,
|
|
1536
|
-
disabled:
|
|
1546
|
+
disabled: S,
|
|
1537
1547
|
style: { backgroundColor: "#1e4a5e" },
|
|
1538
1548
|
children: /* @__PURE__ */ ae(
|
|
1539
1549
|
"svg",
|
|
@@ -1567,7 +1577,7 @@ const Sn = ({
|
|
|
1567
1577
|
{
|
|
1568
1578
|
type: "submit",
|
|
1569
1579
|
className: "mic-button",
|
|
1570
|
-
disabled:
|
|
1580
|
+
disabled: S,
|
|
1571
1581
|
style: { backgroundColor: "#1e4a5e" },
|
|
1572
1582
|
title: "Send",
|
|
1573
1583
|
children: /* @__PURE__ */ l(
|
|
@@ -1599,10 +1609,10 @@ const Sn = ({
|
|
|
1599
1609
|
) })
|
|
1600
1610
|
] }),
|
|
1601
1611
|
/* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ ae("div", { className: "avatar-scene-wrapper", children: [
|
|
1602
|
-
|
|
1612
|
+
le !== "hidden" && /* @__PURE__ */ l(
|
|
1603
1613
|
"div",
|
|
1604
1614
|
{
|
|
1605
|
-
className: `avatar-bubble${
|
|
1615
|
+
className: `avatar-bubble${le === "entering" ? " avatar-bubble--entering" : le === "exiting" ? " avatar-bubble--exiting" : ""}`,
|
|
1606
1616
|
onAnimationEnd: zt,
|
|
1607
1617
|
children: /* @__PURE__ */ l("div", { ref: mt, className: `avatar-bubble__content${nt ? " avatar-bubble__content--nudge" : ""}`, children: pt })
|
|
1608
1618
|
}
|
|
@@ -1611,7 +1621,7 @@ const Sn = ({
|
|
|
1611
1621
|
"div",
|
|
1612
1622
|
{
|
|
1613
1623
|
className: "avatar-canvas-layer",
|
|
1614
|
-
style: { width:
|
|
1624
|
+
style: { width: z, height: z },
|
|
1615
1625
|
children: /* @__PURE__ */ ae(
|
|
1616
1626
|
Kt,
|
|
1617
1627
|
{
|
|
@@ -1621,27 +1631,27 @@ const Sn = ({
|
|
|
1621
1631
|
dpr: 1.8,
|
|
1622
1632
|
style: { pointerEvents: "none", width: "100%", height: "100%" },
|
|
1623
1633
|
children: [
|
|
1624
|
-
/* @__PURE__ */ l(
|
|
1634
|
+
/* @__PURE__ */ l(vn, { target: mn }),
|
|
1625
1635
|
/* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
|
|
1626
1636
|
/* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
|
|
1627
1637
|
/* @__PURE__ */ l(Yt, { preset: "city" }),
|
|
1628
|
-
/* @__PURE__ */ l(tn, { fallback: null, children:
|
|
1629
|
-
|
|
1638
|
+
/* @__PURE__ */ l(tn, { fallback: null, children: j !== null && /* @__PURE__ */ l(
|
|
1639
|
+
yn,
|
|
1630
1640
|
{
|
|
1631
|
-
avatarUrl:
|
|
1632
|
-
isPlayingRef:
|
|
1641
|
+
avatarUrl: j,
|
|
1642
|
+
isPlayingRef: M,
|
|
1633
1643
|
visemeQueueRef: x,
|
|
1634
|
-
audioContextRef:
|
|
1635
|
-
responseAudioStartTimeRef:
|
|
1636
|
-
adjustments:
|
|
1637
|
-
mood:
|
|
1638
|
-
expression:
|
|
1639
|
-
agentResponse:
|
|
1644
|
+
audioContextRef: C,
|
|
1645
|
+
responseAudioStartTimeRef: ve,
|
|
1646
|
+
adjustments: hn,
|
|
1647
|
+
mood: s,
|
|
1648
|
+
expression: W,
|
|
1649
|
+
agentResponse: N,
|
|
1640
1650
|
isSpeaking: U,
|
|
1641
|
-
nextStartTimeRef:
|
|
1642
|
-
stopPlayback:
|
|
1643
|
-
setIsSpeaking:
|
|
1644
|
-
expressionUrl:
|
|
1651
|
+
nextStartTimeRef: ce,
|
|
1652
|
+
stopPlayback: Ye,
|
|
1653
|
+
setIsSpeaking: me,
|
|
1654
|
+
expressionUrl: Ze,
|
|
1645
1655
|
onExpressionFinished: Ut,
|
|
1646
1656
|
isNudgeResponse: nt,
|
|
1647
1657
|
avatarGender: p
|
|
@@ -1654,20 +1664,20 @@ const Sn = ({
|
|
|
1654
1664
|
)
|
|
1655
1665
|
] }) })
|
|
1656
1666
|
] });
|
|
1657
|
-
},
|
|
1667
|
+
}, En = ({
|
|
1658
1668
|
token: f,
|
|
1659
|
-
avatarGender:
|
|
1669
|
+
avatarGender: L,
|
|
1660
1670
|
onNavigationRequested: b,
|
|
1661
1671
|
presetUserDetails: p
|
|
1662
1672
|
}) => /* @__PURE__ */ l(
|
|
1663
|
-
|
|
1673
|
+
xn,
|
|
1664
1674
|
{
|
|
1665
1675
|
token: f,
|
|
1666
1676
|
onNavigationRequested: b,
|
|
1667
|
-
avatarGender:
|
|
1677
|
+
avatarGender: L,
|
|
1668
1678
|
presetUserDetails: p
|
|
1669
1679
|
}
|
|
1670
1680
|
);
|
|
1671
1681
|
export {
|
|
1672
|
-
|
|
1682
|
+
En as AvatarWidget
|
|
1673
1683
|
};
|