@zeroweight/react 0.2.25 → 0.2.27

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