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