orb-ui 0.2.3 → 0.2.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # orb-ui
2
2
 
3
- The simplest way to add voice UI to your React app. One install, one component, works with Vapi and ElevenLabs out of the box.
3
+ React voice agent UI components for Vapi, ElevenLabs, and custom realtime voice AI apps. orb-ui gives you animated voice orbs, audio-reactive themes, accessible clickable controls, and provider adapters for building polished voice agent interfaces in React.
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://orb-ui.com">
@@ -9,26 +9,46 @@ The simplest way to add voice UI to your React app. One install, one component,
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- <a href="https://orb-ui.com">Live Demo</a> · <a href="https://www.npmjs.com/package/orb-ui">npm</a> · <a href="https://github.com/alexanderqchen/orb-ui">GitHub</a>
12
+ <a href="https://orb-ui.com">Live Demo</a> · <a href="https://orb-ui.com/docs/guides/voice-agent-ui">Voice Agent UI Guide</a> · <a href="https://www.npmjs.com/package/orb-ui">npm</a> · <a href="https://github.com/alexanderqchen/orb-ui">GitHub</a>
13
13
  </p>
14
14
 
15
15
  ```jsx
16
+ import Vapi from '@vapi-ai/web'
16
17
  import { Orb } from 'orb-ui'
17
18
  import { createVapiAdapter } from 'orb-ui/adapters'
18
19
 
19
- <Orb adapter={createVapiAdapter(vapi, { assistantId: 'your-id' })} theme="circle" />
20
+ const vapi = new Vapi('your-public-key')
21
+ const adapter = createVapiAdapter(vapi, { assistantId: 'your-assistant-id' })
22
+
23
+ export function VoiceOrb() {
24
+ return <Orb adapter={adapter} theme="circle" aria-label="Start voice assistant" />
25
+ }
20
26
  ```
21
27
 
22
28
  ## Install
23
29
 
30
+ Install the component package:
31
+
24
32
  ```bash
25
33
  npm install orb-ui
26
34
  ```
27
35
 
36
+ Provider adapters are lightweight wrappers around provider SDKs. Install the SDK for the provider you use:
37
+
38
+ ```bash
39
+ # Vapi
40
+ npm install orb-ui @vapi-ai/web
41
+
42
+ # ElevenLabs Conversational AI
43
+ npm install orb-ui @elevenlabs/client
44
+ ```
45
+
28
46
  > **Note:** Orb uses React hooks internally — in Next.js App Router, use it in a `'use client'` component.
29
47
 
30
48
  ## Quick Start
31
49
 
50
+ Use orb-ui as a React voice AI component when you need a Vapi voice UI, an ElevenLabs voice UI, or a custom animated voice orb for another realtime voice agent stack.
51
+
32
52
  ### With Vapi
33
53
 
34
54
  ```jsx
@@ -40,7 +60,7 @@ const vapi = new Vapi('your-public-key')
40
60
  const adapter = createVapiAdapter(vapi, { assistantId: 'your-assistant-id' })
41
61
 
42
62
  function App() {
43
- return <Orb adapter={adapter} theme="circle" />
63
+ return <Orb adapter={adapter} theme="circle" aria-label="Start Vapi assistant" />
44
64
  }
45
65
  ```
46
66
 
@@ -54,7 +74,7 @@ import { createElevenLabsAdapter } from 'orb-ui/adapters'
54
74
  const adapter = createElevenLabsAdapter(Conversation, { agentId: 'your-agent-id' })
55
75
 
56
76
  function App() {
57
- return <Orb adapter={adapter} theme="circle" />
77
+ return <Orb adapter={adapter} theme="circle" aria-label="Start ElevenLabs assistant" />
58
78
  }
59
79
  ```
60
80
 
@@ -74,23 +94,29 @@ function App() {
74
94
 
75
95
  ## Themes
76
96
 
77
- | Theme | Description |
78
- |---|---|
79
- | `debug` | State + volume display with start/stop. Use to verify your integration works. |
80
- | `circle` | Pulsing circle that reacts to volume. |
81
- | `bars` | Five bars that animate with voice. |
97
+ | Theme | Description |
98
+ | -------- | ----------------------------------------------------------------------------- |
99
+ | `debug` | State + volume display with start/stop. Use to verify your integration works. |
100
+ | `circle` | Pulsing circle that reacts to volume. |
101
+ | `bars` | Five bars that animate with voice. |
102
+
103
+ When an adapter or `onStart`/`onStop` handler is provided, `circle` and `bars` render as keyboard-accessible `<button type="button">` controls. Pass an `aria-label` when the surrounding UI does not already label the control.
82
104
 
83
105
  ## Props
84
106
 
85
- | Prop | Type | Default | Description |
86
- |---|---|---|---|
87
- | `theme` | `'debug' \| 'circle' \| 'bars'` | `'debug'` | Visual theme |
88
- | `state` | `OrbState` | `'idle'` | Conversation state (controlled mode) |
89
- | `volume` | `number` | `0` | Audio volume, 0–1 (controlled mode) |
90
- | `adapter` | `OrbAdapter` | — | Provider adapter (manages state + volume automatically) |
91
- | `size` | `number` | `200` | Size in pixels |
92
- | `onStart` | `() => void` | — | Custom start handler (overrides adapter.start()) |
93
- | `onStop` | `() => void` | — | Custom stop handler (overrides adapter.stop()) |
107
+ | Prop | Type | Default | Description |
108
+ | ------------ | ------------------------------- | --------- | ----------------------------------------------------------- |
109
+ | `theme` | `'debug' \| 'circle' \| 'bars'` | `'debug'` | Visual theme |
110
+ | `state` | `OrbState` | `'idle'` | Conversation state (controlled mode) |
111
+ | `volume` | `number` | `0` | Audio volume, 0–1 (controlled mode) |
112
+ | `adapter` | `OrbAdapter` | — | Provider adapter (manages state + volume automatically) |
113
+ | `size` | `number` | `200` | Size in pixels |
114
+ | `className` | `string` | — | Optional class name for the rendered theme |
115
+ | `style` | `React.CSSProperties` | — | Optional inline styles for the rendered theme |
116
+ | `disabled` | `boolean` | `false` | Disables clickable themes and debug start/stop controls |
117
+ | `aria-label` | `string` | generated | Accessible label for clickable `circle` and `bars` controls |
118
+ | `onStart` | `() => void` | — | Custom start handler (overrides adapter.start()) |
119
+ | `onStop` | `() => void` | — | Custom stop handler (overrides adapter.stop()) |
94
120
 
95
121
  ## States
96
122
 
@@ -98,27 +124,37 @@ function App() {
98
124
 
99
125
  ## Supported Providers
100
126
 
101
- | Provider | Adapter |
102
- |---|---|
103
- | [Vapi](https://vapi.ai) | `createVapiAdapter` from `orb-ui/adapters` |
104
- | [ElevenLabs](https://elevenlabs.io/conversational-ai) | `createElevenLabsAdapter` from `orb-ui/adapters` |
105
- | Custom | Use controlled mode — pass `state` and `volume` directly |
127
+ | Provider | Adapter |
128
+ | ----------------------------------------------------- | -------------------------------------------------------- |
129
+ | [Vapi](https://vapi.ai) | `createVapiAdapter` from `orb-ui/adapters` |
130
+ | [ElevenLabs](https://elevenlabs.io/conversational-ai) | `createElevenLabsAdapter` from `orb-ui/adapters` |
131
+ | Custom | Use controlled mode — pass `state` and `volume` directly |
106
132
 
107
133
  ## Development
108
134
 
109
135
  ```bash
110
136
  git clone https://github.com/alexanderqchen/orb-ui.git
111
137
  cd orb-ui
112
- npm install
113
- cd demo && npm install && cd ..
138
+ pnpm install
114
139
 
115
140
  # Build the library
116
- npm run build
141
+ pnpm build
117
142
 
118
143
  # Run demo locally
119
- cd demo && npm run dev
144
+ pnpm dev:demo
120
145
  ```
121
146
 
147
+ Useful maintenance commands:
148
+
149
+ ```bash
150
+ pnpm check # format check, lint, typechecks, tests, library build, demo build
151
+ pnpm format # format repo files
152
+ pnpm changeset # add release notes for a user-facing package change
153
+ ```
154
+
155
+ Releases are managed with Changesets. Merging a Changesets version PR publishes
156
+ `orb-ui` to npm from GitHub Actions using npm trusted publishing.
157
+
122
158
  ## License
123
159
 
124
160
  MIT © [Alexander Chen](https://github.com/alexanderqchen)
@@ -0,0 +1,85 @@
1
+ import { OrbAdapter } from '../types.js';
2
+ export type ElevenLabsMode = 'speaking' | 'listening';
3
+ export type ElevenLabsStatus = 'disconnected' | 'connecting' | 'connected' | 'disconnecting';
4
+ export type ElevenLabsConnectionType = 'websocket' | 'webrtc';
5
+ export interface ElevenLabsCallbacks {
6
+ onConnect?: (props: {
7
+ conversationId: string;
8
+ }) => void;
9
+ onDisconnect?: (details: unknown) => void;
10
+ onError?: (message: string, context?: unknown) => void;
11
+ onModeChange?: (prop: {
12
+ mode: ElevenLabsMode;
13
+ }) => void;
14
+ onStatusChange?: (prop: {
15
+ status: ElevenLabsStatus;
16
+ }) => void;
17
+ onVadScore?: (props: {
18
+ vadScore: number;
19
+ }) => void;
20
+ }
21
+ export interface ElevenLabsConversation {
22
+ endSession(): Promise<void>;
23
+ getInputVolume(): number;
24
+ getOutputVolume(): number;
25
+ getInputByteFrequencyData(): Uint8Array;
26
+ getOutputByteFrequencyData(): Uint8Array;
27
+ }
28
+ type ElevenLabsSessionAuth = {
29
+ agentId: string;
30
+ signedUrl?: never;
31
+ conversationToken?: never;
32
+ connectionType?: ElevenLabsConnectionType;
33
+ } | {
34
+ signedUrl: string;
35
+ agentId?: never;
36
+ conversationToken?: never;
37
+ connectionType?: 'websocket';
38
+ } | {
39
+ conversationToken: string;
40
+ agentId?: never;
41
+ signedUrl?: never;
42
+ connectionType?: 'webrtc';
43
+ };
44
+ export type ElevenLabsConfig = ElevenLabsSessionAuth & {
45
+ /** orb-ui expects a voice conversation, so text-only sessions are intentionally unsupported. */
46
+ textOnly?: false;
47
+ /** Allow @elevenlabs/client startSession options that orb-ui does not inspect. */
48
+ [key: string]: unknown;
49
+ };
50
+ export type ElevenLabsStartSessionOptions = ElevenLabsConfig & ElevenLabsCallbacks;
51
+ export interface ElevenLabsConversationClass {
52
+ startSession(options: ElevenLabsStartSessionOptions): Promise<ElevenLabsConversation>;
53
+ }
54
+ export interface ElevenLabsOrbAdapter extends OrbAdapter {
55
+ /** Start an ElevenLabs conversation. Called automatically by Orb on click. */
56
+ start(): Promise<void>;
57
+ /** Stop the current ElevenLabs conversation. Called automatically by Orb on click. */
58
+ stop(): Promise<void>;
59
+ }
60
+ /**
61
+ * Creates an OrbAdapter for ElevenLabs Conversational AI.
62
+ *
63
+ * Unlike createVapiAdapter, this adapter owns the session lifecycle because
64
+ * ElevenLabs requires callbacks to be injected at Conversation.startSession()
65
+ * time. Pass the returned adapter to Orb and Orb will call start()/stop()
66
+ * when the clickable theme is activated.
67
+ *
68
+ * @param ConversationClass - The Conversation class from @elevenlabs/client
69
+ * @param config - agentId / signedUrl + any other startSession options
70
+ *
71
+ * @example
72
+ * import { Conversation } from '@elevenlabs/client'
73
+ * import { Orb } from 'orb-ui'
74
+ * import { createElevenLabsAdapter } from 'orb-ui/adapters'
75
+ *
76
+ * const adapter = createElevenLabsAdapter(Conversation, {
77
+ * agentId: 'your-agent-id',
78
+ * })
79
+ *
80
+ * function App() {
81
+ * return <Orb adapter={adapter} theme="circle" aria-label="Start ElevenLabs assistant" />
82
+ * }
83
+ */
84
+ export declare function createElevenLabsAdapter(ConversationClass: ElevenLabsConversationClass, config: ElevenLabsConfig): ElevenLabsOrbAdapter;
85
+ export {};
@@ -0,0 +1,3 @@
1
+ export { createVapiAdapter } from './vapi/index.js';
2
+ export { createElevenLabsAdapter, type ElevenLabsCallbacks, type ElevenLabsConfig, type ElevenLabsConnectionType, type ElevenLabsConversation, type ElevenLabsConversationClass, type ElevenLabsMode, type ElevenLabsOrbAdapter, type ElevenLabsStartSessionOptions, type ElevenLabsStatus, } from './elevenlabs/index.js';
3
+ export type { OrbAdapter, OrbState, AdapterCallbacks } from './types.js';
@@ -0,0 +1,11 @@
1
+ import { OrbState, OrbAdapter } from '../components/Orb/Orb.types.js';
2
+ export type { OrbState, OrbAdapter };
3
+ export interface AdapterCallbacks {
4
+ onStateChange: (state: OrbState) => void;
5
+ onVolumeChange: (volume: number) => void;
6
+ }
7
+ /**
8
+ * Shared mic volume curve — rescale real-world mic range to 0–1 with pow shaping.
9
+ * Used by both Vapi and ElevenLabs adapters for consistent listening visuals.
10
+ */
11
+ export declare function normalizeMicVolume(v: number): number;
@@ -0,0 +1,42 @@
1
+ import { OrbAdapter } from '../types.js';
2
+ interface VapiClient {
3
+ on(event: 'call-start', listener: () => void): void;
4
+ on(event: 'call-end', listener: () => void): void;
5
+ on(event: 'speech-start', listener: () => void): void;
6
+ on(event: 'speech-end', listener: () => void): void;
7
+ on(event: 'volume-level', listener: (volume: number) => void): void;
8
+ on(event: 'message', listener: (message: VapiMessage) => void): void;
9
+ on(event: 'error', listener: (error: unknown) => void): void;
10
+ removeListener(event: string, listener: (...args: unknown[]) => void): void;
11
+ start(...args: any[]): Promise<unknown>;
12
+ stop(): void;
13
+ }
14
+ interface VapiMessage {
15
+ type: string;
16
+ role?: string;
17
+ transcriptType?: 'partial' | 'final';
18
+ transcript?: string;
19
+ }
20
+ /**
21
+ * Creates an OrbAdapter for Vapi voice agents.
22
+ *
23
+ * State mapping:
24
+ * vapi.start() called (intercepted) → 'connecting'
25
+ * call-start → 'listening'
26
+ * speech-start → 'speaking'
27
+ * speech-end → 'listening' (debounced 350 ms)
28
+ * call-end → 'idle'
29
+ * error → 'error'
30
+ *
31
+ * Volume: raw Vapi values are normalized (noise gate + EMA) before being
32
+ * passed to onVolumeChange, so themes receive a clean 0–1 signal.
33
+ *
34
+ * @param client - A Vapi instance from @vapi-ai/web
35
+ * @param options - Optional config (e.g. assistantId to pass to vapi.start())
36
+ */
37
+ interface VapiAdapterOptions {
38
+ /** Assistant ID passed to vapi.start() when the orb is clicked. */
39
+ assistantId?: string;
40
+ }
41
+ export declare function createVapiAdapter(client: VapiClient, options?: VapiAdapterOptions): OrbAdapter;
42
+ export {};
package/dist/adapters.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=.12;function C(t){let l="idle",e=null;function i(n){if(e&&(clearTimeout(e),e=null),l==="speaking"&&n==="listening"){e=setTimeout(()=>{l=n,t(n),e=null},350);return}l=n,t(n)}function s(){e&&(clearTimeout(e),e=null)}return{emitState:i,clearTimer:s}}function I(t,l){let e=0;function i(s){const n=s<b?0:(s-b)/(1-b),o=n>e?.8:.5;return e=e+(n-e)*o,e}return{async start(){await t.start(l==null?void 0:l.assistantId)},stop(){t.stop()},subscribe({onStateChange:s,onVolumeChange:n}){const{emitState:o,clearTimer:g}=C(s);let a="idle",c=!1;const r=()=>{c=!0,a="listening",o("listening")},u=()=>{c=!1,a="idle",p(),o("idle"),n(0),e=0},S=()=>{c&&(a="speaking",o("speaking"),T())},L=()=>{c&&(p(),a="listening",o("listening"))};let v=0,d=0,m=0;const E=()=>{a==="speaking"&&(d+=(v-d)*.1,n(d)),m=requestAnimationFrame(E)},T=()=>{m||(m=requestAnimationFrame(E))},p=()=>{m&&(cancelAnimationFrame(m),m=0),d=0,v=0},V=f=>{if(a==="speaking"){const A=i(f);v=A/(A+.3)}},h=f=>{},k=f=>{console.error("[orb-ui/vapi] Error:",f),p(),o("error"),n(0),e=0};t.on("call-start",r),t.on("call-end",u),t.on("speech-start",S),t.on("speech-end",L),t.on("volume-level",V),t.on("message",h),t.on("error",k);const y=t.start.bind(t);return t.start=async(...f)=>(o("connecting"),y(...f)),()=>{g(),t.removeListener("call-start",r),t.removeListener("call-end",u),t.removeListener("speech-start",S),t.removeListener("speech-end",L),t.removeListener("volume-level",V),t.removeListener("message",h),t.removeListener("error",k),t.start=y}}}}function O(t,l){let e=null,i=null;const s=new Set;function n(r){s.forEach(u=>u.onStateChange(r))}function o(r){s.forEach(u=>u.onVolumeChange(r))}function g(){i||(i=setInterval(()=>{if(!e)return;const r=e.getOutputVolume();o(Math.min(r*2,1))},33))}function a(){i&&(clearInterval(i),i=null),o(0)}const c={onStatusChange:({status:r})=>{r==="connecting"&&n("connecting")},onConnect:()=>{n("listening")},onModeChange:({mode:r})=>{r==="speaking"?(n("speaking"),g()):(n("listening"),a())},onDisconnect:()=>{a(),n("idle"),o(0),e=null},onError:r=>{console.error("[orb-ui/elevenlabs] Error:",r),a(),n("error"),o(0),e=null}};return{subscribe(r){return s.add(r),()=>{s.delete(r),s.size===0&&a()}},async start(){if(!e)try{e=await t.startSession({...l,...c})}catch(r){console.error("[orb-ui/elevenlabs] startSession failed:",r),n("error"),o(0)}},async stop(){if(e){a();try{await e.endSession()}catch(r){console.error("[orb-ui/elevenlabs] endSession failed:",r)}e=null}}}}exports.createElevenLabsAdapter=O;exports.createVapiAdapter=I;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=.12;function t(e){let t=`idle`,n=null;function r(r){if(n&&=(clearTimeout(n),null),t===`speaking`&&r===`listening`){n=setTimeout(()=>{t=r,e(r),n=null},350);return}t=r,e(r)}function i(){n&&=(clearTimeout(n),null)}return{emitState:r,clearTimer:i}}function n(n,r){let i=0;function a(t){let n=t<e?0:(t-e)/(1-e),r=n>i?.8:.5;return i+=(n-i)*r,i}return{async start(){await n.start(r?.assistantId)},stop(){n.stop()},subscribe({onStateChange:e,onVolumeChange:r}){let{emitState:o,clearTimer:s}=t(e),c=`idle`,l=!1,u=()=>{l=!0,c=`listening`,o(`listening`)},d=()=>{l=!1,c=`idle`,y(),o(`idle`),r(0),i=0},f=()=>{l&&(c=`speaking`,o(`speaking`),v())},p=()=>{l&&(y(),c=`listening`,o(`listening`))},m=0,h=0,g=0,_=()=>{c===`speaking`&&(h+=(m-h)*.1,r(h)),g=requestAnimationFrame(_)},v=()=>{g||=requestAnimationFrame(_)},y=()=>{g&&=(cancelAnimationFrame(g),0),h=0,m=0},b=e=>{if(c===`speaking`){let t=a(e);m=t/(t+.3)}},x=()=>{},S=e=>{console.error(`[orb-ui/vapi] Error:`,e),y(),o(`error`),r(0),i=0};n.on(`call-start`,u),n.on(`call-end`,d),n.on(`speech-start`,f),n.on(`speech-end`,p),n.on(`volume-level`,b),n.on(`message`,x),n.on(`error`,S);let C=n.start.bind(n);return n.start=async(...e)=>(o(`connecting`),C(...e)),()=>{s(),n.removeListener(`call-start`,u),n.removeListener(`call-end`,d),n.removeListener(`speech-start`,f),n.removeListener(`speech-end`,p),n.removeListener(`volume-level`,b),n.removeListener(`message`,x),n.removeListener(`error`,S),n.start=C}}}}function r(e,t){let n=null,r=null,i=new Set;function a(e){i.forEach(t=>t.onStateChange(e))}function o(e){i.forEach(t=>t.onVolumeChange(e))}function s(){r||=setInterval(()=>{if(!n)return;let e=n.getOutputVolume();o(Math.min(e*2,1))},33)}function c(){r&&=(clearInterval(r),null),o(0)}let l={onStatusChange:({status:e})=>{e===`connecting`&&a(`connecting`)},onConnect:()=>{a(`listening`)},onModeChange:({mode:e})=>{e===`speaking`?(a(`speaking`),s()):(a(`listening`),c())},onDisconnect:()=>{c(),a(`idle`),o(0),n=null},onError:e=>{console.error(`[orb-ui/elevenlabs] Error:`,e),c(),a(`error`),o(0),n=null}};return{subscribe(e){return i.add(e),()=>{i.delete(e),i.size===0&&c()}},async start(){if(!n)try{n=await e.startSession({...t,...l})}catch(e){console.error(`[orb-ui/elevenlabs] startSession failed:`,e),a(`error`),o(0)}},async stop(){if(n){c();try{await n.endSession()}catch(e){console.error(`[orb-ui/elevenlabs] endSession failed:`,e)}n=null}}}}exports.createElevenLabsAdapter=r,exports.createVapiAdapter=n;
package/dist/adapters.js CHANGED
@@ -1,137 +1,133 @@
1
- function F(t) {
2
- let l = "idle", e = null;
3
- function i(n) {
4
- if (e && (clearTimeout(e), e = null), l === "speaking" && n === "listening") {
5
- e = setTimeout(() => {
6
- l = n, t(n), e = null;
7
- }, 350);
8
- return;
9
- }
10
- l = n, t(n);
11
- }
12
- function s() {
13
- e && (clearTimeout(e), e = null);
14
- }
15
- return { emitState: i, clearTimer: s };
1
+ //#region src/adapters/vapi/index.ts
2
+ var e = .12;
3
+ function t(e) {
4
+ let t = "idle", n = null;
5
+ function r(r) {
6
+ if (n &&= (clearTimeout(n), null), t === "speaking" && r === "listening") {
7
+ n = setTimeout(() => {
8
+ t = r, e(r), n = null;
9
+ }, 350);
10
+ return;
11
+ }
12
+ t = r, e(r);
13
+ }
14
+ function i() {
15
+ n &&= (clearTimeout(n), null);
16
+ }
17
+ return {
18
+ emitState: r,
19
+ clearTimer: i
20
+ };
16
21
  }
17
- function y(t, l) {
18
- let e = 0;
19
- function i(s) {
20
- const n = s < 0.12 ? 0 : (s - 0.12) / 0.88, o = n > e ? 0.8 : 0.5;
21
- return e = e + (n - e) * o, e;
22
- }
23
- return {
24
- async start() {
25
- await t.start(l == null ? void 0 : l.assistantId);
26
- },
27
- stop() {
28
- t.stop();
29
- },
30
- subscribe({ onStateChange: s, onVolumeChange: n }) {
31
- const { emitState: o, clearTimer: d } = F(s);
32
- let a = "idle", u = !1;
33
- const r = () => {
34
- u = !0, a = "listening", o("listening");
35
- }, c = () => {
36
- u = !1, a = "idle", p(), o("idle"), n(0), e = 0;
37
- }, S = () => {
38
- u && (a = "speaking", o("speaking"), I());
39
- }, L = () => {
40
- u && (p(), a = "listening", o("listening"));
41
- };
42
- let v = 0, g = 0, m = 0;
43
- const b = () => {
44
- a === "speaking" && (g += (v - g) * 0.1, n(g)), m = requestAnimationFrame(b);
45
- }, I = () => {
46
- m || (m = requestAnimationFrame(b));
47
- }, p = () => {
48
- m && (cancelAnimationFrame(m), m = 0), g = 0, v = 0;
49
- }, E = (f) => {
50
- if (a === "speaking") {
51
- const k = i(f);
52
- v = k / (k + 0.3);
53
- }
54
- }, O = (f) => {
55
- }, h = (f) => {
56
- console.error("[orb-ui/vapi] Error:", f), p(), o("error"), n(0), e = 0;
57
- };
58
- t.on("call-start", r), t.on("call-end", c), t.on("speech-start", S), t.on("speech-end", L), t.on("volume-level", E), t.on("message", O), t.on("error", h);
59
- const V = t.start.bind(t);
60
- return t.start = async (...f) => (o("connecting"), V(...f)), () => {
61
- d(), t.removeListener("call-start", r), t.removeListener("call-end", c), t.removeListener("speech-start", S), t.removeListener("speech-end", L), t.removeListener("volume-level", E), t.removeListener("message", O), t.removeListener("error", h), t.start = V;
62
- };
63
- }
64
- };
22
+ function n(n, r) {
23
+ let i = 0;
24
+ function a(t) {
25
+ let n = t < e ? 0 : (t - e) / (1 - e), r = n > i ? .8 : .5;
26
+ return i += (n - i) * r, i;
27
+ }
28
+ return {
29
+ async start() {
30
+ await n.start(r?.assistantId);
31
+ },
32
+ stop() {
33
+ n.stop();
34
+ },
35
+ subscribe({ onStateChange: e, onVolumeChange: r }) {
36
+ let { emitState: o, clearTimer: s } = t(e), c = "idle", l = !1, u = () => {
37
+ l = !0, c = "listening", o("listening");
38
+ }, d = () => {
39
+ l = !1, c = "idle", y(), o("idle"), r(0), i = 0;
40
+ }, f = () => {
41
+ l && (c = "speaking", o("speaking"), v());
42
+ }, p = () => {
43
+ l && (y(), c = "listening", o("listening"));
44
+ }, m = 0, h = 0, g = 0, _ = () => {
45
+ c === "speaking" && (h += (m - h) * .1, r(h)), g = requestAnimationFrame(_);
46
+ }, v = () => {
47
+ g ||= requestAnimationFrame(_);
48
+ }, y = () => {
49
+ g &&= (cancelAnimationFrame(g), 0), h = 0, m = 0;
50
+ }, b = (e) => {
51
+ if (c === "speaking") {
52
+ let t = a(e);
53
+ m = t / (t + .3);
54
+ }
55
+ }, x = () => {}, S = (e) => {
56
+ console.error("[orb-ui/vapi] Error:", e), y(), o("error"), r(0), i = 0;
57
+ };
58
+ n.on("call-start", u), n.on("call-end", d), n.on("speech-start", f), n.on("speech-end", p), n.on("volume-level", b), n.on("message", x), n.on("error", S);
59
+ let C = n.start.bind(n);
60
+ return n.start = async (...e) => (o("connecting"), C(...e)), () => {
61
+ s(), n.removeListener("call-start", u), n.removeListener("call-end", d), n.removeListener("speech-start", f), n.removeListener("speech-end", p), n.removeListener("volume-level", b), n.removeListener("message", x), n.removeListener("error", S), n.start = C;
62
+ };
63
+ }
64
+ };
65
65
  }
66
- function A(t, l) {
67
- let e = null, i = null;
68
- const s = /* @__PURE__ */ new Set();
69
- function n(r) {
70
- s.forEach((c) => c.onStateChange(r));
71
- }
72
- function o(r) {
73
- s.forEach((c) => c.onVolumeChange(r));
74
- }
75
- function d() {
76
- i || (i = setInterval(() => {
77
- if (!e) return;
78
- const r = e.getOutputVolume();
79
- o(Math.min(r * 2, 1));
80
- }, 33));
81
- }
82
- function a() {
83
- i && (clearInterval(i), i = null), o(0);
84
- }
85
- const u = {
86
- onStatusChange: ({ status: r }) => {
87
- r === "connecting" && n("connecting");
88
- },
89
- onConnect: () => {
90
- n("listening");
91
- },
92
- onModeChange: ({ mode: r }) => {
93
- r === "speaking" ? (n("speaking"), d()) : (n("listening"), a());
94
- },
95
- onDisconnect: () => {
96
- a(), n("idle"), o(0), e = null;
97
- },
98
- onError: (r) => {
99
- console.error("[orb-ui/elevenlabs] Error:", r), a(), n("error"), o(0), e = null;
100
- }
101
- };
102
- return {
103
- // ── OrbAdapter.subscribe ────────────────────────────────────────────────
104
- subscribe(r) {
105
- return s.add(r), () => {
106
- s.delete(r), s.size === 0 && a();
107
- };
108
- },
109
- // ── Lifecycle ───────────────────────────────────────────────────────────
110
- async start() {
111
- if (!e)
112
- try {
113
- e = await t.startSession({
114
- ...l,
115
- ...u
116
- });
117
- } catch (r) {
118
- console.error("[orb-ui/elevenlabs] startSession failed:", r), n("error"), o(0);
119
- }
120
- },
121
- async stop() {
122
- if (e) {
123
- a();
124
- try {
125
- await e.endSession();
126
- } catch (r) {
127
- console.error("[orb-ui/elevenlabs] endSession failed:", r);
128
- }
129
- e = null;
130
- }
131
- }
132
- };
66
+ //#endregion
67
+ //#region src/adapters/elevenlabs/index.ts
68
+ function r(e, t) {
69
+ let n = null, r = null, i = /* @__PURE__ */ new Set();
70
+ function a(e) {
71
+ i.forEach((t) => t.onStateChange(e));
72
+ }
73
+ function o(e) {
74
+ i.forEach((t) => t.onVolumeChange(e));
75
+ }
76
+ function s() {
77
+ r ||= setInterval(() => {
78
+ if (!n) return;
79
+ let e = n.getOutputVolume();
80
+ o(Math.min(e * 2, 1));
81
+ }, 33);
82
+ }
83
+ function c() {
84
+ r &&= (clearInterval(r), null), o(0);
85
+ }
86
+ let l = {
87
+ onStatusChange: ({ status: e }) => {
88
+ e === "connecting" && a("connecting");
89
+ },
90
+ onConnect: () => {
91
+ a("listening");
92
+ },
93
+ onModeChange: ({ mode: e }) => {
94
+ e === "speaking" ? (a("speaking"), s()) : (a("listening"), c());
95
+ },
96
+ onDisconnect: () => {
97
+ c(), a("idle"), o(0), n = null;
98
+ },
99
+ onError: (e) => {
100
+ console.error("[orb-ui/elevenlabs] Error:", e), c(), a("error"), o(0), n = null;
101
+ }
102
+ };
103
+ return {
104
+ subscribe(e) {
105
+ return i.add(e), () => {
106
+ i.delete(e), i.size === 0 && c();
107
+ };
108
+ },
109
+ async start() {
110
+ if (!n) try {
111
+ n = await e.startSession({
112
+ ...t,
113
+ ...l
114
+ });
115
+ } catch (e) {
116
+ console.error("[orb-ui/elevenlabs] startSession failed:", e), a("error"), o(0);
117
+ }
118
+ },
119
+ async stop() {
120
+ if (n) {
121
+ c();
122
+ try {
123
+ await n.endSession();
124
+ } catch (e) {
125
+ console.error("[orb-ui/elevenlabs] endSession failed:", e);
126
+ }
127
+ n = null;
128
+ }
129
+ }
130
+ };
133
131
  }
134
- export {
135
- A as createElevenLabsAdapter,
136
- y as createVapiAdapter
137
- };
132
+ //#endregion
133
+ export { r as createElevenLabsAdapter, n as createVapiAdapter };
@@ -0,0 +1,2 @@
1
+ import { OrbProps } from './Orb.types.js';
2
+ export declare function Orb({ state: stateProp, volume: volumeProp, adapter, theme, size, className, style, disabled, onStart, onStop, ...htmlProps }: OrbProps): import("react/jsx-runtime").JSX.Element;