orb-ui 0.6.0 → 0.7.0
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 +29 -20
- package/dist/adapters/audio-level.d.ts +5 -0
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/livekit/browser.d.ts +5 -0
- package/dist/adapters/livekit/index.d.ts +9 -2
- package/dist/adapters/pipecat/index.d.ts +16 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +260 -241
- package/dist/components/Orb/Orb.types.d.ts +8 -4
- package/dist/components/Orb/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/livekit-CukEeYFK.js +316 -0
- package/dist/livekit-Dt-QZ6Gs.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -1
- package/dist/livekit-adapter.js +4 -2
- package/dist/orb-ui.cjs +93 -1
- package/dist/orb-ui.js +251 -28
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/radial/RadialTheme.d.ts +13 -0
- package/dist/themes/radial/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/livekit-Dasur3lv.js +0 -240
- package/dist/livekit-Ro6A52eb.cjs +0 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AriaAttributes, CSSProperties } from 'react';
|
|
2
|
+
export type OrbStyle = CSSProperties & {
|
|
3
|
+
/** Background color revealed around the radial theme's floating phone control. */
|
|
4
|
+
'--orb-ui-radial-control-surround'?: string;
|
|
5
|
+
};
|
|
2
6
|
export type OrbState = 'idle' | 'connecting' | 'listening' | 'thinking' | 'speaking' | 'error';
|
|
3
|
-
export type OrbTheme = 'debug' | 'circle' | 'bars' | 'cloud';
|
|
7
|
+
export type OrbTheme = 'debug' | 'circle' | 'bars' | 'cloud' | 'radial';
|
|
4
8
|
export interface OrbSignal {
|
|
5
9
|
state: OrbState;
|
|
6
10
|
volume?: number;
|
|
@@ -61,11 +65,11 @@ export interface OrbProps extends OrbHtmlAttributes {
|
|
|
61
65
|
/** Optional class name for the rendered orb container/control. */
|
|
62
66
|
className?: string;
|
|
63
67
|
/** Optional inline styles for the rendered orb container/control. */
|
|
64
|
-
style?:
|
|
65
|
-
/** Disable
|
|
68
|
+
style?: OrbStyle;
|
|
69
|
+
/** Disable interactive theme and debug start/stop controls. */
|
|
66
70
|
disabled?: boolean;
|
|
67
71
|
/**
|
|
68
|
-
* Allow the
|
|
72
|
+
* Allow the rendered theme control to start and stop an adapter-backed session.
|
|
69
73
|
* Set this to false when session controls live elsewhere in your UI.
|
|
70
74
|
*/
|
|
71
75
|
interactive?: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Orb } from './Orb.js';
|
|
2
|
-
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './Orb.types.js';
|
|
2
|
+
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbStyle, OrbTheme, } from './Orb.types.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Orb } from './components/Orb/index.js';
|
|
2
|
-
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './components/Orb/index.js';
|
|
2
|
+
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbStyle, OrbTheme, } from './components/Orb/index.js';
|
|
3
3
|
export { Orb as VoiceOrb } from './components/Orb/index.js';
|
|
4
4
|
export type { OrbProps as VoiceOrbProps } from './components/Orb/index.js';
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
//#region src/adapters/types.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = Math.min(e / .5, 1);
|
|
4
|
+
return t **= 1.3, t;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/adapters/audio-level.ts
|
|
8
|
+
var t = {
|
|
9
|
+
noiseFloor: 0,
|
|
10
|
+
gain: 4,
|
|
11
|
+
exponent: .8,
|
|
12
|
+
attack: 1,
|
|
13
|
+
release: 1
|
|
14
|
+
};
|
|
15
|
+
function n(e, t, n) {
|
|
16
|
+
return Math.min(n, Math.max(t, e));
|
|
17
|
+
}
|
|
18
|
+
function r(e, t) {
|
|
19
|
+
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
20
|
+
}
|
|
21
|
+
function i(e) {
|
|
22
|
+
let i = typeof e == "function" ? e() : e;
|
|
23
|
+
return {
|
|
24
|
+
noiseFloor: n(r(i?.noiseFloor, t.noiseFloor), 0, 1),
|
|
25
|
+
gain: Math.max(0, r(i?.gain, t.gain)),
|
|
26
|
+
exponent: Math.max(.01, r(i?.exponent, t.exponent)),
|
|
27
|
+
attack: n(r(i?.attack, t.attack), 0, 1),
|
|
28
|
+
release: n(r(i?.release, t.release), 0, 1)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function a(e, t, r) {
|
|
32
|
+
let a = Number.isFinite(e) ? n(e, 0, 1) : 0, o = i(r), s = n((a <= o.noiseFloor ? 0 : a - o.noiseFloor) * o.gain, 0, 1) ** +o.exponent, c = s > t ? o.attack : o.release;
|
|
33
|
+
return {
|
|
34
|
+
raw: a,
|
|
35
|
+
shaped: s,
|
|
36
|
+
normalized: n(t + (s - t) * c, 0, 1)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function o(e, t, n) {
|
|
40
|
+
let r;
|
|
41
|
+
try {
|
|
42
|
+
if (r = t(), !r) return;
|
|
43
|
+
let i = r;
|
|
44
|
+
i.state === "suspended" && i.resume().catch(() => void 0);
|
|
45
|
+
let a = i.createMediaStreamSource(new MediaStream([e])), o = i.createAnalyser();
|
|
46
|
+
o.fftSize = 512, o.smoothingTimeConstant = .25, a.connect(o);
|
|
47
|
+
let s = new Float32Array(o.fftSize), c = setInterval(() => {
|
|
48
|
+
o.getFloatTimeDomainData(s);
|
|
49
|
+
let e = 0;
|
|
50
|
+
for (let t of s) e += t * t;
|
|
51
|
+
n(Math.sqrt(e / s.length));
|
|
52
|
+
}, 33);
|
|
53
|
+
return { async stop() {
|
|
54
|
+
clearInterval(c);
|
|
55
|
+
try {
|
|
56
|
+
a.disconnect(), o.disconnect();
|
|
57
|
+
} finally {
|
|
58
|
+
i.state !== "closed" && await i.close();
|
|
59
|
+
}
|
|
60
|
+
} };
|
|
61
|
+
} catch {
|
|
62
|
+
r?.state !== "closed" && r?.close().catch(() => void 0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/adapters/livekit/index.ts
|
|
68
|
+
var s = 4, c = {
|
|
69
|
+
fftSize: 512,
|
|
70
|
+
smoothingTimeConstant: .25,
|
|
71
|
+
minDecibels: -85,
|
|
72
|
+
maxDecibels: -20
|
|
73
|
+
}, l = {
|
|
74
|
+
noiseFloor: .015,
|
|
75
|
+
gain: 4.6,
|
|
76
|
+
exponent: 1.15,
|
|
77
|
+
attack: .1,
|
|
78
|
+
release: .48
|
|
79
|
+
};
|
|
80
|
+
function u(e) {
|
|
81
|
+
switch (e) {
|
|
82
|
+
case "speaking": return "speaking";
|
|
83
|
+
case "thinking": return "thinking";
|
|
84
|
+
case "listening":
|
|
85
|
+
case "idle": return "listening";
|
|
86
|
+
case "connecting":
|
|
87
|
+
case "pre-connect-buffering":
|
|
88
|
+
case "initializing": return "connecting";
|
|
89
|
+
case "disconnected": return "idle";
|
|
90
|
+
case "failed": return "error";
|
|
91
|
+
default: return "idle";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function d(e) {
|
|
95
|
+
return "RoomClass" in e;
|
|
96
|
+
}
|
|
97
|
+
function f(e) {
|
|
98
|
+
return typeof e == "function" ? e() : e;
|
|
99
|
+
}
|
|
100
|
+
function p(e) {
|
|
101
|
+
if (!e) return {};
|
|
102
|
+
let t = {}, n = (e, n) => {
|
|
103
|
+
n !== void 0 && (t[e] = n);
|
|
104
|
+
};
|
|
105
|
+
return n("roomName", f(e.roomName)), n("participantName", f(e.participantName)), n("participantIdentity", f(e.participantIdentity)), n("participantMetadata", f(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", f(e.agentName)), n("agentMetadata", f(e.agentMetadata)), n("deployment", f(e.deployment)), t;
|
|
106
|
+
}
|
|
107
|
+
function m(e) {
|
|
108
|
+
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
109
|
+
return e;
|
|
110
|
+
}
|
|
111
|
+
async function h(e) {
|
|
112
|
+
let t = p(e.tokenOptions);
|
|
113
|
+
return typeof e.getConnectionDetails == "function" ? m(await e.getConnectionDetails(t)) : e.tokenSource ? m(await e.tokenSource.fetch(t)) : m({
|
|
114
|
+
serverUrl: e.serverUrl,
|
|
115
|
+
participantToken: e.participantToken
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function g(e) {
|
|
119
|
+
for (let [, t] of e.remoteParticipants) if (!t.isLocal && (t.kind === s || t.attributes?.["lk.agent.state"] !== void 0)) return t;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
function _(e, t, n) {
|
|
123
|
+
let r = e.off;
|
|
124
|
+
if (r) {
|
|
125
|
+
r.call(e, t, n);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
e.removeListener?.call(e, t, n);
|
|
129
|
+
}
|
|
130
|
+
function v(e, t, n) {
|
|
131
|
+
e.on.call(e, t, n);
|
|
132
|
+
}
|
|
133
|
+
function y(t) {
|
|
134
|
+
let n = d(t), r = t.createAudioAnalyser, i = { current: n ? null : t.room }, o = /* @__PURE__ */ new Set(), f = {
|
|
135
|
+
state: "idle",
|
|
136
|
+
volume: 0,
|
|
137
|
+
inputVolume: 0,
|
|
138
|
+
outputVolume: 0
|
|
139
|
+
}, p = "idle", m = null, y = null, b = null, x = null, S = null, C = null, w = null, T = 0, E = null;
|
|
140
|
+
function D(e) {
|
|
141
|
+
f = e, o.forEach((t) => t(e));
|
|
142
|
+
}
|
|
143
|
+
function O(e) {
|
|
144
|
+
D({
|
|
145
|
+
...f,
|
|
146
|
+
...e,
|
|
147
|
+
state: e.state ?? f.state
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function k() {
|
|
151
|
+
let e = typeof t.outputVolumeCalibration == "function" ? t.outputVolumeCalibration() : t.outputVolumeCalibration;
|
|
152
|
+
return {
|
|
153
|
+
...l,
|
|
154
|
+
...e
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function A(e) {
|
|
158
|
+
let n = a(e, T, k);
|
|
159
|
+
return T = n.normalized, t.onOutputVolumeSample?.(n), n.normalized;
|
|
160
|
+
}
|
|
161
|
+
function j() {
|
|
162
|
+
T = 0, O({
|
|
163
|
+
volume: 0,
|
|
164
|
+
outputVolume: 0
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function M({ emitZero: e = !0 } = {}) {
|
|
168
|
+
S &&= (clearInterval(S), null), x &&= (x.cleanup().catch(() => {}), null), e && O({
|
|
169
|
+
volume: 0,
|
|
170
|
+
inputVolume: 0
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function N(t) {
|
|
174
|
+
if (!(m === t && x)) {
|
|
175
|
+
M({ emitZero: !1 }), m = t;
|
|
176
|
+
try {
|
|
177
|
+
x = r(t, c);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
S = setInterval(() => {
|
|
183
|
+
if (!x || p !== "listening") return;
|
|
184
|
+
let t = e(x.calculateVolume());
|
|
185
|
+
O({
|
|
186
|
+
volume: t,
|
|
187
|
+
inputVolume: t,
|
|
188
|
+
outputVolume: 0
|
|
189
|
+
});
|
|
190
|
+
}, 33);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function P({ emitZero: e = !0 } = {}) {
|
|
194
|
+
w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), T = 0, e && O({
|
|
195
|
+
volume: 0,
|
|
196
|
+
outputVolume: 0
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function F(e) {
|
|
200
|
+
P();
|
|
201
|
+
try {
|
|
202
|
+
C = r(e, c);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
w = setInterval(() => {
|
|
208
|
+
if (!C || p !== "speaking") return;
|
|
209
|
+
let e = A(C.calculateVolume());
|
|
210
|
+
O({
|
|
211
|
+
volume: e,
|
|
212
|
+
inputVolume: 0,
|
|
213
|
+
outputVolume: e
|
|
214
|
+
});
|
|
215
|
+
}, 33);
|
|
216
|
+
}
|
|
217
|
+
function I(e) {
|
|
218
|
+
p = e, O({
|
|
219
|
+
state: e,
|
|
220
|
+
volume: 0,
|
|
221
|
+
inputVolume: 0,
|
|
222
|
+
outputVolume: 0
|
|
223
|
+
}), e === "speaking" && y ? F(y) : e !== "speaking" && P({ emitZero: !1 });
|
|
224
|
+
}
|
|
225
|
+
function L(e) {
|
|
226
|
+
b || typeof document > "u" || (b = e.attach(), b.id = "orb-ui-livekit-agent-audio", document.body.appendChild(b));
|
|
227
|
+
}
|
|
228
|
+
function R() {
|
|
229
|
+
b &&= (b.remove(), null);
|
|
230
|
+
}
|
|
231
|
+
function z(e) {
|
|
232
|
+
y = e, L(e), p === "speaking" && F(e);
|
|
233
|
+
}
|
|
234
|
+
function B(e) {
|
|
235
|
+
N(e);
|
|
236
|
+
}
|
|
237
|
+
function V(e) {
|
|
238
|
+
let t = e.getTrackPublication?.("microphone");
|
|
239
|
+
t?.track && B(t.track);
|
|
240
|
+
}
|
|
241
|
+
function H(e) {
|
|
242
|
+
let t = u(e);
|
|
243
|
+
t !== p && I(t);
|
|
244
|
+
}
|
|
245
|
+
function U(e) {
|
|
246
|
+
let t = e.attributes?.["lk.agent.state"];
|
|
247
|
+
t && H(t);
|
|
248
|
+
let n = e.getTrackPublication("microphone");
|
|
249
|
+
n?.track && z(n.track);
|
|
250
|
+
}
|
|
251
|
+
function W(e) {
|
|
252
|
+
if (E) return;
|
|
253
|
+
let t = (e, t) => {
|
|
254
|
+
if (t.isLocal) return;
|
|
255
|
+
let n = e["lk.agent.state"];
|
|
256
|
+
n && H(n);
|
|
257
|
+
}, n = (e, t, n) => {
|
|
258
|
+
n.isLocal || !(n.kind === s || n.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || z(e);
|
|
259
|
+
}, r = (e) => {
|
|
260
|
+
y === e && (y = null, R(), P());
|
|
261
|
+
}, i = (e) => {
|
|
262
|
+
e.source !== "microphone" || !e.track || B(e.track);
|
|
263
|
+
}, a = (e) => {
|
|
264
|
+
e.source === "microphone" && (m = null, M());
|
|
265
|
+
}, o = () => {
|
|
266
|
+
m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), I("idle");
|
|
267
|
+
};
|
|
268
|
+
if (v(e, "participantAttributesChanged", t), v(e, "trackSubscribed", n), v(e, "trackUnsubscribed", r), v(e, "localTrackPublished", i), v(e, "localTrackUnpublished", a), v(e, "disconnected", o), E = () => {
|
|
269
|
+
_(e, "participantAttributesChanged", t), _(e, "trackSubscribed", n), _(e, "trackUnsubscribed", r), _(e, "localTrackPublished", i), _(e, "localTrackUnpublished", a), _(e, "disconnected", o);
|
|
270
|
+
}, V(e.localParticipant), e.state === "connected") {
|
|
271
|
+
let t = g(e);
|
|
272
|
+
t ? U(t) : I("connecting");
|
|
273
|
+
} else I("idle");
|
|
274
|
+
}
|
|
275
|
+
function G() {
|
|
276
|
+
E?.(), E = null, m = null, y = null, R(), M({ emitZero: !1 }), P({ emitZero: !1 }), O({
|
|
277
|
+
volume: 0,
|
|
278
|
+
inputVolume: 0,
|
|
279
|
+
outputVolume: 0
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
let K = (e) => {
|
|
283
|
+
o.add(e), e(f);
|
|
284
|
+
let t = i.current;
|
|
285
|
+
return t && W(t), () => {
|
|
286
|
+
o.delete(e), o.size === 0 && G();
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
return n ? {
|
|
290
|
+
subscribe: K,
|
|
291
|
+
async start() {
|
|
292
|
+
if (i.current) return;
|
|
293
|
+
let e = t, n = new e.RoomClass();
|
|
294
|
+
I("connecting");
|
|
295
|
+
try {
|
|
296
|
+
let t = await h(e);
|
|
297
|
+
if (await n.connect(t.serverUrl, t.participantToken, e.connectOptions), i.current = n, W(n), e.enableMicrophone !== !1) {
|
|
298
|
+
let e = (await n.localParticipant.setMicrophoneEnabled(!0))?.track ?? n.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
299
|
+
e && B(e);
|
|
300
|
+
}
|
|
301
|
+
} catch (e) {
|
|
302
|
+
throw console.error("[orb-ui/livekit] connect failed:", e), i.current === n && G(), n.disconnect(), i.current = null, I("error"), j(), O({ error: e }), e;
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
async stop() {
|
|
306
|
+
let e = i.current;
|
|
307
|
+
if (!e) {
|
|
308
|
+
I("idle");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
G(), e.disconnect(), i.current = null, I("idle");
|
|
312
|
+
}
|
|
313
|
+
} : { subscribe: K };
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
export { o as i, t as n, a as r, y as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t={noiseFloor:0,gain:4,exponent:.8,attack:1,release:1};function n(e,t,n){return Math.min(n,Math.max(t,e))}function r(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function i(e){let i=typeof e==`function`?e():e;return{noiseFloor:n(r(i?.noiseFloor,t.noiseFloor),0,1),gain:Math.max(0,r(i?.gain,t.gain)),exponent:Math.max(.01,r(i?.exponent,t.exponent)),attack:n(r(i?.attack,t.attack),0,1),release:n(r(i?.release,t.release),0,1)}}function a(e,t,r){let a=Number.isFinite(e)?n(e,0,1):0,o=i(r),s=n((a<=o.noiseFloor?0:a-o.noiseFloor)*o.gain,0,1)**+o.exponent,c=s>t?o.attack:o.release;return{raw:a,shaped:s,normalized:n(t+(s-t)*c,0,1)}}function o(e,t,n){let r;try{if(r=t(),!r)return;let i=r;i.state===`suspended`&&i.resume().catch(()=>void 0);let a=i.createMediaStreamSource(new MediaStream([e])),o=i.createAnalyser();o.fftSize=512,o.smoothingTimeConstant=.25,a.connect(o);let s=new Float32Array(o.fftSize),c=setInterval(()=>{o.getFloatTimeDomainData(s);let e=0;for(let t of s)e+=t*t;n(Math.sqrt(e/s.length))},33);return{async stop(){clearInterval(c);try{a.disconnect(),o.disconnect()}finally{i.state!==`closed`&&await i.close()}}}}catch{r?.state!==`closed`&&r?.close().catch(()=>void 0);return}}var s=4,c={fftSize:512,smoothingTimeConstant:.25,minDecibels:-85,maxDecibels:-20},l={noiseFloor:.015,gain:4.6,exponent:1.15,attack:.1,release:.48};function u(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function d(e){return`RoomClass`in e}function f(e){return typeof e==`function`?e():e}function p(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,f(e.roomName)),n(`participantName`,f(e.participantName)),n(`participantIdentity`,f(e.participantIdentity)),n(`participantMetadata`,f(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,f(e.agentName)),n(`agentMetadata`,f(e.agentMetadata)),n(`deployment`,f(e.deployment)),t}function m(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function h(e){let t=p(e.tokenOptions);return typeof e.getConnectionDetails==`function`?m(await e.getConnectionDetails(t)):e.tokenSource?m(await e.tokenSource.fetch(t)):m({serverUrl:e.serverUrl,participantToken:e.participantToken})}function g(e){for(let[,t]of e.remoteParticipants)if(!t.isLocal&&(t.kind===s||t.attributes?.[`lk.agent.state`]!==void 0))return t;return null}function _(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function v(e,t,n){e.on.call(e,t,n)}function y(t){let n=d(t),r=t.createAudioAnalyser,i={current:n?null:t.room},o=new Set,f={state:`idle`,volume:0,inputVolume:0,outputVolume:0},p=`idle`,m=null,y=null,b=null,x=null,S=null,C=null,w=null,T=0,E=null;function D(e){f=e,o.forEach(t=>t(e))}function O(e){D({...f,...e,state:e.state??f.state})}function k(){let e=typeof t.outputVolumeCalibration==`function`?t.outputVolumeCalibration():t.outputVolumeCalibration;return{...l,...e}}function A(e){let n=a(e,T,k);return T=n.normalized,t.onOutputVolumeSample?.(n),n.normalized}function j(){T=0,O({volume:0,outputVolume:0})}function M({emitZero:e=!0}={}){S&&=(clearInterval(S),null),x&&=(x.cleanup().catch(()=>{}),null),e&&O({volume:0,inputVolume:0})}function N(t){if(!(m===t&&x)){M({emitZero:!1}),m=t;try{x=r(t,c)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}S=setInterval(()=>{if(!x||p!==`listening`)return;let t=e(x.calculateVolume());O({volume:t,inputVolume:t,outputVolume:0})},33)}}function P({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),T=0,e&&O({volume:0,outputVolume:0})}function F(e){P();try{C=r(e,c)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||p!==`speaking`)return;let e=A(C.calculateVolume());O({volume:e,inputVolume:0,outputVolume:e})},33)}function I(e){p=e,O({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&y?F(y):e!==`speaking`&&P({emitZero:!1})}function L(e){b||typeof document>`u`||(b=e.attach(),b.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(b))}function R(){b&&=(b.remove(),null)}function z(e){y=e,L(e),p===`speaking`&&F(e)}function B(e){N(e)}function V(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&B(t.track)}function H(e){let t=u(e);t!==p&&I(t)}function U(e){let t=e.attributes?.[`lk.agent.state`];t&&H(t);let n=e.getTrackPublication(`microphone`);n?.track&&z(n.track)}function W(e){if(E)return;let t=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&H(n)},n=(e,t,n)=>{n.isLocal||!(n.kind===s||n.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||z(e)},r=e=>{y===e&&(y=null,R(),P())},i=e=>{e.source!==`microphone`||!e.track||B(e.track)},a=e=>{e.source===`microphone`&&(m=null,M())},o=()=>{m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),I(`idle`)};if(v(e,`participantAttributesChanged`,t),v(e,`trackSubscribed`,n),v(e,`trackUnsubscribed`,r),v(e,`localTrackPublished`,i),v(e,`localTrackUnpublished`,a),v(e,`disconnected`,o),E=()=>{_(e,`participantAttributesChanged`,t),_(e,`trackSubscribed`,n),_(e,`trackUnsubscribed`,r),_(e,`localTrackPublished`,i),_(e,`localTrackUnpublished`,a),_(e,`disconnected`,o)},V(e.localParticipant),e.state===`connected`){let t=g(e);t?U(t):I(`connecting`)}else I(`idle`)}function G(){E?.(),E=null,m=null,y=null,R(),M({emitZero:!1}),P({emitZero:!1}),O({volume:0,inputVolume:0,outputVolume:0})}let K=e=>{o.add(e),e(f);let t=i.current;return t&&W(t),()=>{o.delete(e),o.size===0&&G()}};return n?{subscribe:K,async start(){if(i.current)return;let e=t,n=new e.RoomClass;I(`connecting`);try{let t=await h(e);if(await n.connect(t.serverUrl,t.participantToken,e.connectOptions),i.current=n,W(n),e.enableMicrophone!==!1){let e=(await n.localParticipant.setMicrophoneEnabled(!0))?.track??n.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&B(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),i.current===n&&G(),n.disconnect(),i.current=null,I(`error`),j(),O({error:e}),e}},async stop(){let e=i.current;if(!e){I(`idle`);return}G(),e.disconnect(),i.current=null,I(`idle`)}}:{subscribe:K}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});
|
package/dist/livekit-adapter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-Dt-QZ6Gs.cjs");let t=require("livekit-client");function n(){return`orb-${globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random().toString(36).slice(2)}`}`}function r(r){let{agentMetadata:i,agentName:a,connectOptions:o,deployment:s,enableMicrophone:c,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p=n,outputVolumeCalibration:m,onOutputVolumeSample:h}=r;return e.t({tokenSource:r.tokenEndpoint===void 0?t.TokenSource.sandboxTokenServer(r.sandboxId,r.sandboxOptions):t.TokenSource.endpoint(r.tokenEndpoint,r.tokenEndpointOptions),tokenOptions:{agentMetadata:i,agentName:a,deployment:s,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p},connectOptions:o,enableMicrophone:c,outputVolumeCalibration:m,onOutputVolumeSample:h,createAudioAnalyser:t.createAudioAnalyser,RoomClass:t.Room})}exports.createLiveKitAdapter=r;
|
package/dist/livekit-adapter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as e } from "./livekit-
|
|
1
|
+
import { t as e } from "./livekit-CukEeYFK.js";
|
|
2
2
|
import { Room as t, TokenSource as n, createAudioAnalyser as r } from "livekit-client";
|
|
3
3
|
//#region src/adapters/livekit/browser.ts
|
|
4
4
|
function i() {
|
|
5
5
|
return `orb-${globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`}`;
|
|
6
6
|
}
|
|
7
7
|
function a(a) {
|
|
8
|
-
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i } = a;
|
|
8
|
+
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i, outputVolumeCalibration: g, onOutputVolumeSample: _ } = a;
|
|
9
9
|
return e({
|
|
10
10
|
tokenSource: a.tokenEndpoint === void 0 ? n.sandboxTokenServer(a.sandboxId, a.sandboxOptions) : n.endpoint(a.tokenEndpoint, a.tokenEndpointOptions),
|
|
11
11
|
tokenOptions: {
|
|
@@ -20,6 +20,8 @@ function a(a) {
|
|
|
20
20
|
},
|
|
21
21
|
connectOptions: c,
|
|
22
22
|
enableMicrophone: u,
|
|
23
|
+
outputVolumeCalibration: g,
|
|
24
|
+
onOutputVolumeSample: _,
|
|
23
25
|
createAudioAnalyser: r,
|
|
24
26
|
RoomClass: t
|
|
25
27
|
});
|
package/dist/orb-ui.cjs
CHANGED
|
@@ -108,4 +108,96 @@ void main() {
|
|
|
108
108
|
|
|
109
109
|
gl_FragColor = vec4(color, edge);
|
|
110
110
|
}
|
|
111
|
-
`,A=.55,j=.204,M=.2145,N=.063,P=`#5659dc`,F=1.178,I=180,L=300,R=1350,z=246,B=420,V=354,
|
|
111
|
+
`,A=.55,j=.204,M=.2145,N=.063,P=`#5659dc`,F=1.178,I=180,L=300,R=1350,z=246,B=420,V=354,ee=480;function H(e,t=0,n=1){return Math.min(n,Math.max(t,e))}function U(e,t,n,r){return e+(t-e)*(1-Math.exp(-n*r))}function W(e){return 1-(1-e)**3}function G(e,t,n){return e+(t-e)*n}function K(e,t,n){let r=H((e-t)/(n-t));return r*r*(3-2*r)}function q(e){return e===`listening`||e===`speaking`||e===`thinking`}function J(e,t,n){let r=e.createShader(t);if(r){if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){e.deleteShader(r);return}return r}}function Y(e,t){let n=e.getContext(`webgl`,{alpha:!0,antialias:!0,premultipliedAlpha:!0});if(!n)return;let r=J(n,n.VERTEX_SHADER,O),i=J(n,n.FRAGMENT_SHADER,k);if(!r||!i){r&&n.deleteShader(r),i&&n.deleteShader(i);return}let a=n.createProgram(),o=n.createBuffer();if(!a||!o){a&&n.deleteProgram(a),o&&n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}if(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS)){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}let s=n.getAttribLocation(a,`a_position`),c=n.getUniformLocation(a,`u_resolution`),l=n.getUniformLocation(a,`u_time`),u=n.getUniformLocation(a,`u_activity`);if(s<0||!c||!l||!u){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}let d=Math.min(window.devicePixelRatio||1,2),f=Math.max(1,Math.round(t*d));return e.width=f,e.height=f,n.viewport(0,0,f,f),n.useProgram(a),n.bindBuffer(n.ARRAY_BUFFER,o),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.uniform2f(c,f,f),{draw(e,t){n.uniform1f(l,e),n.uniform1f(u,t),n.drawArrays(n.TRIANGLES,0,6)},destroy(){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i)}}}function te(e){if(e<=I)return N;if(e<=480)return G(N,F,W((e-I)/L));let t=e-I-L;if(t>=R)return 1;let n=H(t/R);return 1+(F-1)*(1-n)**2}function ne({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:c=!1,onClick:l,...u}){let d=(0,e.useRef)(null),f=(0,e.useRef)(null),p=(0,e.useRef)(null),m=(0,e.useRef)(n),h=(0,e.useRef)(r),g=(0,e.useRef)(c),_=(0,e.useRef)(!1);D(()=>{m.current=n,h.current=r,g.current=c},[c,n,r]);let v=i*A;(0,e.useEffect)(()=>{let e=d.current,t=f.current,n=p.current;if(!e||!t||!n)return;let r=window.matchMedia(`(prefers-reduced-motion: reduce)`),i=()=>{_.current=r.matches};i(),r.addEventListener(`change`,i);let a=Y(e,v);a||(e.style.background=`linear-gradient(180deg, #626afb 2%, #8f9dfb 32%, #dde6fd 52%, #c9d3fb 84%)`);let o=0,s=performance.now(),c=m.current,l=q(c)?s:void 0,u=H(h.current),y=1,b=+!!q(c),x=1,S=+(c===`connecting`),C=0,w=r=>{let i=Math.min((r-s)/1e3,.05);s=r;let d=m.current,f=_.current;d!==c&&(q(d)&&!q(c)&&(l=r),(d===`idle`||d===`error`)&&(l=void 0),c=d);let p=H(h.current);u=f?0:U(u,p,p>u?11:6,i);let v=1;d===`listening`&&(v=1-u*j),d===`speaking`&&(v=1+u*M);let T=Math.abs(v-1)>Math.abs(y-1)?12:6;y=f?1:U(y,v,T,i);let E=q(d),D=d===`idle`&&g.current,O=E||D?1:0;b=f?O:U(b,O,14,i);let k=E||D?1:.92;x=f?k:U(x,k,12,i);let A=y*x;D&&(A=N);let P=+!D,F=D?b:0;if(E&&l!==void 0&&!f){let e=r-l,t=te(e),n=H((e-I-L)/R);A=t*G(1,y,n),P=K(e,z,B),F=b*(1-K(e,V,ee)),e>=1830&&(l=void 0)}let W=+(d===`connecting`);S=f?W:U(S,W,18,i),e.style.opacity=String(b*P),e.style.transform=`scale(${A})`,t.style.opacity=String(F),t.style.transform=`scale(${A})`,n.style.opacity=String(S),n.style.transform=`rotate(${f?45:r*.34}deg)`;let J=.24,Y=.1;d===`listening`?(J=.72+u*.78,Y=.28+u*.32):d===`speaking`&&(J=1.65+u*1.55,Y=.66+u*.34),f||(C+=i*J),a?.draw(C,Y),o=requestAnimationFrame(w)};return o=requestAnimationFrame(w),()=>{cancelAnimationFrame(o),r.removeEventListener(`change`,i),a?.destroy()}},[v]);let y={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},b=(0,t.jsxs)(`span`,{style:{position:`relative`,display:`block`,width:v,height:v,borderRadius:`50%`,lineHeight:0,cursor:c?s?`not-allowed`:`pointer`:`default`},children:[(0,t.jsx)(`span`,{ref:f,"data-cloud-launch-dot":``,"aria-hidden":`true`,style:{position:`absolute`,inset:0,display:`block`,borderRadius:`50%`,background:P,opacity:0,transform:`scale(${N})`,transformOrigin:`center`,willChange:`opacity, transform`}}),(0,t.jsx)(`canvas`,{ref:d,"aria-hidden":`true`,style:{position:`absolute`,inset:0,display:`block`,width:v,height:v,borderRadius:`50%`,opacity:0,transform:`scale(${N})`,transformOrigin:`center`,willChange:`opacity, transform`}}),(0,t.jsx)(`span`,{ref:p,"aria-hidden":`true`,style:{position:`absolute`,left:`50%`,top:`50%`,width:v*.105,height:v*.105,boxSizing:`border-box`,border:`${Math.max(1.5,v*.012)}px solid rgba(113, 120, 245, 0.24)`,borderTopColor:`#777ff6`,borderRightColor:`#777ff6`,borderRadius:`50%`,opacity:0,transform:`rotate(0deg)`,transformOrigin:`center`,marginLeft:v*-.0525,marginTop:v*-.0525,willChange:`opacity, transform`}})]});return c?(0,t.jsx)(`button`,{...u,type:`button`,className:a,disabled:s,onClick:s?void 0:l,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:s?`not-allowed`:`pointer`,...y},children:b}):(0,t.jsx)(`div`,{...u,className:a,style:y,children:b})}var re=typeof window<`u`?e.useLayoutEffect:e.useEffect,ie=`
|
|
112
|
+
attribute vec2 a_position;
|
|
113
|
+
|
|
114
|
+
void main() {
|
|
115
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
116
|
+
}
|
|
117
|
+
`,ae=`
|
|
118
|
+
precision highp float;
|
|
119
|
+
|
|
120
|
+
uniform vec2 u_resolution;
|
|
121
|
+
uniform float u_time;
|
|
122
|
+
uniform float u_rotation;
|
|
123
|
+
uniform float u_listen;
|
|
124
|
+
uniform float u_speak;
|
|
125
|
+
|
|
126
|
+
void main() {
|
|
127
|
+
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
128
|
+
vec2 p = (uv - 0.5) * 2.0;
|
|
129
|
+
float radius = length(p);
|
|
130
|
+
float edge = 1.0 - smoothstep(0.993, 1.0, radius);
|
|
131
|
+
|
|
132
|
+
if (edge <= 0.0) discard;
|
|
133
|
+
|
|
134
|
+
float angle = atan(p.y, p.x);
|
|
135
|
+
float warpStrength = 0.026 + u_speak * 0.105;
|
|
136
|
+
float angularWarp =
|
|
137
|
+
sin(angle * 3.0 - u_time * 0.54 + radius * 2.1) +
|
|
138
|
+
0.48 * sin(angle * 5.0 + u_time * 0.31 - radius * 3.7) +
|
|
139
|
+
0.22 * sin(angle * 8.0 - u_time * 0.19 + radius * 5.2);
|
|
140
|
+
float phase =
|
|
141
|
+
angle - 1.78 - u_rotation + angularWarp * warpStrength * (0.2 + radius * 0.8);
|
|
142
|
+
|
|
143
|
+
// Two opposing dark lobes and two opposing aqua lobes form the main pinwheel.
|
|
144
|
+
float lobeField = cos(phase * 2.0);
|
|
145
|
+
float darkMix = smoothstep(-0.04, 0.38, lobeField);
|
|
146
|
+
|
|
147
|
+
vec3 deepBlue = vec3(0.004, 0.105, 0.37);
|
|
148
|
+
vec3 cobalt = vec3(0.015, 0.34, 0.76);
|
|
149
|
+
vec3 aqua = vec3(0.24, 0.76, 0.79);
|
|
150
|
+
vec3 paleAqua = vec3(0.77, 0.96, 0.95);
|
|
151
|
+
|
|
152
|
+
float radialLight = 0.5 + 0.5 * sin(radius * 3.0 - u_time * 0.16);
|
|
153
|
+
vec3 darkColor = mix(cobalt, deepBlue, 0.42 + 0.38 * radius);
|
|
154
|
+
float darkRay = pow(max(lobeField, 0.0), 11.0);
|
|
155
|
+
darkColor = mix(darkColor, aqua, darkRay * (0.18 + radialLight * 0.16));
|
|
156
|
+
|
|
157
|
+
vec3 lightColor = mix(paleAqua, aqua, 0.5 + 0.2 * sin(radius * 3.4 + phase * 2.0));
|
|
158
|
+
float lightRay = pow(max(-lobeField, 0.0), 5.0);
|
|
159
|
+
lightColor = mix(lightColor, vec3(0.04, 0.42, 0.64), lightRay * 0.28);
|
|
160
|
+
|
|
161
|
+
vec3 color = mix(lightColor, darkColor, darkMix);
|
|
162
|
+
|
|
163
|
+
// Soft secondary streaks make each of the four lobes feel layered rather than flat.
|
|
164
|
+
float secondaryRay = 0.5 + 0.5 * sin(phase * 6.0 + radius * 1.8 - u_time * 0.42);
|
|
165
|
+
float rayStrength = (0.055 + u_speak * 0.045) * (0.25 + radius * 0.75);
|
|
166
|
+
color = mix(color, vec3(0.26, 0.76, 0.8), secondaryRay * rayStrength);
|
|
167
|
+
|
|
168
|
+
// The outer membrane keeps a circular perimeter while independent traveling waves
|
|
169
|
+
// continuously reshape its inner boundary.
|
|
170
|
+
float rimWave =
|
|
171
|
+
0.063 * sin(angle * 3.0 + u_time * 1.34) +
|
|
172
|
+
0.036 * sin(angle * 5.0 - u_time * 0.91 + 1.4) +
|
|
173
|
+
0.021 * sin(angle * 7.0 + u_time * 0.63 - 0.8) +
|
|
174
|
+
0.012 * sin(angle * 11.0 - u_time * 1.72 + sin(angle * 2.0 + u_time * 0.58));
|
|
175
|
+
rimWave *= 1.0 + u_listen * 0.38;
|
|
176
|
+
float rimInner = 0.82 + rimWave - u_listen * 0.2;
|
|
177
|
+
float rim = smoothstep(rimInner - 0.02, rimInner + 0.015, radius);
|
|
178
|
+
float rimStrength = rim * (0.3 + u_listen * 0.3);
|
|
179
|
+
vec3 membrane = mix(
|
|
180
|
+
vec3(0.47, 0.84, 0.84),
|
|
181
|
+
vec3(0.76, 0.93, 0.92),
|
|
182
|
+
smoothstep(0.78, 1.0, radius)
|
|
183
|
+
);
|
|
184
|
+
color = mix(color, membrane, clamp(rimStrength, 0.0, 0.72));
|
|
185
|
+
|
|
186
|
+
// Only one transition direction becomes a bright seam, producing two opposing ribbons.
|
|
187
|
+
float seamDirection = max(0.0, -sin(phase * 2.0));
|
|
188
|
+
float seamExponent = mix(30.0, 3.2, smoothstep(0.05, 1.0, radius));
|
|
189
|
+
float seam = pow(seamDirection, seamExponent) * (0.78 + radius * 0.25);
|
|
190
|
+
color = mix(color, vec3(0.985, 0.995, 0.995), clamp(seam, 0.0, 0.96));
|
|
191
|
+
|
|
192
|
+
// The drawing buffer uses premultiplied alpha. Premultiply the antialiased
|
|
193
|
+
// perimeter so translucent edge pixels cannot become a bright outline.
|
|
194
|
+
gl_FragColor = vec4(color * edge, edge);
|
|
195
|
+
}
|
|
196
|
+
`,oe=`
|
|
197
|
+
@keyframes orb-radial-spinner {
|
|
198
|
+
to { transform: rotate(360deg); }
|
|
199
|
+
}
|
|
200
|
+
@media (prefers-reduced-motion: reduce) {
|
|
201
|
+
[data-radial-spinner] { animation: none !important; }
|
|
202
|
+
}
|
|
203
|
+
`,se=.66,ce=.2;function X(e,t=0,n=1){return Math.min(n,Math.max(t,e))}function Z(e,t,n,r){return e+(t-e)*(1-Math.exp(-n*r))}function Q(e,t,n){let r=e.createShader(t);if(r){if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){e.deleteShader(r);return}return r}}function le(e,t){let n=e.getContext(`webgl`,{alpha:!0,antialias:!0,premultipliedAlpha:!0});if(!n)return;let r=Q(n,n.VERTEX_SHADER,ie),i=Q(n,n.FRAGMENT_SHADER,ae);if(!r||!i){r&&n.deleteShader(r),i&&n.deleteShader(i);return}let a=n.createProgram(),o=n.createBuffer();if(!a||!o){a&&n.deleteProgram(a),o&&n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}if(n.attachShader(a,r),n.attachShader(a,i),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS)){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}let s=n.getAttribLocation(a,`a_position`),c=n.getUniformLocation(a,`u_resolution`),l=n.getUniformLocation(a,`u_time`),u=n.getUniformLocation(a,`u_rotation`),d=n.getUniformLocation(a,`u_listen`),f=n.getUniformLocation(a,`u_speak`);if(s<0||!c||!l||!u||!d||!f){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i);return}let p=Math.min(window.devicePixelRatio||1,2),m=Math.max(1,Math.round(t*p));return e.width=m,e.height=m,n.viewport(0,0,m,m),n.useProgram(a),n.bindBuffer(n.ARRAY_BUFFER,o),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),n.STATIC_DRAW),n.enableVertexAttribArray(s),n.vertexAttribPointer(s,2,n.FLOAT,!1,0,0),n.uniform2f(c,m,m),{draw(e,t,r,i){n.uniform1f(l,e),n.uniform1f(u,t),n.uniform1f(d,r),n.uniform1f(f,i),n.drawArrays(n.TRIANGLES,0,6)},destroy(){n.deleteProgram(a),n.deleteBuffer(o),n.deleteShader(r),n.deleteShader(i)}}}function ue(e){return e!==`idle`&&e!==`connecting`&&e!==`error`}function de({active:e}){return(0,t.jsx)(`svg`,{"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,style:{display:`block`,width:`50%`,height:`50%`,transform:`rotate(${e?132:-8}deg)`,transformOrigin:`center`,transition:`transform 180ms ease`},children:(0,t.jsx)(`path`,{d:`M6.7 3.8 9.1 7a1.6 1.6 0 0 1-.2 2.1l-1.4 1.3a13.1 13.1 0 0 0 6.1 6.1l1.3-1.4a1.6 1.6 0 0 1 2.1-.2l3.2 2.4a1.6 1.6 0 0 1 .5 1.9l-.7 1.7c-.3.8-1.1 1.3-2 1.2C9.7 21.2 2.8 14.3 1.9 6c-.1-.9.4-1.7 1.2-2l1.7-.7a1.6 1.6 0 0 1 1.9.5Z`,fill:`currentColor`})})}function fe({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:c=!1,onClick:l,...u}){let d=(0,e.useRef)(null),f=(0,e.useRef)(n),p=(0,e.useRef)(r),m=(0,e.useRef)(!1);re(()=>{f.current=n,p.current=r},[n,r]);let h=i*se,g=h*ce;(0,e.useEffect)(()=>{let e=`orb-radial-keyframes`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=oe,document.head.appendChild(t)}},[]),(0,e.useEffect)(()=>{let e=d.current;if(!e)return;let t=window.matchMedia(`(prefers-reduced-motion: reduce)`),n=()=>{m.current=t.matches};n(),t.addEventListener(`change`,n);let r=le(e,h),i=0,a=performance.now(),o=0,s=.36,c=.62,l=.15,u=0,g=0,_=0,v=0,y=+(f.current===`speaking`),b=X(p.current),x=f.current===`listening`?b:0,S=f.current===`speaking`?b:0,C=e=>{let t=Math.min((e-a)/1e3,.05);a=e;let n=f.current,d=m.current,h=X(p.current);b=d?0:Z(b,h,h>b?15:7,t);let w=n===`listening`?b:0,T=n===`speaking`?b:0;x=d?0:Z(x,w,w>x?17:7,t),S=d?0:Z(S,T,T>S?12:5,t);let E=.36,D=.62,O=.15;if(n===`connecting`?(E=.42,D=.68,O=.13):n===`listening`?(E=.54+x*.26,D=.78+x*.18,O=.18+x*.04):n===`thinking`?(E=.46,D=.72,O=.16):n===`speaking`&&(E=1.05+S*1.15),!d){s=Z(s,E,3.6,t),c=Z(c,D,3.6,t),l=Z(l,O,3.6,t),y=Z(y,+(n===`speaking`),n===`speaking`?3.8:3,t),o+=t*s,_+=t*c;let e=1.2+S*1.35+Math.sin(o*1.73)*.34+Math.sin(o*.61+.8)*.18;v+=t*Math.max(.65,e);let r=Math.sin(_)*l+Math.sin(_*.47+1.1)*.032,i=Math.sin(v*1.08),a=Math.sin(v*2.47+.9),d=Math.sin(v*.43-.5),f=r+(i*(.13+S*.17)+a*(.035+S*.035)+d*.055-r)*y,p=4.2+y*3,m=p*p,h=2*p;g+=((f-u)*m-g*h)*t,u+=g*t}r?.draw(o,u,x,S),i=requestAnimationFrame(C)};return i=requestAnimationFrame(C),()=>{cancelAnimationFrame(i),t.removeEventListener(`change`,n),r?.destroy()}},[h]);let _=ue(n),v=n===`connecting`,y=h+(c?g*.5:0),b={"--orb-ui-radial-control-surround":`#fff`,width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},x=(0,t.jsxs)(`span`,{style:{position:`relative`,display:`block`,width:h,height:y,lineHeight:0},children:[(0,t.jsx)(`canvas`,{ref:d,"aria-hidden":`true`,"data-radial-surface":``,style:{position:`absolute`,left:0,top:0,display:`block`,width:h,height:h,borderRadius:`50%`,background:`conic-gradient(from 12deg, #06358d 0deg, #0b65b5 72deg, #c7f1ef 92deg, #45c2c8 172deg, #06358d 196deg, #0b65b5 254deg, #c7f1ef 278deg, #45c2c8 360deg)`}}),c?(0,t.jsx)(`button`,{...u,type:`button`,"data-radial-control":``,disabled:s,onClick:s?void 0:l,style:{appearance:`none`,WebkitAppearance:`none`,position:`absolute`,left:`50%`,top:h-g*.52,width:g,height:g,display:`flex`,alignItems:`center`,justifyContent:`center`,boxSizing:`border-box`,padding:0,margin:0,border:0,borderRadius:`50%`,background:v?`#9da1aa`:_?`#ef4146`:`#080808`,color:`#fff`,boxShadow:`0 0 0 ${Math.max(3,g*.085)}px var(--orb-ui-radial-control-surround), 0 2px 5px rgba(0, 0, 0, 0.18)`,cursor:s?`not-allowed`:`pointer`,opacity:s?.52:1,transform:`translateX(-50%)`,transition:`background 160ms ease, opacity 160ms ease, transform 160ms ease`,font:`inherit`},children:v?(0,t.jsx)(`span`,{"aria-hidden":`true`,"data-radial-spinner":``,style:{width:`42%`,height:`42%`,boxSizing:`border-box`,border:`${Math.max(1.5,g*.055)}px solid rgba(255, 255, 255, 0.38)`,borderTopColor:`#fff`,borderRightColor:`#fff`,borderRadius:`50%`,animation:`orb-radial-spinner 760ms linear infinite`}}):(0,t.jsx)(de,{active:_})}):null]});return c?(0,t.jsx)(`div`,{className:a,style:b,children:x}):(0,t.jsx)(`div`,{...u,className:a,style:b,children:x})}function $({signal:i,state:a,volume:s,adapter:c,theme:l=`debug`,size:u=200,className:d,style:f,disabled:p=!1,interactive:m=!0,onStart:h,onStop:g,..._}){let[v,y]=(0,e.useState)({state:`idle`});(0,e.useEffect)(()=>{if(y({state:`idle`}),c)return c.subscribe(y)},[c]);let x=i??v,S=n(a,i,v),C=r(s,S,x),w=S!==`idle`&&S!==`error`,T=(0,e.useCallback)(()=>{p||(w?g?g():c?.stop?.():h?h():c?.start?.())},[c,p,w,h,g]),D=w?!!(c?.stop||g):!!(c?.start||h),O=m&&D,k=O&&!p?T:void 0,A={state:S,volume:C,size:u,className:d,style:f,disabled:p,..._,"aria-label":_[`aria-label`]??(O?`${w?`Stop`:`Start`} voice session`:void 0)},j={...A,interactive:O};switch(l){case`circle`:return(0,t.jsx)(b,{...j,onClick:k});case`bars`:return(0,t.jsx)(E,{...j,onClick:k});case`cloud`:return(0,t.jsx)(ne,{...j,onClick:k});case`radial`:return(0,t.jsx)(fe,{...j,onClick:k});default:return(0,t.jsx)(o,{...A,disabled:p||!m,onStart:p||!m?void 0:h??(()=>c?.start?.()),onStop:p||!m?void 0:g??(()=>c?.stop?.())})}}exports.Orb=$,exports.VoiceOrb=$;
|