@streamoji/avatar-widget 0.4.7 → 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,11 +1,11 @@
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
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) => {
8
+ }, Mn = (...g) => {
9
9
  }, Kt = ({ analyser: g }) => {
10
10
  const v = c(null), y = c(null);
11
11
  return W(() => {
@@ -23,14 +23,14 @@ const nt = "https://ai.streamoji.com", N = (...g) => {
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
25
  (!y.current || y.current.length !== q) && (y.current = new Float32Array(q).fill(2));
26
- const se = q * G, M = (Be - se) / 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
  }
@@ -42,8 +42,8 @@ const nt = "https://ai.streamoji.com", N = (...g) => {
42
42
  for (let m = 0; m < q; m++) {
43
43
  const O = q - 1 - m, z = Math.max(ae[m], ae[O]), A = y.current[m] + (z - y.current[m]) * 0.3;
44
44
  y.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();
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
49
  return Qe(), () => {
@@ -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, 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 = {
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,
@@ -658,25 +658,25 @@ const Kn = Tn(
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] = 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");
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,39 +780,39 @@ 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";
@@ -821,20 +821,20 @@ const Kn = Tn(
821
821
  if (te.update(h), o > Ee.current && !Ze.current && (Ze.current = !0, We.current = o), Ze.current) {
822
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, $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);
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
838
  const ye = !U && o >= Je && o < Ue, Ne = !U && o >= Ue && o < fe;
839
839
  (ye || Ne) && ct.current !== Je && (ct.current = Je, De.current = Math.random() < 0.7 ? "left" : "up");
840
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;
@@ -850,10 +850,10 @@ const Kn = Tn(
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
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(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);
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
859
  const _ = v.current ? 0 : Q.rotation[1];
@@ -871,7 +871,7 @@ const Kn = Tn(
871
871
  }
872
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) {
@@ -933,14 +933,14 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
933
933
  e = !0;
934
934
  };
935
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(
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
940
  const e = window.matchMedia("(max-width: 480px)"), n = () => te(e.matches);
941
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), We = 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
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
@@ -1109,13 +1109,13 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1109
1109
  })();
1110
1110
  }, [y]), W(() => {
1111
1111
  const e = () => {
1112
- ze.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
1115
  const n = setInterval(async () => {
1116
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 = {
@@ -1130,7 +1130,7 @@ 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;
@@ -1177,12 +1177,12 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1177
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 = [], We.current = !1, z(!1), De.current = 0, Ve.current = 0, de.current = 0, Ie.current.forEach((n) => {
1180
+ e && (ke.current = !0, m(!1), b("Ready")), Ie.current = [], Ee.current = [], We.current = !1, z(!1), De.current = 0, Ve.current = 0, de.current = 0, Me.current.forEach((n) => {
1181
1181
  try {
1182
1182
  n.stop();
1183
1183
  } catch {
1184
1184
  }
1185
- }), Ue.current && (clearTimeout(Ue.current), Ue.current = null), Je(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
1188
  const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), n = window.AudioContext || window.webkitAudioContext, r = new n(), i = r.createMediaStreamSource(e), t = r.createAnalyser();
@@ -1216,7 +1216,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1216
1216
  if (n <= 0) return;
1217
1217
  const r = we.current, i = De.current;
1218
1218
  if (!r) return;
1219
- const t = r.currentTime - i, s = Math.min(Math.max(0, t), n), w = sn(M).trim().length;
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
1222
  Math.round(s / n * w),
@@ -1225,7 +1225,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
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
1231
  xt((n) => n + 1);
@@ -1277,8 +1277,8 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1277
1277
  const C = t.createBufferSource();
1278
1278
  C.buffer = w;
1279
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), Ie.current.push(C), ke.current) {
1281
- Ie.current = Ie.current.filter(($) => $ !== C);
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) {
@@ -1309,7 +1309,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1309
1309
  0
1310
1310
  )}ms => vtime=${zt}ms`
1311
1311
  ), ge.forEach((Yt) => {
1312
- Me.current.push({
1312
+ Ie.current.push({
1313
1313
  viseme: Yt.v,
1314
1314
  weight: Yt.w,
1315
1315
  vtime: zt,
@@ -1332,13 +1332,12 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
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`, k = await fetch(w, {
1335
+ const w = `${nt}/stt?token=${encodeURIComponent(Xe)}`, k = await fetch(w, {
1336
1336
  method: "POST",
1337
1337
  headers: { "Content-Type": "application/json" },
1338
1338
  body: JSON.stringify({
1339
1339
  audio_base64: f,
1340
- audio_format: "wav",
1341
- token: Xe
1340
+ audio_format: "wav"
1342
1341
  })
1343
1342
  });
1344
1343
  if (k.status === 429) {
@@ -1461,7 +1460,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1461
1460
  { role: "user", content: q || "..." },
1462
1461
  { role: "assistant", content: i }
1463
1462
  ];
1464
- ln(t), ct.current = [...Me.current], b("Ready"), m(!1), se("");
1463
+ ln(t), ct.current = [...Ie.current], b("Ready"), m(!1), se("");
1465
1464
  break;
1466
1465
  }
1467
1466
  case "error": {
@@ -1527,18 +1526,17 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1527
1526
  }, [S, jt, Gt]);
1528
1527
  const wn = async (e) => {
1529
1528
  m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
1530
- const n = `${nt}/agent/chat`;
1529
+ const n = `${nt}/agent/chat?token=${encodeURIComponent(Xe)}`;
1531
1530
  try {
1532
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
1537
  history: r,
1539
1538
  question: e,
1540
- lead_id: i,
1541
- token: Xe
1539
+ lead_id: i
1542
1540
  };
1543
1541
  N("[CHAT] Sending payload:", t);
1544
1542
  const s = await fetch(n, {
@@ -1595,7 +1593,7 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1595
1593
  } catch (r) {
1596
1594
  console.error("Chat Error:", r), b("Agent Failed"), m(!1);
1597
1595
  }
1598
- }, yn = M.trim(), qt = sn(yn), Et = qt && O ? qt.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
  ) : "";
@@ -1916,13 +1914,13 @@ const Ct = /* @__PURE__ */ new Map(), Xn = ({
1916
1914
  {
1917
1915
  avatarUrl: Ae,
1918
1916
  isPlayingRef: We,
1919
- visemeQueueRef: Me,
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
1925
  nextStartTimeRef: Ve,
1928
1926
  stopPlayback: st,