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