@streamoji/avatar-widget 0.3.4 → 0.3.6

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