@craftedxp/voice-js 0.4.1 → 0.4.2
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 +4 -1
- package/dist/browser.d.ts +259 -327
- package/dist/browser.js +717 -720
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +43 -37
- package/dist/browser.mjs.map +1 -1
- package/dist/embed.iife.js +4 -1110
- package/dist/node.d.ts +256 -317
- package/dist/node.js +431 -440
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +5 -0
- package/dist/node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -1,128 +1,103 @@
|
|
|
1
1
|
interface ClientTool {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
description: string;
|
|
3
|
+
parameters: Record<string, unknown>;
|
|
4
|
+
usage?: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
example?: string;
|
|
7
|
+
handler: (args: Record<string, unknown>) => Promise<string | object> | string | object;
|
|
8
8
|
}
|
|
9
|
-
type ClientToolMap = Record<string, ClientTool
|
|
9
|
+
type ClientToolMap = Record<string, ClientTool>;
|
|
10
10
|
interface ClientToolCallFrame {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
toolCallId: string;
|
|
12
|
+
name: string;
|
|
13
|
+
args: Record<string, unknown>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type CallState =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
| {
|
|
38
|
-
id: string
|
|
39
|
-
role: 'tool'
|
|
40
|
-
text: string
|
|
41
|
-
}
|
|
42
|
-
| {
|
|
43
|
-
id: string
|
|
44
|
-
role: 'system'
|
|
45
|
-
text: string
|
|
46
|
-
}
|
|
47
|
-
type CallErrorCode =
|
|
48
|
-
| 'missing_credentials'
|
|
49
|
-
| 'forbidden'
|
|
50
|
-
| 'mic_denied'
|
|
51
|
-
| 'mic_start_failed'
|
|
52
|
-
| 'audio_session_failed'
|
|
53
|
-
| 'token_expired'
|
|
54
|
-
| 'token_invalid'
|
|
55
|
-
| 'unauthorized'
|
|
56
|
-
| 'network_unreachable'
|
|
57
|
-
| 'socket_error'
|
|
58
|
-
| 'payment_required'
|
|
59
|
-
| 'not_found'
|
|
60
|
-
| 'silence_timeout'
|
|
61
|
-
| 'server_error'
|
|
16
|
+
type CallState = 'idle' | 'connecting' | 'listening' | 'user_speaking' | 'agent_speaking' | 'ended' | 'error';
|
|
17
|
+
type TranscriptEntry = {
|
|
18
|
+
id: string;
|
|
19
|
+
role: 'user';
|
|
20
|
+
text: string;
|
|
21
|
+
committed: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
id: string;
|
|
24
|
+
role: 'agent';
|
|
25
|
+
text: string;
|
|
26
|
+
interrupted?: boolean;
|
|
27
|
+
} | {
|
|
28
|
+
id: string;
|
|
29
|
+
role: 'tool';
|
|
30
|
+
text: string;
|
|
31
|
+
} | {
|
|
32
|
+
id: string;
|
|
33
|
+
role: 'system';
|
|
34
|
+
text: string;
|
|
35
|
+
};
|
|
36
|
+
type CallErrorCode = 'missing_credentials' | 'forbidden' | 'mic_denied' | 'mic_start_failed' | 'audio_session_failed' | 'token_expired' | 'token_invalid' | 'unauthorized' | 'network_unreachable' | 'socket_error' | 'payment_required' | 'not_found' | 'silence_timeout' | 'server_error';
|
|
62
37
|
interface CallError {
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
code: CallErrorCode;
|
|
39
|
+
message: string;
|
|
65
40
|
}
|
|
66
|
-
type CallEndReason = 'agent_ended' | 'user_hangup' | 'timeout' | 'error'
|
|
41
|
+
type CallEndReason = 'agent_ended' | 'user_hangup' | 'timeout' | 'error';
|
|
67
42
|
interface CallEndEvent {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
reason: CallEndReason;
|
|
44
|
+
errorCode?: CallErrorCode;
|
|
45
|
+
durationMs: number;
|
|
71
46
|
}
|
|
72
47
|
interface VolumeEvent {
|
|
73
|
-
|
|
74
|
-
|
|
48
|
+
input: number;
|
|
49
|
+
output: number;
|
|
75
50
|
}
|
|
76
51
|
type ServerMessage = Record<string, unknown> & {
|
|
77
|
-
|
|
78
|
-
}
|
|
52
|
+
type?: string;
|
|
53
|
+
};
|
|
79
54
|
interface ProtocolState {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
55
|
+
state: CallState;
|
|
56
|
+
transcript: TranscriptEntry[];
|
|
57
|
+
agentBubbleId: string | null;
|
|
58
|
+
idCounter: number;
|
|
59
|
+
endReason: CallEndReason | null;
|
|
85
60
|
}
|
|
86
|
-
declare const createProtocolState: () => ProtocolState
|
|
61
|
+
declare const createProtocolState: () => ProtocolState;
|
|
87
62
|
interface ProtocolCallbacks {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
onState: (next: CallState) => void;
|
|
64
|
+
onTranscript: (entries: TranscriptEntry[]) => void;
|
|
65
|
+
onError: (err: CallError) => void;
|
|
66
|
+
onInterrupt: () => void;
|
|
67
|
+
onAgentTurnStart: (seq?: number) => void;
|
|
68
|
+
onAgentTurnEnd: (seq?: number) => void;
|
|
69
|
+
onCallEnd: (reason: CallEndReason) => void;
|
|
70
|
+
onConnected: () => void;
|
|
71
|
+
onClientToolCall: (frame: ClientToolCallFrame) => void;
|
|
97
72
|
}
|
|
98
|
-
declare function handleServerMessage(raw: string, state: ProtocolState, cb: ProtocolCallbacks): void
|
|
73
|
+
declare function handleServerMessage(raw: string, state: ProtocolState, cb: ProtocolCallbacks): void;
|
|
99
74
|
interface BuildWsUrlArgs {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
75
|
+
apiBase: string;
|
|
76
|
+
agentId: string;
|
|
77
|
+
token: string;
|
|
78
|
+
bargeIn?: boolean;
|
|
104
79
|
}
|
|
105
|
-
declare function buildWsUrl(args: BuildWsUrlArgs): string
|
|
80
|
+
declare function buildWsUrl(args: BuildWsUrlArgs): string;
|
|
106
81
|
|
|
107
82
|
interface FetchTokenArgs {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
83
|
+
/** The agent the SDK is about to call. */
|
|
84
|
+
agentId: string;
|
|
85
|
+
/**
|
|
86
|
+
* Optional consumer-side user identifier. Round-tripped to the server
|
|
87
|
+
* as `contactId` for Phase 11 contact memory. The SDK does not
|
|
88
|
+
* inspect this; your backend uses it to scope the token mint.
|
|
89
|
+
*/
|
|
90
|
+
userId?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Per-call structured context lowered into the agent's effective
|
|
93
|
+
* system prompt server-side at session open. Opaque to the SDK.
|
|
94
|
+
*/
|
|
95
|
+
context?: Record<string, unknown>;
|
|
96
|
+
/**
|
|
97
|
+
* String key/value pairs round-tripped on the `call.ended` webhook.
|
|
98
|
+
* Capped at 1 KB total server-side. NOT lowered into the system prompt.
|
|
99
|
+
*/
|
|
100
|
+
metadata?: Record<string, string>;
|
|
126
101
|
}
|
|
127
102
|
/**
|
|
128
103
|
* What `fetchToken` may return. The rich object form lets the server
|
|
@@ -130,210 +105,207 @@ interface FetchTokenArgs {
|
|
|
130
105
|
* compatible — the SDK treats it as `{ token, transport: 'ws' }`.
|
|
131
106
|
*/
|
|
132
107
|
interface FetchTokenResult {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
108
|
+
/** Raw `ct_` to feed into the WS open / WebRTC offer. */
|
|
109
|
+
token: string;
|
|
110
|
+
/** Server-selected transport. Default `'ws'` if absent. */
|
|
111
|
+
transport?: 'ws' | 'webrtc';
|
|
112
|
+
/** Required when `transport === 'webrtc'` AND the server uses a
|
|
113
|
+
* separate signaling gateway. When omitted on a webrtc result, the
|
|
114
|
+
* SDK falls back to the API base's Phase-1 routes (local dev). */
|
|
115
|
+
webrtcGatewayBase?: string;
|
|
141
116
|
}
|
|
142
|
-
type FetchToken = (args: FetchTokenArgs) => Promise<string | FetchTokenResult
|
|
117
|
+
type FetchToken = (args: FetchTokenArgs) => Promise<string | FetchTokenResult>;
|
|
143
118
|
interface VoiceClientConfig {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Full HTTPS URL of the Voissia server. The WebSocket scheme is
|
|
121
|
+
* derived: `https` → `wss`, `http` → `ws`. No trailing slash needed.
|
|
122
|
+
*/
|
|
123
|
+
apiBase: string;
|
|
124
|
+
/**
|
|
125
|
+
* Called by the SDK whenever it needs a fresh `ct_` token (initial
|
|
126
|
+
* connect; mid-call refresh on `token_expired`). Your implementation
|
|
127
|
+
* should hit YOUR backend, which holds the `sk_` API key and mints
|
|
128
|
+
* via `POST /v1/call-tokens` (or `client.callTokens.mint` from
|
|
129
|
+
* @craftedxp/sdk-node). Never embed `sk_` in JS code that ships to a
|
|
130
|
+
* client.
|
|
131
|
+
*/
|
|
132
|
+
fetchToken: FetchToken;
|
|
133
|
+
/**
|
|
134
|
+
* Optional metadata applied to EVERY startCall. Per-call `metadata`
|
|
135
|
+
* in `startCall` is merged on top (per-call wins on key conflicts).
|
|
136
|
+
* Useful for dashboard-wide tags like `{ surface: 'web', appVersion }`.
|
|
137
|
+
*/
|
|
138
|
+
defaultMetadata?: Record<string, string>;
|
|
139
|
+
/**
|
|
140
|
+
* Optional context applied to EVERY startCall. Per-call `context` in
|
|
141
|
+
* `startCall` is merged on top. Useful for cross-call invariants like
|
|
142
|
+
* the signed-in user's locale.
|
|
143
|
+
*/
|
|
144
|
+
defaultContext?: Record<string, unknown>;
|
|
170
145
|
}
|
|
171
146
|
interface StartCallOptions {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
147
|
+
/** The agent to call. */
|
|
148
|
+
agentId: string;
|
|
149
|
+
/** Per-call user identifier. Round-tripped to fetchToken as `userId`. */
|
|
150
|
+
userId?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Per-call structured context. Merged on top of `defaultContext`
|
|
153
|
+
* configured at factory time.
|
|
154
|
+
*/
|
|
155
|
+
context?: Record<string, unknown>;
|
|
156
|
+
/**
|
|
157
|
+
* Per-call metadata. Merged on top of `defaultMetadata` configured
|
|
158
|
+
* at factory time.
|
|
159
|
+
*/
|
|
160
|
+
metadata?: Record<string, string>;
|
|
161
|
+
/**
|
|
162
|
+
* When false, the SDK + server stay full-duplex but barge-in is
|
|
163
|
+
* suppressed. Useful for alarm-style flows where the user shouldn't
|
|
164
|
+
* accidentally interrupt the script. Default true.
|
|
165
|
+
*/
|
|
166
|
+
bargeIn?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Client-side tools the agent's LLM can call mid-conversation. Each
|
|
169
|
+
* tool's handler runs on the consumer's side; result is fed back to
|
|
170
|
+
* the LLM through the existing call WebSocket. Schema and handler
|
|
171
|
+
* colocate. Validated synchronously at startCall — bad input throws.
|
|
172
|
+
*
|
|
173
|
+
* See docs/integration-echocheck.md for the wire protocol and the
|
|
174
|
+
* server-side guarantees.
|
|
175
|
+
*/
|
|
176
|
+
clientTools?: ClientToolMap;
|
|
177
|
+
/**
|
|
178
|
+
* Test-only escape hatch — pass a pre-minted `ct_` directly and skip
|
|
179
|
+
* the `fetchToken` call. Don't use this in production code: tokens
|
|
180
|
+
* expire and the SDK can't re-mint without the callback.
|
|
181
|
+
*/
|
|
182
|
+
token?: string;
|
|
183
|
+
onStateChange?: (state: CallState) => void;
|
|
184
|
+
onTranscript?: (entries: TranscriptEntry[]) => void;
|
|
185
|
+
onError?: (err: CallError) => void;
|
|
186
|
+
onEnd?: (end: CallEndEvent) => void;
|
|
187
|
+
/** Volume-meter event for VU UIs. ~10 Hz cadence (browser bundle only). */
|
|
188
|
+
onVolume?: (vol: VolumeEvent) => void;
|
|
189
|
+
/**
|
|
190
|
+
* Fires when the server signals barge-in (the user started talking
|
|
191
|
+
* mid-agent-turn). The browser bundle automatically flushes its
|
|
192
|
+
* built-in audio playback before this callback runs; the callback is
|
|
193
|
+
* fired regardless. Node / Electron consumers with custom playback
|
|
194
|
+
* should drain their audio queue here so the agent goes silent
|
|
195
|
+
* immediately.
|
|
196
|
+
*/
|
|
197
|
+
onInterrupt?: () => void;
|
|
198
|
+
/**
|
|
199
|
+
* Fires on `agent_turn_start` — the server has begun a new agent
|
|
200
|
+
* turn. The state-machine transition to `agent_speaking` happens at
|
|
201
|
+
* the same moment via `onStateChange`; use this when you want a
|
|
202
|
+
* precise turn anchor (e.g. "agent has been speaking for N ms" UIs)
|
|
203
|
+
* without diffing state.
|
|
204
|
+
*/
|
|
205
|
+
onAgentTurnStart?: () => void;
|
|
231
206
|
}
|
|
232
207
|
interface Call {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
208
|
+
/** Current state. Snapshot — subscribe via onStateChange for live updates. */
|
|
209
|
+
readonly state: CallState;
|
|
210
|
+
/** Full transcript so far. Snapshot — subscribe via onTranscript for live updates. */
|
|
211
|
+
readonly transcript: TranscriptEntry[];
|
|
212
|
+
/** True after `mute()` and before `unmute()`. */
|
|
213
|
+
readonly isMuted: boolean;
|
|
214
|
+
/** End the call locally. Closes the WS, stops the mic, fires onEnd. Idempotent. */
|
|
215
|
+
end: () => void;
|
|
216
|
+
/** Mute mic frames. Wire stays active so server endpointing doesn't false-positive. Idempotent. */
|
|
217
|
+
mute: () => void;
|
|
218
|
+
/** Unmute mic frames. Idempotent. */
|
|
219
|
+
unmute: () => void;
|
|
245
220
|
}
|
|
246
221
|
interface VoiceClientFactory {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
222
|
+
/** Read back the resolved config (post trailing-slash normalisation). */
|
|
223
|
+
readonly config: VoiceClientConfig;
|
|
224
|
+
/**
|
|
225
|
+
* Open a fresh call. Returns when the WS is open; rejects on
|
|
226
|
+
* pre-flight failure (missing config, fetchToken throw, etc). Mid-
|
|
227
|
+
* call failures arrive via the per-call `onError` callback — they
|
|
228
|
+
* don't reject this promise.
|
|
229
|
+
*/
|
|
230
|
+
startCall: (options: StartCallOptions) => Promise<Call>;
|
|
256
231
|
}
|
|
257
232
|
|
|
258
|
-
type OnChunk = (pcm: ArrayBuffer) => void
|
|
259
|
-
type OnVolume$1 = (rms01: number) => void
|
|
260
|
-
type OnError = (err: Error) => void
|
|
233
|
+
type OnChunk = (pcm: ArrayBuffer) => void;
|
|
234
|
+
type OnVolume$1 = (rms01: number) => void;
|
|
235
|
+
type OnError = (err: Error) => void;
|
|
261
236
|
interface CaptureOptions {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
237
|
+
onChunk: OnChunk;
|
|
238
|
+
onVolume?: OnVolume$1;
|
|
239
|
+
onError?: OnError;
|
|
265
240
|
}
|
|
266
241
|
interface CaptureController {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
242
|
+
start: () => Promise<void>;
|
|
243
|
+
stop: () => void;
|
|
244
|
+
mute: (muted: boolean) => void;
|
|
245
|
+
isCapturing: () => boolean;
|
|
271
246
|
}
|
|
272
|
-
declare const createAudioCapture: (options: CaptureOptions) => CaptureController
|
|
247
|
+
declare const createAudioCapture: (options: CaptureOptions) => CaptureController;
|
|
273
248
|
|
|
274
|
-
type OnVolume = (rms01: number) => void
|
|
275
|
-
type OnAgentSpeakingChange = (speaking: boolean) => void
|
|
249
|
+
type OnVolume = (rms01: number) => void;
|
|
250
|
+
type OnAgentSpeakingChange = (speaking: boolean) => void;
|
|
276
251
|
interface PlaybackOptions {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
252
|
+
sampleRate?: number;
|
|
253
|
+
onVolume?: OnVolume;
|
|
254
|
+
onSpeakingChange?: OnAgentSpeakingChange;
|
|
280
255
|
}
|
|
281
256
|
interface PlaybackController {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
257
|
+
enqueue: (pcm: ArrayBuffer) => void;
|
|
258
|
+
flush: () => void;
|
|
259
|
+
close: () => void;
|
|
260
|
+
resume: () => Promise<void>;
|
|
286
261
|
}
|
|
287
|
-
declare const createAudioPlayback: (options?: PlaybackOptions) => PlaybackController
|
|
262
|
+
declare const createAudioPlayback: (options?: PlaybackOptions) => PlaybackController;
|
|
288
263
|
|
|
289
|
-
type RWSEvent =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
| {
|
|
307
|
-
type: 'error'
|
|
308
|
-
error: Error
|
|
309
|
-
}
|
|
264
|
+
type RWSEvent = {
|
|
265
|
+
type: 'open';
|
|
266
|
+
} | {
|
|
267
|
+
type: 'reconnected';
|
|
268
|
+
} | {
|
|
269
|
+
type: 'message';
|
|
270
|
+
data: string | ArrayBuffer;
|
|
271
|
+
} | {
|
|
272
|
+
type: 'close';
|
|
273
|
+
code: number;
|
|
274
|
+
reason: string;
|
|
275
|
+
permanent: boolean;
|
|
276
|
+
} | {
|
|
277
|
+
type: 'error';
|
|
278
|
+
error: Error;
|
|
279
|
+
};
|
|
310
280
|
interface WebSocketLike {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
281
|
+
binaryType: string;
|
|
282
|
+
readyState: number;
|
|
283
|
+
onopen: ((ev: unknown) => void) | null;
|
|
284
|
+
onmessage: ((ev: {
|
|
285
|
+
data: string | ArrayBuffer;
|
|
286
|
+
}) => void) | null;
|
|
287
|
+
onerror: ((ev: unknown) => void) | null;
|
|
288
|
+
onclose: ((ev: {
|
|
289
|
+
code: number;
|
|
290
|
+
reason: string;
|
|
291
|
+
}) => void) | null;
|
|
292
|
+
send: (data: string | ArrayBuffer | ArrayBufferView) => void;
|
|
293
|
+
close: (code?: number, reason?: string) => void;
|
|
319
294
|
}
|
|
320
|
-
type WebSocketFactory = (url: string) => WebSocketLike
|
|
295
|
+
type WebSocketFactory = (url: string) => WebSocketLike;
|
|
321
296
|
interface RWSOptions {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
declare const createReconnectingWebSocket: (
|
|
329
|
-
options: RWSOptions,
|
|
330
|
-
onEvent: (ev: RWSEvent) => void,
|
|
331
|
-
) => {
|
|
332
|
-
send: (data: string | ArrayBuffer | ArrayBufferView) => void
|
|
333
|
-
close: (code?: number, reason?: string) => void
|
|
334
|
-
readyState: () => number
|
|
297
|
+
url: string;
|
|
298
|
+
wsFactory: WebSocketFactory;
|
|
299
|
+
maxRetries?: number;
|
|
300
|
+
initialBackoffMs?: number;
|
|
301
|
+
maxBackoffMs?: number;
|
|
335
302
|
}
|
|
336
|
-
|
|
303
|
+
declare const createReconnectingWebSocket: (options: RWSOptions, onEvent: (ev: RWSEvent) => void) => {
|
|
304
|
+
send: (data: string | ArrayBuffer | ArrayBufferView) => void;
|
|
305
|
+
close: (code?: number, reason?: string) => void;
|
|
306
|
+
readyState: () => number;
|
|
307
|
+
};
|
|
308
|
+
type ReconnectingWebSocket = ReturnType<typeof createReconnectingWebSocket>;
|
|
337
309
|
|
|
338
310
|
/**
|
|
339
311
|
* One-time SDK setup. Returns a factory you call `startCall` on for
|
|
@@ -360,46 +332,6 @@ type ReconnectingWebSocket = ReturnType<typeof createReconnectingWebSocket>
|
|
|
360
332
|
* call.mute()
|
|
361
333
|
* call.end()
|
|
362
334
|
*/
|
|
363
|
-
declare function configureVoiceClient(config: VoiceClientConfig): VoiceClientFactory
|
|
335
|
+
declare function configureVoiceClient(config: VoiceClientConfig): VoiceClientFactory;
|
|
364
336
|
|
|
365
|
-
export {
|
|
366
|
-
type Call,
|
|
367
|
-
type CallEndEvent,
|
|
368
|
-
type CallEndReason,
|
|
369
|
-
type CallError,
|
|
370
|
-
type CallErrorCode,
|
|
371
|
-
type CallState,
|
|
372
|
-
type CaptureController,
|
|
373
|
-
type CaptureOptions,
|
|
374
|
-
type ClientTool,
|
|
375
|
-
type ClientToolMap,
|
|
376
|
-
type FetchToken,
|
|
377
|
-
type FetchTokenArgs,
|
|
378
|
-
type FetchTokenResult,
|
|
379
|
-
type OnAgentSpeakingChange,
|
|
380
|
-
type OnChunk,
|
|
381
|
-
type OnError,
|
|
382
|
-
type OnVolume$1 as OnVolume,
|
|
383
|
-
type PlaybackController,
|
|
384
|
-
type PlaybackOptions,
|
|
385
|
-
type ProtocolCallbacks,
|
|
386
|
-
type ProtocolState,
|
|
387
|
-
type RWSEvent,
|
|
388
|
-
type RWSOptions,
|
|
389
|
-
type ReconnectingWebSocket,
|
|
390
|
-
type ServerMessage,
|
|
391
|
-
type StartCallOptions,
|
|
392
|
-
type TranscriptEntry,
|
|
393
|
-
type VoiceClientConfig,
|
|
394
|
-
type VoiceClientFactory,
|
|
395
|
-
type VolumeEvent,
|
|
396
|
-
type WebSocketFactory,
|
|
397
|
-
type WebSocketLike,
|
|
398
|
-
buildWsUrl,
|
|
399
|
-
configureVoiceClient,
|
|
400
|
-
createAudioCapture,
|
|
401
|
-
createAudioPlayback,
|
|
402
|
-
createProtocolState,
|
|
403
|
-
createReconnectingWebSocket,
|
|
404
|
-
handleServerMessage,
|
|
405
|
-
}
|
|
337
|
+
export { type Call, type CallEndEvent, type CallEndReason, type CallError, type CallErrorCode, type CallState, type CaptureController, type CaptureOptions, type ClientTool, type ClientToolMap, type FetchToken, type FetchTokenArgs, type FetchTokenResult, type OnAgentSpeakingChange, type OnChunk, type OnError, type OnVolume$1 as OnVolume, type PlaybackController, type PlaybackOptions, type ProtocolCallbacks, type ProtocolState, type RWSEvent, type RWSOptions, type ReconnectingWebSocket, type ServerMessage, type StartCallOptions, type TranscriptEntry, type VoiceClientConfig, type VoiceClientFactory, type VolumeEvent, type WebSocketFactory, type WebSocketLike, buildWsUrl, configureVoiceClient, createAudioCapture, createAudioPlayback, createProtocolState, createReconnectingWebSocket, handleServerMessage };
|