@zeroweight/react 0.2.1 → 0.2.21

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,165 +1,171 @@
1
- import { useMemo as ve, useRef as b, useState as h, useCallback as y, useEffect as x } from "react";
2
- import { ZeroWeightRenderer as ye, ActionQueue as be, VoiceActivityDetector as xe } from "@zeroweight/renderer";
1
+ import { useMemo as ve, useRef as y, useState as h, useCallback as v, useEffect as b } from "react";
2
+ import { ZeroWeightRenderer as ye, ActionQueue as be, VoiceActivityDetector as Se } from "@zeroweight/renderer";
3
3
  import { jsxs as S, jsx as n, Fragment as j } from "react/jsx-runtime";
4
- import { useVoiceAssistant as Se, useLocalParticipant as we, useTrackTranscription as ke, useDataChannel as Te, RoomAudioRenderer as Ae, LiveKitRoom as Re } from "@livekit/components-react";
4
+ import { useVoiceAssistant as xe, useLocalParticipant as we, useIsSpeaking as ke, useDataChannel as Ae, RoomAudioRenderer as Te, LiveKitRoom as Re } from "@livekit/components-react";
5
5
  import "@livekit/components-styles";
6
- import { Loader2 as ee, MicOff as Ce, Mic as Ie, Power as Me, Activity as Ee } from "lucide-react";
7
- import { Track as Le } from "livekit-client";
8
- const De = 3e4, ze = 120, $e = "wss://prod-project-pazuyq69.livekit.cloud", J = "https://api.zeroweight.ai", Ue = () => {
9
- const d = ["Happy", "Swift", "Bright", "Cool", "Smart"], o = ["User", "Guest", "Visitor", "Agent", "Caller"], e = Math.floor(Math.random() * 1e3);
10
- return `${d[Math.floor(Math.random() * d.length)]}${o[Math.floor(Math.random() * o.length)]}${e}`;
6
+ import { Loader2 as ee, MicOff as Ie, 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", J = "https://api.zeroweight.ai", Ue = () => {
8
+ const d = ["Happy", "Swift", "Bright", "Cool", "Smart"], o = ["User", "Guest", "Visitor", "Agent", "Caller"], t = Math.floor(Math.random() * 1e3);
9
+ return `${d[Math.floor(Math.random() * d.length)]}${o[Math.floor(Math.random() * o.length)]}${t}`;
11
10
  };
12
- function je(d) {
11
+ function $e(d) {
13
12
  const {
14
13
  avatarId: o,
15
- apiKey: e = null,
16
- api: p,
17
- livekitUrl: w = $e,
18
- sessionDuration: c = ze,
19
- inactivityTimeout: m = De
20
- } = d, I = w, l = ve(() => {
21
- if (p) return p;
22
- const t = e ? { "X-ZW-Api-Key": e } : void 0;
14
+ apiKey: t = null,
15
+ api: f,
16
+ livekitUrl: x = ze,
17
+ sessionDuration: l = De,
18
+ inactivityTimeout: m = Le
19
+ } = d, M = x, s = ve(() => {
20
+ if (f) return f;
21
+ const e = t ? { "X-ZW-Api-Key": t } : void 0;
23
22
  return {
24
- getBundle: async (s) => {
25
- const T = await fetch(
23
+ getBundle: async (c) => {
24
+ const A = await fetch(
26
25
  `${J}/avatars/bundle/${encodeURIComponent(
27
- s
26
+ c
28
27
  )}`,
29
- { headers: t }
28
+ { headers: e }
30
29
  );
31
- if (!T.ok)
30
+ if (!A.ok)
32
31
  throw new Error(
33
- `Failed to fetch avatar bundle (${T.status} ${T.statusText})`
32
+ `Failed to fetch avatar bundle (${A.status} ${A.statusText})`
34
33
  );
35
- return T.json();
34
+ return A.json();
36
35
  },
37
- getLiveKitToken: async (s, T) => {
36
+ getLiveKitToken: async (c, A) => {
38
37
  const g = new URLSearchParams({
39
- avatar_id: s,
40
- name: T
41
- }), M = await fetch(
38
+ avatar_id: c,
39
+ name: A
40
+ }), E = await fetch(
42
41
  `${J}/livekit/token?${g.toString()}`,
43
- { headers: t }
42
+ { headers: e }
44
43
  );
45
- if (!M.ok)
44
+ if (!E.ok)
46
45
  throw new Error(
47
- `Failed to fetch LiveKit token (${M.status} ${M.statusText})`
46
+ `Failed to fetch LiveKit token (${E.status} ${E.statusText})`
48
47
  );
49
- return M.json();
48
+ return E.json();
50
49
  }
51
50
  };
52
- }, [p, e]), i = b(null), v = b(null), f = b(null), a = b(null), [k, u] = h("idle"), [r, R] = h(null), [L, z] = h(
51
+ }, [f, t]), i = y(null), w = y(null), u = y(null), a = y(null), [k, p] = h("idle"), [r, R] = h(null), [L, z] = h(
53
52
  /* @__PURE__ */ new Set(["listening"])
54
- ), [$, W] = h({
53
+ ), [U, W] = h({
55
54
  listening: { kind: "looped" },
56
55
  speaking: { kind: "looped" }
57
- }), [te, B] = h(!1), [ne, O] = h(null), [P, U] = h(!1), [F, H] = h(!1), [re, _] = h(c), C = b(null), K = b(() => {
58
- }), [ie, oe] = h(!1), [ae, Q] = h(0.8), E = b(null), N = k === "ready", q = y(() => {
59
- const t = i.current;
60
- if (!t) return null;
61
- let s = t.querySelector("canvas");
62
- return s || (s = document.createElement("canvas"), s.style.width = "100%", s.style.height = "100%", s.style.display = "block", t.appendChild(s)), v.current = s, s;
56
+ }), [te, B] = h(!1), [ne, O] = h(null), [P, $] = h(!1), [F, H] = h(!1), [re, _] = h(l), I = y(null), K = y(() => {
57
+ }), [ie, oe] = h(!1), [ae, Q] = h(0.8), C = y(null), N = k === "ready", q = v(() => {
58
+ const e = i.current;
59
+ if (!e) return null;
60
+ let c = e.querySelector("canvas");
61
+ return c || (c = document.createElement("canvas"), c.style.width = "100%", c.style.height = "100%", c.style.display = "block", e.appendChild(c)), w.current = c, c;
63
62
  }, []);
64
- x(() => {
65
- let t = !1;
63
+ b(() => {
64
+ let e = !1;
66
65
  return (async () => {
67
- const T = q();
68
- if (!T) return;
66
+ const A = q();
67
+ if (!A) return;
69
68
  const g = new ye();
70
- f.current = g;
71
- const M = new be((A, D) => {
72
- g.play(A, D);
69
+ u.current = g;
70
+ const E = new be((T, D) => {
71
+ g.play(T, D);
73
72
  });
74
- a.current = M, g.on("stateChanged", (A) => {
75
- t || u(A);
76
- }), g.on("dimensions", (A, D) => {
77
- t || R({ width: A, height: D });
78
- }), g.on("actionLoaded", (A) => {
79
- t || z((D) => {
73
+ a.current = E, g.on("stateChanged", (T) => {
74
+ e || p(T);
75
+ }), g.on("dimensions", (T, D) => {
76
+ e || R({ width: T, height: D });
77
+ }), g.on("actionLoaded", (T) => {
78
+ e || z((D) => {
80
79
  const G = new Set(D);
81
- return G.add(A), G;
80
+ return G.add(T), G;
82
81
  });
83
82
  }), g.on("allActionsLoaded", () => {
84
- t || B(!1);
83
+ e || B(!1);
85
84
  }), g.on("ready", () => {
86
- t || (W(g.getActionMetadata()), M.setActionMetadata(g.getActionMetadata()));
85
+ e || (W(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata()));
87
86
  });
88
87
  try {
89
88
  B(!0);
90
- const A = await l.getBundle(o);
91
- if (t || (await g.init(T, { payload: A.payload }), t)) return;
92
- W(g.getActionMetadata()), M.setActionMetadata(g.getActionMetadata());
93
- } catch (A) {
94
- console.error("[useAvatarSession] Init failed:", A);
89
+ const T = await s.getBundle(o);
90
+ if (e || (await g.init(A, { payload: T.payload }), e)) return;
91
+ W(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata());
92
+ } catch (T) {
93
+ console.error("[useAvatarSession] Init failed:", T);
95
94
  }
96
95
  })(), () => {
97
- t = !0, f.current?.destroy(), f.current = null, a.current = null;
96
+ e = !0, u.current?.destroy(), u.current = null, a.current = null;
98
97
  };
99
- }, [o, q, l]);
100
- const Z = b(!1);
101
- x(() => {
102
- N && f.current && L.has("wave_hand") && !Z.current && (f.current.play("wave_hand", "listening"), Z.current = !0);
98
+ }, [o, q, s]);
99
+ const Z = y(!1);
100
+ b(() => {
101
+ N && u.current && L.has("wave_hand") && !Z.current && (u.current.play("wave_hand", "listening"), Z.current = !0);
103
102
  }, [N, L]);
104
- const se = y(async () => {
103
+ const se = v(async () => {
105
104
  if (!(P || F)) {
106
- U(!0);
105
+ $(!0);
107
106
  try {
108
107
  await navigator.mediaDevices.getUserMedia({ audio: !0 });
109
- const t = Ue(), s = await l.getLiveKitToken(o, t);
110
- O(s.token);
111
- } catch (t) {
112
- console.error("[useAvatarSession] Failed to connect:", t), U(!1);
108
+ const e = Ue(), c = await s.getLiveKitToken(o, e);
109
+ O(c.token);
110
+ } catch (e) {
111
+ console.error("[useAvatarSession] Failed to connect:", e), $(!1);
113
112
  }
114
113
  }
115
- }, [P, F, o, l]), V = y(() => {
116
- C.current && (clearInterval(C.current), C.current = null), _(c), E.current && (clearTimeout(E.current), E.current = null), O(null), H(!1), U(!1), a.current?.forceListening();
117
- }, [c]);
118
- x(() => {
114
+ }, [P, F, o, s]), V = v(() => {
115
+ I.current && (clearInterval(I.current), I.current = null), _(l), C.current && (clearTimeout(C.current), C.current = null), O(null), H(!1), $(!1), a.current?.forceListening();
116
+ }, [l]);
117
+ b(() => {
119
118
  K.current = V;
120
119
  }, [V]);
121
- const ce = y(() => {
122
- H(!0), U(!1);
123
- }, []), le = y(() => {
124
- C.current && clearInterval(C.current), _(c), C.current = setInterval(() => {
125
- _((t) => t <= 1 ? (clearInterval(C.current), C.current = null, setTimeout(() => K.current(), 0), 0) : t - 1);
120
+ const ce = v(() => {
121
+ H(!0), $(!1);
122
+ }, []), le = v(() => {
123
+ I.current && clearInterval(I.current), _(l), I.current = setInterval(() => {
124
+ _((e) => e <= 1 ? (clearInterval(I.current), I.current = null, setTimeout(() => K.current(), 0), 0) : e - 1);
126
125
  }, 1e3);
127
- }, [c]), de = y((t) => {
128
- const s = Math.floor(t / 60).toString().padStart(2, "0"), T = (t % 60).toString().padStart(2, "0");
129
- return `${s}:${T}`;
126
+ }, [l]), de = v((e) => {
127
+ const c = Math.floor(e / 60).toString().padStart(2, "0"), A = (e % 60).toString().padStart(2, "0");
128
+ return `${c}:${A}`;
130
129
  }, []);
131
- x(() => () => {
132
- C.current && clearInterval(C.current);
130
+ b(() => () => {
131
+ I.current && clearInterval(I.current);
133
132
  }, []);
134
- const ue = y(() => {
135
- E.current && clearTimeout(E.current), E.current = setTimeout(() => {
136
- K.current();
137
- }, m);
138
- }, [m]), pe = y(() => {
139
- oe((t) => !t);
140
- }, []), fe = y((t) => {
141
- Q(t);
142
- }, []), ge = y(() => {
143
- Q((t) => t > 0 ? 0 : 1);
144
- }, []), he = y(() => {
145
- f.current?.interrupt();
146
- }, []), me = y((t) => {
147
- a.current ? a.current.dispatch(t) : f.current?.play(t, "listening");
133
+ const ue = v(
134
+ (e) => {
135
+ if (!e) {
136
+ C.current && (clearTimeout(C.current), C.current = null);
137
+ return;
138
+ }
139
+ C.current || (C.current = setTimeout(() => {
140
+ C.current = null, K.current();
141
+ }, m));
142
+ },
143
+ [m]
144
+ ), pe = v(() => {
145
+ oe((e) => !e);
146
+ }, []), fe = v((e) => {
147
+ Q(e);
148
+ }, []), ge = v(() => {
149
+ Q((e) => e > 0 ? 0 : 1);
150
+ }, []), he = v(() => {
151
+ u.current?.interrupt();
152
+ }, []), me = v((e) => {
153
+ a.current ? a.current.dispatch(e) : u.current?.play(e, "listening");
148
154
  }, []);
149
155
  return {
150
156
  containerRef: i,
151
- renderer: f.current,
157
+ renderer: u.current,
152
158
  actionQueue: a.current,
153
159
  rendererState: k,
154
160
  avatarDimensions: r,
155
161
  loadedActions: L,
156
- actionMetadata: $,
162
+ actionMetadata: U,
157
163
  isLoadingActions: te,
158
164
  isEngineReady: N,
159
165
  token: ne,
160
166
  isConnecting: P,
161
167
  isConnected: F,
162
- livekitUrl: I,
168
+ livekitUrl: M,
163
169
  timeRemaining: re,
164
170
  formatTime: de,
165
171
  micMuted: ie,
@@ -173,13 +179,13 @@ function je(d) {
173
179
  runAction: me,
174
180
  startSessionTimer: le,
175
181
  markConnected: ce,
176
- onInactivityReset: ue
182
+ setInactivityActive: ue
177
183
  };
178
184
  }
179
- const Pe = ({
185
+ const je = ({
180
186
  session: d,
181
187
  style: o,
182
- loadingContent: e
188
+ loadingContent: t
183
189
  }) => /* @__PURE__ */ S(
184
190
  "div",
185
191
  {
@@ -230,7 +236,7 @@ const Pe = ({
230
236
  backdropFilter: "blur(4px)",
231
237
  zIndex: 10
232
238
  },
233
- children: e || /* @__PURE__ */ S(
239
+ children: t || /* @__PURE__ */ S(
234
240
  "div",
235
241
  {
236
242
  style: {
@@ -299,39 +305,39 @@ const Pe = ({
299
305
  transition: "all 0.3s",
300
306
  border: "none",
301
307
  cursor: "pointer"
302
- }, Fe = ({
308
+ }, Pe = ({
303
309
  session: d,
304
310
  style: o
305
311
  }) => {
306
312
  const {
307
- micMuted: e,
308
- toggleMic: p,
309
- isConnected: w,
310
- isConnecting: c,
313
+ micMuted: t,
314
+ toggleMic: f,
315
+ isConnected: x,
316
+ isConnecting: l,
311
317
  connect: m,
312
- disconnect: I
313
- } = d, [l, i] = h(!1), [v, f] = h(!1), a = e ? {
318
+ disconnect: M
319
+ } = d, [s, i] = h(!1), [w, u] = h(!1), a = t ? {
314
320
  ...X,
315
321
  background: "rgba(239,68,68,0.1)",
316
322
  color: "#f87171",
317
323
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.3)",
318
- ...l ? { background: "rgba(239,68,68,0.2)" } : {}
324
+ ...s ? { background: "rgba(239,68,68,0.2)" } : {}
319
325
  } : {
320
326
  ...X,
321
- background: l ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
327
+ background: s ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.4)",
322
328
  color: "#fff",
323
329
  boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.1)"
324
- }, k = w ? {
330
+ }, k = x ? {
325
331
  ...Y,
326
- background: v ? "rgba(0,0,0,0.6)" : "rgba(0,0,0,0.4)",
332
+ background: w ? "rgba(0,0,0,0.6)" : "rgba(0,0,0,0.4)",
327
333
  boxShadow: "inset 0 0 0 1px rgba(239,68,68,0.5), 0 0 20px rgba(239,68,68,0.2)"
328
334
  } : {
329
335
  ...Y,
330
336
  background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
331
337
  boxShadow: "0 0 30px rgba(236,72,153,0.3)",
332
- opacity: v ? 0.9 : 1
338
+ opacity: w ? 0.9 : 1
333
339
  };
334
- return c && (k.opacity = 0.5, k.cursor = "not-allowed"), /* @__PURE__ */ S(
340
+ return l && (k.opacity = 0.5, k.cursor = "not-allowed"), /* @__PURE__ */ S(
335
341
  "div",
336
342
  {
337
343
  style: {
@@ -368,27 +374,27 @@ const Pe = ({
368
374
  "button",
369
375
  {
370
376
  type: "button",
371
- onClick: p,
377
+ onClick: f,
372
378
  onMouseEnter: () => i(!0),
373
379
  onMouseLeave: () => i(!1),
374
380
  style: a,
375
- title: e ? "Unmute mic" : "Mute mic",
376
- children: e ? /* @__PURE__ */ n(Ce, { size: 24 }) : /* @__PURE__ */ n(Ie, { size: 24 })
381
+ title: t ? "Unmute mic" : "Mute mic",
382
+ children: t ? /* @__PURE__ */ n(Ie, { size: 24 }) : /* @__PURE__ */ n(Ce, { size: 24 })
377
383
  }
378
384
  ),
379
385
  /* @__PURE__ */ n(
380
386
  "button",
381
387
  {
382
388
  type: "button",
383
- onClick: w ? I : m,
384
- onMouseEnter: () => f(!0),
385
- onMouseLeave: () => f(!1),
386
- disabled: c,
389
+ onClick: x ? M : m,
390
+ onMouseEnter: () => u(!0),
391
+ onMouseLeave: () => u(!1),
392
+ disabled: l,
387
393
  style: k,
388
- children: c ? /* @__PURE__ */ S(j, { children: [
394
+ children: l ? /* @__PURE__ */ S(j, { children: [
389
395
  /* @__PURE__ */ n(ee, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
390
396
  /* @__PURE__ */ n("span", { children: "Connecting..." })
391
- ] }) : w ? /* @__PURE__ */ S(j, { children: [
397
+ ] }) : x ? /* @__PURE__ */ S(j, { children: [
392
398
  /* @__PURE__ */ n(Me, { size: 20 }),
393
399
  /* @__PURE__ */ n("span", { children: "End Session" })
394
400
  ] }) : /* @__PURE__ */ S(j, { children: [
@@ -403,10 +409,10 @@ const Pe = ({
403
409
  ]
404
410
  }
405
411
  );
406
- }, _e = ({
412
+ }, Fe = ({
407
413
  session: d
408
414
  }) => {
409
- const { isConnected: o, timeRemaining: e, formatTime: p } = d, w = o && e <= 30, c = o && e > 30 && e <= 60, m = {
415
+ const { isConnected: o, timeRemaining: t, formatTime: f } = d, x = o && t <= 30, l = o && t > 30 && t <= 60, m = {
410
416
  display: "flex",
411
417
  alignItems: "center",
412
418
  gap: 8,
@@ -416,12 +422,12 @@ const Pe = ({
416
422
  border: "1px solid",
417
423
  pointerEvents: "auto",
418
424
  transition: "all 0.3s",
419
- ...w ? {
425
+ ...x ? {
420
426
  background: "rgba(239,68,68,0.3)",
421
427
  borderColor: "rgba(239,68,68,0.4)",
422
428
  boxShadow: "0 0 15px rgba(239,68,68,0.3)",
423
429
  animation: "zwr-pulse 2s ease-in-out infinite"
424
- } : c ? {
430
+ } : l ? {
425
431
  background: "rgba(249,115,22,0.2)",
426
432
  borderColor: "rgba(249,115,22,0.3)",
427
433
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
@@ -465,24 +471,20 @@ const Pe = ({
465
471
  color: "rgba(255,255,255,0.7)",
466
472
  textTransform: "uppercase"
467
473
  },
468
- children: o ? `Online ${p(e)}` : "Offline"
474
+ children: o ? `Online ${f(t)}` : "Offline"
469
475
  }
470
476
  )
471
477
  ] })
472
478
  ] });
473
- }, Ke = ({
479
+ }, _e = ({
474
480
  session: d
475
481
  }) => {
476
- const { renderer: o, actionQueue: e, micMuted: p, volume: w, onInactivityReset: c, loadedActions: m } = d, I = b(!1), { state: l, audioTrack: i } = Se(), v = we(), { segments: f } = ke({
477
- publication: v.microphoneTrack,
478
- source: Le.Source.Microphone,
479
- participant: v.localParticipant
480
- }), a = b(null), k = b(m);
481
- x(() => {
482
+ const { renderer: o, actionQueue: t, micMuted: f, volume: x, setInactivityActive: l, loadedActions: m } = d, M = y(!1), { state: s, audioTrack: i } = xe(), w = we(), u = ke(w.localParticipant), a = y(null), k = y(m);
483
+ b(() => {
482
484
  k.current = m;
483
- }, [m]), x(() => {
484
- if (!e) return;
485
- const r = new xe({
485
+ }, [m]), b(() => {
486
+ if (!t) return;
487
+ const r = new Se({
486
488
  threshold: 8e-3,
487
489
  analyseIntervalMs: 30,
488
490
  speechStartFrames: 1,
@@ -490,13 +492,13 @@ const Pe = ({
490
492
  turnEndFrames: 50
491
493
  });
492
494
  return a.current = r, r.on("speechStart", () => {
493
- e.setTurnActive(!0), e.setSpeechState("speaking");
495
+ t.setTurnActive(!0), t.setSpeechState("speaking");
494
496
  }), r.on("turnEnd", () => {
495
- e.setTurnActive(!1);
497
+ t.setTurnActive(!1);
496
498
  }), () => {
497
499
  r.stop(), a.current = null;
498
500
  };
499
- }, [e]), x(() => {
501
+ }, [t]), b(() => {
500
502
  const r = a.current;
501
503
  if (r)
502
504
  if (i?.publication?.track) {
@@ -505,61 +507,61 @@ const Pe = ({
505
507
  } else
506
508
  r.stop();
507
509
  }, [i?.publication?.track]);
508
- const u = b(null);
509
- return x(() => {
510
- if (!e) return;
511
- const r = l;
512
- r === "speaking" ? (u.current && (clearTimeout(u.current), u.current = null), e.setTurnActive(!0), e.setSpeechState("speaking")) : r === "listening" || r === "idle" ? (u.current && (clearTimeout(u.current), u.current = null), a.current?.endTurn(), e.setTurnActive(!1)) : r === "thinking" && (u.current || (u.current = setTimeout(() => {
513
- u.current = null, a.current?.endTurn(), e.setTurnActive(!1);
510
+ const p = y(null);
511
+ return b(() => {
512
+ if (!t) return;
513
+ const r = s;
514
+ r === "speaking" ? (p.current && (clearTimeout(p.current), p.current = null), t.setTurnActive(!0), t.setSpeechState("speaking")) : r === "listening" || r === "idle" ? (p.current && (clearTimeout(p.current), p.current = null), a.current?.endTurn(), t.setTurnActive(!1)) : r === "thinking" && (p.current || (p.current = setTimeout(() => {
515
+ p.current = null, a.current?.endTurn(), t.setTurnActive(!1);
514
516
  }, 500)));
515
- }, [l, e]), x(() => () => {
516
- u.current && clearTimeout(u.current);
517
- }, []), Te((r) => {
517
+ }, [s, t]), b(() => () => {
518
+ p.current && clearTimeout(p.current);
519
+ }, []), Ae((r) => {
518
520
  try {
519
521
  const L = new TextDecoder().decode(r.payload), z = JSON.parse(L);
520
522
  if (z.type === "AVATAR_UPDATE") {
521
- const $ = z.action;
522
- if (!k.current.has($))
523
+ const U = z.action;
524
+ if (!k.current.has(U))
523
525
  return;
524
- e?.dispatch($);
526
+ t?.dispatch(U);
525
527
  }
526
528
  } catch (R) {
527
529
  console.error("[LiveKitAvatarProvider] Failed to parse data message:", R);
528
530
  }
529
- }), x(() => {
530
- c();
531
- }, [f, l, c]), x(() => {
532
- if (!e) return;
531
+ }), b(() => {
532
+ l(!(s === "speaking") && !u);
533
+ }, [u, l, s]), b(() => {
534
+ if (!t) return;
533
535
  const r = !!i;
534
- (!r || l === "disconnected") && (a.current?.endTurn(), e.forceListening()), I.current = r;
535
- }, [i, l, e]), x(() => {
536
- const r = v.localParticipant;
537
- r && r.setMicrophoneEnabled(!p).catch((R) => {
536
+ (!r || s === "disconnected") && (a.current?.endTurn(), t.forceListening()), M.current = r;
537
+ }, [i, s, t]), b(() => {
538
+ const r = w.localParticipant;
539
+ r && r.setMicrophoneEnabled(!f).catch((R) => {
538
540
  console.error("[LiveKitAvatarProvider] Failed to set mic state:", R);
539
541
  });
540
- }, [p, v.localParticipant]), /* @__PURE__ */ n("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ n(Ae, { volume: w }) });
541
- }, qe = ({
542
+ }, [f, w.localParticipant]), /* @__PURE__ */ n("div", { style: { position: "absolute", bottom: 80, left: 8, right: 8, display: "flex", flexDirection: "column", gap: 8 }, children: /* @__PURE__ */ n(Te, { volume: x }) });
543
+ }, He = ({
542
544
  avatarId: d,
543
545
  apiKey: o,
544
- api: e,
545
- livekitUrl: p,
546
- style: w,
547
- className: c,
546
+ api: t,
547
+ livekitUrl: f,
548
+ style: x,
549
+ className: l,
548
550
  loadingContent: m,
549
- customControls: I,
550
- customStatusBadge: l
551
+ customControls: M,
552
+ customStatusBadge: s
551
553
  }) => {
552
- const i = je({ avatarId: d, apiKey: o, api: e, livekitUrl: p }), {
553
- token: v,
554
- isConnected: f,
554
+ const i = $e({ avatarId: d, apiKey: o, api: t, livekitUrl: f }), {
555
+ token: w,
556
+ isConnected: u,
555
557
  avatarDimensions: a,
556
558
  disconnect: k,
557
- startSessionTimer: u
559
+ startSessionTimer: p
558
560
  } = i;
559
561
  return /* @__PURE__ */ S(
560
562
  "section",
561
563
  {
562
- className: c,
564
+ className: l,
563
565
  style: {
564
566
  position: "relative",
565
567
  display: "flex",
@@ -574,10 +576,10 @@ const Pe = ({
574
576
  width: "auto",
575
577
  maxWidth: "100%",
576
578
  aspectRatio: a ? `${a.width} / ${a.height}` : "3 / 4",
577
- ...w
579
+ ...x
578
580
  },
579
581
  children: [
580
- /* @__PURE__ */ n(Pe, { session: i, loadingContent: m }),
582
+ /* @__PURE__ */ n(je, { session: i, loadingContent: m }),
581
583
  /* @__PURE__ */ S(
582
584
  "div",
583
585
  {
@@ -602,28 +604,28 @@ const Pe = ({
602
604
  justifyContent: "space-between"
603
605
  },
604
606
  children: [
605
- l ? l(i) : /* @__PURE__ */ n(_e, { session: i }),
607
+ s ? s(i) : /* @__PURE__ */ n(Fe, { session: i }),
606
608
  /* @__PURE__ */ n("div", {})
607
609
  ]
608
610
  }
609
611
  ),
610
- I ? I(i) : /* @__PURE__ */ n(Fe, { session: i })
612
+ M ? M(i) : /* @__PURE__ */ n(Pe, { session: i })
611
613
  ]
612
614
  }
613
615
  ),
614
- /* @__PURE__ */ n("div", { style: { display: "none" }, children: v && p && /* @__PURE__ */ n(
616
+ /* @__PURE__ */ n("div", { style: { display: "none" }, children: w && f && /* @__PURE__ */ n(
615
617
  Re,
616
618
  {
617
- serverUrl: p,
618
- token: v,
619
+ serverUrl: f,
620
+ token: w,
619
621
  connect: !0,
620
622
  video: !1,
621
623
  audio: !0,
622
624
  onConnected: () => {
623
- i.markConnected(), u();
625
+ i.markConnected(), p();
624
626
  },
625
627
  onDisconnected: k,
626
- children: /* @__PURE__ */ n(Ke, { session: i })
628
+ children: /* @__PURE__ */ n(_e, { session: i })
627
629
  }
628
630
  ) })
629
631
  ]
@@ -631,11 +633,11 @@ const Pe = ({
631
633
  );
632
634
  };
633
635
  export {
634
- Pe as AvatarCanvas,
635
- Fe as AvatarControls,
636
- _e as AvatarStatusBadge,
637
- Ke as LiveKitAvatarProvider,
638
- qe as LiveKitAvatarSession,
639
- je as useAvatarSession
636
+ je as AvatarCanvas,
637
+ Pe as AvatarControls,
638
+ Fe as AvatarStatusBadge,
639
+ _e as LiveKitAvatarProvider,
640
+ He as LiveKitAvatarSession,
641
+ $e as useAvatarSession
640
642
  };
641
643
  //# sourceMappingURL=zeroweight-renderer-react.es.js.map