@zeroweight/react 0.2.27 → 0.2.28

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,29 +1,26 @@
1
- import { useMemo as ve, useRef as A, useState as y, useCallback as w, useEffect as b } from "react";
1
+ import { useMemo as ve, useRef as A, useState as v, useCallback as w, useEffect as y } from "react";
2
2
  import { ZeroWeightRenderer as ye, ActionQueue as be, VoiceActivityDetector as Se } from "@zeroweight/renderer";
3
- import { jsxs as S, jsx as r, Fragment as U } from "react/jsx-runtime";
3
+ import { jsxs as b, jsx as r, Fragment as P } from "react/jsx-runtime";
4
4
  import { useVoiceAssistant as xe, useLocalParticipant as we, useIsSpeaking as Ae, useDataChannel as ke, RoomAudioRenderer as Te, LiveKitRoom as Ie } from "@livekit/components-react";
5
5
  import "@livekit/components-styles";
6
- import { Loader2 as W, MicOff as Re, Mic as Ce, Power as Me, Activity as Ee } from "lucide-react";
7
- const Le = 3e4, De = 120, ze = "wss://prod-project-pazuyq69.livekit.cloud", X = "https://api.zeroweight.ai", Pe = () => {
8
- const u = ["Happy", "Swift", "Bright", "Cool", "Smart"], o = ["User", "Guest", "Visitor", "Agent", "Caller"], t = Math.floor(Math.random() * 1e3);
9
- return `${u[Math.floor(Math.random() * u.length)]}${o[Math.floor(Math.random() * o.length)]}${t}`;
10
- };
11
- function Ue(u) {
6
+ import { Loader2 as V, MicOff as Re, Mic as Ce, Power as Me, Activity as Ee } from "lucide-react";
7
+ const Le = 3e4, De = 120, ze = "wss://prod-project-pazuyq69.livekit.cloud", Y = "https://api.zeroweight.ai";
8
+ function Pe(S) {
12
9
  const {
13
- avatarId: o,
10
+ avatarId: a,
14
11
  apiKey: t = null,
15
12
  api: f,
16
- livekitUrl: h = ze,
13
+ livekitUrl: g = ze,
17
14
  sessionDuration: d = De,
18
15
  inactivityTimeout: x = Le
19
- } = u, M = h, p = ve(() => {
16
+ } = S, M = g, u = ve(() => {
20
17
  if (f) return f;
21
18
  const e = t ? { "X-ZW-Api-Key": t } : void 0;
22
19
  return {
23
- getBundle: async (l) => {
20
+ getBundle: async (p) => {
24
21
  const k = await fetch(
25
- `${X}/avatars/bundle/${encodeURIComponent(
26
- l
22
+ `${Y}/avatars/bundle/${encodeURIComponent(
23
+ p
27
24
  )}`,
28
25
  { headers: e }
29
26
  );
@@ -33,101 +30,101 @@ function Ue(u) {
33
30
  );
34
31
  return k.json();
35
32
  },
36
- getLiveKitToken: async (l, k) => {
37
- const g = new URLSearchParams({
38
- avatar_id: l,
39
- name: k
40
- }), E = await fetch(
41
- `${X}/livekit/token?${g.toString()}`,
33
+ getLiveKitToken: async (p) => {
34
+ const k = new URLSearchParams({
35
+ avatar_id: p,
36
+ name: "anonymuous"
37
+ }), l = await fetch(
38
+ `${Y}/livekit/token?${k.toString()}`,
42
39
  { headers: e }
43
40
  );
44
- if (!E.ok)
41
+ if (!l.ok)
45
42
  throw new Error(
46
- `Failed to fetch LiveKit token (${E.status} ${E.statusText})`
43
+ `Failed to fetch LiveKit token (${l.status} ${l.statusText})`
47
44
  );
48
- return E.json();
45
+ return l.json();
49
46
  }
50
47
  };
51
- }, [f, t]), m = A(null), v = A(null), i = A(null), c = A(null), [R, a] = y("idle"), [n, s] = y(null), [L, D] = y(
48
+ }, [f, t]), h = A(null), m = A(null), i = A(null), c = A(null), [R, o] = v("idle"), [n, s] = v(null), [E, L] = v(
52
49
  /* @__PURE__ */ new Set(["listening"])
53
- ), [z, $] = y({
50
+ ), [D, F] = v({
54
51
  listening: { kind: "looped" },
55
52
  speaking: { kind: "looped" }
56
- }), [te, B] = y(!1), [ne, H] = y(null), [j, F] = y(!1), [_, Q] = y(!1), [re, K] = y(d), I = A(null), N = A(() => {
57
- }), [ie, oe] = y(!1), [ae, q] = y(0.8), C = A(null), O = R === "ready", J = w(() => {
58
- const e = m.current;
53
+ }), [te, B] = v(!1), [ne, H] = v(null), [_, U] = v(!1), [j, Q] = v(!1), [re, $] = v(d), I = A(null), K = A(() => {
54
+ }), [ie, oe] = v(!1), [ae, q] = v(0.8), C = A(null), O = R === "ready", J = w(() => {
55
+ const e = h.current;
59
56
  if (!e) return null;
60
- let l = e.querySelector("canvas");
61
- return l || (l = document.createElement("canvas"), l.style.width = "100%", l.style.height = "100%", l.style.display = "block", e.appendChild(l)), v.current = l, l;
57
+ let p = e.querySelector("canvas");
58
+ return p || (p = document.createElement("canvas"), p.style.width = "100%", p.style.height = "100%", p.style.display = "block", e.appendChild(p)), m.current = p, p;
62
59
  }, []);
63
- b(() => {
60
+ y(() => {
64
61
  let e = !1;
65
62
  return (async () => {
66
63
  const k = J();
67
64
  if (!k) return;
68
- const g = new ye();
69
- i.current = g;
70
- const E = new be((T, P) => {
71
- g.play(T, P);
65
+ const l = new ye();
66
+ i.current = l;
67
+ const W = new be((T, z) => {
68
+ l.play(T, z);
72
69
  });
73
- c.current = E, g.on("stateChanged", (T) => {
74
- e || a(T);
75
- }), g.on("dimensions", (T, P) => {
76
- e || s({ width: T, height: P });
77
- }), g.on("actionLoaded", (T) => {
78
- e || D((P) => {
79
- const G = new Set(P);
80
- return G.add(T), G;
70
+ c.current = W, l.on("stateChanged", (T) => {
71
+ e || o(T);
72
+ }), l.on("dimensions", (T, z) => {
73
+ e || s({ width: T, height: z });
74
+ }), l.on("actionLoaded", (T) => {
75
+ e || L((z) => {
76
+ const X = new Set(z);
77
+ return X.add(T), X;
81
78
  });
82
- }), g.on("allActionsLoaded", () => {
79
+ }), l.on("allActionsLoaded", () => {
83
80
  e || B(!1);
84
- }), g.on("ready", () => {
85
- e || ($(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata()));
81
+ }), l.on("ready", () => {
82
+ e || (F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata()));
86
83
  });
87
84
  try {
88
85
  B(!0);
89
- const T = await p.getBundle(o);
90
- if (e || (await g.init(k, { payload: T.payload }), e)) return;
91
- $(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata());
86
+ const T = await u.getBundle(a);
87
+ if (e || (await l.init(k, { payload: T.payload }), e)) return;
88
+ F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata());
92
89
  } catch (T) {
93
90
  console.error("[useAvatarSession] Init failed:", T);
94
91
  }
95
92
  })(), () => {
96
93
  e = !0, i.current?.destroy(), i.current = null, c.current = null;
97
94
  };
98
- }, [o, J, p]);
95
+ }, [a, J, u]);
99
96
  const Z = A(!1);
100
- b(() => {
101
- O && i.current && L.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
102
- }, [O, L]);
97
+ y(() => {
98
+ O && i.current && E.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
99
+ }, [O, E]);
103
100
  const se = w(async () => {
104
- if (!(j || _)) {
105
- F(!0);
101
+ if (!(_ || j)) {
102
+ U(!0);
106
103
  try {
107
104
  await navigator.mediaDevices.getUserMedia({ audio: !0 });
108
- const e = Pe(), l = await p.getLiveKitToken(o, e);
109
- H(l.token);
105
+ const e = await u.getLiveKitToken(a);
106
+ H(e.token);
110
107
  } catch (e) {
111
- console.error("[useAvatarSession] Failed to connect:", e), F(!1);
108
+ console.error("[useAvatarSession] Failed to connect:", e), U(!1);
112
109
  }
113
110
  }
114
- }, [j, _, o, p]), V = w(() => {
115
- I.current && (clearInterval(I.current), I.current = null), K(d), C.current && (clearTimeout(C.current), C.current = null), H(null), Q(!1), F(!1), c.current?.forceListening();
111
+ }, [_, j, a, u]), N = w(() => {
112
+ I.current && (clearInterval(I.current), I.current = null), $(d), C.current && (clearTimeout(C.current), C.current = null), H(null), Q(!1), U(!1), c.current?.forceListening();
116
113
  }, [d]);
117
- b(() => {
118
- N.current = V;
119
- }, [V]);
114
+ y(() => {
115
+ K.current = N;
116
+ }, [N]);
120
117
  const ce = w(() => {
121
- Q(!0), F(!1);
118
+ Q(!0), U(!1);
122
119
  }, []), le = w(() => {
123
- I.current && clearInterval(I.current), K(d), I.current = setInterval(() => {
124
- K((e) => e <= 1 ? (clearInterval(I.current), I.current = null, setTimeout(() => N.current(), 0), 0) : e - 1);
120
+ I.current && clearInterval(I.current), $(d), I.current = setInterval(() => {
121
+ $((e) => e <= 1 ? (clearInterval(I.current), I.current = null, setTimeout(() => K.current(), 0), 0) : e - 1);
125
122
  }, 1e3);
126
123
  }, [d]), de = w((e) => {
127
- const l = Math.floor(e / 60).toString().padStart(2, "0"), k = (e % 60).toString().padStart(2, "0");
128
- return `${l}:${k}`;
124
+ const p = Math.floor(e / 60).toString().padStart(2, "0"), k = (e % 60).toString().padStart(2, "0");
125
+ return `${p}:${k}`;
129
126
  }, []);
130
- b(() => () => {
127
+ y(() => () => {
131
128
  I.current && clearInterval(I.current);
132
129
  }, []);
133
130
  const ue = w(
@@ -137,7 +134,7 @@ function Ue(u) {
137
134
  return;
138
135
  }
139
136
  C.current || (C.current = setTimeout(() => {
140
- C.current = null, N.current();
137
+ C.current = null, K.current();
141
138
  }, x));
142
139
  },
143
140
  [x]
@@ -153,25 +150,25 @@ function Ue(u) {
153
150
  i.current?.play(e, "listening");
154
151
  }, []);
155
152
  return {
156
- containerRef: m,
153
+ containerRef: h,
157
154
  renderer: i.current,
158
155
  actionQueue: c.current,
159
156
  rendererState: R,
160
157
  avatarDimensions: n,
161
- loadedActions: L,
162
- actionMetadata: z,
158
+ loadedActions: E,
159
+ actionMetadata: D,
163
160
  isLoadingActions: te,
164
161
  isEngineReady: O,
165
162
  token: ne,
166
- isConnecting: j,
167
- isConnected: _,
163
+ isConnecting: _,
164
+ isConnected: j,
168
165
  livekitUrl: M,
169
166
  timeRemaining: re,
170
167
  formatTime: de,
171
168
  micMuted: ie,
172
169
  volume: ae,
173
170
  connect: se,
174
- disconnect: V,
171
+ disconnect: N,
175
172
  toggleMic: pe,
176
173
  setVolume: fe,
177
174
  toggleVolume: ge,
@@ -182,11 +179,11 @@ function Ue(u) {
182
179
  setInactivityActive: ue
183
180
  };
184
181
  }
185
- const $e = ({
186
- session: u,
187
- style: o,
182
+ const Fe = ({
183
+ session: S,
184
+ style: a,
188
185
  loadingContent: t
189
- }) => /* @__PURE__ */ S(
186
+ }) => /* @__PURE__ */ b(
190
187
  "div",
191
188
  {
192
189
  style: {
@@ -200,7 +197,7 @@ const $e = ({
200
197
  justifyContent: "center",
201
198
  alignItems: "center",
202
199
  overflow: "hidden",
203
- ...o
200
+ ...a
204
201
  },
205
202
  children: [
206
203
  /* @__PURE__ */ r("style", { children: `
@@ -216,14 +213,14 @@ const $e = ({
216
213
  /* @__PURE__ */ r(
217
214
  "div",
218
215
  {
219
- ref: u.containerRef,
216
+ ref: S.containerRef,
220
217
  style: {
221
218
  position: "relative",
222
219
  width: "100%",
223
220
  height: "100%",
224
221
  transition: "all 0.5s ease-in-out"
225
222
  },
226
- children: !u.isEngineReady && /* @__PURE__ */ r(
223
+ children: !S.isEngineReady && /* @__PURE__ */ r(
227
224
  "div",
228
225
  {
229
226
  style: {
@@ -236,7 +233,7 @@ const $e = ({
236
233
  backdropFilter: "blur(4px)",
237
234
  zIndex: 10
238
235
  },
239
- children: t || /* @__PURE__ */ S(
236
+ children: t || /* @__PURE__ */ b(
240
237
  "div",
241
238
  {
242
239
  style: {
@@ -247,7 +244,7 @@ const $e = ({
247
244
  },
248
245
  children: [
249
246
  /* @__PURE__ */ r(
250
- W,
247
+ V,
251
248
  {
252
249
  style: {
253
250
  width: 40,
@@ -280,7 +277,7 @@ const $e = ({
280
277
  )
281
278
  ]
282
279
  }
283
- ), Y = {
280
+ ), G = {
284
281
  flexShrink: 0,
285
282
  borderRadius: 9999,
286
283
  padding: 16,
@@ -305,31 +302,31 @@ const $e = ({
305
302
  transition: "all 0.3s",
306
303
  border: "none",
307
304
  cursor: "pointer"
308
- }, Fe = ({
309
- session: u,
310
- style: o
305
+ }, Ue = ({
306
+ session: S,
307
+ style: a
311
308
  }) => {
312
309
  const {
313
310
  micMuted: t,
314
311
  toggleMic: f,
315
- isConnected: h,
312
+ isConnected: g,
316
313
  isConnecting: d,
317
314
  isEngineReady: x,
318
315
  loadedActions: M,
319
- connect: p,
320
- disconnect: m
321
- } = u, [v, i] = y(!1), [c, R] = y(!1), a = x && M.has("listening") && M.has("speaking"), n = t ? {
322
- ...Y,
316
+ connect: u,
317
+ disconnect: h
318
+ } = S, [m, i] = v(!1), [c, R] = v(!1), o = x && M.has("listening") && M.has("speaking"), n = t ? {
319
+ ...G,
323
320
  background: "rgba(239,68,68,0.1)",
324
321
  color: "#f87171",
325
322
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
326
- ...v ? { background: "rgba(239,68,68,0.2)" } : {}
323
+ ...m ? { background: "rgba(239,68,68,0.2)" } : {}
327
324
  } : {
328
- ...Y,
329
- background: v ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
325
+ ...G,
326
+ background: m ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
330
327
  color: "#fff",
331
328
  boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
332
- }, s = h ? {
329
+ }, s = g ? {
333
330
  ...ee,
334
331
  background: c ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
335
332
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
@@ -339,7 +336,7 @@ const $e = ({
339
336
  boxShadow: "0 0 30px rgba(236,72,153,0.3)",
340
337
  opacity: c ? 0.9 : 1
341
338
  };
342
- return (d || !a) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ S(
339
+ return (d || !o) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ b(
343
340
  "div",
344
341
  {
345
342
  style: {
@@ -350,7 +347,7 @@ const $e = ({
350
347
  alignItems: "center",
351
348
  gap: 16,
352
349
  paddingBottom: 16,
353
- ...o
350
+ ...a
354
351
  },
355
352
  children: [
356
353
  /* @__PURE__ */ r("style", { children: `
@@ -359,7 +356,7 @@ const $e = ({
359
356
  to { transform: rotate(360deg); }
360
357
  }
361
358
  ` }),
362
- /* @__PURE__ */ S(
359
+ /* @__PURE__ */ b(
363
360
  "div",
364
361
  {
365
362
  style: {
@@ -388,21 +385,21 @@ const $e = ({
388
385
  "button",
389
386
  {
390
387
  type: "button",
391
- onClick: h ? m : p,
388
+ onClick: g ? h : u,
392
389
  onMouseEnter: () => R(!0),
393
390
  onMouseLeave: () => R(!1),
394
- disabled: !h && (d || !a),
391
+ disabled: !g && (d || !o),
395
392
  style: s,
396
- children: d ? /* @__PURE__ */ S(U, { children: [
397
- /* @__PURE__ */ r(W, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
393
+ children: d ? /* @__PURE__ */ b(P, { children: [
394
+ /* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
398
395
  /* @__PURE__ */ r("span", { children: "Connecting..." })
399
- ] }) : !h && !a ? /* @__PURE__ */ S(U, { children: [
400
- /* @__PURE__ */ r(W, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
396
+ ] }) : !g && !o ? /* @__PURE__ */ b(P, { children: [
397
+ /* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
401
398
  /* @__PURE__ */ r("span", { children: "Loading Avatar..." })
402
- ] }) : h ? /* @__PURE__ */ S(U, { children: [
399
+ ] }) : g ? /* @__PURE__ */ b(P, { children: [
403
400
  /* @__PURE__ */ r(Me, { size: 20 }),
404
401
  /* @__PURE__ */ r("span", { children: "End Session" })
405
- ] }) : /* @__PURE__ */ S(U, { children: [
402
+ ] }) : /* @__PURE__ */ b(P, { children: [
406
403
  /* @__PURE__ */ r(Ee, { size: 20 }),
407
404
  /* @__PURE__ */ r("span", { children: "Start Session" })
408
405
  ] })
@@ -414,10 +411,10 @@ const $e = ({
414
411
  ]
415
412
  }
416
413
  );
417
- }, je = ({
418
- session: u
414
+ }, _e = ({
415
+ session: S
419
416
  }) => {
420
- const { isConnected: o, timeRemaining: t, formatTime: f } = u, h = o && t <= 30, d = o && t > 30 && t <= 60, x = {
417
+ const { isConnected: a, timeRemaining: t, formatTime: f } = S, g = a && t <= 30, d = a && t > 30 && t <= 60, x = {
421
418
  display: "flex",
422
419
  alignItems: "center",
423
420
  gap: 8,
@@ -427,7 +424,7 @@ const $e = ({
427
424
  border: "1px solid",
428
425
  pointerEvents: "auto",
429
426
  transition: "all 0.3s",
430
- ...h ? {
427
+ ...g ? {
431
428
  background: "rgba(239,68,68,0.3)",
432
429
  borderColor: "rgba(239,68,68,0.4)",
433
430
  boxShadow: "0 0 15px rgba(239,68,68,0.3)",
@@ -442,14 +439,14 @@ const $e = ({
442
439
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
443
440
  }
444
441
  };
445
- return /* @__PURE__ */ S(U, { children: [
442
+ return /* @__PURE__ */ b(P, { children: [
446
443
  /* @__PURE__ */ r("style", { children: `
447
444
  @keyframes zwr-pulse {
448
445
  0%, 100% { opacity: 1; }
449
446
  50% { opacity: 0.5; }
450
447
  }
451
448
  ` }),
452
- /* @__PURE__ */ S("div", { style: x, children: [
449
+ /* @__PURE__ */ b("div", { style: x, children: [
453
450
  /* @__PURE__ */ r(
454
451
  "div",
455
452
  {
@@ -457,7 +454,7 @@ const $e = ({
457
454
  height: 8,
458
455
  width: 8,
459
456
  borderRadius: "50%",
460
- ...o ? {
457
+ ...a ? {
461
458
  background: "#22c55e",
462
459
  boxShadow: "0 0 10px rgba(34,197,94,0.5)"
463
460
  } : {
@@ -476,35 +473,35 @@ const $e = ({
476
473
  color: "rgba(255,255,255,0.7)",
477
474
  textTransform: "uppercase"
478
475
  },
479
- children: o ? `Online ${f(t)}` : "Offline"
476
+ children: a ? `Online ${f(t)}` : "Offline"
480
477
  }
481
478
  )
482
479
  ] })
483
480
  ] });
484
- }, _e = ({
485
- session: u
481
+ }, je = ({
482
+ session: S
486
483
  }) => {
487
- const { renderer: o, actionQueue: t, micMuted: f, volume: h, setInactivityActive: d, loadedActions: x } = u, M = A(!1), { state: p, audioTrack: m } = xe(), v = we(), i = Ae(v.localParticipant), c = A(null), R = A(x);
488
- b(() => {
484
+ const { renderer: a, actionQueue: t, micMuted: f, volume: g, setInactivityActive: d, loadedActions: x } = S, M = A(!1), { state: u, audioTrack: h } = xe(), m = we(), i = Ae(m.localParticipant), c = A(null), R = A(x);
485
+ y(() => {
489
486
  R.current = x;
490
- }, [x]), b(() => {
491
- const n = v.localParticipant;
492
- if (!o || !n) return;
487
+ }, [x]), y(() => {
488
+ const n = m.localParticipant;
489
+ if (!a || !n) return;
493
490
  const s = new TextEncoder();
494
- return o.onOneshotComplete((D) => {
495
- const z = s.encode(
491
+ return a.onOneshotComplete((L) => {
492
+ const D = s.encode(
496
493
  JSON.stringify({
497
494
  type: "ACTION_FINISHED",
498
- action: D
495
+ action: L
499
496
  })
500
497
  );
501
- n.publishData(z, {
498
+ n.publishData(D, {
502
499
  reliable: !0
503
- }).catch(($) => {
504
- console.error("[LiveKitAvatarProvider] Failed to publish action completion:", $);
500
+ }).catch((F) => {
501
+ console.error("[LiveKitAvatarProvider] Failed to publish action completion:", F);
505
502
  });
506
503
  });
507
- }, [o, v.localParticipant]), b(() => {
504
+ }, [a, m.localParticipant]), y(() => {
508
505
  if (!t) return;
509
506
  const n = new Se({
510
507
  threshold: 8e-3,
@@ -520,76 +517,76 @@ const $e = ({
520
517
  }), () => {
521
518
  n.stop(), c.current = null;
522
519
  };
523
- }, [t]), b(() => {
520
+ }, [t]), y(() => {
524
521
  const n = c.current;
525
522
  if (n)
526
- if (m?.publication?.track) {
527
- const s = m.publication.track.mediaStreamTrack;
523
+ if (h?.publication?.track) {
524
+ const s = h.publication.track.mediaStreamTrack;
528
525
  s && n.start(s);
529
526
  } else
530
527
  n.stop();
531
- }, [m?.publication?.track]);
532
- const a = A(null);
533
- return b(() => {
528
+ }, [h?.publication?.track]);
529
+ const o = A(null);
530
+ return y(() => {
534
531
  if (!t) return;
535
- const n = p;
536
- n === "speaking" ? (a.current && (clearTimeout(a.current), a.current = null), t.setTurnActive(!0), t.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (a.current && (clearTimeout(a.current), a.current = null), c.current?.endTurn(), t.setTurnActive(!1)) : n === "thinking" && (a.current || (a.current = setTimeout(() => {
537
- a.current = null, c.current?.endTurn(), t.setTurnActive(!1);
532
+ const n = u;
533
+ n === "speaking" ? (o.current && (clearTimeout(o.current), o.current = null), t.setTurnActive(!0), t.setSpeechState("speaking")) : n === "listening" || n === "idle" ? (o.current && (clearTimeout(o.current), o.current = null), c.current?.endTurn(), t.setTurnActive(!1)) : n === "thinking" && (o.current || (o.current = setTimeout(() => {
534
+ o.current = null, c.current?.endTurn(), t.setTurnActive(!1);
538
535
  }, 500)));
539
- }, [p, t]), b(() => () => {
540
- a.current && clearTimeout(a.current);
536
+ }, [u, t]), y(() => () => {
537
+ o.current && clearTimeout(o.current);
541
538
  }, []), ke((n) => {
542
539
  try {
543
- const L = new TextDecoder().decode(n.payload), D = JSON.parse(L);
544
- if (D.type === "AVATAR_UPDATE") {
545
- const z = D.action;
546
- if (!R.current.has(z))
540
+ const E = new TextDecoder().decode(n.payload), L = JSON.parse(E);
541
+ if (L.type === "AVATAR_UPDATE") {
542
+ const D = L.action;
543
+ if (!R.current.has(D))
547
544
  return;
548
- t?.dispatch(z);
545
+ t?.dispatch(D);
549
546
  }
550
547
  } catch (s) {
551
548
  console.error("[LiveKitAvatarProvider] Failed to parse data message:", s);
552
549
  }
553
- }), b(() => {
554
- d(!(p === "speaking") && !i);
555
- }, [i, d, p]), b(() => {
550
+ }), y(() => {
551
+ d(!(u === "speaking") && !i);
552
+ }, [i, d, u]), y(() => {
556
553
  if (!t) return;
557
- const n = !!m;
558
- (!n || p === "disconnected") && (c.current?.endTurn(), t.forceListening()), M.current = n;
559
- }, [m, p, t]), b(() => {
560
- const n = v.localParticipant;
554
+ const n = !!h;
555
+ (!n || u === "disconnected") && (c.current?.endTurn(), t.forceListening()), M.current = n;
556
+ }, [h, u, t]), y(() => {
557
+ const n = m.localParticipant;
561
558
  n && n.setMicrophoneEnabled(!f).catch((s) => {
562
559
  console.error("[LiveKitAvatarProvider] Failed to set mic state:", s);
563
560
  });
564
- }, [f, v.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Te, { volume: h }) });
565
- }, He = ({
566
- avatarId: u,
567
- apiKey: o,
561
+ }, [f, m.localParticipant]), /* @__PURE__ */ r("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ r(Te, { volume: g }) });
562
+ }, Be = ({
563
+ avatarId: S,
564
+ apiKey: a,
568
565
  api: t,
569
566
  livekitUrl: f,
570
- sessionDuration: h,
567
+ sessionDuration: g,
571
568
  inactivityTimeout: d,
572
569
  style: x,
573
570
  className: M,
574
- loadingContent: p,
575
- customControls: m,
576
- customStatusBadge: v
571
+ loadingContent: u,
572
+ customControls: h,
573
+ customStatusBadge: m
577
574
  }) => {
578
- const i = Ue({
579
- avatarId: u,
580
- apiKey: o,
575
+ const i = Pe({
576
+ avatarId: S,
577
+ apiKey: a,
581
578
  api: t,
582
579
  livekitUrl: f,
583
- sessionDuration: h,
580
+ sessionDuration: g,
584
581
  inactivityTimeout: d
585
582
  }), {
586
583
  token: c,
587
584
  isConnected: R,
588
- avatarDimensions: a,
585
+ avatarDimensions: o,
589
586
  disconnect: n,
590
587
  startSessionTimer: s
591
588
  } = i;
592
- return /* @__PURE__ */ S(
589
+ return /* @__PURE__ */ b(
593
590
  "section",
594
591
  {
595
592
  className: M,
@@ -606,12 +603,12 @@ const $e = ({
606
603
  height: "80vh",
607
604
  width: "auto",
608
605
  maxWidth: "100%",
609
- aspectRatio: a ? `${a.width} / ${a.height}` : "3 / 4",
606
+ aspectRatio: o ? `${o.width} / ${o.height}` : "3 / 4",
610
607
  ...x
611
608
  },
612
609
  children: [
613
- /* @__PURE__ */ r($e, { session: i, loadingContent: p }),
614
- /* @__PURE__ */ S(
610
+ /* @__PURE__ */ r(Fe, { session: i, loadingContent: u }),
611
+ /* @__PURE__ */ b(
615
612
  "div",
616
613
  {
617
614
  style: {
@@ -625,7 +622,7 @@ const $e = ({
625
622
  padding: 16
626
623
  },
627
624
  children: [
628
- /* @__PURE__ */ S(
625
+ /* @__PURE__ */ b(
629
626
  "div",
630
627
  {
631
628
  style: {
@@ -635,12 +632,12 @@ const $e = ({
635
632
  justifyContent: "space-between"
636
633
  },
637
634
  children: [
638
- v ? v(i) : /* @__PURE__ */ r(je, { session: i }),
635
+ m ? m(i) : /* @__PURE__ */ r(_e, { session: i }),
639
636
  /* @__PURE__ */ r("div", {})
640
637
  ]
641
638
  }
642
639
  ),
643
- m ? m(i) : /* @__PURE__ */ r(Fe, { session: i })
640
+ h ? h(i) : /* @__PURE__ */ r(Ue, { session: i })
644
641
  ]
645
642
  }
646
643
  ),
@@ -656,7 +653,7 @@ const $e = ({
656
653
  i.markConnected(), s();
657
654
  },
658
655
  onDisconnected: n,
659
- children: /* @__PURE__ */ r(_e, { session: i })
656
+ children: /* @__PURE__ */ r(je, { session: i })
660
657
  }
661
658
  ) })
662
659
  ]
@@ -664,11 +661,11 @@ const $e = ({
664
661
  );
665
662
  };
666
663
  export {
667
- $e as AvatarCanvas,
668
- Fe as AvatarControls,
669
- je as AvatarStatusBadge,
670
- _e as LiveKitAvatarProvider,
671
- He as LiveKitAvatarSession,
672
- Ue as useAvatarSession
664
+ Fe as AvatarCanvas,
665
+ Ue as AvatarControls,
666
+ _e as AvatarStatusBadge,
667
+ je as LiveKitAvatarProvider,
668
+ Be as LiveKitAvatarSession,
669
+ Pe as useAvatarSession
673
670
  };
674
671
  //# sourceMappingURL=zeroweight-renderer-react.es.js.map