@streamoji/avatar-widget 0.3.8 → 0.3.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,30 +1,30 @@
1
1
  import { jsx as d, jsxs as le } from "react/jsx-runtime";
2
2
  import { useGLTF as mt, Environment as on } from "@react-three/drei";
3
3
  import { useFrame as an, Canvas as cn, useThree as un } from "@react-three/fiber";
4
- import { memo as ln, useMemo as bt, useRef as c, useState as v, useEffect as W, useCallback as $e, useLayoutEffect as dn, Suspense as hn } from "react";
4
+ import { memo as ln, useMemo as bt, useRef as a, useState as y, useEffect as W, useCallback as $e, useLayoutEffect as dn, Suspense as hn } from "react";
5
5
  import * as ze from "three";
6
6
  import { GLTFLoader as fn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
- const Ye = "https://ai.streamoji.com", B = (...m) => {
8
- }, mn = (...m) => {
9
- }, Nt = ({ analyser: m }) => {
10
- const T = c(null), y = c(null);
7
+ const Ye = "https://ai.streamoji.com", B = (...f) => {
8
+ }, mn = (...f) => {
9
+ }, Nt = ({ analyser: f }) => {
10
+ const T = a(null), x = a(null);
11
11
  return W(() => {
12
12
  const b = T.current;
13
13
  if (!b) return;
14
- const x = b.getContext("2d", { alpha: !0 });
15
- if (!x) return;
14
+ const S = b.getContext("2d", { alpha: !0 });
15
+ if (!S) return;
16
16
  let H, I = null;
17
- m && (m.fftSize = 128, I = new Uint8Array(m.frequencyBinCount));
17
+ f && (f.fftSize = 128, I = new Uint8Array(f.frequencyBinCount));
18
18
  const Ue = () => {
19
19
  H = requestAnimationFrame(Ue), (b.width !== b.offsetWidth || b.height !== b.offsetHeight) && (b.width = b.offsetWidth, b.height = b.offsetHeight);
20
20
  const se = b.width, R = b.height;
21
21
  if (se === 0 || R === 0) return;
22
22
  const we = R / 2;
23
- x.clearRect(0, 0, se, R), x.fillStyle = "#1e293b";
23
+ S.clearRect(0, 0, se, R), S.fillStyle = "#1e293b";
24
24
  const K = 2, l = K + 2, Q = se * 0.95, g = Math.floor(Q / l);
25
- (!y.current || y.current.length !== g) && (y.current = new Float32Array(g).fill(2));
25
+ (!x.current || x.current.length !== g) && (x.current = new Float32Array(g).fill(2));
26
26
  const ee = g * l, k = (se - ee) / 2;
27
- m && I && m.getByteFrequencyData(I);
27
+ f && I && f.getByteFrequencyData(I);
28
28
  const Te = I ? I.length : 0, te = Math.floor(Te * 0.7) / g, Se = new Float32Array(g);
29
29
  for (let D = 0; D < g; D++) {
30
30
  let J = 0;
@@ -40,16 +40,16 @@ const Ye = "https://ai.streamoji.com", B = (...m) => {
40
40
  Se[D] = F;
41
41
  }
42
42
  for (let D = 0; D < g; D++) {
43
- const J = g - 1 - D, Y = Math.max(Se[D], Se[J]), F = y.current[D] + (Y - y.current[D]) * 0.3;
44
- y.current[D] = F;
43
+ const J = g - 1 - D, Y = Math.max(Se[D], Se[J]), F = x.current[D] + (Y - x.current[D]) * 0.3;
44
+ x.current[D] = F;
45
45
  const V = k + D * l, $ = we - F / 2;
46
- x.beginPath(), x.roundRect ? x.roundRect(V, $, K, F, 4) : x.fillRect(V, $, K, F), x.fill();
46
+ S.beginPath(), S.roundRect ? S.roundRect(V, $, K, F, 4) : S.fillRect(V, $, K, F), S.fill();
47
47
  }
48
48
  };
49
49
  return Ue(), () => {
50
50
  cancelAnimationFrame(H);
51
51
  };
52
- }, [m]), /* @__PURE__ */ d(
52
+ }, [f]), /* @__PURE__ */ d(
53
53
  "canvas",
54
54
  {
55
55
  ref: T,
@@ -57,33 +57,33 @@ const Ye = "https://ai.streamoji.com", B = (...m) => {
57
57
  }
58
58
  );
59
59
  }, pn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Pt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
- async function gn(m) {
60
+ async function gn(f) {
61
61
  const T = await crypto.subtle.digest(
62
62
  "SHA-256",
63
- new TextEncoder().encode(m)
63
+ new TextEncoder().encode(f)
64
64
  );
65
- return Array.from(new Uint8Array(T)).map((y) => y.toString(16).padStart(2, "0")).join("");
65
+ return Array.from(new Uint8Array(T)).map((x) => x.toString(16).padStart(2, "0")).join("");
66
66
  }
67
- function bn(m) {
68
- const [T, y] = v(null);
67
+ function bn(f) {
68
+ const [T, x] = y(null);
69
69
  return W(() => {
70
- if (!m) {
71
- y(null);
70
+ if (!f) {
71
+ x(null);
72
72
  return;
73
73
  }
74
74
  let b = !1;
75
- return gn(m).then((x) => {
75
+ return gn(f).then((S) => {
76
76
  if (b) return;
77
- const H = `${pn}/${x}.glb`;
77
+ const H = `${pn}/${S}.glb`;
78
78
  fetch(H, { method: "HEAD" }).then((I) => {
79
- b || y(I.ok ? H : Pt);
79
+ b || x(I.ok ? H : Pt);
80
80
  }).catch(() => {
81
- b || y(Pt);
81
+ b || x(Pt);
82
82
  });
83
83
  }), () => {
84
84
  b = !0;
85
85
  };
86
- }, [m]), T;
86
+ }, [f]), T;
87
87
  }
88
88
  const _n = [
89
89
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
@@ -622,39 +622,39 @@ const _n = [
622
622
  ],
623
623
  sil: [{ v: "sil", w: 1 }]
624
624
  };
625
- function En(m) {
626
- if (!m) return [{ v: "sil", w: 1 }];
627
- const T = m.toLowerCase();
625
+ function En(f) {
626
+ if (!f) return [{ v: "sil", w: 1 }];
627
+ const T = f.toLowerCase();
628
628
  return Mn[T] ?? [{ v: "sil", w: 1 }];
629
629
  }
630
- function In({ target: m }) {
630
+ function In({ target: f }) {
631
631
  const { camera: T } = un();
632
632
  return W(() => {
633
- T.lookAt(...m);
634
- }, [T, m]), null;
633
+ T.lookAt(...f);
634
+ }, [T, f]), null;
635
635
  }
636
- function E(m, T, y) {
637
- if (!m || !m.morphTargetDictionary)
636
+ function E(f, T, x) {
637
+ if (!f || !f.morphTargetDictionary)
638
638
  return;
639
- const b = m, x = b.morphTargetDictionary, H = b.morphTargetInfluences;
639
+ const b = f, S = b.morphTargetDictionary, H = b.morphTargetInfluences;
640
640
  if (H)
641
- for (const I in x)
642
- I.toLowerCase() === T.toLowerCase() && (H[x[I]] = y);
641
+ for (const I in S)
642
+ I.toLowerCase() === T.toLowerCase() && (H[S[I]] = x);
643
643
  }
644
- function gt(m, T = 0.97) {
645
- if (!m) return;
646
- const y = m;
647
- if (y.morphTargetInfluences)
648
- for (let b = 0; b < y.morphTargetInfluences.length; b++)
649
- y.morphTargetInfluences[b] *= T;
644
+ function gt(f, T = 0.97) {
645
+ if (!f) return;
646
+ const x = f;
647
+ if (x.morphTargetInfluences)
648
+ for (let b = 0; b < x.morphTargetInfluences.length; b++)
649
+ x.morphTargetInfluences[b] *= T;
650
650
  }
651
651
  const Dn = ln(
652
652
  ({
653
- avatarUrl: m,
653
+ avatarUrl: f,
654
654
  isPlayingRef: T,
655
- visemeQueueRef: y,
655
+ visemeQueueRef: x,
656
656
  audioContextRef: b,
657
- responseAudioStartTimeRef: x,
657
+ responseAudioStartTimeRef: S,
658
658
  adjustments: H,
659
659
  mood: I,
660
660
  expression: Ue,
@@ -668,37 +668,37 @@ const Dn = ln(
668
668
  isNudgeResponse: g,
669
669
  avatarGender: ee
670
670
  }) => {
671
- const { scene: k } = mt(m), Me = mt(ee === "female" ? wn : _n), te = bt(
672
- () => Me.flatMap((p) => p.animations),
671
+ const { scene: k } = mt(f), Me = mt(ee === "female" ? wn : _n), te = bt(
672
+ () => Me.flatMap((m) => m.animations),
673
673
  [Me]
674
674
  ), D = mt(ee === "female" ? yn : vn), J = bt(
675
- () => D.flatMap((p) => p.animations),
675
+ () => D.flatMap((m) => m.animations),
676
676
  [D]
677
- ), Y = c(null), F = c(null), V = c(null), $ = c(null), Ee = c([]), [U] = v(() => new ze.AnimationMixer(k)), N = c({}), O = c(null), ve = c(0), Ne = c(!1), ye = c(0), de = c(null);
677
+ ), Y = a(null), F = a(null), V = a(null), $ = a(null), Ee = a([]), [U] = y(() => new ze.AnimationMixer(k)), N = a({}), O = a(null), ve = a(0), Ne = a(!1), ye = a(0), de = a(null);
678
678
  W(() => {
679
679
  if (!(!te || !k)) {
680
- if (te.forEach((p, u) => {
680
+ if (te.forEach((m, u) => {
681
681
  const s = `idle_${u}`;
682
682
  if (!N.current[s]) {
683
- const o = U.clipAction(p, k);
683
+ const o = U.clipAction(m, k);
684
684
  o.name = s, o.setLoop(ze.LoopOnce, 1), o.clampWhenFinished = !0, N.current[s] = o;
685
685
  }
686
- }), J.forEach((p, u) => {
686
+ }), J.forEach((m, u) => {
687
687
  const s = `talk_${u}`;
688
688
  if (!N.current[s]) {
689
- const o = U.clipAction(p, k);
689
+ const o = U.clipAction(m, k);
690
690
  o.name = s, o.setLoop(ze.LoopOnce, 1), o.clampWhenFinished = !0, N.current[s] = o;
691
691
  }
692
692
  }), te.length > 0) {
693
- const p = N.current.idle_0, u = O.current && U.existingAction(O.current.getClip());
694
- p && !u && (p.reset().fadeIn(0.5).play(), O.current = p);
693
+ const m = N.current.idle_0, u = O.current && U.existingAction(O.current.getClip());
694
+ m && !u && (m.reset().fadeIn(0.5).play(), O.current = m);
695
695
  }
696
696
  return () => {
697
697
  U.stopAllAction(), N.current = {}, O.current = null;
698
698
  };
699
699
  }
700
700
  }, [te, J, k, U]);
701
- const pe = c("");
701
+ const pe = a("");
702
702
  W(() => {
703
703
  if (!l || !k || l === pe.current) return;
704
704
  pe.current = l, de.current = l, new fn().load(
@@ -718,7 +718,7 @@ const Dn = ln(
718
718
  }
719
719
  );
720
720
  }, [l, k, U, R]), W(() => {
721
- const p = (u) => {
721
+ const m = (u) => {
722
722
  const s = u.action, o = s.name || "";
723
723
  if (o.startsWith("idle_")) {
724
724
  const M = (parseInt(o.split("_")[1]) + 1) % te.length, X = N.current[`idle_${M}`];
@@ -743,7 +743,7 @@ const Dn = ln(
743
743
  h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), O.current = h);
744
744
  }
745
745
  };
746
- return U.addEventListener("finished", p), () => U.removeEventListener("finished", p);
746
+ return U.addEventListener("finished", m), () => U.removeEventListener("finished", m);
747
747
  }, [
748
748
  U,
749
749
  te,
@@ -753,13 +753,13 @@ const Dn = ln(
753
753
  Q
754
754
  ]), W(() => {
755
755
  if (R && k) {
756
- const p = O.current, u = p?.name || "";
756
+ const m = O.current, u = m?.name || "";
757
757
  if (u.startsWith("idle_") || u.startsWith("talk_") || u === "") {
758
758
  const s = de.current;
759
759
  if (s) {
760
760
  const o = N.current[`EXPR_${s}`];
761
761
  if (o) {
762
- o.reset().fadeIn(0.3).play(), p && p !== o && p.crossFadeTo(o, 0.3, !0), O.current = o, de.current = null;
762
+ o.reset().fadeIn(0.3).play(), m && m !== o && m.crossFadeTo(o, 0.3, !0), O.current = o, de.current = null;
763
763
  return;
764
764
  }
765
765
  }
@@ -767,14 +767,14 @@ const Dn = ln(
767
767
  const o = Math.floor(
768
768
  Math.random() * J.length
769
769
  ), h = N.current[`talk_${o}`];
770
- h && (h.reset().fadeIn(0.5).play(), p && p.crossFadeTo(h, 0.5, !0), O.current = h);
770
+ h && (h.reset().fadeIn(0.5).play(), m && m.crossFadeTo(h, 0.5, !0), O.current = h);
771
771
  }
772
772
  }
773
773
  } else if (!R && k) {
774
- const p = O.current, u = p?.name || "";
774
+ const m = O.current, u = m?.name || "";
775
775
  if (u.startsWith("talk_") || u.startsWith("EXPR_")) {
776
776
  const s = N.current.idle_0;
777
- s && (s.reset().fadeIn(0.5).play(), p && p.crossFadeTo(s, 0.5, !0), O.current = s);
777
+ s && (s.reset().fadeIn(0.5).play(), m && m.crossFadeTo(s, 0.5, !0), O.current = s);
778
778
  }
779
779
  }
780
780
  }, [R, k, l]), W(() => {
@@ -785,8 +785,8 @@ const Dn = ln(
785
785
  (o.includes("head") || o.includes("avatar")) && (F.current = s, B(`[ANIMATION] Found head mesh: ${s.name}`)), o.includes("teeth") && (V.current = s, B(`[ANIMATION] Found teeth mesh: ${s.name}`)), o.includes("beard") && ($.current = s, B(`[ANIMATION] Found beard mesh: ${s.name}`));
786
786
  }
787
787
  });
788
- const p = F.current?.morphTargetDictionary;
789
- p && Object.keys(p).filter(
788
+ const m = F.current?.morphTargetDictionary;
789
+ m && Object.keys(m).filter(
790
790
  (s) => s.toLowerCase().includes("brow")
791
791
  );
792
792
  const u = [];
@@ -797,8 +797,8 @@ const Dn = ln(
797
797
  }
798
798
  }), Ee.current = u, u.length > 0 && B("[ANIMATION] Meshes with brow morphs:", u.length);
799
799
  }, [k]);
800
- const He = (p, u = 1) => {
801
- const s = `viseme_${p}`.toLowerCase(), o = Tn.find((h) => h.key.toLowerCase() === s);
800
+ const He = (m, u = 1) => {
801
+ const s = `viseme_${m}`.toLowerCase(), o = Tn.find((h) => h.key.toLowerCase() === s);
802
802
  if (o) {
803
803
  for (const h in o.mix) {
804
804
  const M = o.mix[h] * u;
@@ -810,15 +810,15 @@ const Dn = ln(
810
810
  E(V.current, h, M);
811
811
  }
812
812
  }
813
- }, xe = (p) => {
814
- const u = nt[p] ?? nt.neutral;
813
+ }, xe = (m) => {
814
+ const u = nt[m] ?? nt.neutral;
815
815
  for (const s in u)
816
816
  E(F.current, s, u[s]), E(V.current, s, u[s]), E($.current, s, u[s]);
817
817
  };
818
- return an((p, u) => {
818
+ return an((m, u) => {
819
819
  const s = Math.pow(0.88, 60 * u);
820
820
  gt(F.current, s), gt(V.current, s), gt($.current, s), xe(I);
821
- const o = p.clock.elapsedTime;
821
+ const o = m.clock.elapsedTime;
822
822
  let h = 0;
823
823
  if (Math.floor(o) % 5 === 0 && Math.floor((o - u) % 5) !== 0) {
824
824
  let q = null;
@@ -849,9 +849,9 @@ const Dn = ln(
849
849
  ), Y.current.position.set(...H.position), Y.current.scale.setScalar(H.scale), Y.current.rotation.x = H.rotation[0], Y.current.rotation.z = H.rotation[2];
850
850
  }
851
851
  if (T.current && b.current) {
852
- const q = b.current.currentTime, Be = (q - x.current) * 1e3 - -150;
853
- for (let re = 0; re < y.current.length; re++) {
854
- const ae = y.current[re];
852
+ const q = b.current.currentTime, Be = (q - S.current) * 1e3 - -150;
853
+ for (let re = 0; re < x.current.length; re++) {
854
+ const ae = x.current[re];
855
855
  Be >= ae.vtime && Be < ae.vtime + ae.vduration && He(ae.viseme, ae.weight ?? 1);
856
856
  }
857
857
  q > we.current + 0.5 && (K(), j(!1));
@@ -859,38 +859,38 @@ const Dn = ln(
859
859
  }), /* @__PURE__ */ d("group", { ref: Y, children: /* @__PURE__ */ d("primitive", { object: k }) });
860
860
  }
861
861
  );
862
- function On(m) {
863
- return m ? m.charAt(0).toUpperCase() + m.slice(1).toLowerCase() : "";
862
+ function On(f) {
863
+ return f ? f.charAt(0).toUpperCase() + f.slice(1).toLowerCase() : "";
864
864
  }
865
- function Wt(m) {
866
- return m.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
865
+ function Wt(f) {
866
+ return f.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
867
867
  }
868
868
  const Cn = ({
869
- token: m,
869
+ token: f,
870
870
  agentToken: T,
871
- onNavigationRequested: y,
871
+ onNavigationRequested: x,
872
872
  avatarGender: b,
873
- presetUserDetails: x,
873
+ presetUserDetails: S,
874
874
  onAvatarReady: H
875
875
  } = {}) => {
876
- const I = m ?? T ?? "", Ue = bn(I || void 0), [se, R] = v(""), [we, K] = v(""), [j, l] = v("Ready"), [Q, g] = v(!1), [ee, k] = v(!1), [Te, Me] = v([]), [te, Se] = v(""), D = c(null), [J, Y] = v(
876
+ const I = f ?? T ?? "", Ue = bn(I || void 0), [se, R] = y(""), [we, K] = y(""), [j, l] = y("Ready"), [Q, g] = y(!1), [ee, k] = y(!1), [Te, Me] = y([]), [te, Se] = y(""), D = a(null), [J, Y] = y(
877
877
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
878
878
  );
879
879
  W(() => {
880
880
  const e = window.matchMedia("(max-width: 480px)"), t = () => Y(e.matches);
881
881
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
882
882
  }, []);
883
- const F = J ? 80 : 600, V = c(!1), $ = c([]), Ee = c(0), U = c(!1), N = c([]), O = c(null), ve = c([]);
884
- c([]);
885
- const Ne = c([]), ye = c(0), de = c(0), pe = c(0), He = c(0), xe = c(!1), [p, u] = v(
883
+ const F = J ? 80 : 600, V = a(!1), $ = a([]), Ee = a(0), U = a(!1), N = a([]), O = a(null), ve = a([]);
884
+ a([]);
885
+ const Ne = a([]), ye = a(0), de = a(0), pe = a(0), He = a(0), xe = a(!1), [m, u] = y(
886
886
  null
887
- ), s = c(null), [o, h] = v("neutral"), [M, X] = v(""), [rt, Ke] = v(""), [je, Ie] = v("Chat with us"), [ne, Qe] = v(
887
+ ), s = a(null), [o, h] = y("neutral"), [M, X] = y(""), [rt, Ke] = y(""), [je, Ie] = y("Chat with us"), [ne, Qe] = y(
888
888
  null
889
- ), [oe, De] = v("hidden"), [Le, Pe] = v(""), Oe = c(null), q = c(oe);
889
+ ), [oe, De] = y("hidden"), [Le, Pe] = y(""), Oe = a(null), q = a(oe);
890
890
  q.current = oe;
891
- const [ke, z] = v(null), Be = c(null), re = c(null), [ae, _t] = v(!1), wt = c(null), [he, Xe] = v("hidden"), [St, Vt] = v(""), it = c(he);
891
+ const [ke, z] = y(null), Be = a(null), re = a(null), [ae, _t] = y(!1), wt = a(null), [he, Xe] = y("hidden"), [St, Vt] = y(""), it = a(he);
892
892
  it.current = he;
893
- const ie = c(""), ge = c(!1), be = c(""), vt = c(Date.now()), st = c([]), Je = c(!1), [ot, qe] = v(!1), [yt, xt] = v(!1), Re = c(null), We = bt(() => ae ? "Try again" : j === "Busy" ? "Busy" : j === "Thinking..." || j === "Processing Voice..." ? j : ne != null && ne !== "" && ne !== "none" && ne !== "<none>" ? `Enter ${On(ne)}` : he !== "hidden" || !yt ? null : Bt, [j, ne, ae, he, yt]), Lt = !ae && j !== "Busy" && j !== "Thinking..." && j !== "Processing Voice..." && (ne == null || ne === "" || ne === "none" || ne === "<none>");
893
+ const ie = a(""), ge = a(!1), be = a(""), vt = a(Date.now()), st = a([]), Je = a(!1), [ot, qe] = y(!1), [yt, xt] = y(!1), Re = a(null), We = bt(() => ae ? "Try again" : j === "Busy" ? "Busy" : j === "Thinking..." || j === "Processing Voice..." ? j : ne != null && ne !== "" && ne !== "none" && ne !== "<none>" ? `Enter ${On(ne)}` : he !== "hidden" || !yt ? null : Bt, [j, ne, ae, he, yt]), Lt = !ae && j !== "Busy" && j !== "Thinking..." && j !== "Processing Voice..." && (ne == null || ne === "" || ne === "none" || ne === "<none>");
894
894
  W(() => {
895
895
  if (he !== "hidden" || !Lt) {
896
896
  xt(!1), Re.current != null && (clearTimeout(Re.current), Re.current = null);
@@ -948,21 +948,21 @@ const Cn = ({
948
948
  if (e.expression != null) {
949
949
  const r = String(e.expression).trim();
950
950
  X(r);
951
- const a = Sn.find(
952
- (f) => f.name.toLowerCase() === r.toLowerCase()
951
+ const c = Sn.find(
952
+ (p) => p.name.toLowerCase() === r.toLowerCase()
953
953
  );
954
954
  B(
955
- `[STREAM] Animation match for "${r}": ${a ? a.name : "NONE"}`
956
- ), Ke(a?.url ?? "");
955
+ `[STREAM] Animation match for "${r}": ${c ? c.name : "NONE"}`
956
+ ), Ke(c?.url ?? "");
957
957
  }
958
958
  if (e.navigation != null) {
959
959
  const r = String(e.navigation).trim();
960
- r !== "" && (y ? y(r) : window.open(r, "_blank"));
960
+ r !== "" && (x ? x(r) : window.open(r, "_blank"));
961
961
  }
962
962
  const t = e.ask_for || e.lead_capture?.ask_for, n = t ? String(t).trim().toLowerCase() : "", i = n === "none" || n === "<none>";
963
963
  if (t && !i) {
964
964
  const r = n;
965
- if (x && (r === "email" && x.email || r === "name" && x.name || r === "phone" && x.phone))
965
+ if (S && (r === "email" && S.email || r === "name" && S.name || r === "phone" && S.phone))
966
966
  return;
967
967
  Qe(r || null), Ie(r === "email" ? "Enter your email" : r === "name" ? "Enter your name" : r === "phone" ? "Enter your phone number" : "Chat with us");
968
968
  } else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Qe(null), je !== "Chat with us" && Ie("Chat with us"));
@@ -1011,22 +1011,22 @@ const Cn = ({
1011
1011
  if (!sessionStorage.getItem(
1012
1012
  "STREAMOJI_LEADS_SESSION_LEAD_ID"
1013
1013
  )) {
1014
- const r = "secret", a = Math.floor(Date.now() / 1e3).toString();
1014
+ const r = "secret", c = Math.floor(Date.now() / 1e3).toString();
1015
1015
  try {
1016
- const f = new TextEncoder(), _ = await crypto.subtle.importKey(
1016
+ const p = new TextEncoder(), _ = await crypto.subtle.importKey(
1017
1017
  "raw",
1018
- f.encode(r),
1018
+ p.encode(r),
1019
1019
  { name: "HMAC", hash: "SHA-256" },
1020
1020
  !1,
1021
1021
  ["sign"]
1022
- ), S = await crypto.subtle.sign(
1022
+ ), v = await crypto.subtle.sign(
1023
1023
  "HMAC",
1024
1024
  _,
1025
- f.encode(a)
1026
- ), w = Array.from(new Uint8Array(S)).map((A) => A.toString(16).padStart(2, "0")).join("");
1025
+ p.encode(c)
1026
+ ), w = Array.from(new Uint8Array(v)).map((A) => A.toString(16).padStart(2, "0")).join("");
1027
1027
  sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w), B("[SESSION] New HMAC UID generated and saved:", w);
1028
- } catch (f) {
1029
- console.error("[SESSION] HMAC generation failed:", f);
1028
+ } catch (p) {
1029
+ console.error("[SESSION] HMAC generation failed:", p);
1030
1030
  const _ = Math.random().toString(36) + Date.now().toString();
1031
1031
  sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", _);
1032
1032
  }
@@ -1039,7 +1039,7 @@ const Cn = ({
1039
1039
  } catch {
1040
1040
  i = [];
1041
1041
  }
1042
- i.length === 0 && x && (x.name || x.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${x.name || ""}" , Email is "${x.email || ""}"` }], sessionStorage.setItem(
1042
+ 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(
1043
1043
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1044
1044
  JSON.stringify(i)
1045
1045
  )) : n || sessionStorage.setItem(
@@ -1047,7 +1047,7 @@ const Cn = ({
1047
1047
  JSON.stringify([])
1048
1048
  );
1049
1049
  })();
1050
- }, [x]), W(() => {
1050
+ }, [S]), W(() => {
1051
1051
  const e = () => {
1052
1052
  vt.current = Date.now(), Je.current && (Je.current = !1, qe(!1), Me([]), Se(""), K(""), k(!1));
1053
1053
  };
@@ -1058,19 +1058,19 @@ const Cn = ({
1058
1058
  qe(!0), Me(st.current);
1059
1059
  else
1060
1060
  try {
1061
- const r = `${Ye}/nudgeUser`, a = {
1061
+ const r = `${Ye}/nudgeUser`, c = {
1062
1062
  navigationUrl: window.location.href,
1063
1063
  token: I
1064
- }, f = await fetch(r, {
1064
+ }, p = await fetch(r, {
1065
1065
  method: "POST",
1066
1066
  headers: {
1067
1067
  "Content-Type": "application/json"
1068
1068
  },
1069
- body: JSON.stringify(a)
1069
+ body: JSON.stringify(c)
1070
1070
  });
1071
- if (f.ok) {
1072
- const S = (await f.json()).nudge_questions;
1073
- S && S.length > 0 && (B("[NUDGE] Received nudge questions from API:", S), st.current = S, qe(!0), Me(S));
1071
+ if (p.ok) {
1072
+ const v = (await p.json()).nudge_questions;
1073
+ v && v.length > 0 && (B("[NUDGE] Received nudge questions from API:", v), st.current = v, qe(!0), Me(v));
1074
1074
  }
1075
1075
  } catch (r) {
1076
1076
  console.error("[NUDGE] Error calling /nudgeUser:", r), Je.current = !1;
@@ -1083,15 +1083,15 @@ const Cn = ({
1083
1083
  if (Te.length === 0) return;
1084
1084
  let e = 0, t = 0, n = !1, i = 100;
1085
1085
  const r = () => {
1086
- const a = Te[e];
1086
+ const c = Te[e];
1087
1087
  if (n) {
1088
- const f = a.substring(0, t - 1);
1089
- Se(f), t--, i = 50;
1088
+ const p = c.substring(0, t - 1);
1089
+ Se(p), t--, i = 50;
1090
1090
  } else {
1091
- const f = a.substring(0, t + 1);
1092
- Se(f), t++, i = 100;
1091
+ const p = c.substring(0, t + 1);
1092
+ Se(p), t++, i = 100;
1093
1093
  }
1094
- !n && t === a.length ? (n = !0, i = 3e3) : n && t === 0 && (n = !1, e = (e + 1) % Te.length, i = 500), D.current = setTimeout(r, i);
1094
+ !n && t === c.length ? (n = !0, i = 3e3) : n && t === 0 && (n = !1, e = (e + 1) % Te.length, i = 500), D.current = setTimeout(r, i);
1095
1095
  };
1096
1096
  return r(), () => {
1097
1097
  D.current && clearTimeout(D.current);
@@ -1110,11 +1110,11 @@ const Cn = ({
1110
1110
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1111
1111
  JSON.stringify(e)
1112
1112
  );
1113
- }, [ct, ut] = v(!1), [At, lt] = v(0), fe = c(null), et = c([]), Tt = c(0), [Mt, Gt] = v(
1113
+ }, [ct, ut] = y(!1), [At, lt] = y(0), fe = a(null), et = a([]), Tt = a(0), [Mt, Gt] = y(
1114
1114
  null
1115
- ), [zt, dt] = v(
1115
+ ), [zt, dt] = y(
1116
1116
  null
1117
- ), _e = c(null), Ce = c(
1117
+ ), _e = a(null), Ce = a(
1118
1118
  null
1119
1119
  ), Ge = $e((e = !1) => {
1120
1120
  e && (xe.current = !0, g(!1), l("Ready")), N.current = [], $.current = [], U.current = !1, k(!1), ye.current = 0, de.current = 0, pe.current = 0, ve.current.forEach((t) => {
@@ -1127,12 +1127,12 @@ const Cn = ({
1127
1127
  try {
1128
1128
  const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, n = new t(), i = n.createMediaStreamSource(e), r = n.createAnalyser();
1129
1129
  r.fftSize = 64, i.connect(r), _e.current = n, Ce.current = i, dt(r);
1130
- const a = new MediaRecorder(e);
1131
- fe.current = a, et.current = [], a.ondataavailable = (f) => {
1132
- f.data.size > 0 && et.current.push(f.data);
1133
- }, a.onstop = async () => {
1134
- const f = Date.now() - Tt.current;
1135
- if (dt(null), Ce.current && (Ce.current.disconnect(), Ce.current = null), _e.current && _e.current.state !== "closed" && (_e.current.close(), _e.current = null), f < 1e3) {
1130
+ const c = new MediaRecorder(e);
1131
+ fe.current = c, et.current = [], c.ondataavailable = (p) => {
1132
+ p.data.size > 0 && et.current.push(p.data);
1133
+ }, c.onstop = async () => {
1134
+ const p = Date.now() - Tt.current;
1135
+ if (dt(null), Ce.current && (Ce.current.disconnect(), Ce.current = null), _e.current && _e.current.state !== "closed" && (_e.current.close(), _e.current = null), p < 1e3) {
1136
1136
  l("Recording too short. Hold or click longer."), g(!1);
1137
1137
  return;
1138
1138
  }
@@ -1140,7 +1140,7 @@ const Cn = ({
1140
1140
  type: "audio/wav"
1141
1141
  });
1142
1142
  await Zt(_);
1143
- }, Tt.current = Date.now(), a.start(100), ut(!0), l("Listening...");
1143
+ }, Tt.current = Date.now(), c.start(100), ut(!0), l("Listening...");
1144
1144
  } catch (e) {
1145
1145
  console.error("Error accessing microphone:", e), l("Mic Access Error");
1146
1146
  }
@@ -1156,13 +1156,13 @@ const Cn = ({
1156
1156
  if (t <= 0) return;
1157
1157
  const n = O.current, i = ye.current;
1158
1158
  if (!n) return;
1159
- const r = n.currentTime - i, a = Math.min(Math.max(0, r), t), _ = Wt(we).trim().length;
1159
+ const r = n.currentTime - i, c = Math.min(Math.max(0, r), t), _ = Wt(we).trim().length;
1160
1160
  if (_ <= 0) return;
1161
- const S = Math.min(
1162
- Math.round(a / t * _),
1161
+ const v = Math.min(
1162
+ Math.round(c / t * _),
1163
1163
  _
1164
1164
  );
1165
- u(S);
1165
+ u(v);
1166
1166
  };
1167
1167
  return clearInterval(s.current ?? void 0), s.current = setInterval(e, 90), () => clearInterval(s.current ?? void 0);
1168
1168
  }, [ee, we, pe.current]), W(() => {
@@ -1173,20 +1173,20 @@ const Cn = ({
1173
1173
  }, [ct]);
1174
1174
  const Xt = (e) => {
1175
1175
  const t = e.numberOfChannels, n = e.length * t * 2 + 44, i = new ArrayBuffer(n), r = new DataView(i);
1176
- let a = 0;
1177
- const f = (w) => {
1178
- r.setUint16(a, w, !0), a += 2;
1176
+ let c = 0;
1177
+ const p = (w) => {
1178
+ r.setUint16(c, w, !0), c += 2;
1179
1179
  }, _ = (w) => {
1180
- r.setUint32(a, w, !0), a += 4;
1180
+ r.setUint32(c, w, !0), c += 4;
1181
1181
  };
1182
- _(1179011410), _(n - 8), _(1163280727), _(544501094), _(16), f(1), f(t), _(e.sampleRate), _(e.sampleRate * 2 * t), f(t * 2), f(16), _(1635017060), _(n - a - 4);
1183
- const S = [];
1184
- for (let w = 0; w < t; w++) S.push(e.getChannelData(w));
1182
+ _(1179011410), _(n - 8), _(1163280727), _(544501094), _(16), p(1), p(t), _(e.sampleRate), _(e.sampleRate * 2 * t), p(t * 2), p(16), _(1635017060), _(n - c - 4);
1183
+ const v = [];
1184
+ for (let w = 0; w < t; w++) v.push(e.getChannelData(w));
1185
1185
  let L = 0;
1186
- for (; a < n; ) {
1186
+ for (; c < n; ) {
1187
1187
  for (let w = 0; w < t; w++) {
1188
- let A = Math.max(-1, Math.min(1, S[w][L]));
1189
- A = A < 0 ? A * 32768 : A * 32767, r.setInt16(a, A, !0), a += 2;
1188
+ let A = Math.max(-1, Math.min(1, v[w][L]));
1189
+ A = A < 0 ? A * 32768 : A * 32767, r.setInt16(c, A, !0), c += 2;
1190
1190
  }
1191
1191
  L++;
1192
1192
  }
@@ -1205,15 +1205,15 @@ const Cn = ({
1205
1205
  try {
1206
1206
  const i = window.AudioContext || window.webkitAudioContext, r = O.current ?? new i();
1207
1207
  r.state === "suspended" && await r.resume(), O.current = r;
1208
- const a = window.atob(e), f = new Uint8Array(a.length);
1209
- for (let P = 0; P < a.length; P++)
1210
- f[P] = a.charCodeAt(P);
1211
- const _ = await r.decodeAudioData(f.buffer.slice(0));
1208
+ const c = window.atob(e), p = new Uint8Array(c.length);
1209
+ for (let P = 0; P < c.length; P++)
1210
+ p[P] = c.charCodeAt(P);
1211
+ const _ = await r.decodeAudioData(p.buffer.slice(0));
1212
1212
  pe.current += _.duration;
1213
- const S = r.currentTime;
1213
+ const v = r.currentTime;
1214
1214
  let L = de.current;
1215
1215
  const w = !U.current;
1216
- L < S && (L = S + 0.1), de.current = L + _.duration;
1216
+ L < v && (L = v + 0.1), de.current = L + _.duration;
1217
1217
  const A = r.createBufferSource();
1218
1218
  A.buffer = _;
1219
1219
  let G = Mt;
@@ -1227,11 +1227,11 @@ const Cn = ({
1227
1227
  3
1228
1228
  )}`
1229
1229
  ), ye.current = L;
1230
- const P = (L - S) * 1e3;
1230
+ const P = (L - v) * 1e3;
1231
1231
  Ee.current = performance.now() + P, B(
1232
1232
  `[AUDIO] Response started. Initial startTime: ${L.toFixed(
1233
1233
  3
1234
- )}, CT: ${S.toFixed(3)}`
1234
+ )}, CT: ${v.toFixed(3)}`
1235
1235
  );
1236
1236
  }
1237
1237
  A.start(L);
@@ -1268,31 +1268,31 @@ const Cn = ({
1268
1268
  }, Zt = async (e) => {
1269
1269
  try {
1270
1270
  g(!0), qe(!1), be.current = "", K(""), l("Processing Voice...");
1271
- const t = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), r = Xt(i), a = new FileReader();
1272
- a.readAsDataURL(r), a.onloadend = async () => {
1273
- const f = a.result.split(",")[1];
1271
+ const t = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), r = Xt(i), c = new FileReader();
1272
+ c.readAsDataURL(r), c.onloadend = async () => {
1273
+ const p = c.result.split(",")[1];
1274
1274
  Ge(), R(""), ie.current = "", ge.current = !1;
1275
1275
  const _ = `${Ye}/stt?token=${encodeURIComponent(
1276
1276
  I
1277
- )}`, S = await fetch(_, {
1277
+ )}`, v = await fetch(_, {
1278
1278
  method: "POST",
1279
1279
  headers: { "Content-Type": "application/json" },
1280
1280
  body: JSON.stringify({
1281
- audio_base64: f,
1281
+ audio_base64: p,
1282
1282
  audio_format: "wav"
1283
1283
  })
1284
1284
  });
1285
- if (S.status === 429) {
1285
+ if (v.status === 429) {
1286
1286
  try {
1287
- const ce = await S.text(), C = JSON.parse(ce);
1287
+ const ce = await v.text(), C = JSON.parse(ce);
1288
1288
  B("[STT] 429 agent at capacity:", C?.detail);
1289
1289
  } catch {
1290
1290
  }
1291
1291
  R(""), l("Busy"), g(!1);
1292
1292
  return;
1293
1293
  }
1294
- if (!S.ok) {
1295
- const ce = await S.text();
1294
+ if (!v.ok) {
1295
+ const ce = await v.text();
1296
1296
  let C = "STT Failed";
1297
1297
  try {
1298
1298
  C = JSON.parse(ce).error || C;
@@ -1301,7 +1301,7 @@ const Cn = ({
1301
1301
  }
1302
1302
  throw new Error(C);
1303
1303
  }
1304
- const L = S.body;
1304
+ const L = v.body;
1305
1305
  if (B("this is body" + L), !L) {
1306
1306
  l("STT Failed"), g(!1);
1307
1307
  return;
@@ -1366,8 +1366,8 @@ const Cn = ({
1366
1366
  }, Ve = (e) => {
1367
1367
  const t = e.split(/\r?\n/);
1368
1368
  let n = "", i = "";
1369
- for (const a of t)
1370
- a.startsWith("event:") ? n = a.slice(6).trim() : a.startsWith("data:") && (i = a.slice(5).trim());
1369
+ for (const c of t)
1370
+ c.startsWith("event:") ? n = c.slice(6).trim() : c.startsWith("data:") && (i = c.slice(5).trim());
1371
1371
  if (!n) return null;
1372
1372
  let r = {};
1373
1373
  if (i)
@@ -1427,22 +1427,22 @@ const Cn = ({
1427
1427
  }
1428
1428
  const r = i.getReader();
1429
1429
  xe.current = !1;
1430
- const a = new TextDecoder();
1431
- let f = "";
1430
+ const c = new TextDecoder();
1431
+ let p = "";
1432
1432
  for (; ; ) {
1433
- const { done: _, value: S } = await r.read();
1434
- S && (f += a.decode(S, { stream: !0 }));
1435
- const L = f.split(`
1433
+ const { done: _, value: v } = await r.read();
1434
+ v && (p += c.decode(v, { stream: !0 }));
1435
+ const L = p.split(`
1436
1436
 
1437
1437
  `);
1438
- f = L.pop() ?? "";
1438
+ p = L.pop() ?? "";
1439
1439
  for (const w of L) {
1440
1440
  const A = Ve(w);
1441
1441
  A && tt(A.event, A.data);
1442
1442
  }
1443
1443
  if (_) {
1444
- if (f.trim()) {
1445
- const w = Ve(f.trim());
1444
+ if (p.trim()) {
1445
+ const w = Ve(p.trim());
1446
1446
  w && tt(w.event, w.data);
1447
1447
  }
1448
1448
  l("Ready"), g(!1);
@@ -1452,13 +1452,13 @@ const Cn = ({
1452
1452
  } catch (n) {
1453
1453
  console.error("Streaming Error:", n), l("Failed"), g(!1);
1454
1454
  }
1455
- }, It = $e(async (e, t, n, i, r, a = "inworld") => {
1456
- const f = `${Ye}/avatar_tts`;
1457
- await Et(f, { text: e, userQuery: t, llmPrompt: n, accessKey: i, agentUrl: r, flow: a });
1458
- }, []), Dt = $e(async (e, t, n, i, r = "inworld") => {
1459
- const a = `${Ye}/avatar_ttsWithKnowledge`;
1460
- await Et(a, { userQuery: e, llmPrompt: t, knowledge: n, history: i, flow: r });
1461
- }, []), Ot = c(!1);
1455
+ }, It = $e(async (e, t, n) => {
1456
+ const i = `${Ye}/avatar_tts`;
1457
+ await Et(i, { text: e, userQuery: t, llmPrompt: n });
1458
+ }, []), Dt = $e(async (e, t, n, i) => {
1459
+ const r = `${Ye}/avatar_ttsWithKnowledge`;
1460
+ await Et(r, { userQuery: e, llmPrompt: t, knowledge: n, history: i });
1461
+ }, []), Ot = a(!1);
1462
1462
  W(() => {
1463
1463
  H && !Ot.current && (H({ avatarSpeak: It, avatarRespond: Dt }), Ot.current = !0);
1464
1464
  }, [H, It, Dt]);
@@ -1479,7 +1479,7 @@ const Cn = ({
1479
1479
  lead_id: i
1480
1480
  };
1481
1481
  B("[CHAT] Sending payload:", r);
1482
- const a = await fetch(t, {
1482
+ const c = await fetch(t, {
1483
1483
  method: "POST",
1484
1484
  headers: {
1485
1485
  "Content-Type": "application/json"
@@ -1487,31 +1487,31 @@ const Cn = ({
1487
1487
  body: JSON.stringify(r),
1488
1488
  cache: "default"
1489
1489
  });
1490
- if (a.status === 429) {
1490
+ if (c.status === 429) {
1491
1491
  try {
1492
- const w = await a.json();
1492
+ const w = await c.json();
1493
1493
  B("[CHAT] 429 agent at capacity:", w?.detail);
1494
1494
  } catch {
1495
1495
  }
1496
1496
  R(""), l("Busy"), g(!1);
1497
1497
  return;
1498
1498
  }
1499
- if (!a.ok)
1499
+ if (!c.ok)
1500
1500
  throw new Error("Agent request failed");
1501
- const f = a.body;
1502
- if (!f) {
1501
+ const p = c.body;
1502
+ if (!p) {
1503
1503
  l("Agent Failed"), g(!1);
1504
1504
  return;
1505
1505
  }
1506
- const _ = f.getReader();
1506
+ const _ = p.getReader();
1507
1507
  xe.current = !1;
1508
- const S = new TextDecoder();
1508
+ const v = new TextDecoder();
1509
1509
  let L = "";
1510
1510
  for (; ; ) {
1511
1511
  const { done: w, value: A } = await _.read();
1512
1512
  B(
1513
1513
  `[SSE] Chunk received. done=${w}, length=${A?.length || 0}`
1514
- ), A && (L += S.decode(A, { stream: !0 }));
1514
+ ), A && (L += v.decode(A, { stream: !0 }));
1515
1515
  const G = L.split(`
1516
1516
 
1517
1517
  `);
@@ -1535,7 +1535,7 @@ const Cn = ({
1535
1535
  }
1536
1536
  }, nn = we.trim(), Ct = Wt(nn), ft = Ct && ee ? Ct.slice(
1537
1537
  0,
1538
- p != null && p > 0 ? p : 0
1538
+ m != null && m > 0 ? m : 0
1539
1539
  ) : "";
1540
1540
  W(() => {
1541
1541
  const e = it.current;
@@ -1879,17 +1879,19 @@ const Cn = ({
1879
1879
  ] }) })
1880
1880
  ] });
1881
1881
  }, Wn = ({
1882
- token: m,
1882
+ token: f,
1883
1883
  avatarGender: T,
1884
- onNavigationRequested: y,
1885
- presetUserDetails: b
1884
+ onNavigationRequested: x,
1885
+ presetUserDetails: b,
1886
+ onAvatarReady: S
1886
1887
  }) => /* @__PURE__ */ d(
1887
1888
  Cn,
1888
1889
  {
1889
- token: m,
1890
- onNavigationRequested: y,
1890
+ token: f,
1891
+ onNavigationRequested: x,
1891
1892
  avatarGender: T,
1892
- presetUserDetails: b
1893
+ presetUserDetails: b,
1894
+ onAvatarReady: S
1893
1895
  }
1894
1896
  );
1895
1897
  export {