@zeroweight/react 0.2.26 → 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,136 +1,133 @@
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 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 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 b, jsx as r, Fragment as P } 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 = () => {
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 $e(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 = De,
17
- sessionDuration: l = ze,
18
- inactivityTimeout: b = Le
19
- } = u, M = h, p = ve(() => {
13
+ livekitUrl: g = ze,
14
+ sessionDuration: d = De,
15
+ inactivityTimeout: x = Le
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 (c) => {
24
- const A = await fetch(
25
- `${X}/avatars/bundle/${encodeURIComponent(
26
- c
20
+ getBundle: async (p) => {
21
+ const k = await fetch(
22
+ `${Y}/avatars/bundle/${encodeURIComponent(
23
+ p
27
24
  )}`,
28
25
  { headers: e }
29
26
  );
30
- if (!A.ok)
27
+ if (!k.ok)
31
28
  throw new Error(
32
- `Failed to fetch avatar bundle (${A.status} ${A.statusText})`
29
+ `Failed to fetch avatar bundle (${k.status} ${k.statusText})`
33
30
  );
34
- return A.json();
31
+ return k.json();
35
32
  },
36
- getLiveKitToken: async (c, A) => {
37
- const g = new URLSearchParams({
38
- avatar_id: c,
39
- name: A
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 = x(null), k = x(null), i = x(null), s = x(null), [I, a] = v("idle"), [r, d] = v(null), [L, U] = v(
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
- ), [$, B] = v({
50
+ ), [D, F] = v({
54
51
  listening: { kind: "looped" },
55
52
  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(() => {
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 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;
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
- w(() => {
60
+ y(() => {
64
61
  let e = !1;
65
62
  return (async () => {
66
- const A = Z();
67
- if (!A) return;
68
- const g = new ye();
69
- i.current = g;
70
- const E = new be((T, z) => {
71
- g.play(T, z);
63
+ const k = J();
64
+ if (!k) return;
65
+ const l = new ye();
66
+ i.current = l;
67
+ const W = new be((T, z) => {
68
+ l.play(T, z);
72
69
  });
73
- s.current = E, g.on("stateChanged", (T) => {
74
- e || a(T);
75
- }), g.on("dimensions", (T, z) => {
76
- e || d({ width: T, height: z });
77
- }), g.on("actionLoaded", (T) => {
78
- e || U((z) => {
79
- const J = new Set(z);
80
- return J.add(T), J;
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", () => {
83
- e || O(!1);
84
- }), g.on("ready", () => {
85
- e || (B(g.getActionMetadata()), E.setActionMetadata(g.getActionMetadata()));
79
+ }), l.on("allActionsLoaded", () => {
80
+ e || B(!1);
81
+ }), l.on("ready", () => {
82
+ e || (F(l.getActionMetadata()), W.setActionMetadata(l.getActionMetadata()));
86
83
  });
87
84
  try {
88
- O(!0);
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());
85
+ B(!0);
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
- e = !0, i.current?.destroy(), i.current = null, s.current = null;
93
+ e = !0, i.current?.destroy(), i.current = null, c.current = null;
97
94
  };
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);
95
+ }, [a, J, u]);
96
+ const Z = A(!1);
97
+ y(() => {
98
+ O && i.current && E.has("wave_hand") && !Z.current && (i.current.play("wave_hand", "listening"), Z.current = !0);
99
+ }, [O, E]);
100
+ const se = w(async () => {
101
+ if (!(_ || j)) {
102
+ U(!0);
106
103
  try {
107
104
  await navigator.mediaDevices.getUserMedia({ audio: !0 });
108
- const e = Ue(), c = await p.getLiveKitToken(o, e);
109
- H(c.token);
105
+ const e = await u.getLiveKitToken(a);
106
+ H(e.token);
110
107
  } catch (e) {
111
- console.error("[useAvatarSession] Failed to connect:", e), j(!1);
108
+ console.error("[useAvatarSession] Failed to connect:", e), U(!1);
112
109
  }
113
110
  }
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;
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);
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();
113
+ }, [d]);
114
+ y(() => {
115
+ K.current = N;
116
+ }, [N]);
117
+ const ce = w(() => {
118
+ Q(!0), U(!1);
119
+ }, []), le = w(() => {
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
- }, [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}`;
123
+ }, [d]), de = w((e) => {
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
- w(() => () => {
131
- R.current && clearInterval(R.current);
127
+ y(() => () => {
128
+ I.current && clearInterval(I.current);
132
129
  }, []);
133
- const ue = S(
130
+ const ue = w(
134
131
  (e) => {
135
132
  if (!e) {
136
133
  C.current && (clearTimeout(C.current), C.current = null);
@@ -138,40 +135,40 @@ function $e(u) {
138
135
  }
139
136
  C.current || (C.current = setTimeout(() => {
140
137
  C.current = null, K.current();
141
- }, b));
138
+ }, x));
142
139
  },
143
- [b]
144
- ), pe = S(() => {
145
- ae((e) => !e);
146
- }, []), fe = S((e) => {
140
+ [x]
141
+ ), pe = w(() => {
142
+ oe((e) => !e);
143
+ }, []), fe = w((e) => {
147
144
  q(e);
148
- }, []), ge = S(() => {
145
+ }, []), ge = w(() => {
149
146
  q((e) => e > 0 ? 0 : 1);
150
- }, []), he = S(() => {
147
+ }, []), he = w(() => {
151
148
  i.current?.interrupt();
152
- }, []), me = S((e) => {
149
+ }, []), me = w((e) => {
153
150
  i.current?.play(e, "listening");
154
151
  }, []);
155
152
  return {
156
- containerRef: m,
153
+ containerRef: h,
157
154
  renderer: i.current,
158
- actionQueue: s.current,
159
- rendererState: I,
160
- avatarDimensions: r,
161
- loadedActions: L,
162
- actionMetadata: $,
155
+ actionQueue: c.current,
156
+ rendererState: R,
157
+ avatarDimensions: n,
158
+ loadedActions: E,
159
+ actionMetadata: D,
163
160
  isLoadingActions: te,
164
- isEngineReady: N,
161
+ isEngineReady: O,
165
162
  token: ne,
166
- isConnecting: P,
167
- isConnected: F,
163
+ isConnecting: _,
164
+ isConnected: j,
168
165
  livekitUrl: M,
169
166
  timeRemaining: re,
170
167
  formatTime: de,
171
168
  micMuted: ie,
172
- volume: oe,
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 $e(u) {
182
179
  setInactivityActive: ue
183
180
  };
184
181
  }
185
- const je = ({
186
- session: u,
187
- style: o,
182
+ const Fe = ({
183
+ session: S,
184
+ style: a,
188
185
  loadingContent: t
189
- }) => /* @__PURE__ */ y(
186
+ }) => /* @__PURE__ */ b(
190
187
  "div",
191
188
  {
192
189
  style: {
@@ -200,10 +197,10 @@ const je = ({
200
197
  justifyContent: "center",
201
198
  alignItems: "center",
202
199
  overflow: "hidden",
203
- ...o
200
+ ...a
204
201
  },
205
202
  children: [
206
- /* @__PURE__ */ n("style", { children: `
203
+ /* @__PURE__ */ r("style", { children: `
207
204
  @keyframes zwr-spin {
208
205
  from { transform: rotate(0deg); }
209
206
  to { transform: rotate(360deg); }
@@ -213,17 +210,17 @@ const je = ({
213
210
  50% { opacity: 0.5; }
214
211
  }
215
212
  ` }),
216
- /* @__PURE__ */ n(
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__ */ n(
223
+ children: !S.isEngineReady && /* @__PURE__ */ r(
227
224
  "div",
228
225
  {
229
226
  style: {
@@ -236,7 +233,7 @@ const je = ({
236
233
  backdropFilter: "blur(4px)",
237
234
  zIndex: 10
238
235
  },
239
- children: t || /* @__PURE__ */ y(
236
+ children: t || /* @__PURE__ */ b(
240
237
  "div",
241
238
  {
242
239
  style: {
@@ -246,8 +243,8 @@ const je = ({
246
243
  gap: 16
247
244
  },
248
245
  children: [
249
- /* @__PURE__ */ n(
250
- W,
246
+ /* @__PURE__ */ r(
247
+ V,
251
248
  {
252
249
  style: {
253
250
  width: 40,
@@ -257,7 +254,7 @@ const je = ({
257
254
  }
258
255
  }
259
256
  ),
260
- /* @__PURE__ */ n(
257
+ /* @__PURE__ */ r(
261
258
  "div",
262
259
  {
263
260
  style: {
@@ -280,7 +277,7 @@ const je = ({
280
277
  )
281
278
  ]
282
279
  }
283
- ), Y = {
280
+ ), G = {
284
281
  flexShrink: 0,
285
282
  borderRadius: 9999,
286
283
  padding: 16,
@@ -305,41 +302,41 @@ const je = ({
305
302
  transition: "all 0.3s",
306
303
  border: "none",
307
304
  cursor: "pointer"
308
- }, Pe = ({
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,
316
- isConnecting: l,
317
- isEngineReady: b,
312
+ isConnected: g,
313
+ isConnecting: d,
314
+ isEngineReady: x,
318
315
  loadedActions: M,
319
- connect: p,
320
- disconnect: m
321
- } = u, [k, i] = v(!1), [s, I] = v(!1), a = b && M.has("listening") && M.has("speaking"), r = 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
- ...k ? { background: "rgba(239,68,68,0.2)" } : {}
323
+ ...m ? { background: "rgba(239,68,68,0.2)" } : {}
327
324
  } : {
328
- ...Y,
329
- background: k ? "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
- }, d = h ? {
329
+ }, s = g ? {
333
330
  ...ee,
334
- background: s ? "rgba(239,68,68,0.22)" : "rgba(239,68,68,0.14)",
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)"
336
333
  } : {
337
334
  ...ee,
338
335
  background: "linear-gradient(to right, #7c3aed, #db2777, #f97316)",
339
336
  boxShadow: "0 0 30px rgba(236,72,153,0.3)",
340
- opacity: s ? 0.9 : 1
337
+ opacity: c ? 0.9 : 1
341
338
  };
342
- return (l || !a) && (d.opacity = 0.5, d.cursor = "not-allowed"), /* @__PURE__ */ y(
339
+ return (d || !o) && (s.opacity = 0.5, s.cursor = "not-allowed"), /* @__PURE__ */ b(
343
340
  "div",
344
341
  {
345
342
  style: {
@@ -350,16 +347,16 @@ const je = ({
350
347
  alignItems: "center",
351
348
  gap: 16,
352
349
  paddingBottom: 16,
353
- ...o
350
+ ...a
354
351
  },
355
352
  children: [
356
- /* @__PURE__ */ n("style", { children: `
353
+ /* @__PURE__ */ r("style", { children: `
357
354
  @keyframes zwr-spin {
358
355
  from { transform: rotate(0deg); }
359
356
  to { transform: rotate(360deg); }
360
357
  }
361
358
  ` }),
362
- /* @__PURE__ */ y(
359
+ /* @__PURE__ */ b(
363
360
  "div",
364
361
  {
365
362
  style: {
@@ -372,39 +369,39 @@ const je = ({
372
369
  pointerEvents: "auto"
373
370
  },
374
371
  children: [
375
- /* @__PURE__ */ n(
372
+ /* @__PURE__ */ r(
376
373
  "button",
377
374
  {
378
375
  type: "button",
379
376
  onClick: f,
380
377
  onMouseEnter: () => i(!0),
381
378
  onMouseLeave: () => i(!1),
382
- style: r,
379
+ style: n,
383
380
  title: t ? "Unmute mic" : "Mute mic",
384
- children: t ? /* @__PURE__ */ n(Ie, { size: 24 }) : /* @__PURE__ */ n(Ce, { size: 24 })
381
+ children: t ? /* @__PURE__ */ r(Re, { size: 24 }) : /* @__PURE__ */ r(Ce, { size: 24 })
385
382
  }
386
383
  ),
387
- /* @__PURE__ */ n(
384
+ /* @__PURE__ */ r(
388
385
  "button",
389
386
  {
390
387
  type: "button",
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" })
388
+ onClick: g ? h : u,
389
+ onMouseEnter: () => R(!0),
390
+ onMouseLeave: () => R(!1),
391
+ disabled: !g && (d || !o),
392
+ style: s,
393
+ children: d ? /* @__PURE__ */ b(P, { children: [
394
+ /* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
395
+ /* @__PURE__ */ r("span", { children: "Connecting..." })
396
+ ] }) : !g && !o ? /* @__PURE__ */ b(P, { children: [
397
+ /* @__PURE__ */ r(V, { size: 20, style: { animation: "zwr-spin 1s linear infinite" } }),
398
+ /* @__PURE__ */ r("span", { children: "Loading Avatar..." })
399
+ ] }) : g ? /* @__PURE__ */ b(P, { children: [
400
+ /* @__PURE__ */ r(Me, { size: 20 }),
401
+ /* @__PURE__ */ r("span", { children: "End Session" })
402
+ ] }) : /* @__PURE__ */ b(P, { children: [
403
+ /* @__PURE__ */ r(Ee, { size: 20 }),
404
+ /* @__PURE__ */ r("span", { children: "Start Session" })
408
405
  ] })
409
406
  }
410
407
  )
@@ -414,10 +411,10 @@ const je = ({
414
411
  ]
415
412
  }
416
413
  );
417
- }, Fe = ({
418
- session: u
414
+ }, _e = ({
415
+ session: S
419
416
  }) => {
420
- const { isConnected: o, timeRemaining: t, formatTime: f } = u, h = o && t <= 30, l = o && t > 30 && t <= 60, b = {
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,12 +424,12 @@ const je = ({
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)",
434
431
  animation: "zwr-pulse 2s ease-in-out infinite"
435
- } : l ? {
432
+ } : d ? {
436
433
  background: "rgba(249,115,22,0.2)",
437
434
  borderColor: "rgba(249,115,22,0.3)",
438
435
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
@@ -442,22 +439,22 @@ const je = ({
442
439
  boxShadow: "0 4px 12px rgba(0,0,0,0.3)"
443
440
  }
444
441
  };
445
- return /* @__PURE__ */ y(D, { children: [
446
- /* @__PURE__ */ n("style", { children: `
442
+ return /* @__PURE__ */ b(P, { children: [
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__ */ y("div", { style: b, children: [
453
- /* @__PURE__ */ n(
449
+ /* @__PURE__ */ b("div", { style: x, children: [
450
+ /* @__PURE__ */ r(
454
451
  "div",
455
452
  {
456
453
  style: {
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
  } : {
@@ -466,7 +463,7 @@ const je = ({
466
463
  }
467
464
  }
468
465
  ),
469
- /* @__PURE__ */ n(
466
+ /* @__PURE__ */ r(
470
467
  "span",
471
468
  {
472
469
  style: {
@@ -476,103 +473,120 @@ const je = ({
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: 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(() => {
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(() => {
486
+ R.current = x;
487
+ }, [x]), y(() => {
488
+ const n = m.localParticipant;
489
+ if (!a || !n) return;
490
+ const s = new TextEncoder();
491
+ return a.onOneshotComplete((L) => {
492
+ const D = s.encode(
493
+ JSON.stringify({
494
+ type: "ACTION_FINISHED",
495
+ action: L
496
+ })
497
+ );
498
+ n.publishData(D, {
499
+ reliable: !0
500
+ }).catch((F) => {
501
+ console.error("[LiveKitAvatarProvider] Failed to publish action completion:", F);
502
+ });
503
+ });
504
+ }, [a, m.localParticipant]), y(() => {
491
505
  if (!t) return;
492
- const r = new Se({
506
+ const n = new Se({
493
507
  threshold: 8e-3,
494
508
  analyseIntervalMs: 30,
495
509
  speechStartFrames: 1,
496
510
  speechPauseFrames: 30,
497
511
  turnEndFrames: 50
498
512
  });
499
- return s.current = r, r.on("speechStart", () => {
513
+ return c.current = n, n.on("speechStart", () => {
500
514
  t.setTurnActive(!0), t.setSpeechState("speaking");
501
- }), r.on("turnEnd", () => {
515
+ }), n.on("turnEnd", () => {
502
516
  t.setTurnActive(!1);
503
517
  }), () => {
504
- r.stop(), s.current = null;
518
+ n.stop(), c.current = null;
505
519
  };
506
- }, [t]), w(() => {
507
- const r = s.current;
508
- if (r)
509
- if (m?.publication?.track) {
510
- const d = m.publication.track.mediaStreamTrack;
511
- d && r.start(d);
520
+ }, [t]), y(() => {
521
+ const n = c.current;
522
+ if (n)
523
+ if (h?.publication?.track) {
524
+ const s = h.publication.track.mediaStreamTrack;
525
+ s && n.start(s);
512
526
  } else
513
- r.stop();
514
- }, [m?.publication?.track]);
515
- const a = x(null);
516
- return w(() => {
527
+ n.stop();
528
+ }, [h?.publication?.track]);
529
+ const o = A(null);
530
+ return y(() => {
517
531
  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);
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);
521
535
  }, 500)));
522
- }, [p, t]), w(() => () => {
523
- a.current && clearTimeout(a.current);
524
- }, []), Ae((r) => {
536
+ }, [u, t]), y(() => () => {
537
+ o.current && clearTimeout(o.current);
538
+ }, []), ke((n) => {
525
539
  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($))
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))
530
544
  return;
531
- t?.dispatch($);
545
+ t?.dispatch(D);
532
546
  }
533
- } catch (d) {
534
- console.error("[LiveKitAvatarProvider] Failed to parse data message:", d);
547
+ } catch (s) {
548
+ console.error("[LiveKitAvatarProvider] Failed to parse data message:", s);
535
549
  }
536
- }), w(() => {
537
- l(!(p === "speaking") && !i);
538
- }, [i, l, p]), w(() => {
550
+ }), y(() => {
551
+ d(!(u === "speaking") && !i);
552
+ }, [i, d, u]), y(() => {
539
553
  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);
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;
558
+ n && n.setMicrophoneEnabled(!f).catch((s) => {
559
+ console.error("[LiveKitAvatarProvider] Failed to set mic state:", s);
546
560
  });
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 }) });
548
- }, He = ({
549
- avatarId: u,
550
- 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,
551
565
  api: t,
552
566
  livekitUrl: f,
553
- sessionDuration: h,
554
- inactivityTimeout: l,
555
- style: b,
567
+ sessionDuration: g,
568
+ inactivityTimeout: d,
569
+ style: x,
556
570
  className: M,
557
- loadingContent: p,
558
- customControls: m,
559
- customStatusBadge: k
571
+ loadingContent: u,
572
+ customControls: h,
573
+ customStatusBadge: m
560
574
  }) => {
561
- const i = $e({
562
- avatarId: u,
563
- apiKey: o,
575
+ const i = Pe({
576
+ avatarId: S,
577
+ apiKey: a,
564
578
  api: t,
565
579
  livekitUrl: f,
566
- sessionDuration: h,
567
- inactivityTimeout: l
580
+ sessionDuration: g,
581
+ inactivityTimeout: d
568
582
  }), {
569
- token: s,
570
- isConnected: I,
571
- avatarDimensions: a,
572
- disconnect: r,
573
- startSessionTimer: d
583
+ token: c,
584
+ isConnected: R,
585
+ avatarDimensions: o,
586
+ disconnect: n,
587
+ startSessionTimer: s
574
588
  } = i;
575
- return /* @__PURE__ */ y(
589
+ return /* @__PURE__ */ b(
576
590
  "section",
577
591
  {
578
592
  className: M,
@@ -589,12 +603,12 @@ const je = ({
589
603
  height: "80vh",
590
604
  width: "auto",
591
605
  maxWidth: "100%",
592
- aspectRatio: a ? `${a.width} / ${a.height}` : "3 / 4",
593
- ...b
606
+ aspectRatio: o ? `${o.width} / ${o.height}` : "3 / 4",
607
+ ...x
594
608
  },
595
609
  children: [
596
- /* @__PURE__ */ n(je, { session: i, loadingContent: p }),
597
- /* @__PURE__ */ y(
610
+ /* @__PURE__ */ r(Fe, { session: i, loadingContent: u }),
611
+ /* @__PURE__ */ b(
598
612
  "div",
599
613
  {
600
614
  style: {
@@ -608,7 +622,7 @@ const je = ({
608
622
  padding: 16
609
623
  },
610
624
  children: [
611
- /* @__PURE__ */ y(
625
+ /* @__PURE__ */ b(
612
626
  "div",
613
627
  {
614
628
  style: {
@@ -618,28 +632,28 @@ const je = ({
618
632
  justifyContent: "space-between"
619
633
  },
620
634
  children: [
621
- k ? k(i) : /* @__PURE__ */ n(Fe, { session: i }),
622
- /* @__PURE__ */ n("div", {})
635
+ m ? m(i) : /* @__PURE__ */ r(_e, { session: i }),
636
+ /* @__PURE__ */ r("div", {})
623
637
  ]
624
638
  }
625
639
  ),
626
- m ? m(i) : /* @__PURE__ */ n(Pe, { session: i })
640
+ h ? h(i) : /* @__PURE__ */ r(Ue, { session: i })
627
641
  ]
628
642
  }
629
643
  ),
630
- /* @__PURE__ */ n("div", { style: { display: "none" }, children: s && f && /* @__PURE__ */ n(
631
- Re,
644
+ /* @__PURE__ */ r("div", { style: { display: "none" }, children: c && f && /* @__PURE__ */ r(
645
+ Ie,
632
646
  {
633
647
  serverUrl: f,
634
- token: s,
648
+ token: c,
635
649
  connect: !0,
636
650
  video: !1,
637
651
  audio: !0,
638
652
  onConnected: () => {
639
- i.markConnected(), d();
653
+ i.markConnected(), s();
640
654
  },
641
- onDisconnected: r,
642
- children: /* @__PURE__ */ n(_e, { session: i })
655
+ onDisconnected: n,
656
+ children: /* @__PURE__ */ r(je, { session: i })
643
657
  }
644
658
  ) })
645
659
  ]
@@ -647,11 +661,11 @@ const je = ({
647
661
  );
648
662
  };
649
663
  export {
650
- je as AvatarCanvas,
651
- Pe as AvatarControls,
652
- Fe as AvatarStatusBadge,
653
- _e as LiveKitAvatarProvider,
654
- He as LiveKitAvatarSession,
655
- $e 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
656
670
  };
657
671
  //# sourceMappingURL=zeroweight-renderer-react.es.js.map