@streamoji/avatar-widget 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/avatar-widget.cjs +5 -5
- package/dist/avatar-widget.js +147 -145
- package/dist/avatar-widget.umd.js +12 -12
- package/package.json +1 -1
package/dist/avatar-widget.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as m, jsxs as ge } from "react/jsx-runtime";
|
|
2
|
-
import { useGLTF as
|
|
2
|
+
import { useGLTF as Ut, Environment as Rn } from "@react-three/drei";
|
|
3
3
|
import { useFrame as xn, Canvas as Tn, useThree as Mn } from "@react-three/fiber";
|
|
4
|
-
import { memo as En, useMemo as
|
|
5
|
-
import * as
|
|
4
|
+
import { memo as En, useMemo as Vt, useRef as s, useState as L, useEffect as F, useCallback as ct, useLayoutEffect as In, Suspense as An } from "react";
|
|
5
|
+
import * as pt from "three";
|
|
6
6
|
import { GLTFLoader as On } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
7
|
-
const
|
|
7
|
+
const ut = "https://ai.streamoji.com", N = (...f) => {
|
|
8
8
|
}, Zt = ({ analyser: f }) => {
|
|
9
9
|
const _ = s(null), k = s(null);
|
|
10
10
|
return F(() => {
|
|
@@ -18,7 +18,7 @@ const ct = "https://ai.streamoji.com", N = (...f) => {
|
|
|
18
18
|
Y = requestAnimationFrame(Ke), (w.width !== w.offsetWidth || w.height !== w.offsetHeight) && (w.width = w.offsetWidth, w.height = w.offsetHeight);
|
|
19
19
|
const $e = w.width, C = w.height;
|
|
20
20
|
if ($e === 0 || C === 0) return;
|
|
21
|
-
const
|
|
21
|
+
const lt = C / 2;
|
|
22
22
|
H.clearRect(0, 0, $e, C), H.fillStyle = "#1e293b";
|
|
23
23
|
const Se = 2, j = Se + 2, Re = $e * 0.95, ne = Math.floor(Re / j);
|
|
24
24
|
(!k.current || k.current.length !== ne) && (k.current = new Float32Array(ne).fill(2));
|
|
@@ -41,7 +41,7 @@ const ct = "https://ai.streamoji.com", N = (...f) => {
|
|
|
41
41
|
for (let h = 0; h < ne; h++) {
|
|
42
42
|
const A = ne - 1 - h, y = Math.max(P[h], P[A]), T = k.current[h] + (y - k.current[h]) * 0.3;
|
|
43
43
|
k.current[h] = T;
|
|
44
|
-
const O = E + h * j, D =
|
|
44
|
+
const O = E + h * j, D = lt - T / 2;
|
|
45
45
|
H.beginPath(), H.roundRect ? H.roundRect(O, D, Se, T, 4) : H.fillRect(O, D, Se, T), H.fill();
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -265,7 +265,7 @@ const Nn = [
|
|
|
265
265
|
rotation: [0.15, 0.02, 0]
|
|
266
266
|
}, Vn = [-0.45, 1.9, 0.1], Wn = [-0.45, 1.75, 0.1], Hn = {
|
|
267
267
|
browInnerUp: 0.2
|
|
268
|
-
},
|
|
268
|
+
}, Ft = 0.18, jn = 1, Gn = 0.5, tn = 3, St = 0.55, Pt = 0.12, nn = 2, rn = 2, Rt = 4, on = 8, Jn = 1, sn = 0.38, an = 0.32, cn = "__branding__", xt = {
|
|
269
269
|
neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
|
|
270
270
|
happy: {
|
|
271
271
|
mouthSmileLeft: 0.2,
|
|
@@ -551,7 +551,7 @@ const Nn = [
|
|
|
551
551
|
{ v: "CH", w: 0.1 }
|
|
552
552
|
// c, x (affricate-ish)
|
|
553
553
|
]
|
|
554
|
-
},
|
|
554
|
+
}, Bt = new Set(
|
|
555
555
|
dn.flatMap((f) => [
|
|
556
556
|
...Object.keys(f.mix),
|
|
557
557
|
...f.teethMix ? Object.keys(f.teethMix) : []
|
|
@@ -597,34 +597,34 @@ const Qn = En(
|
|
|
597
597
|
expression: Ke,
|
|
598
598
|
agentResponse: $e,
|
|
599
599
|
isSpeaking: C,
|
|
600
|
-
nextStartTimeRef:
|
|
600
|
+
nextStartTimeRef: lt,
|
|
601
601
|
stopPlayback: Se,
|
|
602
|
-
setIsSpeaking:
|
|
602
|
+
setIsSpeaking: Qe,
|
|
603
603
|
expressionUrl: j,
|
|
604
604
|
onExpressionFinished: Re,
|
|
605
605
|
isNudgeResponse: ne,
|
|
606
606
|
avatarGender: Ve
|
|
607
607
|
}) => {
|
|
608
|
-
const { scene: E } =
|
|
608
|
+
const { scene: E } = Ut(f), Ae = Ut(Ve === "female" ? Un : Nn), G = Vt(
|
|
609
609
|
() => Ae.flatMap((g) => g.animations),
|
|
610
610
|
[Ae]
|
|
611
|
-
), h =
|
|
611
|
+
), h = Ut(Ve === "female" ? Bn : Pn), A = Vt(
|
|
612
612
|
() => h.flatMap((g) => g.animations),
|
|
613
613
|
[h]
|
|
614
|
-
), y = s(null), T = s(null), O = s(null), D = s(null), q = s(null), re = s(null),
|
|
614
|
+
), y = s(null), T = s(null), O = s(null), D = s(null), q = s(null), re = s(null), dt = s([]), [K] = L(() => new pt.AnimationMixer(E)), z = s({}), J = s(null), Xe = s(0), Oe = s(!1), We = s(0), ft = s(!1), _e = s(null), He = s(tn), je = s(-1), De = s("left"), gt = s(Rt + Math.random() * (on - Rt)), we = s(0), xe = s("smile"), Ce = s({});
|
|
615
615
|
F(() => {
|
|
616
616
|
if (!(!G || !E)) {
|
|
617
617
|
if (G.forEach((g, p) => {
|
|
618
618
|
const r = `idle_${p}`;
|
|
619
619
|
if (!z.current[r]) {
|
|
620
620
|
const d = K.clipAction(g, E);
|
|
621
|
-
d.name = r, d.setLoop(
|
|
621
|
+
d.name = r, d.setLoop(pt.LoopOnce, 1), d.clampWhenFinished = !0, z.current[r] = d;
|
|
622
622
|
}
|
|
623
623
|
}), A.forEach((g, p) => {
|
|
624
624
|
const r = `talk_${p}`;
|
|
625
625
|
if (!z.current[r]) {
|
|
626
626
|
const d = K.clipAction(g, E);
|
|
627
|
-
d.name = r, d.setLoop(
|
|
627
|
+
d.name = r, d.setLoop(pt.LoopOnce, 1), d.clampWhenFinished = !0, z.current[r] = d;
|
|
628
628
|
}
|
|
629
629
|
}), G.length > 0) {
|
|
630
630
|
const g = z.current.idle_0, p = J.current && K.existingAction(J.current.getClip());
|
|
@@ -635,15 +635,15 @@ const Qn = En(
|
|
|
635
635
|
};
|
|
636
636
|
}
|
|
637
637
|
}, [G, A, E, K]);
|
|
638
|
-
const
|
|
638
|
+
const Ze = s("");
|
|
639
639
|
F(() => {
|
|
640
|
-
if (!j || !E || j ===
|
|
641
|
-
|
|
640
|
+
if (!j || !E || j === Ze.current) return;
|
|
641
|
+
Ze.current = j, _e.current = j, new On().load(
|
|
642
642
|
j,
|
|
643
643
|
(p) => {
|
|
644
644
|
if (p.animations && p.animations.length > 0) {
|
|
645
645
|
const r = p.animations[0], d = K.clipAction(r, E);
|
|
646
|
-
if (d.name = `EXPR_${j}`, d.setLoop(
|
|
646
|
+
if (d.name = `EXPR_${j}`, d.setLoop(pt.LoopOnce, 1), d.clampWhenFinished = !0, z.current[`EXPR_${j}`] = d, C && _e.current === j) {
|
|
647
647
|
const v = J.current;
|
|
648
648
|
d.reset().fadeIn(0.3).play(), v && v !== d && v.crossFadeTo(d, 0.3, !0), J.current = d, _e.current = null;
|
|
649
649
|
}
|
|
@@ -732,10 +732,10 @@ const Qn = En(
|
|
|
732
732
|
const v = r.morphTargetDictionary;
|
|
733
733
|
v && Object.keys(v).some((oe) => oe.toLowerCase().includes("brow")) && p.push(r);
|
|
734
734
|
}
|
|
735
|
-
}),
|
|
735
|
+
}), dt.current = p, p.length > 0 && N("[ANIMATION] Meshes with brow morphs:", p.length);
|
|
736
736
|
}, [E]);
|
|
737
737
|
const Ne = (g) => {
|
|
738
|
-
const p =
|
|
738
|
+
const p = xt[g] ?? xt.neutral;
|
|
739
739
|
for (const r in p)
|
|
740
740
|
u(T.current, r, p[r]), u(O.current, r, p[r]), u(D.current, r, p[r]);
|
|
741
741
|
};
|
|
@@ -751,30 +751,30 @@ const Qn = En(
|
|
|
751
751
|
const $ = l ? `Hips Y: ${l.position.y.toFixed(4)}` : "Hips not found";
|
|
752
752
|
N(`[ANIMATION] Mixer Time: ${K.time.toFixed(2)}, ${$}`);
|
|
753
753
|
}
|
|
754
|
-
if (K.update(p), r >
|
|
754
|
+
if (K.update(p), r > Xe.current && !Oe.current && (Oe.current = !0, We.current = r), Oe.current) {
|
|
755
755
|
const l = C ? 0.2 : 0.3, $ = (r - We.current) / l;
|
|
756
756
|
if ($ >= 1)
|
|
757
|
-
if (Oe.current = !1,
|
|
757
|
+
if (Oe.current = !1, ft.current) {
|
|
758
758
|
const I = C ? 1 : 2.5;
|
|
759
|
-
|
|
759
|
+
Xe.current = r + I, ft.current = !1;
|
|
760
760
|
} else
|
|
761
|
-
|
|
761
|
+
Xe.current = r + 0.12, ft.current = !0;
|
|
762
762
|
else {
|
|
763
763
|
const I = $ < 0.5 ? $ * 2 : (1 - $) * 2;
|
|
764
764
|
u(T.current, "eyeBlinkLeft", I), u(T.current, "eyeBlinkRight", I), u(O.current, "eyeBlinkLeft", I), u(O.current, "eyeBlinkRight", I), u(D.current, "eyeBlinkLeft", I), u(D.current, "eyeBlinkRight", I), d = I * Hn.browInnerUp;
|
|
765
765
|
}
|
|
766
766
|
}
|
|
767
|
-
const v =
|
|
768
|
-
u(T.current, "browInnerUp", Je), u(O.current, "browInnerUp", Je), u(D.current, "browInnerUp", Je), u(T.current, "browOuterUpLeft",
|
|
769
|
-
const Te = He.current, Fe = Te +
|
|
770
|
-
r >
|
|
771
|
-
const se = !C && r >= Te && r < Fe, de = !C && r >= Fe && r <
|
|
767
|
+
const v = xt[X] ?? xt.neutral, oe = v.browInnerUp ?? 0, ie = v.browOuterUpLeft ?? 0, Tt = v.browOuterUpRight ?? 0, et = r * jn, ce = Ft * Math.sin(et), bt = Ft * 0.7 * Math.sin(et + 0.7), Ue = Ft * 0.7 * Math.sin(et + 1.3), S = (l) => Math.max(0, Math.min(1, l)), tt = S(oe + ce), nt = S(ie + bt), Ge = S(Tt + Ue), Je = S(tt + d);
|
|
768
|
+
u(T.current, "browInnerUp", Je), u(O.current, "browInnerUp", Je), u(D.current, "browInnerUp", Je), u(T.current, "browOuterUpLeft", nt), u(O.current, "browOuterUpLeft", nt), u(D.current, "browOuterUpLeft", nt), u(T.current, "browOuterUpRight", Ge), u(O.current, "browOuterUpRight", Ge), u(D.current, "browOuterUpRight", Ge);
|
|
769
|
+
const Te = He.current, Fe = Te + St, rt = Fe + Pt;
|
|
770
|
+
r > rt && (He.current += St + Pt + tn);
|
|
771
|
+
const se = !C && r >= Te && r < Fe, de = !C && r >= Fe && r < rt;
|
|
772
772
|
(se || de) && je.current !== Te && (je.current = Te, De.current = Math.random() < 0.7 ? "left" : "up");
|
|
773
|
-
const _t = se ? r - Te : de ?
|
|
774
|
-
if (De.current === "up" ? (u(q.current, "eyeLookUpLeft", S(B("eyeLookUpLeft") +
|
|
773
|
+
const _t = se ? r - Te : de ? St : 0, ht = se || de ? Math.min(1, _t / St) : 0, ae = ht <= 0 ? 0 : Math.sin(ht * Math.PI), ot = de ? 1 - (r - Fe) / Pt : 1, wt = se ? ae : de ? ae * ot : 0, it = Gn * wt, B = (l) => v[l] ?? 0;
|
|
774
|
+
if (De.current === "up" ? (u(q.current, "eyeLookUpLeft", S(B("eyeLookUpLeft") + it)), u(q.current, "eyeLookDownLeft", S(B("eyeLookDownLeft"))), u(q.current, "eyeLookOutLeft", S(B("eyeLookOutLeft"))), u(q.current, "eyeLookInLeft", S(B("eyeLookInLeft"))), u(re.current, "eyeLookUpRight", S(B("eyeLookUpRight") + it)), u(re.current, "eyeLookDownRight", S(B("eyeLookDownRight"))), u(re.current, "eyeLookOutRight", S(B("eyeLookOutRight"))), u(re.current, "eyeLookInRight", S(B("eyeLookInRight")))) : (u(q.current, "eyeLookUpLeft", S(B("eyeLookUpLeft"))), u(q.current, "eyeLookDownLeft", S(B("eyeLookDownLeft"))), u(q.current, "eyeLookOutLeft", S(B("eyeLookOutLeft"))), u(q.current, "eyeLookInLeft", S(B("eyeLookInLeft") + it)), u(re.current, "eyeLookUpRight", S(B("eyeLookUpRight"))), u(re.current, "eyeLookDownRight", S(B("eyeLookDownRight"))), u(re.current, "eyeLookOutRight", S(B("eyeLookOutRight") + it)), u(re.current, "eyeLookInRight", S(B("eyeLookInRight")))), !C && r >= gt.current) {
|
|
775
775
|
we.current = r, xe.current = Math.random() < 0.5 ? "pucker" : "smile";
|
|
776
776
|
const l = xe.current === "pucker" ? rn : nn;
|
|
777
|
-
gt.current = r + l +
|
|
777
|
+
gt.current = r + l + Rt + Math.random() * (on - Rt);
|
|
778
778
|
}
|
|
779
779
|
const Z = xe.current === "pucker" ? rn : nn, ue = !C && r >= we.current && r < we.current + Z, ee = ue ? (r - we.current) / Z : 0, Pe = ee <= 0 ? 0 : ee < 0.5 ? ee * 2 : (() => {
|
|
780
780
|
const l = (ee - 0.5) * 2;
|
|
@@ -790,14 +790,14 @@ const Qn = En(
|
|
|
790
790
|
}
|
|
791
791
|
if (y.current) {
|
|
792
792
|
const l = _.current ? 0 : Y.rotation[1];
|
|
793
|
-
y.current.rotation.y =
|
|
793
|
+
y.current.rotation.y = pt.MathUtils.lerp(
|
|
794
794
|
y.current.rotation.y,
|
|
795
795
|
l,
|
|
796
796
|
0.1
|
|
797
797
|
), y.current.position.set(...Y.position), y.current.scale.setScalar(Y.scale), y.current.rotation.x = Y.rotation[0], y.current.rotation.z = Y.rotation[2];
|
|
798
798
|
}
|
|
799
799
|
const le = {};
|
|
800
|
-
if (
|
|
800
|
+
if (Bt.forEach((l) => {
|
|
801
801
|
le[l] = 0;
|
|
802
802
|
}), _.current && w.current) {
|
|
803
803
|
const l = w.current.currentTime, Q = (l - H.current) * 1e3 - -150;
|
|
@@ -805,23 +805,23 @@ const Qn = En(
|
|
|
805
805
|
const ve = k.current[ye];
|
|
806
806
|
if (Q < ve.vtime || Q >= ve.vtime + ve.vduration)
|
|
807
807
|
continue;
|
|
808
|
-
const
|
|
808
|
+
const st = zn(
|
|
809
809
|
Q,
|
|
810
810
|
ve.vtime,
|
|
811
811
|
ve.vduration
|
|
812
|
-
),
|
|
812
|
+
), Mt = `viseme_${ve.viseme}`.toLowerCase(), Ee = dn.find((fe) => fe.key.toLowerCase() === Mt);
|
|
813
813
|
if (!Ee) continue;
|
|
814
|
-
const yt = (ve.weight ?? 1) *
|
|
814
|
+
const yt = (ve.weight ?? 1) * st;
|
|
815
815
|
for (const fe in Ee.mix)
|
|
816
816
|
le[fe] = Math.max(le[fe] ?? 0, Ee.mix[fe] * yt);
|
|
817
817
|
if (Ee.teethMix)
|
|
818
818
|
for (const fe in Ee.teethMix)
|
|
819
819
|
le[fe] = Math.max(le[fe] ?? 0, Ee.teethMix[fe] * yt);
|
|
820
820
|
}
|
|
821
|
-
l >
|
|
821
|
+
l > lt.current + 0.5 && (Se(), Qe(!1));
|
|
822
822
|
}
|
|
823
823
|
const qe = Ce.current;
|
|
824
|
-
|
|
824
|
+
Bt.forEach((l) => {
|
|
825
825
|
const $ = le[l] ?? 0, I = qe[l] ?? 0;
|
|
826
826
|
qe[l] = Math.max(
|
|
827
827
|
0,
|
|
@@ -830,7 +830,7 @@ const Qn = En(
|
|
|
830
830
|
I + ($ - I) * (1 - Math.exp(-20 * p))
|
|
831
831
|
)
|
|
832
832
|
);
|
|
833
|
-
}),
|
|
833
|
+
}), Bt.forEach((l) => {
|
|
834
834
|
const $ = qe[l] ?? 0;
|
|
835
835
|
u(T.current, l, $), u(D.current, l, $), u(O.current, l, $);
|
|
836
836
|
});
|
|
@@ -843,13 +843,13 @@ function Xn(f) {
|
|
|
843
843
|
function ln(f) {
|
|
844
844
|
return f.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
|
|
845
845
|
}
|
|
846
|
-
const
|
|
846
|
+
const $t = /* @__PURE__ */ new Map(), Zn = ({
|
|
847
847
|
onNavigationRequested: f,
|
|
848
848
|
agentId: _,
|
|
849
849
|
presetUserDetails: k,
|
|
850
850
|
onAvatarReady: w
|
|
851
851
|
}) => {
|
|
852
|
-
const [H, Y] = L(""), [X, Ke] = L("male"), [$e, C] = L(""), [
|
|
852
|
+
const [H, Y] = L(""), [X, Ke] = L("male"), [$e, C] = L(""), [lt, Se] = L(!1), [Qe, j] = L(() => typeof window > "u" ? null : sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")), Re = H, ne = X;
|
|
853
853
|
F(() => {
|
|
854
854
|
if (!_) {
|
|
855
855
|
Se(!0);
|
|
@@ -869,12 +869,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
869
869
|
console.error("Failed to parse cached avatar config:", c), sessionStorage.removeItem(n);
|
|
870
870
|
}
|
|
871
871
|
let i;
|
|
872
|
-
if (
|
|
873
|
-
console.log(">> REUSING in-flight fetch for", _), i = await
|
|
872
|
+
if ($t.has(_))
|
|
873
|
+
console.log(">> REUSING in-flight fetch for", _), i = await $t.get(_);
|
|
874
874
|
else {
|
|
875
875
|
const c = (async () => {
|
|
876
876
|
console.log(">> INITIATING visitedWebsite fetch for", _);
|
|
877
|
-
const R = { agentId: _, lead_id: a }, b = await fetch(`${
|
|
877
|
+
const R = { agentId: _, lead_id: a }, b = await fetch(`${ut}/visitedWebsite`, {
|
|
878
878
|
method: "POST",
|
|
879
879
|
headers: { "Content-Type": "application/json" },
|
|
880
880
|
body: JSON.stringify(R)
|
|
@@ -883,7 +883,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
883
883
|
const x = await b.json();
|
|
884
884
|
return sessionStorage.setItem(n, JSON.stringify(x)), x;
|
|
885
885
|
})();
|
|
886
|
-
|
|
886
|
+
$t.set(_, c), i = await c;
|
|
887
887
|
}
|
|
888
888
|
if (e) return;
|
|
889
889
|
i && (i.encryptedAgentToken && Y(i.encryptedAgentToken), i.avatarGender && Ke(i.avatarGender), i.agent_id && C(i.agent_id), i.lead_id && (j(i.lead_id), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i.lead_id)));
|
|
@@ -896,18 +896,18 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
896
896
|
e = !0;
|
|
897
897
|
};
|
|
898
898
|
}, [_]);
|
|
899
|
-
const Ve = Cn(_ ?? $e), [E, be] = L(""), [Ae, G] = L(""), [P, h] = L("Ready"), [A, y] = L(!1), [T, O] = L(!1), [D, q] = L([]), [re,
|
|
899
|
+
const Ve = Cn(_ ?? $e), [E, be] = L(""), [Ae, G] = L(""), [P, h] = L("Ready"), [A, y] = L(!1), [T, O] = L(!1), [D, q] = L([]), [re, dt] = L(""), K = s(null), [z, J] = L(
|
|
900
900
|
() => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
|
|
901
901
|
);
|
|
902
902
|
F(() => {
|
|
903
903
|
const e = window.matchMedia("(max-width: 480px)"), t = () => J(e.matches);
|
|
904
904
|
return e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
905
905
|
}, []);
|
|
906
|
-
const
|
|
906
|
+
const Xe = z ? 80 : 600, Oe = s(!1), We = s([]), ft = s(0), _e = s(!1), He = s([]), je = s(null), De = s([]);
|
|
907
907
|
s([]);
|
|
908
|
-
const gt = s([]), we = s(0), xe = s(0), Ce = s(0),
|
|
908
|
+
const gt = s([]), we = s(0), xe = s(0), Ce = s(0), Ze = s(0), Ne = s(!1), [g, p] = L(
|
|
909
909
|
null
|
|
910
|
-
), r = s(null), [d, v] = L("neutral"), [oe, ie] = L(""), [
|
|
910
|
+
), r = s(null), [d, v] = L("neutral"), [oe, ie] = L(""), [Tt, et] = L(""), [ce, bt] = L(
|
|
911
911
|
() => {
|
|
912
912
|
if (typeof window > "u") return null;
|
|
913
913
|
try {
|
|
@@ -917,11 +917,11 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
917
917
|
return null;
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
), [Ue, S] = L("hidden"), [
|
|
920
|
+
), [Ue, S] = L("hidden"), [tt, nt] = L(""), Ge = s(null), Je = s(Ue);
|
|
921
921
|
Je.current = Ue;
|
|
922
|
-
const [Te, Fe] = L(null),
|
|
922
|
+
const [Te, Fe] = L(null), rt = s(null), se = s(null), [de, _t] = L(!1), ht = s(null), [ae, ot] = L("hidden"), [wt, it] = L(""), B = s(ae);
|
|
923
923
|
B.current = ae;
|
|
924
|
-
const Z = s(""), ue = s(!1), ee = s(""), Pe = s(Date.now()), Me = s([]), le = s(!1), [qe, l] = L(!1), [$, I] = L(!1), Q = s(null), ye =
|
|
924
|
+
const Z = s(""), ue = s(!1), ee = s(""), Pe = s(Date.now()), Me = s([]), le = s(!1), [qe, l] = L(!1), [$, I] = L(!1), Q = s(null), ye = Vt(() => de ? "Try again" : P === "Busy" ? "Busy" : P === "Thinking..." || P === "Processing Voice..." ? P : ce != null && ce !== "" && ce !== "none" && ce !== "<none>" ? `Enter ${Xn(ce)}` : ae !== "hidden" || !$ ? null : cn, [P, ce, de, ae, $]), ve = !de && P !== "Busy" && P !== "Thinking..." && P !== "Processing Voice..." && (ce == null || ce === "" || ce === "none" || ce === "<none>");
|
|
925
925
|
F(() => {
|
|
926
926
|
if (ae !== "hidden" || !ve) {
|
|
927
927
|
I(!1), Q.current != null && (clearTimeout(Q.current), Q.current = null);
|
|
@@ -933,21 +933,21 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
933
933
|
Q.current != null && (clearTimeout(Q.current), Q.current = null);
|
|
934
934
|
};
|
|
935
935
|
}, [ae, ve]);
|
|
936
|
-
const
|
|
936
|
+
const st = ye != null && ye !== "";
|
|
937
937
|
F(() => {
|
|
938
938
|
const e = Je.current;
|
|
939
939
|
if (!(e === "exiting" || e === "entering")) {
|
|
940
940
|
if (e === "hidden") {
|
|
941
|
-
|
|
941
|
+
st && (nt(ye ?? ""), S("entering"));
|
|
942
942
|
return;
|
|
943
943
|
}
|
|
944
|
-
e === "visible" && (!
|
|
944
|
+
e === "visible" && (!st || ye !== tt) && (Ge.current = st ? ye : null, S("exiting"));
|
|
945
945
|
}
|
|
946
946
|
}, [
|
|
947
|
-
|
|
947
|
+
st,
|
|
948
948
|
ye,
|
|
949
949
|
Ue,
|
|
950
|
-
|
|
950
|
+
tt
|
|
951
951
|
]), F(() => {
|
|
952
952
|
if (P !== "Busy") {
|
|
953
953
|
se.current != null && (clearTimeout(se.current), se.current = null);
|
|
@@ -963,12 +963,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
963
963
|
const e = setTimeout(() => _t(!1), 2500);
|
|
964
964
|
return () => clearTimeout(e);
|
|
965
965
|
}, [de]);
|
|
966
|
-
const
|
|
966
|
+
const Mt = ct(() => {
|
|
967
967
|
const e = Je.current;
|
|
968
968
|
if (e === "exiting") {
|
|
969
969
|
S("hidden");
|
|
970
970
|
const t = Ge.current;
|
|
971
|
-
Ge.current = null, t != null && t !== "" && (
|
|
971
|
+
Ge.current = null, t != null && t !== "" && (nt(t), S("entering"));
|
|
972
972
|
} else e === "entering" && S("visible");
|
|
973
973
|
}, []), Ee = (e) => {
|
|
974
974
|
if (!e) return;
|
|
@@ -984,7 +984,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
984
984
|
);
|
|
985
985
|
N(
|
|
986
986
|
`[STREAM] Animation match for "${o}": ${i ? i.name : "NONE"}`
|
|
987
|
-
),
|
|
987
|
+
), et(i?.url ?? "");
|
|
988
988
|
}
|
|
989
989
|
if (e.navigation != null) {
|
|
990
990
|
const o = String(e.navigation).trim();
|
|
@@ -1040,8 +1040,8 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1040
1040
|
return { [a]: o };
|
|
1041
1041
|
}
|
|
1042
1042
|
return null;
|
|
1043
|
-
}, fe =
|
|
1044
|
-
}, []), Be = "§",
|
|
1043
|
+
}, fe = ct(() => {
|
|
1044
|
+
}, []), Be = "§", Et = () => {
|
|
1045
1045
|
for (; Z.current.includes(`
|
|
1046
1046
|
`); ) {
|
|
1047
1047
|
const e = Z.current.indexOf(`
|
|
@@ -1050,20 +1050,20 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1050
1050
|
const n = yt(t);
|
|
1051
1051
|
n && Ee(n);
|
|
1052
1052
|
}
|
|
1053
|
-
},
|
|
1053
|
+
}, Wt = (e) => {
|
|
1054
1054
|
if (ue.current)
|
|
1055
1055
|
if (e.includes(Be)) {
|
|
1056
1056
|
const t = e.indexOf(Be), n = e.slice(0, t), a = e.slice(t + Be.length);
|
|
1057
|
-
n && (ee.current += n, G((o) => o + n)), ue.current = !1, a && (Z.current += a,
|
|
1057
|
+
n && (ee.current += n, G((o) => o + n)), ue.current = !1, a && (Z.current += a, Et());
|
|
1058
1058
|
} else e === Be ? ue.current = !1 : (ee.current += e, G((t) => t + e));
|
|
1059
1059
|
else if (e.includes(Be)) {
|
|
1060
1060
|
const t = e.indexOf(Be), n = e.slice(0, t), a = e.slice(t + Be.length);
|
|
1061
|
-
Z.current += n,
|
|
1061
|
+
Z.current += n, Et(), ue.current = !0, a && (ee.current += a, G((o) => o + a));
|
|
1062
1062
|
} else if (e === Be) {
|
|
1063
1063
|
ue.current = !0;
|
|
1064
1064
|
return;
|
|
1065
1065
|
} else
|
|
1066
|
-
Z.current += e,
|
|
1066
|
+
Z.current += e, Et();
|
|
1067
1067
|
};
|
|
1068
1068
|
F(() => {
|
|
1069
1069
|
(async () => {
|
|
@@ -1085,7 +1085,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1085
1085
|
})();
|
|
1086
1086
|
}, [k]), F(() => {
|
|
1087
1087
|
const e = () => {
|
|
1088
|
-
Pe.current = Date.now(), le.current && (le.current = !1, l(!1), q([]),
|
|
1088
|
+
Pe.current = Date.now(), le.current && (le.current = !1, l(!1), q([]), dt(""), G(""), O(!1));
|
|
1089
1089
|
};
|
|
1090
1090
|
window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
|
|
1091
1091
|
const t = setInterval(async () => {
|
|
@@ -1094,10 +1094,10 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1094
1094
|
l(!0), q(Me.current);
|
|
1095
1095
|
else
|
|
1096
1096
|
try {
|
|
1097
|
-
const o = `${
|
|
1097
|
+
const o = `${ut}/nudgeUser`, i = {
|
|
1098
1098
|
navigationUrl: window.location.href,
|
|
1099
1099
|
agentId: _,
|
|
1100
|
-
lead_id:
|
|
1100
|
+
lead_id: Qe
|
|
1101
1101
|
}, c = await fetch(o, {
|
|
1102
1102
|
method: "POST",
|
|
1103
1103
|
headers: {
|
|
@@ -1123,10 +1123,10 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1123
1123
|
const i = D[e];
|
|
1124
1124
|
if (n) {
|
|
1125
1125
|
const c = i.substring(0, t - 1);
|
|
1126
|
-
|
|
1126
|
+
dt(c), t--, a = 50;
|
|
1127
1127
|
} else {
|
|
1128
1128
|
const c = i.substring(0, t + 1);
|
|
1129
|
-
|
|
1129
|
+
dt(c), t++, a = 100;
|
|
1130
1130
|
}
|
|
1131
1131
|
!n && t === i.length ? (n = !0, a = 3e3) : n && t === 0 && (n = !1, e = (e + 1) % D.length, a = 500), K.current = setTimeout(o, a);
|
|
1132
1132
|
};
|
|
@@ -1134,7 +1134,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1134
1134
|
K.current && clearTimeout(K.current);
|
|
1135
1135
|
};
|
|
1136
1136
|
}, [D]);
|
|
1137
|
-
const
|
|
1137
|
+
const Ht = () => {
|
|
1138
1138
|
try {
|
|
1139
1139
|
return JSON.parse(
|
|
1140
1140
|
sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
|
|
@@ -1147,31 +1147,31 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1147
1147
|
"STREAMOJI_LEADS_SESSION_MESSAGES",
|
|
1148
1148
|
JSON.stringify(e)
|
|
1149
1149
|
);
|
|
1150
|
-
}, [
|
|
1150
|
+
}, [It, At] = L(!1), [jt, Ot] = L(0), Le = s(null), vt = s([]), Gt = s(0), [Jt, hn] = L(
|
|
1151
1151
|
null
|
|
1152
|
-
), [mn,
|
|
1152
|
+
), [mn, Dt] = L(
|
|
1153
1153
|
null
|
|
1154
1154
|
), Ie = s(null), ze = s(
|
|
1155
1155
|
null
|
|
1156
|
-
),
|
|
1156
|
+
), mt = ct((e = !1) => {
|
|
1157
1157
|
e && (Ne.current = !0, y(!1), h("Ready")), He.current = [], We.current = [], _e.current = !1, O(!1), we.current = 0, xe.current = 0, Ce.current = 0, De.current.forEach((t) => {
|
|
1158
1158
|
try {
|
|
1159
1159
|
t.stop();
|
|
1160
1160
|
} catch {
|
|
1161
1161
|
}
|
|
1162
|
-
}),
|
|
1163
|
-
Fe(null),
|
|
1162
|
+
}), rt.current && (clearTimeout(rt.current), rt.current = null), setTimeout(() => {
|
|
1163
|
+
Fe(null), et("");
|
|
1164
1164
|
}, 10), De.current = [];
|
|
1165
1165
|
}, []), pn = async () => {
|
|
1166
1166
|
try {
|
|
1167
1167
|
const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, n = new t(), a = n.createMediaStreamSource(e), o = n.createAnalyser();
|
|
1168
|
-
o.fftSize = 64, a.connect(o), Ie.current = n, ze.current = a,
|
|
1168
|
+
o.fftSize = 64, a.connect(o), Ie.current = n, ze.current = a, Dt(o);
|
|
1169
1169
|
const i = new MediaRecorder(e);
|
|
1170
1170
|
Le.current = i, vt.current = [], i.ondataavailable = (c) => {
|
|
1171
1171
|
c.data.size > 0 && vt.current.push(c.data);
|
|
1172
1172
|
}, i.onstop = async () => {
|
|
1173
|
-
const c = Date.now() -
|
|
1174
|
-
if (
|
|
1173
|
+
const c = Date.now() - Gt.current;
|
|
1174
|
+
if (Dt(null), ze.current && (ze.current.disconnect(), ze.current = null), Ie.current && Ie.current.state !== "closed" && (Ie.current.close(), Ie.current = null), c < 1e3) {
|
|
1175
1175
|
h("Recording too short. Hold or click longer."), y(!1);
|
|
1176
1176
|
return;
|
|
1177
1177
|
}
|
|
@@ -1179,14 +1179,14 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1179
1179
|
type: "audio/wav"
|
|
1180
1180
|
});
|
|
1181
1181
|
await wn(R);
|
|
1182
|
-
},
|
|
1182
|
+
}, Gt.current = Date.now(), i.start(100), At(!0), h("Listening...");
|
|
1183
1183
|
} catch (e) {
|
|
1184
1184
|
console.error("Error accessing microphone:", e), h("Mic Access Error");
|
|
1185
1185
|
}
|
|
1186
1186
|
}, gn = () => {
|
|
1187
|
-
Le.current && Le.current.state !== "inactive" && (Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()),
|
|
1187
|
+
Le.current && Le.current.state !== "inactive" && (Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()), At(!1));
|
|
1188
1188
|
}, bn = () => {
|
|
1189
|
-
Le.current && Le.current.state !== "inactive" && (Le.current.onstop = null, Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()),
|
|
1189
|
+
Le.current && Le.current.state !== "inactive" && (Le.current.onstop = null, Le.current.stop(), Le.current.stream.getTracks().forEach((e) => e.stop()), Dt(null), ze.current && (ze.current.disconnect(), ze.current = null), Ie.current && Ie.current.state !== "closed" && (Ie.current.close(), Ie.current = null), At(!1), vt.current = [], h("Ready"));
|
|
1190
1190
|
};
|
|
1191
1191
|
F(() => {
|
|
1192
1192
|
if (!T) return;
|
|
@@ -1206,10 +1206,10 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1206
1206
|
return clearInterval(r.current ?? void 0), r.current = setInterval(e, 90), () => clearInterval(r.current ?? void 0);
|
|
1207
1207
|
}, [T, Ae, Ce.current]), F(() => {
|
|
1208
1208
|
let e;
|
|
1209
|
-
return
|
|
1210
|
-
|
|
1211
|
-
}, 1e3)) :
|
|
1212
|
-
}, [
|
|
1209
|
+
return It ? (Ot(0), e = window.setInterval(() => {
|
|
1210
|
+
Ot((t) => t + 1);
|
|
1211
|
+
}, 1e3)) : Ot(0), () => clearInterval(e);
|
|
1212
|
+
}, [It]);
|
|
1213
1213
|
const _n = (e) => {
|
|
1214
1214
|
const t = e.numberOfChannels, n = e.length * t * 2 + 44, a = new ArrayBuffer(n), o = new DataView(a);
|
|
1215
1215
|
let i = 0;
|
|
@@ -1230,7 +1230,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1230
1230
|
x++;
|
|
1231
1231
|
}
|
|
1232
1232
|
return new Blob([a], { type: "audio/wav" });
|
|
1233
|
-
},
|
|
1233
|
+
}, Ct = async (e, t, n = !1) => {
|
|
1234
1234
|
if (!Ne.current) {
|
|
1235
1235
|
if (Oe.current) {
|
|
1236
1236
|
We.current.push({
|
|
@@ -1255,7 +1255,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1255
1255
|
x < b && (x = b + 0.1), xe.current = x + R.duration;
|
|
1256
1256
|
const V = o.createBufferSource();
|
|
1257
1257
|
V.buffer = R;
|
|
1258
|
-
let W =
|
|
1258
|
+
let W = Jt;
|
|
1259
1259
|
if ((!W || W.context !== o) && (W = o.createAnalyser(), W.fftSize = 64, W.connect(o.destination), hn(W)), V.connect(W), De.current.push(V), Ne.current) {
|
|
1260
1260
|
De.current = De.current.filter((te) => te !== V);
|
|
1261
1261
|
return;
|
|
@@ -1267,7 +1267,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1267
1267
|
)}`
|
|
1268
1268
|
), we.current = x;
|
|
1269
1269
|
const te = (x - b) * 1e3;
|
|
1270
|
-
|
|
1270
|
+
ft.current = performance.now() + te, N(
|
|
1271
1271
|
`[AUDIO] Response started. Initial startTime: ${x.toFixed(
|
|
1272
1272
|
3
|
|
1273
1273
|
)}, CT: ${b.toFixed(3)}`
|
|
@@ -1275,16 +1275,16 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1275
1275
|
}
|
|
1276
1276
|
V.start(x);
|
|
1277
1277
|
const he = (x - we.current) * 1e3;
|
|
1278
|
-
n && (
|
|
1278
|
+
n && (Ze.current = he, N(
|
|
1279
1279
|
`[AUDIO] New segment detected at +${he.toFixed(
|
|
1280
1280
|
0
|
|
1281
1281
|
)}ms. Resetting segment offset.`
|
|
1282
1282
|
)), t.forEach((te, me) => {
|
|
1283
1283
|
const U = te.symbol ?? "";
|
|
1284
1284
|
if (U) {
|
|
1285
|
-
const pe = Yn(U), ke = Math.round(te.start * 1e3), Ye = Math.round((te.duration ?? 0) * 1e3), Qt =
|
|
1285
|
+
const pe = Yn(U), ke = Math.round(te.start * 1e3), Ye = Math.round((te.duration ?? 0) * 1e3), Qt = Ze.current + ke;
|
|
1286
1286
|
me < 3 && N(
|
|
1287
|
-
`[AUDIO] Viseme "${U}": segment_relative=${ke}ms, segment_offset=${
|
|
1287
|
+
`[AUDIO] Viseme "${U}": segment_relative=${ke}ms, segment_offset=${Ze.current.toFixed(
|
|
1288
1288
|
0
|
|
1289
1289
|
)}ms => vtime=${Qt}ms`
|
|
1290
1290
|
), pe.forEach((Xt) => {
|
|
@@ -1300,7 +1300,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1300
1300
|
} finally {
|
|
1301
1301
|
if (Oe.current = !1, We.current.length > 0) {
|
|
1302
1302
|
const a = We.current.shift();
|
|
1303
|
-
a &&
|
|
1303
|
+
a && Ct(a.audio, a.visemes, a.isNewSegment);
|
|
1304
1304
|
}
|
|
1305
1305
|
}
|
|
1306
1306
|
}
|
|
@@ -1310,13 +1310,14 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1310
1310
|
const t = await e.arrayBuffer(), a = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), o = _n(a), i = new FileReader();
|
|
1311
1311
|
i.readAsDataURL(o), i.onloadend = async () => {
|
|
1312
1312
|
const c = i.result.split(",")[1];
|
|
1313
|
-
|
|
1314
|
-
const R = `${
|
|
1313
|
+
mt(), be(""), Z.current = "", ue.current = !1;
|
|
1314
|
+
const R = `${ut}/stt?token=${encodeURIComponent(Re)}`, b = await fetch(R, {
|
|
1315
1315
|
method: "POST",
|
|
1316
1316
|
headers: { "Content-Type": "application/json" },
|
|
1317
1317
|
body: JSON.stringify({
|
|
1318
1318
|
audio_base64: c,
|
|
1319
|
-
audio_format: "wav"
|
|
1319
|
+
audio_format: "wav",
|
|
1320
|
+
lead_id: Qe
|
|
1320
1321
|
})
|
|
1321
1322
|
});
|
|
1322
1323
|
if (b.status === 429) {
|
|
@@ -1354,12 +1355,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1354
1355
|
break;
|
|
1355
1356
|
case "text": {
|
|
1356
1357
|
const pe = U.delta ?? U.text ?? "";
|
|
1357
|
-
pe &&
|
|
1358
|
+
pe && Wt(pe);
|
|
1358
1359
|
break;
|
|
1359
1360
|
}
|
|
1360
1361
|
case "audio": {
|
|
1361
1362
|
const pe = U.chunk, ke = U.visemes ?? [], Ye = !!U.is_new_segment;
|
|
1362
|
-
pe && await
|
|
1363
|
+
pe && await Ct(pe, ke, Ye);
|
|
1363
1364
|
break;
|
|
1364
1365
|
}
|
|
1365
1366
|
case "done": {
|
|
@@ -1382,12 +1383,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1382
1383
|
`);
|
|
1383
1384
|
W = pe.pop() ?? "";
|
|
1384
1385
|
for (const ke of pe) {
|
|
1385
|
-
const Ye =
|
|
1386
|
+
const Ye = at(ke);
|
|
1386
1387
|
Ye && await te(Ye.event, Ye.data);
|
|
1387
1388
|
}
|
|
1388
1389
|
if (me) {
|
|
1389
1390
|
if (W.trim()) {
|
|
1390
|
-
const ke =
|
|
1391
|
+
const ke = at(W.trim());
|
|
1391
1392
|
ke && await te(ke.event, ke.data);
|
|
1392
1393
|
}
|
|
1393
1394
|
he || (h("Ready"), y(!1));
|
|
@@ -1400,7 +1401,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1400
1401
|
}
|
|
1401
1402
|
}, yn = async (e) => {
|
|
1402
1403
|
e && e.preventDefault(), l(!1), ee.current = "", G(""), !(!E || A) && await vn(E);
|
|
1403
|
-
},
|
|
1404
|
+
}, at = (e) => {
|
|
1404
1405
|
const t = e.split(/\r?\n/);
|
|
1405
1406
|
let n = "", a = "";
|
|
1406
1407
|
for (const i of t)
|
|
@@ -1421,7 +1422,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1421
1422
|
break;
|
|
1422
1423
|
case "text": {
|
|
1423
1424
|
const n = t.delta ?? "";
|
|
1424
|
-
n &&
|
|
1425
|
+
n && Wt(n);
|
|
1425
1426
|
break;
|
|
1426
1427
|
}
|
|
1427
1428
|
case "metadata": {
|
|
@@ -1430,11 +1431,11 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1430
1431
|
}
|
|
1431
1432
|
case "audio": {
|
|
1432
1433
|
const n = t.chunk, a = t.visemes ?? [], o = t.is_new_segment ?? !1;
|
|
1433
|
-
n &&
|
|
1434
|
+
n && Ct(n, a, o);
|
|
1434
1435
|
break;
|
|
1435
1436
|
}
|
|
1436
1437
|
case "done": {
|
|
1437
|
-
const n =
|
|
1438
|
+
const n = Ht(), a = ee.current.trim(), o = [
|
|
1438
1439
|
...n,
|
|
1439
1440
|
{ role: "user", content: E || "..." },
|
|
1440
1441
|
{ role: "assistant", content: a }
|
|
@@ -1448,8 +1449,8 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1448
1449
|
break;
|
|
1449
1450
|
}
|
|
1450
1451
|
}
|
|
1451
|
-
},
|
|
1452
|
-
y(!0), h("Thinking..."), ee.current = "", Z.current = "", ue.current = !1,
|
|
1452
|
+
}, kt = async (e, t) => {
|
|
1453
|
+
y(!0), h("Thinking..."), ee.current = "", Z.current = "", ue.current = !1, mt(), Ce.current = 0, p(0);
|
|
1453
1454
|
try {
|
|
1454
1455
|
const n = await fetch(e, {
|
|
1455
1456
|
method: "POST",
|
|
@@ -1474,12 +1475,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1474
1475
|
`);
|
|
1475
1476
|
c = x.pop() ?? "";
|
|
1476
1477
|
for (const M of x) {
|
|
1477
|
-
const V =
|
|
1478
|
+
const V = at(M);
|
|
1478
1479
|
V && Lt(V.event, V.data);
|
|
1479
1480
|
}
|
|
1480
1481
|
if (R) {
|
|
1481
1482
|
if (c.trim()) {
|
|
1482
|
-
const M =
|
|
1483
|
+
const M = at(c.trim());
|
|
1483
1484
|
M && Lt(M.event, M.data);
|
|
1484
1485
|
}
|
|
1485
1486
|
return h("Ready"), y(!1), ee.current;
|
|
@@ -1488,23 +1489,24 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1488
1489
|
} catch (n) {
|
|
1489
1490
|
return console.error("Streaming Error:", n), h("Failed"), y(!1), "";
|
|
1490
1491
|
}
|
|
1491
|
-
}, qt =
|
|
1492
|
-
const t = `${
|
|
1493
|
-
return await
|
|
1494
|
-
}, []), zt =
|
|
1495
|
-
const a = `${
|
|
1496
|
-
return await
|
|
1497
|
-
}, []), Yt = s(!1);
|
|
1492
|
+
}, qt = ct(async (e) => {
|
|
1493
|
+
const t = `${ut}/avatar_tts`;
|
|
1494
|
+
return await kt(t, { user_query: e });
|
|
1495
|
+
}, [kt]), zt = ct(async (e, t, n) => {
|
|
1496
|
+
const a = `${ut}/avatar_ttsWithKnowledge`;
|
|
1497
|
+
return await kt(a, { user_query: e, knowledge: t, history: n });
|
|
1498
|
+
}, [kt]), Yt = s(!1);
|
|
1498
1499
|
F(() => {
|
|
1499
1500
|
w && !Yt.current && (w({ avatarSpeak: qt, avatarRespond: zt }), Yt.current = !0);
|
|
1500
1501
|
}, [w, qt, zt]);
|
|
1501
1502
|
const vn = async (e) => {
|
|
1502
|
-
y(!0), h("Thinking..."), ee.current = "", Z.current = "", ue.current = !1,
|
|
1503
|
-
const t = `${
|
|
1503
|
+
y(!0), h("Thinking..."), ee.current = "", Z.current = "", ue.current = !1, mt(), Ce.current = 0, p(0);
|
|
1504
|
+
const t = `${ut}/agent/chat?token=${encodeURIComponent(Re)}`;
|
|
1504
1505
|
try {
|
|
1505
1506
|
const a = {
|
|
1506
|
-
history:
|
|
1507
|
-
question: e
|
|
1507
|
+
history: Ht(),
|
|
1508
|
+
question: e,
|
|
1509
|
+
lead_id: Qe
|
|
1508
1510
|
};
|
|
1509
1511
|
N("[CHAT] Sending payload:", a);
|
|
1510
1512
|
const o = await fetch(t, {
|
|
@@ -1546,12 +1548,12 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1546
1548
|
b = V.pop() ?? "";
|
|
1547
1549
|
for (const W of V) {
|
|
1548
1550
|
N(`[SSE] Processing block: ${W.slice(0, 50)}...`);
|
|
1549
|
-
const he =
|
|
1551
|
+
const he = at(W);
|
|
1550
1552
|
he && (N(`[SSE] Event: ${he.event}`), Lt(he.event, he.data));
|
|
1551
1553
|
}
|
|
1552
1554
|
if (x) {
|
|
1553
1555
|
if (N("[SSE] Stream finished"), b.trim()) {
|
|
1554
|
-
const W =
|
|
1556
|
+
const W = at(b.trim());
|
|
1555
1557
|
W && Lt(W.event, W.data);
|
|
1556
1558
|
}
|
|
1557
1559
|
h("Ready"), y(!1), be("");
|
|
@@ -1561,15 +1563,15 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1561
1563
|
} catch (n) {
|
|
1562
1564
|
console.error("Chat Error:", n), h("Agent Failed"), y(!1);
|
|
1563
1565
|
}
|
|
1564
|
-
}, Ln = Ae.trim(), Kt = ln(Ln),
|
|
1566
|
+
}, Ln = Ae.trim(), Kt = ln(Ln), Nt = Kt && T ? Kt.slice(
|
|
1565
1567
|
0,
|
|
1566
1568
|
g != null && g > 0 ? g : 0
|
|
1567
1569
|
) : "";
|
|
1568
1570
|
F(() => {
|
|
1569
1571
|
const e = B.current;
|
|
1570
1572
|
if (e !== "exiting") {
|
|
1571
|
-
if (
|
|
1572
|
-
|
|
1573
|
+
if (Nt)
|
|
1574
|
+
it(Nt), e === "hidden" && ot("entering");
|
|
1573
1575
|
else if (e === "visible" || e === "entering") {
|
|
1574
1576
|
if (!f && Te) {
|
|
1575
1577
|
const t = Te;
|
|
@@ -1580,27 +1582,27 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1580
1582
|
}
|
|
1581
1583
|
Fe(null);
|
|
1582
1584
|
}
|
|
1583
|
-
|
|
1585
|
+
ot("exiting");
|
|
1584
1586
|
}
|
|
1585
1587
|
}
|
|
1586
|
-
}, [
|
|
1587
|
-
const kn =
|
|
1588
|
+
}, [Nt, ae, f, Te]);
|
|
1589
|
+
const kn = ct(() => {
|
|
1588
1590
|
const e = B.current;
|
|
1589
|
-
e === "entering" ?
|
|
1591
|
+
e === "entering" ? ot("visible") : e === "exiting" && ot("hidden");
|
|
1590
1592
|
}, []);
|
|
1591
1593
|
In(() => {
|
|
1592
|
-
const e =
|
|
1594
|
+
const e = ht.current;
|
|
1593
1595
|
e && (e.scrollTop = e.scrollHeight);
|
|
1594
1596
|
}, [wt]);
|
|
1595
1597
|
const Sn = ne === "female" ? Wn : Vn;
|
|
1596
|
-
return
|
|
1598
|
+
return lt ? /* @__PURE__ */ ge("div", { className: "avatar-widget-container", children: [
|
|
1597
1599
|
/* @__PURE__ */ ge("div", { className: "avatar-input-area", children: [
|
|
1598
1600
|
Ue !== "hidden" ? /* @__PURE__ */ m(
|
|
1599
1601
|
"div",
|
|
1600
1602
|
{
|
|
1601
1603
|
className: `avatar-thinking-tab${Ue === "exiting" ? " avatar-thinking-tab--exiting" : Ue === "entering" ? " avatar-thinking-tab--entering" : ""}`,
|
|
1602
|
-
onAnimationEnd:
|
|
1603
|
-
children:
|
|
1604
|
+
onAnimationEnd: Mt,
|
|
1605
|
+
children: tt === cn ? /* @__PURE__ */ m(
|
|
1604
1606
|
"a",
|
|
1605
1607
|
{
|
|
1606
1608
|
href: "https://leads.streamoji.com",
|
|
@@ -1608,7 +1610,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1608
1610
|
rel: "noopener noreferrer",
|
|
1609
1611
|
children: "Made by Streamoji Leads"
|
|
1610
1612
|
}
|
|
1611
|
-
) :
|
|
1613
|
+
) : tt
|
|
1612
1614
|
}
|
|
1613
1615
|
) : null,
|
|
1614
1616
|
/* @__PURE__ */ m("div", { className: "avatar-input-container", children: /* @__PURE__ */ m(
|
|
@@ -1620,7 +1622,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1620
1622
|
width: "100%",
|
|
1621
1623
|
height: "100%"
|
|
1622
1624
|
},
|
|
1623
|
-
children:
|
|
1625
|
+
children: It ? /* @__PURE__ */ ge("div", { className: "avatar-input-recording", children: [
|
|
1624
1626
|
/* @__PURE__ */ m(
|
|
1625
1627
|
"button",
|
|
1626
1628
|
{
|
|
@@ -1674,9 +1676,9 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1674
1676
|
fontVariantNumeric: "tabular-nums"
|
|
1675
1677
|
},
|
|
1676
1678
|
children: [
|
|
1677
|
-
Math.floor(
|
|
1679
|
+
Math.floor(jt / 60),
|
|
1678
1680
|
":",
|
|
1679
|
-
String(
|
|
1681
|
+
String(jt % 60).padStart(2, "0")
|
|
1680
1682
|
]
|
|
1681
1683
|
}
|
|
1682
1684
|
)
|
|
@@ -1718,7 +1720,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1718
1720
|
alignItems: "center",
|
|
1719
1721
|
paddingRight: "8px"
|
|
1720
1722
|
},
|
|
1721
|
-
children: /* @__PURE__ */ m(Zt, { analyser:
|
|
1723
|
+
children: /* @__PURE__ */ m(Zt, { analyser: Jt })
|
|
1722
1724
|
}
|
|
1723
1725
|
),
|
|
1724
1726
|
/* @__PURE__ */ m(
|
|
@@ -1726,7 +1728,7 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1726
1728
|
{
|
|
1727
1729
|
type: "button",
|
|
1728
1730
|
className: "avatar-speaking-stop",
|
|
1729
|
-
onClick: () =>
|
|
1731
|
+
onClick: () => mt(!0),
|
|
1730
1732
|
title: "Stop",
|
|
1731
1733
|
children: /* @__PURE__ */ m("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
|
|
1732
1734
|
}
|
|
@@ -1871,14 +1873,14 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1871
1873
|
{
|
|
1872
1874
|
className: `avatar-bubble${ae === "entering" ? " avatar-bubble--entering" : ae === "exiting" ? " avatar-bubble--exiting" : ""}`,
|
|
1873
1875
|
onAnimationEnd: kn,
|
|
1874
|
-
children: /* @__PURE__ */ m("div", { ref:
|
|
1876
|
+
children: /* @__PURE__ */ m("div", { ref: ht, className: `avatar-bubble__content${qe ? " avatar-bubble__content--nudge" : ""}`, children: wt })
|
|
1875
1877
|
}
|
|
1876
1878
|
),
|
|
1877
1879
|
/* @__PURE__ */ m(
|
|
1878
1880
|
"div",
|
|
1879
1881
|
{
|
|
1880
1882
|
className: "avatar-canvas-layer",
|
|
1881
|
-
style: { width:
|
|
1883
|
+
style: { width: Xe, height: Xe },
|
|
1882
1884
|
children: /* @__PURE__ */ ge(
|
|
1883
1885
|
Tn,
|
|
1884
1886
|
{
|
|
@@ -1906,9 +1908,9 @@ const Bt = /* @__PURE__ */ new Map(), Zn = ({
|
|
|
1906
1908
|
agentResponse: Ae,
|
|
1907
1909
|
isSpeaking: T,
|
|
1908
1910
|
nextStartTimeRef: xe,
|
|
1909
|
-
stopPlayback:
|
|
1911
|
+
stopPlayback: mt,
|
|
1910
1912
|
setIsSpeaking: O,
|
|
1911
|
-
expressionUrl:
|
|
1913
|
+
expressionUrl: Tt,
|
|
1912
1914
|
onExpressionFinished: fe,
|
|
1913
1915
|
isNudgeResponse: qe,
|
|
1914
1916
|
avatarGender: ne
|