@streamoji/avatar-widget 0.2.7 → 0.2.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,100 +1,100 @@
1
- import { jsx as l, jsxs as oe } from "react/jsx-runtime";
2
- import { useGLTF as ct, Environment as zt } from "@react-three/drei";
3
- import { useFrame as Yt, Canvas as Qt, useThree as Xt } from "@react-three/fiber";
4
- import { memo as Kt, useMemo as dt, useRef as c, useState as b, useEffect as P, useCallback as Qe, useLayoutEffect as Zt, Suspense as en } from "react";
1
+ import { jsx as l, jsxs as ae } from "react/jsx-runtime";
2
+ import { useGLTF as lt, Environment as Yt } from "@react-three/drei";
3
+ import { useFrame as Qt, Canvas as Xt, useThree as Kt } from "@react-three/fiber";
4
+ import { memo as Zt, useMemo as ft, useRef as a, useState as g, useEffect as $, useCallback as Ye, useLayoutEffect as en, Suspense as tn } from "react";
5
5
  import * as Ve from "three";
6
- import { GLTFLoader as tn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
- const lt = "https://ai.streamoji.com", B = (...f) => {
8
- }, nn = (...f) => {
9
- }, Tt = ({ analyser: f }) => {
10
- const A = c(null), w = c(null);
11
- return P(() => {
12
- const g = A.current;
13
- if (!g) return;
14
- const T = g.getContext("2d", { alpha: !0 });
15
- if (!T) return;
16
- let V, E = null;
17
- f && (f.fftSize = 128, E = new Uint8Array(f.frequencyBinCount));
18
- const te = () => {
19
- V = requestAnimationFrame(te), (g.width !== g.offsetWidth || g.height !== g.offsetHeight) && (g.width = g.offsetWidth, g.height = g.offsetHeight);
20
- const ae = g.width, I = g.height;
21
- if (ae === 0 || I === 0) return;
22
- const U = I / 2;
23
- T.clearRect(0, 0, ae, I), T.fillStyle = "#1e293b";
24
- const _ = 2, m = _ + 2, Y = ae * 0.95, $ = Math.floor(Y / m);
25
- (!w.current || w.current.length !== $) && (w.current = new Float32Array($).fill(2));
26
- const pe = $ * m, k = (ae - pe) / 2;
27
- f && E && f.getByteFrequencyData(E);
28
- const He = E ? E.length : 0, q = Math.floor(He * 0.7) / $, ge = new Float32Array($);
29
- for (let M = 0; M < $; M++) {
30
- let O = 0;
31
- if (E && q > 0) {
32
- const be = Math.floor(M * q), L = Math.floor((M + 1) * q);
33
- for (let v = be; v < L; v++) {
34
- const y = E[v] || 0;
35
- y > O && (O = y);
6
+ import { GLTFLoader as nn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
+ const ut = "https://ai.streamoji.com", V = (...f) => {
8
+ }, rn = (...f) => {
9
+ }, Et = ({ analyser: f }) => {
10
+ const T = a(null), b = a(null);
11
+ return $(() => {
12
+ const p = T.current;
13
+ if (!p) return;
14
+ const _ = p.getContext("2d", { alpha: !0 });
15
+ if (!_) return;
16
+ let O, H = null;
17
+ f && (f.fftSize = 128, H = new Uint8Array(f.frequencyBinCount));
18
+ const he = () => {
19
+ O = requestAnimationFrame(he), (p.width !== p.offsetWidth || p.height !== p.offsetHeight) && (p.width = p.offsetWidth, p.height = p.offsetHeight);
20
+ const X = p.width, D = p.height;
21
+ if (X === 0 || D === 0) return;
22
+ const me = D / 2;
23
+ _.clearRect(0, 0, X, D), _.fillStyle = "#1e293b";
24
+ const I = 2, k = I + 2, E = X * 0.95, U = Math.floor(E / k);
25
+ (!b.current || b.current.length !== U) && (b.current = new Float32Array(U).fill(2));
26
+ const be = U * k, y = (X - be) / 2;
27
+ f && H && f.getByteFrequencyData(H);
28
+ const Ie = H ? H.length : 0, G = Math.floor(Ie * 0.7) / U, ce = new Float32Array(U);
29
+ for (let M = 0; M < U; M++) {
30
+ let B = 0;
31
+ if (H && G > 0) {
32
+ const ne = Math.floor(M * G), P = Math.floor((M + 1) * G);
33
+ for (let S = ne; S < P; S++) {
34
+ const x = H[S] || 0;
35
+ x > B && (B = x);
36
36
  }
37
37
  }
38
- O < 10 && (O = 0);
39
- const W = O / 255, D = O > 0 ? Math.max(2, Math.pow(W, 1.4) * I * 0.25) : 2;
40
- ge[M] = D;
38
+ B < 10 && (B = 0);
39
+ const j = B / 255, N = B > 0 ? Math.max(2, Math.pow(j, 1.4) * D * 0.25) : 2;
40
+ ce[M] = N;
41
41
  }
42
- for (let M = 0; M < $; M++) {
43
- const O = $ - 1 - M, W = Math.max(ge[M], ge[O]), D = w.current[M] + (W - w.current[M]) * 0.3;
44
- w.current[M] = D;
45
- const be = k + M * m, L = U - D / 2;
46
- T.beginPath(), T.roundRect ? T.roundRect(be, L, _, D, 4) : T.fillRect(be, L, _, D), T.fill();
42
+ for (let M = 0; M < U; M++) {
43
+ const B = U - 1 - M, j = Math.max(ce[M], ce[B]), N = b.current[M] + (j - b.current[M]) * 0.3;
44
+ b.current[M] = N;
45
+ const ne = y + M * k, P = me - N / 2;
46
+ _.beginPath(), _.roundRect ? _.roundRect(ne, P, I, N, 4) : _.fillRect(ne, P, I, N), _.fill();
47
47
  }
48
48
  };
49
- return te(), () => {
50
- cancelAnimationFrame(V);
49
+ return he(), () => {
50
+ cancelAnimationFrame(O);
51
51
  };
52
52
  }, [f]), /* @__PURE__ */ l(
53
53
  "canvas",
54
54
  {
55
- ref: A,
55
+ ref: T,
56
56
  style: { width: "100%", height: "100%", display: "block" }
57
57
  }
58
58
  );
59
- }, rn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Et = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.glb";
60
- async function sn(f) {
61
- const A = await crypto.subtle.digest(
59
+ }, sn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", It = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.glb";
60
+ async function on(f) {
61
+ const T = await crypto.subtle.digest(
62
62
  "SHA-256",
63
63
  new TextEncoder().encode(f)
64
64
  );
65
- return Array.from(new Uint8Array(A)).map((w) => w.toString(16).padStart(2, "0")).join("");
65
+ return Array.from(new Uint8Array(T)).map((b) => b.toString(16).padStart(2, "0")).join("");
66
66
  }
67
- function on(f) {
68
- const [A, w] = b(null);
69
- return P(() => {
67
+ function an(f) {
68
+ const [T, b] = g(null);
69
+ return $(() => {
70
70
  if (!f) {
71
- w(null);
71
+ b(null);
72
72
  return;
73
73
  }
74
- let g = !1;
75
- return sn(f).then((T) => {
76
- if (g) return;
77
- const V = `${rn}/${T}.glb`;
78
- fetch(V, { method: "HEAD" }).then((E) => {
79
- g || w(E.ok ? V : Et);
74
+ let p = !1;
75
+ return on(f).then((_) => {
76
+ if (p) return;
77
+ const O = `${sn}/${_}.glb`;
78
+ fetch(O, { method: "HEAD" }).then((H) => {
79
+ p || b(H.ok ? O : It);
80
80
  }).catch(() => {
81
- g || w(Et);
81
+ p || b(It);
82
82
  });
83
83
  }), () => {
84
- g = !0;
84
+ p = !0;
85
85
  };
86
- }, [f]), A;
86
+ }, [f]), T;
87
87
  }
88
- const an = [
88
+ const cn = [
89
89
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
90
90
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
91
91
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
92
92
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
93
- ], cn = [
93
+ ], ln = [
94
94
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb",
95
95
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb",
96
96
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"
97
- ], ln = [
97
+ ], un = [
98
98
  {
99
99
  id: "m_expr_01",
100
100
  name: "Friendly Wave",
@@ -260,17 +260,17 @@ const an = [
260
260
  name: "Take It Easy",
261
261
  url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
262
262
  }
263
- ], un = [
263
+ ], dn = [
264
264
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
265
265
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"
266
- ], dn = {
266
+ ], fn = {
267
267
  zoom: 0.85,
268
268
  position: [0.15, -0.8, 0],
269
269
  scale: 1.5,
270
270
  rotation: [0.15, 0.02, 0]
271
- }, fn = [-0.45, 1.9, 0.1], hn = {
271
+ }, hn = [-0.45, 1.9, 0.1], mn = {
272
272
  browInnerUp: 0.2
273
- }, ut = 0.18, mn = 1, It = "__branding__", Xe = {
273
+ }, dt = 0.18, pn = 1, Mt = "__branding__", Qe = {
274
274
  neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
275
275
  happy: {
276
276
  mouthSmileLeft: 0.2,
@@ -352,7 +352,7 @@ const an = [
352
352
  mouthUpperUpLeft: 0.1,
353
353
  mouthUpperUpRight: 0.1
354
354
  }
355
- }, pn = [
355
+ }, gn = [
356
356
  { key: "viseme_aa", mix: { jawOpen: 0.6 } },
357
357
  {
358
358
  key: "viseme_E",
@@ -448,7 +448,7 @@ const an = [
448
448
  }
449
449
  },
450
450
  { key: "viseme_sil", mix: {} }
451
- ], gn = {
451
+ ], bn = {
452
452
  aei: [
453
453
  { v: "E", w: 0.8 },
454
454
  { v: "I", w: 0.2 }
@@ -477,333 +477,336 @@ const an = [
477
477
  ],
478
478
  sil: [{ v: "sil", w: 1 }]
479
479
  };
480
- function bn(f) {
480
+ function _n(f) {
481
481
  if (!f) return [{ v: "sil", w: 1 }];
482
- const A = f.toLowerCase();
483
- return gn[A] ?? [{ v: "sil", w: 1 }];
482
+ const T = f.toLowerCase();
483
+ return bn[T] ?? [{ v: "sil", w: 1 }];
484
484
  }
485
- function _n({ target: f }) {
486
- const { camera: A } = Xt();
487
- return P(() => {
488
- A.lookAt(...f);
489
- }, [A, f]), null;
485
+ function wn({ target: f }) {
486
+ const { camera: T } = Kt();
487
+ return $(() => {
488
+ T.lookAt(...f);
489
+ }, [T, f]), null;
490
490
  }
491
- function z(f, A, w) {
491
+ function Q(f, T, b) {
492
492
  if (!f || !f.morphTargetDictionary)
493
493
  return;
494
- const g = f, T = g.morphTargetDictionary, V = g.morphTargetInfluences;
495
- if (V)
496
- for (const E in T)
497
- E.toLowerCase() === A.toLowerCase() && (V[T[E]] = w);
494
+ const p = f, _ = p.morphTargetDictionary, O = p.morphTargetInfluences;
495
+ if (O)
496
+ for (const H in _)
497
+ H.toLowerCase() === T.toLowerCase() && (O[_[H]] = b);
498
498
  }
499
- function Mt(f, A = 0.97) {
499
+ function Ct(f, T = 0.97) {
500
500
  if (!f) return;
501
- const w = f;
502
- if (w.morphTargetInfluences)
503
- for (let g = 0; g < w.morphTargetInfluences.length; g++)
504
- w.morphTargetInfluences[g] *= A;
501
+ const b = f;
502
+ if (b.morphTargetInfluences)
503
+ for (let p = 0; p < b.morphTargetInfluences.length; p++)
504
+ b.morphTargetInfluences[p] *= T;
505
505
  }
506
- const wn = Kt(
506
+ const vn = Zt(
507
507
  ({
508
508
  avatarUrl: f,
509
- isPlayingRef: A,
510
- visemeQueueRef: w,
511
- audioContextRef: g,
512
- responseAudioStartTimeRef: T,
513
- adjustments: V,
514
- mood: E,
515
- expression: te,
516
- agentResponse: ae,
517
- isSpeaking: I,
518
- nextStartTimeRef: U,
519
- stopPlayback: _,
520
- setIsSpeaking: ce,
521
- expressionUrl: m,
522
- onExpressionFinished: Y,
523
- isNudgeResponse: $,
524
- avatarGender: pe
509
+ isPlayingRef: T,
510
+ visemeQueueRef: b,
511
+ audioContextRef: p,
512
+ responseAudioStartTimeRef: _,
513
+ adjustments: O,
514
+ mood: H,
515
+ expression: he,
516
+ agentResponse: X,
517
+ isSpeaking: D,
518
+ nextStartTimeRef: me,
519
+ stopPlayback: I,
520
+ setIsSpeaking: v,
521
+ expressionUrl: k,
522
+ onExpressionFinished: E,
523
+ isNudgeResponse: U,
524
+ avatarGender: be
525
525
  }) => {
526
- const { scene: k } = ct(f), xe = ct(pe === "female" ? cn : an), q = dt(
527
- () => xe.flatMap((d) => d.animations),
528
- [xe]
529
- ), ge = ct(un), M = dt(
530
- () => ge.flatMap((d) => d.animations),
531
- [ge]
532
- ), O = c(null), W = c(null), D = c(null), be = c([]), [L] = b(() => new Ve.AnimationMixer(k)), v = c({}), y = c(null), _e = c(0), Ie = c(!1), we = c(0), le = c(null);
533
- P(() => {
534
- if (!(!q || !k)) {
535
- if (q.forEach((d, u) => {
536
- const i = `idle_${u}`;
537
- if (!v.current[i]) {
538
- const r = L.clipAction(d, k);
539
- r.name = i, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[i] = r;
526
+ const { scene: y } = lt(f), Ne = lt(be === "female" ? ln : cn), G = ft(
527
+ () => Ne.flatMap((u) => u.animations),
528
+ [Ne]
529
+ ), ce = lt(dn), M = ft(
530
+ () => ce.flatMap((u) => u.animations),
531
+ [ce]
532
+ ), B = a(null), j = a(null), N = a(null), ne = a([]), [P] = g(() => new Ve.AnimationMixer(y)), S = a({}), x = a(null), ye = a(0), le = a(!1), $e = a(0), re = a(null);
533
+ $(() => {
534
+ if (!(!G || !y)) {
535
+ if (G.forEach((u, d) => {
536
+ const s = `idle_${d}`;
537
+ if (!S.current[s]) {
538
+ const r = P.clipAction(u, y);
539
+ r.name = s, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, S.current[s] = r;
540
540
  }
541
- }), M.forEach((d, u) => {
542
- const i = `talk_${u}`;
543
- if (!v.current[i]) {
544
- const r = L.clipAction(d, k);
545
- r.name = i, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[i] = r;
541
+ }), M.forEach((u, d) => {
542
+ const s = `talk_${d}`;
543
+ if (!S.current[s]) {
544
+ const r = P.clipAction(u, y);
545
+ r.name = s, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, S.current[s] = r;
546
546
  }
547
- }), q.length > 0) {
548
- const d = v.current.idle_0, u = y.current && L.existingAction(y.current.getClip());
549
- d && !u && (d.reset().fadeIn(0.5).play(), y.current = d);
547
+ }), G.length > 0) {
548
+ const u = S.current.idle_0, d = x.current && P.existingAction(x.current.getClip());
549
+ u && !d && (u.reset().fadeIn(0.5).play(), x.current = u);
550
550
  }
551
551
  return () => {
552
- L.stopAllAction(), v.current = {}, y.current = null;
552
+ P.stopAllAction(), S.current = {}, x.current = null;
553
553
  };
554
554
  }
555
- }, [q, M, k, L]);
556
- const ve = c("");
557
- P(() => {
558
- if (!m || !k || m === ve.current) return;
559
- ve.current = m, le.current = m, new tn().load(
560
- m,
561
- (u) => {
562
- if (u.animations && u.animations.length > 0) {
563
- const i = u.animations[0], r = L.clipAction(i, k);
564
- if (r.name = `EXPR_${m}`, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, v.current[`EXPR_${m}`] = r, I && le.current === m) {
565
- const h = y.current;
566
- r.reset().fadeIn(0.3).play(), h && h !== r && h.crossFadeTo(r, 0.3, !0), y.current = r, le.current = null;
555
+ }, [G, M, y, P]);
556
+ const Se = a("");
557
+ $(() => {
558
+ if (!k || !y || k === Se.current) return;
559
+ Se.current = k, re.current = k, new nn().load(
560
+ k,
561
+ (d) => {
562
+ if (d.animations && d.animations.length > 0) {
563
+ const s = d.animations[0], r = P.clipAction(s, y);
564
+ if (r.name = `EXPR_${k}`, r.setLoop(Ve.LoopOnce, 1), r.clampWhenFinished = !0, S.current[`EXPR_${k}`] = r, D && re.current === k) {
565
+ const m = x.current;
566
+ r.reset().fadeIn(0.3).play(), m && m !== r && m.crossFadeTo(r, 0.3, !0), x.current = r, re.current = null;
567
567
  }
568
568
  }
569
569
  },
570
570
  void 0,
571
- (u) => {
572
- console.error(`[ANIMATION] Failed to load ${m}`, u);
571
+ (d) => {
572
+ console.error(`[ANIMATION] Failed to load ${k}`, d);
573
573
  }
574
574
  );
575
- }, [m, k, L, I]), P(() => {
576
- const d = (u) => {
577
- const i = u.action, r = i.name || "";
575
+ }, [k, y, P, D]), $(() => {
576
+ const u = (d) => {
577
+ const s = d.action, r = s.name || "";
578
578
  if (r.startsWith("idle_")) {
579
- const G = (parseInt(r.split("_")[1]) + 1) % q.length, Q = v.current[`idle_${G}`];
580
- Q && (Q.reset().fadeIn(0.5).play(), i.crossFadeTo(Q, 0.5, !0), y.current = Q);
579
+ const z = (parseInt(r.split("_")[1]) + 1) % G.length, K = S.current[`idle_${z}`];
580
+ K && (K.reset().fadeIn(0.5).play(), s.crossFadeTo(K, 0.5, !0), x.current = K);
581
581
  } else if (r.startsWith("EXPR_")) {
582
- if (I) {
583
- const h = v.current.talk_0;
584
- h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), y.current = h);
582
+ if (D) {
583
+ const m = S.current.talk_0;
584
+ m && (m.reset().fadeIn(0.5).play(), s.crossFadeTo(m, 0.5, !0), x.current = m);
585
585
  } else {
586
- const h = v.current.idle_0;
587
- h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), y.current = h);
586
+ const m = S.current.idle_0;
587
+ m && (m.reset().fadeIn(0.5).play(), s.crossFadeTo(m, 0.5, !0), x.current = m);
588
588
  }
589
- Y && Y();
589
+ E && E();
590
590
  } else if (r.startsWith("talk_"))
591
- if (I && !$) {
592
- const G = (parseInt(r.split("_")[1]) + 1) % M.length, Q = v.current[`talk_${G}`];
593
- Q && (Q.reset().fadeIn(0.3).play(), i.crossFadeTo(Q, 0.3, !0), y.current = Q);
591
+ if (D && !U) {
592
+ const z = (parseInt(r.split("_")[1]) + 1) % M.length, K = S.current[`talk_${z}`];
593
+ K && (K.reset().fadeIn(0.3).play(), s.crossFadeTo(K, 0.3, !0), x.current = K);
594
594
  } else {
595
- const h = v.current.idle_0;
596
- h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), y.current = h);
595
+ const m = S.current.idle_0;
596
+ m && (m.reset().fadeIn(0.5).play(), s.crossFadeTo(m, 0.5, !0), x.current = m);
597
597
  }
598
598
  };
599
- return L.addEventListener("finished", d), () => L.removeEventListener("finished", d);
599
+ return P.addEventListener("finished", u), () => P.removeEventListener("finished", u);
600
600
  }, [
601
- L,
602
- q,
601
+ P,
602
+ G,
603
603
  M,
604
- I,
605
- $,
606
- Y
607
- ]), P(() => {
608
- if (I && k) {
609
- const d = y.current, u = d?.name || "";
610
- if (u.startsWith("idle_") || u.startsWith("talk_") || u === "") {
611
- const i = le.current;
612
- if (i) {
613
- const r = v.current[`EXPR_${i}`];
604
+ D,
605
+ U,
606
+ E
607
+ ]), $(() => {
608
+ if (D && y) {
609
+ const u = x.current, d = u?.name || "";
610
+ if (d.startsWith("idle_") || d.startsWith("talk_") || d === "") {
611
+ const s = re.current;
612
+ if (s) {
613
+ const r = S.current[`EXPR_${s}`];
614
614
  if (r) {
615
- r.reset().fadeIn(0.3).play(), d && d !== r && d.crossFadeTo(r, 0.3, !0), y.current = r, le.current = null;
615
+ r.reset().fadeIn(0.3).play(), u && u !== r && u.crossFadeTo(r, 0.3, !0), x.current = r, re.current = null;
616
616
  return;
617
617
  }
618
618
  }
619
- if (u.startsWith("idle_") || u === "") {
620
- const r = v.current.talk_0;
621
- r && (r.reset().fadeIn(0.5).play(), d && d.crossFadeTo(r, 0.5, !0), y.current = r);
619
+ if (d.startsWith("idle_") || d === "") {
620
+ const r = S.current.talk_0;
621
+ r && (r.reset().fadeIn(0.5).play(), u && u.crossFadeTo(r, 0.5, !0), x.current = r);
622
622
  }
623
623
  }
624
- } else if (!I && k) {
625
- const d = y.current, u = d?.name || "";
626
- if (u.startsWith("talk_") || u.startsWith("EXPR_")) {
627
- const i = v.current.idle_0;
628
- i && (i.reset().fadeIn(0.5).play(), d && d.crossFadeTo(i, 0.5, !0), y.current = i);
624
+ } else if (!D && y) {
625
+ const u = x.current, d = u?.name || "";
626
+ if (d.startsWith("talk_") || d.startsWith("EXPR_")) {
627
+ const s = S.current.idle_0;
628
+ s && (s.reset().fadeIn(0.5).play(), u && u.crossFadeTo(s, 0.5, !0), x.current = s);
629
629
  }
630
630
  }
631
- }, [I, k, m]), P(() => {
632
- if (!k) return;
633
- k.traverse((i) => {
634
- if (i.isMesh && i.morphTargetDictionary) {
635
- const r = i.name.toLowerCase();
636
- (r.includes("head") || r.includes("avatar")) && (W.current = i, B(`[ANIMATION] Found head mesh: ${i.name}`)), r.includes("teeth") && (D.current = i, B(`[ANIMATION] Found teeth mesh: ${i.name}`));
631
+ }, [D, y, k]), $(() => {
632
+ if (!y) return;
633
+ y.traverse((s) => {
634
+ if (s.isMesh && s.morphTargetDictionary) {
635
+ const r = s.name.toLowerCase();
636
+ (r.includes("head") || r.includes("avatar")) && (j.current = s, V(`[ANIMATION] Found head mesh: ${s.name}`)), r.includes("teeth") && (N.current = s, V(`[ANIMATION] Found teeth mesh: ${s.name}`));
637
637
  }
638
638
  });
639
- const d = W.current?.morphTargetDictionary;
640
- d && Object.keys(d).filter(
641
- (i) => i.toLowerCase().includes("brow")
639
+ const u = j.current?.morphTargetDictionary;
640
+ u && Object.keys(u).filter(
641
+ (s) => s.toLowerCase().includes("brow")
642
642
  );
643
- const u = [];
644
- k.traverse((i) => {
645
- if (i.isMesh) {
646
- const h = i.morphTargetDictionary;
647
- h && Object.keys(h).some((G) => G.toLowerCase().includes("brow")) && u.push(i);
643
+ const d = [];
644
+ y.traverse((s) => {
645
+ if (s.isMesh) {
646
+ const m = s.morphTargetDictionary;
647
+ m && Object.keys(m).some((z) => z.toLowerCase().includes("brow")) && d.push(s);
648
648
  }
649
- }), be.current = u, u.length > 0 && B("[ANIMATION] Meshes with brow morphs:", u.length);
650
- }, [k]);
651
- const Ne = (d, u = 1) => {
652
- const i = `viseme_${d}`.toLowerCase(), r = pn.find((h) => h.key.toLowerCase() === i);
649
+ }), ne.current = d, d.length > 0 && V("[ANIMATION] Meshes with brow morphs:", d.length);
650
+ }, [y]);
651
+ const xe = (u, d = 1) => {
652
+ const s = `viseme_${u}`.toLowerCase(), r = gn.find((m) => m.key.toLowerCase() === s);
653
653
  if (r)
654
- for (const h in r.mix) {
655
- const G = r.mix[h] * u;
656
- z(W.current, h, G), z(D.current, h, G);
654
+ for (const m in r.mix) {
655
+ const z = r.mix[m] * d;
656
+ Q(j.current, m, z), Q(N.current, m, z);
657
657
  }
658
- }, ke = (d) => {
659
- const u = Xe[d] ?? Xe.neutral;
660
- for (const i in u)
661
- z(W.current, i, u[i]), z(D.current, i, u[i]);
658
+ }, Fe = (u) => {
659
+ const d = Qe[u] ?? Qe.neutral;
660
+ for (const s in d)
661
+ Q(j.current, s, d[s]), Q(N.current, s, d[s]);
662
662
  };
663
- return Yt((d, u) => {
664
- const i = Math.pow(0.88, 60 * u);
665
- Mt(W.current, i), Mt(D.current, i), ke(E);
666
- const r = d.clock.elapsedTime;
667
- let h = 0;
668
- if (Math.floor(r) % 5 === 0 && Math.floor((r - u) % 5) !== 0) {
669
- let j = null;
670
- k.traverse((X) => {
671
- X.name.toLowerCase().includes("hips") && (j = X);
663
+ return Qt((u, d) => {
664
+ const s = Math.pow(0.88, 60 * d);
665
+ Ct(j.current, s), Ct(N.current, s), Fe(H);
666
+ const r = u.clock.elapsedTime;
667
+ let m = 0;
668
+ if (Math.floor(r) % 5 === 0 && Math.floor((r - d) % 5) !== 0) {
669
+ let J = null;
670
+ y.traverse((te) => {
671
+ te.name.toLowerCase().includes("hips") && (J = te);
672
672
  });
673
- const ye = j ? `Hips Y: ${j.position.y.toFixed(4)}` : "Hips not found";
674
- B(`[ANIMATION] Mixer Time: ${L.time.toFixed(2)}, ${ye}`);
673
+ const ie = J ? `Hips Y: ${J.position.y.toFixed(4)}` : "Hips not found";
674
+ V(`[ANIMATION] Mixer Time: ${P.time.toFixed(2)}, ${ie}`);
675
675
  }
676
- if (L.update(u), r > _e.current && !Ie.current && (Ie.current = !0, we.current = r), Ie.current) {
677
- const j = I ? 0.2 : 0.3, ye = (r - we.current) / j;
678
- if (ye >= 1) {
679
- Ie.current = !1;
680
- const X = I ? 1 : 2.5;
681
- _e.current = r + X;
676
+ if (P.update(d), r > ye.current && !le.current && (le.current = !0, $e.current = r), le.current) {
677
+ const J = D ? 0.2 : 0.3, ie = (r - $e.current) / J;
678
+ if (ie >= 1) {
679
+ le.current = !1;
680
+ const te = D ? 1 : 2.5;
681
+ ye.current = r + te;
682
682
  } else {
683
- const X = ye < 0.5 ? ye * 2 : (1 - ye) * 2;
684
- z(W.current, "eyeBlinkLeft", X), z(W.current, "eyeBlinkRight", X), z(D.current, "eyeBlinkLeft", X), z(D.current, "eyeBlinkRight", X), h = X * hn.browInnerUp;
683
+ const te = ie < 0.5 ? ie * 2 : (1 - ie) * 2;
684
+ Q(j.current, "eyeBlinkLeft", te), Q(j.current, "eyeBlinkRight", te), Q(N.current, "eyeBlinkLeft", te), Q(N.current, "eyeBlinkRight", te), m = te * mn.browInnerUp;
685
685
  }
686
686
  }
687
- const G = Xe[E] ?? Xe.neutral, Q = G.browInnerUp ?? 0, Ke = G.browOuterUpLeft ?? 0, $e = G.browOuterUpRight ?? 0, Ue = r * mn, Re = ut * Math.sin(Ue), Z = ut * 0.7 * Math.sin(Ue + 0.7), je = ut * 0.7 * Math.sin(Ue + 1.3), ne = (j) => Math.max(0, Math.min(1, j)), Ae = ne(Q + Re), Le = ne(Ke + Z), Be = ne($e + je), Me = ne(Ae + h);
688
- if (z(W.current, "browInnerUp", Me), z(D.current, "browInnerUp", Me), z(W.current, "browOuterUpLeft", Le), z(D.current, "browOuterUpLeft", Le), z(W.current, "browOuterUpRight", Be), z(D.current, "browOuterUpRight", Be), O.current) {
689
- const j = A.current ? 0 : V.rotation[1];
690
- O.current.rotation.y = Ve.MathUtils.lerp(
691
- O.current.rotation.y,
692
- j,
687
+ const z = Qe[H] ?? Qe.neutral, K = z.browInnerUp ?? 0, Xe = z.browOuterUpLeft ?? 0, Ke = z.browOuterUpRight ?? 0, Me = r * pn, Ze = dt * Math.sin(Me), ke = dt * 0.7 * Math.sin(Me + 0.7), ee = dt * 0.7 * Math.sin(Me + 1.3), Ae = (J) => Math.max(0, Math.min(1, J)), _e = Ae(K + Ze), we = Ae(Xe + ke), Re = Ae(Ke + ee), Ue = Ae(_e + m);
688
+ if (Q(j.current, "browInnerUp", Ue), Q(N.current, "browInnerUp", Ue), Q(j.current, "browOuterUpLeft", we), Q(N.current, "browOuterUpLeft", we), Q(j.current, "browOuterUpRight", Re), Q(N.current, "browOuterUpRight", Re), B.current) {
689
+ const J = T.current ? 0 : O.rotation[1];
690
+ B.current.rotation.y = Ve.MathUtils.lerp(
691
+ B.current.rotation.y,
692
+ J,
693
693
  0.1
694
- ), O.current.position.set(...V.position), O.current.scale.setScalar(V.scale), O.current.rotation.x = V.rotation[0], O.current.rotation.z = V.rotation[2];
694
+ ), B.current.position.set(...O.position), B.current.scale.setScalar(O.scale), B.current.rotation.x = O.rotation[0], B.current.rotation.z = O.rotation[2];
695
695
  }
696
- if (A.current && g.current) {
697
- const j = g.current.currentTime, De = (j - T.current) * 1e3 - -150;
698
- for (let ee = 0; ee < w.current.length; ee++) {
699
- const re = w.current[ee];
700
- De >= re.vtime && De < re.vtime + re.vduration && Ne(re.viseme, re.weight ?? 1);
696
+ if (T.current && p.current) {
697
+ const J = p.current.currentTime, He = (J - _.current) * 1e3 - -150;
698
+ for (let Le = 0; Le < b.current.length; Le++) {
699
+ const Y = b.current[Le];
700
+ He >= Y.vtime && He < Y.vtime + Y.vduration && xe(Y.viseme, Y.weight ?? 1);
701
701
  }
702
- j > U.current + 0.5 && (_(), ce(!1));
702
+ J > me.current + 0.5 && (I(), v(!1));
703
703
  }
704
- }), /* @__PURE__ */ l("group", { ref: O, children: /* @__PURE__ */ l("primitive", { object: k }) });
704
+ }), /* @__PURE__ */ l("group", { ref: B, children: /* @__PURE__ */ l("primitive", { object: y }) });
705
705
  }
706
706
  );
707
- function vn(f) {
707
+ function yn(f) {
708
708
  return f ? f.charAt(0).toUpperCase() + f.slice(1).toLowerCase() : "";
709
709
  }
710
- const yn = ({
710
+ const Sn = ({
711
711
  token: f,
712
- agentToken: A,
713
- onNavigationRequested: w,
714
- avatarGender: g
712
+ agentToken: T,
713
+ onNavigationRequested: b,
714
+ avatarGender: p,
715
+ presetUserDetails: _
715
716
  } = {}) => {
716
- const T = f ?? A ?? "", V = on(T || void 0), [E, te] = b(""), [ae, I] = b(""), [U, _] = b("Ready"), [ce, m] = b(!1), [Y, $] = b(!1), [pe, k] = b([]), [He, xe] = b(""), q = c(null), [ge, M] = b(
717
+ const O = f ?? T ?? "", H = an(O || void 0), [he, X] = g(""), [D, me] = g(""), [I, v] = g("Ready"), [k, E] = g(!1), [U, be] = g(!1), [y, Ie] = g([]), [Ne, G] = g(""), ce = a(null), [M, B] = g(
717
718
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
718
719
  );
719
- P(() => {
720
- const e = window.matchMedia("(max-width: 480px)"), t = () => M(e.matches);
720
+ $(() => {
721
+ const e = window.matchMedia("(max-width: 480px)"), t = () => B(e.matches);
721
722
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
722
723
  }, []);
723
- const O = ge ? 80 : 600, W = c(!1), D = c([]), be = c(0), L = c(!1), v = c([]), y = c(null), _e = c([]);
724
- c([]);
725
- const Ie = c([]), we = c(0), le = c(0), ve = c(0), Ne = c(0), ke = c(!1), [d, u] = b(
724
+ const j = M ? 80 : 600, N = a(!1), ne = a([]), P = a(0), S = a(!1), x = a([]), ye = a(null), le = a([]);
725
+ a([]);
726
+ const $e = a([]), re = a(0), Se = a(0), xe = a(0), Fe = a(0), u = a(!1), [d, s] = g(
726
727
  null
727
- ), i = c(null), [r, h] = b("neutral"), [G, Q] = b(""), [Ke, $e] = b(""), [Ue, Re] = b("Chat with us"), [Z, je] = b(
728
+ ), r = a(null), [m, z] = g("neutral"), [K, Xe] = g(""), [Ke, Me] = g(""), [Ze, ke] = g("Chat with us"), [ee, Ae] = g(
728
729
  null
729
- ), [ne, Ae] = b("hidden"), [Le, Be] = b(""), Me = c(null), j = c(ne);
730
- j.current = ne;
731
- const [ye, X] = b(null), De = c(null), ee = c(null), [re, ft] = b(!1), ht = c(null), [ue, Je] = b("hidden"), [mt, Dt] = b(""), Ze = c(ue);
732
- Ze.current = ue;
733
- const he = c(""), Ce = c(!1), Oe = c(""), pt = c(Date.now()), et = c([]), Pe = c(!1), [tt, We] = b(!1), [gt, bt] = b(!1), Se = c(null), Fe = dt(() => re ? "Try again" : U === "Busy" ? "Busy" : U === "Thinking..." || U === "Processing Voice..." ? U : Z != null && Z !== "" && Z !== "none" && Z !== "<none>" ? `Enter ${vn(Z)}` : ue !== "hidden" || !gt ? null : It, [U, Z, re, ue, gt]), _t = !re && U !== "Busy" && U !== "Thinking..." && U !== "Processing Voice..." && (Z == null || Z === "" || Z === "none" || Z === "<none>");
734
- P(() => {
735
- if (ue !== "hidden" || !_t) {
736
- bt(!1), Se.current != null && (clearTimeout(Se.current), Se.current = null);
730
+ ), [_e, we] = g("hidden"), [Re, Ue] = g(""), J = a(null), ie = a(_e);
731
+ ie.current = _e;
732
+ const [te, He] = g(null), Le = a(null), Y = a(null), [Be, ht] = g(!1), mt = a(null), [ue, je] = g("hidden"), [pt, Ot] = g(""), et = a(ue);
733
+ et.current = ue;
734
+ const pe = a(""), Ce = a(!1), Oe = a(""), gt = a(Date.now()), tt = a([]), Pe = a(!1), [nt, We] = g(!1), [bt, _t] = g(!1), ve = a(null), De = ft(() => Be ? "Try again" : I === "Busy" ? "Busy" : I === "Thinking..." || I === "Processing Voice..." ? I : ee != null && ee !== "" && ee !== "none" && ee !== "<none>" ? `Enter ${yn(ee)}` : ue !== "hidden" || !bt ? null : Mt, [I, ee, Be, ue, bt]), wt = !Be && I !== "Busy" && I !== "Thinking..." && I !== "Processing Voice..." && (ee == null || ee === "" || ee === "none" || ee === "<none>");
735
+ $(() => {
736
+ if (ue !== "hidden" || !wt) {
737
+ _t(!1), ve.current != null && (clearTimeout(ve.current), ve.current = null);
737
738
  return;
738
739
  }
739
- return Se.current = setTimeout(() => {
740
- Se.current = null, bt(!0);
740
+ return ve.current = setTimeout(() => {
741
+ ve.current = null, _t(!0);
741
742
  }, 400), () => {
742
- Se.current != null && (clearTimeout(Se.current), Se.current = null);
743
+ ve.current != null && (clearTimeout(ve.current), ve.current = null);
743
744
  };
744
- }, [ue, _t]);
745
- const qe = Fe != null && Fe !== "";
746
- P(() => {
747
- const e = j.current;
745
+ }, [ue, wt]);
746
+ const Je = De != null && De !== "";
747
+ $(() => {
748
+ const e = ie.current;
748
749
  if (!(e === "exiting" || e === "entering")) {
749
750
  if (e === "hidden") {
750
- qe && (Be(Fe ?? ""), Ae("entering"));
751
+ Je && (Ue(De ?? ""), we("entering"));
751
752
  return;
752
753
  }
753
- e === "visible" && (!qe || Fe !== Le) && (Me.current = qe ? Fe : null, Ae("exiting"));
754
+ e === "visible" && (!Je || De !== Re) && (J.current = Je ? De : null, we("exiting"));
754
755
  }
755
756
  }, [
756
- qe,
757
- Fe,
758
- ne,
759
- Le
760
- ]), P(() => {
761
- if (U !== "Busy") {
762
- ee.current != null && (clearTimeout(ee.current), ee.current = null);
757
+ Je,
758
+ De,
759
+ _e,
760
+ Re
761
+ ]), $(() => {
762
+ if (I !== "Busy") {
763
+ Y.current != null && (clearTimeout(Y.current), Y.current = null);
763
764
  return;
764
765
  }
765
- return ee.current = setTimeout(() => {
766
- ee.current = null, _("Ready"), ft(!0);
766
+ return Y.current = setTimeout(() => {
767
+ Y.current = null, v("Ready"), ht(!0);
767
768
  }, 12e3), () => {
768
- ee.current != null && (clearTimeout(ee.current), ee.current = null);
769
+ Y.current != null && (clearTimeout(Y.current), Y.current = null);
769
770
  };
770
- }, [U]), P(() => {
771
- if (!re) return;
772
- const e = setTimeout(() => ft(!1), 2500);
771
+ }, [I]), $(() => {
772
+ if (!Be) return;
773
+ const e = setTimeout(() => ht(!1), 2500);
773
774
  return () => clearTimeout(e);
774
- }, [re]);
775
- const Ct = Qe(() => {
776
- const e = j.current;
775
+ }, [Be]);
776
+ const Dt = Ye(() => {
777
+ const e = ie.current;
777
778
  if (e === "exiting") {
778
- Ae("hidden");
779
- const t = Me.current;
780
- Me.current = null, t != null && t !== "" && (Be(t), Ae("entering"));
781
- } else e === "entering" && Ae("visible");
782
- }, []), Ot = (e) => {
779
+ we("hidden");
780
+ const t = J.current;
781
+ J.current = null, t != null && t !== "" && (Ue(t), we("entering"));
782
+ } else e === "entering" && we("visible");
783
+ }, []), Nt = (e) => {
783
784
  if (!e) return;
784
785
  if (e.mood != null) {
785
786
  const n = String(e.mood).toLowerCase();
786
- h(n);
787
+ z(n);
787
788
  }
788
789
  if (e.expression != null) {
789
790
  const n = String(e.expression).trim();
790
- Q(n);
791
- const a = ln.find(
792
- (p) => p.name.toLowerCase() === n.toLowerCase()
791
+ Xe(n);
792
+ const c = un.find(
793
+ (h) => h.name.toLowerCase() === n.toLowerCase()
793
794
  );
794
- B(
795
- `[STREAM] Animation match for "${n}": ${a ? a.name : "NONE"}`
796
- ), $e(a?.url ?? "");
795
+ V(
796
+ `[STREAM] Animation match for "${n}": ${c ? c.name : "NONE"}`
797
+ ), Me(c?.url ?? "");
797
798
  }
798
799
  if (e.navigation != null) {
799
800
  const n = String(e.navigation).trim();
800
- n !== "" && (w ? w(n) : window.open(n, "_blank"));
801
+ n !== "" && (b ? b(n) : window.open(n, "_blank"));
801
802
  }
802
- const t = e.ask_for || e.lead_capture?.ask_for, s = t ? String(t).trim().toLowerCase() : "", o = s === "none" || s === "<none>";
803
+ const t = e.ask_for || e.lead_capture?.ask_for, i = t ? String(t).trim().toLowerCase() : "", o = i === "none" || i === "<none>";
803
804
  if (t && !o) {
804
- const n = s;
805
- je(n || null), Re(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
806
- } else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (je(null), Ue !== "Chat with us" && Re("Chat with us"));
805
+ const n = i;
806
+ if (_ && (n === "email" && _.email || n === "name" && _.name || n === "phone" && _.phone))
807
+ return;
808
+ Ae(n || null), ke(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
809
+ } else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Ae(null), Ze !== "Chat with us" && ke("Chat with us"));
807
810
  e.collected, e.valid;
808
811
  }, Ft = (e) => {
809
812
  const t = e.trim();
@@ -815,81 +818,92 @@ const yn = ({
815
818
  return null;
816
819
  }
817
820
  if (t.includes(":")) {
818
- const s = t.split(":"), o = s[0].trim().toLowerCase(), n = s.slice(1).join(":").trim();
821
+ const i = t.split(":"), o = i[0].trim().toLowerCase(), n = i.slice(1).join(":").trim();
819
822
  return { [o]: n };
820
823
  }
821
824
  return null;
822
- }, Nt = Qe(() => {
823
- }, []), wt = (e) => {
825
+ }, Ut = Ye(() => {
826
+ }, []), vt = (e) => {
824
827
  if (Ce.current)
825
- e === "§" ? Ce.current = !1 : (Oe.current += e, I((t) => t + e));
828
+ e === "§" ? Ce.current = !1 : (Oe.current += e, me((t) => t + e));
826
829
  else if (e === "§") {
827
830
  Ce.current = !0;
828
831
  return;
829
832
  } else
830
- for (he.current += e; he.current.includes(`
833
+ for (pe.current += e; pe.current.includes(`
831
834
  `); ) {
832
- const t = he.current.indexOf(`
833
- `), s = he.current.slice(0, t).trim();
834
- he.current = he.current.slice(t + 1);
835
- const o = Ft(s);
836
- o && Ot(o);
835
+ const t = pe.current.indexOf(`
836
+ `), i = pe.current.slice(0, t).trim();
837
+ pe.current = pe.current.slice(t + 1);
838
+ const o = Ft(i);
839
+ o && Nt(o);
837
840
  }
838
841
  };
839
- P(() => {
842
+ $(() => {
840
843
  (async () => {
841
844
  if (!sessionStorage.getItem(
842
845
  "STREAMOJI_LEADS_SESSION_LEAD_ID"
843
846
  )) {
844
- const s = "secret", o = Math.floor(Date.now() / 1e3).toString();
847
+ const n = "secret", c = Math.floor(Date.now() / 1e3).toString();
845
848
  try {
846
- const n = new TextEncoder(), a = await crypto.subtle.importKey(
849
+ const h = new TextEncoder(), w = await crypto.subtle.importKey(
847
850
  "raw",
848
- n.encode(s),
851
+ h.encode(n),
849
852
  { name: "HMAC", hash: "SHA-256" },
850
853
  !1,
851
854
  ["sign"]
852
- ), p = await crypto.subtle.sign(
855
+ ), A = await crypto.subtle.sign(
853
856
  "HMAC",
854
- a,
855
- n.encode(o)
856
- ), S = Array.from(new Uint8Array(p)).map((x) => x.toString(16).padStart(2, "0")).join("");
857
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", S), B("[SESSION] New HMAC UID generated and saved:", S);
858
- } catch (n) {
859
- console.error("[SESSION] HMAC generation failed:", n);
860
- const a = Math.random().toString(36) + Date.now().toString();
861
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", a);
857
+ w,
858
+ h.encode(c)
859
+ ), L = Array.from(new Uint8Array(A)).map((W) => W.toString(16).padStart(2, "0")).join("");
860
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", L), V("[SESSION] New HMAC UID generated and saved:", L);
861
+ } catch (h) {
862
+ console.error("[SESSION] HMAC generation failed:", h);
863
+ const w = Math.random().toString(36) + Date.now().toString();
864
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
862
865
  }
863
866
  }
864
- sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || sessionStorage.setItem(
867
+ const i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
868
+ let o = [];
869
+ if (i)
870
+ try {
871
+ o = JSON.parse(i);
872
+ } catch {
873
+ o = [];
874
+ }
875
+ o.length === 0 && _ && (_.name || _.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${_.name || ""}" , Email is "${_.email || ""}"` }], sessionStorage.setItem(
876
+ "STREAMOJI_LEADS_SESSION_MESSAGES",
877
+ JSON.stringify(o)
878
+ )) : i || sessionStorage.setItem(
865
879
  "STREAMOJI_LEADS_SESSION_MESSAGES",
866
880
  JSON.stringify([])
867
881
  );
868
882
  })();
869
- }, []), P(() => {
883
+ }, [_]), $(() => {
870
884
  const e = () => {
871
- pt.current = Date.now(), Pe.current && (Pe.current = !1, We(!1), k([]), xe(""), I(""), $(!1));
885
+ gt.current = Date.now(), Pe.current && (Pe.current = !1, We(!1), Ie([]), G(""), me(""), be(!1));
872
886
  };
873
887
  window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
874
888
  const t = setInterval(async () => {
875
- if (Date.now() - pt.current >= 3e4 && !Y && !ce && U === "Ready" && !Pe.current)
876
- if (Pe.current = !0, et.current.length > 0)
877
- We(!0), k(et.current);
889
+ if (Date.now() - gt.current >= 3e4 && !U && !k && I === "Ready" && !Pe.current)
890
+ if (Pe.current = !0, tt.current.length > 0)
891
+ We(!0), Ie(tt.current);
878
892
  else
879
893
  try {
880
- const n = `${lt}/nudgeUser`, a = {
894
+ const n = `${ut}/nudgeUser`, c = {
881
895
  navigationUrl: window.location.href,
882
- token: T
883
- }, p = await fetch(n, {
896
+ token: O
897
+ }, h = await fetch(n, {
884
898
  method: "POST",
885
899
  headers: {
886
900
  "Content-Type": "application/json"
887
901
  },
888
- body: JSON.stringify(a)
902
+ body: JSON.stringify(c)
889
903
  });
890
- if (p.ok) {
891
- const S = (await p.json()).nudge_questions;
892
- S && S.length > 0 && (B("[NUDGE] Received nudge questions from API:", S), et.current = S, We(!0), k(S));
904
+ if (h.ok) {
905
+ const A = (await h.json()).nudge_questions;
906
+ A && A.length > 0 && (V("[NUDGE] Received nudge questions from API:", A), tt.current = A, We(!0), Ie(A));
893
907
  }
894
908
  } catch (n) {
895
909
  console.error("[NUDGE] Error calling /nudgeUser:", n), Pe.current = !1;
@@ -898,25 +912,25 @@ const yn = ({
898
912
  return () => {
899
913
  window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(t);
900
914
  };
901
- }, [T, Y, ce, U]), P(() => {
902
- if (pe.length === 0) return;
903
- let e = 0, t = 0, s = !1, o = 100;
915
+ }, [O, U, k, I]), $(() => {
916
+ if (y.length === 0) return;
917
+ let e = 0, t = 0, i = !1, o = 100;
904
918
  const n = () => {
905
- const a = pe[e];
906
- if (s) {
907
- const p = a.substring(0, t - 1);
908
- xe(p), t--, o = 50;
919
+ const c = y[e];
920
+ if (i) {
921
+ const h = c.substring(0, t - 1);
922
+ G(h), t--, o = 50;
909
923
  } else {
910
- const p = a.substring(0, t + 1);
911
- xe(p), t++, o = 100;
924
+ const h = c.substring(0, t + 1);
925
+ G(h), t++, o = 100;
912
926
  }
913
- !s && t === a.length ? (s = !0, o = 3e3) : s && t === 0 && (s = !1, e = (e + 1) % pe.length, o = 500), q.current = setTimeout(n, o);
927
+ !i && t === c.length ? (i = !0, o = 3e3) : i && t === 0 && (i = !1, e = (e + 1) % y.length, o = 500), ce.current = setTimeout(n, o);
914
928
  };
915
929
  return n(), () => {
916
- q.current && clearTimeout(q.current);
930
+ ce.current && clearTimeout(ce.current);
917
931
  };
918
- }, [pe]);
919
- const vt = () => {
932
+ }, [y]);
933
+ const yt = () => {
920
934
  try {
921
935
  return JSON.parse(
922
936
  sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
@@ -924,194 +938,194 @@ const yn = ({
924
938
  } catch {
925
939
  return [];
926
940
  }
927
- }, Ut = (e) => {
941
+ }, Bt = (e) => {
928
942
  sessionStorage.setItem(
929
943
  "STREAMOJI_LEADS_SESSION_MESSAGES",
930
944
  JSON.stringify(e)
931
945
  );
932
- }, [nt, rt] = b(!1), [yt, st] = b(0), de = c(null), Ge = c([]), St = c(0), [xt, Bt] = b(
946
+ }, [rt, it] = g(!1), [St, st] = g(0), de = a(null), qe = a([]), xt = a(0), [kt, Pt] = g(
933
947
  null
934
- ), [Pt, it] = b(
948
+ ), [Wt, ot] = g(
935
949
  null
936
- ), me = c(null), Te = c(
950
+ ), ge = a(null), Te = a(
937
951
  null
938
- ), ze = Qe((e = !1) => {
939
- e && (ke.current = !0, m(!1), _("Ready")), v.current = [], D.current = [], L.current = !1, $(!1), we.current = 0, le.current = 0, ve.current = 0, _e.current.forEach((t) => {
952
+ ), Ge = Ye((e = !1) => {
953
+ e && (u.current = !0, E(!1), v("Ready")), x.current = [], ne.current = [], S.current = !1, be(!1), re.current = 0, Se.current = 0, xe.current = 0, le.current.forEach((t) => {
940
954
  try {
941
955
  t.stop();
942
956
  } catch {
943
957
  }
944
- }), De.current && (clearTimeout(De.current), De.current = null), X(null), $e(""), _e.current = [];
945
- }, []), Wt = async () => {
958
+ }), Le.current && (clearTimeout(Le.current), Le.current = null), He(null), Me(""), le.current = [];
959
+ }, []), Vt = async () => {
946
960
  try {
947
- const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, s = new t(), o = s.createMediaStreamSource(e), n = s.createAnalyser();
948
- n.fftSize = 64, o.connect(n), me.current = s, Te.current = o, it(n);
949
- const a = new MediaRecorder(e);
950
- de.current = a, Ge.current = [], a.ondataavailable = (p) => {
951
- p.data.size > 0 && Ge.current.push(p.data);
952
- }, a.onstop = async () => {
953
- const p = Date.now() - St.current;
954
- if (it(null), Te.current && (Te.current.disconnect(), Te.current = null), me.current && me.current.state !== "closed" && (me.current.close(), me.current = null), p < 1e3) {
955
- _("Recording too short. Hold or click longer."), m(!1);
961
+ const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, i = new t(), o = i.createMediaStreamSource(e), n = i.createAnalyser();
962
+ n.fftSize = 64, o.connect(n), ge.current = i, Te.current = o, ot(n);
963
+ const c = new MediaRecorder(e);
964
+ de.current = c, qe.current = [], c.ondataavailable = (h) => {
965
+ h.data.size > 0 && qe.current.push(h.data);
966
+ }, c.onstop = async () => {
967
+ const h = Date.now() - xt.current;
968
+ if (ot(null), Te.current && (Te.current.disconnect(), Te.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), h < 1e3) {
969
+ v("Recording too short. Hold or click longer."), E(!1);
956
970
  return;
957
971
  }
958
- const R = new Blob(Ge.current, {
972
+ const w = new Blob(qe.current, {
959
973
  type: "audio/wav"
960
974
  });
961
- await jt(R);
962
- }, St.current = Date.now(), a.start(100), rt(!0), _("Listening...");
975
+ await Jt(w);
976
+ }, xt.current = Date.now(), c.start(100), it(!0), v("Listening...");
963
977
  } catch (e) {
964
- console.error("Error accessing microphone:", e), _("Mic Access Error");
978
+ console.error("Error accessing microphone:", e), v("Mic Access Error");
965
979
  }
966
- }, Vt = () => {
967
- de.current && de.current.state !== "inactive" && (de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), rt(!1));
980
+ }, $t = () => {
981
+ de.current && de.current.state !== "inactive" && (de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), it(!1));
968
982
  }, Ht = () => {
969
- de.current && de.current.state !== "inactive" && (de.current.onstop = null, de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), it(null), Te.current && (Te.current.disconnect(), Te.current = null), me.current && me.current.state !== "closed" && (me.current.close(), me.current = null), rt(!1), Ge.current = [], _("Ready"));
983
+ de.current && de.current.state !== "inactive" && (de.current.onstop = null, de.current.stop(), de.current.stream.getTracks().forEach((e) => e.stop()), ot(null), Te.current && (Te.current.disconnect(), Te.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), it(!1), qe.current = [], v("Ready"));
970
984
  };
971
- P(() => {
972
- if (!Y) return;
985
+ $(() => {
986
+ if (!U) return;
973
987
  const e = () => {
974
- const t = ve.current;
988
+ const t = xe.current;
975
989
  if (t <= 0) return;
976
- const s = y.current, o = we.current;
977
- if (!s) return;
978
- const n = s.currentTime - o, a = Math.min(Math.max(0, n), t), p = ae.trim().length;
979
- if (p <= 0) return;
980
- const R = Math.min(
981
- Math.round(a / t * p),
982
- p
990
+ const i = ye.current, o = re.current;
991
+ if (!i) return;
992
+ const n = i.currentTime - o, c = Math.min(Math.max(0, n), t), h = D.trim().length;
993
+ if (h <= 0) return;
994
+ const w = Math.min(
995
+ Math.round(c / t * h),
996
+ h
983
997
  );
984
- u(R);
998
+ s(w);
985
999
  };
986
- return clearInterval(i.current ?? void 0), i.current = setInterval(e, 90), () => clearInterval(i.current ?? void 0);
987
- }, [Y, ae, ve.current]), P(() => {
1000
+ return clearInterval(r.current ?? void 0), r.current = setInterval(e, 90), () => clearInterval(r.current ?? void 0);
1001
+ }, [U, D, xe.current]), $(() => {
988
1002
  let e;
989
- return nt ? (st(0), e = window.setInterval(() => {
1003
+ return rt ? (st(0), e = window.setInterval(() => {
990
1004
  st((t) => t + 1);
991
1005
  }, 1e3)) : st(0), () => clearInterval(e);
992
- }, [nt]);
993
- const $t = (e) => {
994
- const t = e.numberOfChannels, s = e.length * t * 2 + 44, o = new ArrayBuffer(s), n = new DataView(o);
995
- let a = 0;
996
- const p = (F) => {
997
- n.setUint16(a, F, !0), a += 2;
998
- }, R = (F) => {
999
- n.setUint32(a, F, !0), a += 4;
1006
+ }, [rt]);
1007
+ const jt = (e) => {
1008
+ const t = e.numberOfChannels, i = e.length * t * 2 + 44, o = new ArrayBuffer(i), n = new DataView(o);
1009
+ let c = 0;
1010
+ const h = (L) => {
1011
+ n.setUint16(c, L, !0), c += 2;
1012
+ }, w = (L) => {
1013
+ n.setUint32(c, L, !0), c += 4;
1000
1014
  };
1001
- R(1179011410), R(s - 8), R(1163280727), R(544501094), R(16), p(1), p(t), R(e.sampleRate), R(e.sampleRate * 2 * t), p(t * 2), p(16), R(1635017060), R(s - a - 4);
1002
- const S = [];
1003
- for (let F = 0; F < t; F++) S.push(e.getChannelData(F));
1004
- let x = 0;
1005
- for (; a < s; ) {
1006
- for (let F = 0; F < t; F++) {
1007
- let H = Math.max(-1, Math.min(1, S[F][x]));
1008
- H = H < 0 ? H * 32768 : H * 32767, n.setInt16(a, H, !0), a += 2;
1015
+ w(1179011410), w(i - 8), w(1163280727), w(544501094), w(16), h(1), h(t), w(e.sampleRate), w(e.sampleRate * 2 * t), h(t * 2), h(16), w(1635017060), w(i - c - 4);
1016
+ const A = [];
1017
+ for (let L = 0; L < t; L++) A.push(e.getChannelData(L));
1018
+ let R = 0;
1019
+ for (; c < i; ) {
1020
+ for (let L = 0; L < t; L++) {
1021
+ let W = Math.max(-1, Math.min(1, A[L][R]));
1022
+ W = W < 0 ? W * 32768 : W * 32767, n.setInt16(c, W, !0), c += 2;
1009
1023
  }
1010
- x++;
1024
+ R++;
1011
1025
  }
1012
1026
  return new Blob([o], { type: "audio/wav" });
1013
- }, ot = async (e, t, s = !1) => {
1014
- if (!ke.current) {
1015
- if (W.current) {
1016
- D.current.push({
1027
+ }, at = async (e, t, i = !1) => {
1028
+ if (!u.current) {
1029
+ if (N.current) {
1030
+ ne.current.push({
1017
1031
  audio: e,
1018
1032
  visemes: t,
1019
- isNewSegment: s
1033
+ isNewSegment: i
1020
1034
  });
1021
1035
  return;
1022
1036
  }
1023
- W.current = !0;
1037
+ N.current = !0;
1024
1038
  try {
1025
- const o = window.AudioContext || window.webkitAudioContext, n = y.current ?? new o();
1026
- n.state === "suspended" && await n.resume(), y.current = n;
1027
- const a = window.atob(e), p = new Uint8Array(a.length);
1028
- for (let N = 0; N < a.length; N++)
1029
- p[N] = a.charCodeAt(N);
1030
- const R = await n.decodeAudioData(p.buffer.slice(0));
1031
- ve.current += R.duration;
1032
- const S = n.currentTime;
1033
- let x = le.current;
1034
- const F = !L.current;
1035
- x < S && (x = S + 0.1), le.current = x + R.duration;
1036
- const H = n.createBufferSource();
1037
- H.buffer = R;
1038
- let J = xt;
1039
- if ((!J || J.context !== n) && (J = n.createAnalyser(), J.fftSize = 64, J.connect(n.destination), Bt(J)), H.connect(J), _e.current.push(H), ke.current) {
1040
- _e.current = _e.current.filter((N) => N !== H);
1039
+ const o = window.AudioContext || window.webkitAudioContext, n = ye.current ?? new o();
1040
+ n.state === "suspended" && await n.resume(), ye.current = n;
1041
+ const c = window.atob(e), h = new Uint8Array(c.length);
1042
+ for (let F = 0; F < c.length; F++)
1043
+ h[F] = c.charCodeAt(F);
1044
+ const w = await n.decodeAudioData(h.buffer.slice(0));
1045
+ xe.current += w.duration;
1046
+ const A = n.currentTime;
1047
+ let R = Se.current;
1048
+ const L = !S.current;
1049
+ R < A && (R = A + 0.1), Se.current = R + w.duration;
1050
+ const W = n.createBufferSource();
1051
+ W.buffer = w;
1052
+ let q = kt;
1053
+ if ((!q || q.context !== n) && (q = n.createAnalyser(), q.fftSize = 64, q.connect(n.destination), Pt(q)), W.connect(q), le.current.push(W), u.current) {
1054
+ le.current = le.current.filter((F) => F !== W);
1041
1055
  return;
1042
1056
  }
1043
- if (F) {
1044
- L.current = !0, $(!0), B(
1045
- `[AUDIO] setIsSpeaking(true) - First chunk starting at ${x.toFixed(
1057
+ if (L) {
1058
+ S.current = !0, be(!0), V(
1059
+ `[AUDIO] setIsSpeaking(true) - First chunk starting at ${R.toFixed(
1046
1060
  3
1047
1061
  )}`
1048
- ), we.current = x;
1049
- const N = (x - S) * 1e3;
1050
- be.current = performance.now() + N, B(
1051
- `[AUDIO] Response started. Initial startTime: ${x.toFixed(
1062
+ ), re.current = R;
1063
+ const F = (R - A) * 1e3;
1064
+ P.current = performance.now() + F, V(
1065
+ `[AUDIO] Response started. Initial startTime: ${R.toFixed(
1052
1066
  3
1053
- )}, CT: ${S.toFixed(3)}`
1067
+ )}, CT: ${A.toFixed(3)}`
1054
1068
  );
1055
1069
  }
1056
- H.start(x);
1057
- const K = (x - we.current) * 1e3;
1058
- s && (Ne.current = K, B(
1059
- `[AUDIO] New segment detected at +${K.toFixed(
1070
+ W.start(R);
1071
+ const Z = (R - re.current) * 1e3;
1072
+ i && (Fe.current = Z, V(
1073
+ `[AUDIO] New segment detected at +${Z.toFixed(
1060
1074
  0
1061
1075
  )}ms. Resetting segment offset.`
1062
- )), t.forEach((N, se) => {
1063
- const C = N.symbol ?? "";
1076
+ )), t.forEach((F, se) => {
1077
+ const C = F.symbol ?? "";
1064
1078
  if (C) {
1065
- const ie = bn(C), fe = Math.round(N.start * 1e3), Ee = Math.round((N.duration ?? 0) * 1e3), At = Ne.current + fe;
1066
- se < 3 && B(
1067
- `[AUDIO] Viseme "${C}": segment_relative=${fe}ms, segment_offset=${Ne.current.toFixed(
1079
+ const oe = _n(C), fe = Math.round(F.start * 1e3), Ee = Math.round((F.duration ?? 0) * 1e3), Lt = Fe.current + fe;
1080
+ se < 3 && V(
1081
+ `[AUDIO] Viseme "${C}": segment_relative=${fe}ms, segment_offset=${Fe.current.toFixed(
1068
1082
  0
1069
- )}ms => vtime=${At}ms`
1070
- ), ie.forEach((Lt) => {
1071
- v.current.push({
1072
- viseme: Lt.v,
1073
- weight: Lt.w,
1074
- vtime: At,
1083
+ )}ms => vtime=${Lt}ms`
1084
+ ), oe.forEach((Tt) => {
1085
+ x.current.push({
1086
+ viseme: Tt.v,
1087
+ weight: Tt.w,
1088
+ vtime: Lt,
1075
1089
  vduration: Ee
1076
1090
  });
1077
1091
  });
1078
1092
  }
1079
- }), _("Speaking...");
1093
+ }), v("Speaking...");
1080
1094
  } finally {
1081
- if (W.current = !1, D.current.length > 0) {
1082
- const o = D.current.shift();
1083
- o && ot(o.audio, o.visemes, o.isNewSegment);
1095
+ if (N.current = !1, ne.current.length > 0) {
1096
+ const o = ne.current.shift();
1097
+ o && at(o.audio, o.visemes, o.isNewSegment);
1084
1098
  }
1085
1099
  }
1086
1100
  }
1087
- }, jt = async (e) => {
1101
+ }, Jt = async (e) => {
1088
1102
  try {
1089
- m(!0), We(!1), Oe.current = "", I(""), _("Processing Voice...");
1090
- const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = $t(o), a = new FileReader();
1091
- a.readAsDataURL(n), a.onloadend = async () => {
1092
- const p = a.result.split(",")[1];
1093
- ze(), te(""), he.current = "", Ce.current = !1;
1094
- const R = `${lt}/stt?token=${encodeURIComponent(
1095
- T
1096
- )}`, S = await fetch(R, {
1103
+ E(!0), We(!1), Oe.current = "", me(""), v("Processing Voice...");
1104
+ const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = jt(o), c = new FileReader();
1105
+ c.readAsDataURL(n), c.onloadend = async () => {
1106
+ const h = c.result.split(",")[1];
1107
+ Ge(), X(""), pe.current = "", Ce.current = !1;
1108
+ const w = `${ut}/stt?token=${encodeURIComponent(
1109
+ O
1110
+ )}`, A = await fetch(w, {
1097
1111
  method: "POST",
1098
1112
  headers: { "Content-Type": "application/json" },
1099
1113
  body: JSON.stringify({
1100
- audio_base64: p,
1114
+ audio_base64: h,
1101
1115
  audio_format: "wav"
1102
1116
  })
1103
1117
  });
1104
- if (S.status === 429) {
1118
+ if (A.status === 429) {
1105
1119
  try {
1106
- const se = await S.text(), C = JSON.parse(se);
1107
- B("[STT] 429 agent at capacity:", C?.detail);
1120
+ const se = await A.text(), C = JSON.parse(se);
1121
+ V("[STT] 429 agent at capacity:", C?.detail);
1108
1122
  } catch {
1109
1123
  }
1110
- te(""), _("Busy"), m(!1);
1124
+ X(""), v("Busy"), E(!1);
1111
1125
  return;
1112
1126
  }
1113
- if (!S.ok) {
1114
- const se = await S.text();
1127
+ if (!A.ok) {
1128
+ const se = await A.text();
1115
1129
  let C = "STT Failed";
1116
1130
  try {
1117
1131
  C = JSON.parse(se).error || C;
@@ -1120,36 +1134,36 @@ const yn = ({
1120
1134
  }
1121
1135
  throw new Error(C);
1122
1136
  }
1123
- const x = S.body;
1124
- if (B("this is body" + x), !x) {
1125
- _("STT Failed"), m(!1);
1137
+ const R = A.body;
1138
+ if (V("this is body" + R), !R) {
1139
+ v("STT Failed"), E(!1);
1126
1140
  return;
1127
1141
  }
1128
- const F = x.getReader();
1129
- ke.current = !1;
1130
- const H = new TextDecoder();
1131
- let J = "", K = !1;
1132
- const N = async (se, C) => {
1142
+ const L = R.getReader();
1143
+ u.current = !1;
1144
+ const W = new TextDecoder();
1145
+ let q = "", Z = !1;
1146
+ const F = async (se, C) => {
1133
1147
  switch (se) {
1134
1148
  case "transcript":
1135
- C.transcript != null && te(String(C.transcript));
1149
+ C.transcript != null && X(String(C.transcript));
1136
1150
  break;
1137
1151
  case "text": {
1138
- const ie = C.delta ?? C.text ?? "";
1139
- ie && wt(ie);
1152
+ const oe = C.delta ?? C.text ?? "";
1153
+ oe && vt(oe);
1140
1154
  break;
1141
1155
  }
1142
1156
  case "audio": {
1143
- const ie = C.chunk, fe = C.visemes ?? [], Ee = !!C.is_new_segment;
1144
- ie && await ot(ie, fe, Ee);
1157
+ const oe = C.chunk, fe = C.visemes ?? [], Ee = !!C.is_new_segment;
1158
+ oe && await at(oe, fe, Ee);
1145
1159
  break;
1146
1160
  }
1147
1161
  case "done": {
1148
- K = !0, _("Ready"), m(!1);
1162
+ Z = !0, v("Ready"), E(!1);
1149
1163
  break;
1150
1164
  }
1151
1165
  case "error": {
1152
- K = !0, _("STT Failed"), m(!1);
1166
+ Z = !0, v("STT Failed"), E(!1);
1153
1167
  break;
1154
1168
  }
1155
1169
  default:
@@ -1157,37 +1171,37 @@ const yn = ({
1157
1171
  }
1158
1172
  };
1159
1173
  for (; ; ) {
1160
- const { done: se, value: C } = await F.read();
1161
- C && (J += H.decode(C, { stream: !0 }));
1162
- const ie = J.split(`
1174
+ const { done: se, value: C } = await L.read();
1175
+ C && (q += W.decode(C, { stream: !0 }));
1176
+ const oe = q.split(`
1163
1177
 
1164
1178
  `);
1165
- J = ie.pop() ?? "";
1166
- for (const fe of ie) {
1167
- const Ee = Ye(fe);
1168
- Ee && await N(Ee.event, Ee.data);
1179
+ q = oe.pop() ?? "";
1180
+ for (const fe of oe) {
1181
+ const Ee = ze(fe);
1182
+ Ee && await F(Ee.event, Ee.data);
1169
1183
  }
1170
1184
  if (se) {
1171
- if (J.trim()) {
1172
- const fe = Ye(J.trim());
1173
- fe && await N(fe.event, fe.data);
1185
+ if (q.trim()) {
1186
+ const fe = ze(q.trim());
1187
+ fe && await F(fe.event, fe.data);
1174
1188
  }
1175
- K || (_("Ready"), m(!1));
1189
+ Z || (v("Ready"), E(!1));
1176
1190
  break;
1177
1191
  }
1178
1192
  }
1179
1193
  };
1180
1194
  } catch (t) {
1181
- console.error("Audio Submission Error:", t), _("STT Failed"), m(!1);
1195
+ console.error("Audio Submission Error:", t), v("STT Failed"), E(!1);
1182
1196
  }
1183
- }, Jt = async (e) => {
1184
- e && e.preventDefault(), We(!1), Oe.current = "", I(""), !(!E || ce) && await qt(E);
1185
- }, Ye = (e) => {
1197
+ }, qt = async (e) => {
1198
+ e && e.preventDefault(), We(!1), Oe.current = "", me(""), !(!he || k) && await Gt(he);
1199
+ }, ze = (e) => {
1186
1200
  const t = e.split(/\r?\n/);
1187
- let s = "", o = "";
1188
- for (const a of t)
1189
- a.startsWith("event:") ? s = a.slice(6).trim() : a.startsWith("data:") && (o = a.slice(5).trim());
1190
- if (!s) return null;
1201
+ let i = "", o = "";
1202
+ for (const c of t)
1203
+ c.startsWith("event:") ? i = c.slice(6).trim() : c.startsWith("data:") && (o = c.slice(5).trim());
1204
+ if (!i) return null;
1191
1205
  let n = {};
1192
1206
  if (o)
1193
1207
  try {
@@ -1195,55 +1209,55 @@ const yn = ({
1195
1209
  } catch {
1196
1210
  n = { raw: o };
1197
1211
  }
1198
- return { event: s, data: n };
1199
- }, kt = (e, t) => {
1212
+ return { event: i, data: n };
1213
+ }, At = (e, t) => {
1200
1214
  switch (e) {
1201
1215
  case "connected":
1202
- he.current = "", Ce.current = !1;
1216
+ pe.current = "", Ce.current = !1;
1203
1217
  break;
1204
1218
  case "text": {
1205
- const s = t.delta ?? "";
1206
- s && wt(s);
1219
+ const i = t.delta ?? "";
1220
+ i && vt(i);
1207
1221
  break;
1208
1222
  }
1209
1223
  case "audio": {
1210
- const s = t.chunk, o = t.visemes ?? [];
1211
- s && ot(s, o);
1224
+ const i = t.chunk, o = t.visemes ?? [];
1225
+ i && at(i, o);
1212
1226
  break;
1213
1227
  }
1214
1228
  case "done": {
1215
- const s = vt(), o = Oe.current.trim(), n = [
1216
- ...s,
1217
- { role: "user", content: E || "..." },
1229
+ const i = yt(), o = Oe.current.trim(), n = [
1230
+ ...i,
1231
+ { role: "user", content: he || "..." },
1218
1232
  { role: "assistant", content: o }
1219
1233
  ];
1220
- Ut(n), Ie.current = [...v.current], _("Ready"), m(!1), te("");
1234
+ Bt(n), $e.current = [...x.current], v("Ready"), E(!1), X("");
1221
1235
  break;
1222
1236
  }
1223
1237
  case "error": {
1224
- const s = t.message ?? "Unknown error";
1225
- Oe.current = s, I(s), _("Agent Failed"), m(!1);
1238
+ const i = t.message ?? "Unknown error";
1239
+ Oe.current = i, me(i), v("Agent Failed"), E(!1);
1226
1240
  break;
1227
1241
  }
1228
1242
  }
1229
- }, qt = async (e) => {
1230
- m(!0), _("Thinking..."), Oe.current = "", he.current = "", Ce.current = !1, ze(), ve.current = 0, u(0);
1231
- const t = `${lt}/agent/chat?token=${encodeURIComponent(
1232
- T
1243
+ }, Gt = async (e) => {
1244
+ E(!0), v("Thinking..."), Oe.current = "", pe.current = "", Ce.current = !1, Ge(), xe.current = 0, s(0);
1245
+ const t = `${ut}/agent/chat?token=${encodeURIComponent(
1246
+ O
1233
1247
  )}`;
1234
1248
  try {
1235
- const s = vt();
1249
+ const i = yt();
1236
1250
  let o = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1237
- o || (nn(
1251
+ o || (rn(
1238
1252
  "[CHAT] Session UID missing at send time! Generating emergency backup."
1239
1253
  ), o = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", o));
1240
1254
  const n = {
1241
- history: s,
1255
+ history: i,
1242
1256
  question: e,
1243
1257
  lead_id: o
1244
1258
  };
1245
- B("[CHAT] Sending payload:", n);
1246
- const a = await fetch(t, {
1259
+ V("[CHAT] Sending payload:", n);
1260
+ const c = await fetch(t, {
1247
1261
  method: "POST",
1248
1262
  headers: {
1249
1263
  "Content-Type": "application/json"
@@ -1251,75 +1265,75 @@ const yn = ({
1251
1265
  body: JSON.stringify(n),
1252
1266
  cache: "default"
1253
1267
  });
1254
- if (a.status === 429) {
1268
+ if (c.status === 429) {
1255
1269
  try {
1256
- const F = await a.json();
1257
- B("[CHAT] 429 agent at capacity:", F?.detail);
1270
+ const L = await c.json();
1271
+ V("[CHAT] 429 agent at capacity:", L?.detail);
1258
1272
  } catch {
1259
1273
  }
1260
- te(""), _("Busy"), m(!1);
1274
+ X(""), v("Busy"), E(!1);
1261
1275
  return;
1262
1276
  }
1263
- if (!a.ok)
1277
+ if (!c.ok)
1264
1278
  throw new Error("Agent request failed");
1265
- const p = a.body;
1266
- if (!p) {
1267
- _("Agent Failed"), m(!1);
1279
+ const h = c.body;
1280
+ if (!h) {
1281
+ v("Agent Failed"), E(!1);
1268
1282
  return;
1269
1283
  }
1270
- const R = p.getReader();
1271
- ke.current = !1;
1272
- const S = new TextDecoder();
1273
- let x = "";
1284
+ const w = h.getReader();
1285
+ u.current = !1;
1286
+ const A = new TextDecoder();
1287
+ let R = "";
1274
1288
  for (; ; ) {
1275
- const { done: F, value: H } = await R.read();
1276
- B(
1277
- `[SSE] Chunk received. done=${F}, length=${H?.length || 0}`
1278
- ), H && (x += S.decode(H, { stream: !0 }));
1279
- const J = x.split(`
1289
+ const { done: L, value: W } = await w.read();
1290
+ V(
1291
+ `[SSE] Chunk received. done=${L}, length=${W?.length || 0}`
1292
+ ), W && (R += A.decode(W, { stream: !0 }));
1293
+ const q = R.split(`
1280
1294
 
1281
1295
  `);
1282
- x = J.pop() ?? "";
1283
- for (const K of J) {
1284
- B(`[SSE] Processing block: ${K.slice(0, 50)}...`);
1285
- const N = Ye(K);
1286
- N && (B(`[SSE] Event: ${N.event}`), kt(N.event, N.data));
1296
+ R = q.pop() ?? "";
1297
+ for (const Z of q) {
1298
+ V(`[SSE] Processing block: ${Z.slice(0, 50)}...`);
1299
+ const F = ze(Z);
1300
+ F && (V(`[SSE] Event: ${F.event}`), At(F.event, F.data));
1287
1301
  }
1288
- if (F) {
1289
- if (B("[SSE] Stream finished"), x.trim()) {
1290
- const K = Ye(x.trim());
1291
- K && kt(K.event, K.data);
1302
+ if (L) {
1303
+ if (V("[SSE] Stream finished"), R.trim()) {
1304
+ const Z = ze(R.trim());
1305
+ Z && At(Z.event, Z.data);
1292
1306
  }
1293
- _("Ready"), m(!1), te("");
1307
+ v("Ready"), E(!1), X("");
1294
1308
  break;
1295
1309
  }
1296
1310
  }
1297
- } catch (s) {
1298
- console.error("Chat Error:", s), _("Agent Failed"), m(!1);
1311
+ } catch (i) {
1312
+ console.error("Chat Error:", i), v("Agent Failed"), E(!1);
1299
1313
  }
1300
- }, Rt = ae.trim(), at = Rt && Y ? Rt.slice(
1314
+ }, Rt = D.trim(), ct = Rt && U ? Rt.slice(
1301
1315
  0,
1302
1316
  d != null && d > 0 ? d : 0
1303
1317
  ) : "";
1304
- P(() => {
1305
- const e = Ze.current;
1306
- e !== "exiting" && (at ? (Dt(at), e === "hidden" && Je("entering")) : (e === "visible" || e === "entering") && Je("exiting"));
1307
- }, [at, ue]);
1308
- const Gt = Qe(() => {
1309
- const e = Ze.current;
1310
- e === "entering" ? Je("visible") : e === "exiting" && Je("hidden");
1318
+ $(() => {
1319
+ const e = et.current;
1320
+ e !== "exiting" && (ct ? (Ot(ct), e === "hidden" && je("entering")) : (e === "visible" || e === "entering") && je("exiting"));
1321
+ }, [ct, ue]);
1322
+ const zt = Ye(() => {
1323
+ const e = et.current;
1324
+ e === "entering" ? je("visible") : e === "exiting" && je("hidden");
1311
1325
  }, []);
1312
- return Zt(() => {
1313
- const e = ht.current;
1326
+ return en(() => {
1327
+ const e = mt.current;
1314
1328
  e && (e.scrollTop = e.scrollHeight);
1315
- }, [mt]), /* @__PURE__ */ oe("div", { className: "avatar-widget-container", children: [
1316
- /* @__PURE__ */ oe("div", { className: "avatar-input-area", children: [
1317
- ne !== "hidden" ? /* @__PURE__ */ l(
1329
+ }, [pt]), /* @__PURE__ */ ae("div", { className: "avatar-widget-container", children: [
1330
+ /* @__PURE__ */ ae("div", { className: "avatar-input-area", children: [
1331
+ _e !== "hidden" ? /* @__PURE__ */ l(
1318
1332
  "div",
1319
1333
  {
1320
- className: `avatar-thinking-tab${ne === "exiting" ? " avatar-thinking-tab--exiting" : ne === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1321
- onAnimationEnd: Ct,
1322
- children: Le === It ? /* @__PURE__ */ l(
1334
+ className: `avatar-thinking-tab${_e === "exiting" ? " avatar-thinking-tab--exiting" : _e === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1335
+ onAnimationEnd: Dt,
1336
+ children: Re === Mt ? /* @__PURE__ */ l(
1323
1337
  "a",
1324
1338
  {
1325
1339
  href: "https://leads.streamoji.com",
@@ -1327,7 +1341,7 @@ const yn = ({
1327
1341
  rel: "noopener noreferrer",
1328
1342
  children: "Made by Streamoji Leads"
1329
1343
  }
1330
- ) : Le
1344
+ ) : Re
1331
1345
  }
1332
1346
  ) : null,
1333
1347
  /* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
@@ -1339,7 +1353,7 @@ const yn = ({
1339
1353
  width: "100%",
1340
1354
  height: "100%"
1341
1355
  },
1342
- children: nt ? /* @__PURE__ */ oe("div", { className: "avatar-input-recording", children: [
1356
+ children: rt ? /* @__PURE__ */ ae("div", { className: "avatar-input-recording", children: [
1343
1357
  /* @__PURE__ */ l(
1344
1358
  "button",
1345
1359
  {
@@ -1347,7 +1361,7 @@ const yn = ({
1347
1361
  className: "avatar-recording-cancel",
1348
1362
  onClick: Ht,
1349
1363
  title: "Cancel",
1350
- children: /* @__PURE__ */ oe(
1364
+ children: /* @__PURE__ */ ae(
1351
1365
  "svg",
1352
1366
  {
1353
1367
  width: "18",
@@ -1367,7 +1381,7 @@ const yn = ({
1367
1381
  )
1368
1382
  }
1369
1383
  ),
1370
- /* @__PURE__ */ oe(
1384
+ /* @__PURE__ */ ae(
1371
1385
  "div",
1372
1386
  {
1373
1387
  style: {
@@ -1379,8 +1393,8 @@ const yn = ({
1379
1393
  minWidth: 0
1380
1394
  },
1381
1395
  children: [
1382
- /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Tt, { analyser: Pt }) }),
1383
- /* @__PURE__ */ oe(
1396
+ /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Et, { analyser: Wt }) }),
1397
+ /* @__PURE__ */ ae(
1384
1398
  "span",
1385
1399
  {
1386
1400
  style: {
@@ -1393,9 +1407,9 @@ const yn = ({
1393
1407
  fontVariantNumeric: "tabular-nums"
1394
1408
  },
1395
1409
  children: [
1396
- Math.floor(yt / 60),
1410
+ Math.floor(St / 60),
1397
1411
  ":",
1398
- String(yt % 60).padStart(2, "0")
1412
+ String(St % 60).padStart(2, "0")
1399
1413
  ]
1400
1414
  }
1401
1415
  )
@@ -1407,7 +1421,7 @@ const yn = ({
1407
1421
  {
1408
1422
  type: "button",
1409
1423
  className: "avatar-recording-confirm",
1410
- onClick: Vt,
1424
+ onClick: $t,
1411
1425
  title: "Send",
1412
1426
  children: /* @__PURE__ */ l(
1413
1427
  "svg",
@@ -1426,7 +1440,7 @@ const yn = ({
1426
1440
  )
1427
1441
  }
1428
1442
  )
1429
- ] }) : Y && !tt ? /* @__PURE__ */ oe("div", { className: "avatar-input-speaking", children: [
1443
+ ] }) : U && !nt ? /* @__PURE__ */ ae("div", { className: "avatar-input-speaking", children: [
1430
1444
  /* @__PURE__ */ l(
1431
1445
  "div",
1432
1446
  {
@@ -1437,7 +1451,7 @@ const yn = ({
1437
1451
  alignItems: "center",
1438
1452
  paddingRight: "8px"
1439
1453
  },
1440
- children: /* @__PURE__ */ l(Tt, { analyser: xt })
1454
+ children: /* @__PURE__ */ l(Et, { analyser: kt })
1441
1455
  }
1442
1456
  ),
1443
1457
  /* @__PURE__ */ l(
@@ -1445,12 +1459,12 @@ const yn = ({
1445
1459
  {
1446
1460
  type: "button",
1447
1461
  className: "avatar-speaking-stop",
1448
- onClick: () => ze(!0),
1462
+ onClick: () => Ge(!0),
1449
1463
  title: "Stop",
1450
1464
  children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
1451
1465
  }
1452
1466
  )
1453
- ] }) : ce ? /* @__PURE__ */ l(
1467
+ ] }) : k ? /* @__PURE__ */ l(
1454
1468
  "div",
1455
1469
  {
1456
1470
  style: {
@@ -1462,10 +1476,10 @@ const yn = ({
1462
1476
  },
1463
1477
  children: /* @__PURE__ */ l("div", { className: "avatar-input-loader" })
1464
1478
  }
1465
- ) : /* @__PURE__ */ oe(
1479
+ ) : /* @__PURE__ */ ae(
1466
1480
  "form",
1467
1481
  {
1468
- onSubmit: Jt,
1482
+ onSubmit: qt,
1469
1483
  style: {
1470
1484
  flex: 1,
1471
1485
  display: "flex",
@@ -1478,15 +1492,15 @@ const yn = ({
1478
1492
  {
1479
1493
  id: "avatar-text-input",
1480
1494
  type: "text",
1481
- value: E,
1482
- onChange: (e) => te(e.target.value),
1483
- placeholder: U === "Busy" ? "Assisting another user" : He || "Ask me anything",
1484
- disabled: ce || U === "Busy",
1495
+ value: he,
1496
+ onChange: (e) => X(e.target.value),
1497
+ placeholder: I === "Busy" ? "Assisting another user" : Ne || "Ask me anything",
1498
+ disabled: k || I === "Busy",
1485
1499
  autoComplete: "off",
1486
1500
  style: { width: "100%", height: "100%" }
1487
1501
  }
1488
1502
  ),
1489
- U === "Busy" ? /* @__PURE__ */ l(
1503
+ I === "Busy" ? /* @__PURE__ */ l(
1490
1504
  "button",
1491
1505
  {
1492
1506
  type: "button",
@@ -1513,15 +1527,15 @@ const yn = ({
1513
1527
  }
1514
1528
  )
1515
1529
  }
1516
- ) : E.trim() === "" ? /* @__PURE__ */ l(
1530
+ ) : he.trim() === "" ? /* @__PURE__ */ l(
1517
1531
  "button",
1518
1532
  {
1519
1533
  type: "button",
1520
1534
  className: "mic-button",
1521
- onClick: Wt,
1522
- disabled: ce,
1535
+ onClick: Vt,
1536
+ disabled: k,
1523
1537
  style: { backgroundColor: "#1e4a5e" },
1524
- children: /* @__PURE__ */ oe(
1538
+ children: /* @__PURE__ */ ae(
1525
1539
  "svg",
1526
1540
  {
1527
1541
  width: "28",
@@ -1553,7 +1567,7 @@ const yn = ({
1553
1567
  {
1554
1568
  type: "submit",
1555
1569
  className: "mic-button",
1556
- disabled: ce,
1570
+ disabled: k,
1557
1571
  style: { backgroundColor: "#1e4a5e" },
1558
1572
  title: "Send",
1559
1573
  children: /* @__PURE__ */ l(
@@ -1584,22 +1598,22 @@ const yn = ({
1584
1598
  }
1585
1599
  ) })
1586
1600
  ] }),
1587
- /* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ oe("div", { className: "avatar-scene-wrapper", children: [
1601
+ /* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ ae("div", { className: "avatar-scene-wrapper", children: [
1588
1602
  ue !== "hidden" && /* @__PURE__ */ l(
1589
1603
  "div",
1590
1604
  {
1591
1605
  className: `avatar-bubble${ue === "entering" ? " avatar-bubble--entering" : ue === "exiting" ? " avatar-bubble--exiting" : ""}`,
1592
- onAnimationEnd: Gt,
1593
- children: /* @__PURE__ */ l("div", { ref: ht, className: `avatar-bubble__content${tt ? " avatar-bubble__content--nudge" : ""}`, children: mt })
1606
+ onAnimationEnd: zt,
1607
+ children: /* @__PURE__ */ l("div", { ref: mt, className: `avatar-bubble__content${nt ? " avatar-bubble__content--nudge" : ""}`, children: pt })
1594
1608
  }
1595
1609
  ),
1596
1610
  /* @__PURE__ */ l(
1597
1611
  "div",
1598
1612
  {
1599
1613
  className: "avatar-canvas-layer",
1600
- style: { width: O, height: O },
1601
- children: /* @__PURE__ */ oe(
1602
- Qt,
1614
+ style: { width: j, height: j },
1615
+ children: /* @__PURE__ */ ae(
1616
+ Xt,
1603
1617
  {
1604
1618
  shadows: !0,
1605
1619
  camera: { position: [0.2, 1.4, 3], fov: 42 },
@@ -1607,30 +1621,30 @@ const yn = ({
1607
1621
  dpr: 1.8,
1608
1622
  style: { pointerEvents: "none", width: "100%", height: "100%" },
1609
1623
  children: [
1610
- /* @__PURE__ */ l(_n, { target: fn }),
1624
+ /* @__PURE__ */ l(wn, { target: hn }),
1611
1625
  /* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
1612
1626
  /* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1613
- /* @__PURE__ */ l(zt, { preset: "city" }),
1614
- /* @__PURE__ */ l(en, { fallback: null, children: V !== null && /* @__PURE__ */ l(
1615
- wn,
1627
+ /* @__PURE__ */ l(Yt, { preset: "city" }),
1628
+ /* @__PURE__ */ l(tn, { fallback: null, children: H !== null && /* @__PURE__ */ l(
1629
+ vn,
1616
1630
  {
1617
- avatarUrl: V,
1618
- isPlayingRef: L,
1619
- visemeQueueRef: v,
1620
- audioContextRef: y,
1621
- responseAudioStartTimeRef: we,
1622
- adjustments: dn,
1623
- mood: r,
1624
- expression: G,
1625
- agentResponse: ae,
1626
- isSpeaking: Y,
1627
- nextStartTimeRef: le,
1628
- stopPlayback: ze,
1629
- setIsSpeaking: $,
1631
+ avatarUrl: H,
1632
+ isPlayingRef: S,
1633
+ visemeQueueRef: x,
1634
+ audioContextRef: ye,
1635
+ responseAudioStartTimeRef: re,
1636
+ adjustments: fn,
1637
+ mood: m,
1638
+ expression: K,
1639
+ agentResponse: D,
1640
+ isSpeaking: U,
1641
+ nextStartTimeRef: Se,
1642
+ stopPlayback: Ge,
1643
+ setIsSpeaking: be,
1630
1644
  expressionUrl: Ke,
1631
- onExpressionFinished: Nt,
1632
- isNudgeResponse: tt,
1633
- avatarGender: g
1645
+ onExpressionFinished: Ut,
1646
+ isNudgeResponse: nt,
1647
+ avatarGender: p
1634
1648
  }
1635
1649
  ) })
1636
1650
  ]
@@ -1640,17 +1654,21 @@ const yn = ({
1640
1654
  )
1641
1655
  ] }) })
1642
1656
  ] });
1643
- }, Ln = ({
1657
+ }, Tn = ({
1644
1658
  token: f,
1645
- onNavigationRequested: A
1659
+ avatarGender: T,
1660
+ onNavigationRequested: b,
1661
+ presetUserDetails: p
1646
1662
  }) => /* @__PURE__ */ l(
1647
- yn,
1663
+ Sn,
1648
1664
  {
1649
1665
  token: f,
1650
- onNavigationRequested: A
1666
+ onNavigationRequested: b,
1667
+ avatarGender: T,
1668
+ presetUserDetails: p
1651
1669
  }
1652
1670
  );
1653
1671
  export {
1654
- Ln as AvatarWidget
1672
+ Tn as AvatarWidget
1655
1673
  };
1656
1674
  //# sourceMappingURL=avatar-widget.js.map