orb-ui 0.2.2 → 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 +21 -0
- package/README.md +64 -30
- package/dist/adapters/elevenlabs/index.d.ts +85 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/types.d.ts +11 -0
- package/dist/adapters/vapi/index.d.ts +42 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +130 -134
- package/dist/components/Orb/Orb.d.ts +2 -0
- package/dist/components/Orb/Orb.types.d.ts +68 -0
- package/dist/components/Orb/index.d.ts +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/orb-ui.cjs +2 -2
- package/dist/orb-ui.js +556 -512
- package/dist/themes/bars/BarsTheme.d.ts +14 -0
- package/dist/themes/bars/index.d.ts +1 -0
- package/dist/themes/circle/CircleTheme.d.ts +14 -0
- package/dist/themes/circle/index.d.ts +1 -0
- package/dist/themes/debug/DebugTheme.d.ts +15 -0
- package/dist/themes/debug/index.d.ts +1 -0
- package/dist/themes/index.d.ts +3 -0
- package/package.json +50 -27
- package/dist/adapters.d.ts +0 -145
- package/dist/orb-ui.d.ts +0 -56
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
|
-
|
|
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,28 +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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
34
|
+
```
|
|
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
|
|
28
44
|
```
|
|
29
45
|
|
|
30
46
|
> **Note:** Orb uses React hooks internally — in Next.js App Router, use it in a `'use client'` component.
|
|
31
47
|
|
|
32
48
|
## Quick Start
|
|
33
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
|
+
|
|
34
52
|
### With Vapi
|
|
35
53
|
|
|
36
54
|
```jsx
|
|
@@ -42,7 +60,7 @@ const vapi = new Vapi('your-public-key')
|
|
|
42
60
|
const adapter = createVapiAdapter(vapi, { assistantId: 'your-assistant-id' })
|
|
43
61
|
|
|
44
62
|
function App() {
|
|
45
|
-
return <Orb adapter={adapter} theme="circle" />
|
|
63
|
+
return <Orb adapter={adapter} theme="circle" aria-label="Start Vapi assistant" />
|
|
46
64
|
}
|
|
47
65
|
```
|
|
48
66
|
|
|
@@ -56,7 +74,7 @@ import { createElevenLabsAdapter } from 'orb-ui/adapters'
|
|
|
56
74
|
const adapter = createElevenLabsAdapter(Conversation, { agentId: 'your-agent-id' })
|
|
57
75
|
|
|
58
76
|
function App() {
|
|
59
|
-
return <Orb adapter={adapter} theme="circle" />
|
|
77
|
+
return <Orb adapter={adapter} theme="circle" aria-label="Start ElevenLabs assistant" />
|
|
60
78
|
}
|
|
61
79
|
```
|
|
62
80
|
|
|
@@ -76,23 +94,29 @@ function App() {
|
|
|
76
94
|
|
|
77
95
|
## Themes
|
|
78
96
|
|
|
79
|
-
| Theme
|
|
80
|
-
|
|
81
|
-
| `debug`
|
|
82
|
-
| `circle` | Pulsing circle that reacts to volume.
|
|
83
|
-
| `bars`
|
|
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.
|
|
84
104
|
|
|
85
105
|
## Props
|
|
86
106
|
|
|
87
|
-
| Prop
|
|
88
|
-
|
|
89
|
-
| `theme`
|
|
90
|
-
| `state`
|
|
91
|
-
| `volume`
|
|
92
|
-
| `adapter`
|
|
93
|
-
| `size`
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
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()) |
|
|
96
120
|
|
|
97
121
|
## States
|
|
98
122
|
|
|
@@ -100,27 +124,37 @@ function App() {
|
|
|
100
124
|
|
|
101
125
|
## Supported Providers
|
|
102
126
|
|
|
103
|
-
| Provider
|
|
104
|
-
|
|
105
|
-
| [Vapi](https://vapi.ai)
|
|
106
|
-
| [ElevenLabs](https://elevenlabs.io/conversational-ai) | `createElevenLabsAdapter` from `orb-ui/adapters`
|
|
107
|
-
| Custom
|
|
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 |
|
|
108
132
|
|
|
109
133
|
## Development
|
|
110
134
|
|
|
111
135
|
```bash
|
|
112
136
|
git clone https://github.com/alexanderqchen/orb-ui.git
|
|
113
137
|
cd orb-ui
|
|
114
|
-
|
|
115
|
-
cd demo && yarn install && cd ..
|
|
138
|
+
pnpm install
|
|
116
139
|
|
|
117
140
|
# Build the library
|
|
118
|
-
|
|
141
|
+
pnpm build
|
|
119
142
|
|
|
120
143
|
# Run demo locally
|
|
121
|
-
|
|
144
|
+
pnpm dev:demo
|
|
122
145
|
```
|
|
123
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
|
+
|
|
124
158
|
## License
|
|
125
159
|
|
|
126
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
y as createVapiAdapter
|
|
137
|
-
};
|
|
132
|
+
//#endregion
|
|
133
|
+
export { r as createElevenLabsAdapter, n as createVapiAdapter };
|