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