orb-ui 0.2.3 → 0.3.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/LICENSE +21 -0
- package/README.md +105 -29
- package/dist/adapters/elevenlabs/index.d.ts +85 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/livekit/index.d.ts +129 -0
- package/dist/adapters/types.d.ts +7 -0
- package/dist/adapters/vapi/index.d.ts +42 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +482 -134
- package/dist/components/Orb/Orb.d.ts +2 -0
- package/dist/components/Orb/Orb.types.d.ts +89 -0
- package/dist/components/Orb/index.d.ts +2 -0
- package/dist/components/Orb/signals.d.ts +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/orb-ui.cjs +2 -2
- package/dist/orb-ui.js +534 -511
- 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 +54 -28
- 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, LiveKit, 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,49 @@ 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
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
|
+
# LiveKit Agents
|
|
46
|
+
npm install orb-ui livekit-client
|
|
47
|
+
```
|
|
48
|
+
|
|
28
49
|
> **Note:** Orb uses React hooks internally — in Next.js App Router, use it in a `'use client'` component.
|
|
29
50
|
|
|
30
51
|
## Quick Start
|
|
31
52
|
|
|
53
|
+
Use orb-ui as a React voice AI component when you need a Vapi voice UI, an ElevenLabs voice UI, a LiveKit voice UI, or a custom animated voice orb for another realtime voice agent stack.
|
|
54
|
+
|
|
32
55
|
### With Vapi
|
|
33
56
|
|
|
34
57
|
```jsx
|
|
@@ -40,7 +63,7 @@ const vapi = new Vapi('your-public-key')
|
|
|
40
63
|
const adapter = createVapiAdapter(vapi, { assistantId: 'your-assistant-id' })
|
|
41
64
|
|
|
42
65
|
function App() {
|
|
43
|
-
return <Orb adapter={adapter} theme="circle" />
|
|
66
|
+
return <Orb adapter={adapter} theme="circle" aria-label="Start Vapi assistant" />
|
|
44
67
|
}
|
|
45
68
|
```
|
|
46
69
|
|
|
@@ -54,10 +77,35 @@ import { createElevenLabsAdapter } from 'orb-ui/adapters'
|
|
|
54
77
|
const adapter = createElevenLabsAdapter(Conversation, { agentId: 'your-agent-id' })
|
|
55
78
|
|
|
56
79
|
function App() {
|
|
57
|
-
return <Orb adapter={adapter} theme="circle" />
|
|
80
|
+
return <Orb adapter={adapter} theme="circle" aria-label="Start ElevenLabs assistant" />
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### With LiveKit
|
|
85
|
+
|
|
86
|
+
```jsx
|
|
87
|
+
import { Room, TokenSource, createAudioAnalyser } from 'livekit-client'
|
|
88
|
+
import { Orb } from 'orb-ui'
|
|
89
|
+
import { createLiveKitAdapter } from 'orb-ui/adapters'
|
|
90
|
+
|
|
91
|
+
const adapter = createLiveKitAdapter({
|
|
92
|
+
tokenSource: TokenSource.endpoint('/api/livekit-token'),
|
|
93
|
+
tokenOptions: {
|
|
94
|
+
agentName: 'your-agent-name',
|
|
95
|
+
roomName: () => `orb-${crypto.randomUUID()}`,
|
|
96
|
+
},
|
|
97
|
+
createAudioAnalyser,
|
|
98
|
+
RoomClass: Room,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
function App() {
|
|
102
|
+
return <Orb adapter={adapter} theme="circle" aria-label="Start LiveKit assistant" />
|
|
58
103
|
}
|
|
59
104
|
```
|
|
60
105
|
|
|
106
|
+
The LiveKit adapter meters the local microphone while listening and the remote agent audio while
|
|
107
|
+
speaking, so every audio-reactive theme follows the active side of the conversation.
|
|
108
|
+
|
|
61
109
|
### Controlled mode (custom integration)
|
|
62
110
|
|
|
63
111
|
```jsx
|
|
@@ -72,53 +120,81 @@ function App() {
|
|
|
72
120
|
}
|
|
73
121
|
```
|
|
74
122
|
|
|
123
|
+
Use `signal` when your integration has separate input and output levels:
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
import { Orb } from 'orb-ui'
|
|
127
|
+
|
|
128
|
+
function App() {
|
|
129
|
+
return <Orb signal={{ state: 'speaking', outputVolume: 0.7 }} theme="circle" />
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
75
133
|
## Themes
|
|
76
134
|
|
|
77
|
-
| Theme
|
|
78
|
-
|
|
79
|
-
| `debug`
|
|
80
|
-
| `circle` | Pulsing circle that reacts to volume.
|
|
81
|
-
| `bars`
|
|
135
|
+
| Theme | Description |
|
|
136
|
+
| -------- | ----------------------------------------------------------------------------- |
|
|
137
|
+
| `debug` | State + volume display with start/stop. Use to verify your integration works. |
|
|
138
|
+
| `circle` | Pulsing circle that reacts to volume. |
|
|
139
|
+
| `bars` | Five bars that animate with voice. |
|
|
140
|
+
|
|
141
|
+
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
142
|
|
|
83
143
|
## Props
|
|
84
144
|
|
|
85
|
-
| Prop
|
|
86
|
-
|
|
87
|
-
| `theme`
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
145
|
+
| Prop | Type | Default | Description |
|
|
146
|
+
| ------------ | ------------------------------- | --------- | ----------------------------------------------------------- |
|
|
147
|
+
| `theme` | `'debug' \| 'circle' \| 'bars'` | `'debug'` | Visual theme |
|
|
148
|
+
| `signal` | `OrbSignal` | — | Rich controlled signal with state/input/output volume |
|
|
149
|
+
| `state` | `OrbState` | `'idle'` | Conversation state (controlled mode) |
|
|
150
|
+
| `volume` | `number` | `0` | Audio volume, 0–1. Overrides signal/adapter volume. |
|
|
151
|
+
| `adapter` | `OrbAdapter` | — | Provider adapter (manages signal updates automatically) |
|
|
152
|
+
| `size` | `number` | `200` | Size in pixels |
|
|
153
|
+
| `className` | `string` | — | Optional class name for the rendered theme |
|
|
154
|
+
| `style` | `React.CSSProperties` | — | Optional inline styles for the rendered theme |
|
|
155
|
+
| `disabled` | `boolean` | `false` | Disables clickable themes and debug start/stop controls |
|
|
156
|
+
| `aria-label` | `string` | generated | Accessible label for clickable `circle` and `bars` controls |
|
|
157
|
+
| `onStart` | `() => void` | — | Custom start handler (overrides adapter.start()) |
|
|
158
|
+
| `onStop` | `() => void` | — | Custom stop handler (overrides adapter.stop()) |
|
|
94
159
|
|
|
95
160
|
## States
|
|
96
161
|
|
|
97
|
-
`idle` · `connecting` · `listening` · `speaking` · `error`
|
|
162
|
+
`idle` · `connecting` · `listening` · `thinking` · `speaking` · `error`
|
|
98
163
|
|
|
99
164
|
## Supported Providers
|
|
100
165
|
|
|
101
|
-
| Provider
|
|
102
|
-
|
|
103
|
-
| [Vapi](https://vapi.ai)
|
|
104
|
-
| [ElevenLabs](https://elevenlabs.io/conversational-ai) | `createElevenLabsAdapter` from `orb-ui/adapters`
|
|
105
|
-
|
|
|
166
|
+
| Provider | Adapter |
|
|
167
|
+
| ----------------------------------------------------- | --------------------------------------------------------------------- |
|
|
168
|
+
| [Vapi](https://vapi.ai) | `createVapiAdapter` from `orb-ui/adapters` |
|
|
169
|
+
| [ElevenLabs](https://elevenlabs.io/conversational-ai) | `createElevenLabsAdapter` from `orb-ui/adapters` |
|
|
170
|
+
| [LiveKit](https://livekit.io) | `createLiveKitAdapter` from `orb-ui/adapters` |
|
|
171
|
+
| Custom | Use controlled mode — pass `signal`, or `state` and `volume` directly |
|
|
106
172
|
|
|
107
173
|
## Development
|
|
108
174
|
|
|
109
175
|
```bash
|
|
110
176
|
git clone https://github.com/alexanderqchen/orb-ui.git
|
|
111
177
|
cd orb-ui
|
|
112
|
-
|
|
113
|
-
cd demo && npm install && cd ..
|
|
178
|
+
pnpm install
|
|
114
179
|
|
|
115
180
|
# Build the library
|
|
116
|
-
|
|
181
|
+
pnpm build
|
|
117
182
|
|
|
118
183
|
# Run demo locally
|
|
119
|
-
|
|
184
|
+
pnpm dev:demo
|
|
120
185
|
```
|
|
121
186
|
|
|
187
|
+
Useful maintenance commands:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
pnpm check # format check, lint, typechecks, tests, library build, demo build
|
|
191
|
+
pnpm format # format repo files
|
|
192
|
+
pnpm changeset # add release notes for a user-facing package change
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Releases are managed with Changesets. Merging a Changesets version PR publishes
|
|
196
|
+
`orb-ui` to npm from GitHub Actions using npm trusted publishing.
|
|
197
|
+
|
|
122
198
|
## License
|
|
123
199
|
|
|
124
200
|
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,4 @@
|
|
|
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 { createLiveKitAdapter, type LiveKitAdapterConfig, type LiveKitConnectionDetails, type LiveKitOrbAdapter, type LiveKitResolvedTokenOptions, type LiveKitTokenOptions, type LiveKitTokenSource, } from './livekit/index.js';
|
|
4
|
+
export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbSignal, OrbSignalListener, OrbState, } from './types.js';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { OrbAdapter } from '../types.js';
|
|
2
|
+
interface LKAnalyserResult {
|
|
3
|
+
calculateVolume: () => number;
|
|
4
|
+
cleanup: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
interface LKAudioTrack {
|
|
7
|
+
mediaStreamTrack: MediaStreamTrack;
|
|
8
|
+
}
|
|
9
|
+
interface LKRemoteAudioTrack extends LKAudioTrack {
|
|
10
|
+
attach(): HTMLMediaElement;
|
|
11
|
+
detach(): HTMLMediaElement[];
|
|
12
|
+
}
|
|
13
|
+
interface LKTrackPublication<TTrack extends LKAudioTrack = LKRemoteAudioTrack> {
|
|
14
|
+
track?: TTrack;
|
|
15
|
+
source: string;
|
|
16
|
+
}
|
|
17
|
+
interface LKParticipant {
|
|
18
|
+
isLocal: boolean;
|
|
19
|
+
attributes?: Record<string, string>;
|
|
20
|
+
getTrackPublication(source: string): LKTrackPublication | undefined;
|
|
21
|
+
kind?: number;
|
|
22
|
+
}
|
|
23
|
+
interface LKLocalParticipant {
|
|
24
|
+
setMicrophoneEnabled(enabled: boolean): Promise<LKTrackPublication<LKAudioTrack> | undefined>;
|
|
25
|
+
getTrackPublication?(source: string): LKTrackPublication<LKAudioTrack> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface LKRoom {
|
|
28
|
+
connect(serverUrl: string, token: string, options?: Record<string, unknown>): Promise<void>;
|
|
29
|
+
disconnect(): void;
|
|
30
|
+
on: unknown;
|
|
31
|
+
off?: unknown;
|
|
32
|
+
removeListener?: unknown;
|
|
33
|
+
remoteParticipants: Map<string, LKParticipant>;
|
|
34
|
+
localParticipant: LKLocalParticipant;
|
|
35
|
+
state: string;
|
|
36
|
+
}
|
|
37
|
+
interface LKCreateAudioAnalyser<TTrack = unknown> {
|
|
38
|
+
(track: TTrack, options?: Record<string, unknown>): LKAnalyserResult;
|
|
39
|
+
}
|
|
40
|
+
type LiveKitTokenOptionValue = string | (() => string);
|
|
41
|
+
export interface LiveKitConnectionDetails {
|
|
42
|
+
/** LiveKit server URL, e.g. "wss://your-project.livekit.cloud". */
|
|
43
|
+
serverUrl: string;
|
|
44
|
+
/** Short-lived participant token generated by LiveKit or your token endpoint. */
|
|
45
|
+
participantToken: string;
|
|
46
|
+
}
|
|
47
|
+
export interface LiveKitResolvedTokenOptions {
|
|
48
|
+
roomName?: string;
|
|
49
|
+
participantName?: string;
|
|
50
|
+
participantIdentity?: string;
|
|
51
|
+
participantMetadata?: string;
|
|
52
|
+
participantAttributes?: Record<string, string>;
|
|
53
|
+
agentName?: string;
|
|
54
|
+
agentMetadata?: string;
|
|
55
|
+
deployment?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface LiveKitTokenOptions {
|
|
58
|
+
roomName?: LiveKitTokenOptionValue;
|
|
59
|
+
participantName?: LiveKitTokenOptionValue;
|
|
60
|
+
participantIdentity?: LiveKitTokenOptionValue;
|
|
61
|
+
participantMetadata?: LiveKitTokenOptionValue;
|
|
62
|
+
participantAttributes?: Record<string, string> | (() => Record<string, string>);
|
|
63
|
+
agentName?: LiveKitTokenOptionValue;
|
|
64
|
+
agentMetadata?: LiveKitTokenOptionValue;
|
|
65
|
+
deployment?: LiveKitTokenOptionValue;
|
|
66
|
+
}
|
|
67
|
+
export interface LiveKitTokenSource {
|
|
68
|
+
fetch(options?: LiveKitResolvedTokenOptions, force?: boolean): Promise<LiveKitConnectionDetails>;
|
|
69
|
+
}
|
|
70
|
+
interface LiveKitManagedBaseConfig<TTrack = unknown> {
|
|
71
|
+
/** The createAudioAnalyser function from livekit-client. */
|
|
72
|
+
createAudioAnalyser: LKCreateAudioAnalyser<TTrack>;
|
|
73
|
+
/** The Room constructor from livekit-client. */
|
|
74
|
+
RoomClass: new (...args: never[]) => LKRoom;
|
|
75
|
+
/** LiveKit room.connect options passed through unchanged. */
|
|
76
|
+
connectOptions?: Record<string, unknown>;
|
|
77
|
+
/** Enable the local microphone after connecting. Defaults to true. */
|
|
78
|
+
enableMicrophone?: boolean;
|
|
79
|
+
/** Options passed to token sources or getConnectionDetails. Values may be resolved per start. */
|
|
80
|
+
tokenOptions?: LiveKitTokenOptions;
|
|
81
|
+
}
|
|
82
|
+
/** App-managed mode: subscribe to a pre-existing Room. */
|
|
83
|
+
interface LiveKitRoomConfig<TTrack = unknown> {
|
|
84
|
+
/** A connected Room instance from livekit-client. */
|
|
85
|
+
room: LKRoom;
|
|
86
|
+
/** The createAudioAnalyser function from livekit-client. */
|
|
87
|
+
createAudioAnalyser: LKCreateAudioAnalyser<TTrack>;
|
|
88
|
+
}
|
|
89
|
+
/** Recommended mode: fetch connection details when the orb starts. */
|
|
90
|
+
interface LiveKitConnectionDetailsConfig<TTrack = unknown> extends LiveKitManagedBaseConfig<TTrack> {
|
|
91
|
+
getConnectionDetails(options: LiveKitResolvedTokenOptions): Promise<LiveKitConnectionDetails>;
|
|
92
|
+
tokenSource?: never;
|
|
93
|
+
serverUrl?: never;
|
|
94
|
+
participantToken?: never;
|
|
95
|
+
}
|
|
96
|
+
/** Convenience mode: use a LiveKit TokenSource such as TokenSource.endpoint or sandboxTokenServer. */
|
|
97
|
+
interface LiveKitTokenSourceConfig<TTrack = unknown> extends LiveKitManagedBaseConfig<TTrack> {
|
|
98
|
+
tokenSource: LiveKitTokenSource;
|
|
99
|
+
getConnectionDetails?: never;
|
|
100
|
+
serverUrl?: never;
|
|
101
|
+
participantToken?: never;
|
|
102
|
+
}
|
|
103
|
+
/** Advanced mode: pass already-generated static credentials. */
|
|
104
|
+
interface LiveKitStaticConnectionConfig<TTrack = unknown> extends LiveKitManagedBaseConfig<TTrack> {
|
|
105
|
+
/** LiveKit server URL, e.g. "wss://your-project.livekit.cloud". */
|
|
106
|
+
serverUrl: string;
|
|
107
|
+
/** Short-lived participant token. Generate this on your server. */
|
|
108
|
+
participantToken: string;
|
|
109
|
+
getConnectionDetails?: never;
|
|
110
|
+
tokenSource?: never;
|
|
111
|
+
}
|
|
112
|
+
type LiveKitManagedConfig<TTrack = unknown> = LiveKitConnectionDetailsConfig<TTrack> | LiveKitTokenSourceConfig<TTrack> | LiveKitStaticConnectionConfig<TTrack>;
|
|
113
|
+
export type LiveKitAdapterConfig<TTrack = unknown> = LiveKitRoomConfig<TTrack> | LiveKitManagedConfig<TTrack>;
|
|
114
|
+
export interface LiveKitOrbAdapter extends OrbAdapter {
|
|
115
|
+
/** Connect to the LiveKit room and start tracking agent state. */
|
|
116
|
+
start(): Promise<void>;
|
|
117
|
+
/** Disconnect from the LiveKit room. */
|
|
118
|
+
stop(): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Creates an OrbAdapter for LiveKit Agents.
|
|
122
|
+
*
|
|
123
|
+
* Managed modes create and own a Room. App-managed mode listens to a Room that
|
|
124
|
+
* your app already connected. The adapter emits signal-native orb-ui state,
|
|
125
|
+
* including LiveKit `thinking` as `OrbState` `"thinking"`, local microphone
|
|
126
|
+
* audio as `inputVolume`, and agent audio as `outputVolume`.
|
|
127
|
+
*/
|
|
128
|
+
export declare function createLiveKitAdapter<TTrack = unknown>(config: LiveKitAdapterConfig<TTrack>): LiveKitOrbAdapter | OrbAdapter;
|
|
129
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbSignal, OrbSignalListener, OrbState } from '../components/Orb/Orb.types.js';
|
|
2
|
+
export type { AdapterCallbacks, LegacyOrbAdapter, OrbAdapter, OrbSignal, OrbSignalListener, OrbState, };
|
|
3
|
+
/**
|
|
4
|
+
* Shared mic volume curve — rescale real-world mic range to 0–1 with pow shaping
|
|
5
|
+
* for custom provider adapters that need browser-side input metering.
|
|
6
|
+
*/
|
|
7
|
+
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 emitted
|
|
32
|
+
* as outputVolume while the assistant is speaking.
|
|
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=new Set,a=null;function o(){a||(a=n.start.bind(n),n.start=async(...e)=>(i.forEach(e=>e()),a(...e)))}function s(){i.size>0||!a||(n.start=a,a=null)}return{async start(){await n.start(r?.assistantId)},stop(){n.stop()},subscribe(r){let a={state:`idle`,volume:0,outputVolume:0},c=0;function l(t){let n=t<e?0:(t-e)/(1-e),r=n>c?.8:.5;return c+=(n-c)*r,c}function u(e){a=e,r(e)}function d(e){u({...a,...e,state:e.state??a.state})}let{emitState:f,clearTimer:p}=t(e=>d({state:e})),m=()=>f(`connecting`),h=`idle`,g=!1,_=()=>{g=!0,h=`listening`,f(`listening`),d({volume:0,outputVolume:0})},v=()=>{g=!1,h=`idle`,E(),f(`idle`),d({volume:0,outputVolume:0}),c=0},y=()=>{g&&(h=`speaking`,f(`speaking`),d({volume:0,outputVolume:0}),T())},b=()=>{g&&(E(),h=`listening`,d({volume:0,outputVolume:0}),c=0,f(`listening`))},x=0,S=0,C=0,w=()=>{h===`speaking`&&(S+=(x-S)*.1,d({volume:S,outputVolume:S})),C=requestAnimationFrame(w)},T=()=>{C||=requestAnimationFrame(w)},E=()=>{C&&=(cancelAnimationFrame(C),0),S=0,x=0},D=e=>{if(h===`speaking`){let t=l(e);x=t/(t+.3)}},O=()=>{},k=e=>{console.error(`[orb-ui/vapi] Error:`,e),g=!1,h=`error`,p(),E(),d({state:`error`,volume:0,outputVolume:0,error:e}),c=0};return n.on(`call-start`,_),n.on(`call-end`,v),n.on(`speech-start`,y),n.on(`speech-end`,b),n.on(`volume-level`,D),n.on(`message`,O),n.on(`error`,k),i.add(m),o(),()=>{p(),E(),c=0,n.removeListener(`call-start`,_),n.removeListener(`call-end`,v),n.removeListener(`speech-start`,y),n.removeListener(`speech-end`,b),n.removeListener(`volume-level`,D),n.removeListener(`message`,O),n.removeListener(`error`,k),i.delete(m),s()}}}}function r(e,t){let n=null,r=0,i=null,a=null,o={state:`idle`,volume:0,inputVolume:0,outputVolume:0},s=`idle`,c=new Set;function l(e){o=e,c.forEach(t=>t(e))}function u(e){o={...o,...e,state:e.state??o.state},l(o)}function d(e){s=e,u({state:e})}function f(){a||=setInterval(()=>{if(n){if(s===`listening`){let e=Math.min(n.getInputVolume()*2,1);u({volume:e,inputVolume:e})}else if(s===`speaking`){let e=Math.min(n.getOutputVolume()*2,1);u({volume:e,outputVolume:e})}}},33)}function p(){a&&=(clearInterval(a),null)}function m(){p(),u({volume:0,inputVolume:0,outputVolume:0})}function h(){s=`idle`,u({state:`idle`,volume:0,inputVolume:0,outputVolume:0})}function g(e){return e===r}function _(e){return{onStatusChange:({status:t})=>{g(e)&&t===`connecting`&&d(`connecting`)},onConnect:()=>{g(e)&&(d(`listening`),f())},onModeChange:({mode:t})=>{g(e)&&(t===`speaking`?(d(`speaking`),f()):(d(`listening`),f()))},onDisconnect:()=>{g(e)&&(p(),n=null,h())},onError:t=>{g(e)&&(console.error(`[orb-ui/elevenlabs] Error:`,t),p(),s=`error`,u({state:`error`,volume:0,inputVolume:0,outputVolume:0,error:t}),n=null)}}}return{subscribe(e){return c.add(e),e(o),n&&(s===`listening`||s===`speaking`)&&f(),()=>{c.delete(e),c.size===0&&m()}},async start(){if(n||i)return i??void 0;r+=1;let a=r;return i=(async()=>{try{let r=await e.startSession({...t,..._(a)});if(!g(a)){await r.endSession().catch(e=>{console.error(`[orb-ui/elevenlabs] stale session cleanup failed:`,e)});return}n=r}catch(e){if(!g(a))return;console.error(`[orb-ui/elevenlabs] startSession failed:`,e),d(`error`),u({volume:0,inputVolume:0,outputVolume:0,error:e})}finally{i=null}})(),i},async stop(){let e=n;if(!e){i&&(r+=1,p(),h(),await i);return}let t=r;p();try{await e.endSession()}catch(e){console.error(`[orb-ui/elevenlabs] endSession failed:`,e)}n===e&&g(t)&&(n=null,h())}}}function i(e){let t=Math.min(e/.5,1);return t**=1.3,t}var a=4,o=.03,s=1.5,c=.6,l=.2,u=.35;function d(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 f(e){return`RoomClass`in e}function p(e){return typeof e==`function`?e():e}function m(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,p(e.roomName)),n(`participantName`,p(e.participantName)),n(`participantIdentity`,p(e.participantIdentity)),n(`participantMetadata`,p(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,p(e.agentName)),n(`agentMetadata`,p(e.agentMetadata)),n(`deployment`,p(e.deployment)),t}function h(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function g(e){let t=m(e.tokenOptions);return typeof e.getConnectionDetails==`function`?h(await e.getConnectionDetails(t)):e.tokenSource?h(await e.tokenSource.fetch(t)):h({serverUrl:e.serverUrl,participantToken:e.participantToken})}function _(e){for(let[,t]of e.remoteParticipants)if(!t.isLocal&&(t.kind===a||t.attributes?.[`lk.agent.state`]!==void 0))return t;return null}function v(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function y(e,t,n){e.on.call(e,t,n)}function b(e){let t=f(e),n=e.createAudioAnalyser,r={current:t?null:e.room},p=new Set,m={state:`idle`,volume:0,inputVolume:0,outputVolume:0},h=`idle`,b=null,x=null,S=null,C=null,w=null,T=null,E=null,D=0,O=null;function k(e){m=e,p.forEach(t=>t(e))}function A(e){k({...m,...e,state:e.state??m.state})}function j(e){let t=e<o?0:e,n=t>D?c:l;D+=(t-D)*n;let r=Math.min(D*s,1);return r/(r+u)}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(e){if(!(b===e&&C)){N({emitZero:!1}),b=e;try{C=n(e)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}w=setInterval(()=>{if(!C||h!==`listening`)return;let e=i(C.calculateVolume());A({volume:e,inputVolume:e,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=n(e)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}E=setInterval(()=>{if(!T||h!==`speaking`)return;let e=j(T.calculateVolume());A({volume:e,inputVolume:0,outputVolume:e})},33)}function L(e){h=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),h===`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=d(e);t!==h&&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 t=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&U(n)},n=(e,t,n)=>{n.isLocal||!(n.kind===a||n.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||B(e)},r=e=>{x===e&&(x=null,z(),F())},i=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(y(e,`participantAttributesChanged`,t),y(e,`trackSubscribed`,n),y(e,`trackUnsubscribed`,r),y(e,`localTrackPublished`,i),y(e,`localTrackUnpublished`,o),y(e,`disconnected`,s),O=()=>{v(e,`participantAttributesChanged`,t),v(e,`trackSubscribed`,n),v(e,`trackUnsubscribed`,r),v(e,`localTrackPublished`,i),v(e,`localTrackUnpublished`,o),v(e,`disconnected`,s)},H(e.localParticipant),e.state===`connected`){let t=_(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=>{p.add(e),e(m);let t=r.current;return t&&G(t),()=>{p.delete(e),p.size===0&&K()}};return t?{subscribe:q,async start(){if(r.current)return;let t=e,n=new t.RoomClass;L(`connecting`);try{let e=await g(t);if(await n.connect(e.serverUrl,e.participantToken,t.connectOptions),r.current=n,G(n),t.enableMicrophone!==!1){let e=(await n.localParticipant.setMicrophoneEnabled(!0))?.track??n.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&V(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),r.current===n&&K(),n.disconnect(),r.current=null,L(`error`),M(),A({error:e}),e}},async stop(){let e=r.current;if(!e){L(`idle`);return}K(),e.disconnect(),r.current=null,L(`idle`)}}:{subscribe:q}}exports.createElevenLabsAdapter=r,exports.createLiveKitAdapter=b,exports.createVapiAdapter=n;
|