orb-ui 0.3.0 → 0.5.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 +117 -19
- package/dist/adapters/audio-level.d.ts +23 -0
- package/dist/adapters/gemini-live/index.d.ts +70 -0
- package/dist/adapters/index.d.ts +5 -1
- package/dist/adapters/livekit/browser.d.ts +44 -0
- package/dist/adapters/livekit/index.d.ts +1 -1
- package/dist/adapters/openai-realtime/index.d.ts +37 -0
- package/dist/adapters/pipecat/index.d.ts +46 -0
- package/dist/adapters/types.d.ts +2 -2
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +527 -200
- package/dist/components/Orb/Orb.types.d.ts +1 -12
- package/dist/components/Orb/index.d.ts +1 -1
- package/dist/components/Orb/signals.d.ts +1 -3
- package/dist/index.d.ts +1 -1
- package/dist/livekit-Dasur3lv.js +240 -0
- package/dist/livekit-Ro6A52eb.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -0
- package/dist/livekit-adapter.js +28 -0
- package/dist/orb-ui.cjs +2 -2
- package/dist/orb-ui.js +83 -110
- package/package.json +27 -4
|
@@ -20,17 +20,6 @@ export interface OrbAdapter {
|
|
|
20
20
|
/** Stop the voice session. Called internally by Orb on click. */
|
|
21
21
|
stop?: () => void | Promise<void>;
|
|
22
22
|
}
|
|
23
|
-
/** @deprecated Use signal-based OrbAdapter.subscribe(listener). */
|
|
24
|
-
export interface AdapterCallbacks {
|
|
25
|
-
onStateChange: (state: OrbState) => void;
|
|
26
|
-
onVolumeChange: (volume: number) => void;
|
|
27
|
-
}
|
|
28
|
-
/** @deprecated Callback-object adapters will be removed in 0.5.0. */
|
|
29
|
-
export interface LegacyOrbAdapter {
|
|
30
|
-
subscribe(callbacks: AdapterCallbacks): () => void;
|
|
31
|
-
start?: () => void | Promise<void>;
|
|
32
|
-
stop?: () => void | Promise<void>;
|
|
33
|
-
}
|
|
34
23
|
type DataAttributeValue = string | number | boolean | null | undefined;
|
|
35
24
|
export interface OrbHtmlAttributes extends AriaAttributes {
|
|
36
25
|
/** Forwarded to the rendered orb control/container. */
|
|
@@ -64,7 +53,7 @@ export interface OrbProps extends OrbHtmlAttributes {
|
|
|
64
53
|
* Provider adapter (Vapi, ElevenLabs, etc.).
|
|
65
54
|
* Handles signal updates automatically from the SDK.
|
|
66
55
|
*/
|
|
67
|
-
adapter?: OrbAdapter
|
|
56
|
+
adapter?: OrbAdapter;
|
|
68
57
|
/** Visual theme. Defaults to 'debug'. */
|
|
69
58
|
theme?: OrbTheme;
|
|
70
59
|
/** Size in pixels. Defaults to 200. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Orb } from './Orb.js';
|
|
2
|
-
export type {
|
|
2
|
+
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './Orb.types.js';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type HybridOrbSignalListener = OrbSignalListener & AdapterCallbacks;
|
|
1
|
+
import { OrbSignal, OrbState } from './Orb.types.js';
|
|
3
2
|
export declare function deriveOrbState(state: OrbState | undefined, signal: OrbSignal | undefined, adapterSignal: OrbSignal): OrbState;
|
|
4
3
|
export declare function deriveOrbVolume(volume: number | undefined, state: OrbState, signal: OrbSignal): number;
|
|
5
|
-
export declare function createOrbSignalListener(onSignal: OrbSignalListener, onLegacyAdapterUsed: () => void): HybridOrbSignalListener;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Orb } from './components/Orb/index.js';
|
|
2
|
-
export type {
|
|
2
|
+
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, 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,240 @@
|
|
|
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/livekit/index.ts
|
|
8
|
+
var t = 4, n = .03, r = 1.5, i = .6, a = .2, o = .35;
|
|
9
|
+
function s(e) {
|
|
10
|
+
switch (e) {
|
|
11
|
+
case "speaking": return "speaking";
|
|
12
|
+
case "thinking": return "thinking";
|
|
13
|
+
case "listening":
|
|
14
|
+
case "idle": return "listening";
|
|
15
|
+
case "connecting":
|
|
16
|
+
case "pre-connect-buffering":
|
|
17
|
+
case "initializing": return "connecting";
|
|
18
|
+
case "disconnected": return "idle";
|
|
19
|
+
case "failed": return "error";
|
|
20
|
+
default: return "idle";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function c(e) {
|
|
24
|
+
return "RoomClass" in e;
|
|
25
|
+
}
|
|
26
|
+
function l(e) {
|
|
27
|
+
return typeof e == "function" ? e() : e;
|
|
28
|
+
}
|
|
29
|
+
function u(e) {
|
|
30
|
+
if (!e) return {};
|
|
31
|
+
let t = {}, n = (e, n) => {
|
|
32
|
+
n !== void 0 && (t[e] = n);
|
|
33
|
+
};
|
|
34
|
+
return n("roomName", l(e.roomName)), n("participantName", l(e.participantName)), n("participantIdentity", l(e.participantIdentity)), n("participantMetadata", l(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", l(e.agentName)), n("agentMetadata", l(e.agentMetadata)), n("deployment", l(e.deployment)), t;
|
|
35
|
+
}
|
|
36
|
+
function d(e) {
|
|
37
|
+
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
38
|
+
return e;
|
|
39
|
+
}
|
|
40
|
+
async function f(e) {
|
|
41
|
+
let t = u(e.tokenOptions);
|
|
42
|
+
return typeof e.getConnectionDetails == "function" ? d(await e.getConnectionDetails(t)) : e.tokenSource ? d(await e.tokenSource.fetch(t)) : d({
|
|
43
|
+
serverUrl: e.serverUrl,
|
|
44
|
+
participantToken: e.participantToken
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function p(e) {
|
|
48
|
+
for (let [, n] of e.remoteParticipants) if (!n.isLocal && (n.kind === t || n.attributes?.["lk.agent.state"] !== void 0)) return n;
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function m(e, t, n) {
|
|
52
|
+
let r = e.off;
|
|
53
|
+
if (r) {
|
|
54
|
+
r.call(e, t, n);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
e.removeListener?.call(e, t, n);
|
|
58
|
+
}
|
|
59
|
+
function h(e, t, n) {
|
|
60
|
+
e.on.call(e, t, n);
|
|
61
|
+
}
|
|
62
|
+
function g(l) {
|
|
63
|
+
let u = c(l), d = l.createAudioAnalyser, g = { current: u ? null : l.room }, _ = /* @__PURE__ */ new Set(), v = {
|
|
64
|
+
state: "idle",
|
|
65
|
+
volume: 0,
|
|
66
|
+
inputVolume: 0,
|
|
67
|
+
outputVolume: 0
|
|
68
|
+
}, y = "idle", b = null, x = null, S = null, C = null, w = null, T = null, E = null, D = 0, O = null;
|
|
69
|
+
function k(e) {
|
|
70
|
+
v = e, _.forEach((t) => t(e));
|
|
71
|
+
}
|
|
72
|
+
function A(e) {
|
|
73
|
+
k({
|
|
74
|
+
...v,
|
|
75
|
+
...e,
|
|
76
|
+
state: e.state ?? v.state
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function j(e) {
|
|
80
|
+
let t = e < n ? 0 : e, s = t > D ? i : a;
|
|
81
|
+
D += (t - D) * s;
|
|
82
|
+
let c = Math.min(D * r, 1);
|
|
83
|
+
return c / (c + o);
|
|
84
|
+
}
|
|
85
|
+
function M() {
|
|
86
|
+
D = 0, A({
|
|
87
|
+
volume: 0,
|
|
88
|
+
outputVolume: 0
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function N({ emitZero: e = !0 } = {}) {
|
|
92
|
+
w &&= (clearInterval(w), null), C &&= (C.cleanup().catch(() => {}), null), e && A({
|
|
93
|
+
volume: 0,
|
|
94
|
+
inputVolume: 0
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function P(t) {
|
|
98
|
+
if (!(b === t && C)) {
|
|
99
|
+
N({ emitZero: !1 }), b = t;
|
|
100
|
+
try {
|
|
101
|
+
C = d(t);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
w = setInterval(() => {
|
|
107
|
+
if (!C || y !== "listening") return;
|
|
108
|
+
let t = e(C.calculateVolume());
|
|
109
|
+
A({
|
|
110
|
+
volume: t,
|
|
111
|
+
inputVolume: t,
|
|
112
|
+
outputVolume: 0
|
|
113
|
+
});
|
|
114
|
+
}, 33);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function F({ emitZero: e = !0 } = {}) {
|
|
118
|
+
E &&= (clearInterval(E), null), T &&= (T.cleanup().catch(() => {}), null), D = 0, e && A({
|
|
119
|
+
volume: 0,
|
|
120
|
+
outputVolume: 0
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function I(e) {
|
|
124
|
+
F();
|
|
125
|
+
try {
|
|
126
|
+
T = d(e);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
E = setInterval(() => {
|
|
132
|
+
if (!T || y !== "speaking") return;
|
|
133
|
+
let e = j(T.calculateVolume());
|
|
134
|
+
A({
|
|
135
|
+
volume: e,
|
|
136
|
+
inputVolume: 0,
|
|
137
|
+
outputVolume: e
|
|
138
|
+
});
|
|
139
|
+
}, 33);
|
|
140
|
+
}
|
|
141
|
+
function L(e) {
|
|
142
|
+
y = e, A({
|
|
143
|
+
state: e,
|
|
144
|
+
volume: 0,
|
|
145
|
+
inputVolume: 0,
|
|
146
|
+
outputVolume: 0
|
|
147
|
+
}), e === "speaking" && x ? I(x) : e !== "speaking" && F({ emitZero: !1 });
|
|
148
|
+
}
|
|
149
|
+
function R(e) {
|
|
150
|
+
S || typeof document > "u" || (S = e.attach(), S.id = "orb-ui-livekit-agent-audio", document.body.appendChild(S));
|
|
151
|
+
}
|
|
152
|
+
function z() {
|
|
153
|
+
S &&= (S.remove(), null);
|
|
154
|
+
}
|
|
155
|
+
function B(e) {
|
|
156
|
+
x = e, R(e), y === "speaking" && I(e);
|
|
157
|
+
}
|
|
158
|
+
function V(e) {
|
|
159
|
+
P(e);
|
|
160
|
+
}
|
|
161
|
+
function H(e) {
|
|
162
|
+
let t = e.getTrackPublication?.("microphone");
|
|
163
|
+
t?.track && V(t.track);
|
|
164
|
+
}
|
|
165
|
+
function U(e) {
|
|
166
|
+
let t = s(e);
|
|
167
|
+
t !== y && L(t);
|
|
168
|
+
}
|
|
169
|
+
function W(e) {
|
|
170
|
+
let t = e.attributes?.["lk.agent.state"];
|
|
171
|
+
t && U(t);
|
|
172
|
+
let n = e.getTrackPublication("microphone");
|
|
173
|
+
n?.track && B(n.track);
|
|
174
|
+
}
|
|
175
|
+
function G(e) {
|
|
176
|
+
if (O) return;
|
|
177
|
+
let n = (e, t) => {
|
|
178
|
+
if (t.isLocal) return;
|
|
179
|
+
let n = e["lk.agent.state"];
|
|
180
|
+
n && U(n);
|
|
181
|
+
}, r = (e, n, r) => {
|
|
182
|
+
r.isLocal || !(r.kind === t || r.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || B(e);
|
|
183
|
+
}, i = (e) => {
|
|
184
|
+
x === e && (x = null, z(), F());
|
|
185
|
+
}, a = (e) => {
|
|
186
|
+
e.source !== "microphone" || !e.track || V(e.track);
|
|
187
|
+
}, o = (e) => {
|
|
188
|
+
e.source === "microphone" && (b = null, N());
|
|
189
|
+
}, s = () => {
|
|
190
|
+
b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), L("idle");
|
|
191
|
+
};
|
|
192
|
+
if (h(e, "participantAttributesChanged", n), h(e, "trackSubscribed", r), h(e, "trackUnsubscribed", i), h(e, "localTrackPublished", a), h(e, "localTrackUnpublished", o), h(e, "disconnected", s), O = () => {
|
|
193
|
+
m(e, "participantAttributesChanged", n), m(e, "trackSubscribed", r), m(e, "trackUnsubscribed", i), m(e, "localTrackPublished", a), m(e, "localTrackUnpublished", o), m(e, "disconnected", s);
|
|
194
|
+
}, H(e.localParticipant), e.state === "connected") {
|
|
195
|
+
let t = p(e);
|
|
196
|
+
t ? W(t) : L("connecting");
|
|
197
|
+
} else L("idle");
|
|
198
|
+
}
|
|
199
|
+
function K() {
|
|
200
|
+
O?.(), O = null, b = null, x = null, z(), N({ emitZero: !1 }), F({ emitZero: !1 }), A({
|
|
201
|
+
volume: 0,
|
|
202
|
+
inputVolume: 0,
|
|
203
|
+
outputVolume: 0
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
let q = (e) => {
|
|
207
|
+
_.add(e), e(v);
|
|
208
|
+
let t = g.current;
|
|
209
|
+
return t && G(t), () => {
|
|
210
|
+
_.delete(e), _.size === 0 && K();
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
return u ? {
|
|
214
|
+
subscribe: q,
|
|
215
|
+
async start() {
|
|
216
|
+
if (g.current) return;
|
|
217
|
+
let e = l, t = new e.RoomClass();
|
|
218
|
+
L("connecting");
|
|
219
|
+
try {
|
|
220
|
+
let n = await f(e);
|
|
221
|
+
if (await t.connect(n.serverUrl, n.participantToken, e.connectOptions), g.current = t, G(t), e.enableMicrophone !== !1) {
|
|
222
|
+
let e = (await t.localParticipant.setMicrophoneEnabled(!0))?.track ?? t.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
223
|
+
e && V(e);
|
|
224
|
+
}
|
|
225
|
+
} catch (e) {
|
|
226
|
+
throw console.error("[orb-ui/livekit] connect failed:", e), g.current === t && K(), t.disconnect(), g.current = null, L("error"), M(), A({ error: e }), e;
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
async stop() {
|
|
230
|
+
let e = g.current;
|
|
231
|
+
if (!e) {
|
|
232
|
+
L("idle");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
K(), e.disconnect(), g.current = null, L("idle");
|
|
236
|
+
}
|
|
237
|
+
} : { subscribe: q };
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { g as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=Math.min(e/.5,1);return t**=1.3,t}var t=4,n=.03,r=1.5,i=.6,a=.2,o=.35;function s(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 c(e){return`RoomClass`in e}function l(e){return typeof e==`function`?e():e}function u(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,l(e.roomName)),n(`participantName`,l(e.participantName)),n(`participantIdentity`,l(e.participantIdentity)),n(`participantMetadata`,l(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,l(e.agentName)),n(`agentMetadata`,l(e.agentMetadata)),n(`deployment`,l(e.deployment)),t}function d(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function f(e){let t=u(e.tokenOptions);return typeof e.getConnectionDetails==`function`?d(await e.getConnectionDetails(t)):e.tokenSource?d(await e.tokenSource.fetch(t)):d({serverUrl:e.serverUrl,participantToken:e.participantToken})}function p(e){for(let[,n]of e.remoteParticipants)if(!n.isLocal&&(n.kind===t||n.attributes?.[`lk.agent.state`]!==void 0))return n;return null}function m(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function h(e,t,n){e.on.call(e,t,n)}function g(l){let u=c(l),d=l.createAudioAnalyser,g={current:u?null:l.room},_=new Set,v={state:`idle`,volume:0,inputVolume:0,outputVolume:0},y=`idle`,b=null,x=null,S=null,C=null,w=null,T=null,E=null,D=0,O=null;function k(e){v=e,_.forEach(t=>t(e))}function A(e){k({...v,...e,state:e.state??v.state})}function j(e){let t=e<n?0:e,s=t>D?i:a;D+=(t-D)*s;let c=Math.min(D*r,1);return c/(c+o)}function M(){D=0,A({volume:0,outputVolume:0})}function N({emitZero:e=!0}={}){w&&=(clearInterval(w),null),C&&=(C.cleanup().catch(()=>{}),null),e&&A({volume:0,inputVolume:0})}function P(t){if(!(b===t&&C)){N({emitZero:!1}),b=t;try{C=d(t)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||y!==`listening`)return;let t=e(C.calculateVolume());A({volume:t,inputVolume:t,outputVolume:0})},33)}}function F({emitZero:e=!0}={}){E&&=(clearInterval(E),null),T&&=(T.cleanup().catch(()=>{}),null),D=0,e&&A({volume:0,outputVolume:0})}function I(e){F();try{T=d(e)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}E=setInterval(()=>{if(!T||y!==`speaking`)return;let e=j(T.calculateVolume());A({volume:e,inputVolume:0,outputVolume:e})},33)}function L(e){y=e,A({state:e,volume:0,inputVolume:0,outputVolume:0}),e===`speaking`&&x?I(x):e!==`speaking`&&F({emitZero:!1})}function R(e){S||typeof document>`u`||(S=e.attach(),S.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(S))}function z(){S&&=(S.remove(),null)}function B(e){x=e,R(e),y===`speaking`&&I(e)}function V(e){P(e)}function H(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&V(t.track)}function U(e){let t=s(e);t!==y&&L(t)}function W(e){let t=e.attributes?.[`lk.agent.state`];t&&U(t);let n=e.getTrackPublication(`microphone`);n?.track&&B(n.track)}function G(e){if(O)return;let n=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&U(n)},r=(e,n,r)=>{r.isLocal||!(r.kind===t||r.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||B(e)},i=e=>{x===e&&(x=null,z(),F())},a=e=>{e.source!==`microphone`||!e.track||V(e.track)},o=e=>{e.source===`microphone`&&(b=null,N())},s=()=>{b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),L(`idle`)};if(h(e,`participantAttributesChanged`,n),h(e,`trackSubscribed`,r),h(e,`trackUnsubscribed`,i),h(e,`localTrackPublished`,a),h(e,`localTrackUnpublished`,o),h(e,`disconnected`,s),O=()=>{m(e,`participantAttributesChanged`,n),m(e,`trackSubscribed`,r),m(e,`trackUnsubscribed`,i),m(e,`localTrackPublished`,a),m(e,`localTrackUnpublished`,o),m(e,`disconnected`,s)},H(e.localParticipant),e.state===`connected`){let t=p(e);t?W(t):L(`connecting`)}else L(`idle`)}function K(){O?.(),O=null,b=null,x=null,z(),N({emitZero:!1}),F({emitZero:!1}),A({volume:0,inputVolume:0,outputVolume:0})}let q=e=>{_.add(e),e(v);let t=g.current;return t&&G(t),()=>{_.delete(e),_.size===0&&K()}};return u?{subscribe:q,async start(){if(g.current)return;let e=l,t=new e.RoomClass;L(`connecting`);try{let n=await f(e);if(await t.connect(n.serverUrl,n.participantToken,e.connectOptions),g.current=t,G(t),e.enableMicrophone!==!1){let e=(await t.localParticipant.setMicrophoneEnabled(!0))?.track??t.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&V(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),g.current===t&&K(),t.disconnect(),g.current=null,L(`error`),M(),A({error:e}),e}},async stop(){let e=g.current;if(!e){L(`idle`);return}K(),e.disconnect(),g.current=null,L(`idle`)}}:{subscribe:q}}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return g}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-Ro6A52eb.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}=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,createAudioAnalyser:t.createAudioAnalyser,RoomClass:t.Room})}exports.createLiveKitAdapter=r;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { t as e } from "./livekit-Dasur3lv.js";
|
|
2
|
+
import { Room as t, TokenSource as n, createAudioAnalyser as r } from "livekit-client";
|
|
3
|
+
//#region src/adapters/livekit/browser.ts
|
|
4
|
+
function i() {
|
|
5
|
+
return `orb-${globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`}`;
|
|
6
|
+
}
|
|
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;
|
|
9
|
+
return e({
|
|
10
|
+
tokenSource: a.tokenEndpoint === void 0 ? n.sandboxTokenServer(a.sandboxId, a.sandboxOptions) : n.endpoint(a.tokenEndpoint, a.tokenEndpointOptions),
|
|
11
|
+
tokenOptions: {
|
|
12
|
+
agentMetadata: o,
|
|
13
|
+
agentName: s,
|
|
14
|
+
deployment: l,
|
|
15
|
+
participantAttributes: d,
|
|
16
|
+
participantIdentity: f,
|
|
17
|
+
participantMetadata: p,
|
|
18
|
+
participantName: m,
|
|
19
|
+
roomName: h
|
|
20
|
+
},
|
|
21
|
+
connectOptions: c,
|
|
22
|
+
enableMicrophone: u,
|
|
23
|
+
createAudioAnalyser: r,
|
|
24
|
+
RoomClass: t
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { a as createLiveKitAdapter };
|
package/dist/orb-ui.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");function n(e,t,n){return e??t?.state??n.state}function r(e,t,n){return e===void 0?t===`listening`?n.inputVolume??n.volume??0:t===`speaking`?n.outputVolume??n.volume??0:n.volume??0:e}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");function n(e,t,n){return e??t?.state??n.state}function r(e,t,n){return e===void 0?t===`listening`?n.inputVolume??n.volume??0:t===`speaking`?n.outputVolume??n.volume??0:n.volume??0:e}var i=[`idle`,`connecting`,`listening`,`thinking`,`speaking`,`error`],a={idle:`#888`,connecting:`#f0c040`,listening:`#40c0f0`,thinking:`#c084fc`,speaking:`#40f080`,error:`#f04040`};function o({state:e,volume:n,size:r,className:o,style:s,disabled:c=!1,onStart:l,onStop:u,...d}){return(0,t.jsxs)(`div`,{...d,className:o,style:{width:r,fontFamily:`monospace`,fontSize:12,background:`#111`,color:`#ccc`,border:`1px solid #333`,borderRadius:8,padding:12,boxSizing:`border-box`,userSelect:`none`,...s},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:10,fontSize:10,letterSpacing:1},children:`ORB DEBUG`}),(0,t.jsxs)(`div`,{style:{marginBottom:8},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`state `}),(0,t.jsx)(`span`,{style:{color:a[e],fontWeight:`bold`},children:e})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`span`,{style:{color:`#555`},children:`volume `}),(0,t.jsx)(`span`,{style:{color:`#ccc`},children:n.toFixed(2)}),(0,t.jsx)(`div`,{style:{marginTop:4,height:4,background:`#222`,borderRadius:2,overflow:`hidden`},children:(0,t.jsx)(`div`,{style:{height:`100%`,width:`${n*100}%`,background:a[e],borderRadius:2,transition:`width 50ms linear`}})})]}),(0,t.jsxs)(`div`,{style:{marginBottom:10},children:[(0,t.jsx)(`div`,{style:{color:`#555`,marginBottom:4,fontSize:10},children:`force state`}),(0,t.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:4},children:i.map(n=>(0,t.jsx)(`button`,{disabled:c,style:{fontSize:10,padding:`2px 6px`,background:e===n?a[n]:`#222`,color:e===n?`#000`:`#888`,border:`1px solid ${e===n?a[n]:`#333`}`,borderRadius:3,cursor:c?`not-allowed`:`pointer`},onClick:()=>{console.warn(`[orb-ui debug] To force state '${n}', use controlled mode: <Orb state="${n}" />`)},children:n},n))})]}),(0,t.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,t.jsx)(`button`,{disabled:c,onClick:l,style:{flex:1,padding:`4px 0`,background:`#1a3a1a`,color:`#40f080`,border:`1px solid #40f080`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Start`}),(0,t.jsx)(`button`,{disabled:c,onClick:u,style:{flex:1,padding:`4px 0`,background:`#3a1a1a`,color:`#f04040`,border:`1px solid #f04040`,borderRadius:4,cursor:c?`not-allowed`:`pointer`,fontSize:11},children:`Stop`})]})]})}var s=typeof window<`u`?e.useLayoutEffect:e.useEffect;function c(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}var l={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`},u=`
|
|
2
2
|
@keyframes orb-circle-idle-pulse {
|
|
3
3
|
from { transform: scale(1); }
|
|
4
4
|
to { transform: scale(1.06); }
|
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
8
8
|
50% { opacity: 0.6; transform: scale(0.95); }
|
|
9
9
|
100% { opacity: 1; transform: scale(1); }
|
|
10
10
|
}
|
|
11
|
-
`,
|
|
11
|
+
`,d=.95,f=.08,p=.82,m=.18,h=24,g=0,_=.55,v=.12,y=.002;function b({state:n,volume:r,size:i,className:a,style:o,disabled:b=!1,interactive:x=!1,onClick:S,...C}){let w=(0,e.useRef)(null),T=(0,e.useRef)(null),E=(0,e.useRef)(null),D=(0,e.useRef)(0),O=(0,e.useRef)(r);s(()=>{O.current=r},[r]);let k=(0,e.useRef)(1),A=(0,e.useRef)(0),j=(0,e.useRef)(c(l.idle)),M=.06,N=(0,e.useRef)(p),P=(0,e.useRef)(m);(0,e.useEffect)(()=>{let e=`orb-circle-keyframes`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=u,document.head.appendChild(t)}},[]),(0,e.useEffect)(()=>{let e=w.current;if(e)if(n===`listening`||n===`speaking`){let t=n===`speaking`?d:p,r=n===`speaking`?f:m,i=n===`speaking`?h:g,a=()=>{let o=O.current;N.current+=(t-N.current)*M,P.current+=(r-P.current)*M;let s=N.current+o*P.current,u=o*i;n===`listening`?(k.current+=(s-k.current)*_,A.current+=(u-A.current)*_):(k.current=s,A.current=u);let d=c(l[n]),[f,p,m]=j.current;j.current=[f+(d[0]-f)*.05,p+(d[1]-p)*.05,m+(d[2]-m)*.05];let[h,g,v]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${h},${g},${v})`,e.style.boxShadow=`none`,e.style.animation=`none`;let y=T.current;if(y){let e=A.current;y.style.transform=`scale(${k.current})`,y.style.boxShadow=e>.5?`0 0 ${e}px ${e*.4}px rgb(${h},${g},${v})`:`none`}D.current=requestAnimationFrame(a)};return D.current=requestAnimationFrame(a),()=>{cancelAnimationFrame(D.current)}}else{cancelAnimationFrame(D.current);let t=l[n]??l.idle,r=c(t),i=()=>{k.current+=(1-k.current)*v,A.current+=(0-A.current)*v;let[a,o,s]=j.current;j.current=[a+(r[0]-a)*v,o+(r[1]-o)*v,s+(r[2]-s)*v];let[c,l,u]=j.current.map(Math.round);e.style.transform=`scale(${k.current})`,e.style.background=`rgb(${c},${l},${u})`,e.style.boxShadow=`none`,e.style.animation=`none`,T.current&&(T.current.style.transform=`scale(${k.current})`,T.current.style.boxShadow=`none`);let d=Math.abs(k.current-1)<y,f=A.current<.1,p=j.current.every((e,t)=>Math.abs(e-r[t])<1);if(d&&f&&p){k.current=1,A.current=0,j.current=r,e.style.transform=``,e.style.boxShadow=`none`,e.style.background=t,T.current&&(T.current.style.transform=`scale(1)`,T.current.style.boxShadow=`none`),n===`idle`?e.style.animation=`orb-circle-idle-pulse 3s ease-in-out infinite alternate`:n===`connecting`||n===`thinking`?e.style.animation=`orb-circle-connecting-pulse 1.5s ease-in-out infinite`:e.style.animation=`none`;return}D.current=requestAnimationFrame(i)};return D.current=requestAnimationFrame(i),()=>cancelAnimationFrame(D.current)}},[n]);let F=i*.55,I={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},L=(0,t.jsxs)(`span`,{ref:E,onMouseEnter:()=>{E.current&&!b&&(E.current.style.transform=`scale(1.06)`,E.current.style.filter=`brightness(1.12)`)},onMouseLeave:()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{E.current&&(E.current.style.transform=`scale(1)`,E.current.style.filter=`brightness(1)`)},200)},style:{position:`relative`,display:`inline-block`,transition:`transform 0.3s ease, filter 0.3s ease`,cursor:x?b?`not-allowed`:`pointer`:`default`,borderRadius:`50%`,lineHeight:0},children:[(0,t.jsx)(`span`,{ref:T,style:{position:`absolute`,display:`block`,width:F,height:F,borderRadius:`50%`,pointerEvents:`none`}}),(0,t.jsx)(`span`,{ref:w,style:{position:`relative`,display:`block`,width:F,height:F,borderRadius:`50%`,background:l[n]}})]});return x?(0,t.jsx)(`button`,{...C,type:`button`,className:a,disabled:b,onClick:b?void 0:S,style:{appearance:`none`,WebkitAppearance:`none`,border:0,padding:0,margin:0,background:`transparent`,color:`inherit`,font:`inherit`,cursor:b?`not-allowed`:`pointer`,...I},children:L}):(0,t.jsx)(`div`,{...C,className:a,style:I,children:L})}var x=5,S=1.4,C=Math.PI*2/x,w={idle:`#cccccc`,connecting:`#cccccc`,listening:`#999999`,thinking:`#d8d8d8`,speaking:`#e8e8e8`,error:`#f87171`};function T(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function E({state:n,volume:r,size:i,className:a,style:o,disabled:s=!1,interactive:c=!1,onClick:l,...u}){let d=(0,e.useRef)([]),f=(0,e.useRef)(null),p=(0,e.useRef)(0),m=(0,e.useRef)(Array(x).fill(0)),h=(0,e.useRef)(r),g=(0,e.useRef)(!1),_=(0,e.useRef)(0),v=(0,e.useRef)(T(w.idle)),y=(0,e.useRef)(null),b=(0,e.useRef)(Array(x).fill(0)),E=(0,e.useRef)(n);(0,e.useEffect)(()=>{n!==E.current&&(b.current=[...m.current],y.current=Date.now(),E.current=n)},[n]),(0,e.useEffect)(()=>{h.current=r},[r]),(0,e.useEffect)(()=>{let e=i*.55,t=i*.06,r=w[n]??w.idle,a=i*.1,o=Array.from({length:x},(e,t)=>{let n=(x-1)/2;return 1-.7*(Math.abs(t-n)/n)}),s=()=>{let e=g.current?a:0;_.current+=(e-_.current)*.15},c=(t,r)=>{s();let i=T(r),[a,c,l]=v.current;v.current=[a+(i[0]-a)*.08,c+(i[1]-c)*.08,l+(i[2]-l)*.08];let[u,f,p]=v.current.map(Math.round),m=`rgb(${u},${f},${p})`;for(let r=0;r<x;r++){let i=d.current[r];if(!i)continue;let a=n===`idle`?o[r]:1,s=_.current*a;i.style.height=`${Math.min(t[r]+s,e)}px`,i.style.background=m,i.style.animation=`none`}};if(n===`listening`||n===`speaking`){let i=n===`speaking`?1:.4,a=()=>{let o=h.current,s=Date.now()/1e3;for(let r=0;r<x;r++){let a=.5+.15*Math.sin(s*S*i*Math.PI*2+r*C),c=t+(e-t)*o*a;if(y.current!==null){let e=Date.now()-y.current,t=Math.min(e/300,1),n=1-(1-t)*(1-t);c=b.current[r]+(c-b.current[r])*n,t>=1&&(y.current=null)}let l=n===`listening`?.45:1;m.current[r]+=(c-m.current[r])*l}c(m.current,r),p.current=requestAnimationFrame(a)};return p.current=requestAnimationFrame(a),()=>cancelAnimationFrame(p.current)}if(n===`connecting`||n===`thinking`){let n=Date.now(),i=()=>{let a=(Date.now()-n)/1e3;s();for(let n=0;n<x;n++){let r=(a*.6+n/x*.5)%1,i=r<.5?Math.sin(r/.5*Math.PI):0,o=t+(e*.4-t)*i;m.current[n]+=(o-m.current[n])*.15}c(m.current,r),p.current=requestAnimationFrame(i)};return p.current=requestAnimationFrame(i),()=>cancelAnimationFrame(p.current)}cancelAnimationFrame(p.current);let l=()=>{s();for(let e=0;e<x;e++)m.current[e]+=(t-m.current[e])*.16;c(m.current,r),p.current=requestAnimationFrame(l)};return p.current=requestAnimationFrame(l),()=>cancelAnimationFrame(p.current)},[n,i]);let D=i*.055,O=i*.035,k=i*.03,A=i*.55,j=i*.06,M={width:i,height:i,display:`flex`,alignItems:`center`,justifyContent:`center`,position:`relative`,...o},N=(0,t.jsx)(`span`,{ref:f,onMouseEnter:()=>{s||(g.current=!0,f.current&&(f.current.style.filter=`brightness(1.35)`))},onMouseLeave:()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},onTouchEnd:()=>{setTimeout(()=>{g.current=!1,f.current&&(f.current.style.filter=`brightness(1)`)},200)},style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:O,transition:`filter 0.3s ease`,cursor:c?s?`not-allowed`:`pointer`:`default`},children:Array.from({length:x},(e,r)=>(0,t.jsx)(`span`,{ref:e=>{d.current[r]=e},style:{width:D,minHeight:j,maxHeight:A,height:j,borderRadius:k,background:w[n]??w.idle}},r))});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`,...M},children:N}):(0,t.jsx)(`div`,{...u,className:a,style:M,children:N})}function D({signal:i,state:a,volume:s,adapter:c,theme:l=`debug`,size:u=200,className:d,style:f,disabled:p=!1,onStart:m,onStop:h,...g}){let[_,v]=(0,e.useState)({state:`idle`});(0,e.useEffect)(()=>{if(v({state:`idle`}),c)return c.subscribe(v)},[c]);let y=i??_,x=n(a,i,_),S=r(s,x,y),C=x!==`idle`&&x!==`error`,w=(0,e.useCallback)(()=>{p||(C?h?h():c?.stop?.():m?m():c?.start?.())},[c,p,C,m,h]),T=C?!!(c?.stop||h):!!(c?.start||m),D=T&&!p?w:void 0,O={state:x,volume:S,size:u,className:d,style:f,disabled:p,...g,"aria-label":g[`aria-label`]??(T?`${C?`Stop`:`Start`} voice session`:void 0)},k={...O,interactive:T};switch(l){case`circle`:return(0,t.jsx)(b,{...k,onClick:D});case`bars`:return(0,t.jsx)(E,{...k,onClick:D});default:return(0,t.jsx)(o,{...O,onStart:p?void 0:m??(()=>c?.start?.()),onStop:p?void 0:h??(()=>c?.stop?.())})}}exports.Orb=D,exports.VoiceOrb=D;
|