@streamoji/avatar-widget 0.3.5 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,100 +1,100 @@
1
- import { jsx as l, jsxs as ae } from "react/jsx-runtime";
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
- if (!p) return;
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++) {
1
+ import { jsx as d, jsxs as le } from "react/jsx-runtime";
2
+ import { useGLTF as mt, Environment as on } from "@react-three/drei";
3
+ import { useFrame as an, Canvas as cn, useThree as un } from "@react-three/fiber";
4
+ import { memo as ln, useMemo as bt, useRef as c, useState as v, useEffect as W, useCallback as $e, useLayoutEffect as dn, Suspense as hn } from "react";
5
+ import * as ze from "three";
6
+ import { GLTFLoader as fn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
+ const Ye = "https://ai.streamoji.com", B = (...m) => {
8
+ }, mn = (...m) => {
9
+ }, Nt = ({ analyser: m }) => {
10
+ const T = c(null), y = c(null);
11
+ return W(() => {
12
+ const b = T.current;
13
+ if (!b) return;
14
+ const x = b.getContext("2d", { alpha: !0 });
15
+ if (!x) return;
16
+ let H, I = null;
17
+ m && (m.fftSize = 128, I = new Uint8Array(m.frequencyBinCount));
18
+ const Ue = () => {
19
+ H = requestAnimationFrame(Ue), (b.width !== b.offsetWidth || b.height !== b.offsetHeight) && (b.width = b.offsetWidth, b.height = b.offsetHeight);
20
+ const se = b.width, R = b.height;
21
+ if (se === 0 || R === 0) return;
22
+ const we = R / 2;
23
+ x.clearRect(0, 0, se, R), x.fillStyle = "#1e293b";
24
+ const K = 2, l = K + 2, Q = se * 0.95, g = Math.floor(Q / l);
25
+ (!y.current || y.current.length !== g) && (y.current = new Float32Array(g).fill(2));
26
+ const ee = g * l, k = (se - ee) / 2;
27
+ m && I && m.getByteFrequencyData(I);
28
+ const Te = I ? I.length : 0, te = Math.floor(Te * 0.7) / g, Se = new Float32Array(g);
29
+ for (let D = 0; D < g; D++) {
30
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);
31
+ if (I && te > 0) {
32
+ const V = Math.floor(D * te), $ = Math.floor((D + 1) * te);
33
+ for (let Ee = V; Ee < $; Ee++) {
34
+ const U = I[Ee] || 0;
35
+ U > J && (J = U);
36
36
  }
37
37
  }
38
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;
39
+ const Y = J / 255, F = J > 0 ? Math.max(2, Math.pow(Y, 1.4) * R * 0.25) : 2;
40
+ Se[D] = F;
41
41
  }
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();
42
+ for (let D = 0; D < g; D++) {
43
+ const J = g - 1 - D, Y = Math.max(Se[D], Se[J]), F = y.current[D] + (Y - y.current[D]) * 0.3;
44
+ y.current[D] = F;
45
+ const V = k + D * l, $ = we - F / 2;
46
+ x.beginPath(), x.roundRect ? x.roundRect(V, $, K, F, 4) : x.fillRect(V, $, K, F), x.fill();
47
47
  }
48
48
  };
49
- return fe(), () => {
50
- cancelAnimationFrame(D);
49
+ return Ue(), () => {
50
+ cancelAnimationFrame(H);
51
51
  };
52
- }, [d]), /* @__PURE__ */ l(
52
+ }, [m]), /* @__PURE__ */ d(
53
53
  "canvas",
54
54
  {
55
- ref: L,
55
+ ref: T,
56
56
  style: { width: "100%", height: "100%", display: "block" }
57
57
  }
58
58
  );
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(
59
+ }, pn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Pt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
+ async function gn(m) {
61
+ const T = await crypto.subtle.digest(
62
62
  "SHA-256",
63
- new TextEncoder().encode(d)
63
+ new TextEncoder().encode(m)
64
64
  );
65
- return Array.from(new Uint8Array(L)).map((_) => _.toString(16).padStart(2, "0")).join("");
65
+ return Array.from(new Uint8Array(T)).map((y) => y.toString(16).padStart(2, "0")).join("");
66
66
  }
67
- function ln(d) {
68
- const [L, _] = b(null);
69
- return H(() => {
70
- if (!d) {
71
- _(null);
67
+ function bn(m) {
68
+ const [T, y] = v(null);
69
+ return W(() => {
70
+ if (!m) {
71
+ y(null);
72
72
  return;
73
73
  }
74
- let p = !1;
75
- return cn(d).then((w) => {
76
- if (p) return;
77
- const D = `${an}/${w}.glb`;
78
- fetch(D, { method: "HEAD" }).then((j) => {
79
- p || _(j.ok ? D : It);
74
+ let b = !1;
75
+ return gn(m).then((x) => {
76
+ if (b) return;
77
+ const H = `${pn}/${x}.glb`;
78
+ fetch(H, { method: "HEAD" }).then((I) => {
79
+ b || y(I.ok ? H : Pt);
80
80
  }).catch(() => {
81
- p || _(It);
81
+ b || y(Pt);
82
82
  });
83
83
  }), () => {
84
- p = !0;
84
+ b = !0;
85
85
  };
86
- }, [d]), L;
86
+ }, [m]), T;
87
87
  }
88
- const un = [
88
+ const _n = [
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
- ], dn = [
93
+ ], wn = [
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
- ], fn = [
97
+ ], Sn = [
98
98
  {
99
99
  id: "m_expr_01",
100
100
  name: "Friendly Wave",
@@ -260,23 +260,23 @@ const un = [
260
260
  name: "Take It Easy",
261
261
  url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
262
262
  }
263
- ], hn = [
263
+ ], vn = [
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
- ], mn = [
267
+ ], yn = [
268
268
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb",
269
269
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb",
270
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
- ], pn = {
272
+ ], xn = {
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
- }, gn = [-0.45, 1.9, 0.1], bn = {
277
+ }, Ln = [-0.45, 1.9, 0.1], kn = [-0.45, 1.75, 0.1], Rn = {
278
278
  browInnerUp: 0.2
279
- }, dt = 0.18, _n = 1, Mt = "__branding__", Xe = {
279
+ }, pt = 0.18, An = 1, Bt = "__branding__", nt = {
280
280
  neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
281
281
  happy: {
282
282
  mouthSmileLeft: 0.2,
@@ -358,37 +358,84 @@ const un = [
358
358
  mouthUpperUpLeft: 0.1,
359
359
  mouthUpperUpRight: 0.1
360
360
  }
361
- }, wn = [
362
- { key: "viseme_aa", mix: { jawOpen: 0.6 } },
361
+ }, Tn = [
362
+ {
363
+ key: "viseme_aa",
364
+ mix: { jawOpen: 0.4, mouthSmileLeft: 0.15, mouthSmileRight: 0.15 },
365
+ teethMix: { jawOpen: 0.2, mouthSmileLeft: 0.15, mouthSmileRight: 0.15 }
366
+ },
363
367
  {
364
368
  key: "viseme_E",
365
369
  mix: {
366
- mouthPressLeft: 0.8,
367
- mouthPressRight: 0.8,
370
+ mouthPressLeft: 0.65,
371
+ mouthPressRight: 0.65,
368
372
  mouthDimpleLeft: 1,
369
373
  mouthDimpleRight: 1,
370
- jawOpen: 0.3
374
+ jawOpen: 0.25,
375
+ mouthFunnel: 0.1
376
+ },
377
+ teethMix: {
378
+ jawOpen: 0.15,
379
+ mouthPressLeft: 0.65,
380
+ mouthPressRight: 0.65,
381
+ mouthDimpleLeft: 1,
382
+ mouthDimpleRight: 1,
383
+ mouthFunnel: 0.1
371
384
  }
372
385
  },
373
386
  {
374
387
  key: "viseme_I",
375
388
  mix: {
376
- mouthPressLeft: 0.6,
377
- mouthPressRight: 0.6,
378
- mouthDimpleLeft: 0.6,
379
- mouthDimpleRight: 0.6,
380
- jawOpen: 0.2
389
+ mouthPressLeft: 0.55,
390
+ mouthPressRight: 0.55,
391
+ mouthDimpleLeft: 1,
392
+ mouthDimpleRight: 1,
393
+ jawOpen: 0.15,
394
+ mouthFunnel: 0.05
395
+ },
396
+ teethMix: {
397
+ mouthPressLeft: 0.55,
398
+ mouthPressRight: 0.55,
399
+ mouthDimpleLeft: 1,
400
+ mouthDimpleRight: 1,
401
+ jawOpen: 0.15,
402
+ mouthFunnel: 0.05
403
+ }
404
+ },
405
+ {
406
+ key: "viseme_O",
407
+ mix: { mouthPucker: 0.7, jawOpen: 0.4, mouthFunnel: 0.25 },
408
+ teethMix: { jawForward: 0.6, jawOpen: 0.2, mouthPucker: 0.7, mouthFunnel: 0.25 }
409
+ },
410
+ {
411
+ key: "viseme_U",
412
+ mix: { mouthFunnel: 1, mouthClose: 0.2 },
413
+ teethMix: {
414
+ mouthFunnel: 1,
415
+ mouthClose: 0.2
381
416
  }
382
417
  },
383
- { key: "viseme_O", mix: { mouthPucker: 1, jawForward: 0.6, jawOpen: 0.2 } },
384
- { key: "viseme_U", mix: { mouthFunnel: 1 } },
385
418
  {
386
419
  key: "viseme_PP",
387
420
  mix: {
421
+ mouthDimpleLeft: 0.5,
422
+ mouthDimpleRight: 0.5,
423
+ mouthStretchLeft: 0.3,
424
+ mouthStretchRight: 0.3,
425
+ mouthRollLower: 0.3,
426
+ mouthRollUpper: 0.3,
427
+ mouthPressLeft: 0.5,
428
+ mouthPressRight: 0.5
429
+ },
430
+ teethMix: {
431
+ mouthDimpleLeft: 0.5,
432
+ mouthDimpleRight: 0.5,
433
+ mouthStretchLeft: 0.3,
434
+ mouthStretchRight: 0.3,
388
435
  mouthRollLower: 0.3,
389
436
  mouthRollUpper: 0.3,
390
- mouthUpperUpLeft: 0.3,
391
- mouthUpperUpRight: 0.3
437
+ mouthPressLeft: 0.5,
438
+ mouthPressRight: 0.5
392
439
  }
393
440
  },
394
441
  {
@@ -396,20 +443,43 @@ const un = [
396
443
  mix: {
397
444
  mouthPucker: 1,
398
445
  mouthShrugUpper: 1,
399
- mouthLowerDownLeft: 0.2,
400
- mouthLowerDownRight: 0.2,
401
446
  mouthDimpleLeft: 1,
402
447
  mouthDimpleRight: 1,
403
- mouthRollLower: 0.3
448
+ mouthStretchLeft: 0.5,
449
+ mouthStretchRight: 0.5,
450
+ mouthPressLeft: 0.3,
451
+ mouthPressRight: 0.3,
452
+ mouthRollLower: 0.1
453
+ },
454
+ teethMix: {
455
+ mouthPucker: 1,
456
+ mouthShrugUpper: 1,
457
+ mouthDimpleLeft: 1,
458
+ mouthDimpleRight: 1,
459
+ mouthStretchLeft: 0.5,
460
+ mouthStretchRight: 0.5,
461
+ mouthPressLeft: 0.3,
462
+ mouthPressRight: 0.3,
463
+ mouthRollLower: 0.1
404
464
  }
405
465
  },
406
466
  {
407
467
  key: "viseme_DD",
408
468
  mix: {
409
- mouthPressLeft: 0.8,
410
- mouthPressRight: 0.8,
411
- mouthFunnel: 0.5,
412
- jawOpen: 0.2
469
+ mouthShrugUpper: 0.25,
470
+ mouthShrugLower: 0.25,
471
+ mouthPressLeft: 0.4,
472
+ mouthPressRight: 0.4,
473
+ mouthFunnel: 0.7,
474
+ jawOpen: 0.1
475
+ },
476
+ teethMix: {
477
+ mouthShrugUpper: 0.25,
478
+ mouthShrugLower: 0.25,
479
+ mouthPressLeft: 0.4,
480
+ mouthPressRight: 0.4,
481
+ mouthFunnel: 0.7,
482
+ jawOpen: 0.1
413
483
  }
414
484
  },
415
485
  {
@@ -417,44 +487,113 @@ const un = [
417
487
  mix: {
418
488
  mouthPressLeft: 0.8,
419
489
  mouthPressRight: 0.8,
420
- mouthLowerDownLeft: 0.5,
421
- mouthLowerDownRight: 0.5,
490
+ mouthLowerDownLeft: 0.3,
491
+ mouthLowerDownRight: 0.3,
492
+ jawOpen: 0.1
493
+ },
494
+ teethMix: {
495
+ mouthPressLeft: 0.8,
496
+ mouthPressRight: 0.8,
497
+ mouthLowerDownLeft: 0.3,
498
+ mouthLowerDownRight: 0.3,
422
499
  jawOpen: 0.1
423
500
  }
424
501
  },
425
502
  {
426
503
  key: "viseme_TH",
427
- mix: { mouthRollUpper: 0.3, jawOpen: 0.2, tongueOut: 0.4 }
504
+ mix: { mouthStretchLeft: 0.4, mouthStretchRight: 0.4, mouthDimpleLeft: 1, mouthDimpleRight: 1, mouthFunnel: 0.4, jawOpen: 0.15, mouthShrugLower: 0.45, mouthShrugUpper: 0.45 },
505
+ teethMix: {
506
+ mouthStretchLeft: 0.4,
507
+ mouthStretchRight: 0.4,
508
+ mouthDimpleLeft: 1,
509
+ mouthDimpleRight: 1,
510
+ mouthFunnel: 0.4,
511
+ jawOpen: 0.15,
512
+ mouthShrugLower: 0.45,
513
+ mouthShrugUpper: 0.45
514
+ }
515
+ },
516
+ {
517
+ key: "viseme_CH",
518
+ mix: {
519
+ mouthPucker: 0.8,
520
+ mouthShrugLower: 0.7,
521
+ mouthShrugUpper: 0.2,
522
+ mouthLowerDownLeft: 0.6,
523
+ mouthLowerDownRight: 0.6,
524
+ mouthDimpleLeft: 0.5,
525
+ mouthDimpleRight: 0.5,
526
+ mouthUpperUpLeft: 0.8,
527
+ mouthUpperUpRight: 0.8,
528
+ jawOpen: 0.2
529
+ },
530
+ teethMix: {
531
+ mouthPucker: 0.8,
532
+ mouthShrugLower: 0.7,
533
+ mouthShrugUpper: 0.2,
534
+ mouthLowerDownLeft: 0.6,
535
+ mouthLowerDownRight: 0.6,
536
+ mouthDimpleLeft: 0.5,
537
+ mouthDimpleRight: 0.5,
538
+ mouthUpperUpLeft: 0.8,
539
+ mouthUpperUpRight: 0.8,
540
+ jawOpen: 0.2
541
+ }
542
+ },
543
+ {
544
+ key: "viseme_RR",
545
+ mix: { mouthPucker: 0.4, jawOpen: 0.2, mouthShrugUpper: 0.5, mouthFunnel: 0.15, mouthDimpleLeft: 0.5, mouthDimpleRight: 0.5 },
546
+ teethMix: {
547
+ mouthPucker: 0.4,
548
+ jawOpen: 0.2,
549
+ mouthShrugUpper: 0.5,
550
+ mouthFunnel: 0.15,
551
+ mouthDimpleLeft: 0.5,
552
+ mouthDimpleRight: 0.5
553
+ }
428
554
  },
429
- { key: "viseme_CH", mix: { mouthPucker: 0.5, jawOpen: 0.2 } },
430
- { key: "viseme_RR", mix: { mouthPucker: 0.5, jawOpen: 0.2 } },
431
555
  {
432
556
  key: "viseme_kk",
433
557
  mix: {
434
- mouthLowerDownLeft: 0.4,
435
- mouthLowerDownRight: 0.4,
436
- mouthDimpleLeft: 0.3,
437
- mouthDimpleRight: 0.3,
438
- mouthFunnel: 0.3,
439
- mouthPucker: 0.3,
440
- jawOpen: 0.15
558
+ mouthPucker: 0.5,
559
+ jawOpen: 0.2,
560
+ mouthShrugUpper: 0.5,
561
+ mouthFunnel: 0.2,
562
+ mouthDimpleLeft: 0.5,
563
+ mouthDimpleRight: 0.5
564
+ },
565
+ teethMix: {
566
+ mouthPucker: 0.5,
567
+ jawOpen: 0.2,
568
+ mouthShrugUpper: 0.5,
569
+ mouthFunnel: 0.2,
570
+ mouthDimpleLeft: 0.5,
571
+ mouthDimpleRight: 0.5
441
572
  }
442
573
  },
443
574
  {
444
575
  key: "viseme_nn",
445
576
  mix: {
446
- mouthLowerDownLeft: 0.4,
447
- mouthLowerDownRight: 0.4,
448
- mouthDimpleLeft: 0.3,
449
- mouthDimpleRight: 0.3,
450
- mouthFunnel: 0.3,
451
- mouthPucker: 0.3,
452
- jawOpen: 0.15,
453
- tongueOut: 0.2
577
+ mouthPucker: 0.6,
578
+ jawOpen: 0.2,
579
+ mouthShrugUpper: 0.7,
580
+ mouthShrugLower: 0.1,
581
+ mouthFunnel: 0.1,
582
+ mouthDimpleLeft: 0.8,
583
+ mouthDimpleRight: 0.8
584
+ },
585
+ teethMix: {
586
+ mouthPucker: 0.6,
587
+ jawOpen: 0.2,
588
+ mouthShrugUpper: 0.7,
589
+ mouthShrugLower: 0.1,
590
+ mouthFunnel: 0.1,
591
+ mouthDimpleLeft: 0.8,
592
+ mouthDimpleRight: 0.8
454
593
  }
455
594
  },
456
595
  { key: "viseme_sil", mix: {} }
457
- ], vn = {
596
+ ], Mn = {
458
597
  aei: [
459
598
  { v: "E", w: 0.8 },
460
599
  { v: "I", w: 0.2 }
@@ -483,345 +622,352 @@ const un = [
483
622
  ],
484
623
  sil: [{ v: "sil", w: 1 }]
485
624
  };
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 }];
625
+ function En(m) {
626
+ if (!m) return [{ v: "sil", w: 1 }];
627
+ const T = m.toLowerCase();
628
+ return Mn[T] ?? [{ v: "sil", w: 1 }];
490
629
  }
491
- function Sn({ target: d }) {
492
- const { camera: L } = en();
493
- return H(() => {
494
- L.lookAt(...d);
495
- }, [L, d]), null;
630
+ function In({ target: m }) {
631
+ const { camera: T } = un();
632
+ return W(() => {
633
+ T.lookAt(...m);
634
+ }, [T, m]), null;
496
635
  }
497
- function Q(d, L, _) {
498
- if (!d || !d.morphTargetDictionary)
636
+ function E(m, T, y) {
637
+ if (!m || !m.morphTargetDictionary)
499
638
  return;
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]] = _);
639
+ const b = m, x = b.morphTargetDictionary, H = b.morphTargetInfluences;
640
+ if (H)
641
+ for (const I in x)
642
+ I.toLowerCase() === T.toLowerCase() && (H[x[I]] = y);
504
643
  }
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;
644
+ function gt(m, T = 0.97) {
645
+ if (!m) return;
646
+ const y = m;
647
+ if (y.morphTargetInfluences)
648
+ for (let b = 0; b < y.morphTargetInfluences.length; b++)
649
+ y.morphTargetInfluences[b] *= T;
511
650
  }
512
- const xn = tn(
651
+ const Dn = ln(
513
652
  ({
514
- avatarUrl: d,
515
- isPlayingRef: L,
516
- visemeQueueRef: _,
517
- audioContextRef: p,
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,
529
- isNudgeResponse: U,
530
- avatarGender: me
653
+ avatarUrl: m,
654
+ isPlayingRef: T,
655
+ visemeQueueRef: y,
656
+ audioContextRef: b,
657
+ responseAudioStartTimeRef: x,
658
+ adjustments: H,
659
+ mood: I,
660
+ expression: Ue,
661
+ agentResponse: se,
662
+ isSpeaking: R,
663
+ nextStartTimeRef: we,
664
+ stopPlayback: K,
665
+ setIsSpeaking: j,
666
+ expressionUrl: l,
667
+ onExpressionFinished: Q,
668
+ isNudgeResponse: g,
669
+ avatarGender: ee
531
670
  }) => {
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;
671
+ const { scene: k } = mt(m), Me = mt(ee === "female" ? wn : _n), te = bt(
672
+ () => Me.flatMap((p) => p.animations),
673
+ [Me]
674
+ ), D = mt(ee === "female" ? yn : vn), J = bt(
675
+ () => D.flatMap((p) => p.animations),
676
+ [D]
677
+ ), Y = c(null), F = c(null), V = c(null), $ = c(null), Ee = c([]), [U] = v(() => new ze.AnimationMixer(k)), N = c({}), O = c(null), ve = c(0), Ne = c(!1), ye = c(0), de = c(null);
678
+ W(() => {
679
+ if (!(!te || !k)) {
680
+ if (te.forEach((p, u) => {
681
+ const s = `idle_${u}`;
682
+ if (!N.current[s]) {
683
+ const o = U.clipAction(p, k);
684
+ o.name = s, o.setLoop(ze.LoopOnce, 1), o.clampWhenFinished = !0, N.current[s] = o;
546
685
  }
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;
686
+ }), J.forEach((p, u) => {
687
+ const s = `talk_${u}`;
688
+ if (!N.current[s]) {
689
+ const o = U.clipAction(p, k);
690
+ o.name = s, o.setLoop(ze.LoopOnce, 1), o.clampWhenFinished = !0, N.current[s] = o;
552
691
  }
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);
692
+ }), te.length > 0) {
693
+ const p = N.current.idle_0, u = O.current && U.existingAction(O.current.getClip());
694
+ p && !u && (p.reset().fadeIn(0.5).play(), O.current = p);
556
695
  }
557
696
  return () => {
558
- M.stopAllAction(), k.current = {}, C.current = null;
697
+ U.stopAllAction(), N.current = {}, O.current = null;
559
698
  };
560
699
  }
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,
700
+ }, [te, J, k, U]);
701
+ const pe = c("");
702
+ W(() => {
703
+ if (!l || !k || l === pe.current) return;
704
+ pe.current = l, de.current = l, new fn().load(
705
+ l,
567
706
  (u) => {
568
707
  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;
708
+ const s = u.animations[0], o = U.clipAction(s, k);
709
+ if (o.name = `EXPR_${l}`, o.setLoop(ze.LoopOnce, 1), o.clampWhenFinished = !0, N.current[`EXPR_${l}`] = o, R && de.current === l) {
710
+ const h = O.current;
711
+ o.reset().fadeIn(0.3).play(), h && h !== o && h.crossFadeTo(o, 0.3, !0), O.current = o, de.current = null;
573
712
  }
574
713
  }
575
714
  },
576
715
  void 0,
577
716
  (u) => {
578
- console.error(`[ANIMATION] Failed to load ${x}`, u);
717
+ console.error(`[ANIMATION] Failed to load ${l}`, u);
579
718
  }
580
719
  );
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) {
720
+ }, [l, k, U, R]), W(() => {
721
+ const p = (u) => {
722
+ const s = u.action, o = s.name || "";
723
+ if (o.startsWith("idle_")) {
724
+ const M = (parseInt(o.split("_")[1]) + 1) % te.length, X = N.current[`idle_${M}`];
725
+ X && (X.reset().fadeIn(0.5).play(), s.crossFadeTo(X, 0.5, !0), O.current = X);
726
+ } else if (o.startsWith("EXPR_")) {
727
+ if (R) {
589
728
  const h = Math.floor(
590
729
  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);
730
+ ), M = N.current[`talk_${h}`];
731
+ M && (M.reset().fadeIn(0.5).play(), s.crossFadeTo(M, 0.5, !0), O.current = M);
593
732
  } else {
594
- const h = k.current.idle_0;
595
- h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
733
+ const h = N.current.idle_0;
734
+ h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), O.current = h);
596
735
  }
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);
736
+ Q && Q();
737
+ } else if (o.startsWith("talk_"))
738
+ if (R && !g) {
739
+ const M = (parseInt(o.split("_")[1]) + 1) % J.length, X = N.current[`talk_${M}`];
740
+ X && (X.reset().fadeIn(0.3).play(), s.crossFadeTo(X, 0.3, !0), O.current = X);
602
741
  } else {
603
- const h = k.current.idle_0;
604
- h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
742
+ const h = N.current.idle_0;
743
+ h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), O.current = h);
605
744
  }
606
745
  };
607
- return M.addEventListener("finished", f), () => M.removeEventListener("finished", f);
746
+ return U.addEventListener("finished", p), () => U.removeEventListener("finished", p);
608
747
  }, [
609
- M,
610
- Y,
611
- J,
612
- N,
613
748
  U,
614
- R
615
- ]), H(() => {
616
- if (N && S) {
617
- const f = C.current, u = f?.name || "";
749
+ te,
750
+ J,
751
+ R,
752
+ g,
753
+ Q
754
+ ]), W(() => {
755
+ if (R && k) {
756
+ const p = O.current, u = p?.name || "";
618
757
  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;
758
+ const s = de.current;
759
+ if (s) {
760
+ const o = N.current[`EXPR_${s}`];
761
+ if (o) {
762
+ o.reset().fadeIn(0.3).play(), p && p !== o && p.crossFadeTo(o, 0.3, !0), O.current = o, de.current = null;
624
763
  return;
625
764
  }
626
765
  }
627
766
  if (u.startsWith("idle_") || u === "") {
628
- const s = Math.floor(
767
+ const o = Math.floor(
629
768
  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);
769
+ ), h = N.current[`talk_${o}`];
770
+ h && (h.reset().fadeIn(0.5).play(), p && p.crossFadeTo(h, 0.5, !0), O.current = h);
632
771
  }
633
772
  }
634
- } else if (!N && S) {
635
- const f = C.current, u = f?.name || "";
773
+ } else if (!R && k) {
774
+ const p = O.current, u = p?.name || "";
636
775
  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);
776
+ const s = N.current.idle_0;
777
+ s && (s.reset().fadeIn(0.5).play(), p && p.crossFadeTo(s, 0.5, !0), O.current = s);
639
778
  }
640
779
  }
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}`));
780
+ }, [R, k, l]), W(() => {
781
+ if (!k) return;
782
+ k.traverse((s) => {
783
+ if (s.isMesh && s.morphTargetDictionary) {
784
+ const o = s.name.toLowerCase();
785
+ (o.includes("head") || o.includes("avatar")) && (F.current = s, B(`[ANIMATION] Found head mesh: ${s.name}`)), o.includes("teeth") && (V.current = s, B(`[ANIMATION] Found teeth mesh: ${s.name}`)), o.includes("beard") && ($.current = s, B(`[ANIMATION] Found beard mesh: ${s.name}`));
647
786
  }
648
787
  });
649
- const f = I.current?.morphTargetDictionary;
650
- f && Object.keys(f).filter(
651
- (i) => i.toLowerCase().includes("brow")
788
+ const p = F.current?.morphTargetDictionary;
789
+ p && Object.keys(p).filter(
790
+ (s) => s.toLowerCase().includes("brow")
652
791
  );
653
792
  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);
793
+ k.traverse((s) => {
794
+ if (s.isMesh) {
795
+ const h = s.morphTargetDictionary;
796
+ h && Object.keys(h).some((M) => M.toLowerCase().includes("brow")) && u.push(s);
658
797
  }
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);
798
+ }), Ee.current = u, u.length > 0 && B("[ANIMATION] Meshes with brow morphs:", u.length);
799
+ }, [k]);
800
+ const He = (p, u = 1) => {
801
+ const s = `viseme_${p}`.toLowerCase(), o = Tn.find((h) => h.key.toLowerCase() === s);
802
+ if (o) {
803
+ for (const h in o.mix) {
804
+ const M = o.mix[h] * u;
805
+ E(F.current, h, M), E($.current, h, M), (!o.teethMix || !(h in o.teethMix)) && E(V.current, h, M);
667
806
  }
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]);
807
+ if (o.teethMix)
808
+ for (const h in o.teethMix) {
809
+ const M = o.teethMix[h] * u;
810
+ E(V.current, h, M);
811
+ }
812
+ }
813
+ }, xe = (p) => {
814
+ const u = nt[p] ?? nt.neutral;
815
+ for (const s in u)
816
+ E(F.current, s, u[s]), E(V.current, s, u[s]), E($.current, s, u[s]);
672
817
  };
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;
818
+ return an((p, u) => {
819
+ const s = Math.pow(0.88, 60 * u);
820
+ gt(F.current, s), gt(V.current, s), gt($.current, s), xe(I);
821
+ const o = p.clock.elapsedTime;
677
822
  let h = 0;
678
- if (Math.floor(s) % 5 === 0 && Math.floor((s - u) % 5) !== 0) {
823
+ if (Math.floor(o) % 5 === 0 && Math.floor((o - u) % 5) !== 0) {
679
824
  let q = null;
680
- S.traverse((Z) => {
681
- Z.name.toLowerCase().includes("hips") && (q = Z);
825
+ k.traverse((z) => {
826
+ z.name.toLowerCase().includes("hips") && (q = z);
682
827
  });
683
- const Se = q ? `Hips Y: ${q.position.y.toFixed(4)}` : "Hips not found";
684
- $(`[ANIMATION] Mixer Time: ${M.time.toFixed(2)}, ${Se}`);
828
+ const ke = q ? `Hips Y: ${q.position.y.toFixed(4)}` : "Hips not found";
829
+ B(`[ANIMATION] Mixer Time: ${U.time.toFixed(2)}, ${ke}`);
685
830
  }
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;
831
+ if (U.update(u), o > ve.current && !Ne.current && (Ne.current = !0, ye.current = o), Ne.current) {
832
+ const q = R ? 0.2 : 0.3, ke = (o - ye.current) / q;
833
+ if (ke >= 1) {
834
+ Ne.current = !1;
835
+ const z = R ? 1 : 2.5;
836
+ ve.current = o + z;
692
837
  } else {
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;
838
+ const z = ke < 0.5 ? ke * 2 : (1 - ke) * 2;
839
+ E(F.current, "eyeBlinkLeft", z), E(F.current, "eyeBlinkRight", z), E(V.current, "eyeBlinkLeft", z), E(V.current, "eyeBlinkRight", z), E($.current, "eyeBlinkLeft", z), E($.current, "eyeBlinkRight", z), h = z * Rn.browInnerUp;
695
840
  }
696
841
  }
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,
842
+ const M = nt[I] ?? nt.neutral, X = M.browInnerUp ?? 0, rt = M.browOuterUpLeft ?? 0, Ke = M.browOuterUpRight ?? 0, je = o * An, Ie = pt * Math.sin(je), ne = pt * 0.7 * Math.sin(je + 0.7), Qe = pt * 0.7 * Math.sin(je + 1.3), oe = (q) => Math.max(0, Math.min(1, q)), De = oe(X + Ie), Le = oe(rt + ne), Pe = oe(Ke + Qe), Oe = oe(De + h);
843
+ if (E(F.current, "browInnerUp", Oe), E(V.current, "browInnerUp", Oe), E($.current, "browInnerUp", Oe), E(F.current, "browOuterUpLeft", Le), E(V.current, "browOuterUpLeft", Le), E($.current, "browOuterUpLeft", Le), E(F.current, "browOuterUpRight", Pe), E(V.current, "browOuterUpRight", Pe), E($.current, "browOuterUpRight", Pe), Y.current) {
844
+ const q = T.current ? 0 : H.rotation[1];
845
+ Y.current.rotation.y = ze.MathUtils.lerp(
846
+ Y.current.rotation.y,
702
847
  q,
703
848
  0.1
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];
849
+ ), Y.current.position.set(...H.position), Y.current.scale.setScalar(H.scale), Y.current.rotation.x = H.rotation[0], Y.current.rotation.z = H.rotation[2];
705
850
  }
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);
851
+ if (T.current && b.current) {
852
+ const q = b.current.currentTime, Be = (q - x.current) * 1e3 - -150;
853
+ for (let re = 0; re < y.current.length; re++) {
854
+ const ae = y.current[re];
855
+ Be >= ae.vtime && Be < ae.vtime + ae.vduration && He(ae.viseme, ae.weight ?? 1);
711
856
  }
712
- q > he.current + 0.5 && (E(), y(!1));
857
+ q > we.current + 0.5 && (K(), j(!1));
713
858
  }
714
- }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: S }) });
859
+ }), /* @__PURE__ */ d("group", { ref: Y, children: /* @__PURE__ */ d("primitive", { object: k }) });
715
860
  }
716
861
  );
717
- function kn(d) {
718
- return d ? d.charAt(0).toUpperCase() + d.slice(1).toLowerCase() : "";
862
+ function On(m) {
863
+ return m ? m.charAt(0).toUpperCase() + m.slice(1).toLowerCase() : "";
719
864
  }
720
- function Ot(d) {
721
- return d.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
865
+ function Wt(m) {
866
+ return m.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
722
867
  }
723
- const An = ({
724
- token: d,
725
- agentToken: L,
726
- onNavigationRequested: _,
727
- avatarGender: p,
728
- presetUserDetails: w
868
+ const Cn = ({
869
+ token: m,
870
+ agentToken: T,
871
+ onNavigationRequested: y,
872
+ avatarGender: b,
873
+ presetUserDetails: x,
874
+ onAvatarReady: H
729
875
  } = {}) => {
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(
876
+ const I = m ?? T ?? "", Ue = bn(I || void 0), [se, R] = v(""), [we, K] = v(""), [j, l] = v("Ready"), [Q, g] = v(!1), [ee, k] = v(!1), [Te, Me] = v([]), [te, Se] = v(""), D = c(null), [J, Y] = v(
731
877
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
732
878
  );
733
- H(() => {
734
- const e = window.matchMedia("(max-width: 480px)"), t = () => J(e.matches);
879
+ W(() => {
880
+ const e = window.matchMedia("(max-width: 480px)"), t = () => Y(e.matches);
735
881
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
736
882
  }, []);
737
- const z = B ? 80 : 600, I = a(!1), P = a([]), _e = a(0), M = a(!1), k = a([]), C = a(null), we = a([]);
738
- a([]);
739
- const Me = a([]), ve = a(0), ce = a(0), ye = a(0), Be = a(0), ke = a(!1), [f, u] = b(
883
+ const F = J ? 80 : 600, V = c(!1), $ = c([]), Ee = c(0), U = c(!1), N = c([]), O = c(null), ve = c([]);
884
+ c([]);
885
+ const Ne = c([]), ye = c(0), de = c(0), pe = c(0), He = c(0), xe = c(!1), [p, u] = v(
740
886
  null
741
- ), i = a(null), [s, h] = b("neutral"), [W, X] = b(""), [Ze, je] = b(""), [Pe, Ae] = b("Chat with us"), [te, Je] = b(
887
+ ), s = c(null), [o, h] = v("neutral"), [M, X] = v(""), [rt, Ke] = v(""), [je, Ie] = v("Chat with us"), [ne, Qe] = v(
742
888
  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);
889
+ ), [oe, De] = v("hidden"), [Le, Pe] = v(""), Oe = c(null), q = c(oe);
890
+ q.current = oe;
891
+ const [ke, z] = v(null), Be = c(null), re = c(null), [ae, _t] = v(!1), wt = c(null), [he, Xe] = v("hidden"), [St, Vt] = v(""), it = c(he);
892
+ it.current = he;
893
+ const ie = c(""), ge = c(!1), be = c(""), vt = c(Date.now()), st = c([]), Je = c(!1), [ot, qe] = v(!1), [yt, xt] = v(!1), Re = c(null), We = bt(() => ae ? "Try again" : j === "Busy" ? "Busy" : j === "Thinking..." || j === "Processing Voice..." ? j : ne != null && ne !== "" && ne !== "none" && ne !== "<none>" ? `Enter ${On(ne)}` : he !== "hidden" || !yt ? null : Bt, [j, ne, ae, he, yt]), Lt = !ae && j !== "Busy" && j !== "Thinking..." && j !== "Processing Voice..." && (ne == null || ne === "" || ne === "none" || ne === "<none>");
894
+ W(() => {
895
+ if (he !== "hidden" || !Lt) {
896
+ xt(!1), Re.current != null && (clearTimeout(Re.current), Re.current = null);
751
897
  return;
752
898
  }
753
- return xe.current = setTimeout(() => {
754
- xe.current = null, _t(!0);
899
+ return Re.current = setTimeout(() => {
900
+ Re.current = null, xt(!0);
755
901
  }, 400), () => {
756
- xe.current != null && (clearTimeout(xe.current), xe.current = null);
902
+ Re.current != null && (clearTimeout(Re.current), Re.current = null);
757
903
  };
758
- }, [le, wt]);
759
- const Ge = Fe != null && Fe !== "";
760
- H(() => {
904
+ }, [he, Lt]);
905
+ const Ze = We != null && We !== "";
906
+ W(() => {
761
907
  const e = q.current;
762
908
  if (!(e === "exiting" || e === "entering")) {
763
909
  if (e === "hidden") {
764
- Ge && (We(Fe ?? ""), Te("entering"));
910
+ Ze && (Pe(We ?? ""), De("entering"));
765
911
  return;
766
912
  }
767
- e === "visible" && (!Ge || Fe !== Le) && (Ce.current = Ge ? Fe : null, Te("exiting"));
913
+ e === "visible" && (!Ze || We !== Le) && (Oe.current = Ze ? We : null, De("exiting"));
768
914
  }
769
915
  }, [
770
- Ge,
771
- Fe,
772
- re,
916
+ Ze,
917
+ We,
918
+ oe,
773
919
  Le
774
- ]), H(() => {
775
- if (E !== "Busy") {
776
- ne.current != null && (clearTimeout(ne.current), ne.current = null);
920
+ ]), W(() => {
921
+ if (j !== "Busy") {
922
+ re.current != null && (clearTimeout(re.current), re.current = null);
777
923
  return;
778
924
  }
779
- return ne.current = setTimeout(() => {
780
- ne.current = null, y("Ready"), ht(!0);
925
+ return re.current = setTimeout(() => {
926
+ re.current = null, l("Ready"), _t(!0);
781
927
  }, 12e3), () => {
782
- ne.current != null && (clearTimeout(ne.current), ne.current = null);
928
+ re.current != null && (clearTimeout(re.current), re.current = null);
783
929
  };
784
- }, [E]), H(() => {
785
- if (!ie) return;
786
- const e = setTimeout(() => ht(!1), 2500);
930
+ }, [j]), W(() => {
931
+ if (!ae) return;
932
+ const e = setTimeout(() => _t(!1), 2500);
787
933
  return () => clearTimeout(e);
788
- }, [ie]);
789
- const Nt = Ke(() => {
934
+ }, [ae]);
935
+ const $t = $e(() => {
790
936
  const e = q.current;
791
937
  if (e === "exiting") {
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) => {
938
+ De("hidden");
939
+ const t = Oe.current;
940
+ Oe.current = null, t != null && t !== "" && (Pe(t), De("entering"));
941
+ } else e === "entering" && De("visible");
942
+ }, []), Ht = (e) => {
797
943
  if (!e) return;
798
944
  if (e.mood != null) {
799
- const n = String(e.mood).toLowerCase();
800
- h(n);
945
+ const r = String(e.mood).toLowerCase();
946
+ h(r);
801
947
  }
802
948
  if (e.expression != null) {
803
- const n = String(e.expression).trim();
804
- X(n);
805
- const c = fn.find(
806
- (m) => m.name.toLowerCase() === n.toLowerCase()
949
+ const r = String(e.expression).trim();
950
+ X(r);
951
+ const a = Sn.find(
952
+ (f) => f.name.toLowerCase() === r.toLowerCase()
807
953
  );
808
- $(
809
- `[STREAM] Animation match for "${n}": ${c ? c.name : "NONE"}`
810
- ), je(c?.url ?? "");
954
+ B(
955
+ `[STREAM] Animation match for "${r}": ${a ? a.name : "NONE"}`
956
+ ), Ke(a?.url ?? "");
811
957
  }
812
958
  if (e.navigation != null) {
813
- const n = String(e.navigation).trim();
814
- n !== "" && (_ ? _(n) : window.open(n, "_blank"));
959
+ const r = String(e.navigation).trim();
960
+ r !== "" && (y ? y(r) : window.open(r, "_blank"));
815
961
  }
816
- const t = e.ask_for || e.lead_capture?.ask_for, r = t ? String(t).trim().toLowerCase() : "", o = r === "none" || r === "<none>";
817
- if (t && !o) {
818
- const n = r;
819
- if (w && (n === "email" && w.email || n === "name" && w.name || n === "phone" && w.phone))
962
+ const t = e.ask_for || e.lead_capture?.ask_for, n = t ? String(t).trim().toLowerCase() : "", i = n === "none" || n === "<none>";
963
+ if (t && !i) {
964
+ const r = n;
965
+ if (x && (r === "email" && x.email || r === "name" && x.name || r === "phone" && x.phone))
820
966
  return;
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"));
967
+ Qe(r || null), Ie(r === "email" ? "Enter your email" : r === "name" ? "Enter your name" : r === "phone" ? "Enter your phone number" : "Chat with us");
968
+ } else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Qe(null), je !== "Chat with us" && Ie("Chat with us"));
823
969
  e.collected, e.valid;
824
- }, Ut = (e) => {
970
+ }, jt = (e) => {
825
971
  const t = e.trim();
826
972
  if (!t) return null;
827
973
  if (t.startsWith("{"))
@@ -831,119 +977,127 @@ const An = ({
831
977
  return null;
832
978
  }
833
979
  if (t.includes(":")) {
834
- const r = t.split(":"), o = r[0].trim().toLowerCase(), n = r.slice(1).join(":").trim();
835
- return { [o]: n };
980
+ const n = t.split(":"), i = n[0].trim().toLowerCase(), r = n.slice(1).join(":").trim();
981
+ return { [i]: r };
836
982
  }
837
983
  return null;
838
- }, Bt = Ke(() => {
839
- }, []), vt = (e) => {
840
- if (De.current)
841
- e === "§" ? De.current = !1 : (Ne.current += e, he((t) => t + e));
842
- else if (e === "§") {
843
- De.current = !0;
984
+ }, Jt = $e(() => {
985
+ }, []), Ae = "§", at = () => {
986
+ for (; ie.current.includes(`
987
+ `); ) {
988
+ const e = ie.current.indexOf(`
989
+ `), t = ie.current.slice(0, e).trim();
990
+ ie.current = ie.current.slice(e + 1);
991
+ const n = jt(t);
992
+ n && Ht(n);
993
+ }
994
+ }, kt = (e) => {
995
+ if (ge.current)
996
+ if (e.includes(Ae)) {
997
+ const t = e.indexOf(Ae), n = e.slice(0, t), i = e.slice(t + Ae.length);
998
+ n && (be.current += n, K((r) => r + n)), ge.current = !1, i && (ie.current += i, at());
999
+ } else e === Ae ? ge.current = !1 : (be.current += e, K((t) => t + e));
1000
+ else if (e.includes(Ae)) {
1001
+ const t = e.indexOf(Ae), n = e.slice(0, t), i = e.slice(t + Ae.length);
1002
+ ie.current += n, at(), ge.current = !0, i && (be.current += i, K((r) => r + i));
1003
+ } else if (e === Ae) {
1004
+ ge.current = !0;
844
1005
  return;
845
1006
  } else
846
- for (pe.current += e; pe.current.includes(`
847
- `); ) {
848
- const t = pe.current.indexOf(`
849
- `), r = pe.current.slice(0, t).trim();
850
- pe.current = pe.current.slice(t + 1);
851
- const o = Ut(r);
852
- o && Ft(o);
853
- }
1007
+ ie.current += e, at();
854
1008
  };
855
- H(() => {
1009
+ W(() => {
856
1010
  (async () => {
857
1011
  if (!sessionStorage.getItem(
858
1012
  "STREAMOJI_LEADS_SESSION_LEAD_ID"
859
1013
  )) {
860
- const n = "secret", c = Math.floor(Date.now() / 1e3).toString();
1014
+ const r = "secret", a = Math.floor(Date.now() / 1e3).toString();
861
1015
  try {
862
- const m = new TextEncoder(), g = await crypto.subtle.importKey(
1016
+ const f = new TextEncoder(), _ = await crypto.subtle.importKey(
863
1017
  "raw",
864
- m.encode(n),
1018
+ f.encode(r),
865
1019
  { name: "HMAC", hash: "SHA-256" },
866
1020
  !1,
867
1021
  ["sign"]
868
- ), v = await crypto.subtle.sign(
1022
+ ), S = await crypto.subtle.sign(
869
1023
  "HMAC",
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);
1024
+ _,
1025
+ f.encode(a)
1026
+ ), w = Array.from(new Uint8Array(S)).map((A) => A.toString(16).padStart(2, "0")).join("");
1027
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w), B("[SESSION] New HMAC UID generated and saved:", w);
1028
+ } catch (f) {
1029
+ console.error("[SESSION] HMAC generation failed:", f);
1030
+ const _ = Math.random().toString(36) + Date.now().toString();
1031
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", _);
878
1032
  }
879
1033
  }
880
- const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
881
- let o = [];
882
- if (r)
1034
+ const n = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
1035
+ let i = [];
1036
+ if (n)
883
1037
  try {
884
- o = JSON.parse(r);
1038
+ i = JSON.parse(n);
885
1039
  } catch {
886
- o = [];
1040
+ i = [];
887
1041
  }
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(
1042
+ i.length === 0 && x && (x.name || x.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${x.name || ""}" , Email is "${x.email || ""}"` }], sessionStorage.setItem(
889
1043
  "STREAMOJI_LEADS_SESSION_MESSAGES",
890
- JSON.stringify(o)
891
- )) : r || sessionStorage.setItem(
1044
+ JSON.stringify(i)
1045
+ )) : n || sessionStorage.setItem(
892
1046
  "STREAMOJI_LEADS_SESSION_MESSAGES",
893
1047
  JSON.stringify([])
894
1048
  );
895
1049
  })();
896
- }, [w]), H(() => {
1050
+ }, [x]), W(() => {
897
1051
  const e = () => {
898
- gt.current = Date.now(), Ve.current && (Ve.current = !1, $e(!1), Ie([]), Y(""), he(""), me(!1));
1052
+ vt.current = Date.now(), Je.current && (Je.current = !1, qe(!1), Me([]), Se(""), K(""), k(!1));
899
1053
  };
900
1054
  window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
901
1055
  const t = setInterval(async () => {
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);
1056
+ if (Date.now() - vt.current >= 3e4 && !ee && !Q && j === "Ready" && !Je.current)
1057
+ if (Je.current = !0, st.current.length > 0)
1058
+ qe(!0), Me(st.current);
905
1059
  else
906
1060
  try {
907
- const n = `${ut}/nudgeUser`, c = {
1061
+ const r = `${Ye}/nudgeUser`, a = {
908
1062
  navigationUrl: window.location.href,
909
- token: D
910
- }, m = await fetch(n, {
1063
+ token: I
1064
+ }, f = await fetch(r, {
911
1065
  method: "POST",
912
1066
  headers: {
913
1067
  "Content-Type": "application/json"
914
1068
  },
915
- body: JSON.stringify(c)
1069
+ body: JSON.stringify(a)
916
1070
  });
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));
1071
+ if (f.ok) {
1072
+ const S = (await f.json()).nudge_questions;
1073
+ S && S.length > 0 && (B("[NUDGE] Received nudge questions from API:", S), st.current = S, qe(!0), Me(S));
920
1074
  }
921
- } catch (n) {
922
- console.error("[NUDGE] Error calling /nudgeUser:", n), Ve.current = !1;
1075
+ } catch (r) {
1076
+ console.error("[NUDGE] Error calling /nudgeUser:", r), Je.current = !1;
923
1077
  }
924
1078
  }, 1e3);
925
1079
  return () => {
926
1080
  window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(t);
927
1081
  };
928
- }, [D, U, x, E]), H(() => {
929
- if (S.length === 0) return;
930
- let e = 0, t = 0, r = !1, o = 100;
931
- const n = () => {
932
- const c = S[e];
933
- if (r) {
934
- const m = c.substring(0, t - 1);
935
- Y(m), t--, o = 50;
1082
+ }, [I, ee, Q, j]), W(() => {
1083
+ if (Te.length === 0) return;
1084
+ let e = 0, t = 0, n = !1, i = 100;
1085
+ const r = () => {
1086
+ const a = Te[e];
1087
+ if (n) {
1088
+ const f = a.substring(0, t - 1);
1089
+ Se(f), t--, i = 50;
936
1090
  } else {
937
- const m = c.substring(0, t + 1);
938
- Y(m), t++, o = 100;
1091
+ const f = a.substring(0, t + 1);
1092
+ Se(f), t++, i = 100;
939
1093
  }
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);
1094
+ !n && t === a.length ? (n = !0, i = 3e3) : n && t === 0 && (n = !1, e = (e + 1) % Te.length, i = 500), D.current = setTimeout(r, i);
941
1095
  };
942
- return n(), () => {
943
- be.current && clearTimeout(be.current);
1096
+ return r(), () => {
1097
+ D.current && clearTimeout(D.current);
944
1098
  };
945
- }, [S]);
946
- const yt = () => {
1099
+ }, [Te]);
1100
+ const Rt = () => {
947
1101
  try {
948
1102
  return JSON.parse(
949
1103
  sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
@@ -951,232 +1105,232 @@ const An = ({
951
1105
  } catch {
952
1106
  return [];
953
1107
  }
954
- }, Pt = (e) => {
1108
+ }, qt = (e) => {
955
1109
  sessionStorage.setItem(
956
1110
  "STREAMOJI_LEADS_SESSION_MESSAGES",
957
1111
  JSON.stringify(e)
958
1112
  );
959
- }, [rt, it] = b(!1), [St, st] = b(0), ue = a(null), ze = a([]), xt = a(0), [kt, Wt] = b(
1113
+ }, [ct, ut] = v(!1), [At, lt] = v(0), fe = c(null), et = c([]), Tt = c(0), [Mt, Gt] = v(
960
1114
  null
961
- ), [Vt, ot] = b(
1115
+ ), [zt, dt] = v(
962
1116
  null
963
- ), ge = a(null), Re = a(
1117
+ ), _e = c(null), Ce = c(
964
1118
  null
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) => {
1119
+ ), Ge = $e((e = !1) => {
1120
+ e && (xe.current = !0, g(!1), l("Ready")), N.current = [], $.current = [], U.current = !1, k(!1), ye.current = 0, de.current = 0, pe.current = 0, ve.current.forEach((t) => {
967
1121
  try {
968
1122
  t.stop();
969
1123
  } catch {
970
1124
  }
971
- }), Oe.current && (clearTimeout(Oe.current), Oe.current = null), Z(null), je(""), we.current = [];
972
- }, []), $t = async () => {
1125
+ }), Be.current && (clearTimeout(Be.current), Be.current = null), z(null), Ke(""), ve.current = [];
1126
+ }, []), Yt = async () => {
973
1127
  try {
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);
976
- const c = new MediaRecorder(e);
977
- ue.current = c, ze.current = [], c.ondataavailable = (m) => {
978
- m.data.size > 0 && ze.current.push(m.data);
979
- }, c.onstop = async () => {
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);
1128
+ const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, n = new t(), i = n.createMediaStreamSource(e), r = n.createAnalyser();
1129
+ r.fftSize = 64, i.connect(r), _e.current = n, Ce.current = i, dt(r);
1130
+ const a = new MediaRecorder(e);
1131
+ fe.current = a, et.current = [], a.ondataavailable = (f) => {
1132
+ f.data.size > 0 && et.current.push(f.data);
1133
+ }, a.onstop = async () => {
1134
+ const f = Date.now() - Tt.current;
1135
+ if (dt(null), Ce.current && (Ce.current.disconnect(), Ce.current = null), _e.current && _e.current.state !== "closed" && (_e.current.close(), _e.current = null), f < 1e3) {
1136
+ l("Recording too short. Hold or click longer."), g(!1);
983
1137
  return;
984
1138
  }
985
- const g = new Blob(ze.current, {
1139
+ const _ = new Blob(et.current, {
986
1140
  type: "audio/wav"
987
1141
  });
988
- await qt(g);
989
- }, xt.current = Date.now(), c.start(100), it(!0), y("Listening...");
1142
+ await Zt(_);
1143
+ }, Tt.current = Date.now(), a.start(100), ut(!0), l("Listening...");
990
1144
  } catch (e) {
991
- console.error("Error accessing microphone:", e), y("Mic Access Error");
1145
+ console.error("Error accessing microphone:", e), l("Mic Access Error");
992
1146
  }
993
- }, Ht = () => {
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"));
1147
+ }, Kt = () => {
1148
+ fe.current && fe.current.state !== "inactive" && (fe.current.stop(), fe.current.stream.getTracks().forEach((e) => e.stop()), ut(!1));
1149
+ }, Qt = () => {
1150
+ fe.current && fe.current.state !== "inactive" && (fe.current.onstop = null, fe.current.stop(), fe.current.stream.getTracks().forEach((e) => e.stop()), dt(null), Ce.current && (Ce.current.disconnect(), Ce.current = null), _e.current && _e.current.state !== "closed" && (_e.current.close(), _e.current = null), ut(!1), et.current = [], l("Ready"));
997
1151
  };
998
- H(() => {
999
- if (!U) return;
1152
+ W(() => {
1153
+ if (!ee) return;
1000
1154
  const e = () => {
1001
- const t = ye.current;
1155
+ const t = pe.current;
1002
1156
  if (t <= 0) return;
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
1157
+ const n = O.current, i = ye.current;
1158
+ if (!n) return;
1159
+ const r = n.currentTime - i, a = Math.min(Math.max(0, r), t), _ = Wt(we).trim().length;
1160
+ if (_ <= 0) return;
1161
+ const S = Math.min(
1162
+ Math.round(a / t * _),
1163
+ _
1010
1164
  );
1011
- u(v);
1165
+ u(S);
1012
1166
  };
1013
- return clearInterval(i.current ?? void 0), i.current = setInterval(e, 90), () => clearInterval(i.current ?? void 0);
1014
- }, [U, N, ye.current]), H(() => {
1167
+ return clearInterval(s.current ?? void 0), s.current = setInterval(e, 90), () => clearInterval(s.current ?? void 0);
1168
+ }, [ee, we, pe.current]), W(() => {
1015
1169
  let e;
1016
- return rt ? (st(0), e = window.setInterval(() => {
1017
- st((t) => t + 1);
1018
- }, 1e3)) : st(0), () => clearInterval(e);
1019
- }, [rt]);
1020
- const Jt = (e) => {
1021
- const t = e.numberOfChannels, r = e.length * t * 2 + 44, o = new ArrayBuffer(r), n = new DataView(o);
1022
- let c = 0;
1023
- const m = (T) => {
1024
- n.setUint16(c, T, !0), c += 2;
1025
- }, g = (T) => {
1026
- n.setUint32(c, T, !0), c += 4;
1170
+ return ct ? (lt(0), e = window.setInterval(() => {
1171
+ lt((t) => t + 1);
1172
+ }, 1e3)) : lt(0), () => clearInterval(e);
1173
+ }, [ct]);
1174
+ const Xt = (e) => {
1175
+ const t = e.numberOfChannels, n = e.length * t * 2 + 44, i = new ArrayBuffer(n), r = new DataView(i);
1176
+ let a = 0;
1177
+ const f = (w) => {
1178
+ r.setUint16(a, w, !0), a += 2;
1179
+ }, _ = (w) => {
1180
+ r.setUint32(a, w, !0), a += 4;
1027
1181
  };
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;
1182
+ _(1179011410), _(n - 8), _(1163280727), _(544501094), _(16), f(1), f(t), _(e.sampleRate), _(e.sampleRate * 2 * t), f(t * 2), f(16), _(1635017060), _(n - a - 4);
1183
+ const S = [];
1184
+ for (let w = 0; w < t; w++) S.push(e.getChannelData(w));
1185
+ let L = 0;
1186
+ for (; a < n; ) {
1187
+ for (let w = 0; w < t; w++) {
1188
+ let A = Math.max(-1, Math.min(1, S[w][L]));
1189
+ A = A < 0 ? A * 32768 : A * 32767, r.setInt16(a, A, !0), a += 2;
1036
1190
  }
1037
- A++;
1191
+ L++;
1038
1192
  }
1039
- return new Blob([o], { type: "audio/wav" });
1040
- }, at = async (e, t, r = !1) => {
1041
- if (!ke.current) {
1042
- if (I.current) {
1043
- P.current.push({
1193
+ return new Blob([i], { type: "audio/wav" });
1194
+ }, ht = async (e, t, n = !1) => {
1195
+ if (!xe.current) {
1196
+ if (V.current) {
1197
+ $.current.push({
1044
1198
  audio: e,
1045
1199
  visemes: t,
1046
- isNewSegment: r
1200
+ isNewSegment: n
1047
1201
  });
1048
1202
  return;
1049
1203
  }
1050
- I.current = !0;
1204
+ V.current = !0;
1051
1205
  try {
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);
1055
- for (let F = 0; F < c.length; F++)
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);
1206
+ const i = window.AudioContext || window.webkitAudioContext, r = O.current ?? new i();
1207
+ r.state === "suspended" && await r.resume(), O.current = r;
1208
+ const a = window.atob(e), f = new Uint8Array(a.length);
1209
+ for (let P = 0; P < a.length; P++)
1210
+ f[P] = a.charCodeAt(P);
1211
+ const _ = await r.decodeAudioData(f.buffer.slice(0));
1212
+ pe.current += _.duration;
1213
+ const S = r.currentTime;
1214
+ let L = de.current;
1215
+ const w = !U.current;
1216
+ L < S && (L = S + 0.1), de.current = L + _.duration;
1217
+ const A = r.createBufferSource();
1218
+ A.buffer = _;
1219
+ let G = Mt;
1220
+ if ((!G || G.context !== r) && (G = r.createAnalyser(), G.fftSize = 64, G.connect(r.destination), Gt(G)), A.connect(G), ve.current.push(A), xe.current) {
1221
+ ve.current = ve.current.filter((P) => P !== A);
1068
1222
  return;
1069
1223
  }
1070
- if (T) {
1071
- M.current = !0, me(!0), $(
1072
- `[AUDIO] setIsSpeaking(true) - First chunk starting at ${A.toFixed(
1224
+ if (w) {
1225
+ U.current = !0, k(!0), B(
1226
+ `[AUDIO] setIsSpeaking(true) - First chunk starting at ${L.toFixed(
1073
1227
  3
1074
1228
  )}`
1075
- ), ve.current = A;
1076
- const F = (A - v) * 1e3;
1077
- _e.current = performance.now() + F, $(
1078
- `[AUDIO] Response started. Initial startTime: ${A.toFixed(
1229
+ ), ye.current = L;
1230
+ const P = (L - S) * 1e3;
1231
+ Ee.current = performance.now() + P, B(
1232
+ `[AUDIO] Response started. Initial startTime: ${L.toFixed(
1079
1233
  3
1080
- )}, CT: ${v.toFixed(3)}`
1234
+ )}, CT: ${S.toFixed(3)}`
1081
1235
  );
1082
1236
  }
1083
- V.start(A);
1084
- const ee = (A - ve.current) * 1e3;
1085
- r && (Be.current = ee, $(
1086
- `[AUDIO] New segment detected at +${ee.toFixed(
1237
+ A.start(L);
1238
+ const Z = (L - ye.current) * 1e3;
1239
+ n && (He.current = Z, B(
1240
+ `[AUDIO] New segment detected at +${Z.toFixed(
1087
1241
  0
1088
1242
  )}ms. Resetting segment offset.`
1089
- )), t.forEach((F, se) => {
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(
1243
+ )), t.forEach((P, ce) => {
1244
+ const C = P.symbol ?? "";
1245
+ if (C) {
1246
+ const ue = En(C), me = Math.round(P.start * 1e3), Fe = Math.round((P.duration ?? 0) * 1e3), Ft = He.current + me;
1247
+ ce < 3 && B(
1248
+ `[AUDIO] Viseme "${C}": segment_relative=${me}ms, segment_offset=${He.current.toFixed(
1095
1249
  0
1096
- )}ms => vtime=${Lt}ms`
1097
- ), oe.forEach((Rt) => {
1098
- k.current.push({
1099
- viseme: Rt.v,
1100
- weight: Rt.w,
1101
- vtime: Lt,
1102
- vduration: Ee
1250
+ )}ms => vtime=${Ft}ms`
1251
+ ), ue.forEach((Ut) => {
1252
+ N.current.push({
1253
+ viseme: Ut.v,
1254
+ weight: Ut.w,
1255
+ vtime: Ft,
1256
+ vduration: Fe
1103
1257
  });
1104
1258
  });
1105
1259
  }
1106
- }), y("Speaking...");
1260
+ }), l("Speaking...");
1107
1261
  } finally {
1108
- if (I.current = !1, P.current.length > 0) {
1109
- const o = P.current.shift();
1110
- o && at(o.audio, o.visemes, o.isNewSegment);
1262
+ if (V.current = !1, $.current.length > 0) {
1263
+ const i = $.current.shift();
1264
+ i && ht(i.audio, i.visemes, i.isNewSegment);
1111
1265
  }
1112
1266
  }
1113
1267
  }
1114
- }, qt = async (e) => {
1268
+ }, Zt = async (e) => {
1115
1269
  try {
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();
1118
- c.readAsDataURL(n), c.onloadend = async () => {
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, {
1270
+ g(!0), qe(!1), be.current = "", K(""), l("Processing Voice...");
1271
+ const t = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), r = Xt(i), a = new FileReader();
1272
+ a.readAsDataURL(r), a.onloadend = async () => {
1273
+ const f = a.result.split(",")[1];
1274
+ Ge(), R(""), ie.current = "", ge.current = !1;
1275
+ const _ = `${Ye}/stt?token=${encodeURIComponent(
1276
+ I
1277
+ )}`, S = await fetch(_, {
1124
1278
  method: "POST",
1125
1279
  headers: { "Content-Type": "application/json" },
1126
1280
  body: JSON.stringify({
1127
- audio_base64: m,
1281
+ audio_base64: f,
1128
1282
  audio_format: "wav"
1129
1283
  })
1130
1284
  });
1131
- if (v.status === 429) {
1285
+ if (S.status === 429) {
1132
1286
  try {
1133
- const se = await v.text(), O = JSON.parse(se);
1134
- $("[STT] 429 agent at capacity:", O?.detail);
1287
+ const ce = await S.text(), C = JSON.parse(ce);
1288
+ B("[STT] 429 agent at capacity:", C?.detail);
1135
1289
  } catch {
1136
1290
  }
1137
- K(""), y("Busy"), R(!1);
1291
+ R(""), l("Busy"), g(!1);
1138
1292
  return;
1139
1293
  }
1140
- if (!v.ok) {
1141
- const se = await v.text();
1142
- let O = "STT Failed";
1294
+ if (!S.ok) {
1295
+ const ce = await S.text();
1296
+ let C = "STT Failed";
1143
1297
  try {
1144
- O = JSON.parse(se).error || O;
1298
+ C = JSON.parse(ce).error || C;
1145
1299
  } catch {
1146
- se && (O = se.slice(0, 200));
1300
+ ce && (C = ce.slice(0, 200));
1147
1301
  }
1148
- throw new Error(O);
1302
+ throw new Error(C);
1149
1303
  }
1150
- const A = v.body;
1151
- if ($("this is body" + A), !A) {
1152
- y("STT Failed"), R(!1);
1304
+ const L = S.body;
1305
+ if (B("this is body" + L), !L) {
1306
+ l("STT Failed"), g(!1);
1153
1307
  return;
1154
1308
  }
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) => {
1160
- switch (se) {
1309
+ const w = L.getReader();
1310
+ xe.current = !1;
1311
+ const A = new TextDecoder();
1312
+ let G = "", Z = !1;
1313
+ const P = async (ce, C) => {
1314
+ switch (ce) {
1161
1315
  case "transcript":
1162
- O.transcript != null && K(String(O.transcript));
1316
+ C.transcript != null && R(String(C.transcript));
1163
1317
  break;
1164
1318
  case "text": {
1165
- const oe = O.delta ?? O.text ?? "";
1166
- oe && vt(oe);
1319
+ const ue = C.delta ?? C.text ?? "";
1320
+ ue && kt(ue);
1167
1321
  break;
1168
1322
  }
1169
1323
  case "audio": {
1170
- const oe = O.chunk, de = O.visemes ?? [], Ee = !!O.is_new_segment;
1171
- oe && await at(oe, de, Ee);
1324
+ const ue = C.chunk, me = C.visemes ?? [], Fe = !!C.is_new_segment;
1325
+ ue && await ht(ue, me, Fe);
1172
1326
  break;
1173
1327
  }
1174
1328
  case "done": {
1175
- ee = !0, y("Ready"), R(!1);
1329
+ Z = !0, l("Ready"), g(!1);
1176
1330
  break;
1177
1331
  }
1178
1332
  case "error": {
1179
- ee = !0, y("STT Failed"), R(!1);
1333
+ Z = !0, l("STT Failed"), g(!1);
1180
1334
  break;
1181
1335
  }
1182
1336
  default:
@@ -1184,169 +1338,226 @@ const An = ({
1184
1338
  }
1185
1339
  };
1186
1340
  for (; ; ) {
1187
- const { done: se, value: O } = await T.read();
1188
- O && (G += V.decode(O, { stream: !0 }));
1189
- const oe = G.split(`
1341
+ const { done: ce, value: C } = await w.read();
1342
+ C && (G += A.decode(C, { stream: !0 }));
1343
+ const ue = G.split(`
1190
1344
 
1191
1345
  `);
1192
- G = oe.pop() ?? "";
1193
- for (const de of oe) {
1194
- const Ee = Qe(de);
1195
- Ee && await F(Ee.event, Ee.data);
1346
+ G = ue.pop() ?? "";
1347
+ for (const me of ue) {
1348
+ const Fe = Ve(me);
1349
+ Fe && await P(Fe.event, Fe.data);
1196
1350
  }
1197
- if (se) {
1351
+ if (ce) {
1198
1352
  if (G.trim()) {
1199
- const de = Qe(G.trim());
1200
- de && await F(de.event, de.data);
1353
+ const me = Ve(G.trim());
1354
+ me && await P(me.event, me.data);
1201
1355
  }
1202
- ee || (y("Ready"), R(!1));
1356
+ Z || (l("Ready"), g(!1));
1203
1357
  break;
1204
1358
  }
1205
1359
  }
1206
1360
  };
1207
1361
  } catch (t) {
1208
- console.error("Audio Submission Error:", t), y("STT Failed"), R(!1);
1362
+ console.error("Audio Submission Error:", t), l("STT Failed"), g(!1);
1209
1363
  }
1210
- }, Gt = async (e) => {
1211
- e && e.preventDefault(), $e(!1), Ne.current = "", he(""), !(!fe || x) && await zt(fe);
1212
- }, Qe = (e) => {
1364
+ }, en = async (e) => {
1365
+ e && e.preventDefault(), qe(!1), be.current = "", K(""), !(!se || Q) && await tn(se);
1366
+ }, Ve = (e) => {
1213
1367
  const t = e.split(/\r?\n/);
1214
- let r = "", o = "";
1215
- for (const c of t)
1216
- c.startsWith("event:") ? r = c.slice(6).trim() : c.startsWith("data:") && (o = c.slice(5).trim());
1217
- if (!r) return null;
1218
- let n = {};
1219
- if (o)
1368
+ let n = "", i = "";
1369
+ for (const a of t)
1370
+ a.startsWith("event:") ? n = a.slice(6).trim() : a.startsWith("data:") && (i = a.slice(5).trim());
1371
+ if (!n) return null;
1372
+ let r = {};
1373
+ if (i)
1220
1374
  try {
1221
- n = JSON.parse(o);
1375
+ r = JSON.parse(i);
1222
1376
  } catch {
1223
- n = { raw: o };
1377
+ r = { raw: i };
1224
1378
  }
1225
- return { event: r, data: n };
1226
- }, At = (e, t) => {
1379
+ return { event: n, data: r };
1380
+ }, tt = (e, t) => {
1227
1381
  switch (e) {
1228
1382
  case "connected":
1229
- pe.current = "", De.current = !1;
1383
+ ie.current = "", ge.current = !1;
1230
1384
  break;
1231
1385
  case "text": {
1232
- const r = t.delta ?? "";
1233
- r && vt(r);
1386
+ const n = t.delta ?? "";
1387
+ n && kt(n);
1234
1388
  break;
1235
1389
  }
1236
1390
  case "audio": {
1237
- const r = t.chunk, o = t.visemes ?? [];
1238
- r && at(r, o);
1391
+ const n = t.chunk, i = t.visemes ?? [];
1392
+ n && ht(n, i);
1239
1393
  break;
1240
1394
  }
1241
1395
  case "done": {
1242
- const r = yt(), o = Ne.current.trim(), n = [
1243
- ...r,
1244
- { role: "user", content: fe || "..." },
1245
- { role: "assistant", content: o }
1396
+ const n = Rt(), i = be.current.trim(), r = [
1397
+ ...n,
1398
+ { role: "user", content: se || "..." },
1399
+ { role: "assistant", content: i }
1246
1400
  ];
1247
- Pt(n), Me.current = [...k.current], y("Ready"), R(!1), K("");
1401
+ qt(r), Ne.current = [...N.current], l("Ready"), g(!1), R("");
1248
1402
  break;
1249
1403
  }
1250
1404
  case "error": {
1251
- const r = t.message ?? "Unknown error";
1252
- Ne.current = r, he(r), y("Agent Failed"), R(!1);
1405
+ const n = t.message ?? "Unknown error";
1406
+ be.current = n, K(n), l("Agent Failed"), g(!1);
1253
1407
  break;
1254
1408
  }
1255
1409
  }
1256
- }, zt = async (e) => {
1257
- R(!0), y("Thinking..."), Ne.current = "", pe.current = "", De.current = !1, Ye(), ye.current = 0, u(0);
1258
- const t = `${ut}/agent/chat?token=${encodeURIComponent(
1259
- D
1410
+ }, Et = async (e, t) => {
1411
+ g(!0), l("Thinking..."), be.current = "", ie.current = "", ge.current = !1, Ge(), pe.current = 0, u(0);
1412
+ try {
1413
+ const n = await fetch(e, {
1414
+ method: "POST",
1415
+ headers: { "Content-Type": "application/json" },
1416
+ body: JSON.stringify(t)
1417
+ });
1418
+ if (n.status === 429) {
1419
+ l("Busy"), g(!1);
1420
+ return;
1421
+ }
1422
+ if (!n.ok) throw new Error("Request failed");
1423
+ const i = n.body;
1424
+ if (!i) {
1425
+ l("Failed"), g(!1);
1426
+ return;
1427
+ }
1428
+ const r = i.getReader();
1429
+ xe.current = !1;
1430
+ const a = new TextDecoder();
1431
+ let f = "";
1432
+ for (; ; ) {
1433
+ const { done: _, value: S } = await r.read();
1434
+ S && (f += a.decode(S, { stream: !0 }));
1435
+ const L = f.split(`
1436
+
1437
+ `);
1438
+ f = L.pop() ?? "";
1439
+ for (const w of L) {
1440
+ const A = Ve(w);
1441
+ A && tt(A.event, A.data);
1442
+ }
1443
+ if (_) {
1444
+ if (f.trim()) {
1445
+ const w = Ve(f.trim());
1446
+ w && tt(w.event, w.data);
1447
+ }
1448
+ l("Ready"), g(!1);
1449
+ break;
1450
+ }
1451
+ }
1452
+ } catch (n) {
1453
+ console.error("Streaming Error:", n), l("Failed"), g(!1);
1454
+ }
1455
+ }, It = $e(async (e, t, n, i, r, a = "inworld") => {
1456
+ const f = `${Ye}/avatar_tts`;
1457
+ await Et(f, { text: e, userQuery: t, llmPrompt: n, accessKey: i, agentUrl: r, flow: a });
1458
+ }, []), Dt = $e(async (e, t, n, i, r = "inworld") => {
1459
+ const a = `${Ye}/avatar_ttsWithKnowledge`;
1460
+ await Et(a, { userQuery: e, llmPrompt: t, knowledge: n, history: i, flow: r });
1461
+ }, []), Ot = c(!1);
1462
+ W(() => {
1463
+ H && !Ot.current && (H({ avatarSpeak: It, avatarRespond: Dt }), Ot.current = !0);
1464
+ }, [H, It, Dt]);
1465
+ const tn = async (e) => {
1466
+ g(!0), l("Thinking..."), be.current = "", ie.current = "", ge.current = !1, Ge(), pe.current = 0, u(0);
1467
+ const t = `${Ye}/agent/chat?token=${encodeURIComponent(
1468
+ I
1260
1469
  )}`;
1261
1470
  try {
1262
- const r = yt();
1263
- let o = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1264
- o || (on(
1471
+ const n = Rt();
1472
+ let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1473
+ i || (mn(
1265
1474
  "[CHAT] Session UID missing at send time! Generating emergency backup."
1266
- ), o = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", o));
1267
- const n = {
1268
- history: r,
1475
+ ), i = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i));
1476
+ const r = {
1477
+ history: n,
1269
1478
  question: e,
1270
- lead_id: o
1479
+ lead_id: i
1271
1480
  };
1272
- $("[CHAT] Sending payload:", n);
1273
- const c = await fetch(t, {
1481
+ B("[CHAT] Sending payload:", r);
1482
+ const a = await fetch(t, {
1274
1483
  method: "POST",
1275
1484
  headers: {
1276
1485
  "Content-Type": "application/json"
1277
1486
  },
1278
- body: JSON.stringify(n),
1487
+ body: JSON.stringify(r),
1279
1488
  cache: "default"
1280
1489
  });
1281
- if (c.status === 429) {
1490
+ if (a.status === 429) {
1282
1491
  try {
1283
- const T = await c.json();
1284
- $("[CHAT] 429 agent at capacity:", T?.detail);
1492
+ const w = await a.json();
1493
+ B("[CHAT] 429 agent at capacity:", w?.detail);
1285
1494
  } catch {
1286
1495
  }
1287
- K(""), y("Busy"), R(!1);
1496
+ R(""), l("Busy"), g(!1);
1288
1497
  return;
1289
1498
  }
1290
- if (!c.ok)
1499
+ if (!a.ok)
1291
1500
  throw new Error("Agent request failed");
1292
- const m = c.body;
1293
- if (!m) {
1294
- y("Agent Failed"), R(!1);
1501
+ const f = a.body;
1502
+ if (!f) {
1503
+ l("Agent Failed"), g(!1);
1295
1504
  return;
1296
1505
  }
1297
- const g = m.getReader();
1298
- ke.current = !1;
1299
- const v = new TextDecoder();
1300
- let A = "";
1506
+ const _ = f.getReader();
1507
+ xe.current = !1;
1508
+ const S = new TextDecoder();
1509
+ let L = "";
1301
1510
  for (; ; ) {
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(`
1511
+ const { done: w, value: A } = await _.read();
1512
+ B(
1513
+ `[SSE] Chunk received. done=${w}, length=${A?.length || 0}`
1514
+ ), A && (L += S.decode(A, { stream: !0 }));
1515
+ const G = L.split(`
1307
1516
 
1308
1517
  `);
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));
1518
+ L = G.pop() ?? "";
1519
+ for (const Z of G) {
1520
+ B(`[SSE] Processing block: ${Z.slice(0, 50)}...`);
1521
+ const P = Ve(Z);
1522
+ P && (B(`[SSE] Event: ${P.event}`), tt(P.event, P.data));
1314
1523
  }
1315
- if (T) {
1316
- if ($("[SSE] Stream finished"), A.trim()) {
1317
- const ee = Qe(A.trim());
1318
- ee && At(ee.event, ee.data);
1524
+ if (w) {
1525
+ if (B("[SSE] Stream finished"), L.trim()) {
1526
+ const Z = Ve(L.trim());
1527
+ Z && tt(Z.event, Z.data);
1319
1528
  }
1320
- y("Ready"), R(!1), K("");
1529
+ l("Ready"), g(!1), R("");
1321
1530
  break;
1322
1531
  }
1323
1532
  }
1324
- } catch (r) {
1325
- console.error("Chat Error:", r), y("Agent Failed"), R(!1);
1533
+ } catch (n) {
1534
+ console.error("Chat Error:", n), l("Agent Failed"), g(!1);
1326
1535
  }
1327
- }, Yt = N.trim(), Tt = Ot(Yt), ct = Tt && U ? Tt.slice(
1536
+ }, nn = we.trim(), Ct = Wt(nn), ft = Ct && ee ? Ct.slice(
1328
1537
  0,
1329
- f != null && f > 0 ? f : 0
1538
+ p != null && p > 0 ? p : 0
1330
1539
  ) : "";
1331
- H(() => {
1332
- const e = et.current;
1333
- e !== "exiting" && (ct ? (Dt(ct), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
1334
- }, [ct, le]);
1335
- const Qt = Ke(() => {
1336
- const e = et.current;
1337
- e === "entering" ? qe("visible") : e === "exiting" && qe("hidden");
1540
+ W(() => {
1541
+ const e = it.current;
1542
+ e !== "exiting" && (ft ? (Vt(ft), e === "hidden" && Xe("entering")) : (e === "visible" || e === "entering") && Xe("exiting"));
1543
+ }, [ft, he]);
1544
+ const rn = $e(() => {
1545
+ const e = it.current;
1546
+ e === "entering" ? Xe("visible") : e === "exiting" && Xe("hidden");
1338
1547
  }, []);
1339
- return nn(() => {
1340
- const e = mt.current;
1548
+ dn(() => {
1549
+ const e = wt.current;
1341
1550
  e && (e.scrollTop = e.scrollHeight);
1342
- }, [pt]), /* @__PURE__ */ ae("div", { className: "avatar-widget-container", children: [
1343
- /* @__PURE__ */ ae("div", { className: "avatar-input-area", children: [
1344
- re !== "hidden" ? /* @__PURE__ */ l(
1551
+ }, [St]);
1552
+ const sn = b === "female" ? kn : Ln;
1553
+ return /* @__PURE__ */ le("div", { className: "avatar-widget-container", children: [
1554
+ /* @__PURE__ */ le("div", { className: "avatar-input-area", children: [
1555
+ oe !== "hidden" ? /* @__PURE__ */ d(
1345
1556
  "div",
1346
1557
  {
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(
1558
+ className: `avatar-thinking-tab${oe === "exiting" ? " avatar-thinking-tab--exiting" : oe === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1559
+ onAnimationEnd: $t,
1560
+ children: Le === Bt ? /* @__PURE__ */ d(
1350
1561
  "a",
1351
1562
  {
1352
1563
  href: "https://leads.streamoji.com",
@@ -1357,7 +1568,7 @@ const An = ({
1357
1568
  ) : Le
1358
1569
  }
1359
1570
  ) : null,
1360
- /* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
1571
+ /* @__PURE__ */ d("div", { className: "avatar-input-container", children: /* @__PURE__ */ d(
1361
1572
  "div",
1362
1573
  {
1363
1574
  style: {
@@ -1366,15 +1577,15 @@ const An = ({
1366
1577
  width: "100%",
1367
1578
  height: "100%"
1368
1579
  },
1369
- children: rt ? /* @__PURE__ */ ae("div", { className: "avatar-input-recording", children: [
1370
- /* @__PURE__ */ l(
1580
+ children: ct ? /* @__PURE__ */ le("div", { className: "avatar-input-recording", children: [
1581
+ /* @__PURE__ */ d(
1371
1582
  "button",
1372
1583
  {
1373
1584
  type: "button",
1374
1585
  className: "avatar-recording-cancel",
1375
- onClick: jt,
1586
+ onClick: Qt,
1376
1587
  title: "Cancel",
1377
- children: /* @__PURE__ */ ae(
1588
+ children: /* @__PURE__ */ le(
1378
1589
  "svg",
1379
1590
  {
1380
1591
  width: "18",
@@ -1387,14 +1598,14 @@ const An = ({
1387
1598
  strokeLinejoin: "round",
1388
1599
  style: { display: "block" },
1389
1600
  children: [
1390
- /* @__PURE__ */ l("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1391
- /* @__PURE__ */ l("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1601
+ /* @__PURE__ */ d("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1602
+ /* @__PURE__ */ d("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1392
1603
  ]
1393
1604
  }
1394
1605
  )
1395
1606
  }
1396
1607
  ),
1397
- /* @__PURE__ */ ae(
1608
+ /* @__PURE__ */ le(
1398
1609
  "div",
1399
1610
  {
1400
1611
  style: {
@@ -1406,8 +1617,8 @@ const An = ({
1406
1617
  minWidth: 0
1407
1618
  },
1408
1619
  children: [
1409
- /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Et, { analyser: Vt }) }),
1410
- /* @__PURE__ */ ae(
1620
+ /* @__PURE__ */ d("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ d(Nt, { analyser: zt }) }),
1621
+ /* @__PURE__ */ le(
1411
1622
  "span",
1412
1623
  {
1413
1624
  style: {
@@ -1420,23 +1631,23 @@ const An = ({
1420
1631
  fontVariantNumeric: "tabular-nums"
1421
1632
  },
1422
1633
  children: [
1423
- Math.floor(St / 60),
1634
+ Math.floor(At / 60),
1424
1635
  ":",
1425
- String(St % 60).padStart(2, "0")
1636
+ String(At % 60).padStart(2, "0")
1426
1637
  ]
1427
1638
  }
1428
1639
  )
1429
1640
  ]
1430
1641
  }
1431
1642
  ),
1432
- /* @__PURE__ */ l(
1643
+ /* @__PURE__ */ d(
1433
1644
  "button",
1434
1645
  {
1435
1646
  type: "button",
1436
1647
  className: "avatar-recording-confirm",
1437
- onClick: Ht,
1648
+ onClick: Kt,
1438
1649
  title: "Send",
1439
- children: /* @__PURE__ */ l(
1650
+ children: /* @__PURE__ */ d(
1440
1651
  "svg",
1441
1652
  {
1442
1653
  width: "18",
@@ -1448,13 +1659,13 @@ const An = ({
1448
1659
  strokeLinecap: "round",
1449
1660
  strokeLinejoin: "round",
1450
1661
  style: { display: "block" },
1451
- children: /* @__PURE__ */ l("polyline", { points: "20 6 9 17 4 12" })
1662
+ children: /* @__PURE__ */ d("polyline", { points: "20 6 9 17 4 12" })
1452
1663
  }
1453
1664
  )
1454
1665
  }
1455
1666
  )
1456
- ] }) : U && !nt ? /* @__PURE__ */ ae("div", { className: "avatar-input-speaking", children: [
1457
- /* @__PURE__ */ l(
1667
+ ] }) : ee && !ot ? /* @__PURE__ */ le("div", { className: "avatar-input-speaking", children: [
1668
+ /* @__PURE__ */ d(
1458
1669
  "div",
1459
1670
  {
1460
1671
  style: {
@@ -1464,20 +1675,20 @@ const An = ({
1464
1675
  alignItems: "center",
1465
1676
  paddingRight: "8px"
1466
1677
  },
1467
- children: /* @__PURE__ */ l(Et, { analyser: kt })
1678
+ children: /* @__PURE__ */ d(Nt, { analyser: Mt })
1468
1679
  }
1469
1680
  ),
1470
- /* @__PURE__ */ l(
1681
+ /* @__PURE__ */ d(
1471
1682
  "button",
1472
1683
  {
1473
1684
  type: "button",
1474
1685
  className: "avatar-speaking-stop",
1475
- onClick: () => Ye(!0),
1686
+ onClick: () => Ge(!0),
1476
1687
  title: "Stop",
1477
- children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
1688
+ children: /* @__PURE__ */ d("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
1478
1689
  }
1479
1690
  )
1480
- ] }) : x ? /* @__PURE__ */ l(
1691
+ ] }) : Q ? /* @__PURE__ */ d(
1481
1692
  "div",
1482
1693
  {
1483
1694
  style: {
@@ -1487,12 +1698,12 @@ const An = ({
1487
1698
  alignItems: "center",
1488
1699
  justifyContent: "center"
1489
1700
  },
1490
- children: /* @__PURE__ */ l("div", { className: "avatar-input-loader" })
1701
+ children: /* @__PURE__ */ d("div", { className: "avatar-input-loader" })
1491
1702
  }
1492
- ) : /* @__PURE__ */ ae(
1703
+ ) : /* @__PURE__ */ le(
1493
1704
  "form",
1494
1705
  {
1495
- onSubmit: Gt,
1706
+ onSubmit: en,
1496
1707
  style: {
1497
1708
  flex: 1,
1498
1709
  display: "flex",
@@ -1500,20 +1711,20 @@ const An = ({
1500
1711
  alignItems: "center"
1501
1712
  },
1502
1713
  children: [
1503
- /* @__PURE__ */ l(
1714
+ /* @__PURE__ */ d(
1504
1715
  "input",
1505
1716
  {
1506
1717
  id: "avatar-text-input",
1507
1718
  type: "text",
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",
1719
+ value: se,
1720
+ onChange: (e) => R(e.target.value),
1721
+ placeholder: j === "Busy" ? "Assisting another user" : te || "Ask me anything",
1722
+ disabled: Q || j === "Busy",
1512
1723
  autoComplete: "off",
1513
1724
  style: { width: "100%", height: "100%" }
1514
1725
  }
1515
1726
  ),
1516
- E === "Busy" ? /* @__PURE__ */ l(
1727
+ j === "Busy" ? /* @__PURE__ */ d(
1517
1728
  "button",
1518
1729
  {
1519
1730
  type: "button",
@@ -1521,7 +1732,7 @@ const An = ({
1521
1732
  disabled: !0,
1522
1733
  style: { backgroundColor: "#1e4a5e" },
1523
1734
  title: "Agent at capacity",
1524
- children: /* @__PURE__ */ l(
1735
+ children: /* @__PURE__ */ d(
1525
1736
  "svg",
1526
1737
  {
1527
1738
  width: "24",
@@ -1530,7 +1741,7 @@ const An = ({
1530
1741
  fill: "none",
1531
1742
  xmlns: "http://www.w3.org/2000/svg",
1532
1743
  "aria-hidden": "true",
1533
- children: /* @__PURE__ */ l(
1744
+ children: /* @__PURE__ */ d(
1534
1745
  "path",
1535
1746
  {
1536
1747
  d: "M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",
@@ -1540,15 +1751,15 @@ const An = ({
1540
1751
  }
1541
1752
  )
1542
1753
  }
1543
- ) : fe.trim() === "" ? /* @__PURE__ */ l(
1754
+ ) : se.trim() === "" ? /* @__PURE__ */ d(
1544
1755
  "button",
1545
1756
  {
1546
1757
  type: "button",
1547
1758
  className: "mic-button",
1548
- onClick: $t,
1549
- disabled: x,
1759
+ onClick: Yt,
1760
+ disabled: Q,
1550
1761
  style: { backgroundColor: "#1e4a5e" },
1551
- children: /* @__PURE__ */ ae(
1762
+ children: /* @__PURE__ */ le(
1552
1763
  "svg",
1553
1764
  {
1554
1765
  width: "28",
@@ -1557,14 +1768,14 @@ const An = ({
1557
1768
  fill: "none",
1558
1769
  xmlns: "http://www.w3.org/2000/svg",
1559
1770
  children: [
1560
- /* @__PURE__ */ l(
1771
+ /* @__PURE__ */ d(
1561
1772
  "path",
1562
1773
  {
1563
1774
  d: "M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z",
1564
1775
  fill: "white"
1565
1776
  }
1566
1777
  ),
1567
- /* @__PURE__ */ l(
1778
+ /* @__PURE__ */ d(
1568
1779
  "path",
1569
1780
  {
1570
1781
  d: "M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z",
@@ -1575,15 +1786,15 @@ const An = ({
1575
1786
  }
1576
1787
  )
1577
1788
  }
1578
- ) : /* @__PURE__ */ l(
1789
+ ) : /* @__PURE__ */ d(
1579
1790
  "button",
1580
1791
  {
1581
1792
  type: "submit",
1582
1793
  className: "mic-button",
1583
- disabled: x,
1794
+ disabled: Q,
1584
1795
  style: { backgroundColor: "#1e4a5e" },
1585
1796
  title: "Send",
1586
- children: /* @__PURE__ */ l(
1797
+ children: /* @__PURE__ */ d(
1587
1798
  "svg",
1588
1799
  {
1589
1800
  width: 24,
@@ -1591,7 +1802,7 @@ const An = ({
1591
1802
  viewBox: "0 0 24 24",
1592
1803
  fill: "none",
1593
1804
  "aria-hidden": "true",
1594
- children: /* @__PURE__ */ l(
1805
+ children: /* @__PURE__ */ d(
1595
1806
  "path",
1596
1807
  {
1597
1808
  d: "M19 12H5M19 12L14 17M19 12L14 7",
@@ -1611,22 +1822,22 @@ const An = ({
1611
1822
  }
1612
1823
  ) })
1613
1824
  ] }),
1614
- /* @__PURE__ */ l("div", { className: "avatar-wrapper", children: /* @__PURE__ */ ae("div", { className: "avatar-scene-wrapper", children: [
1615
- le !== "hidden" && /* @__PURE__ */ l(
1825
+ /* @__PURE__ */ d("div", { className: "avatar-wrapper", children: /* @__PURE__ */ le("div", { className: "avatar-scene-wrapper", children: [
1826
+ he !== "hidden" && /* @__PURE__ */ d(
1616
1827
  "div",
1617
1828
  {
1618
- className: `avatar-bubble${le === "entering" ? " avatar-bubble--entering" : le === "exiting" ? " avatar-bubble--exiting" : ""}`,
1619
- onAnimationEnd: Qt,
1620
- children: /* @__PURE__ */ l("div", { ref: mt, className: `avatar-bubble__content${nt ? " avatar-bubble__content--nudge" : ""}`, children: pt })
1829
+ className: `avatar-bubble${he === "entering" ? " avatar-bubble--entering" : he === "exiting" ? " avatar-bubble--exiting" : ""}`,
1830
+ onAnimationEnd: rn,
1831
+ children: /* @__PURE__ */ d("div", { ref: wt, className: `avatar-bubble__content${ot ? " avatar-bubble__content--nudge" : ""}`, children: St })
1621
1832
  }
1622
1833
  ),
1623
- /* @__PURE__ */ l(
1834
+ /* @__PURE__ */ d(
1624
1835
  "div",
1625
1836
  {
1626
1837
  className: "avatar-canvas-layer",
1627
- style: { width: z, height: z },
1628
- children: /* @__PURE__ */ ae(
1629
- Zt,
1838
+ style: { width: F, height: F },
1839
+ children: /* @__PURE__ */ le(
1840
+ cn,
1630
1841
  {
1631
1842
  shadows: !0,
1632
1843
  camera: { position: [0.2, 1.4, 3], fov: 42 },
@@ -1634,30 +1845,30 @@ const An = ({
1634
1845
  dpr: 1.8,
1635
1846
  style: { pointerEvents: "none", width: "100%", height: "100%" },
1636
1847
  children: [
1637
- /* @__PURE__ */ l(Sn, { target: gn }),
1638
- /* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
1639
- /* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1640
- /* @__PURE__ */ l(Kt, { preset: "city" }),
1641
- /* @__PURE__ */ l(rn, { fallback: null, children: j !== null && /* @__PURE__ */ l(
1642
- xn,
1848
+ /* @__PURE__ */ d(In, { target: sn }),
1849
+ /* @__PURE__ */ d("ambientLight", { intensity: 0.7 }),
1850
+ /* @__PURE__ */ d("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1851
+ /* @__PURE__ */ d(on, { preset: "city" }),
1852
+ /* @__PURE__ */ d(hn, { fallback: null, children: Ue !== null && /* @__PURE__ */ d(
1853
+ Dn,
1643
1854
  {
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,
1653
- isSpeaking: U,
1654
- nextStartTimeRef: ce,
1655
- stopPlayback: Ye,
1656
- setIsSpeaking: me,
1657
- expressionUrl: Ze,
1658
- onExpressionFinished: Bt,
1659
- isNudgeResponse: nt,
1660
- avatarGender: p
1855
+ avatarUrl: Ue,
1856
+ isPlayingRef: U,
1857
+ visemeQueueRef: N,
1858
+ audioContextRef: O,
1859
+ responseAudioStartTimeRef: ye,
1860
+ adjustments: xn,
1861
+ mood: o,
1862
+ expression: M,
1863
+ agentResponse: we,
1864
+ isSpeaking: ee,
1865
+ nextStartTimeRef: de,
1866
+ stopPlayback: Ge,
1867
+ setIsSpeaking: k,
1868
+ expressionUrl: rt,
1869
+ onExpressionFinished: Jt,
1870
+ isNudgeResponse: ot,
1871
+ avatarGender: b
1661
1872
  }
1662
1873
  ) })
1663
1874
  ]
@@ -1667,20 +1878,20 @@ const An = ({
1667
1878
  )
1668
1879
  ] }) })
1669
1880
  ] });
1670
- }, Mn = ({
1671
- token: d,
1672
- avatarGender: L,
1673
- onNavigationRequested: _,
1674
- presetUserDetails: p
1675
- }) => /* @__PURE__ */ l(
1676
- An,
1881
+ }, Wn = ({
1882
+ token: m,
1883
+ avatarGender: T,
1884
+ onNavigationRequested: y,
1885
+ presetUserDetails: b
1886
+ }) => /* @__PURE__ */ d(
1887
+ Cn,
1677
1888
  {
1678
- token: d,
1679
- onNavigationRequested: _,
1680
- avatarGender: L,
1681
- presetUserDetails: p
1889
+ token: m,
1890
+ onNavigationRequested: y,
1891
+ avatarGender: T,
1892
+ presetUserDetails: b
1682
1893
  }
1683
1894
  );
1684
1895
  export {
1685
- Mn as AvatarWidget
1896
+ Wn as AvatarWidget
1686
1897
  };