@zeroweight/react 0.2.0 → 0.2.1

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