@streamoji/avatar-widget 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,28 @@
1
1
  import { jsx as l, jsxs as be } from "react/jsx-runtime";
2
2
  import { useGLTF as Mt, 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
6
  import { GLTFLoader as Mn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
7
  const nt = "https://ai.streamoji.com", N = (...g) => {
8
8
  }, In = (...g) => {
9
- }, Yt = ({ analyser: g }) => {
10
- const y = c(null), S = c(null);
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));
25
+ (!y.current || y.current.length !== q) && (y.current = new Float32Array(q).fill(2));
26
26
  const se = q * G, M = (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);
@@ -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;
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
45
  const I = M + m * G, F = rt - A / 2;
46
46
  j.beginPath(), j.roundRect ? j.roundRect(I, F, ve, A, 4) : j.fillRect(I, 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
+ }, It = 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,45 +614,45 @@ 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,
@@ -664,7 +664,7 @@ const Kn = Tn(
664
664
  ), m = Mt(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), I = c(null), F = c(null), Y = c(null), X = c(null), yt = c([]), [te] = L(() => new at.AnimationMixer(M)), J = c({}), V = c(null), Ee = c(0), Ze = c(!1), We = c(0), Me = c(!1), we = c(null), Ie = 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
669
  if (!(!b || !M)) {
670
670
  if (b.forEach((p, h) => {
@@ -818,8 +818,8 @@ const Kn = Tn(
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
824
  if (Ze.current = !1, Me.current) {
825
825
  const P = U ? 1 : 2.5;
@@ -831,20 +831,20 @@ const Kn = Tn(
831
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;
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 = It * Math.sin(re), Ce = It * 0.7 * Math.sin(re + 0.7), He = It * 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(I.current, "browInnerUp", ht), u(F.current, "browInnerUp", ht), u(A.current, "browOuterUpLeft", je), u(I.current, "browOuterUpLeft", je), u(F.current, "browOuterUpLeft", je), u(A.current, "browOuterUpRight", Ge), u(I.current, "browOuterUpRight", Ge), u(F.current, "browOuterUpRight", Ge);
836
+ const Je = Ie.current, Ue = Je + bt, fe = Ue + Dt;
837
+ o > fe && (Ie.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)
@@ -852,24 +852,24 @@ const Kn = Tn(
852
852
  const _ = R(me("mouthPucker") + Gn * Re);
853
853
  u(A.current, "mouthPucker", _), u(I.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);
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
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);
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
874
  }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: M }) });
875
875
  }
@@ -877,80 +877,80 @@ const Kn = Tn(
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(""), [M, _e] = L(""), [H, b] = L("Ready"), [ae, m] = L(!1), [O, z] = L(!1), [A, I] = 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), Me = c([]), we = c(null), Ie = 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), I([]), 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
1118
  K(!0), I(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: {
@@ -1137,27 +1137,27 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
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")), Me.current = [], Ee.current = [], We.current = !1, z(!1), De.current = 0, Ve.current = 0, de.current = 0, Ie.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(""), Ie.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,26 +1200,26 @@ 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(M).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);
@@ -1228,36 +1228,36 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1228
1228
  }, [O, M, 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;
1279
+ let Z = $t;
1280
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
1281
  Ie.current = Ie.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) => {
1310
+ )}ms => vtime=${zt}ms`
1311
+ ), ge.forEach((Yt) => {
1312
1312
  Me.current.push({
1313
- viseme: zt.v,
1314
- weight: zt.w,
1315
- vtime: qt,
1316
- vduration: Qe
1313
+ viseme: Yt.v,
1314
+ weight: Yt.w,
1315
+ vtime: zt,
1316
+ vduration: Ke
1317
1317
  });
1318
1318
  });
1319
1319
  }
@@ -1328,19 +1328,17 @@ 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`, 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
1340
  audio_format: "wav",
1343
- agentId: y
1341
+ token: Xe
1344
1342
  })
1345
1343
  });
1346
1344
  if (k.status === 429) {
@@ -1378,12 +1376,12 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1378
1376
  break;
1379
1377
  case "text": {
1380
1378
  const ge = B.delta ?? B.text ?? "";
1381
- ge && Ft(ge);
1379
+ ge && Pt(ge);
1382
1380
  break;
1383
1381
  }
1384
1382
  case "audio": {
1385
- const ge = B.chunk, Le = B.visemes ?? [], Qe = !!B.is_new_segment;
1386
- ge && await At(ge, Le, Qe);
1383
+ const ge = B.chunk, Le = B.visemes ?? [], Ke = !!B.is_new_segment;
1384
+ ge && await At(ge, Le, Ke);
1387
1385
  break;
1388
1386
  }
1389
1387
  case "done": {
@@ -1406,8 +1404,8 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1406
1404
  `);
1407
1405
  Z = ge.pop() ?? "";
1408
1406
  for (const Le of ge) {
1409
- const Qe = et(Le);
1410
- Qe && await $(Qe.event, Qe.data);
1407
+ const Ke = et(Le);
1408
+ Ke && await $(Ke.event, Ke.data);
1411
1409
  }
1412
1410
  if (pe) {
1413
1411
  if (Z.trim()) {
@@ -1419,17 +1417,17 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1419
1417
  }
1420
1418
  }
1421
1419
  };
1422
- } catch (r) {
1423
- console.error("Audio Submission Error:", r), b("STT Failed"), m(!1);
1420
+ } catch (n) {
1421
+ console.error("Audio Submission Error:", n), b("STT Failed"), m(!1);
1424
1422
  }
1425
1423
  }, _n = async (e) => {
1426
1424
  e && e.preventDefault(), K(!1), ue.current = "", _e(""), !(!q || ae) && await wn(q);
1427
1425
  }, 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;
1426
+ const n = e.split(/\r?\n/);
1427
+ let r = "", i = "";
1428
+ for (const s of n)
1429
+ s.startsWith("event:") ? r = s.slice(6).trim() : s.startsWith("data:") && (i = s.slice(5).trim());
1430
+ if (!r) return null;
1433
1431
  let t = {};
1434
1432
  if (i)
1435
1433
  try {
@@ -1437,25 +1435,29 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1437
1435
  } catch {
1438
1436
  t = { raw: i };
1439
1437
  }
1440
- return { event: n, data: t };
1441
- }, gt = (e, r) => {
1438
+ return { event: r, data: t };
1439
+ }, gt = (e, n) => {
1442
1440
  switch (e) {
1443
1441
  case "connected":
1444
1442
  x.current = "", ce.current = !1;
1445
1443
  break;
1446
1444
  case "text": {
1447
- const n = r.delta ?? "";
1448
- n && Ft(n);
1445
+ const r = n.delta ?? "";
1446
+ r && Pt(r);
1447
+ break;
1448
+ }
1449
+ case "metadata": {
1450
+ Ft(n);
1449
1451
  break;
1450
1452
  }
1451
1453
  case "audio": {
1452
- const n = r.chunk, i = r.visemes ?? [];
1453
- n && At(n, i);
1454
+ const r = n.chunk, i = n.visemes ?? [], t = n.is_new_segment ?? !1;
1455
+ r && At(r, i, t);
1454
1456
  break;
1455
1457
  }
1456
1458
  case "done": {
1457
- const n = Pt(), i = ue.current.trim(), t = [
1458
- ...n,
1459
+ const r = Bt(), i = ue.current.trim(), t = [
1460
+ ...r,
1459
1461
  { role: "user", content: q || "..." },
1460
1462
  { role: "assistant", content: i }
1461
1463
  ];
@@ -1463,25 +1465,25 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1463
1465
  break;
1464
1466
  }
1465
1467
  case "error": {
1466
- const n = r.message ?? "Unknown error";
1467
- ue.current = n, _e(n), b("Agent Failed"), m(!1);
1468
+ const r = n.message ?? "Unknown error";
1469
+ ue.current = r, _e(r), b("Agent Failed"), m(!1);
1468
1470
  break;
1469
1471
  }
1470
1472
  }
1471
- }, $t = async (e, r) => {
1473
+ }, Ht = async (e, n) => {
1472
1474
  m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
1473
1475
  try {
1474
- const n = await fetch(e, {
1476
+ const r = await fetch(e, {
1475
1477
  method: "POST",
1476
1478
  headers: { "Content-Type": "application/json" },
1477
- body: JSON.stringify(r)
1479
+ body: JSON.stringify(n)
1478
1480
  });
1479
- if (n.status === 429) {
1481
+ if (r.status === 429) {
1480
1482
  b("Busy"), m(!1);
1481
1483
  return;
1482
1484
  }
1483
- if (!n.ok) throw new Error("Request failed");
1484
- const i = n.body;
1485
+ if (!r.ok) throw new Error("Request failed");
1486
+ const i = r.body;
1485
1487
  if (!i) {
1486
1488
  b("Failed"), m(!1);
1487
1489
  return;
@@ -1510,38 +1512,36 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1510
1512
  break;
1511
1513
  }
1512
1514
  }
1513
- } catch (n) {
1514
- console.error("Streaming Error:", n), b("Failed"), m(!1);
1515
+ } catch (r) {
1516
+ console.error("Streaming Error:", r), b("Failed"), m(!1);
1515
1517
  }
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) => {
1518
+ }, jt = tt(async (e, n) => {
1519
+ const r = `${nt}/avatar_tts`;
1520
+ await Ht(r, { user_query: e, llm_prompt: n });
1521
+ }, []), Gt = tt(async (e, n, r, i) => {
1520
1522
  const t = `${nt}/avatar_ttsWithKnowledge`;
1521
- await $t(t, { userQuery: e, llmPrompt: r, knowledge: n, history: i });
1522
- }, []), Gt = c(!1);
1523
+ await Ht(t, { user_query: e, llm_prompt: n, knowledge: r, history: i });
1524
+ }, []), Jt = c(!1);
1523
1525
  W(() => {
1524
- L && !Gt.current && (L({ avatarSpeak: Ht, avatarRespond: jt }), Gt.current = !0);
1525
- }, [L, Ht, jt]);
1526
+ S && !Jt.current && (S({ avatarSpeak: jt, avatarRespond: Gt }), Jt.current = !0);
1527
+ }, [S, jt, Gt]);
1526
1528
  const wn = async (e) => {
1527
1529
  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
- )}`;
1530
+ const n = `${nt}/agent/chat`;
1531
1531
  try {
1532
- const n = Pt();
1532
+ const r = Bt();
1533
1533
  let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1534
1534
  i || (In(
1535
1535
  "[CHAT] Session UID missing at send time! Generating emergency backup."
1536
1536
  ), i = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i));
1537
1537
  const t = {
1538
- history: n,
1538
+ history: r,
1539
1539
  question: e,
1540
1540
  lead_id: i,
1541
- agentId: y
1541
+ token: Xe
1542
1542
  };
1543
1543
  N("[CHAT] Sending payload:", t);
1544
- const s = await fetch(r, {
1544
+ const s = await fetch(n, {
1545
1545
  method: "POST",
1546
1546
  headers: {
1547
1547
  "Content-Type": "application/json"
@@ -1592,20 +1592,20 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1592
1592
  break;
1593
1593
  }
1594
1594
  }
1595
- } catch (n) {
1596
- console.error("Chat Error:", n), b("Agent Failed"), m(!1);
1595
+ } catch (r) {
1596
+ console.error("Chat Error:", r), b("Agent Failed"), m(!1);
1597
1597
  }
1598
- }, yn = M.trim(), Jt = on(yn), Et = Jt && O ? Jt.slice(
1598
+ }, yn = M.trim(), qt = sn(yn), Et = qt && O ? qt.slice(
1599
1599
  0,
1600
1600
  ot != null && ot > 0 ? ot : 0
1601
1601
  ) : "";
1602
1602
  W(() => {
1603
1603
  const e = Fe.current;
1604
- e !== "exiting" && (Et ? (Lt(Et), e === "hidden" && ze("entering")) : (e === "visible" || e === "entering") && ze("exiting"));
1604
+ e !== "exiting" && (Et ? (Lt(Et), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
1605
1605
  }, [Et, oe]);
1606
1606
  const Sn = tt(() => {
1607
1607
  const e = Fe.current;
1608
- e === "entering" ? ze("visible") : e === "exiting" && ze("hidden");
1608
+ e === "entering" ? qe("visible") : e === "exiting" && qe("hidden");
1609
1609
  }, []);
1610
1610
  An(() => {
1611
1611
  const e = dt.current;
@@ -1618,8 +1618,8 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1618
1618
  "div",
1619
1619
  {
1620
1620
  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(
1621
+ onAnimationEnd: an,
1622
+ children: R === on ? /* @__PURE__ */ l(
1623
1623
  "a",
1624
1624
  {
1625
1625
  href: "https://leads.streamoji.com",
@@ -1679,7 +1679,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1679
1679
  minWidth: 0
1680
1680
  },
1681
1681
  children: [
1682
- /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Yt, { analyser: dn }) }),
1682
+ /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Kt, { analyser: dn }) }),
1683
1683
  /* @__PURE__ */ be(
1684
1684
  "span",
1685
1685
  {
@@ -1693,9 +1693,9 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1693
1693
  fontVariantNumeric: "tabular-nums"
1694
1694
  },
1695
1695
  children: [
1696
- Math.floor(Bt / 60),
1696
+ Math.floor(Wt / 60),
1697
1697
  ":",
1698
- String(Bt % 60).padStart(2, "0")
1698
+ String(Wt % 60).padStart(2, "0")
1699
1699
  ]
1700
1700
  }
1701
1701
  )
@@ -1737,7 +1737,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1737
1737
  alignItems: "center",
1738
1738
  paddingRight: "8px"
1739
1739
  },
1740
- children: /* @__PURE__ */ l(Yt, { analyser: Vt })
1740
+ children: /* @__PURE__ */ l(Kt, { analyser: $t })
1741
1741
  }
1742
1742
  ),
1743
1743
  /* @__PURE__ */ l(
@@ -1915,7 +1915,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1915
1915
  Kn,
1916
1916
  {
1917
1917
  avatarUrl: Ae,
1918
- isPlayingRef: Ve,
1918
+ isPlayingRef: We,
1919
1919
  visemeQueueRef: Me,
1920
1920
  audioContextRef: we,
1921
1921
  responseAudioStartTimeRef: De,
@@ -1924,7 +1924,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1924
1924
  expression: o,
1925
1925
  agentResponse: M,
1926
1926
  isSpeaking: O,
1927
- nextStartTimeRef: $e,
1927
+ nextStartTimeRef: Ve,
1928
1928
  stopPlayback: st,
1929
1929
  setIsSpeaking: z,
1930
1930
  expressionUrl: D,
@@ -1942,16 +1942,16 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1942
1942
  ] }) : null;
1943
1943
  }, or = ({
1944
1944
  agentId: g,
1945
- onNavigationRequested: y,
1946
- presetUserDetails: S,
1947
- onAvatarReady: L
1945
+ onNavigationRequested: v,
1946
+ presetUserDetails: y,
1947
+ onAvatarReady: S
1948
1948
  }) => /* @__PURE__ */ l(
1949
1949
  Xn,
1950
1950
  {
1951
1951
  agentId: g,
1952
- onNavigationRequested: y,
1953
- presetUserDetails: S,
1954
- onAvatarReady: L
1952
+ onNavigationRequested: v,
1953
+ presetUserDetails: y,
1954
+ onAvatarReady: S
1955
1955
  }
1956
1956
  );
1957
1957
  export {