@zeroweight/react 0.2.33 → 0.2.35

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,21 +1,24 @@
1
- import { useMemo as be, useRef as k, useState as x, useCallback as S, useEffect as h } from "react";
2
- import { ZeroWeightRenderer as Se, ActionQueue as xe, VoiceActivityDetector as ke } from "@zeroweight/renderer";
3
- import { jsxs as w, jsx as r, Fragment as j } from "react/jsx-runtime";
4
- import { useVoiceAssistant as we, useLocalParticipant as Ae, useIsSpeaking as Te, useDataChannel as Ie, RoomAudioRenderer as Ce, LiveKitRoom as Re } from "@livekit/components-react";
1
+ import { useMemo as be, useRef as x, useState as k, useCallback as S, useEffect as h } from "react";
2
+ import { ZeroWeightRenderer as Se, ActionQueue as ke, VoiceActivityDetector as xe } from "@zeroweight/renderer";
3
+ import { jsxs as w, jsx as i, Fragment as j } from "react/jsx-runtime";
4
+ import { useVoiceAssistant as we, useLocalParticipant as Ae, useIsSpeaking as Te, useDataChannel as Ie, RoomAudioRenderer as Me, LiveKitRoom as Ce } from "@livekit/components-react";
5
5
  import "@livekit/components-styles";
6
- import { Loader2 as J, MicOff as Me, Mic as Ee, Power as Le, Activity as De } from "lucide-react";
7
- const ze = 3e4, Pe = 120, Fe = "wss://prod-project-pazuyq69.livekit.cloud", ne = "https://api.zeroweight.ai/api/v1";
8
- function Ue(v) {
6
+ import { Loader2 as J, MicOff as Re, Mic as Ee, Power as Le, Activity as De } from "lucide-react";
7
+ const ze = 3e4, Ue = 120, Pe = "wss://prod-project-pazuyq69.livekit.cloud", ne = "https://api.zeroweight.ai/api/v1", $e = () => {
8
+ const l = ["Happy", "Swift", "Bright", "Cool", "Smart"], a = ["User", "Guest", "Visitor", "Agent", "Caller"], e = Math.floor(Math.random() * 1e3);
9
+ return `${l[Math.floor(Math.random() * l.length)]}${a[Math.floor(Math.random() * a.length)]}${e}`;
10
+ };
11
+ function Fe(l) {
9
12
  const {
10
13
  avatarId: a,
11
14
  apiKey: e = null,
12
- api: u,
13
- turnOffMicWhenAISpeaking: d = !0,
14
- livekitUrl: A = Fe,
15
- sessionDuration: p = Pe,
16
- inactivityTimeout: C = ze
17
- } = v, D = A, y = be(() => {
18
- if (u) return u;
15
+ api: d,
16
+ turnOffMicWhenAISpeaking: v = !0,
17
+ livekitUrl: A = Pe,
18
+ sessionDuration: f = Ue,
19
+ inactivityTimeout: M = ze
20
+ } = l, D = A, y = be(() => {
21
+ if (d) return d;
19
22
  const t = e ? { "X-ZW-Api-Key": e } : void 0;
20
23
  return {
21
24
  getBundle: async (g) => {
@@ -34,7 +37,7 @@ function Ue(v) {
34
37
  getLiveKitToken: async (g) => {
35
38
  const T = new URLSearchParams({
36
39
  avatar_id: g,
37
- name: "alice"
40
+ name: $e()
38
41
  }), c = await fetch(
39
42
  `${ne}/livekit/getToken?${T.toString()}`,
40
43
  { headers: t }
@@ -46,13 +49,13 @@ function Ue(v) {
46
49
  return c.json();
47
50
  }
48
51
  };
49
- }, [u, e]), m = k(null), E = k(null), i = k(null), l = k(null), [b, R] = x("idle"), [f, P] = x(null), [s, U] = x(
52
+ }, [d, e]), m = x(null), E = x(null), r = x(null), u = x(null), [b, C] = k("idle"), [p, U] = k(null), [s, $] = k(
50
53
  /* @__PURE__ */ new Set(["listening"])
51
- ), [n, o] = x({
54
+ ), [n, o] = k({
52
55
  listening: { kind: "looped" },
53
56
  speaking: { kind: "looped" }
54
- }), [O, z] = x(!1), [F, $] = x(null), [W, K] = x(!1), [N, Z] = x(!1), [ae, V] = x(p), M = k(null), B = k(() => {
55
- }), [oe, X] = x(!1), [se, Y] = x(0.8), L = k(null), H = b === "ready", G = S(() => {
57
+ }), [_, z] = k(!1), [P, O] = k(null), [N, K] = k(!1), [W, Z] = k(!1), [ae, V] = k(f), R = x(null), B = x(() => {
58
+ }), [oe, G] = k(!1), [se, X] = k(0.8), L = x(null), H = b === "ready", Y = S(() => {
56
59
  const t = m.current;
57
60
  if (!t) return null;
58
61
  let g = t.querySelector("canvas");
@@ -61,20 +64,20 @@ function Ue(v) {
61
64
  h(() => {
62
65
  let t = !1;
63
66
  return (async () => {
64
- const T = G();
67
+ const T = Y();
65
68
  if (!T) return;
66
69
  const c = new Se();
67
- i.current = c;
68
- const q = new xe((I, _) => {
69
- c.play(I, _);
70
+ r.current = c;
71
+ const q = new ke((I, F) => {
72
+ c.play(I, F);
70
73
  });
71
- l.current = q, c.on("stateChanged", (I) => {
72
- t || R(I);
73
- }), c.on("dimensions", (I, _) => {
74
- t || P({ width: I, height: _ });
74
+ u.current = q, c.on("stateChanged", (I) => {
75
+ t || C(I);
76
+ }), c.on("dimensions", (I, F) => {
77
+ t || U({ width: I, height: F });
75
78
  }), c.on("actionLoaded", (I) => {
76
- t || U((_) => {
77
- const te = new Set(_);
79
+ t || $((F) => {
80
+ const te = new Set(F);
78
81
  return te.add(I), te;
79
82
  });
80
83
  }), c.on("allActionsLoaded", () => {
@@ -91,44 +94,44 @@ function Ue(v) {
91
94
  console.error("[useAvatarSession] Init failed:", I);
92
95
  }
93
96
  })(), () => {
94
- t = !0, i.current?.destroy(), i.current = null, l.current = null;
97
+ t = !0, r.current?.destroy(), r.current = null, u.current = null;
95
98
  };
96
- }, [a, G, y]);
97
- const ee = k(!1);
99
+ }, [a, Y, y]);
100
+ const ee = x(!1);
98
101
  h(() => {
99
- H && i.current && s.has("wave_hand") && !ee.current && (i.current.play("wave_hand", "listening"), ee.current = !0);
102
+ H && r.current && s.has("wave_hand") && !ee.current && (r.current.play("wave_hand", "listening"), ee.current = !0);
100
103
  }, [H, s]);
101
104
  const ce = S(async () => {
102
- if (!(W || N)) {
105
+ if (!(N || W)) {
103
106
  K(!0);
104
107
  try {
105
108
  await navigator.mediaDevices.getUserMedia({ audio: !0 });
106
109
  const t = await y.getLiveKitToken(a);
107
- $(t.token);
110
+ O(t.token);
108
111
  } catch (t) {
109
112
  console.error("[useAvatarSession] Failed to connect:", t), K(!1);
110
113
  }
111
114
  }
112
- }, [W, N, a, y]), Q = S(() => {
113
- M.current && (clearInterval(M.current), M.current = null), V(p), L.current && (clearTimeout(L.current), L.current = null), $(null), Z(!1), K(!1), l.current?.forceListening();
114
- }, [p]);
115
+ }, [N, W, a, y]), Q = S(() => {
116
+ R.current && (clearInterval(R.current), R.current = null), V(f), L.current && (clearTimeout(L.current), L.current = null), O(null), Z(!1), K(!1), u.current?.forceListening();
117
+ }, [f]);
115
118
  h(() => {
116
119
  B.current = Q;
117
120
  }, [Q]);
118
121
  const le = S(() => {
119
122
  Z(!0), K(!1);
120
123
  }, []), ue = S(() => {
121
- M.current && clearInterval(M.current), V(p), M.current = setInterval(() => {
122
- V((t) => t <= 1 ? (clearInterval(M.current), M.current = null, setTimeout(() => B.current(), 0), 0) : t - 1);
124
+ R.current && clearInterval(R.current), V(f), R.current = setInterval(() => {
125
+ V((t) => t <= 1 ? (clearInterval(R.current), R.current = null, setTimeout(() => B.current(), 0), 0) : t - 1);
123
126
  }, 1e3);
124
- }, [p]), de = S((t) => {
127
+ }, [f]), de = S((t) => {
125
128
  const g = Math.floor(t / 60).toString().padStart(2, "0"), T = (t % 60).toString().padStart(2, "0");
126
129
  return `${g}:${T}`;
127
130
  }, []);
128
131
  h(() => () => {
129
- M.current && clearInterval(M.current);
132
+ R.current && clearInterval(R.current);
130
133
  }, []);
131
- const pe = S(
134
+ const fe = S(
132
135
  (t) => {
133
136
  if (!t) {
134
137
  L.current && (clearTimeout(L.current), L.current = null);
@@ -136,44 +139,44 @@ function Ue(v) {
136
139
  }
137
140
  L.current || (L.current = setTimeout(() => {
138
141
  L.current = null, B.current();
139
- }, C));
142
+ }, M));
140
143
  },
141
- [C]
142
- ), fe = S(() => {
143
- X((t) => !t);
144
+ [M]
145
+ ), pe = S(() => {
146
+ G((t) => !t);
144
147
  }, []), ge = S((t) => {
145
- X(t);
148
+ G(t);
146
149
  }, []), he = S((t) => {
147
- Y(t);
150
+ X(t);
148
151
  }, []), me = S(() => {
149
- Y((t) => t > 0 ? 0 : 1);
152
+ X((t) => t > 0 ? 0 : 1);
150
153
  }, []), ve = S(() => {
151
- i.current?.interrupt();
154
+ r.current?.interrupt();
152
155
  }, []), ye = S((t) => {
153
- i.current?.play(t, "listening");
156
+ r.current?.play(t, "listening");
154
157
  }, []);
155
158
  return {
156
159
  containerRef: m,
157
- renderer: i.current,
158
- actionQueue: l.current,
160
+ renderer: r.current,
161
+ actionQueue: u.current,
159
162
  rendererState: b,
160
- avatarDimensions: f,
163
+ avatarDimensions: p,
161
164
  loadedActions: s,
162
165
  actionMetadata: n,
163
- isLoadingActions: O,
166
+ isLoadingActions: _,
164
167
  isEngineReady: H,
165
- token: F,
166
- isConnecting: W,
167
- isConnected: N,
168
+ token: P,
169
+ isConnecting: N,
170
+ isConnected: W,
168
171
  livekitUrl: D,
169
172
  timeRemaining: ae,
170
173
  formatTime: de,
171
174
  micMuted: oe,
172
175
  volume: se,
173
- turnOffMicWhenAISpeaking: d,
176
+ turnOffMicWhenAISpeaking: v,
174
177
  connect: ce,
175
178
  disconnect: Q,
176
- toggleMic: fe,
179
+ toggleMic: pe,
177
180
  setMicMuted: ge,
178
181
  setVolume: he,
179
182
  toggleVolume: me,
@@ -181,11 +184,11 @@ function Ue(v) {
181
184
  runAction: ye,
182
185
  startSessionTimer: ue,
183
186
  markConnected: le,
184
- setInactivityActive: pe
187
+ setInactivityActive: fe
185
188
  };
186
189
  }
187
- const _e = ({
188
- session: v,
190
+ const je = ({
191
+ session: l,
189
192
  style: a,
190
193
  loadingContent: e
191
194
  }) => /* @__PURE__ */ w(
@@ -205,7 +208,7 @@ const _e = ({
205
208
  ...a
206
209
  },
207
210
  children: [
208
- /* @__PURE__ */ r("style", { children: `
211
+ /* @__PURE__ */ i("style", { children: `
209
212
  @keyframes zwr-spin {
210
213
  from { transform: rotate(0deg); }
211
214
  to { transform: rotate(360deg); }
@@ -215,17 +218,17 @@ const _e = ({
215
218
  50% { opacity: 0.5; }
216
219
  }
217
220
  ` }),
218
- /* @__PURE__ */ r(
221
+ /* @__PURE__ */ i(
219
222
  "div",
220
223
  {
221
- ref: v.containerRef,
224
+ ref: l.containerRef,
222
225
  style: {
223
226
  position: "relative",
224
227
  width: "100%",
225
228
  height: "100%",
226
229
  transition: "all 0.5s ease-in-out"
227
230
  },
228
- children: !v.isEngineReady && /* @__PURE__ */ r(
231
+ children: !l.isEngineReady && /* @__PURE__ */ i(
229
232
  "div",
230
233
  {
231
234
  style: {
@@ -248,7 +251,7 @@ const _e = ({
248
251
  gap: 16
249
252
  },
250
253
  children: [
251
- /* @__PURE__ */ r(
254
+ /* @__PURE__ */ i(
252
255
  J,
253
256
  {
254
257
  style: {
@@ -259,7 +262,7 @@ const _e = ({
259
262
  }
260
263
  }
261
264
  ),
262
- /* @__PURE__ */ r(
265
+ /* @__PURE__ */ i(
263
266
  "div",
264
267
  {
265
268
  style: {
@@ -307,20 +310,20 @@ const _e = ({
307
310
  transition: "all 0.3s",
308
311
  border: "none",
309
312
  cursor: "pointer"
310
- }, je = ({
311
- session: v,
313
+ }, _e = ({
314
+ session: l,
312
315
  style: a
313
316
  }) => {
314
317
  const {
315
318
  micMuted: e,
316
- toggleMic: u,
317
- isConnected: d,
319
+ toggleMic: d,
320
+ isConnected: v,
318
321
  isConnecting: A,
319
- isEngineReady: p,
320
- loadedActions: C,
322
+ isEngineReady: f,
323
+ loadedActions: M,
321
324
  connect: D,
322
325
  disconnect: y
323
- } = v, [m, E] = x(!1), [i, l] = x(!1), b = p && C.has("listening") && C.has("speaking"), R = e ? {
326
+ } = l, [m, E] = k(!1), [r, u] = k(!1), b = f && M.has("listening") && M.has("speaking"), C = e ? {
324
327
  ...re,
325
328
  background: "rgba(239,68,68,0.1)",
326
329
  color: "#f87171",
@@ -331,17 +334,17 @@ const _e = ({
331
334
  background: m ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
332
335
  color: "#fff",
333
336
  boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
334
- }, f = d ? {
337
+ }, p = v ? {
335
338
  ...ie,
336
- background: i ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
339
+ background: r ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
337
340
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
338
341
  } : {
339
342
  ...ie,
340
343
  background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
341
344
  boxShadow: "0 0 30px rgba(236,72,153,0.3)",
342
- opacity: i ? 0.9 : 1
345
+ opacity: r ? 0.9 : 1
343
346
  };
344
- return (A || !b) && (f.opacity = 0.5, f.cursor = "not-allowed"), /* @__PURE__ */ w(
347
+ return (A || !b) && (p.opacity = 0.5, p.cursor = "not-allowed"), /* @__PURE__ */ w(
345
348
  "div",
346
349
  {
347
350
  style: {
@@ -355,7 +358,7 @@ const _e = ({
355
358
  ...a
356
359
  },
357
360
  children: [
358
- /* @__PURE__ */ r("style", { children: `
361
+ /* @__PURE__ */ i("style", { children: `
359
362
  @keyframes zwr-spin {
360
363
  from { transform: rotate(0deg); }
361
364
  to { transform: rotate(360deg); }
@@ -374,39 +377,39 @@ const _e = ({
374
377
  pointerEvents: "auto"
375
378
  },
376
379
  children: [
377
- /* @__PURE__ */ r(
380
+ /* @__PURE__ */ i(
378
381
  "button",
379
382
  {
380
383
  type: "button",
381
- onClick: u,
384
+ onClick: d,
382
385
  onMouseEnter: () => E(!0),
383
386
  onMouseLeave: () => E(!1),
384
- style: R,
387
+ style: C,
385
388
  title: e ? "Unmute mic" : "Mute mic",
386
- children: e ? /* @__PURE__ */ r(Me, { size: 24 }) : /* @__PURE__ */ r(Ee, { size: 24 })
389
+ children: e ? /* @__PURE__ */ i(Re, { size: 24 }) : /* @__PURE__ */ i(Ee, { size: 24 })
387
390
  }
388
391
  ),
389
- /* @__PURE__ */ r(
392
+ /* @__PURE__ */ i(
390
393
  "button",
391
394
  {
392
395
  type: "button",
393
- onClick: d ? y : D,
394
- onMouseEnter: () => l(!0),
395
- onMouseLeave: () => l(!1),
396
- disabled: !d && (A || !b),
397
- style: f,
396
+ onClick: v ? y : D,
397
+ onMouseEnter: () => u(!0),
398
+ onMouseLeave: () => u(!1),
399
+ disabled: !v && (A || !b),
400
+ style: p,
398
401
  children: A ? /* @__PURE__ */ w(j, { children: [
399
- /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
400
- /* @__PURE__ */ r("span", { children: "Connecting..." })
401
- ] }) : !d && !b ? /* @__PURE__ */ w(j, { children: [
402
- /* @__PURE__ */ r(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
403
- /* @__PURE__ */ r("span", { children: "Loading Avatar..." })
404
- ] }) : d ? /* @__PURE__ */ w(j, { children: [
405
- /* @__PURE__ */ r(Le, { size: 20 }),
406
- /* @__PURE__ */ r("span", { children: "End Session" })
402
+ /* @__PURE__ */ i(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
403
+ /* @__PURE__ */ i("span", { children: "Connecting..." })
404
+ ] }) : !v && !b ? /* @__PURE__ */ w(j, { children: [
405
+ /* @__PURE__ */ i(J, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
406
+ /* @__PURE__ */ i("span", { children: "Loading Avatar..." })
407
+ ] }) : v ? /* @__PURE__ */ w(j, { children: [
408
+ /* @__PURE__ */ i(Le, { size: 20 }),
409
+ /* @__PURE__ */ i("span", { children: "End Session" })
407
410
  ] }) : /* @__PURE__ */ w(j, { children: [
408
- /* @__PURE__ */ r(De, { size: 20 }),
409
- /* @__PURE__ */ r("span", { children: "Start Session" })
411
+ /* @__PURE__ */ i(De, { size: 20 }),
412
+ /* @__PURE__ */ i("span", { children: "Start Session" })
410
413
  ] })
411
414
  }
412
415
  )
@@ -417,9 +420,9 @@ const _e = ({
417
420
  }
418
421
  );
419
422
  }, Oe = ({
420
- session: v
423
+ session: l
421
424
  }) => {
422
- const { isConnected: a, timeRemaining: e, formatTime: u } = v, d = a && e <= 30, A = a && e > 30 && e <= 60, p = {
425
+ const { isConnected: a, timeRemaining: e, formatTime: d } = l, v = a && e <= 30, A = a && e > 30 && e <= 60, f = {
423
426
  display: "flex",
424
427
  alignItems: "center",
425
428
  gap: 8,
@@ -429,7 +432,7 @@ const _e = ({
429
432
  border: "1px solid",
430
433
  pointerEvents: "auto",
431
434
  transition: "all 0.3s",
432
- ...d ? {
435
+ ...v ? {
433
436
  background: "rgba(239,68,68,0.3)",
434
437
  borderColor: "rgba(239,68,68,0.4)",
435
438
  boxShadow: "0 0 15px rgba(239,68,68,0.3)",
@@ -445,14 +448,14 @@ const _e = ({
445
448
  }
446
449
  };
447
450
  return /* @__PURE__ */ w(j, { children: [
448
- /* @__PURE__ */ r("style", { children: `
451
+ /* @__PURE__ */ i("style", { children: `
449
452
  @keyframes zwr-pulse {
450
453
  0%, 100% { opacity: 1; }
451
454
  50% { opacity: 0.5; }
452
455
  }
453
456
  ` }),
454
- /* @__PURE__ */ w("div", { style: p, children: [
455
- /* @__PURE__ */ r(
457
+ /* @__PURE__ */ w("div", { style: f, children: [
458
+ /* @__PURE__ */ i(
456
459
  "div",
457
460
  {
458
461
  style: {
@@ -468,7 +471,7 @@ const _e = ({
468
471
  }
469
472
  }
470
473
  ),
471
- /* @__PURE__ */ r(
474
+ /* @__PURE__ */ i(
472
475
  "span",
473
476
  {
474
477
  style: {
@@ -478,88 +481,88 @@ const _e = ({
478
481
  color: "rgba(255,255,255,0.7)",
479
482
  textTransform: "uppercase"
480
483
  },
481
- children: a ? `Online ${u(e)}` : "Offline"
484
+ children: a ? `Online ${d(e)}` : "Offline"
482
485
  }
483
486
  )
484
487
  ] })
485
488
  ] });
486
- }, $e = ({
487
- session: v
489
+ }, Ke = ({
490
+ session: l
488
491
  }) => {
489
492
  const {
490
493
  renderer: a,
491
494
  actionQueue: e,
492
- micMuted: u,
493
- volume: d,
495
+ micMuted: d,
496
+ volume: v,
494
497
  setInactivityActive: A,
495
- loadedActions: p,
496
- token: C,
498
+ loadedActions: f,
499
+ token: M,
497
500
  isConnected: D
498
- } = v, { turnOffMicWhenAISpeaking: y, setMicMuted: m } = v, E = k(!1), { state: i, audioTrack: l } = we(), b = Ae(), R = Te(b.localParticipant), f = k(null), P = k(p);
501
+ } = l, { turnOffMicWhenAISpeaking: y, setMicMuted: m } = l, E = x(!1), { state: r, audioTrack: u } = we(), b = Ae(), C = Te(b.localParticipant), p = x(null), U = x(f);
499
502
  h(() => {
500
- P.current = p;
501
- }, [p]), h(() => {
503
+ U.current = f;
504
+ }, [f]), h(() => {
502
505
  const n = b.localParticipant;
503
506
  if (!a || !n) return;
504
507
  const o = new TextEncoder();
505
508
  return a.onOneshotComplete((z) => {
506
- const F = o.encode(
509
+ const P = o.encode(
507
510
  JSON.stringify({
508
511
  type: "ACTION_FINISHED",
509
512
  action: z
510
513
  })
511
514
  );
512
- n.publishData(F, {
515
+ n.publishData(P, {
513
516
  reliable: !0
514
- }).catch(($) => {
515
- console.error("[LiveKitAvatarProvider] Failed to publish action completion:", $);
517
+ }).catch((O) => {
518
+ console.error("[LiveKitAvatarProvider] Failed to publish action completion:", O);
516
519
  });
517
520
  });
518
521
  }, [a, b.localParticipant]), h(() => {
519
522
  if (!e) return;
520
- const n = new ke({
523
+ const n = new xe({
521
524
  threshold: 8e-3,
522
525
  analyseIntervalMs: 30,
523
526
  speechStartFrames: 1,
524
527
  speechPauseFrames: 30,
525
528
  turnEndFrames: 50
526
529
  });
527
- return f.current = n, n.on("speechStart", () => {
530
+ return p.current = n, n.on("speechStart", () => {
528
531
  e.setTurnActive(!0), e.setSpeechState("speaking");
529
532
  }), n.on("turnEnd", () => {
530
533
  e.setTurnActive(!1);
531
534
  }), () => {
532
- n.stop(), f.current = null;
535
+ n.stop(), p.current = null;
533
536
  };
534
537
  }, [e]), h(() => {
535
- const n = f.current;
538
+ const n = p.current;
536
539
  if (n)
537
- if (l?.publication?.track) {
538
- const o = l.publication.track.mediaStreamTrack;
540
+ if (u?.publication?.track) {
541
+ const o = u.publication.track.mediaStreamTrack;
539
542
  o && n.start(o);
540
543
  } else
541
544
  n.stop();
542
- }, [l?.publication?.track]);
543
- const s = k(null), U = k(!1);
545
+ }, [u?.publication?.track]);
546
+ const s = x(null), $ = x(!1);
544
547
  return h(() => {
545
548
  if (!e) return;
546
- const n = i;
547
- if (!C || !D || n === "disconnected") {
548
- s.current && (clearTimeout(s.current), s.current = null), f.current?.endTurn(), e.forceListening();
549
+ const n = r;
550
+ if (!M || !D || n === "disconnected") {
551
+ s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.forceListening();
549
552
  return;
550
553
  }
551
- n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null), f.current?.endTurn(), e.setTurnActive(!1)) : n === "thinking" && (s.current || (s.current = setTimeout(() => {
552
- s.current = null, f.current?.endTurn(), e.setTurnActive(!1);
554
+ n === "speaking" ? (s.current && (clearTimeout(s.current), s.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (s.current && (clearTimeout(s.current), s.current = null), p.current?.endTurn(), e.setTurnActive(!1)) : n === "thinking" && (s.current || (s.current = setTimeout(() => {
555
+ s.current = null, p.current?.endTurn(), e.setTurnActive(!1);
553
556
  }, 500)));
554
- }, [e, D, i, C]), h(() => {
555
- const n = i === "speaking";
557
+ }, [e, D, r, M]), h(() => {
558
+ const n = r === "speaking";
556
559
  if (!y) {
557
- U.current = n;
560
+ $.current = n;
558
561
  return;
559
562
  }
560
- const o = U.current;
561
- !o && n ? u || m(!0) : o && !n && u && m(!1), U.current = n;
562
- }, [u, m, i, y]), h(() => {
563
+ const o = $.current;
564
+ !o && n ? d || m(!0) : o && !n && d && m(!1), $.current = n;
565
+ }, [d, m, r, y]), h(() => {
563
566
  if (!y || !e) return;
564
567
  const n = (o) => {
565
568
  o || m(!1);
@@ -571,57 +574,57 @@ const _e = ({
571
574
  s.current && clearTimeout(s.current);
572
575
  }, []), Ie((n) => {
573
576
  try {
574
- const O = new TextDecoder().decode(n.payload), z = JSON.parse(O);
577
+ const _ = new TextDecoder().decode(n.payload), z = JSON.parse(_);
575
578
  if (z.type === "AVATAR_UPDATE") {
576
- const F = z.action;
577
- if (!P.current.has(F))
579
+ const P = z.action;
580
+ if (!U.current.has(P))
578
581
  return;
579
- e?.dispatch(F);
582
+ e?.dispatch(P);
580
583
  }
581
584
  } catch (o) {
582
585
  console.error("[LiveKitAvatarProvider] Failed to parse data message:", o);
583
586
  }
584
587
  }), h(() => {
585
- A(!(i === "speaking") && !R);
586
- }, [R, A, i]), h(() => {
588
+ A(!(r === "speaking") && !C);
589
+ }, [C, A, r]), h(() => {
587
590
  if (!e) return;
588
- const n = !!l;
589
- (!n || i === "disconnected") && (f.current?.endTurn(), e.forceListening()), E.current = n;
590
- }, [l, i, e]), h(() => {
591
+ const n = !!u;
592
+ (!n || r === "disconnected") && (p.current?.endTurn(), e.forceListening()), E.current = n;
593
+ }, [u, r, e]), h(() => {
591
594
  const n = b.localParticipant;
592
- n && n.setMicrophoneEnabled(!u).catch((o) => {
595
+ n && n.setMicrophoneEnabled(!d).catch((o) => {
593
596
  console.error("[LiveKitAvatarProvider] Failed to set mic state:", o);
594
597
  });
595
- }, [u, b.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Ce, { volume: d }) });
596
- }, Qe = ({
597
- avatarId: v,
598
+ }, [d, b.localParticipant]), /* @__PURE__ */ i("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ i(Me, { volume: v }) });
599
+ }, qe = ({
600
+ avatarId: l,
598
601
  apiKey: a,
599
602
  api: e,
600
- turnOffMicWhenAISpeaking: u,
601
- livekitUrl: d,
603
+ turnOffMicWhenAISpeaking: d,
604
+ livekitUrl: v,
602
605
  sessionDuration: A,
603
- inactivityTimeout: p,
604
- style: C,
606
+ inactivityTimeout: f,
607
+ style: M,
605
608
  className: D,
606
609
  loadingContent: y,
607
610
  customControls: m,
608
611
  customStatusBadge: E
609
612
  }) => {
610
- const i = Ue({
611
- avatarId: v,
613
+ const r = Fe({
614
+ avatarId: l,
612
615
  apiKey: a,
613
616
  api: e,
614
- turnOffMicWhenAISpeaking: u,
615
- livekitUrl: d,
617
+ turnOffMicWhenAISpeaking: d,
618
+ livekitUrl: v,
616
619
  sessionDuration: A,
617
- inactivityTimeout: p
620
+ inactivityTimeout: f
618
621
  }), {
619
- token: l,
622
+ token: u,
620
623
  isConnected: b,
621
- avatarDimensions: R,
622
- disconnect: f,
623
- startSessionTimer: P
624
- } = i;
624
+ avatarDimensions: C,
625
+ disconnect: p,
626
+ startSessionTimer: U
627
+ } = r;
625
628
  return /* @__PURE__ */ w(
626
629
  "section",
627
630
  {
@@ -639,11 +642,11 @@ const _e = ({
639
642
  height: "80vh",
640
643
  width: "auto",
641
644
  maxWidth: "100%",
642
- aspectRatio: R ? `${R.width} / ${R.height}` : "3 / 4",
643
- ...C
645
+ aspectRatio: C ? `${C.width} / ${C.height}` : "3 / 4",
646
+ ...M
644
647
  },
645
648
  children: [
646
- /* @__PURE__ */ r(_e, { session: i, loadingContent: y }),
649
+ /* @__PURE__ */ i(je, { session: r, loadingContent: y }),
647
650
  /* @__PURE__ */ w(
648
651
  "div",
649
652
  {
@@ -668,28 +671,28 @@ const _e = ({
668
671
  justifyContent: "space-between"
669
672
  },
670
673
  children: [
671
- E ? E(i) : /* @__PURE__ */ r(Oe, { session: i }),
672
- /* @__PURE__ */ r("div", {})
674
+ E ? E(r) : /* @__PURE__ */ i(Oe, { session: r }),
675
+ /* @__PURE__ */ i("div", {})
673
676
  ]
674
677
  }
675
678
  ),
676
- m ? m(i) : /* @__PURE__ */ r(je, { session: i })
679
+ m ? m(r) : /* @__PURE__ */ i(_e, { session: r })
677
680
  ]
678
681
  }
679
682
  ),
680
- /* @__PURE__ */ r("div", { style: { display: "none" }, children: l && d && /* @__PURE__ */ r(
681
- Re,
683
+ /* @__PURE__ */ i("div", { style: { display: "none" }, children: u && r.livekitUrl && /* @__PURE__ */ i(
684
+ Ce,
682
685
  {
683
- serverUrl: d,
684
- token: l,
686
+ serverUrl: r.livekitUrl,
687
+ token: u,
685
688
  connect: !0,
686
689
  video: !1,
687
690
  audio: !0,
688
691
  onConnected: () => {
689
- i.markConnected(), P();
692
+ r.markConnected(), U();
690
693
  },
691
- onDisconnected: f,
692
- children: /* @__PURE__ */ r($e, { session: i })
694
+ onDisconnected: p,
695
+ children: /* @__PURE__ */ i(Ke, { session: r })
693
696
  }
694
697
  ) })
695
698
  ]
@@ -697,11 +700,11 @@ const _e = ({
697
700
  );
698
701
  };
699
702
  export {
700
- _e as AvatarCanvas,
701
- je as AvatarControls,
703
+ je as AvatarCanvas,
704
+ _e as AvatarControls,
702
705
  Oe as AvatarStatusBadge,
703
- $e as LiveKitAvatarProvider,
704
- Qe as LiveKitAvatarSession,
705
- Ue as useAvatarSession
706
+ Ke as LiveKitAvatarProvider,
707
+ qe as LiveKitAvatarSession,
708
+ Fe as useAvatarSession
706
709
  };
707
710
  //# sourceMappingURL=zeroweight-renderer-react.es.js.map