@streamoji/avatar-widget 0.5.5 → 0.5.6
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 +230 -230
- package/dist/avatar-widget.umd.js +16 -16
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { jsx as h, jsxs as
|
|
1
|
+
import { jsx as h, jsxs as we } from "react/jsx-runtime";
|
|
2
2
|
import { useGLTF as Dt, Environment as Sn } from "@react-three/drei";
|
|
3
3
|
import { useFrame as kn, Canvas as Rn, useThree as xn } from "@react-three/fiber";
|
|
4
|
-
import { memo as Tn, useMemo as Pt, useRef as a, useState as
|
|
4
|
+
import { memo as Tn, useMemo as Pt, useRef as a, useState as R, useEffect as B, useCallback as at, useLayoutEffect as Mn, Suspense as An } from "react";
|
|
5
5
|
import * as gt from "three";
|
|
6
6
|
import { GLTFLoader as En } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
7
|
const ct = "https://ai.streamoji.com", N = (...u) => {
|
|
8
8
|
}, In = (...u) => {
|
|
9
9
|
}, Qt = ({ analyser: u }) => {
|
|
10
|
-
const
|
|
10
|
+
const _ = a(null), S = a(null);
|
|
11
11
|
return B(() => {
|
|
12
|
-
const y =
|
|
12
|
+
const y = _.current;
|
|
13
13
|
if (!y) return;
|
|
14
14
|
const j = y.getContext("2d", { alpha: !0 });
|
|
15
15
|
if (!j) return;
|
|
@@ -25,7 +25,7 @@ const ct = "https://ai.streamoji.com", N = (...u) => {
|
|
|
25
25
|
(!S.current || S.current.length !== q) && (S.current = new Float32Array(q).fill(2));
|
|
26
26
|
const ae = q * G, O = (We - ae) / 2;
|
|
27
27
|
u && ee && u.getByteFrequencyData(ee);
|
|
28
|
-
const
|
|
28
|
+
const _e = ee ? ee.length : 0, g = Math.floor(_e * 0.7) / q, ce = new Float32Array(q);
|
|
29
29
|
for (let m = 0; m < q; m++) {
|
|
30
30
|
let D = 0;
|
|
31
31
|
if (ee && g > 0) {
|
|
@@ -52,13 +52,13 @@ const ct = "https://ai.streamoji.com", N = (...u) => {
|
|
|
52
52
|
}, [u]), /* @__PURE__ */ h(
|
|
53
53
|
"canvas",
|
|
54
54
|
{
|
|
55
|
-
ref:
|
|
55
|
+
ref: _,
|
|
56
56
|
style: { width: "100%", height: "100%", display: "block" }
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
59
|
}, On = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Xt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
|
|
60
60
|
function Dn(u) {
|
|
61
|
-
const [
|
|
61
|
+
const [_, S] = R(null);
|
|
62
62
|
return B(() => {
|
|
63
63
|
if (!u) {
|
|
64
64
|
S(null);
|
|
@@ -73,7 +73,7 @@ function Dn(u) {
|
|
|
73
73
|
}), () => {
|
|
74
74
|
y = !0;
|
|
75
75
|
};
|
|
76
|
-
}, [u]),
|
|
76
|
+
}, [u]), _;
|
|
77
77
|
}
|
|
78
78
|
const Cn = [
|
|
79
79
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
|
|
@@ -557,37 +557,37 @@ const Cn = [
|
|
|
557
557
|
])
|
|
558
558
|
);
|
|
559
559
|
function an(u) {
|
|
560
|
-
const
|
|
561
|
-
return
|
|
560
|
+
const _ = Math.max(0, Math.min(1, u));
|
|
561
|
+
return _ * _ * (3 - 2 * _);
|
|
562
562
|
}
|
|
563
|
-
function qn(u,
|
|
563
|
+
function qn(u, _, S) {
|
|
564
564
|
if (S <= 0) return 0;
|
|
565
|
-
const y = (u -
|
|
565
|
+
const y = (u - _) / S;
|
|
566
566
|
return y < 0 || y > 1 ? 0 : y < 0.25 ? an(y / 0.25) : y > 0.75 ? an((1 - y) / 0.25) : 1;
|
|
567
567
|
}
|
|
568
568
|
function zn(u) {
|
|
569
569
|
if (!u) return [{ v: "sil", w: 1 }];
|
|
570
|
-
const
|
|
571
|
-
return Jn[
|
|
570
|
+
const _ = u.toLowerCase();
|
|
571
|
+
return Jn[_] ?? [{ v: "sil", w: 1 }];
|
|
572
572
|
}
|
|
573
573
|
function Yn({ target: u }) {
|
|
574
|
-
const { camera:
|
|
574
|
+
const { camera: _ } = xn();
|
|
575
575
|
return B(() => {
|
|
576
|
-
|
|
577
|
-
}, [
|
|
576
|
+
_.lookAt(...u);
|
|
577
|
+
}, [_, u]), null;
|
|
578
578
|
}
|
|
579
|
-
function c(u,
|
|
579
|
+
function c(u, _, S) {
|
|
580
580
|
if (!u || !u.morphTargetDictionary)
|
|
581
581
|
return;
|
|
582
582
|
const y = u, j = y.morphTargetDictionary, Q = y.morphTargetInfluences;
|
|
583
583
|
if (Q)
|
|
584
584
|
for (const ee in j)
|
|
585
|
-
ee.toLowerCase() ===
|
|
585
|
+
ee.toLowerCase() === _.toLowerCase() && (Q[j[ee]] = S);
|
|
586
586
|
}
|
|
587
587
|
const Kn = Tn(
|
|
588
588
|
({
|
|
589
589
|
avatarUrl: u,
|
|
590
|
-
isPlayingRef:
|
|
590
|
+
isPlayingRef: _,
|
|
591
591
|
visemeQueueRef: S,
|
|
592
592
|
audioContextRef: y,
|
|
593
593
|
responseAudioStartTimeRef: j,
|
|
@@ -610,7 +610,7 @@ const Kn = Tn(
|
|
|
610
610
|
), m = Dt(ae === "female" ? Pn : Fn), D = Pt(
|
|
611
611
|
() => m.flatMap((b) => b.animations),
|
|
612
612
|
[m]
|
|
613
|
-
), z = a(null), A = a(null), F = a(null), $ = a(null), Y = a(null), X = a(null), kt = a([]), [te] =
|
|
613
|
+
), z = a(null), A = a(null), F = a(null), $ = a(null), Y = a(null), X = a(null), kt = a([]), [te] = R(() => new gt.AnimationMixer(O)), J = a({}), V = a(null), Ee = a(0), tt = a(!1), He = a(0), Ie = a(!1), ye = a(null), Oe = a(Zt), bt = a(-1), De = a("left"), je = a(Lt + Math.random() * (nn - Lt)), he = a(0), Ce = a("smile"), Ne = a({});
|
|
614
614
|
B(() => {
|
|
615
615
|
if (!(!g || !O)) {
|
|
616
616
|
if (g.forEach((b, p) => {
|
|
@@ -643,8 +643,8 @@ const Kn = Tn(
|
|
|
643
643
|
if (p.animations && p.animations.length > 0) {
|
|
644
644
|
const o = p.animations[0], l = te.clipAction(o, O);
|
|
645
645
|
if (l.name = `EXPR_${G}`, l.setLoop(gt.LoopOnce, 1), l.clampWhenFinished = !0, J.current[`EXPR_${G}`] = l, U && ye.current === G) {
|
|
646
|
-
const
|
|
647
|
-
l.reset().fadeIn(0.3).play(),
|
|
646
|
+
const v = V.current;
|
|
647
|
+
l.reset().fadeIn(0.3).play(), v && v !== l && v.crossFadeTo(l, 0.3, !0), V.current = l, ye.current = null;
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
},
|
|
@@ -661,13 +661,13 @@ const Kn = Tn(
|
|
|
661
661
|
re && (re.reset().fadeIn(0.5).play(), o.crossFadeTo(re, 0.5, !0), V.current = re);
|
|
662
662
|
} else if (l.startsWith("EXPR_")) {
|
|
663
663
|
if (U) {
|
|
664
|
-
const
|
|
664
|
+
const v = Math.floor(
|
|
665
665
|
Math.random() * D.length
|
|
666
|
-
), ne = J.current[`talk_${
|
|
666
|
+
), ne = J.current[`talk_${v}`];
|
|
667
667
|
ne && (ne.reset().fadeIn(0.5).play(), o.crossFadeTo(ne, 0.5, !0), V.current = ne);
|
|
668
668
|
} else {
|
|
669
|
-
const
|
|
670
|
-
|
|
669
|
+
const v = J.current.idle_0;
|
|
670
|
+
v && (v.reset().fadeIn(0.5).play(), o.crossFadeTo(v, 0.5, !0), V.current = v);
|
|
671
671
|
}
|
|
672
672
|
Ae && Ae();
|
|
673
673
|
} else if (l.startsWith("talk_"))
|
|
@@ -675,8 +675,8 @@ const Kn = Tn(
|
|
|
675
675
|
const ne = (parseInt(l.split("_")[1]) + 1) % D.length, re = J.current[`talk_${ne}`];
|
|
676
676
|
re && (re.reset().fadeIn(0.3).play(), o.crossFadeTo(re, 0.3, !0), V.current = re);
|
|
677
677
|
} else {
|
|
678
|
-
const
|
|
679
|
-
|
|
678
|
+
const v = J.current.idle_0;
|
|
679
|
+
v && (v.reset().fadeIn(0.5).play(), o.crossFadeTo(v, 0.5, !0), V.current = v);
|
|
680
680
|
}
|
|
681
681
|
};
|
|
682
682
|
return te.addEventListener("finished", b), () => te.removeEventListener("finished", b);
|
|
@@ -702,8 +702,8 @@ const Kn = Tn(
|
|
|
702
702
|
if (p.startsWith("idle_") || p === "") {
|
|
703
703
|
const l = Math.floor(
|
|
704
704
|
Math.random() * D.length
|
|
705
|
-
),
|
|
706
|
-
|
|
705
|
+
), v = J.current[`talk_${l}`];
|
|
706
|
+
v && (v.reset().fadeIn(0.5).play(), b && b.crossFadeTo(v, 0.5, !0), V.current = v);
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
709
|
} else if (!U && O) {
|
|
@@ -728,8 +728,8 @@ const Kn = Tn(
|
|
|
728
728
|
const p = [];
|
|
729
729
|
O.traverse((o) => {
|
|
730
730
|
if (o.isMesh) {
|
|
731
|
-
const
|
|
732
|
-
|
|
731
|
+
const v = o.morphTargetDictionary;
|
|
732
|
+
v && Object.keys(v).some((ne) => ne.toLowerCase().includes("brow")) && p.push(o);
|
|
733
733
|
}
|
|
734
734
|
}), kt.current = p, p.length > 0 && N("[ANIMATION] Meshes with brow morphs:", p.length);
|
|
735
735
|
}, [O]);
|
|
@@ -743,95 +743,95 @@ const Kn = Tn(
|
|
|
743
743
|
const o = b.clock.elapsedTime;
|
|
744
744
|
let l = 0;
|
|
745
745
|
if (Math.floor(o) % 5 === 0 && Math.floor((o - p) % 5) !== 0) {
|
|
746
|
-
let
|
|
747
|
-
O.traverse((
|
|
748
|
-
|
|
746
|
+
let f = null;
|
|
747
|
+
O.traverse((M) => {
|
|
748
|
+
M.name.toLowerCase().includes("hips") && (f = M);
|
|
749
749
|
});
|
|
750
|
-
const I =
|
|
750
|
+
const I = f ? `Hips Y: ${f.position.y.toFixed(4)}` : "Hips not found";
|
|
751
751
|
N(`[ANIMATION] Mixer Time: ${te.time.toFixed(2)}, ${I}`);
|
|
752
752
|
}
|
|
753
753
|
if (te.update(p), o > Ee.current && !tt.current && (tt.current = !0, He.current = o), tt.current) {
|
|
754
|
-
const
|
|
754
|
+
const f = U ? 0.2 : 0.3, I = (o - He.current) / f;
|
|
755
755
|
if (I >= 1)
|
|
756
756
|
if (tt.current = !1, Ie.current) {
|
|
757
|
-
const
|
|
758
|
-
Ee.current = o +
|
|
757
|
+
const M = U ? 1 : 2.5;
|
|
758
|
+
Ee.current = o + M, Ie.current = !1;
|
|
759
759
|
} else
|
|
760
760
|
Ee.current = o + 0.12, Ie.current = !0;
|
|
761
761
|
else {
|
|
762
|
-
const
|
|
763
|
-
c(A.current, "eyeBlinkLeft",
|
|
762
|
+
const M = I < 0.5 ? I * 2 : (1 - I) * 2;
|
|
763
|
+
c(A.current, "eyeBlinkLeft", M), c(A.current, "eyeBlinkRight", M), c(F.current, "eyeBlinkLeft", M), c(F.current, "eyeBlinkRight", M), c($.current, "eyeBlinkLeft", M), c($.current, "eyeBlinkRight", M), l = M * Wn.browInnerUp;
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
|
-
const
|
|
766
|
+
const v = St[ee] ?? St.neutral, ne = v.browInnerUp ?? 0, re = v.browOuterUpLeft ?? 0, ue = v.browOuterUpRight ?? 0, rt = o * Hn, Ue = Ct * Math.sin(rt), Ge = Ct * 0.7 * Math.sin(rt + 0.7), ot = Ct * 0.7 * Math.sin(rt + 1.3), T = (f) => Math.max(0, Math.min(1, f)), dt = T(ne + Ue), Je = T(re + Ge), qe = T(ue + ot), ze = T(dt + l);
|
|
767
767
|
c(A.current, "browInnerUp", ze), c(F.current, "browInnerUp", ze), c($.current, "browInnerUp", ze), c(A.current, "browOuterUpLeft", Je), c(F.current, "browOuterUpLeft", Je), c($.current, "browOuterUpLeft", Je), c(A.current, "browOuterUpRight", qe), c(F.current, "browOuterUpRight", qe), c($.current, "browOuterUpRight", qe);
|
|
768
768
|
const Re = Oe.current, oe = Re + vt, Fe = oe + Nt;
|
|
769
769
|
o > Fe && (Oe.current += vt + Nt + Zt);
|
|
770
770
|
const Ye = !U && o >= Re && o < oe, Pe = !U && o >= oe && o < Fe;
|
|
771
771
|
(Ye || Pe) && bt.current !== Re && (bt.current = Re, De.current = Math.random() < 0.7 ? "left" : "up");
|
|
772
|
-
const le = Ye ? o - Re : Pe ? vt : 0, Ke = Ye || Pe ? Math.min(1, le / vt) : 0, ft = Ke <= 0 ? 0 : Math.sin(Ke * Math.PI), Rt = Pe ? 1 - (o - oe) / Nt : 1, ht = Ye ? ft : Pe ? ft * Rt : 0, K = jn * ht, E = (
|
|
773
|
-
if (De.current === "up" ? (c(Y.current, "eyeLookUpLeft",
|
|
772
|
+
const le = Ye ? o - Re : Pe ? vt : 0, Ke = Ye || Pe ? Math.min(1, le / vt) : 0, ft = Ke <= 0 ? 0 : Math.sin(Ke * Math.PI), Rt = Pe ? 1 - (o - oe) / Nt : 1, ht = Ye ? ft : Pe ? ft * Rt : 0, K = jn * ht, E = (f) => v[f] ?? 0;
|
|
773
|
+
if (De.current === "up" ? (c(Y.current, "eyeLookUpLeft", T(E("eyeLookUpLeft") + K)), c(Y.current, "eyeLookDownLeft", T(E("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", T(E("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", T(E("eyeLookInLeft"))), c(X.current, "eyeLookUpRight", T(E("eyeLookUpRight") + K)), c(X.current, "eyeLookDownRight", T(E("eyeLookDownRight"))), c(X.current, "eyeLookOutRight", T(E("eyeLookOutRight"))), c(X.current, "eyeLookInRight", T(E("eyeLookInRight")))) : (c(Y.current, "eyeLookUpLeft", T(E("eyeLookUpLeft"))), c(Y.current, "eyeLookDownLeft", T(E("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", T(E("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", T(E("eyeLookInLeft") + K)), c(X.current, "eyeLookUpRight", T(E("eyeLookUpRight"))), c(X.current, "eyeLookDownRight", T(E("eyeLookDownRight"))), c(X.current, "eyeLookOutRight", T(E("eyeLookOutRight") + K)), c(X.current, "eyeLookInRight", T(E("eyeLookInRight")))), !U && o >= je.current) {
|
|
774
774
|
he.current = o, Ce.current = Math.random() < 0.5 ? "pucker" : "smile";
|
|
775
|
-
const
|
|
776
|
-
je.current = o +
|
|
775
|
+
const f = Ce.current === "pucker" ? tn : en;
|
|
776
|
+
je.current = o + f + Lt + Math.random() * (nn - Lt);
|
|
777
777
|
}
|
|
778
778
|
const de = Ce.current === "pucker" ? tn : en, mt = !U && o >= he.current && o < he.current + de, Be = mt ? (o - he.current) / de : 0, me = Be <= 0 ? 0 : Be < 0.5 ? Be * 2 : (() => {
|
|
779
|
-
const
|
|
780
|
-
return 1 -
|
|
781
|
-
})(), xe = (
|
|
779
|
+
const f = (Be - 0.5) * 2;
|
|
780
|
+
return 1 - f * f * (3 - 2 * f);
|
|
781
|
+
})(), xe = (f) => v[f] ?? 0;
|
|
782
782
|
if (mt)
|
|
783
783
|
if (Ce.current === "pucker") {
|
|
784
|
-
const
|
|
785
|
-
c(A.current, "mouthPucker",
|
|
784
|
+
const f = T(xe("mouthPucker") + Gn * me);
|
|
785
|
+
c(A.current, "mouthPucker", f), c(F.current, "mouthPucker", f), c($.current, "mouthPucker", f);
|
|
786
786
|
} else {
|
|
787
|
-
const
|
|
788
|
-
c(A.current, "mouthSmileLeft",
|
|
787
|
+
const f = T(xe("mouthSmileLeft") + rn * me), I = T(xe("mouthSmileRight") + rn * me), M = T(xe("mouthDimpleLeft") + on * me), ve = T(xe("mouthDimpleRight") + on * me);
|
|
788
|
+
c(A.current, "mouthSmileLeft", f), c(A.current, "mouthSmileRight", I), c(A.current, "mouthDimpleLeft", M), c(A.current, "mouthDimpleRight", ve), c(F.current, "mouthSmileLeft", f), c(F.current, "mouthSmileRight", I), c(F.current, "mouthDimpleLeft", M), c(F.current, "mouthDimpleRight", ve), c($.current, "mouthSmileLeft", f), c($.current, "mouthSmileRight", I), c($.current, "mouthDimpleLeft", M), c($.current, "mouthDimpleRight", ve);
|
|
789
789
|
}
|
|
790
790
|
if (z.current) {
|
|
791
|
-
const
|
|
791
|
+
const f = _.current ? 0 : Q.rotation[1];
|
|
792
792
|
z.current.rotation.y = gt.MathUtils.lerp(
|
|
793
793
|
z.current.rotation.y,
|
|
794
|
-
|
|
794
|
+
f,
|
|
795
795
|
0.1
|
|
796
796
|
), z.current.position.set(...Q.position), z.current.scale.setScalar(Q.scale), z.current.rotation.x = Q.rotation[0], z.current.rotation.z = Q.rotation[2];
|
|
797
797
|
}
|
|
798
798
|
const fe = {};
|
|
799
|
-
if (Ut.forEach((
|
|
800
|
-
fe[
|
|
801
|
-
}),
|
|
802
|
-
const
|
|
799
|
+
if (Ut.forEach((f) => {
|
|
800
|
+
fe[f] = 0;
|
|
801
|
+
}), _.current && y.current) {
|
|
802
|
+
const f = y.current.currentTime, ve = (f - j.current) * 1e3 - -150;
|
|
803
803
|
for (let $e = 0; $e < S.current.length; $e++) {
|
|
804
804
|
const Te = S.current[$e];
|
|
805
805
|
if (ve < Te.vtime || ve >= Te.vtime + Te.vduration)
|
|
806
806
|
continue;
|
|
807
|
-
const
|
|
807
|
+
const wt = qn(
|
|
808
808
|
ve,
|
|
809
809
|
Te.vtime,
|
|
810
810
|
Te.vduration
|
|
811
811
|
), xt = `viseme_${Te.viseme}`.toLowerCase(), Ve = un.find((ie) => ie.key.toLowerCase() === xt);
|
|
812
812
|
if (!Ve) continue;
|
|
813
|
-
const pe = (Te.weight ?? 1) *
|
|
813
|
+
const pe = (Te.weight ?? 1) * wt;
|
|
814
814
|
for (const ie in Ve.mix)
|
|
815
815
|
fe[ie] = (fe[ie] ?? 0) + Ve.mix[ie] * pe;
|
|
816
816
|
if (Ve.teethMix)
|
|
817
817
|
for (const ie in Ve.teethMix)
|
|
818
818
|
fe[ie] = (fe[ie] ?? 0) + Ve.teethMix[ie] * pe;
|
|
819
819
|
}
|
|
820
|
-
|
|
820
|
+
f > ut.current + 0.5 && (ke(), et(!1));
|
|
821
821
|
}
|
|
822
822
|
const it = Ne.current;
|
|
823
|
-
Ut.forEach((
|
|
824
|
-
const I = fe[
|
|
825
|
-
it[
|
|
823
|
+
Ut.forEach((f) => {
|
|
824
|
+
const I = fe[f] ?? 0, M = it[f] ?? 0;
|
|
825
|
+
it[f] = Math.max(
|
|
826
826
|
0,
|
|
827
827
|
Math.min(
|
|
828
828
|
1,
|
|
829
|
-
|
|
829
|
+
M + (I - M) * (1 - Math.exp(-12 * p))
|
|
830
830
|
)
|
|
831
831
|
);
|
|
832
|
-
}), Ut.forEach((
|
|
833
|
-
const I = it[
|
|
834
|
-
c(A.current,
|
|
832
|
+
}), Ut.forEach((f) => {
|
|
833
|
+
const I = it[f] ?? 0;
|
|
834
|
+
c(A.current, f, I), c($.current, f, I), c(F.current, f, I);
|
|
835
835
|
});
|
|
836
836
|
}), /* @__PURE__ */ h("group", { ref: z, children: /* @__PURE__ */ h("primitive", { object: O }) });
|
|
837
837
|
}
|
|
@@ -844,21 +844,21 @@ function cn(u) {
|
|
|
844
844
|
}
|
|
845
845
|
const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
846
846
|
onNavigationRequested: u,
|
|
847
|
-
agentId:
|
|
847
|
+
agentId: _,
|
|
848
848
|
presetUserDetails: S,
|
|
849
849
|
onAvatarReady: y
|
|
850
850
|
}) => {
|
|
851
|
-
const [j, Q] =
|
|
851
|
+
const [j, Q] = R(""), [ee, Ze] = R("male"), [We, U] = R(""), [ut, ke] = R(!1), et = j, G = ee;
|
|
852
852
|
B(() => {
|
|
853
|
-
if (!
|
|
853
|
+
if (!_) {
|
|
854
854
|
ke(!0);
|
|
855
855
|
return;
|
|
856
856
|
}
|
|
857
857
|
let e = !1;
|
|
858
858
|
return (async () => {
|
|
859
|
-
console.log(">> fetchConfig RUNNING for",
|
|
859
|
+
console.log(">> fetchConfig RUNNING for", _);
|
|
860
860
|
try {
|
|
861
|
-
const r = `agent_config_${
|
|
861
|
+
const r = `agent_config_${_}`, i = sessionStorage.getItem(r);
|
|
862
862
|
if (i)
|
|
863
863
|
try {
|
|
864
864
|
const s = JSON.parse(i);
|
|
@@ -868,21 +868,21 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
868
868
|
console.error("Failed to parse cached avatar config:", s), sessionStorage.removeItem(r);
|
|
869
869
|
}
|
|
870
870
|
let n;
|
|
871
|
-
if (Ft.has(
|
|
872
|
-
console.log(">> REUSING in-flight fetch for",
|
|
871
|
+
if (Ft.has(_))
|
|
872
|
+
console.log(">> REUSING in-flight fetch for", _), n = await Ft.get(_);
|
|
873
873
|
else {
|
|
874
874
|
const s = (async () => {
|
|
875
|
-
console.log(">> INITIATING visitedWebsite fetch for",
|
|
876
|
-
const
|
|
875
|
+
console.log(">> INITIATING visitedWebsite fetch for", _);
|
|
876
|
+
const d = { agentId: _ }, w = await fetch(`${ct}/visitedWebsite`, {
|
|
877
877
|
method: "POST",
|
|
878
878
|
headers: { "Content-Type": "application/json" },
|
|
879
|
-
body: JSON.stringify(
|
|
879
|
+
body: JSON.stringify(d)
|
|
880
880
|
});
|
|
881
|
-
if (!
|
|
882
|
-
const
|
|
883
|
-
return sessionStorage.setItem(r, JSON.stringify(
|
|
881
|
+
if (!w.ok) throw new Error(`Fetch failed: ${w.status}`);
|
|
882
|
+
const L = await w.json();
|
|
883
|
+
return sessionStorage.setItem(r, JSON.stringify(L)), L;
|
|
884
884
|
})();
|
|
885
|
-
Ft.set(
|
|
885
|
+
Ft.set(_, s), n = await s;
|
|
886
886
|
}
|
|
887
887
|
if (e) return;
|
|
888
888
|
n && (n.encryptedAgentToken && Q(n.encryptedAgentToken), n.avatarGender && Ze(n.avatarGender), n.agent_id && U(n.agent_id));
|
|
@@ -894,8 +894,8 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
894
894
|
})(), () => {
|
|
895
895
|
e = !0;
|
|
896
896
|
};
|
|
897
|
-
}, [
|
|
898
|
-
const Ae = Dn(
|
|
897
|
+
}, [_]);
|
|
898
|
+
const Ae = Dn(_ ?? We), [q, ae] = R(""), [O, _e] = R(""), [H, g] = R("Ready"), [ce, m] = R(!1), [D, z] = R(!1), [A, F] = R([]), [$, Y] = R(""), X = a(null), [kt, te] = R(
|
|
899
899
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
900
900
|
);
|
|
901
901
|
B(() => {
|
|
@@ -904,9 +904,9 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
904
904
|
}, []);
|
|
905
905
|
const J = kt ? 80 : 600, V = a(!1), Ee = a([]), tt = a(0), He = a(!1), Ie = a([]), ye = a(null), Oe = a([]);
|
|
906
906
|
a([]);
|
|
907
|
-
const bt = a([]), De = a(0), je = a(0), he = a(0), Ce = a(0), Ne = a(!1), [nt, lt] =
|
|
907
|
+
const bt = a([]), De = a(0), je = a(0), he = a(0), Ce = a(0), Ne = a(!1), [nt, lt] = R(
|
|
908
908
|
null
|
|
909
|
-
), b = a(null), [p, o] =
|
|
909
|
+
), b = a(null), [p, o] = R("neutral"), [l, v] = R(""), [ne, re] = R(""), [ue, rt] = R(
|
|
910
910
|
() => {
|
|
911
911
|
if (typeof window > "u") return null;
|
|
912
912
|
try {
|
|
@@ -916,35 +916,35 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
916
916
|
return null;
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
|
-
), [Ue, Ge] =
|
|
919
|
+
), [Ue, Ge] = R("hidden"), [ot, T] = R(""), dt = a(null), Je = a(Ue);
|
|
920
920
|
Je.current = Ue;
|
|
921
|
-
const [qe, ze] =
|
|
921
|
+
const [qe, ze] = R(null), Re = a(null), oe = a(null), [Fe, Ye] = R(!1), Pe = a(null), [le, Ke] = R("hidden"), [ft, Rt] = R(""), ht = a(le);
|
|
922
922
|
ht.current = le;
|
|
923
|
-
const K = a(""), E = a(!1), de = a(""), mt = a(Date.now()), Be = a([]), me = a(!1), [xe, fe] =
|
|
923
|
+
const K = a(""), E = a(!1), de = a(""), mt = a(Date.now()), Be = a([]), me = a(!1), [xe, fe] = R(!1), [it, f] = R(!1), I = a(null), M = Pt(() => Fe ? "Try again" : H === "Busy" ? "Busy" : H === "Thinking..." || H === "Processing Voice..." ? H : ue != null && ue !== "" && ue !== "none" && ue !== "<none>" ? `Enter ${Qn(ue)}` : le !== "hidden" || !it ? null : sn, [H, ue, Fe, le, it]), ve = !Fe && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (ue == null || ue === "" || ue === "none" || ue === "<none>");
|
|
924
924
|
B(() => {
|
|
925
925
|
if (le !== "hidden" || !ve) {
|
|
926
|
-
|
|
926
|
+
f(!1), I.current != null && (clearTimeout(I.current), I.current = null);
|
|
927
927
|
return;
|
|
928
928
|
}
|
|
929
929
|
return I.current = setTimeout(() => {
|
|
930
|
-
I.current = null,
|
|
930
|
+
I.current = null, f(!0);
|
|
931
931
|
}, 400), () => {
|
|
932
932
|
I.current != null && (clearTimeout(I.current), I.current = null);
|
|
933
933
|
};
|
|
934
934
|
}, [le, ve]);
|
|
935
|
-
const $e =
|
|
935
|
+
const $e = M != null && M !== "";
|
|
936
936
|
B(() => {
|
|
937
937
|
const e = Je.current;
|
|
938
938
|
if (!(e === "exiting" || e === "entering")) {
|
|
939
939
|
if (e === "hidden") {
|
|
940
|
-
$e && (
|
|
940
|
+
$e && (T(M ?? ""), Ge("entering"));
|
|
941
941
|
return;
|
|
942
942
|
}
|
|
943
|
-
e === "visible" && (!$e ||
|
|
943
|
+
e === "visible" && (!$e || M !== ot) && (dt.current = $e ? M : null, Ge("exiting"));
|
|
944
944
|
}
|
|
945
945
|
}, [
|
|
946
946
|
$e,
|
|
947
|
-
|
|
947
|
+
M,
|
|
948
948
|
Ue,
|
|
949
949
|
ot
|
|
950
950
|
]), B(() => {
|
|
@@ -967,9 +967,9 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
967
967
|
if (e === "exiting") {
|
|
968
968
|
Ge("hidden");
|
|
969
969
|
const t = dt.current;
|
|
970
|
-
dt.current = null, t != null && t !== "" && (
|
|
970
|
+
dt.current = null, t != null && t !== "" && (T(t), Ge("entering"));
|
|
971
971
|
} else e === "entering" && Ge("visible");
|
|
972
|
-
}, []),
|
|
972
|
+
}, []), wt = (e) => {
|
|
973
973
|
if (!e) return;
|
|
974
974
|
if (e.mood != null) {
|
|
975
975
|
const n = String(e.mood).toLowerCase();
|
|
@@ -977,9 +977,9 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
977
977
|
}
|
|
978
978
|
if (e.expression != null) {
|
|
979
979
|
const n = String(e.expression).trim();
|
|
980
|
-
|
|
980
|
+
v(n);
|
|
981
981
|
const s = Un.find(
|
|
982
|
-
(
|
|
982
|
+
(d) => d.name.toLowerCase() === n.toLowerCase()
|
|
983
983
|
);
|
|
984
984
|
N(
|
|
985
985
|
`[STREAM] Animation match for "${n}": ${s ? s.name : "NONE"}`
|
|
@@ -991,13 +991,13 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
991
991
|
let s = !1;
|
|
992
992
|
if (typeof window < "u")
|
|
993
993
|
try {
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
994
|
+
const d = new URL(window.location.href), w = new URL(n, window.location.href), L = d.hostname === "leads.streamoji.com" || d.hostname.includes("localhost");
|
|
995
|
+
if (w.origin !== d.origin && !L) {
|
|
996
996
|
N("[STREAM] Navigation rejected: different origin");
|
|
997
997
|
return;
|
|
998
998
|
}
|
|
999
|
-
const
|
|
1000
|
-
s =
|
|
999
|
+
const x = (k) => k.replace(/\/+$/, "") || "/";
|
|
1000
|
+
s = x(d.pathname) === x(w.pathname);
|
|
1001
1001
|
} catch {
|
|
1002
1002
|
}
|
|
1003
1003
|
if (s)
|
|
@@ -1047,17 +1047,17 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1047
1047
|
`), t = K.current.slice(0, e).trim();
|
|
1048
1048
|
K.current = K.current.slice(e + 1);
|
|
1049
1049
|
const r = xt(t);
|
|
1050
|
-
r &&
|
|
1050
|
+
r && wt(r);
|
|
1051
1051
|
}
|
|
1052
1052
|
}, Bt = (e) => {
|
|
1053
1053
|
if (E.current)
|
|
1054
1054
|
if (e.includes(pe)) {
|
|
1055
1055
|
const t = e.indexOf(pe), r = e.slice(0, t), i = e.slice(t + pe.length);
|
|
1056
|
-
r && (de.current += r,
|
|
1057
|
-
} else e === pe ? E.current = !1 : (de.current += e,
|
|
1056
|
+
r && (de.current += r, _e((n) => n + r)), E.current = !1, i && (K.current += i, ie());
|
|
1057
|
+
} else e === pe ? E.current = !1 : (de.current += e, _e((t) => t + e));
|
|
1058
1058
|
else if (e.includes(pe)) {
|
|
1059
1059
|
const t = e.indexOf(pe), r = e.slice(0, t), i = e.slice(t + pe.length);
|
|
1060
|
-
K.current += r, ie(), E.current = !0, i && (de.current += i,
|
|
1060
|
+
K.current += r, ie(), E.current = !0, i && (de.current += i, _e((n) => n + i));
|
|
1061
1061
|
} else if (e === pe) {
|
|
1062
1062
|
E.current = !0;
|
|
1063
1063
|
return;
|
|
@@ -1071,22 +1071,22 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1071
1071
|
)) {
|
|
1072
1072
|
const n = "secret", s = Math.floor(Date.now() / 1e3).toString();
|
|
1073
1073
|
try {
|
|
1074
|
-
const
|
|
1074
|
+
const d = new TextEncoder(), w = await globalThis.crypto.subtle.importKey(
|
|
1075
1075
|
"raw",
|
|
1076
|
-
|
|
1076
|
+
d.encode(n),
|
|
1077
1077
|
{ name: "HMAC", hash: "SHA-256" },
|
|
1078
1078
|
!1,
|
|
1079
1079
|
["sign"]
|
|
1080
|
-
),
|
|
1080
|
+
), L = await globalThis.crypto.subtle.sign(
|
|
1081
1081
|
"HMAC",
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
),
|
|
1085
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",
|
|
1086
|
-
} catch (
|
|
1087
|
-
console.error("[SESSION] HMAC generation failed:",
|
|
1088
|
-
const
|
|
1089
|
-
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",
|
|
1082
|
+
w,
|
|
1083
|
+
d.encode(s)
|
|
1084
|
+
), k = Array.from(new Uint8Array(L)).map((C) => C.toString(16).padStart(2, "0")).join("");
|
|
1085
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", k), N("[SESSION] New HMAC UID generated and saved:", k);
|
|
1086
|
+
} catch (d) {
|
|
1087
|
+
console.error("[SESSION] HMAC generation failed:", d);
|
|
1088
|
+
const w = Math.random().toString(36) + Date.now().toString();
|
|
1089
|
+
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
|
|
1090
1090
|
}
|
|
1091
1091
|
}
|
|
1092
1092
|
const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
|
|
@@ -1107,7 +1107,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1107
1107
|
})();
|
|
1108
1108
|
}, [S]), B(() => {
|
|
1109
1109
|
const e = () => {
|
|
1110
|
-
mt.current = Date.now(), me.current && (me.current = !1, fe(!1), F([]), Y(""),
|
|
1110
|
+
mt.current = Date.now(), me.current && (me.current = !1, fe(!1), F([]), Y(""), _e(""), z(!1));
|
|
1111
1111
|
};
|
|
1112
1112
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
1113
1113
|
const t = setInterval(async () => {
|
|
@@ -1118,17 +1118,17 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1118
1118
|
try {
|
|
1119
1119
|
const n = `${ct}/nudgeUser`, s = {
|
|
1120
1120
|
navigationUrl: window.location.href,
|
|
1121
|
-
agentId:
|
|
1122
|
-
},
|
|
1121
|
+
agentId: _
|
|
1122
|
+
}, d = await fetch(n, {
|
|
1123
1123
|
method: "POST",
|
|
1124
1124
|
headers: {
|
|
1125
1125
|
"Content-Type": "application/json"
|
|
1126
1126
|
},
|
|
1127
1127
|
body: JSON.stringify(s)
|
|
1128
1128
|
});
|
|
1129
|
-
if (
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1129
|
+
if (d.ok) {
|
|
1130
|
+
const L = (await d.json()).nudge_questions;
|
|
1131
|
+
L && L.length > 0 && (N("[NUDGE] Received nudge questions from API:", L), Be.current = L, fe(!0), F(L));
|
|
1132
1132
|
}
|
|
1133
1133
|
} catch (n) {
|
|
1134
1134
|
console.error("[NUDGE] Error calling /nudgeUser:", n), me.current = !1;
|
|
@@ -1143,11 +1143,11 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1143
1143
|
const n = () => {
|
|
1144
1144
|
const s = A[e];
|
|
1145
1145
|
if (r) {
|
|
1146
|
-
const
|
|
1147
|
-
Y(
|
|
1146
|
+
const d = s.substring(0, t - 1);
|
|
1147
|
+
Y(d), t--, i = 50;
|
|
1148
1148
|
} else {
|
|
1149
|
-
const
|
|
1150
|
-
Y(
|
|
1149
|
+
const d = s.substring(0, t + 1);
|
|
1150
|
+
Y(d), t++, i = 100;
|
|
1151
1151
|
}
|
|
1152
1152
|
!r && t === s.length ? (r = !0, i = 3e3) : r && t === 0 && (r = !1, e = (e + 1) % A.length, i = 500), X.current = setTimeout(n, i);
|
|
1153
1153
|
};
|
|
@@ -1168,9 +1168,9 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1168
1168
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1169
1169
|
JSON.stringify(e)
|
|
1170
1170
|
);
|
|
1171
|
-
}, [Tt, Mt] =
|
|
1171
|
+
}, [Tt, Mt] = R(!1), [Vt, At] = R(0), Le = a(null), _t = a([]), Wt = a(0), [Ht, dn] = R(
|
|
1172
1172
|
null
|
|
1173
|
-
), [fn, Et] =
|
|
1173
|
+
), [fn, Et] = R(
|
|
1174
1174
|
null
|
|
1175
1175
|
), Me = a(null), Qe = a(
|
|
1176
1176
|
null
|
|
@@ -1188,18 +1188,18 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1188
1188
|
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, r = new t(), i = r.createMediaStreamSource(e), n = r.createAnalyser();
|
|
1189
1189
|
n.fftSize = 64, i.connect(n), Me.current = r, Qe.current = i, Et(n);
|
|
1190
1190
|
const s = new MediaRecorder(e);
|
|
1191
|
-
Le.current = s,
|
|
1192
|
-
|
|
1191
|
+
Le.current = s, _t.current = [], s.ondataavailable = (d) => {
|
|
1192
|
+
d.data.size > 0 && _t.current.push(d.data);
|
|
1193
1193
|
}, s.onstop = async () => {
|
|
1194
|
-
const
|
|
1195
|
-
if (Et(null), Qe.current && (Qe.current.disconnect(), Qe.current = null), Me.current && Me.current.state !== "closed" && (Me.current.close(), Me.current = null),
|
|
1194
|
+
const d = Date.now() - Wt.current;
|
|
1195
|
+
if (Et(null), Qe.current && (Qe.current.disconnect(), Qe.current = null), Me.current && Me.current.state !== "closed" && (Me.current.close(), Me.current = null), d < 1e3) {
|
|
1196
1196
|
g("Recording too short. Hold or click longer."), m(!1);
|
|
1197
1197
|
return;
|
|
1198
1198
|
}
|
|
1199
|
-
const
|
|
1199
|
+
const w = new Blob(_t.current, {
|
|
1200
1200
|
type: "audio/wav"
|
|
1201
1201
|
});
|
|
1202
|
-
await bn(
|
|
1202
|
+
await bn(w);
|
|
1203
1203
|
}, Wt.current = Date.now(), s.start(100), Mt(!0), g("Listening...");
|
|
1204
1204
|
} catch (e) {
|
|
1205
1205
|
console.error("Error accessing microphone:", e), g("Mic Access Error");
|
|
@@ -1207,7 +1207,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1207
1207
|
}, mn = () => {
|
|
1208
1208
|
Le.current && Le.current.state !== "inactive" && (Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()), Mt(!1));
|
|
1209
1209
|
}, pn = () => {
|
|
1210
|
-
Le.current && Le.current.state !== "inactive" && (Le.current.onstop = null, Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()), Et(null), Qe.current && (Qe.current.disconnect(), Qe.current = null), Me.current && Me.current.state !== "closed" && (Me.current.close(), Me.current = null), Mt(!1),
|
|
1210
|
+
Le.current && Le.current.state !== "inactive" && (Le.current.onstop = null, Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()), Et(null), Qe.current && (Qe.current.disconnect(), Qe.current = null), Me.current && Me.current.state !== "closed" && (Me.current.close(), Me.current = null), Mt(!1), _t.current = [], g("Ready"));
|
|
1211
1211
|
};
|
|
1212
1212
|
B(() => {
|
|
1213
1213
|
if (!D) return;
|
|
@@ -1216,13 +1216,13 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1216
1216
|
if (t <= 0) return;
|
|
1217
1217
|
const r = ye.current, i = De.current;
|
|
1218
1218
|
if (!r) return;
|
|
1219
|
-
const n = r.currentTime - i, s = Math.min(Math.max(0, n), t),
|
|
1220
|
-
if (
|
|
1221
|
-
const
|
|
1222
|
-
Math.round(s / t *
|
|
1223
|
-
|
|
1219
|
+
const n = r.currentTime - i, s = Math.min(Math.max(0, n), t), w = cn(O).trim().length;
|
|
1220
|
+
if (w <= 0) return;
|
|
1221
|
+
const L = Math.min(
|
|
1222
|
+
Math.round(s / t * w),
|
|
1223
|
+
w
|
|
1224
1224
|
);
|
|
1225
|
-
lt(
|
|
1225
|
+
lt(L);
|
|
1226
1226
|
};
|
|
1227
1227
|
return clearInterval(b.current ?? void 0), b.current = setInterval(e, 90), () => clearInterval(b.current ?? void 0);
|
|
1228
1228
|
}, [D, O, he.current]), B(() => {
|
|
@@ -1234,21 +1234,21 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1234
1234
|
const gn = (e) => {
|
|
1235
1235
|
const t = e.numberOfChannels, r = e.length * t * 2 + 44, i = new ArrayBuffer(r), n = new DataView(i);
|
|
1236
1236
|
let s = 0;
|
|
1237
|
-
const
|
|
1238
|
-
n.setUint16(s,
|
|
1239
|
-
},
|
|
1240
|
-
n.setUint32(s,
|
|
1237
|
+
const d = (k) => {
|
|
1238
|
+
n.setUint16(s, k, !0), s += 2;
|
|
1239
|
+
}, w = (k) => {
|
|
1240
|
+
n.setUint32(s, k, !0), s += 4;
|
|
1241
1241
|
};
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
for (let
|
|
1245
|
-
let
|
|
1242
|
+
w(1179011410), w(r - 8), w(1163280727), w(544501094), w(16), d(1), d(t), w(e.sampleRate), w(e.sampleRate * 2 * t), d(t * 2), d(16), w(1635017060), w(r - s - 4);
|
|
1243
|
+
const L = [];
|
|
1244
|
+
for (let k = 0; k < t; k++) L.push(e.getChannelData(k));
|
|
1245
|
+
let x = 0;
|
|
1246
1246
|
for (; s < r; ) {
|
|
1247
|
-
for (let
|
|
1248
|
-
let C = Math.max(-1, Math.min(1,
|
|
1247
|
+
for (let k = 0; k < t; k++) {
|
|
1248
|
+
let C = Math.max(-1, Math.min(1, L[k][x]));
|
|
1249
1249
|
C = C < 0 ? C * 32768 : C * 32767, n.setInt16(s, C, !0), s += 2;
|
|
1250
1250
|
}
|
|
1251
|
-
|
|
1251
|
+
x++;
|
|
1252
1252
|
}
|
|
1253
1253
|
return new Blob([i], { type: "audio/wav" });
|
|
1254
1254
|
}, It = async (e, t, r = !1) => {
|
|
@@ -1265,37 +1265,37 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1265
1265
|
try {
|
|
1266
1266
|
const i = window.AudioContext || window.webkitAudioContext, n = ye.current ?? new i();
|
|
1267
1267
|
n.state === "suspended" && await n.resume(), ye.current = n;
|
|
1268
|
-
const s = window.atob(e),
|
|
1268
|
+
const s = window.atob(e), d = new Uint8Array(s.length);
|
|
1269
1269
|
for (let W = 0; W < s.length; W++)
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
he.current +=
|
|
1273
|
-
const
|
|
1274
|
-
let
|
|
1275
|
-
const
|
|
1276
|
-
|
|
1270
|
+
d[W] = s.charCodeAt(W);
|
|
1271
|
+
const w = await n.decodeAudioData(d.buffer.slice(0));
|
|
1272
|
+
he.current += w.duration;
|
|
1273
|
+
const L = n.currentTime;
|
|
1274
|
+
let x = je.current;
|
|
1275
|
+
const k = !He.current;
|
|
1276
|
+
x < L && (x = L + 0.1), je.current = x + w.duration;
|
|
1277
1277
|
const C = n.createBufferSource();
|
|
1278
|
-
C.buffer =
|
|
1278
|
+
C.buffer = w;
|
|
1279
1279
|
let Z = Ht;
|
|
1280
1280
|
if ((!Z || Z.context !== n) && (Z = n.createAnalyser(), Z.fftSize = 64, Z.connect(n.destination), dn(Z)), C.connect(Z), Oe.current.push(C), Ne.current) {
|
|
1281
1281
|
Oe.current = Oe.current.filter((W) => W !== C);
|
|
1282
1282
|
return;
|
|
1283
1283
|
}
|
|
1284
|
-
if (
|
|
1284
|
+
if (k) {
|
|
1285
1285
|
He.current = !0, z(!0), N(
|
|
1286
|
-
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${
|
|
1286
|
+
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${x.toFixed(
|
|
1287
1287
|
3
|
|
1288
1288
|
)}`
|
|
1289
|
-
), De.current =
|
|
1290
|
-
const W = (
|
|
1289
|
+
), De.current = x;
|
|
1290
|
+
const W = (x - L) * 1e3;
|
|
1291
1291
|
tt.current = performance.now() + W, N(
|
|
1292
|
-
`[AUDIO] Response started. Initial startTime: ${
|
|
1292
|
+
`[AUDIO] Response started. Initial startTime: ${x.toFixed(
|
|
1293
1293
|
3
|
|
1294
|
-
)}, CT: ${
|
|
1294
|
+
)}, CT: ${L.toFixed(3)}`
|
|
1295
1295
|
);
|
|
1296
1296
|
}
|
|
1297
|
-
C.start(
|
|
1298
|
-
const se = (
|
|
1297
|
+
C.start(x);
|
|
1298
|
+
const se = (x - De.current) * 1e3;
|
|
1299
1299
|
r && (Ce.current = se, N(
|
|
1300
1300
|
`[AUDIO] New segment detected at +${se.toFixed(
|
|
1301
1301
|
0
|
|
@@ -1327,30 +1327,30 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1327
1327
|
}
|
|
1328
1328
|
}, bn = async (e) => {
|
|
1329
1329
|
try {
|
|
1330
|
-
m(!0), fe(!1), de.current = "",
|
|
1330
|
+
m(!0), fe(!1), de.current = "", _e(""), g("Processing Voice...");
|
|
1331
1331
|
const t = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = gn(i), s = new FileReader();
|
|
1332
1332
|
s.readAsDataURL(n), s.onloadend = async () => {
|
|
1333
|
-
const
|
|
1333
|
+
const d = s.result.split(",")[1];
|
|
1334
1334
|
pt(), ae(""), K.current = "", E.current = !1;
|
|
1335
|
-
const
|
|
1335
|
+
const w = `${ct}/stt?token=${encodeURIComponent(et)}`, L = await fetch(w, {
|
|
1336
1336
|
method: "POST",
|
|
1337
1337
|
headers: { "Content-Type": "application/json" },
|
|
1338
1338
|
body: JSON.stringify({
|
|
1339
|
-
audio_base64:
|
|
1339
|
+
audio_base64: d,
|
|
1340
1340
|
audio_format: "wav"
|
|
1341
1341
|
})
|
|
1342
1342
|
});
|
|
1343
|
-
if (
|
|
1343
|
+
if (L.status === 429) {
|
|
1344
1344
|
try {
|
|
1345
|
-
const ge = await
|
|
1345
|
+
const ge = await L.text(), P = JSON.parse(ge);
|
|
1346
1346
|
N("[STT] 429 agent at capacity:", P?.detail);
|
|
1347
1347
|
} catch {
|
|
1348
1348
|
}
|
|
1349
1349
|
ae(""), g("Busy"), m(!1);
|
|
1350
1350
|
return;
|
|
1351
1351
|
}
|
|
1352
|
-
if (!
|
|
1353
|
-
const ge = await
|
|
1352
|
+
if (!L.ok) {
|
|
1353
|
+
const ge = await L.text();
|
|
1354
1354
|
let P = "STT Failed";
|
|
1355
1355
|
try {
|
|
1356
1356
|
P = JSON.parse(ge).error || P;
|
|
@@ -1359,12 +1359,12 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1359
1359
|
}
|
|
1360
1360
|
throw new Error(P);
|
|
1361
1361
|
}
|
|
1362
|
-
const
|
|
1363
|
-
if (N("this is body" +
|
|
1362
|
+
const x = L.body;
|
|
1363
|
+
if (N("this is body" + x), !x) {
|
|
1364
1364
|
g("STT Failed"), m(!1);
|
|
1365
1365
|
return;
|
|
1366
1366
|
}
|
|
1367
|
-
const
|
|
1367
|
+
const k = x.getReader();
|
|
1368
1368
|
Ne.current = !1;
|
|
1369
1369
|
const C = new TextDecoder();
|
|
1370
1370
|
let Z = "", se = !1;
|
|
@@ -1396,7 +1396,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1396
1396
|
}
|
|
1397
1397
|
};
|
|
1398
1398
|
for (; ; ) {
|
|
1399
|
-
const { done: ge, value: P } = await
|
|
1399
|
+
const { done: ge, value: P } = await k.read();
|
|
1400
1400
|
P && (Z += C.decode(P, { stream: !0 }));
|
|
1401
1401
|
const be = Z.split(`
|
|
1402
1402
|
|
|
@@ -1419,8 +1419,8 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1419
1419
|
} catch (t) {
|
|
1420
1420
|
console.error("Audio Submission Error:", t), g("STT Failed"), m(!1);
|
|
1421
1421
|
}
|
|
1422
|
-
},
|
|
1423
|
-
e && e.preventDefault(), fe(!1), de.current = "",
|
|
1422
|
+
}, wn = async (e) => {
|
|
1423
|
+
e && e.preventDefault(), fe(!1), de.current = "", _e(""), !(!q || ce) && await _n(q);
|
|
1424
1424
|
}, st = (e) => {
|
|
1425
1425
|
const t = e.split(/\r?\n/);
|
|
1426
1426
|
let r = "", i = "";
|
|
@@ -1446,7 +1446,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1446
1446
|
break;
|
|
1447
1447
|
}
|
|
1448
1448
|
case "metadata": {
|
|
1449
|
-
|
|
1449
|
+
wt(t);
|
|
1450
1450
|
break;
|
|
1451
1451
|
}
|
|
1452
1452
|
case "audio": {
|
|
@@ -1465,7 +1465,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1465
1465
|
}
|
|
1466
1466
|
case "error": {
|
|
1467
1467
|
const r = t.message ?? "Unknown error";
|
|
1468
|
-
de.current = r,
|
|
1468
|
+
de.current = r, _e(r), g("Agent Failed"), m(!1);
|
|
1469
1469
|
break;
|
|
1470
1470
|
}
|
|
1471
1471
|
}
|
|
@@ -1490,22 +1490,22 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1490
1490
|
const n = i.getReader();
|
|
1491
1491
|
Ne.current = !1;
|
|
1492
1492
|
const s = new TextDecoder();
|
|
1493
|
-
let
|
|
1493
|
+
let d = "";
|
|
1494
1494
|
for (; ; ) {
|
|
1495
|
-
const { done:
|
|
1496
|
-
|
|
1497
|
-
const
|
|
1495
|
+
const { done: w, value: L } = await n.read();
|
|
1496
|
+
L && (d += s.decode(L, { stream: !0 }));
|
|
1497
|
+
const x = d.split(`
|
|
1498
1498
|
|
|
1499
1499
|
`);
|
|
1500
|
-
|
|
1501
|
-
for (const
|
|
1502
|
-
const C = st(
|
|
1500
|
+
d = x.pop() ?? "";
|
|
1501
|
+
for (const k of x) {
|
|
1502
|
+
const C = st(k);
|
|
1503
1503
|
C && yt(C.event, C.data);
|
|
1504
1504
|
}
|
|
1505
|
-
if (
|
|
1506
|
-
if (
|
|
1507
|
-
const
|
|
1508
|
-
|
|
1505
|
+
if (w) {
|
|
1506
|
+
if (d.trim()) {
|
|
1507
|
+
const k = st(d.trim());
|
|
1508
|
+
k && yt(k.event, k.data);
|
|
1509
1509
|
}
|
|
1510
1510
|
g("Ready"), m(!1);
|
|
1511
1511
|
break;
|
|
@@ -1524,7 +1524,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1524
1524
|
B(() => {
|
|
1525
1525
|
y && !qt.current && (y({ avatarSpeak: Gt, avatarRespond: Jt }), qt.current = !0);
|
|
1526
1526
|
}, [y, Gt, Jt]);
|
|
1527
|
-
const
|
|
1527
|
+
const _n = async (e) => {
|
|
1528
1528
|
m(!0), g("Thinking..."), de.current = "", K.current = "", E.current = !1, pt(), he.current = 0, lt(0);
|
|
1529
1529
|
const t = `${ct}/agent/chat?token=${encodeURIComponent(et)}`;
|
|
1530
1530
|
try {
|
|
@@ -1549,8 +1549,8 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1549
1549
|
});
|
|
1550
1550
|
if (s.status === 429) {
|
|
1551
1551
|
try {
|
|
1552
|
-
const
|
|
1553
|
-
N("[CHAT] 429 agent at capacity:",
|
|
1552
|
+
const k = await s.json();
|
|
1553
|
+
N("[CHAT] 429 agent at capacity:", k?.detail);
|
|
1554
1554
|
} catch {
|
|
1555
1555
|
}
|
|
1556
1556
|
ae(""), g("Busy"), m(!1);
|
|
@@ -1558,32 +1558,32 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1558
1558
|
}
|
|
1559
1559
|
if (!s.ok)
|
|
1560
1560
|
throw new Error("Agent request failed");
|
|
1561
|
-
const
|
|
1562
|
-
if (!
|
|
1561
|
+
const d = s.body;
|
|
1562
|
+
if (!d) {
|
|
1563
1563
|
g("Agent Failed"), m(!1);
|
|
1564
1564
|
return;
|
|
1565
1565
|
}
|
|
1566
|
-
const
|
|
1566
|
+
const w = d.getReader();
|
|
1567
1567
|
Ne.current = !1;
|
|
1568
|
-
const
|
|
1569
|
-
let
|
|
1568
|
+
const L = new TextDecoder();
|
|
1569
|
+
let x = "";
|
|
1570
1570
|
for (; ; ) {
|
|
1571
|
-
const { done:
|
|
1571
|
+
const { done: k, value: C } = await w.read();
|
|
1572
1572
|
N(
|
|
1573
|
-
`[SSE] Chunk received. done=${
|
|
1574
|
-
), C && (
|
|
1575
|
-
const Z =
|
|
1573
|
+
`[SSE] Chunk received. done=${k}, length=${C?.length || 0}`
|
|
1574
|
+
), C && (x += L.decode(C, { stream: !0 }));
|
|
1575
|
+
const Z = x.split(`
|
|
1576
1576
|
|
|
1577
1577
|
`);
|
|
1578
|
-
|
|
1578
|
+
x = Z.pop() ?? "";
|
|
1579
1579
|
for (const se of Z) {
|
|
1580
1580
|
N(`[SSE] Processing block: ${se.slice(0, 50)}...`);
|
|
1581
1581
|
const W = st(se);
|
|
1582
1582
|
W && (N(`[SSE] Event: ${W.event}`), yt(W.event, W.data));
|
|
1583
1583
|
}
|
|
1584
|
-
if (
|
|
1585
|
-
if (N("[SSE] Stream finished"),
|
|
1586
|
-
const se = st(
|
|
1584
|
+
if (k) {
|
|
1585
|
+
if (N("[SSE] Stream finished"), x.trim()) {
|
|
1586
|
+
const se = st(x.trim());
|
|
1587
1587
|
se && yt(se.event, se.data);
|
|
1588
1588
|
}
|
|
1589
1589
|
g("Ready"), m(!1), ae("");
|
|
@@ -1625,8 +1625,8 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1625
1625
|
e && (e.scrollTop = e.scrollHeight);
|
|
1626
1626
|
}, [ft]);
|
|
1627
1627
|
const Ln = G === "female" ? Vn : $n;
|
|
1628
|
-
return ut ? /* @__PURE__ */
|
|
1629
|
-
/* @__PURE__ */
|
|
1628
|
+
return ut ? /* @__PURE__ */ we("div", { className: "avatar-widget-container", children: [
|
|
1629
|
+
/* @__PURE__ */ we("div", { className: "avatar-input-area", children: [
|
|
1630
1630
|
Ue !== "hidden" ? /* @__PURE__ */ h(
|
|
1631
1631
|
"div",
|
|
1632
1632
|
{
|
|
@@ -1652,7 +1652,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1652
1652
|
width: "100%",
|
|
1653
1653
|
height: "100%"
|
|
1654
1654
|
},
|
|
1655
|
-
children: Tt ? /* @__PURE__ */
|
|
1655
|
+
children: Tt ? /* @__PURE__ */ we("div", { className: "avatar-input-recording", children: [
|
|
1656
1656
|
/* @__PURE__ */ h(
|
|
1657
1657
|
"button",
|
|
1658
1658
|
{
|
|
@@ -1660,7 +1660,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1660
1660
|
className: "avatar-recording-cancel",
|
|
1661
1661
|
onClick: pn,
|
|
1662
1662
|
title: "Cancel",
|
|
1663
|
-
children: /* @__PURE__ */
|
|
1663
|
+
children: /* @__PURE__ */ we(
|
|
1664
1664
|
"svg",
|
|
1665
1665
|
{
|
|
1666
1666
|
width: "18",
|
|
@@ -1680,7 +1680,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1680
1680
|
)
|
|
1681
1681
|
}
|
|
1682
1682
|
),
|
|
1683
|
-
/* @__PURE__ */
|
|
1683
|
+
/* @__PURE__ */ we(
|
|
1684
1684
|
"div",
|
|
1685
1685
|
{
|
|
1686
1686
|
style: {
|
|
@@ -1693,7 +1693,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1693
1693
|
},
|
|
1694
1694
|
children: [
|
|
1695
1695
|
/* @__PURE__ */ h("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ h(Qt, { analyser: fn }) }),
|
|
1696
|
-
/* @__PURE__ */
|
|
1696
|
+
/* @__PURE__ */ we(
|
|
1697
1697
|
"span",
|
|
1698
1698
|
{
|
|
1699
1699
|
style: {
|
|
@@ -1739,7 +1739,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1739
1739
|
)
|
|
1740
1740
|
}
|
|
1741
1741
|
)
|
|
1742
|
-
] }) : D && !xe ? /* @__PURE__ */
|
|
1742
|
+
] }) : D && !xe ? /* @__PURE__ */ we("div", { className: "avatar-input-speaking", children: [
|
|
1743
1743
|
/* @__PURE__ */ h(
|
|
1744
1744
|
"div",
|
|
1745
1745
|
{
|
|
@@ -1775,10 +1775,10 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1775
1775
|
},
|
|
1776
1776
|
children: /* @__PURE__ */ h("div", { className: "avatar-input-loader" })
|
|
1777
1777
|
}
|
|
1778
|
-
) : /* @__PURE__ */
|
|
1778
|
+
) : /* @__PURE__ */ we(
|
|
1779
1779
|
"form",
|
|
1780
1780
|
{
|
|
1781
|
-
onSubmit:
|
|
1781
|
+
onSubmit: wn,
|
|
1782
1782
|
style: {
|
|
1783
1783
|
flex: 1,
|
|
1784
1784
|
display: "flex",
|
|
@@ -1834,7 +1834,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1834
1834
|
onClick: hn,
|
|
1835
1835
|
disabled: ce,
|
|
1836
1836
|
style: { backgroundColor: "#1e4a5e" },
|
|
1837
|
-
children: /* @__PURE__ */
|
|
1837
|
+
children: /* @__PURE__ */ we(
|
|
1838
1838
|
"svg",
|
|
1839
1839
|
{
|
|
1840
1840
|
width: "28",
|
|
@@ -1897,7 +1897,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1897
1897
|
}
|
|
1898
1898
|
) })
|
|
1899
1899
|
] }),
|
|
1900
|
-
/* @__PURE__ */ h("div", { className: "avatar-wrapper", children: /* @__PURE__ */
|
|
1900
|
+
/* @__PURE__ */ h("div", { className: "avatar-wrapper", children: /* @__PURE__ */ we("div", { className: "avatar-scene-wrapper", children: [
|
|
1901
1901
|
le !== "hidden" && /* @__PURE__ */ h(
|
|
1902
1902
|
"div",
|
|
1903
1903
|
{
|
|
@@ -1911,7 +1911,7 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1911
1911
|
{
|
|
1912
1912
|
className: "avatar-canvas-layer",
|
|
1913
1913
|
style: { width: J, height: J },
|
|
1914
|
-
children: /* @__PURE__ */
|
|
1914
|
+
children: /* @__PURE__ */ we(
|
|
1915
1915
|
Rn,
|
|
1916
1916
|
{
|
|
1917
1917
|
shadows: !0,
|
|
@@ -1955,14 +1955,14 @@ const Ft = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1955
1955
|
] }) : null;
|
|
1956
1956
|
}, or = ({
|
|
1957
1957
|
agentId: u,
|
|
1958
|
-
onNavigationRequested:
|
|
1958
|
+
onNavigationRequested: _,
|
|
1959
1959
|
presetUserDetails: S,
|
|
1960
1960
|
onAvatarReady: y
|
|
1961
1961
|
}) => /* @__PURE__ */ h(
|
|
1962
1962
|
Xn,
|
|
1963
1963
|
{
|
|
1964
1964
|
agentId: u,
|
|
1965
|
-
onNavigationRequested:
|
|
1965
|
+
onNavigationRequested: _,
|
|
1966
1966
|
presetUserDetails: S,
|
|
1967
1967
|
onAvatarReady: y
|
|
1968
1968
|
}
|