@streamoji/avatar-widget 0.2.5 → 0.2.7

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