@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.
@@ -1,36 +1,36 @@
1
1
  import { jsx as l, jsxs as be } from "react/jsx-runtime";
2
- import { useGLTF as Mt, Environment as vn } from "@react-three/drei";
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 v, useEffect as W, useCallback as tt, useLayoutEffect as An, Suspense as En } from "react";
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 Mn } from "three/examples/jsm/loaders/GLTFLoader.js";
6
+ import { GLTFLoader as In } from "three/examples/jsm/loaders/GLTFLoader.js";
7
7
  const nt = "https://ai.streamoji.com", N = (...g) => {
8
- }, In = (...g) => {
9
- }, Yt = ({ analyser: g }) => {
10
- const y = c(null), S = c(null);
8
+ }, Mn = (...g) => {
9
+ }, Kt = ({ analyser: g }) => {
10
+ const v = c(null), y = c(null);
11
11
  return W(() => {
12
- const L = y.current;
13
- if (!L) return;
14
- const j = L.getContext("2d", { alpha: !0 });
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 Xe = () => {
19
- Q = requestAnimationFrame(Xe), (L.width !== L.offsetWidth || L.height !== L.offsetHeight) && (L.width = L.offsetWidth, L.height = L.offsetHeight);
20
- const Be = L.width, U = L.height;
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
- (!S.current || S.current.length !== q) && (S.current = new Float32Array(q).fill(2));
26
- const se = q * G, M = (Be - se) / 2;
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 I = Math.floor(m * b), F = Math.floor((m + 1) * b);
33
- for (let Y = I; Y < F; 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 = S.current[m] + (z - S.current[m]) * 0.3;
44
- S.current[m] = A;
45
- const I = M + m * G, F = rt - A / 2;
46
- j.beginPath(), j.roundRect ? j.roundRect(I, F, ve, A, 4) : j.fillRect(I, F, ve, A), j.fill();
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 Xe(), () => {
49
+ return Qe(), () => {
50
50
  cancelAnimationFrame(Q);
51
51
  };
52
52
  }, [g]), /* @__PURE__ */ l(
53
53
  "canvas",
54
54
  {
55
- ref: y,
55
+ ref: v,
56
56
  style: { width: "100%", height: "100%", display: "block" }
57
57
  }
58
58
  );
59
- }, Dn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Kt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
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 [y, S] = v(null);
61
+ const [v, y] = L(null);
62
62
  return W(() => {
63
63
  if (!g) {
64
- S(null);
64
+ y(null);
65
65
  return;
66
66
  }
67
- let L = !1;
67
+ let S = !1;
68
68
  const j = `${Dn}/${g}.glb`;
69
69
  return fetch(j, { method: "HEAD" }).then((Q) => {
70
- L || S(Q.ok ? j : Kt);
70
+ S || y(Q.ok ? j : Qt);
71
71
  }).catch(() => {
72
- L || S(Kt);
72
+ S || y(Qt);
73
73
  }), () => {
74
- L = !0;
74
+ S = !0;
75
75
  };
76
- }, [g]), y;
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
- }, It = 0.18, Hn = 1, jn = 0.5, Qt = 3, bt = 0.55, Dt = 0.12, Xt = 2, Zt = 2, _t = 4, en = 8, Gn = 1, tn = 0.38, nn = 0.32, rn = "__branding__", wt = {
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 y = g.toLowerCase();
618
- return qn[y] ?? [{ v: "sil", w: 1 }];
617
+ const v = g.toLowerCase();
618
+ return qn[v] ?? [{ v: "sil", w: 1 }];
619
619
  }
620
620
  function Yn({ target: g }) {
621
- const { camera: y } = xn();
621
+ const { camera: v } = xn();
622
622
  return W(() => {
623
- y.lookAt(...g);
624
- }, [y, g]), null;
623
+ v.lookAt(...g);
624
+ }, [v, g]), null;
625
625
  }
626
- function u(g, y, S) {
626
+ function u(g, v, y) {
627
627
  if (!g || !g.morphTargetDictionary)
628
628
  return;
629
- const L = g, j = L.morphTargetDictionary, Q = L.morphTargetInfluences;
629
+ const S = g, j = S.morphTargetDictionary, Q = S.morphTargetInfluences;
630
630
  if (Q)
631
631
  for (const ee in j)
632
- ee.toLowerCase() === y.toLowerCase() && (Q[j[ee]] = S);
632
+ ee.toLowerCase() === v.toLowerCase() && (Q[j[ee]] = y);
633
633
  }
634
- function Ot(g, y = 0.97) {
634
+ function Ot(g, v = 0.97) {
635
635
  if (!g) return;
636
- const S = g;
637
- if (S.morphTargetInfluences)
638
- for (let L = 0; L < S.morphTargetInfluences.length; L++)
639
- S.morphTargetInfluences[L] *= y;
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: y,
645
- visemeQueueRef: S,
646
- audioContextRef: L,
644
+ isPlayingRef: v,
645
+ visemeQueueRef: y,
646
+ audioContextRef: S,
647
647
  responseAudioStartTimeRef: j,
648
648
  adjustments: Q,
649
649
  mood: ee,
650
- expression: Xe,
650
+ expression: Qe,
651
651
  agentResponse: Be,
652
652
  isSpeaking: U,
653
653
  nextStartTimeRef: rt,
654
654
  stopPlayback: ve,
655
- setIsSpeaking: We,
655
+ setIsSpeaking: Xe,
656
656
  expressionUrl: G,
657
657
  onExpressionFinished: Ae,
658
658
  isNudgeResponse: q,
659
659
  avatarGender: se
660
660
  }) => {
661
- const { scene: M } = Mt(g), H = Mt(se === "female" ? Un : Cn), b = Ut(
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 = Mt(se === "female" ? Pn : Fn), O = Ut(
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), I = c(null), F = c(null), Y = c(null), X = c(null), yt = c([]), [te] = v(() => new at.AnimationMixer(M)), J = c({}), V = c(null), Ee = c(0), Ze = c(!1), Ve = c(0), Me = c(!1), we = c(null), Ie = c(Qt), ct = c(-1), De = c("left"), $e = c(_t + Math.random() * (en - _t)), de = c(0), Oe = c("smile");
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 || !M)) {
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, M);
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, M);
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, M, te]);
690
+ }, [b, O, I, te]);
691
691
  const ke = c("");
692
692
  W(() => {
693
- if (!G || !M || G === ke.current) return;
694
- ke.current = G, we.current = G, new Mn().load(
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, M);
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, M, te, U]), W(() => {
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 && M) {
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 && M) {
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, M, G]), W(() => {
771
- if (!M) return;
772
- M.traverse((a) => {
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") && (I.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}`));
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
- M.traverse((a) => {
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
- }, [M]);
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(I.current, d, D);
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(I.current, d, D);
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(I.current, a, h[a]), u(F.current, a, h[a]);
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(I.current, a), Ot(F.current, a), it(ee);
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
- M.traverse((P) => {
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, Ve.current = o), Ze.current) {
822
- const _ = U ? 0.2 : 0.3, K = (o - Ve.current) / _;
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, Me.current) {
824
+ if (Ze.current = !1, Ie.current) {
825
825
  const P = U ? 1 : 2.5;
826
- Ee.current = o + P, Me.current = !1;
826
+ Ee.current = o + P, Ie.current = !1;
827
827
  } else
828
- Ee.current = o + 0.12, Me.current = !0;
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(I.current, "eyeBlinkLeft", P), u(I.current, "eyeBlinkRight", P), u(F.current, "eyeBlinkLeft", P), u(F.current, "eyeBlinkRight", P), d = P * $n.browInnerUp;
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, He = D.browOuterUpRight ?? 0, re = o * Hn, ut = It * Math.sin(re), Ce = It * 0.7 * Math.sin(re + 0.7), je = It * 0.7 * Math.sin(re + 1.3), R = (_) => Math.max(0, Math.min(1, _)), lt = R(ne + ut), Ge = R(St + Ce), Je = R(He + je), ht = R(lt + d);
835
- u(A.current, "browInnerUp", ht), u(I.current, "browInnerUp", ht), u(F.current, "browInnerUp", ht), u(A.current, "browOuterUpLeft", Ge), u(I.current, "browOuterUpLeft", Ge), u(F.current, "browOuterUpLeft", Ge), u(A.current, "browOuterUpRight", Je), u(I.current, "browOuterUpRight", Je), u(F.current, "browOuterUpRight", Je);
836
- const qe = Ie.current, Ue = qe + bt, fe = Ue + Dt;
837
- o > fe && (Ie.current += bt + Dt + Qt);
838
- const ye = !U && o >= qe && o < Ue, Ne = !U && o >= Ue && o < fe;
839
- (ye || Ne) && ct.current !== qe && (ct.current = qe, De.current = Math.random() < 0.7 ? "left" : "up");
840
- const dt = ye ? o - qe : Ne ? bt : 0, oe = ye || Ne ? Math.min(1, dt / bt) : 0, ze = oe <= 0 ? 0 : Math.sin(oe * Math.PI), ft = Ne ? 1 - (o - Ue) / Dt : 1, Lt = ye ? ze : Ne ? ze * 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 >= $e.current) {
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" ? Zt : Xt;
844
- $e.current = o + _ + _t + Math.random() * (en - _t);
843
+ const _ = Oe.current === "pucker" ? en : Zt;
844
+ Ve.current = o + _ + _t + Math.random() * (tn - _t);
845
845
  }
846
- const ce = Oe.current === "pucker" ? Zt : Xt, ue = !U && o >= de.current && o < de.current + ce, Ye = ue ? (o - de.current) / ce : 0, Re = Ye <= 0 ? 0 : Ye < 0.5 ? Ye * 2 : (() => {
847
- const _ = (Ye - 0.5) * 2;
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(I.current, "mouthPucker", _), u(F.current, "mouthPucker", _);
853
+ u(A.current, "mouthPucker", _), u(M.current, "mouthPucker", _), u(F.current, "mouthPucker", _);
854
854
  } else {
855
- const _ = R(me("mouthSmileLeft") + tn * Re), K = R(me("mouthSmileRight") + tn * Re), P = R(me("mouthDimpleLeft") + nn * Re), xe = R(me("mouthDimpleRight") + nn * Re);
856
- u(A.current, "mouthSmileLeft", _), u(A.current, "mouthSmileRight", K), u(A.current, "mouthDimpleLeft", P), u(A.current, "mouthDimpleRight", xe), u(I.current, "mouthSmileLeft", _), u(I.current, "mouthSmileRight", K), u(I.current, "mouthDimpleLeft", P), u(I.current, "mouthDimpleRight", xe), u(F.current, "mouthSmileLeft", _), u(F.current, "mouthSmileRight", K), u(F.current, "mouthDimpleLeft", P), u(F.current, "mouthDimpleRight", xe);
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 _ = y.current ? 0 : Q.rotation[1];
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 (y.current && L.current) {
867
- const _ = L.current.currentTime, xe = (_ - j.current) * 1e3 - -150;
868
- for (let le = 0; le < S.current.length; le++) {
869
- const he = S.current[le];
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(), We(!1));
872
+ _ > rt.current + 0.5 && (ve(), Xe(!1));
873
873
  }
874
- }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: M }) });
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 on(g) {
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: y,
886
- presetUserDetails: S,
887
- onAvatarReady: L
885
+ agentId: v,
886
+ presetUserDetails: y,
887
+ onAvatarReady: S
888
888
  }) => {
889
- const [j, Q] = v(""), [ee, Xe] = v("male"), [Be, U] = v(""), [rt, ve] = v(!1), We = j, G = ee;
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 (!y) {
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", y);
897
+ console.log(">> fetchConfig RUNNING for", v);
898
898
  try {
899
- const n = `agent_config_${y}`, i = sessionStorage.getItem(n);
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 && Xe(s.avatarGender), s.agent_id && U(s.agent_id), ve(!0));
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(n);
906
+ console.error("Failed to parse cached avatar config:", s), sessionStorage.removeItem(r);
907
907
  }
908
908
  let t;
909
- if (Ct.has(y))
910
- console.log(">> REUSING in-flight fetch for", y), t = await Ct.get(y);
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", y);
914
- const f = { agentId: y }, w = await fetch(`${nt}/visitedWebsite`, {
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(n, JSON.stringify(k)), k;
921
+ return sessionStorage.setItem(r, JSON.stringify(k)), k;
922
922
  })();
923
- Ct.set(y, s), t = await s;
923
+ Ct.set(v, s), t = await s;
924
924
  }
925
925
  if (e) return;
926
- t && (t.encryptedAgentToken && Q(t.encryptedAgentToken), t.avatarGender && Xe(t.avatarGender), t.agent_id && U(t.agent_id));
927
- } catch (n) {
928
- console.error("Failed to fetch avatar config:", n);
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
- }, [y]);
936
- const Ae = On(y ?? Be), [q, se] = v(""), [M, _e] = v(""), [H, b] = v("Ready"), [ae, m] = v(!1), [O, z] = v(!1), [A, I] = v([]), [F, Y] = v(""), X = c(null), [yt, te] = v(
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)"), r = () => te(e.matches);
941
- return e.addEventListener("change", r), () => e.removeEventListener("change", r);
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), Ve = c(!1), Me = c([]), we = c(null), Ie = c([]);
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), $e = c(0), de = c(0), Oe = c(0), ke = c(!1), [ot, it] = v(
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] = v("neutral"), [o, d] = v(""), [D, ne] = v(""), [St, He] = v("Chat with us"), [re, ut] = v(
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, je] = v("hidden"), [R, lt] = v(""), Ge = c(null), Je = c(Ce);
950
- Je.current = Ce;
951
- const [ht, qe] = v(null), Ue = c(null), fe = c(null), [ye, Ne] = v(!1), dt = c(null), [oe, ze] = v("hidden"), [ft, Lt] = v(""), Fe = c(oe);
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(""), Ye = c(Date.now()), Re = c([]), me = c(!1), [_, K] = v(!1), [P, xe] = v(!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 : rn, [H, re, ye, oe, P]), Nt = !ye && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (re == null || re === "" || re === "none" || re === "<none>");
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 = Je.current;
967
+ const e = Ge.current;
968
968
  if (!(e === "exiting" || e === "entering")) {
969
969
  if (e === "hidden") {
970
- mt && (lt(he ?? ""), je("entering"));
970
+ mt && (lt(he ?? ""), He("entering"));
971
971
  return;
972
972
  }
973
- e === "visible" && (!mt || he !== R) && (Ge.current = mt ? he : null, je("exiting"));
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 sn = tt(() => {
996
- const e = Je.current;
995
+ const an = tt(() => {
996
+ const e = Ge.current;
997
997
  if (e === "exiting") {
998
- je("hidden");
999
- const r = Ge.current;
1000
- Ge.current = null, r != null && r !== "" && (lt(r), je("entering"));
1001
- } else e === "entering" && je("visible");
1002
- }, []), an = (e) => {
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 r = e.ask_for || e.lead_capture?.ask_for, n = r ? String(r).trim().toLowerCase() : "", i = n === "none" || n === "<none>";
1023
- if (r && !i) {
1024
- const t = n;
1025
- if (S && (t === "email" && S.email || t === "name" && S.name || t === "phone" && S.phone))
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), He(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" && He("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 r = e.trim();
1032
- if (!r) return null;
1033
- if (r.startsWith("{"))
1031
+ const n = e.trim();
1032
+ if (!n) return null;
1033
+ if (n.startsWith("{"))
1034
1034
  try {
1035
- return JSON.parse(r);
1035
+ return JSON.parse(n);
1036
1036
  } catch {
1037
1037
  return null;
1038
1038
  }
1039
- if (r.includes(":")) {
1040
- const n = r.split(":"), i = n[0].trim().toLowerCase(), t = n.slice(1).join(":").trim();
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
- `), r = x.current.slice(0, e).trim();
1049
+ `), n = x.current.slice(0, e).trim();
1050
1050
  x.current = x.current.slice(e + 1);
1051
- const n = cn(r);
1052
- n && an(n);
1051
+ const r = cn(n);
1052
+ r && Ft(r);
1053
1053
  }
1054
- }, Ft = (e) => {
1054
+ }, Pt = (e) => {
1055
1055
  if (ce.current)
1056
1056
  if (e.includes(Pe)) {
1057
- const r = e.indexOf(Pe), n = e.slice(0, r), i = e.slice(r + Pe.length);
1058
- n && (ue.current += n, _e((t) => t + n)), ce.current = !1, i && (x.current += i, vt());
1059
- } else e === Pe ? ce.current = !1 : (ue.current += e, _e((r) => r + 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 r = e.indexOf(Pe), n = e.slice(0, r), i = e.slice(r + Pe.length);
1062
- x.current += n, vt(), ce.current = !0, i && (ue.current += i, _e((t) => t + i));
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 n = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
1094
+ const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
1095
1095
  let i = [];
1096
- if (n)
1096
+ if (r)
1097
1097
  try {
1098
- i = JSON.parse(n);
1098
+ i = JSON.parse(r);
1099
1099
  } catch {
1100
1100
  i = [];
1101
1101
  }
1102
- i.length === 0 && S && (S.name || S.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${S.name || ""}" , Email is "${S.email || ""}"` }], sessionStorage.setItem(
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
- )) : n || sessionStorage.setItem(
1105
+ )) : r || sessionStorage.setItem(
1106
1106
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1107
1107
  JSON.stringify([])
1108
1108
  );
1109
1109
  })();
1110
- }, [S]), W(() => {
1110
+ }, [y]), W(() => {
1111
1111
  const e = () => {
1112
- Ye.current = Date.now(), me.current && (me.current = !1, K(!1), I([]), Y(""), _e(""), z(!1));
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 r = setInterval(async () => {
1116
- if (Date.now() - Ye.current >= 3e4 && !O && !ae && H === "Ready" && !me.current)
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), I(Re.current);
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
- token: We
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), I(k));
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(r);
1140
+ window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(n);
1141
1141
  };
1142
- }, [We, O, ae, H]), W(() => {
1142
+ }, [Xe, O, ae, H]), W(() => {
1143
1143
  if (A.length === 0) return;
1144
- let e = 0, r = 0, n = !1, i = 100;
1144
+ let e = 0, n = 0, r = !1, i = 100;
1145
1145
  const t = () => {
1146
1146
  const s = A[e];
1147
- if (n) {
1148
- const f = s.substring(0, r - 1);
1149
- Y(f), r--, i = 50;
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, r + 1);
1152
- Y(f), r++, i = 100;
1151
+ const f = s.substring(0, n + 1);
1152
+ Y(f), n++, i = 100;
1153
1153
  }
1154
- !n && r === s.length ? (n = !0, i = 3e3) : n && r === 0 && (n = !1, e = (e + 1) % A.length, i = 500), X.current = setTimeout(t, i);
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 Pt = () => {
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] = v(!1), [Bt, xt] = v(0), Se = c(null), pt = c([]), Wt = c(0), [Vt, hn] = v(
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] = v(
1175
+ ), [dn, Tt] = L(
1176
1176
  null
1177
- ), Te = c(null), Ke = c(
1177
+ ), Te = c(null), Ye = c(
1178
1178
  null
1179
1179
  ), st = tt((e = !1) => {
1180
- e && (ke.current = !0, m(!1), b("Ready")), Me.current = [], Ee.current = [], Ve.current = !1, z(!1), De.current = 0, $e.current = 0, de.current = 0, Ie.current.forEach((r) => {
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
- r.stop();
1182
+ n.stop();
1183
1183
  } catch {
1184
1184
  }
1185
- }), Ue.current && (clearTimeout(Ue.current), Ue.current = null), qe(null), ne(""), Ie.current = [];
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 }), r = window.AudioContext || window.webkitAudioContext, n = new r(), i = n.createMediaStreamSource(e), t = n.createAnalyser();
1189
- t.fftSize = 64, i.connect(t), Te.current = n, Ke.current = i, Tt(t);
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() - Wt.current;
1195
- if (Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), f < 1e3) {
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
- }, Wt.current = Date.now(), s.start(100), Rt(!0), b("Listening...");
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), Ke.current && (Ke.current.disconnect(), Ke.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), Rt(!1), pt.current = [], b("Ready"));
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 r = de.current;
1216
- if (r <= 0) return;
1217
- const n = we.current, i = De.current;
1218
- if (!n) return;
1219
- const t = n.currentTime - i, s = Math.min(Math.max(0, t), r), w = on(M).trim().length;
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 / r * w),
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, M, de.current]), W(() => {
1228
+ }, [O, I, de.current]), W(() => {
1229
1229
  let e;
1230
1230
  return kt ? (xt(0), e = window.setInterval(() => {
1231
- xt((r) => r + 1);
1231
+ xt((n) => n + 1);
1232
1232
  }, 1e3)) : xt(0), () => clearInterval(e);
1233
1233
  }, [kt]);
1234
1234
  const gn = (e) => {
1235
- const r = e.numberOfChannels, n = e.length * r * 2 + 44, i = new ArrayBuffer(n), t = new DataView(i);
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(n - 8), w(1163280727), w(544501094), w(16), f(1), f(r), w(e.sampleRate), w(e.sampleRate * 2 * r), f(r * 2), f(16), w(1635017060), w(n - s - 4);
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 < r; T++) k.push(e.getChannelData(T));
1244
+ for (let T = 0; T < n; T++) k.push(e.getChannelData(T));
1245
1245
  let E = 0;
1246
- for (; s < n; ) {
1247
- for (let T = 0; T < r; 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, r, n = !1) => {
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: r,
1260
- isNewSegment: n
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 = $e.current;
1275
- const T = !Ve.current;
1276
- E < k && (E = k + 0.1), $e.current = E + w.duration;
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 = Vt;
1280
- if ((!Z || Z.context !== t) && (Z = t.createAnalyser(), Z.fftSize = 64, Z.connect(t.destination), hn(Z)), C.connect(Z), Ie.current.push(C), ke.current) {
1281
- Ie.current = Ie.current.filter(($) => $ !== C);
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
- Ve.current = !0, z(!0), N(
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
- n && (Oe.current = ie, N(
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
- )), r.forEach(($, pe) => {
1303
+ )), n.forEach(($, pe) => {
1304
1304
  const B = $.symbol ?? "";
1305
1305
  if (B) {
1306
- const ge = zn(B), Le = Math.round($.start * 1e3), Qe = Math.round(($.duration ?? 0) * 1e3), qt = Oe.current + Le;
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=${qt}ms`
1311
- ), ge.forEach((zt) => {
1312
- Me.current.push({
1313
- viseme: zt.v,
1314
- weight: zt.w,
1315
- vtime: qt,
1316
- vduration: Qe
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 r = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(r), t = gn(i), s = new FileReader();
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 && Ft(ge);
1378
+ ge && Pt(ge);
1382
1379
  break;
1383
1380
  }
1384
1381
  case "audio": {
1385
- const ge = B.chunk, Le = B.visemes ?? [], Qe = !!B.is_new_segment;
1386
- ge && await At(ge, Le, Qe);
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 Qe = et(Le);
1410
- Qe && await $(Qe.event, Qe.data);
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 (r) {
1423
- console.error("Audio Submission Error:", r), b("STT Failed"), m(!1);
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 r = e.split(/\r?\n/);
1429
- let n = "", i = "";
1430
- for (const s of r)
1431
- s.startsWith("event:") ? n = s.slice(6).trim() : s.startsWith("data:") && (i = s.slice(5).trim());
1432
- if (!n) return null;
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: n, data: t };
1441
- }, gt = (e, r) => {
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 n = r.delta ?? "";
1448
- n && Ft(n);
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 n = r.chunk, i = r.visemes ?? [];
1453
- n && At(n, i);
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 n = Pt(), i = ue.current.trim(), t = [
1458
- ...n,
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 = [...Me.current], b("Ready"), m(!1), se("");
1463
+ ln(t), ct.current = [...Ie.current], b("Ready"), m(!1), se("");
1463
1464
  break;
1464
1465
  }
1465
1466
  case "error": {
1466
- const n = r.message ?? "Unknown error";
1467
- ue.current = n, _e(n), b("Agent Failed"), m(!1);
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
- }, $t = async (e, r) => {
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 n = await fetch(e, {
1475
+ const r = await fetch(e, {
1475
1476
  method: "POST",
1476
1477
  headers: { "Content-Type": "application/json" },
1477
- body: JSON.stringify(r)
1478
+ body: JSON.stringify(n)
1478
1479
  });
1479
- if (n.status === 429) {
1480
+ if (r.status === 429) {
1480
1481
  b("Busy"), m(!1);
1481
1482
  return;
1482
1483
  }
1483
- if (!n.ok) throw new Error("Request failed");
1484
- const i = n.body;
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 (n) {
1514
- console.error("Streaming Error:", n), b("Failed"), m(!1);
1514
+ } catch (r) {
1515
+ console.error("Streaming Error:", r), b("Failed"), m(!1);
1515
1516
  }
1516
- }, Ht = tt(async (e, r, n) => {
1517
- const i = `${nt}/avatar_tts`;
1518
- await $t(i, { text: e, userQuery: r, llmPrompt: n });
1519
- }, []), jt = tt(async (e, r, n, i) => {
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 $t(t, { userQuery: e, llmPrompt: r, knowledge: n, history: i });
1522
- }, []), Gt = c(!1);
1522
+ await Ht(t, { user_query: e, llm_prompt: n, knowledge: r, history: i });
1523
+ }, []), Jt = c(!1);
1523
1524
  W(() => {
1524
- L && !Gt.current && (L({ avatarSpeak: Ht, avatarRespond: jt }), Gt.current = !0);
1525
- }, [L, Ht, jt]);
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 r = `${nt}/agent/chat?token=${encodeURIComponent(
1529
- We
1530
- )}`;
1529
+ const n = `${nt}/agent/chat?token=${encodeURIComponent(Xe)}`;
1531
1530
  try {
1532
- const n = Pt();
1531
+ const r = Bt();
1533
1532
  let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1534
- i || (In(
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: n,
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(r, {
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 (n) {
1596
- console.error("Chat Error:", n), b("Agent Failed"), m(!1);
1593
+ } catch (r) {
1594
+ console.error("Chat Error:", r), b("Agent Failed"), m(!1);
1597
1595
  }
1598
- }, yn = M.trim(), Jt = on(yn), Et = Jt && O ? Jt.slice(
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" && ze("entering")) : (e === "visible" || e === "entering") && ze("exiting"));
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" ? ze("visible") : e === "exiting" && ze("hidden");
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: sn,
1622
- children: R === rn ? /* @__PURE__ */ l(
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(Yt, { analyser: dn }) }),
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(Bt / 60),
1694
+ Math.floor(Wt / 60),
1697
1695
  ":",
1698
- String(Bt % 60).padStart(2, "0")
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(Yt, { analyser: Vt })
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: Ve,
1919
- visemeQueueRef: Me,
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: M,
1923
+ agentResponse: I,
1926
1924
  isSpeaking: O,
1927
- nextStartTimeRef: $e,
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: y,
1946
- presetUserDetails: S,
1947
- onAvatarReady: L
1943
+ onNavigationRequested: v,
1944
+ presetUserDetails: y,
1945
+ onAvatarReady: S
1948
1946
  }) => /* @__PURE__ */ l(
1949
1947
  Xn,
1950
1948
  {
1951
1949
  agentId: g,
1952
- onNavigationRequested: y,
1953
- presetUserDetails: S,
1954
- onAvatarReady: L
1950
+ onNavigationRequested: v,
1951
+ presetUserDetails: y,
1952
+ onAvatarReady: S
1955
1953
  }
1956
1954
  );
1957
1955
  export {