@zeroweight/react 0.2.29 → 0.2.31

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