@streamoji/avatar-widget 0.3.3 → 0.3.5

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