@vapi-ai/web 1.0.266 → 1.1.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/.prettierrc +5 -0
- package/README.md +7 -2
- package/api.ts +915 -525
- package/dist/api.d.ts +511 -215
- package/dist/api.js +83 -73
- package/dist/vapi.d.ts +15 -11
- package/dist/vapi.js +29 -26
- package/package.json +3 -3
- package/update.sh +1 -1
- package/vapi.ts +60 -71
- package/dist/AtomicMediaSource.d.ts +0 -17
- package/dist/AtomicMediaSource.js +0 -78
- package/dist/player.d.ts +0 -10
- package/dist/player.js +0 -38
package/dist/api.js
CHANGED
|
@@ -19,16 +19,16 @@ var ContentType;
|
|
|
19
19
|
ContentType["Text"] = "text/plain";
|
|
20
20
|
})(ContentType || (exports.ContentType = ContentType = {}));
|
|
21
21
|
class HttpClient {
|
|
22
|
-
baseUrl =
|
|
22
|
+
baseUrl = 'https://west-api.vapi.ai';
|
|
23
23
|
securityData = null;
|
|
24
24
|
securityWorker;
|
|
25
25
|
abortControllers = new Map();
|
|
26
26
|
customFetch = (...fetchParams) => fetch(...fetchParams);
|
|
27
27
|
baseApiParams = {
|
|
28
|
-
credentials:
|
|
28
|
+
credentials: 'same-origin',
|
|
29
29
|
headers: {},
|
|
30
|
-
redirect:
|
|
31
|
-
referrerPolicy:
|
|
30
|
+
redirect: 'follow',
|
|
31
|
+
referrerPolicy: 'no-referrer',
|
|
32
32
|
};
|
|
33
33
|
constructor(apiConfig = {}) {
|
|
34
34
|
Object.assign(this, apiConfig);
|
|
@@ -38,40 +38,38 @@ class HttpClient {
|
|
|
38
38
|
};
|
|
39
39
|
encodeQueryParam(key, value) {
|
|
40
40
|
const encodedKey = encodeURIComponent(key);
|
|
41
|
-
return `${encodedKey}=${encodeURIComponent(typeof value ===
|
|
41
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === 'number' ? value : `${value}`)}`;
|
|
42
42
|
}
|
|
43
43
|
addQueryParam(query, key) {
|
|
44
44
|
return this.encodeQueryParam(key, query[key]);
|
|
45
45
|
}
|
|
46
46
|
addArrayQueryParam(query, key) {
|
|
47
47
|
const value = query[key];
|
|
48
|
-
return value.map((v) => this.encodeQueryParam(key, v)).join(
|
|
48
|
+
return value.map((v) => this.encodeQueryParam(key, v)).join('&');
|
|
49
49
|
}
|
|
50
50
|
toQueryString(rawQuery) {
|
|
51
51
|
const query = rawQuery || {};
|
|
52
|
-
const keys = Object.keys(query).filter((key) =>
|
|
52
|
+
const keys = Object.keys(query).filter((key) => 'undefined' !== typeof query[key]);
|
|
53
53
|
return keys
|
|
54
54
|
.map((key) => Array.isArray(query[key])
|
|
55
55
|
? this.addArrayQueryParam(query, key)
|
|
56
56
|
: this.addQueryParam(query, key))
|
|
57
|
-
.join(
|
|
57
|
+
.join('&');
|
|
58
58
|
}
|
|
59
59
|
addQueryParams(rawQuery) {
|
|
60
60
|
const queryString = this.toQueryString(rawQuery);
|
|
61
|
-
return queryString ? `?${queryString}` :
|
|
61
|
+
return queryString ? `?${queryString}` : '';
|
|
62
62
|
}
|
|
63
63
|
contentFormatters = {
|
|
64
|
-
[ContentType.Json]: (input) => input !== null && (typeof input ===
|
|
65
|
-
? JSON.stringify(input)
|
|
66
|
-
: input,
|
|
67
|
-
[ContentType.Text]: (input) => input !== null && typeof input !== "string"
|
|
64
|
+
[ContentType.Json]: (input) => input !== null && (typeof input === 'object' || typeof input === 'string')
|
|
68
65
|
? JSON.stringify(input)
|
|
69
66
|
: input,
|
|
67
|
+
[ContentType.Text]: (input) => input !== null && typeof input !== 'string' ? JSON.stringify(input) : input,
|
|
70
68
|
[ContentType.FormData]: (input) => Object.keys(input || {}).reduce((formData, key) => {
|
|
71
69
|
const property = input[key];
|
|
72
70
|
formData.append(key, property instanceof Blob
|
|
73
71
|
? property
|
|
74
|
-
: typeof property ===
|
|
72
|
+
: typeof property === 'object' && property !== null
|
|
75
73
|
? JSON.stringify(property)
|
|
76
74
|
: `${property}`);
|
|
77
75
|
return formData;
|
|
@@ -110,7 +108,7 @@ class HttpClient {
|
|
|
110
108
|
}
|
|
111
109
|
};
|
|
112
110
|
request = async ({ body, secure, path, type, query, format, baseUrl, cancelToken, ...params }) => {
|
|
113
|
-
const secureParams = ((typeof secure ===
|
|
111
|
+
const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) &&
|
|
114
112
|
this.securityWorker &&
|
|
115
113
|
(await this.securityWorker(this.securityData))) ||
|
|
116
114
|
{};
|
|
@@ -118,20 +116,14 @@ class HttpClient {
|
|
|
118
116
|
const queryString = query && this.toQueryString(query);
|
|
119
117
|
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
|
120
118
|
const responseFormat = format || requestParams.format;
|
|
121
|
-
return this.customFetch(`${baseUrl || this.baseUrl ||
|
|
119
|
+
return this.customFetch(`${baseUrl || this.baseUrl || ''}${path}${queryString ? `?${queryString}` : ''}`, {
|
|
122
120
|
...requestParams,
|
|
123
121
|
headers: {
|
|
124
122
|
...(requestParams.headers || {}),
|
|
125
|
-
...(type && type !== ContentType.FormData
|
|
126
|
-
? { "Content-Type": type }
|
|
127
|
-
: {}),
|
|
123
|
+
...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
|
|
128
124
|
},
|
|
129
|
-
signal: (cancelToken
|
|
130
|
-
|
|
131
|
-
: requestParams.signal) || null,
|
|
132
|
-
body: typeof body === "undefined" || body === null
|
|
133
|
-
? null
|
|
134
|
-
: payloadFormatter(body),
|
|
125
|
+
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
|
|
126
|
+
body: typeof body === 'undefined' || body === null ? null : payloadFormatter(body),
|
|
135
127
|
}).then(async (response) => {
|
|
136
128
|
const r = response;
|
|
137
129
|
r.data = null;
|
|
@@ -183,11 +175,11 @@ class Api extends HttpClient {
|
|
|
183
175
|
*/
|
|
184
176
|
assistantControllerCreate: (data, params = {}) => this.request({
|
|
185
177
|
path: `/assistant`,
|
|
186
|
-
method:
|
|
178
|
+
method: 'POST',
|
|
187
179
|
body: data,
|
|
188
180
|
secure: true,
|
|
189
181
|
type: ContentType.Json,
|
|
190
|
-
format:
|
|
182
|
+
format: 'json',
|
|
191
183
|
...params,
|
|
192
184
|
}),
|
|
193
185
|
/**
|
|
@@ -201,10 +193,10 @@ class Api extends HttpClient {
|
|
|
201
193
|
*/
|
|
202
194
|
assistantControllerFindAll: (query, params = {}) => this.request({
|
|
203
195
|
path: `/assistant`,
|
|
204
|
-
method:
|
|
196
|
+
method: 'GET',
|
|
205
197
|
query: query,
|
|
206
198
|
secure: true,
|
|
207
|
-
format:
|
|
199
|
+
format: 'json',
|
|
208
200
|
...params,
|
|
209
201
|
}),
|
|
210
202
|
/**
|
|
@@ -218,9 +210,9 @@ class Api extends HttpClient {
|
|
|
218
210
|
*/
|
|
219
211
|
assistantControllerFindOne: (id, params = {}) => this.request({
|
|
220
212
|
path: `/assistant/${id}`,
|
|
221
|
-
method:
|
|
213
|
+
method: 'GET',
|
|
222
214
|
secure: true,
|
|
223
|
-
format:
|
|
215
|
+
format: 'json',
|
|
224
216
|
...params,
|
|
225
217
|
}),
|
|
226
218
|
/**
|
|
@@ -234,11 +226,11 @@ class Api extends HttpClient {
|
|
|
234
226
|
*/
|
|
235
227
|
assistantControllerUpdate: (id, data, params = {}) => this.request({
|
|
236
228
|
path: `/assistant/${id}`,
|
|
237
|
-
method:
|
|
229
|
+
method: 'PATCH',
|
|
238
230
|
body: data,
|
|
239
231
|
secure: true,
|
|
240
232
|
type: ContentType.Json,
|
|
241
|
-
format:
|
|
233
|
+
format: 'json',
|
|
242
234
|
...params,
|
|
243
235
|
}),
|
|
244
236
|
/**
|
|
@@ -252,11 +244,11 @@ class Api extends HttpClient {
|
|
|
252
244
|
*/
|
|
253
245
|
assistantControllerReplace: (id, data, params = {}) => this.request({
|
|
254
246
|
path: `/assistant/${id}`,
|
|
255
|
-
method:
|
|
247
|
+
method: 'PUT',
|
|
256
248
|
body: data,
|
|
257
249
|
secure: true,
|
|
258
250
|
type: ContentType.Json,
|
|
259
|
-
format:
|
|
251
|
+
format: 'json',
|
|
260
252
|
...params,
|
|
261
253
|
}),
|
|
262
254
|
/**
|
|
@@ -270,9 +262,9 @@ class Api extends HttpClient {
|
|
|
270
262
|
*/
|
|
271
263
|
assistantControllerRemove: (id, params = {}) => this.request({
|
|
272
264
|
path: `/assistant/${id}`,
|
|
273
|
-
method:
|
|
265
|
+
method: 'DELETE',
|
|
274
266
|
secure: true,
|
|
275
|
-
format:
|
|
267
|
+
format: 'json',
|
|
276
268
|
...params,
|
|
277
269
|
}),
|
|
278
270
|
};
|
|
@@ -288,10 +280,10 @@ class Api extends HttpClient {
|
|
|
288
280
|
*/
|
|
289
281
|
callControllerFindAll: (query, params = {}) => this.request({
|
|
290
282
|
path: `/call`,
|
|
291
|
-
method:
|
|
283
|
+
method: 'GET',
|
|
292
284
|
query: query,
|
|
293
285
|
secure: true,
|
|
294
|
-
format:
|
|
286
|
+
format: 'json',
|
|
295
287
|
...params,
|
|
296
288
|
}),
|
|
297
289
|
/**
|
|
@@ -305,9 +297,9 @@ class Api extends HttpClient {
|
|
|
305
297
|
*/
|
|
306
298
|
callControllerFindOne: (id, params = {}) => this.request({
|
|
307
299
|
path: `/call/${id}`,
|
|
308
|
-
method:
|
|
300
|
+
method: 'GET',
|
|
309
301
|
secure: true,
|
|
310
|
-
format:
|
|
302
|
+
format: 'json',
|
|
311
303
|
...params,
|
|
312
304
|
}),
|
|
313
305
|
/**
|
|
@@ -321,11 +313,11 @@ class Api extends HttpClient {
|
|
|
321
313
|
*/
|
|
322
314
|
callControllerCreatePhoneCall: (data, params = {}) => this.request({
|
|
323
315
|
path: `/call/phone`,
|
|
324
|
-
method:
|
|
316
|
+
method: 'POST',
|
|
325
317
|
body: data,
|
|
326
318
|
secure: true,
|
|
327
319
|
type: ContentType.Json,
|
|
328
|
-
format:
|
|
320
|
+
format: 'json',
|
|
329
321
|
...params,
|
|
330
322
|
}),
|
|
331
323
|
/**
|
|
@@ -339,11 +331,11 @@ class Api extends HttpClient {
|
|
|
339
331
|
*/
|
|
340
332
|
callControllerCreateWebCall: (data, params = {}) => this.request({
|
|
341
333
|
path: `/call/web`,
|
|
342
|
-
method:
|
|
334
|
+
method: 'POST',
|
|
343
335
|
body: data,
|
|
344
336
|
secure: true,
|
|
345
337
|
type: ContentType.Json,
|
|
346
|
-
format:
|
|
338
|
+
format: 'json',
|
|
347
339
|
...params,
|
|
348
340
|
}),
|
|
349
341
|
};
|
|
@@ -359,11 +351,11 @@ class Api extends HttpClient {
|
|
|
359
351
|
*/
|
|
360
352
|
credentialControllerCreate: (data, params = {}) => this.request({
|
|
361
353
|
path: `/credential`,
|
|
362
|
-
method:
|
|
354
|
+
method: 'POST',
|
|
363
355
|
body: data,
|
|
364
356
|
secure: true,
|
|
365
357
|
type: ContentType.Json,
|
|
366
|
-
format:
|
|
358
|
+
format: 'json',
|
|
367
359
|
...params,
|
|
368
360
|
}),
|
|
369
361
|
/**
|
|
@@ -377,10 +369,10 @@ class Api extends HttpClient {
|
|
|
377
369
|
*/
|
|
378
370
|
credentialControllerFindAll: (query, params = {}) => this.request({
|
|
379
371
|
path: `/credential`,
|
|
380
|
-
method:
|
|
372
|
+
method: 'GET',
|
|
381
373
|
query: query,
|
|
382
374
|
secure: true,
|
|
383
|
-
format:
|
|
375
|
+
format: 'json',
|
|
384
376
|
...params,
|
|
385
377
|
}),
|
|
386
378
|
/**
|
|
@@ -394,9 +386,9 @@ class Api extends HttpClient {
|
|
|
394
386
|
*/
|
|
395
387
|
credentialControllerFindOne: (id, params = {}) => this.request({
|
|
396
388
|
path: `/credential/${id}`,
|
|
397
|
-
method:
|
|
389
|
+
method: 'GET',
|
|
398
390
|
secure: true,
|
|
399
|
-
format:
|
|
391
|
+
format: 'json',
|
|
400
392
|
...params,
|
|
401
393
|
}),
|
|
402
394
|
/**
|
|
@@ -410,11 +402,11 @@ class Api extends HttpClient {
|
|
|
410
402
|
*/
|
|
411
403
|
credentialControllerUpdate: (id, data, params = {}) => this.request({
|
|
412
404
|
path: `/credential/${id}`,
|
|
413
|
-
method:
|
|
405
|
+
method: 'PUT',
|
|
414
406
|
body: data,
|
|
415
407
|
secure: true,
|
|
416
408
|
type: ContentType.Json,
|
|
417
|
-
format:
|
|
409
|
+
format: 'json',
|
|
418
410
|
...params,
|
|
419
411
|
}),
|
|
420
412
|
/**
|
|
@@ -428,9 +420,9 @@ class Api extends HttpClient {
|
|
|
428
420
|
*/
|
|
429
421
|
credentialControllerRemove: (id, params = {}) => this.request({
|
|
430
422
|
path: `/credential/${id}`,
|
|
431
|
-
method:
|
|
423
|
+
method: 'DELETE',
|
|
432
424
|
secure: true,
|
|
433
|
-
format:
|
|
425
|
+
format: 'json',
|
|
434
426
|
...params,
|
|
435
427
|
}),
|
|
436
428
|
};
|
|
@@ -446,29 +438,47 @@ class Api extends HttpClient {
|
|
|
446
438
|
*/
|
|
447
439
|
phoneNumberControllerBuy: (data, params = {}) => this.request({
|
|
448
440
|
path: `/phone-number/buy`,
|
|
449
|
-
method:
|
|
441
|
+
method: 'POST',
|
|
450
442
|
body: data,
|
|
451
443
|
secure: true,
|
|
452
444
|
type: ContentType.Json,
|
|
453
|
-
format:
|
|
445
|
+
format: 'json',
|
|
454
446
|
...params,
|
|
455
447
|
}),
|
|
456
448
|
/**
|
|
457
449
|
* No description
|
|
458
450
|
*
|
|
459
451
|
* @tags Phone Numbers
|
|
460
|
-
* @name
|
|
452
|
+
* @name PhoneNumberControllerImportTwilio
|
|
461
453
|
* @summary Import Twilio Number
|
|
462
|
-
* @request POST:/phone-number/import
|
|
454
|
+
* @request POST:/phone-number/import/twilio
|
|
455
|
+
* @secure
|
|
456
|
+
*/
|
|
457
|
+
phoneNumberControllerImportTwilio: (data, params = {}) => this.request({
|
|
458
|
+
path: `/phone-number/import/twilio`,
|
|
459
|
+
method: 'POST',
|
|
460
|
+
body: data,
|
|
461
|
+
secure: true,
|
|
462
|
+
type: ContentType.Json,
|
|
463
|
+
format: 'json',
|
|
464
|
+
...params,
|
|
465
|
+
}),
|
|
466
|
+
/**
|
|
467
|
+
* No description
|
|
468
|
+
*
|
|
469
|
+
* @tags Phone Numbers
|
|
470
|
+
* @name PhoneNumberControllerImportVonage
|
|
471
|
+
* @summary Import Vonage Number
|
|
472
|
+
* @request POST:/phone-number/import/vonage
|
|
463
473
|
* @secure
|
|
464
474
|
*/
|
|
465
|
-
|
|
466
|
-
path: `/phone-number/import`,
|
|
467
|
-
method:
|
|
475
|
+
phoneNumberControllerImportVonage: (data, params = {}) => this.request({
|
|
476
|
+
path: `/phone-number/import/vonage`,
|
|
477
|
+
method: 'POST',
|
|
468
478
|
body: data,
|
|
469
479
|
secure: true,
|
|
470
480
|
type: ContentType.Json,
|
|
471
|
-
format:
|
|
481
|
+
format: 'json',
|
|
472
482
|
...params,
|
|
473
483
|
}),
|
|
474
484
|
/**
|
|
@@ -482,10 +492,10 @@ class Api extends HttpClient {
|
|
|
482
492
|
*/
|
|
483
493
|
phoneNumberControllerFindAll: (query, params = {}) => this.request({
|
|
484
494
|
path: `/phone-number`,
|
|
485
|
-
method:
|
|
495
|
+
method: 'GET',
|
|
486
496
|
query: query,
|
|
487
497
|
secure: true,
|
|
488
|
-
format:
|
|
498
|
+
format: 'json',
|
|
489
499
|
...params,
|
|
490
500
|
}),
|
|
491
501
|
/**
|
|
@@ -499,9 +509,9 @@ class Api extends HttpClient {
|
|
|
499
509
|
*/
|
|
500
510
|
phoneNumberControllerFindOne: (id, params = {}) => this.request({
|
|
501
511
|
path: `/phone-number/${id}`,
|
|
502
|
-
method:
|
|
512
|
+
method: 'GET',
|
|
503
513
|
secure: true,
|
|
504
|
-
format:
|
|
514
|
+
format: 'json',
|
|
505
515
|
...params,
|
|
506
516
|
}),
|
|
507
517
|
/**
|
|
@@ -515,11 +525,11 @@ class Api extends HttpClient {
|
|
|
515
525
|
*/
|
|
516
526
|
phoneNumberControllerUpdate: (id, data, params = {}) => this.request({
|
|
517
527
|
path: `/phone-number/${id}`,
|
|
518
|
-
method:
|
|
528
|
+
method: 'PATCH',
|
|
519
529
|
body: data,
|
|
520
530
|
secure: true,
|
|
521
531
|
type: ContentType.Json,
|
|
522
|
-
format:
|
|
532
|
+
format: 'json',
|
|
523
533
|
...params,
|
|
524
534
|
}),
|
|
525
535
|
/**
|
|
@@ -533,9 +543,9 @@ class Api extends HttpClient {
|
|
|
533
543
|
*/
|
|
534
544
|
phoneNumberControllerRemove: (id, params = {}) => this.request({
|
|
535
545
|
path: `/phone-number/${id}`,
|
|
536
|
-
method:
|
|
546
|
+
method: 'DELETE',
|
|
537
547
|
secure: true,
|
|
538
|
-
format:
|
|
548
|
+
format: 'json',
|
|
539
549
|
...params,
|
|
540
550
|
}),
|
|
541
551
|
};
|
|
@@ -551,10 +561,10 @@ class Api extends HttpClient {
|
|
|
551
561
|
*/
|
|
552
562
|
metricsControllerFindAll: (query, params = {}) => this.request({
|
|
553
563
|
path: `/metrics`,
|
|
554
|
-
method:
|
|
564
|
+
method: 'GET',
|
|
555
565
|
query: query,
|
|
556
566
|
secure: true,
|
|
557
|
-
format:
|
|
567
|
+
format: 'json',
|
|
558
568
|
...params,
|
|
559
569
|
}),
|
|
560
570
|
};
|
package/dist/vapi.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Call, CreateAssistantDTO } from
|
|
3
|
-
import type { ChatCompletionMessageParam } from
|
|
4
|
-
import EventEmitter from
|
|
2
|
+
import { Call, CreateAssistantDTO } from './api';
|
|
3
|
+
import type { ChatCompletionMessageParam } from 'openai/resources';
|
|
4
|
+
import EventEmitter from 'events';
|
|
5
5
|
export interface AddMessageMessage {
|
|
6
|
-
type:
|
|
6
|
+
type: 'add-message';
|
|
7
7
|
message: ChatCompletionMessageParam;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
type
|
|
9
|
+
export interface ControlMessages {
|
|
10
|
+
type: 'control';
|
|
11
|
+
control: 'mute-assistant' | 'unmute-assistant';
|
|
12
|
+
}
|
|
13
|
+
type VapiClientToServerMessage = AddMessageMessage | ControlMessages;
|
|
14
|
+
type VapiEventNames = 'call-end' | 'call-start' | 'volume-level' | 'speech-start' | 'speech-end' | 'message' | 'error';
|
|
11
15
|
type VapiEventListeners = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
'call-end': () => void;
|
|
17
|
+
'call-start': () => void;
|
|
18
|
+
'volume-level': (volume: number) => void;
|
|
19
|
+
'speech-start': () => void;
|
|
20
|
+
'speech-end': () => void;
|
|
17
21
|
message: (message: any) => void;
|
|
18
22
|
error: (error: any) => void;
|
|
19
23
|
};
|
package/dist/vapi.js
CHANGED
|
@@ -19,7 +19,7 @@ async function startPlayer(player, track) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
async function buildAudioPlayer(track, participantId) {
|
|
22
|
-
const player = document.createElement(
|
|
22
|
+
const player = document.createElement('audio');
|
|
23
23
|
player.dataset.participantId = participantId;
|
|
24
24
|
document.body.appendChild(player);
|
|
25
25
|
await startPlayer(player, track);
|
|
@@ -63,7 +63,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
63
63
|
averageSpeechLevel = 0;
|
|
64
64
|
constructor(apiToken, apiBaseUrl) {
|
|
65
65
|
super();
|
|
66
|
-
client_1.client.baseUrl = apiBaseUrl ??
|
|
66
|
+
client_1.client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
|
|
67
67
|
client_1.client.setSecurityData(apiToken);
|
|
68
68
|
}
|
|
69
69
|
cleanup() {
|
|
@@ -79,39 +79,42 @@ class Vapi extends VapiEventEmitter {
|
|
|
79
79
|
this.started = true;
|
|
80
80
|
try {
|
|
81
81
|
const webCall = (await client_1.client.call.callControllerCreateWebCall({
|
|
82
|
-
assistant: typeof assistant ===
|
|
83
|
-
assistantId: typeof assistant ===
|
|
82
|
+
assistant: typeof assistant === 'string' ? undefined : assistant,
|
|
83
|
+
assistantId: typeof assistant === 'string' ? assistant : undefined,
|
|
84
84
|
})).data;
|
|
85
|
+
if (this.call) {
|
|
86
|
+
this.cleanup();
|
|
87
|
+
}
|
|
85
88
|
this.call = daily_js_1.default.createCallObject({
|
|
86
89
|
audioSource: true,
|
|
87
90
|
videoSource: false,
|
|
88
91
|
});
|
|
89
|
-
this.call.iframe()?.style.setProperty(
|
|
90
|
-
this.call.on(
|
|
91
|
-
this.emit(
|
|
92
|
+
this.call.iframe()?.style.setProperty('display', 'none');
|
|
93
|
+
this.call.on('left-meeting', () => {
|
|
94
|
+
this.emit('call-end');
|
|
92
95
|
this.cleanup();
|
|
93
96
|
});
|
|
94
|
-
this.call.on(
|
|
97
|
+
this.call.on('participant-left', (e) => {
|
|
95
98
|
if (!e)
|
|
96
99
|
return;
|
|
97
100
|
destroyAudioPlayer(e.participant.session_id);
|
|
98
101
|
});
|
|
99
|
-
this.call.on(
|
|
102
|
+
this.call.on('error', () => {
|
|
100
103
|
// Ignore error
|
|
101
104
|
});
|
|
102
|
-
this.call.on(
|
|
105
|
+
this.call.on('track-started', async (e) => {
|
|
103
106
|
if (!e || !e.participant)
|
|
104
107
|
return;
|
|
105
108
|
if (e.participant?.local)
|
|
106
109
|
return;
|
|
107
|
-
if (e.track.kind !==
|
|
110
|
+
if (e.track.kind !== 'audio')
|
|
108
111
|
return;
|
|
109
112
|
await buildAudioPlayer(e.track, e.participant.session_id);
|
|
110
|
-
if (e?.participant?.user_name !==
|
|
113
|
+
if (e?.participant?.user_name !== 'Vapi Speaker')
|
|
111
114
|
return;
|
|
112
|
-
this.call?.sendAppMessage(
|
|
115
|
+
this.call?.sendAppMessage('playable');
|
|
113
116
|
});
|
|
114
|
-
this.call.on(
|
|
117
|
+
this.call.on('participant-joined', (e) => {
|
|
115
118
|
if (!e || !this.call)
|
|
116
119
|
return;
|
|
117
120
|
subscribeToTracks(e, this.call);
|
|
@@ -121,15 +124,15 @@ class Vapi extends VapiEventEmitter {
|
|
|
121
124
|
subscribeToTracksAutomatically: false,
|
|
122
125
|
});
|
|
123
126
|
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
124
|
-
this.call.on(
|
|
127
|
+
this.call.on('remote-participants-audio-level', (e) => {
|
|
125
128
|
if (e)
|
|
126
129
|
this.handleRemoteParticipantsAudioLevel(e);
|
|
127
130
|
});
|
|
128
|
-
this.call.on(
|
|
131
|
+
this.call.on('app-message', (e) => this.onAppMessage(e));
|
|
129
132
|
this.call.updateInputSettings({
|
|
130
133
|
audio: {
|
|
131
134
|
processor: {
|
|
132
|
-
type:
|
|
135
|
+
type: 'noise-cancellation',
|
|
133
136
|
},
|
|
134
137
|
},
|
|
135
138
|
});
|
|
@@ -137,7 +140,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
137
140
|
}
|
|
138
141
|
catch (e) {
|
|
139
142
|
console.error(e);
|
|
140
|
-
this.emit(
|
|
143
|
+
this.emit('error', e);
|
|
141
144
|
this.cleanup();
|
|
142
145
|
return null;
|
|
143
146
|
}
|
|
@@ -146,16 +149,16 @@ class Vapi extends VapiEventEmitter {
|
|
|
146
149
|
if (!e)
|
|
147
150
|
return;
|
|
148
151
|
try {
|
|
149
|
-
if (e.data ===
|
|
150
|
-
return this.emit(
|
|
152
|
+
if (e.data === 'listening') {
|
|
153
|
+
return this.emit('call-start');
|
|
151
154
|
}
|
|
152
155
|
else {
|
|
153
156
|
try {
|
|
154
157
|
const parsedMessage = JSON.parse(e.data);
|
|
155
|
-
this.emit(
|
|
158
|
+
this.emit('message', parsedMessage);
|
|
156
159
|
}
|
|
157
160
|
catch (parseError) {
|
|
158
|
-
console.log(
|
|
161
|
+
console.log('Error parsing message data: ', parseError);
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
}
|
|
@@ -165,7 +168,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
165
168
|
}
|
|
166
169
|
handleRemoteParticipantsAudioLevel(e) {
|
|
167
170
|
const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
|
|
168
|
-
this.emit(
|
|
171
|
+
this.emit('volume-level', Math.min(1, speechLevel / 0.15));
|
|
169
172
|
const isSpeaking = speechLevel > 0.01;
|
|
170
173
|
if (!isSpeaking)
|
|
171
174
|
return;
|
|
@@ -174,10 +177,10 @@ class Vapi extends VapiEventEmitter {
|
|
|
174
177
|
this.speakingTimeout = null;
|
|
175
178
|
}
|
|
176
179
|
else {
|
|
177
|
-
this.emit(
|
|
180
|
+
this.emit('speech-start');
|
|
178
181
|
}
|
|
179
182
|
this.speakingTimeout = setTimeout(() => {
|
|
180
|
-
this.emit(
|
|
183
|
+
this.emit('speech-end');
|
|
181
184
|
this.speakingTimeout = null;
|
|
182
185
|
}, 1000);
|
|
183
186
|
}
|
|
@@ -192,7 +195,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
192
195
|
setMuted(mute) {
|
|
193
196
|
try {
|
|
194
197
|
if (!this.call) {
|
|
195
|
-
throw new Error(
|
|
198
|
+
throw new Error('Call object is not available.');
|
|
196
199
|
}
|
|
197
200
|
this.call.setLocalAudio(!mute);
|
|
198
201
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vapi-ai/web",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/vapi.js",
|
|
6
6
|
"types": "dist/vapi.d.ts",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"url": "git+https://github.com/VapiAI/snippet.git"
|
|
17
17
|
},
|
|
18
18
|
"author": "vapi",
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"bugs": {
|
|
21
21
|
"url": "https://github.com/VapiAI/snippet/issues"
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/VapiAI/snippet#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@daily-co/daily-js": "^0.
|
|
25
|
+
"@daily-co/daily-js": "^0.58.0",
|
|
26
26
|
"@vapi-ai/web": "^1.0.263",
|
|
27
27
|
"events": "^3.3.0"
|
|
28
28
|
},
|
package/update.sh
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
npm version
|
|
1
|
+
npm version minor && npm run build && npm publish && cd ../landing && npm install @vapi-ai/web@latest && cd -
|