@streamoji/avatar-widget 0.4.6 → 0.4.9
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 +302 -304
- package/dist/avatar-widget.umd.js +21 -21
- package/dist/avatar-widget.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { jsx as l, jsxs as be } from "react/jsx-runtime";
|
|
2
|
-
import { useGLTF as
|
|
2
|
+
import { useGLTF as It, Environment as vn } 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 Ut, useRef as c, useState as
|
|
4
|
+
import { memo as Tn, useMemo as Ut, useRef as c, useState as L, useEffect as W, useCallback as tt, useLayoutEffect as An, Suspense as En } from "react";
|
|
5
5
|
import * as at from "three";
|
|
6
|
-
import { GLTFLoader as
|
|
6
|
+
import { GLTFLoader as In } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
7
|
const nt = "https://ai.streamoji.com", N = (...g) => {
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
const
|
|
8
|
+
}, Mn = (...g) => {
|
|
9
|
+
}, Kt = ({ analyser: g }) => {
|
|
10
|
+
const v = c(null), y = c(null);
|
|
11
11
|
return W(() => {
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
14
|
-
const j =
|
|
12
|
+
const S = v.current;
|
|
13
|
+
if (!S) return;
|
|
14
|
+
const j = S.getContext("2d", { alpha: !0 });
|
|
15
15
|
if (!j) return;
|
|
16
16
|
let Q, ee = null;
|
|
17
17
|
g && (g.fftSize = 128, ee = new Uint8Array(g.frequencyBinCount));
|
|
18
|
-
const
|
|
19
|
-
Q = requestAnimationFrame(
|
|
20
|
-
const Be =
|
|
18
|
+
const Qe = () => {
|
|
19
|
+
Q = requestAnimationFrame(Qe), (S.width !== S.offsetWidth || S.height !== S.offsetHeight) && (S.width = S.offsetWidth, S.height = S.offsetHeight);
|
|
20
|
+
const Be = S.width, U = S.height;
|
|
21
21
|
if (Be === 0 || U === 0) return;
|
|
22
22
|
const rt = U / 2;
|
|
23
23
|
j.clearRect(0, 0, Be, U), j.fillStyle = "#1e293b";
|
|
24
24
|
const ve = 2, G = ve + 2, Ae = Be * 0.95, q = Math.floor(Ae / G);
|
|
25
|
-
(!
|
|
26
|
-
const se = q * G,
|
|
25
|
+
(!y.current || y.current.length !== q) && (y.current = new Float32Array(q).fill(2));
|
|
26
|
+
const se = q * G, I = (Be - se) / 2;
|
|
27
27
|
g && ee && g.getByteFrequencyData(ee);
|
|
28
28
|
const _e = ee ? ee.length : 0, b = Math.floor(_e * 0.7) / q, ae = new Float32Array(q);
|
|
29
29
|
for (let m = 0; m < q; m++) {
|
|
30
30
|
let O = 0;
|
|
31
31
|
if (ee && b > 0) {
|
|
32
|
-
const
|
|
33
|
-
for (let Y =
|
|
32
|
+
const M = Math.floor(m * b), F = Math.floor((m + 1) * b);
|
|
33
|
+
for (let Y = M; Y < F; Y++) {
|
|
34
34
|
const X = ee[Y] || 0;
|
|
35
35
|
X > O && (O = X);
|
|
36
36
|
}
|
|
@@ -40,40 +40,40 @@ const nt = "https://ai.streamoji.com", N = (...g) => {
|
|
|
40
40
|
ae[m] = A;
|
|
41
41
|
}
|
|
42
42
|
for (let m = 0; m < q; m++) {
|
|
43
|
-
const O = q - 1 - m, z = Math.max(ae[m], ae[O]), A =
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
j.beginPath(), j.roundRect ? j.roundRect(
|
|
43
|
+
const O = q - 1 - m, z = Math.max(ae[m], ae[O]), A = y.current[m] + (z - y.current[m]) * 0.3;
|
|
44
|
+
y.current[m] = A;
|
|
45
|
+
const M = I + m * G, F = rt - A / 2;
|
|
46
|
+
j.beginPath(), j.roundRect ? j.roundRect(M, F, ve, A, 4) : j.fillRect(M, F, ve, A), j.fill();
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
return
|
|
49
|
+
return Qe(), () => {
|
|
50
50
|
cancelAnimationFrame(Q);
|
|
51
51
|
};
|
|
52
52
|
}, [g]), /* @__PURE__ */ l(
|
|
53
53
|
"canvas",
|
|
54
54
|
{
|
|
55
|
-
ref:
|
|
55
|
+
ref: v,
|
|
56
56
|
style: { width: "100%", height: "100%", display: "block" }
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
|
-
}, Dn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",
|
|
59
|
+
}, Dn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Qt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
|
|
60
60
|
function On(g) {
|
|
61
|
-
const [
|
|
61
|
+
const [v, y] = L(null);
|
|
62
62
|
return W(() => {
|
|
63
63
|
if (!g) {
|
|
64
|
-
|
|
64
|
+
y(null);
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
let
|
|
67
|
+
let S = !1;
|
|
68
68
|
const j = `${Dn}/${g}.glb`;
|
|
69
69
|
return fetch(j, { method: "HEAD" }).then((Q) => {
|
|
70
|
-
|
|
70
|
+
S || y(Q.ok ? j : Qt);
|
|
71
71
|
}).catch(() => {
|
|
72
|
-
|
|
72
|
+
S || y(Qt);
|
|
73
73
|
}), () => {
|
|
74
|
-
|
|
74
|
+
S = !0;
|
|
75
75
|
};
|
|
76
|
-
}, [g]),
|
|
76
|
+
}, [g]), v;
|
|
77
77
|
}
|
|
78
78
|
const Cn = [
|
|
79
79
|
"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
|
|
@@ -266,7 +266,7 @@ const Cn = [
|
|
|
266
266
|
rotation: [0.15, 0.02, 0]
|
|
267
267
|
}, Wn = [-0.45, 1.9, 0.1], Vn = [-0.45, 1.75, 0.1], $n = {
|
|
268
268
|
browInnerUp: 0.2
|
|
269
|
-
},
|
|
269
|
+
}, Mt = 0.18, Hn = 1, jn = 0.5, Xt = 3, bt = 0.55, Dt = 0.12, Zt = 2, en = 2, _t = 4, tn = 8, Gn = 1, nn = 0.38, rn = 0.32, on = "__branding__", wt = {
|
|
270
270
|
neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
|
|
271
271
|
happy: {
|
|
272
272
|
mouthSmileLeft: 0.2,
|
|
@@ -614,69 +614,69 @@ const Cn = [
|
|
|
614
614
|
};
|
|
615
615
|
function zn(g) {
|
|
616
616
|
if (!g) return [{ v: "sil", w: 1 }];
|
|
617
|
-
const
|
|
618
|
-
return qn[
|
|
617
|
+
const v = g.toLowerCase();
|
|
618
|
+
return qn[v] ?? [{ v: "sil", w: 1 }];
|
|
619
619
|
}
|
|
620
620
|
function Yn({ target: g }) {
|
|
621
|
-
const { camera:
|
|
621
|
+
const { camera: v } = xn();
|
|
622
622
|
return W(() => {
|
|
623
|
-
|
|
624
|
-
}, [
|
|
623
|
+
v.lookAt(...g);
|
|
624
|
+
}, [v, g]), null;
|
|
625
625
|
}
|
|
626
|
-
function u(g,
|
|
626
|
+
function u(g, v, y) {
|
|
627
627
|
if (!g || !g.morphTargetDictionary)
|
|
628
628
|
return;
|
|
629
|
-
const
|
|
629
|
+
const S = g, j = S.morphTargetDictionary, Q = S.morphTargetInfluences;
|
|
630
630
|
if (Q)
|
|
631
631
|
for (const ee in j)
|
|
632
|
-
ee.toLowerCase() ===
|
|
632
|
+
ee.toLowerCase() === v.toLowerCase() && (Q[j[ee]] = y);
|
|
633
633
|
}
|
|
634
|
-
function Ot(g,
|
|
634
|
+
function Ot(g, v = 0.97) {
|
|
635
635
|
if (!g) return;
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
638
|
-
for (let
|
|
639
|
-
|
|
636
|
+
const y = g;
|
|
637
|
+
if (y.morphTargetInfluences)
|
|
638
|
+
for (let S = 0; S < y.morphTargetInfluences.length; S++)
|
|
639
|
+
y.morphTargetInfluences[S] *= v;
|
|
640
640
|
}
|
|
641
641
|
const Kn = Tn(
|
|
642
642
|
({
|
|
643
643
|
avatarUrl: g,
|
|
644
|
-
isPlayingRef:
|
|
645
|
-
visemeQueueRef:
|
|
646
|
-
audioContextRef:
|
|
644
|
+
isPlayingRef: v,
|
|
645
|
+
visemeQueueRef: y,
|
|
646
|
+
audioContextRef: S,
|
|
647
647
|
responseAudioStartTimeRef: j,
|
|
648
648
|
adjustments: Q,
|
|
649
649
|
mood: ee,
|
|
650
|
-
expression:
|
|
650
|
+
expression: Qe,
|
|
651
651
|
agentResponse: Be,
|
|
652
652
|
isSpeaking: U,
|
|
653
653
|
nextStartTimeRef: rt,
|
|
654
654
|
stopPlayback: ve,
|
|
655
|
-
setIsSpeaking:
|
|
655
|
+
setIsSpeaking: Xe,
|
|
656
656
|
expressionUrl: G,
|
|
657
657
|
onExpressionFinished: Ae,
|
|
658
658
|
isNudgeResponse: q,
|
|
659
659
|
avatarGender: se
|
|
660
660
|
}) => {
|
|
661
|
-
const { scene:
|
|
661
|
+
const { scene: I } = It(g), H = It(se === "female" ? Un : Cn), b = Ut(
|
|
662
662
|
() => H.flatMap((p) => p.animations),
|
|
663
663
|
[H]
|
|
664
|
-
), m =
|
|
664
|
+
), m = It(se === "female" ? Pn : Fn), O = Ut(
|
|
665
665
|
() => m.flatMap((p) => p.animations),
|
|
666
666
|
[m]
|
|
667
|
-
), z = c(null), A = c(null),
|
|
667
|
+
), z = c(null), A = c(null), M = c(null), F = c(null), Y = c(null), X = c(null), yt = c([]), [te] = L(() => new at.AnimationMixer(I)), J = c({}), V = c(null), Ee = c(0), Ze = c(!1), We = c(0), Ie = c(!1), we = c(null), Me = c(Xt), ct = c(-1), De = c("left"), Ve = c(_t + Math.random() * (tn - _t)), de = c(0), Oe = c("smile");
|
|
668
668
|
W(() => {
|
|
669
|
-
if (!(!b || !
|
|
669
|
+
if (!(!b || !I)) {
|
|
670
670
|
if (b.forEach((p, h) => {
|
|
671
671
|
const a = `idle_${h}`;
|
|
672
672
|
if (!J.current[a]) {
|
|
673
|
-
const o = te.clipAction(p,
|
|
673
|
+
const o = te.clipAction(p, I);
|
|
674
674
|
o.name = a, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[a] = o;
|
|
675
675
|
}
|
|
676
676
|
}), O.forEach((p, h) => {
|
|
677
677
|
const a = `talk_${h}`;
|
|
678
678
|
if (!J.current[a]) {
|
|
679
|
-
const o = te.clipAction(p,
|
|
679
|
+
const o = te.clipAction(p, I);
|
|
680
680
|
o.name = a, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[a] = o;
|
|
681
681
|
}
|
|
682
682
|
}), b.length > 0) {
|
|
@@ -687,15 +687,15 @@ const Kn = Tn(
|
|
|
687
687
|
te.stopAllAction(), J.current = {}, V.current = null;
|
|
688
688
|
};
|
|
689
689
|
}
|
|
690
|
-
}, [b, O,
|
|
690
|
+
}, [b, O, I, te]);
|
|
691
691
|
const ke = c("");
|
|
692
692
|
W(() => {
|
|
693
|
-
if (!G || !
|
|
694
|
-
ke.current = G, we.current = G, new
|
|
693
|
+
if (!G || !I || G === ke.current) return;
|
|
694
|
+
ke.current = G, we.current = G, new In().load(
|
|
695
695
|
G,
|
|
696
696
|
(h) => {
|
|
697
697
|
if (h.animations && h.animations.length > 0) {
|
|
698
|
-
const a = h.animations[0], o = te.clipAction(a,
|
|
698
|
+
const a = h.animations[0], o = te.clipAction(a, I);
|
|
699
699
|
if (o.name = `EXPR_${G}`, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[`EXPR_${G}`] = o, U && we.current === G) {
|
|
700
700
|
const d = V.current;
|
|
701
701
|
o.reset().fadeIn(0.3).play(), d && d !== o && d.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
|
|
@@ -707,7 +707,7 @@ const Kn = Tn(
|
|
|
707
707
|
console.error(`[ANIMATION] Failed to load ${G}`, h);
|
|
708
708
|
}
|
|
709
709
|
);
|
|
710
|
-
}, [G,
|
|
710
|
+
}, [G, I, te, U]), W(() => {
|
|
711
711
|
const p = (h) => {
|
|
712
712
|
const a = h.action, o = a.name || "";
|
|
713
713
|
if (o.startsWith("idle_")) {
|
|
@@ -742,7 +742,7 @@ const Kn = Tn(
|
|
|
742
742
|
q,
|
|
743
743
|
Ae
|
|
744
744
|
]), W(() => {
|
|
745
|
-
if (U &&
|
|
745
|
+
if (U && I) {
|
|
746
746
|
const p = V.current, h = p?.name || "";
|
|
747
747
|
if (h.startsWith("idle_") || h.startsWith("talk_") || h === "") {
|
|
748
748
|
const a = we.current;
|
|
@@ -760,19 +760,19 @@ const Kn = Tn(
|
|
|
760
760
|
d && (d.reset().fadeIn(0.5).play(), p && p.crossFadeTo(d, 0.5, !0), V.current = d);
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
|
-
} else if (!U &&
|
|
763
|
+
} else if (!U && I) {
|
|
764
764
|
const p = V.current, h = p?.name || "";
|
|
765
765
|
if (h.startsWith("talk_") || h.startsWith("EXPR_")) {
|
|
766
766
|
const a = J.current.idle_0;
|
|
767
767
|
a && (a.reset().fadeIn(0.5).play(), p && p.crossFadeTo(a, 0.5, !0), V.current = a);
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
|
-
}, [U,
|
|
771
|
-
if (!
|
|
772
|
-
|
|
770
|
+
}, [U, I, G]), W(() => {
|
|
771
|
+
if (!I) return;
|
|
772
|
+
I.traverse((a) => {
|
|
773
773
|
if (a.isMesh && a.morphTargetDictionary) {
|
|
774
774
|
const o = a.name.toLowerCase();
|
|
775
|
-
(o.includes("head") || o.includes("avatar")) && (A.current = a, N(`[ANIMATION] Found head mesh: ${a.name}`)), o.includes("teeth") && (
|
|
775
|
+
(o.includes("head") || o.includes("avatar")) && (A.current = a, N(`[ANIMATION] Found head mesh: ${a.name}`)), o.includes("teeth") && (M.current = a, N(`[ANIMATION] Found teeth mesh: ${a.name}`)), o.includes("beard") && (F.current = a, N(`[ANIMATION] Found beard mesh: ${a.name}`)), o.includes("eyeleft") && (Y.current = a, N(`[ANIMATION] Found eye left mesh: ${a.name}`)), o.includes("eyeright") && (X.current = a, N(`[ANIMATION] Found eye right mesh: ${a.name}`));
|
|
776
776
|
}
|
|
777
777
|
});
|
|
778
778
|
const p = A.current?.morphTargetDictionary;
|
|
@@ -780,177 +780,177 @@ const Kn = Tn(
|
|
|
780
780
|
(a) => a.toLowerCase().includes("brow")
|
|
781
781
|
);
|
|
782
782
|
const h = [];
|
|
783
|
-
|
|
783
|
+
I.traverse((a) => {
|
|
784
784
|
if (a.isMesh) {
|
|
785
785
|
const d = a.morphTargetDictionary;
|
|
786
786
|
d && Object.keys(d).some((D) => D.toLowerCase().includes("brow")) && h.push(a);
|
|
787
787
|
}
|
|
788
788
|
}), yt.current = h, h.length > 0 && N("[ANIMATION] Meshes with brow morphs:", h.length);
|
|
789
|
-
}, [
|
|
789
|
+
}, [I]);
|
|
790
790
|
const ot = (p, h = 1) => {
|
|
791
791
|
const a = `viseme_${p}`.toLowerCase(), o = Jn.find((d) => d.key.toLowerCase() === a);
|
|
792
792
|
if (o) {
|
|
793
793
|
for (const d in o.mix) {
|
|
794
794
|
const D = o.mix[d] * h;
|
|
795
|
-
u(A.current, d, D), u(F.current, d, D), (!o.teethMix || !(d in o.teethMix)) && u(
|
|
795
|
+
u(A.current, d, D), u(F.current, d, D), (!o.teethMix || !(d in o.teethMix)) && u(M.current, d, D);
|
|
796
796
|
}
|
|
797
797
|
if (o.teethMix)
|
|
798
798
|
for (const d in o.teethMix) {
|
|
799
799
|
const D = o.teethMix[d] * h;
|
|
800
|
-
u(
|
|
800
|
+
u(M.current, d, D);
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
}, it = (p) => {
|
|
804
804
|
const h = wt[p] ?? wt.neutral;
|
|
805
805
|
for (const a in h)
|
|
806
|
-
u(A.current, a, h[a]), u(
|
|
806
|
+
u(A.current, a, h[a]), u(M.current, a, h[a]), u(F.current, a, h[a]);
|
|
807
807
|
};
|
|
808
808
|
return kn((p, h) => {
|
|
809
809
|
const a = Math.pow(0.88, 60 * h);
|
|
810
|
-
Ot(A.current, a), Ot(
|
|
810
|
+
Ot(A.current, a), Ot(M.current, a), Ot(F.current, a), it(ee);
|
|
811
811
|
const o = p.clock.elapsedTime;
|
|
812
812
|
let d = 0;
|
|
813
813
|
if (Math.floor(o) % 5 === 0 && Math.floor((o - h) % 5) !== 0) {
|
|
814
814
|
let _ = null;
|
|
815
|
-
|
|
815
|
+
I.traverse((P) => {
|
|
816
816
|
P.name.toLowerCase().includes("hips") && (_ = P);
|
|
817
817
|
});
|
|
818
818
|
const K = _ ? `Hips Y: ${_.position.y.toFixed(4)}` : "Hips not found";
|
|
819
819
|
N(`[ANIMATION] Mixer Time: ${te.time.toFixed(2)}, ${K}`);
|
|
820
820
|
}
|
|
821
|
-
if (te.update(h), o > Ee.current && !Ze.current && (Ze.current = !0,
|
|
822
|
-
const _ = U ? 0.2 : 0.3, K = (o -
|
|
821
|
+
if (te.update(h), o > Ee.current && !Ze.current && (Ze.current = !0, We.current = o), Ze.current) {
|
|
822
|
+
const _ = U ? 0.2 : 0.3, K = (o - We.current) / _;
|
|
823
823
|
if (K >= 1)
|
|
824
|
-
if (Ze.current = !1,
|
|
824
|
+
if (Ze.current = !1, Ie.current) {
|
|
825
825
|
const P = U ? 1 : 2.5;
|
|
826
|
-
Ee.current = o + P,
|
|
826
|
+
Ee.current = o + P, Ie.current = !1;
|
|
827
827
|
} else
|
|
828
|
-
Ee.current = o + 0.12,
|
|
828
|
+
Ee.current = o + 0.12, Ie.current = !0;
|
|
829
829
|
else {
|
|
830
830
|
const P = K < 0.5 ? K * 2 : (1 - K) * 2;
|
|
831
|
-
u(A.current, "eyeBlinkLeft", P), u(A.current, "eyeBlinkRight", P), u(
|
|
831
|
+
u(A.current, "eyeBlinkLeft", P), u(A.current, "eyeBlinkRight", P), u(M.current, "eyeBlinkLeft", P), u(M.current, "eyeBlinkRight", P), u(F.current, "eyeBlinkLeft", P), u(F.current, "eyeBlinkRight", P), d = P * $n.browInnerUp;
|
|
832
832
|
}
|
|
833
833
|
}
|
|
834
|
-
const D = wt[ee] ?? wt.neutral, ne = D.browInnerUp ?? 0, St = D.browOuterUpLeft ?? 0,
|
|
835
|
-
u(A.current, "browInnerUp", ht), u(
|
|
836
|
-
const
|
|
837
|
-
o > fe && (
|
|
838
|
-
const ye = !U && o >=
|
|
839
|
-
(ye || Ne) && ct.current !==
|
|
840
|
-
const dt = ye ? o -
|
|
841
|
-
if (De.current === "up" ? (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft") + Fe)), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft"))), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight") + Fe)), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight"))), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))) : (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft"))), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft") + Fe)), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight"))), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight") + Fe)), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))), !U && o >=
|
|
834
|
+
const D = wt[ee] ?? wt.neutral, ne = D.browInnerUp ?? 0, St = D.browOuterUpLeft ?? 0, $e = D.browOuterUpRight ?? 0, re = o * Hn, ut = Mt * Math.sin(re), Ce = Mt * 0.7 * Math.sin(re + 0.7), He = Mt * 0.7 * Math.sin(re + 1.3), R = (_) => Math.max(0, Math.min(1, _)), lt = R(ne + ut), je = R(St + Ce), Ge = R($e + He), ht = R(lt + d);
|
|
835
|
+
u(A.current, "browInnerUp", ht), u(M.current, "browInnerUp", ht), u(F.current, "browInnerUp", ht), u(A.current, "browOuterUpLeft", je), u(M.current, "browOuterUpLeft", je), u(F.current, "browOuterUpLeft", je), u(A.current, "browOuterUpRight", Ge), u(M.current, "browOuterUpRight", Ge), u(F.current, "browOuterUpRight", Ge);
|
|
836
|
+
const Je = Me.current, Ue = Je + bt, fe = Ue + Dt;
|
|
837
|
+
o > fe && (Me.current += bt + Dt + Xt);
|
|
838
|
+
const ye = !U && o >= Je && o < Ue, Ne = !U && o >= Ue && o < fe;
|
|
839
|
+
(ye || Ne) && ct.current !== Je && (ct.current = Je, De.current = Math.random() < 0.7 ? "left" : "up");
|
|
840
|
+
const dt = ye ? o - Je : Ne ? bt : 0, oe = ye || Ne ? Math.min(1, dt / bt) : 0, qe = oe <= 0 ? 0 : Math.sin(oe * Math.PI), ft = Ne ? 1 - (o - Ue) / Dt : 1, Lt = ye ? qe : Ne ? qe * ft : 0, Fe = jn * Lt, x = (_) => D[_] ?? 0;
|
|
841
|
+
if (De.current === "up" ? (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft") + Fe)), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft"))), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight") + Fe)), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight"))), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))) : (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft"))), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft") + Fe)), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight"))), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight") + Fe)), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))), !U && o >= Ve.current) {
|
|
842
842
|
de.current = o, Oe.current = Math.random() < 0.5 ? "pucker" : "smile";
|
|
843
|
-
const _ = Oe.current === "pucker" ?
|
|
844
|
-
|
|
843
|
+
const _ = Oe.current === "pucker" ? en : Zt;
|
|
844
|
+
Ve.current = o + _ + _t + Math.random() * (tn - _t);
|
|
845
845
|
}
|
|
846
|
-
const ce = Oe.current === "pucker" ?
|
|
847
|
-
const _ = (
|
|
846
|
+
const ce = Oe.current === "pucker" ? en : Zt, ue = !U && o >= de.current && o < de.current + ce, ze = ue ? (o - de.current) / ce : 0, Re = ze <= 0 ? 0 : ze < 0.5 ? ze * 2 : (() => {
|
|
847
|
+
const _ = (ze - 0.5) * 2;
|
|
848
848
|
return 1 - _ * _ * (3 - 2 * _);
|
|
849
849
|
})(), me = (_) => D[_] ?? 0;
|
|
850
850
|
if (ue)
|
|
851
851
|
if (Oe.current === "pucker") {
|
|
852
852
|
const _ = R(me("mouthPucker") + Gn * Re);
|
|
853
|
-
u(A.current, "mouthPucker", _), u(
|
|
853
|
+
u(A.current, "mouthPucker", _), u(M.current, "mouthPucker", _), u(F.current, "mouthPucker", _);
|
|
854
854
|
} else {
|
|
855
|
-
const _ = R(me("mouthSmileLeft") +
|
|
856
|
-
u(A.current, "mouthSmileLeft", _), u(A.current, "mouthSmileRight", K), u(A.current, "mouthDimpleLeft", P), u(A.current, "mouthDimpleRight", xe), u(
|
|
855
|
+
const _ = R(me("mouthSmileLeft") + nn * Re), K = R(me("mouthSmileRight") + nn * Re), P = R(me("mouthDimpleLeft") + rn * Re), xe = R(me("mouthDimpleRight") + rn * Re);
|
|
856
|
+
u(A.current, "mouthSmileLeft", _), u(A.current, "mouthSmileRight", K), u(A.current, "mouthDimpleLeft", P), u(A.current, "mouthDimpleRight", xe), u(M.current, "mouthSmileLeft", _), u(M.current, "mouthSmileRight", K), u(M.current, "mouthDimpleLeft", P), u(M.current, "mouthDimpleRight", xe), u(F.current, "mouthSmileLeft", _), u(F.current, "mouthSmileRight", K), u(F.current, "mouthDimpleLeft", P), u(F.current, "mouthDimpleRight", xe);
|
|
857
857
|
}
|
|
858
858
|
if (z.current) {
|
|
859
|
-
const _ =
|
|
859
|
+
const _ = v.current ? 0 : Q.rotation[1];
|
|
860
860
|
z.current.rotation.y = at.MathUtils.lerp(
|
|
861
861
|
z.current.rotation.y,
|
|
862
862
|
_,
|
|
863
863
|
0.1
|
|
864
864
|
), 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];
|
|
865
865
|
}
|
|
866
|
-
if (
|
|
867
|
-
const _ =
|
|
868
|
-
for (let le = 0; le <
|
|
869
|
-
const he =
|
|
866
|
+
if (v.current && S.current) {
|
|
867
|
+
const _ = S.current.currentTime, xe = (_ - j.current) * 1e3 - -150;
|
|
868
|
+
for (let le = 0; le < y.current.length; le++) {
|
|
869
|
+
const he = y.current[le];
|
|
870
870
|
xe >= he.vtime && xe < he.vtime + he.vduration && ot(he.viseme, he.weight ?? 1);
|
|
871
871
|
}
|
|
872
|
-
_ > rt.current + 0.5 && (ve(),
|
|
872
|
+
_ > rt.current + 0.5 && (ve(), Xe(!1));
|
|
873
873
|
}
|
|
874
|
-
}), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object:
|
|
874
|
+
}), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: I }) });
|
|
875
875
|
}
|
|
876
876
|
);
|
|
877
877
|
function Qn(g) {
|
|
878
878
|
return g ? g.charAt(0).toUpperCase() + g.slice(1).toLowerCase() : "";
|
|
879
879
|
}
|
|
880
|
-
function
|
|
880
|
+
function sn(g) {
|
|
881
881
|
return g.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
|
|
882
882
|
}
|
|
883
883
|
const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
884
884
|
onNavigationRequested: g,
|
|
885
|
-
agentId:
|
|
886
|
-
presetUserDetails:
|
|
887
|
-
onAvatarReady:
|
|
885
|
+
agentId: v,
|
|
886
|
+
presetUserDetails: y,
|
|
887
|
+
onAvatarReady: S
|
|
888
888
|
}) => {
|
|
889
|
-
const [j, Q] =
|
|
889
|
+
const [j, Q] = L(""), [ee, Qe] = L("male"), [Be, U] = L(""), [rt, ve] = L(!1), Xe = j, G = ee;
|
|
890
890
|
W(() => {
|
|
891
|
-
if (!
|
|
891
|
+
if (!v) {
|
|
892
892
|
ve(!0);
|
|
893
893
|
return;
|
|
894
894
|
}
|
|
895
895
|
let e = !1;
|
|
896
896
|
return (async () => {
|
|
897
|
-
console.log(">> fetchConfig RUNNING for",
|
|
897
|
+
console.log(">> fetchConfig RUNNING for", v);
|
|
898
898
|
try {
|
|
899
|
-
const
|
|
899
|
+
const r = `agent_config_${v}`, i = sessionStorage.getItem(r);
|
|
900
900
|
if (i)
|
|
901
901
|
try {
|
|
902
902
|
const s = JSON.parse(i);
|
|
903
|
-
e || (s.encryptedAgentToken && Q(s.encryptedAgentToken), s.avatarGender &&
|
|
903
|
+
e || (s.encryptedAgentToken && Q(s.encryptedAgentToken), s.avatarGender && Qe(s.avatarGender), s.agent_id && U(s.agent_id), ve(!0));
|
|
904
904
|
return;
|
|
905
905
|
} catch (s) {
|
|
906
|
-
console.error("Failed to parse cached avatar config:", s), sessionStorage.removeItem(
|
|
906
|
+
console.error("Failed to parse cached avatar config:", s), sessionStorage.removeItem(r);
|
|
907
907
|
}
|
|
908
908
|
let t;
|
|
909
|
-
if (Ct.has(
|
|
910
|
-
console.log(">> REUSING in-flight fetch for",
|
|
909
|
+
if (Ct.has(v))
|
|
910
|
+
console.log(">> REUSING in-flight fetch for", v), t = await Ct.get(v);
|
|
911
911
|
else {
|
|
912
912
|
const s = (async () => {
|
|
913
|
-
console.log(">> INITIATING visitedWebsite fetch for",
|
|
914
|
-
const f = { agentId:
|
|
913
|
+
console.log(">> INITIATING visitedWebsite fetch for", v);
|
|
914
|
+
const f = { agentId: v }, w = await fetch(`${nt}/visitedWebsite`, {
|
|
915
915
|
method: "POST",
|
|
916
916
|
headers: { "Content-Type": "application/json" },
|
|
917
917
|
body: JSON.stringify(f)
|
|
918
918
|
});
|
|
919
919
|
if (!w.ok) throw new Error(`Fetch failed: ${w.status}`);
|
|
920
920
|
const k = await w.json();
|
|
921
|
-
return sessionStorage.setItem(
|
|
921
|
+
return sessionStorage.setItem(r, JSON.stringify(k)), k;
|
|
922
922
|
})();
|
|
923
|
-
Ct.set(
|
|
923
|
+
Ct.set(v, s), t = await s;
|
|
924
924
|
}
|
|
925
925
|
if (e) return;
|
|
926
|
-
t && (t.encryptedAgentToken && Q(t.encryptedAgentToken), t.avatarGender &&
|
|
927
|
-
} catch (
|
|
928
|
-
console.error("Failed to fetch avatar config:",
|
|
926
|
+
t && (t.encryptedAgentToken && Q(t.encryptedAgentToken), t.avatarGender && Qe(t.avatarGender), t.agent_id && U(t.agent_id));
|
|
927
|
+
} catch (r) {
|
|
928
|
+
console.error("Failed to fetch avatar config:", r);
|
|
929
929
|
} finally {
|
|
930
930
|
e || ve(!0);
|
|
931
931
|
}
|
|
932
932
|
})(), () => {
|
|
933
933
|
e = !0;
|
|
934
934
|
};
|
|
935
|
-
}, [
|
|
936
|
-
const Ae = On(
|
|
935
|
+
}, [v]);
|
|
936
|
+
const Ae = On(v ?? Be), [q, se] = L(""), [I, _e] = L(""), [H, b] = L("Ready"), [ae, m] = L(!1), [O, z] = L(!1), [A, M] = L([]), [F, Y] = L(""), X = c(null), [yt, te] = L(
|
|
937
937
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
938
938
|
);
|
|
939
939
|
W(() => {
|
|
940
|
-
const e = window.matchMedia("(max-width: 480px)"),
|
|
941
|
-
return e.addEventListener("change",
|
|
940
|
+
const e = window.matchMedia("(max-width: 480px)"), n = () => te(e.matches);
|
|
941
|
+
return e.addEventListener("change", n), () => e.removeEventListener("change", n);
|
|
942
942
|
}, []);
|
|
943
|
-
const J = yt ? 80 : 600, V = c(!1), Ee = c([]), Ze = c(0),
|
|
943
|
+
const J = yt ? 80 : 600, V = c(!1), Ee = c([]), Ze = c(0), We = c(!1), Ie = c([]), we = c(null), Me = c([]);
|
|
944
944
|
c([]);
|
|
945
|
-
const ct = c([]), De = c(0),
|
|
945
|
+
const ct = c([]), De = c(0), Ve = c(0), de = c(0), Oe = c(0), ke = c(!1), [ot, it] = L(
|
|
946
946
|
null
|
|
947
|
-
), p = c(null), [h, a] =
|
|
947
|
+
), p = c(null), [h, a] = L("neutral"), [o, d] = L(""), [D, ne] = L(""), [St, $e] = L("Chat with us"), [re, ut] = L(
|
|
948
948
|
null
|
|
949
|
-
), [Ce,
|
|
950
|
-
|
|
951
|
-
const [ht,
|
|
949
|
+
), [Ce, He] = L("hidden"), [R, lt] = L(""), je = c(null), Ge = c(Ce);
|
|
950
|
+
Ge.current = Ce;
|
|
951
|
+
const [ht, Je] = L(null), Ue = c(null), fe = c(null), [ye, Ne] = L(!1), dt = c(null), [oe, qe] = L("hidden"), [ft, Lt] = L(""), Fe = c(oe);
|
|
952
952
|
Fe.current = oe;
|
|
953
|
-
const x = c(""), ce = c(!1), ue = c(""),
|
|
953
|
+
const x = c(""), ce = c(!1), ue = c(""), ze = c(Date.now()), Re = c([]), me = c(!1), [_, K] = L(!1), [P, xe] = L(!1), le = c(null), he = Ut(() => ye ? "Try again" : H === "Busy" ? "Busy" : H === "Thinking..." || H === "Processing Voice..." ? H : re != null && re !== "" && re !== "none" && re !== "<none>" ? `Enter ${Qn(re)}` : oe !== "hidden" || !P ? null : on, [H, re, ye, oe, P]), Nt = !ye && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (re == null || re === "" || re === "none" || re === "<none>");
|
|
954
954
|
W(() => {
|
|
955
955
|
if (oe !== "hidden" || !Nt) {
|
|
956
956
|
xe(!1), le.current != null && (clearTimeout(le.current), le.current = null);
|
|
@@ -964,13 +964,13 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
964
964
|
}, [oe, Nt]);
|
|
965
965
|
const mt = he != null && he !== "";
|
|
966
966
|
W(() => {
|
|
967
|
-
const e =
|
|
967
|
+
const e = Ge.current;
|
|
968
968
|
if (!(e === "exiting" || e === "entering")) {
|
|
969
969
|
if (e === "hidden") {
|
|
970
|
-
mt && (lt(he ?? ""),
|
|
970
|
+
mt && (lt(he ?? ""), He("entering"));
|
|
971
971
|
return;
|
|
972
972
|
}
|
|
973
|
-
e === "visible" && (!mt || he !== R) && (
|
|
973
|
+
e === "visible" && (!mt || he !== R) && (je.current = mt ? he : null, He("exiting"));
|
|
974
974
|
}
|
|
975
975
|
}, [
|
|
976
976
|
mt,
|
|
@@ -992,14 +992,14 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
992
992
|
const e = setTimeout(() => Ne(!1), 2500);
|
|
993
993
|
return () => clearTimeout(e);
|
|
994
994
|
}, [ye]);
|
|
995
|
-
const
|
|
996
|
-
const e =
|
|
995
|
+
const an = tt(() => {
|
|
996
|
+
const e = Ge.current;
|
|
997
997
|
if (e === "exiting") {
|
|
998
|
-
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
} else e === "entering" &&
|
|
1002
|
-
}, []),
|
|
998
|
+
He("hidden");
|
|
999
|
+
const n = je.current;
|
|
1000
|
+
je.current = null, n != null && n !== "" && (lt(n), He("entering"));
|
|
1001
|
+
} else e === "entering" && He("visible");
|
|
1002
|
+
}, []), Ft = (e) => {
|
|
1003
1003
|
if (!e) return;
|
|
1004
1004
|
if (e.mood != null) {
|
|
1005
1005
|
const t = String(e.mood).toLowerCase();
|
|
@@ -1019,25 +1019,25 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1019
1019
|
const t = String(e.navigation).trim();
|
|
1020
1020
|
t !== "" && (g ? g(t) : window.open(t, "_blank"));
|
|
1021
1021
|
}
|
|
1022
|
-
const
|
|
1023
|
-
if (
|
|
1024
|
-
const t =
|
|
1025
|
-
if (
|
|
1022
|
+
const n = e.ask_for || e.lead_capture?.ask_for, r = n ? String(n).trim().toLowerCase() : "", i = r === "none" || r === "<none>";
|
|
1023
|
+
if (n && !i) {
|
|
1024
|
+
const t = r;
|
|
1025
|
+
if (y && (t === "email" && y.email || t === "name" && y.name || t === "phone" && y.phone))
|
|
1026
1026
|
return;
|
|
1027
|
-
ut(t || null),
|
|
1028
|
-
} else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (ut(null), St !== "Chat with us" &&
|
|
1027
|
+
ut(t || null), $e(t === "email" ? "Enter your email" : t === "name" ? "Enter your name" : t === "phone" ? "Enter your phone number" : "Chat with us");
|
|
1028
|
+
} else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (ut(null), St !== "Chat with us" && $e("Chat with us"));
|
|
1029
1029
|
e.collected, e.valid;
|
|
1030
1030
|
}, cn = (e) => {
|
|
1031
|
-
const
|
|
1032
|
-
if (!
|
|
1033
|
-
if (
|
|
1031
|
+
const n = e.trim();
|
|
1032
|
+
if (!n) return null;
|
|
1033
|
+
if (n.startsWith("{"))
|
|
1034
1034
|
try {
|
|
1035
|
-
return JSON.parse(
|
|
1035
|
+
return JSON.parse(n);
|
|
1036
1036
|
} catch {
|
|
1037
1037
|
return null;
|
|
1038
1038
|
}
|
|
1039
|
-
if (
|
|
1040
|
-
const
|
|
1039
|
+
if (n.includes(":")) {
|
|
1040
|
+
const r = n.split(":"), i = r[0].trim().toLowerCase(), t = r.slice(1).join(":").trim();
|
|
1041
1041
|
return { [i]: t };
|
|
1042
1042
|
}
|
|
1043
1043
|
return null;
|
|
@@ -1046,20 +1046,20 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1046
1046
|
for (; x.current.includes(`
|
|
1047
1047
|
`); ) {
|
|
1048
1048
|
const e = x.current.indexOf(`
|
|
1049
|
-
`),
|
|
1049
|
+
`), n = x.current.slice(0, e).trim();
|
|
1050
1050
|
x.current = x.current.slice(e + 1);
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1051
|
+
const r = cn(n);
|
|
1052
|
+
r && Ft(r);
|
|
1053
1053
|
}
|
|
1054
|
-
},
|
|
1054
|
+
}, Pt = (e) => {
|
|
1055
1055
|
if (ce.current)
|
|
1056
1056
|
if (e.includes(Pe)) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
} else e === Pe ? ce.current = !1 : (ue.current += e, _e((
|
|
1057
|
+
const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
|
|
1058
|
+
r && (ue.current += r, _e((t) => t + r)), ce.current = !1, i && (x.current += i, vt());
|
|
1059
|
+
} else e === Pe ? ce.current = !1 : (ue.current += e, _e((n) => n + e));
|
|
1060
1060
|
else if (e.includes(Pe)) {
|
|
1061
|
-
const
|
|
1062
|
-
x.current +=
|
|
1061
|
+
const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
|
|
1062
|
+
x.current += r, vt(), ce.current = !0, i && (ue.current += i, _e((t) => t + i));
|
|
1063
1063
|
} else if (e === Pe) {
|
|
1064
1064
|
ce.current = !0;
|
|
1065
1065
|
return;
|
|
@@ -1091,36 +1091,36 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1091
1091
|
sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
const
|
|
1094
|
+
const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
|
|
1095
1095
|
let i = [];
|
|
1096
|
-
if (
|
|
1096
|
+
if (r)
|
|
1097
1097
|
try {
|
|
1098
|
-
i = JSON.parse(
|
|
1098
|
+
i = JSON.parse(r);
|
|
1099
1099
|
} catch {
|
|
1100
1100
|
i = [];
|
|
1101
1101
|
}
|
|
1102
|
-
i.length === 0 &&
|
|
1102
|
+
i.length === 0 && y && (y.name || y.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${y.name || ""}" , Email is "${y.email || ""}"` }], sessionStorage.setItem(
|
|
1103
1103
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1104
1104
|
JSON.stringify(i)
|
|
1105
|
-
)) :
|
|
1105
|
+
)) : r || sessionStorage.setItem(
|
|
1106
1106
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1107
1107
|
JSON.stringify([])
|
|
1108
1108
|
);
|
|
1109
1109
|
})();
|
|
1110
|
-
}, [
|
|
1110
|
+
}, [y]), W(() => {
|
|
1111
1111
|
const e = () => {
|
|
1112
|
-
|
|
1112
|
+
ze.current = Date.now(), me.current && (me.current = !1, K(!1), M([]), Y(""), _e(""), z(!1));
|
|
1113
1113
|
};
|
|
1114
1114
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
1115
|
-
const
|
|
1116
|
-
if (Date.now() -
|
|
1115
|
+
const n = setInterval(async () => {
|
|
1116
|
+
if (Date.now() - ze.current >= 3e4 && !O && !ae && H === "Ready" && !me.current)
|
|
1117
1117
|
if (me.current = !0, Re.current.length > 0)
|
|
1118
|
-
K(!0),
|
|
1118
|
+
K(!0), M(Re.current);
|
|
1119
1119
|
else
|
|
1120
1120
|
try {
|
|
1121
1121
|
const t = `${nt}/nudgeUser`, s = {
|
|
1122
1122
|
navigationUrl: window.location.href,
|
|
1123
|
-
|
|
1123
|
+
agentId: v
|
|
1124
1124
|
}, f = await fetch(t, {
|
|
1125
1125
|
method: "POST",
|
|
1126
1126
|
headers: {
|
|
@@ -1130,34 +1130,34 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1130
1130
|
});
|
|
1131
1131
|
if (f.ok) {
|
|
1132
1132
|
const k = (await f.json()).nudge_questions;
|
|
1133
|
-
k && k.length > 0 && (N("[NUDGE] Received nudge questions from API:", k), Re.current = k, K(!0),
|
|
1133
|
+
k && k.length > 0 && (N("[NUDGE] Received nudge questions from API:", k), Re.current = k, K(!0), M(k));
|
|
1134
1134
|
}
|
|
1135
1135
|
} catch (t) {
|
|
1136
1136
|
console.error("[NUDGE] Error calling /nudgeUser:", t), me.current = !1;
|
|
1137
1137
|
}
|
|
1138
1138
|
}, 1e3);
|
|
1139
1139
|
return () => {
|
|
1140
|
-
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(
|
|
1140
|
+
window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(n);
|
|
1141
1141
|
};
|
|
1142
|
-
}, [
|
|
1142
|
+
}, [Xe, O, ae, H]), W(() => {
|
|
1143
1143
|
if (A.length === 0) return;
|
|
1144
|
-
let e = 0,
|
|
1144
|
+
let e = 0, n = 0, r = !1, i = 100;
|
|
1145
1145
|
const t = () => {
|
|
1146
1146
|
const s = A[e];
|
|
1147
|
-
if (
|
|
1148
|
-
const f = s.substring(0,
|
|
1149
|
-
Y(f),
|
|
1147
|
+
if (r) {
|
|
1148
|
+
const f = s.substring(0, n - 1);
|
|
1149
|
+
Y(f), n--, i = 50;
|
|
1150
1150
|
} else {
|
|
1151
|
-
const f = s.substring(0,
|
|
1152
|
-
Y(f),
|
|
1151
|
+
const f = s.substring(0, n + 1);
|
|
1152
|
+
Y(f), n++, i = 100;
|
|
1153
1153
|
}
|
|
1154
|
-
!
|
|
1154
|
+
!r && n === s.length ? (r = !0, i = 3e3) : r && n === 0 && (r = !1, e = (e + 1) % A.length, i = 500), X.current = setTimeout(t, i);
|
|
1155
1155
|
};
|
|
1156
1156
|
return t(), () => {
|
|
1157
1157
|
X.current && clearTimeout(X.current);
|
|
1158
1158
|
};
|
|
1159
1159
|
}, [A]);
|
|
1160
|
-
const
|
|
1160
|
+
const Bt = () => {
|
|
1161
1161
|
try {
|
|
1162
1162
|
return JSON.parse(
|
|
1163
1163
|
sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
|
|
@@ -1170,29 +1170,29 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1170
1170
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1171
1171
|
JSON.stringify(e)
|
|
1172
1172
|
);
|
|
1173
|
-
}, [kt, Rt] =
|
|
1173
|
+
}, [kt, Rt] = L(!1), [Wt, xt] = L(0), Se = c(null), pt = c([]), Vt = c(0), [$t, hn] = L(
|
|
1174
1174
|
null
|
|
1175
|
-
), [dn, Tt] =
|
|
1175
|
+
), [dn, Tt] = L(
|
|
1176
1176
|
null
|
|
1177
|
-
), Te = c(null),
|
|
1177
|
+
), Te = c(null), Ye = c(
|
|
1178
1178
|
null
|
|
1179
1179
|
), st = tt((e = !1) => {
|
|
1180
|
-
e && (ke.current = !0, m(!1), b("Ready")),
|
|
1180
|
+
e && (ke.current = !0, m(!1), b("Ready")), Ie.current = [], Ee.current = [], We.current = !1, z(!1), De.current = 0, Ve.current = 0, de.current = 0, Me.current.forEach((n) => {
|
|
1181
1181
|
try {
|
|
1182
|
-
|
|
1182
|
+
n.stop();
|
|
1183
1183
|
} catch {
|
|
1184
1184
|
}
|
|
1185
|
-
}), Ue.current && (clearTimeout(Ue.current), Ue.current = null),
|
|
1185
|
+
}), Ue.current && (clearTimeout(Ue.current), Ue.current = null), Je(null), ne(""), Me.current = [];
|
|
1186
1186
|
}, []), fn = async () => {
|
|
1187
1187
|
try {
|
|
1188
|
-
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }),
|
|
1189
|
-
t.fftSize = 64, i.connect(t), Te.current =
|
|
1188
|
+
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), n = window.AudioContext || window.webkitAudioContext, r = new n(), i = r.createMediaStreamSource(e), t = r.createAnalyser();
|
|
1189
|
+
t.fftSize = 64, i.connect(t), Te.current = r, Ye.current = i, Tt(t);
|
|
1190
1190
|
const s = new MediaRecorder(e);
|
|
1191
1191
|
Se.current = s, pt.current = [], s.ondataavailable = (f) => {
|
|
1192
1192
|
f.data.size > 0 && pt.current.push(f.data);
|
|
1193
1193
|
}, s.onstop = async () => {
|
|
1194
|
-
const f = Date.now() -
|
|
1195
|
-
if (Tt(null),
|
|
1194
|
+
const f = Date.now() - Vt.current;
|
|
1195
|
+
if (Tt(null), Ye.current && (Ye.current.disconnect(), Ye.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), f < 1e3) {
|
|
1196
1196
|
b("Recording too short. Hold or click longer."), m(!1);
|
|
1197
1197
|
return;
|
|
1198
1198
|
}
|
|
@@ -1200,64 +1200,64 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1200
1200
|
type: "audio/wav"
|
|
1201
1201
|
});
|
|
1202
1202
|
await bn(w);
|
|
1203
|
-
},
|
|
1203
|
+
}, Vt.current = Date.now(), s.start(100), Rt(!0), b("Listening...");
|
|
1204
1204
|
} catch (e) {
|
|
1205
1205
|
console.error("Error accessing microphone:", e), b("Mic Access Error");
|
|
1206
1206
|
}
|
|
1207
1207
|
}, mn = () => {
|
|
1208
1208
|
Se.current && Se.current.state !== "inactive" && (Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Rt(!1));
|
|
1209
1209
|
}, pn = () => {
|
|
1210
|
-
Se.current && Se.current.state !== "inactive" && (Se.current.onstop = null, Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Tt(null),
|
|
1210
|
+
Se.current && Se.current.state !== "inactive" && (Se.current.onstop = null, Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Tt(null), Ye.current && (Ye.current.disconnect(), Ye.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), Rt(!1), pt.current = [], b("Ready"));
|
|
1211
1211
|
};
|
|
1212
1212
|
W(() => {
|
|
1213
1213
|
if (!O) return;
|
|
1214
1214
|
const e = () => {
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1217
|
-
const
|
|
1218
|
-
if (!
|
|
1219
|
-
const t =
|
|
1215
|
+
const n = de.current;
|
|
1216
|
+
if (n <= 0) return;
|
|
1217
|
+
const r = we.current, i = De.current;
|
|
1218
|
+
if (!r) return;
|
|
1219
|
+
const t = r.currentTime - i, s = Math.min(Math.max(0, t), n), w = sn(I).trim().length;
|
|
1220
1220
|
if (w <= 0) return;
|
|
1221
1221
|
const k = Math.min(
|
|
1222
|
-
Math.round(s /
|
|
1222
|
+
Math.round(s / n * w),
|
|
1223
1223
|
w
|
|
1224
1224
|
);
|
|
1225
1225
|
it(k);
|
|
1226
1226
|
};
|
|
1227
1227
|
return clearInterval(p.current ?? void 0), p.current = setInterval(e, 90), () => clearInterval(p.current ?? void 0);
|
|
1228
|
-
}, [O,
|
|
1228
|
+
}, [O, I, de.current]), W(() => {
|
|
1229
1229
|
let e;
|
|
1230
1230
|
return kt ? (xt(0), e = window.setInterval(() => {
|
|
1231
|
-
xt((
|
|
1231
|
+
xt((n) => n + 1);
|
|
1232
1232
|
}, 1e3)) : xt(0), () => clearInterval(e);
|
|
1233
1233
|
}, [kt]);
|
|
1234
1234
|
const gn = (e) => {
|
|
1235
|
-
const
|
|
1235
|
+
const n = e.numberOfChannels, r = e.length * n * 2 + 44, i = new ArrayBuffer(r), t = new DataView(i);
|
|
1236
1236
|
let s = 0;
|
|
1237
1237
|
const f = (T) => {
|
|
1238
1238
|
t.setUint16(s, T, !0), s += 2;
|
|
1239
1239
|
}, w = (T) => {
|
|
1240
1240
|
t.setUint32(s, T, !0), s += 4;
|
|
1241
1241
|
};
|
|
1242
|
-
w(1179011410), w(
|
|
1242
|
+
w(1179011410), w(r - 8), w(1163280727), w(544501094), w(16), f(1), f(n), w(e.sampleRate), w(e.sampleRate * 2 * n), f(n * 2), f(16), w(1635017060), w(r - s - 4);
|
|
1243
1243
|
const k = [];
|
|
1244
|
-
for (let T = 0; T <
|
|
1244
|
+
for (let T = 0; T < n; T++) k.push(e.getChannelData(T));
|
|
1245
1245
|
let E = 0;
|
|
1246
|
-
for (; s <
|
|
1247
|
-
for (let T = 0; T <
|
|
1246
|
+
for (; s < r; ) {
|
|
1247
|
+
for (let T = 0; T < n; T++) {
|
|
1248
1248
|
let C = Math.max(-1, Math.min(1, k[T][E]));
|
|
1249
1249
|
C = C < 0 ? C * 32768 : C * 32767, t.setInt16(s, C, !0), s += 2;
|
|
1250
1250
|
}
|
|
1251
1251
|
E++;
|
|
1252
1252
|
}
|
|
1253
1253
|
return new Blob([i], { type: "audio/wav" });
|
|
1254
|
-
}, At = async (e,
|
|
1254
|
+
}, At = async (e, n, r = !1) => {
|
|
1255
1255
|
if (!ke.current) {
|
|
1256
1256
|
if (V.current) {
|
|
1257
1257
|
Ee.current.push({
|
|
1258
1258
|
audio: e,
|
|
1259
|
-
visemes:
|
|
1260
|
-
isNewSegment:
|
|
1259
|
+
visemes: n,
|
|
1260
|
+
isNewSegment: r
|
|
1261
1261
|
});
|
|
1262
1262
|
return;
|
|
1263
1263
|
}
|
|
@@ -1271,18 +1271,18 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1271
1271
|
const w = await t.decodeAudioData(f.buffer.slice(0));
|
|
1272
1272
|
de.current += w.duration;
|
|
1273
1273
|
const k = t.currentTime;
|
|
1274
|
-
let E =
|
|
1275
|
-
const T = !
|
|
1276
|
-
E < k && (E = k + 0.1),
|
|
1274
|
+
let E = Ve.current;
|
|
1275
|
+
const T = !We.current;
|
|
1276
|
+
E < k && (E = k + 0.1), Ve.current = E + w.duration;
|
|
1277
1277
|
const C = t.createBufferSource();
|
|
1278
1278
|
C.buffer = w;
|
|
1279
|
-
let Z =
|
|
1280
|
-
if ((!Z || Z.context !== t) && (Z = t.createAnalyser(), Z.fftSize = 64, Z.connect(t.destination), hn(Z)), C.connect(Z),
|
|
1281
|
-
|
|
1279
|
+
let Z = $t;
|
|
1280
|
+
if ((!Z || Z.context !== t) && (Z = t.createAnalyser(), Z.fftSize = 64, Z.connect(t.destination), hn(Z)), C.connect(Z), Me.current.push(C), ke.current) {
|
|
1281
|
+
Me.current = Me.current.filter(($) => $ !== C);
|
|
1282
1282
|
return;
|
|
1283
1283
|
}
|
|
1284
1284
|
if (T) {
|
|
1285
|
-
|
|
1285
|
+
We.current = !0, z(!0), N(
|
|
1286
1286
|
`[AUDIO] setIsSpeaking(true) - First chunk starting at ${E.toFixed(
|
|
1287
1287
|
3
|
|
1288
1288
|
)}`
|
|
@@ -1296,24 +1296,24 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1296
1296
|
}
|
|
1297
1297
|
C.start(E);
|
|
1298
1298
|
const ie = (E - De.current) * 1e3;
|
|
1299
|
-
|
|
1299
|
+
r && (Oe.current = ie, N(
|
|
1300
1300
|
`[AUDIO] New segment detected at +${ie.toFixed(
|
|
1301
1301
|
0
|
|
1302
1302
|
)}ms. Resetting segment offset.`
|
|
1303
|
-
)),
|
|
1303
|
+
)), n.forEach(($, pe) => {
|
|
1304
1304
|
const B = $.symbol ?? "";
|
|
1305
1305
|
if (B) {
|
|
1306
|
-
const ge = zn(B), Le = Math.round($.start * 1e3),
|
|
1306
|
+
const ge = zn(B), Le = Math.round($.start * 1e3), Ke = Math.round(($.duration ?? 0) * 1e3), zt = Oe.current + Le;
|
|
1307
1307
|
pe < 3 && N(
|
|
1308
1308
|
`[AUDIO] Viseme "${B}": segment_relative=${Le}ms, segment_offset=${Oe.current.toFixed(
|
|
1309
1309
|
0
|
|
1310
|
-
)}ms => vtime=${
|
|
1311
|
-
), ge.forEach((
|
|
1312
|
-
|
|
1313
|
-
viseme:
|
|
1314
|
-
weight:
|
|
1315
|
-
vtime:
|
|
1316
|
-
vduration:
|
|
1310
|
+
)}ms => vtime=${zt}ms`
|
|
1311
|
+
), ge.forEach((Yt) => {
|
|
1312
|
+
Ie.current.push({
|
|
1313
|
+
viseme: Yt.v,
|
|
1314
|
+
weight: Yt.w,
|
|
1315
|
+
vtime: zt,
|
|
1316
|
+
vduration: Ke
|
|
1317
1317
|
});
|
|
1318
1318
|
});
|
|
1319
1319
|
}
|
|
@@ -1328,19 +1328,16 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1328
1328
|
}, bn = async (e) => {
|
|
1329
1329
|
try {
|
|
1330
1330
|
m(!0), K(!1), ue.current = "", _e(""), b("Processing Voice...");
|
|
1331
|
-
const
|
|
1331
|
+
const n = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(n), t = gn(i), s = new FileReader();
|
|
1332
1332
|
s.readAsDataURL(t), s.onloadend = async () => {
|
|
1333
1333
|
const f = s.result.split(",")[1];
|
|
1334
1334
|
st(), se(""), x.current = "", ce.current = !1;
|
|
1335
|
-
const w = `${nt}/stt?token=${encodeURIComponent(
|
|
1336
|
-
We
|
|
1337
|
-
)}`, k = await fetch(w, {
|
|
1335
|
+
const w = `${nt}/stt?token=${encodeURIComponent(Xe)}`, k = await fetch(w, {
|
|
1338
1336
|
method: "POST",
|
|
1339
1337
|
headers: { "Content-Type": "application/json" },
|
|
1340
1338
|
body: JSON.stringify({
|
|
1341
1339
|
audio_base64: f,
|
|
1342
|
-
audio_format: "wav"
|
|
1343
|
-
agentId: y
|
|
1340
|
+
audio_format: "wav"
|
|
1344
1341
|
})
|
|
1345
1342
|
});
|
|
1346
1343
|
if (k.status === 429) {
|
|
@@ -1378,12 +1375,12 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1378
1375
|
break;
|
|
1379
1376
|
case "text": {
|
|
1380
1377
|
const ge = B.delta ?? B.text ?? "";
|
|
1381
|
-
ge &&
|
|
1378
|
+
ge && Pt(ge);
|
|
1382
1379
|
break;
|
|
1383
1380
|
}
|
|
1384
1381
|
case "audio": {
|
|
1385
|
-
const ge = B.chunk, Le = B.visemes ?? [],
|
|
1386
|
-
ge && await At(ge, Le,
|
|
1382
|
+
const ge = B.chunk, Le = B.visemes ?? [], Ke = !!B.is_new_segment;
|
|
1383
|
+
ge && await At(ge, Le, Ke);
|
|
1387
1384
|
break;
|
|
1388
1385
|
}
|
|
1389
1386
|
case "done": {
|
|
@@ -1406,8 +1403,8 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1406
1403
|
`);
|
|
1407
1404
|
Z = ge.pop() ?? "";
|
|
1408
1405
|
for (const Le of ge) {
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1406
|
+
const Ke = et(Le);
|
|
1407
|
+
Ke && await $(Ke.event, Ke.data);
|
|
1411
1408
|
}
|
|
1412
1409
|
if (pe) {
|
|
1413
1410
|
if (Z.trim()) {
|
|
@@ -1419,17 +1416,17 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1419
1416
|
}
|
|
1420
1417
|
}
|
|
1421
1418
|
};
|
|
1422
|
-
} catch (
|
|
1423
|
-
console.error("Audio Submission Error:",
|
|
1419
|
+
} catch (n) {
|
|
1420
|
+
console.error("Audio Submission Error:", n), b("STT Failed"), m(!1);
|
|
1424
1421
|
}
|
|
1425
1422
|
}, _n = async (e) => {
|
|
1426
1423
|
e && e.preventDefault(), K(!1), ue.current = "", _e(""), !(!q || ae) && await wn(q);
|
|
1427
1424
|
}, et = (e) => {
|
|
1428
|
-
const
|
|
1429
|
-
let
|
|
1430
|
-
for (const s of
|
|
1431
|
-
s.startsWith("event:") ?
|
|
1432
|
-
if (!
|
|
1425
|
+
const n = e.split(/\r?\n/);
|
|
1426
|
+
let r = "", i = "";
|
|
1427
|
+
for (const s of n)
|
|
1428
|
+
s.startsWith("event:") ? r = s.slice(6).trim() : s.startsWith("data:") && (i = s.slice(5).trim());
|
|
1429
|
+
if (!r) return null;
|
|
1433
1430
|
let t = {};
|
|
1434
1431
|
if (i)
|
|
1435
1432
|
try {
|
|
@@ -1437,51 +1434,55 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1437
1434
|
} catch {
|
|
1438
1435
|
t = { raw: i };
|
|
1439
1436
|
}
|
|
1440
|
-
return { event:
|
|
1441
|
-
}, gt = (e,
|
|
1437
|
+
return { event: r, data: t };
|
|
1438
|
+
}, gt = (e, n) => {
|
|
1442
1439
|
switch (e) {
|
|
1443
1440
|
case "connected":
|
|
1444
1441
|
x.current = "", ce.current = !1;
|
|
1445
1442
|
break;
|
|
1446
1443
|
case "text": {
|
|
1447
|
-
const
|
|
1448
|
-
|
|
1444
|
+
const r = n.delta ?? "";
|
|
1445
|
+
r && Pt(r);
|
|
1446
|
+
break;
|
|
1447
|
+
}
|
|
1448
|
+
case "metadata": {
|
|
1449
|
+
Ft(n);
|
|
1449
1450
|
break;
|
|
1450
1451
|
}
|
|
1451
1452
|
case "audio": {
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1453
|
+
const r = n.chunk, i = n.visemes ?? [], t = n.is_new_segment ?? !1;
|
|
1454
|
+
r && At(r, i, t);
|
|
1454
1455
|
break;
|
|
1455
1456
|
}
|
|
1456
1457
|
case "done": {
|
|
1457
|
-
const
|
|
1458
|
-
...
|
|
1458
|
+
const r = Bt(), i = ue.current.trim(), t = [
|
|
1459
|
+
...r,
|
|
1459
1460
|
{ role: "user", content: q || "..." },
|
|
1460
1461
|
{ role: "assistant", content: i }
|
|
1461
1462
|
];
|
|
1462
|
-
ln(t), ct.current = [...
|
|
1463
|
+
ln(t), ct.current = [...Ie.current], b("Ready"), m(!1), se("");
|
|
1463
1464
|
break;
|
|
1464
1465
|
}
|
|
1465
1466
|
case "error": {
|
|
1466
|
-
const
|
|
1467
|
-
ue.current =
|
|
1467
|
+
const r = n.message ?? "Unknown error";
|
|
1468
|
+
ue.current = r, _e(r), b("Agent Failed"), m(!1);
|
|
1468
1469
|
break;
|
|
1469
1470
|
}
|
|
1470
1471
|
}
|
|
1471
|
-
},
|
|
1472
|
+
}, Ht = async (e, n) => {
|
|
1472
1473
|
m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
|
|
1473
1474
|
try {
|
|
1474
|
-
const
|
|
1475
|
+
const r = await fetch(e, {
|
|
1475
1476
|
method: "POST",
|
|
1476
1477
|
headers: { "Content-Type": "application/json" },
|
|
1477
|
-
body: JSON.stringify(
|
|
1478
|
+
body: JSON.stringify(n)
|
|
1478
1479
|
});
|
|
1479
|
-
if (
|
|
1480
|
+
if (r.status === 429) {
|
|
1480
1481
|
b("Busy"), m(!1);
|
|
1481
1482
|
return;
|
|
1482
1483
|
}
|
|
1483
|
-
if (!
|
|
1484
|
-
const i =
|
|
1484
|
+
if (!r.ok) throw new Error("Request failed");
|
|
1485
|
+
const i = r.body;
|
|
1485
1486
|
if (!i) {
|
|
1486
1487
|
b("Failed"), m(!1);
|
|
1487
1488
|
return;
|
|
@@ -1510,38 +1511,35 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1510
1511
|
break;
|
|
1511
1512
|
}
|
|
1512
1513
|
}
|
|
1513
|
-
} catch (
|
|
1514
|
-
console.error("Streaming Error:",
|
|
1514
|
+
} catch (r) {
|
|
1515
|
+
console.error("Streaming Error:", r), b("Failed"), m(!1);
|
|
1515
1516
|
}
|
|
1516
|
-
},
|
|
1517
|
-
const
|
|
1518
|
-
await
|
|
1519
|
-
}, []),
|
|
1517
|
+
}, jt = tt(async (e, n) => {
|
|
1518
|
+
const r = `${nt}/avatar_tts`;
|
|
1519
|
+
await Ht(r, { user_query: e, llm_prompt: n });
|
|
1520
|
+
}, []), Gt = tt(async (e, n, r, i) => {
|
|
1520
1521
|
const t = `${nt}/avatar_ttsWithKnowledge`;
|
|
1521
|
-
await
|
|
1522
|
-
}, []),
|
|
1522
|
+
await Ht(t, { user_query: e, llm_prompt: n, knowledge: r, history: i });
|
|
1523
|
+
}, []), Jt = c(!1);
|
|
1523
1524
|
W(() => {
|
|
1524
|
-
|
|
1525
|
-
}, [
|
|
1525
|
+
S && !Jt.current && (S({ avatarSpeak: jt, avatarRespond: Gt }), Jt.current = !0);
|
|
1526
|
+
}, [S, jt, Gt]);
|
|
1526
1527
|
const wn = async (e) => {
|
|
1527
1528
|
m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
|
|
1528
|
-
const
|
|
1529
|
-
We
|
|
1530
|
-
)}`;
|
|
1529
|
+
const n = `${nt}/agent/chat?token=${encodeURIComponent(Xe)}`;
|
|
1531
1530
|
try {
|
|
1532
|
-
const
|
|
1531
|
+
const r = Bt();
|
|
1533
1532
|
let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
|
|
1534
|
-
i || (
|
|
1533
|
+
i || (Mn(
|
|
1535
1534
|
"[CHAT] Session UID missing at send time! Generating emergency backup."
|
|
1536
1535
|
), i = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i));
|
|
1537
1536
|
const t = {
|
|
1538
|
-
history:
|
|
1537
|
+
history: r,
|
|
1539
1538
|
question: e,
|
|
1540
|
-
lead_id: i
|
|
1541
|
-
agentId: y
|
|
1539
|
+
lead_id: i
|
|
1542
1540
|
};
|
|
1543
1541
|
N("[CHAT] Sending payload:", t);
|
|
1544
|
-
const s = await fetch(
|
|
1542
|
+
const s = await fetch(n, {
|
|
1545
1543
|
method: "POST",
|
|
1546
1544
|
headers: {
|
|
1547
1545
|
"Content-Type": "application/json"
|
|
@@ -1592,20 +1590,20 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1592
1590
|
break;
|
|
1593
1591
|
}
|
|
1594
1592
|
}
|
|
1595
|
-
} catch (
|
|
1596
|
-
console.error("Chat Error:",
|
|
1593
|
+
} catch (r) {
|
|
1594
|
+
console.error("Chat Error:", r), b("Agent Failed"), m(!1);
|
|
1597
1595
|
}
|
|
1598
|
-
}, yn =
|
|
1596
|
+
}, yn = I.trim(), qt = sn(yn), Et = qt && O ? qt.slice(
|
|
1599
1597
|
0,
|
|
1600
1598
|
ot != null && ot > 0 ? ot : 0
|
|
1601
1599
|
) : "";
|
|
1602
1600
|
W(() => {
|
|
1603
1601
|
const e = Fe.current;
|
|
1604
|
-
e !== "exiting" && (Et ? (Lt(Et), e === "hidden" &&
|
|
1602
|
+
e !== "exiting" && (Et ? (Lt(Et), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
|
|
1605
1603
|
}, [Et, oe]);
|
|
1606
1604
|
const Sn = tt(() => {
|
|
1607
1605
|
const e = Fe.current;
|
|
1608
|
-
e === "entering" ?
|
|
1606
|
+
e === "entering" ? qe("visible") : e === "exiting" && qe("hidden");
|
|
1609
1607
|
}, []);
|
|
1610
1608
|
An(() => {
|
|
1611
1609
|
const e = dt.current;
|
|
@@ -1618,8 +1616,8 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1618
1616
|
"div",
|
|
1619
1617
|
{
|
|
1620
1618
|
className: `avatar-thinking-tab${Ce === "exiting" ? " avatar-thinking-tab--exiting" : Ce === "entering" ? " avatar-thinking-tab--entering" : ""}`,
|
|
1621
|
-
onAnimationEnd:
|
|
1622
|
-
children: R ===
|
|
1619
|
+
onAnimationEnd: an,
|
|
1620
|
+
children: R === on ? /* @__PURE__ */ l(
|
|
1623
1621
|
"a",
|
|
1624
1622
|
{
|
|
1625
1623
|
href: "https://leads.streamoji.com",
|
|
@@ -1679,7 +1677,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1679
1677
|
minWidth: 0
|
|
1680
1678
|
},
|
|
1681
1679
|
children: [
|
|
1682
|
-
/* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(
|
|
1680
|
+
/* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Kt, { analyser: dn }) }),
|
|
1683
1681
|
/* @__PURE__ */ be(
|
|
1684
1682
|
"span",
|
|
1685
1683
|
{
|
|
@@ -1693,9 +1691,9 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1693
1691
|
fontVariantNumeric: "tabular-nums"
|
|
1694
1692
|
},
|
|
1695
1693
|
children: [
|
|
1696
|
-
Math.floor(
|
|
1694
|
+
Math.floor(Wt / 60),
|
|
1697
1695
|
":",
|
|
1698
|
-
String(
|
|
1696
|
+
String(Wt % 60).padStart(2, "0")
|
|
1699
1697
|
]
|
|
1700
1698
|
}
|
|
1701
1699
|
)
|
|
@@ -1737,7 +1735,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1737
1735
|
alignItems: "center",
|
|
1738
1736
|
paddingRight: "8px"
|
|
1739
1737
|
},
|
|
1740
|
-
children: /* @__PURE__ */ l(
|
|
1738
|
+
children: /* @__PURE__ */ l(Kt, { analyser: $t })
|
|
1741
1739
|
}
|
|
1742
1740
|
),
|
|
1743
1741
|
/* @__PURE__ */ l(
|
|
@@ -1915,16 +1913,16 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1915
1913
|
Kn,
|
|
1916
1914
|
{
|
|
1917
1915
|
avatarUrl: Ae,
|
|
1918
|
-
isPlayingRef:
|
|
1919
|
-
visemeQueueRef:
|
|
1916
|
+
isPlayingRef: We,
|
|
1917
|
+
visemeQueueRef: Ie,
|
|
1920
1918
|
audioContextRef: we,
|
|
1921
1919
|
responseAudioStartTimeRef: De,
|
|
1922
1920
|
adjustments: Bn,
|
|
1923
1921
|
mood: h,
|
|
1924
1922
|
expression: o,
|
|
1925
|
-
agentResponse:
|
|
1923
|
+
agentResponse: I,
|
|
1926
1924
|
isSpeaking: O,
|
|
1927
|
-
nextStartTimeRef:
|
|
1925
|
+
nextStartTimeRef: Ve,
|
|
1928
1926
|
stopPlayback: st,
|
|
1929
1927
|
setIsSpeaking: z,
|
|
1930
1928
|
expressionUrl: D,
|
|
@@ -1942,16 +1940,16 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
|
|
|
1942
1940
|
] }) : null;
|
|
1943
1941
|
}, or = ({
|
|
1944
1942
|
agentId: g,
|
|
1945
|
-
onNavigationRequested:
|
|
1946
|
-
presetUserDetails:
|
|
1947
|
-
onAvatarReady:
|
|
1943
|
+
onNavigationRequested: v,
|
|
1944
|
+
presetUserDetails: y,
|
|
1945
|
+
onAvatarReady: S
|
|
1948
1946
|
}) => /* @__PURE__ */ l(
|
|
1949
1947
|
Xn,
|
|
1950
1948
|
{
|
|
1951
1949
|
agentId: g,
|
|
1952
|
-
onNavigationRequested:
|
|
1953
|
-
presetUserDetails:
|
|
1954
|
-
onAvatarReady:
|
|
1950
|
+
onNavigationRequested: v,
|
|
1951
|
+
presetUserDetails: y,
|
|
1952
|
+
onAvatarReady: S
|
|
1955
1953
|
}
|
|
1956
1954
|
);
|
|
1957
1955
|
export {
|