@vapi-ai/web 1.1.6 → 1.2.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/README.md +6 -0
- package/api.ts +2260 -780
- package/dist/api.d.ts +1895 -755
- package/dist/api.js +177 -45
- package/dist/vapi.d.ts +12 -4
- package/dist/vapi.js +35 -2
- package/package.json +1 -1
- package/update.sh +1 -1
- package/vapi.ts +50 -5
package/dist/api.js
CHANGED
|
@@ -10,30 +10,7 @@
|
|
|
10
10
|
* ---------------------------------------------------------------
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Api = exports.HttpClient = exports.ContentType =
|
|
14
|
-
class CreateWebCallDTO {
|
|
15
|
-
/**
|
|
16
|
-
* This is the assistant that will be used for the call. To use a transient assistant, use `assistant` instead.
|
|
17
|
-
*/
|
|
18
|
-
assistantId;
|
|
19
|
-
/**
|
|
20
|
-
* Overrides for the assistant's settings and template variables.
|
|
21
|
-
*/
|
|
22
|
-
assistantOverrides;
|
|
23
|
-
/**
|
|
24
|
-
* This is the assistant that will be used for the call. To use an existing assistant, use `assistantId` instead.
|
|
25
|
-
*/
|
|
26
|
-
assistant;
|
|
27
|
-
/**
|
|
28
|
-
* This will expose SIP URI you can use to connect to the call. Disabled by default.
|
|
29
|
-
*/
|
|
30
|
-
sipEnabled;
|
|
31
|
-
/**
|
|
32
|
-
* This is the metadata associated with the call.
|
|
33
|
-
*/
|
|
34
|
-
metadata;
|
|
35
|
-
}
|
|
36
|
-
exports.CreateWebCallDTO = CreateWebCallDTO;
|
|
13
|
+
exports.Api = exports.HttpClient = exports.ContentType = void 0;
|
|
37
14
|
var ContentType;
|
|
38
15
|
(function (ContentType) {
|
|
39
16
|
ContentType["Json"] = "application/json";
|
|
@@ -325,6 +302,40 @@ class Api extends HttpClient {
|
|
|
325
302
|
format: 'json',
|
|
326
303
|
...params,
|
|
327
304
|
}),
|
|
305
|
+
/**
|
|
306
|
+
* No description
|
|
307
|
+
*
|
|
308
|
+
* @tags Calls
|
|
309
|
+
* @name CallControllerDeleteCallData
|
|
310
|
+
* @summary Delete Call Data
|
|
311
|
+
* @request DELETE:/call/{id}
|
|
312
|
+
* @secure
|
|
313
|
+
*/
|
|
314
|
+
callControllerDeleteCallData: (id, params = {}) => this.request({
|
|
315
|
+
path: `/call/${id}`,
|
|
316
|
+
method: 'DELETE',
|
|
317
|
+
secure: true,
|
|
318
|
+
format: 'json',
|
|
319
|
+
...params,
|
|
320
|
+
}),
|
|
321
|
+
/**
|
|
322
|
+
* No description
|
|
323
|
+
*
|
|
324
|
+
* @tags Calls
|
|
325
|
+
* @name CallControllerUpdate
|
|
326
|
+
* @summary Update Call
|
|
327
|
+
* @request PATCH:/call/{id}
|
|
328
|
+
* @secure
|
|
329
|
+
*/
|
|
330
|
+
callControllerUpdate: (id, data, params = {}) => this.request({
|
|
331
|
+
path: `/call/${id}`,
|
|
332
|
+
method: 'PATCH',
|
|
333
|
+
body: data,
|
|
334
|
+
secure: true,
|
|
335
|
+
type: ContentType.Json,
|
|
336
|
+
format: 'json',
|
|
337
|
+
...params,
|
|
338
|
+
}),
|
|
328
339
|
/**
|
|
329
340
|
* No description
|
|
330
341
|
*
|
|
@@ -591,58 +602,179 @@ class Api extends HttpClient {
|
|
|
591
602
|
...params,
|
|
592
603
|
}),
|
|
593
604
|
};
|
|
594
|
-
|
|
605
|
+
log = {
|
|
595
606
|
/**
|
|
596
607
|
* No description
|
|
597
608
|
*
|
|
598
|
-
* @tags
|
|
599
|
-
* @name
|
|
600
|
-
* @summary Get
|
|
601
|
-
* @request GET:/
|
|
609
|
+
* @tags Logs
|
|
610
|
+
* @name LoggingControllerGetLogs
|
|
611
|
+
* @summary Get Call Logs
|
|
612
|
+
* @request GET:/log
|
|
602
613
|
* @secure
|
|
603
614
|
*/
|
|
604
|
-
|
|
605
|
-
path: `/
|
|
615
|
+
loggingControllerGetLogs: (query, params = {}) => this.request({
|
|
616
|
+
path: `/log`,
|
|
606
617
|
method: 'GET',
|
|
618
|
+
query: query,
|
|
607
619
|
secure: true,
|
|
608
620
|
format: 'json',
|
|
609
621
|
...params,
|
|
610
622
|
}),
|
|
623
|
+
};
|
|
624
|
+
tool = {
|
|
611
625
|
/**
|
|
612
626
|
* No description
|
|
613
627
|
*
|
|
614
|
-
* @tags
|
|
615
|
-
* @name
|
|
616
|
-
* @summary
|
|
617
|
-
* @request POST:/
|
|
628
|
+
* @tags Tools
|
|
629
|
+
* @name ToolControllerCreate
|
|
630
|
+
* @summary Create Tool
|
|
631
|
+
* @request POST:/tool
|
|
618
632
|
* @secure
|
|
619
633
|
*/
|
|
620
|
-
|
|
621
|
-
path: `/
|
|
634
|
+
toolControllerCreate: (data, params = {}) => this.request({
|
|
635
|
+
path: `/tool`,
|
|
622
636
|
method: 'POST',
|
|
637
|
+
body: data,
|
|
623
638
|
secure: true,
|
|
639
|
+
type: ContentType.Json,
|
|
624
640
|
format: 'json',
|
|
625
641
|
...params,
|
|
626
642
|
}),
|
|
627
|
-
};
|
|
628
|
-
logging = {
|
|
629
643
|
/**
|
|
630
644
|
* No description
|
|
631
645
|
*
|
|
632
|
-
* @tags
|
|
633
|
-
* @name
|
|
634
|
-
* @summary
|
|
635
|
-
* @request GET:/
|
|
646
|
+
* @tags Tools
|
|
647
|
+
* @name ToolControllerFindAll
|
|
648
|
+
* @summary List Tools
|
|
649
|
+
* @request GET:/tool
|
|
636
650
|
* @secure
|
|
637
651
|
*/
|
|
638
|
-
|
|
639
|
-
path: `/
|
|
652
|
+
toolControllerFindAll: (query, params = {}) => this.request({
|
|
653
|
+
path: `/tool`,
|
|
640
654
|
method: 'GET',
|
|
641
655
|
query: query,
|
|
642
656
|
secure: true,
|
|
643
657
|
format: 'json',
|
|
644
658
|
...params,
|
|
645
659
|
}),
|
|
660
|
+
/**
|
|
661
|
+
* No description
|
|
662
|
+
*
|
|
663
|
+
* @tags Tools
|
|
664
|
+
* @name ToolControllerFindOne
|
|
665
|
+
* @summary Get Tool
|
|
666
|
+
* @request GET:/tool/{id}
|
|
667
|
+
* @secure
|
|
668
|
+
*/
|
|
669
|
+
toolControllerFindOne: (id, params = {}) => this.request({
|
|
670
|
+
path: `/tool/${id}`,
|
|
671
|
+
method: 'GET',
|
|
672
|
+
secure: true,
|
|
673
|
+
format: 'json',
|
|
674
|
+
...params,
|
|
675
|
+
}),
|
|
676
|
+
/**
|
|
677
|
+
* No description
|
|
678
|
+
*
|
|
679
|
+
* @tags Tools
|
|
680
|
+
* @name ToolControllerUpdate
|
|
681
|
+
* @summary Update Tool
|
|
682
|
+
* @request PATCH:/tool/{id}
|
|
683
|
+
* @secure
|
|
684
|
+
*/
|
|
685
|
+
toolControllerUpdate: (id, data, params = {}) => this.request({
|
|
686
|
+
path: `/tool/${id}`,
|
|
687
|
+
method: 'PATCH',
|
|
688
|
+
body: data,
|
|
689
|
+
secure: true,
|
|
690
|
+
type: ContentType.Json,
|
|
691
|
+
format: 'json',
|
|
692
|
+
...params,
|
|
693
|
+
}),
|
|
694
|
+
/**
|
|
695
|
+
* No description
|
|
696
|
+
*
|
|
697
|
+
* @tags Tools
|
|
698
|
+
* @name ToolControllerRemove
|
|
699
|
+
* @summary Delete Tool
|
|
700
|
+
* @request DELETE:/tool/{id}
|
|
701
|
+
* @secure
|
|
702
|
+
*/
|
|
703
|
+
toolControllerRemove: (id, params = {}) => this.request({
|
|
704
|
+
path: `/tool/${id}`,
|
|
705
|
+
method: 'DELETE',
|
|
706
|
+
secure: true,
|
|
707
|
+
format: 'json',
|
|
708
|
+
...params,
|
|
709
|
+
}),
|
|
710
|
+
};
|
|
711
|
+
file = {
|
|
712
|
+
/**
|
|
713
|
+
* No description
|
|
714
|
+
*
|
|
715
|
+
* @tags Files
|
|
716
|
+
* @name FileControllerCreate
|
|
717
|
+
* @summary Upload File
|
|
718
|
+
* @request POST:/file/upload
|
|
719
|
+
* @secure
|
|
720
|
+
*/
|
|
721
|
+
fileControllerCreate: (data, params = {}) => this.request({
|
|
722
|
+
path: `/file/upload`,
|
|
723
|
+
method: 'POST',
|
|
724
|
+
body: data,
|
|
725
|
+
secure: true,
|
|
726
|
+
type: ContentType.FormData,
|
|
727
|
+
format: 'json',
|
|
728
|
+
...params,
|
|
729
|
+
}),
|
|
730
|
+
/**
|
|
731
|
+
* No description
|
|
732
|
+
*
|
|
733
|
+
* @tags Files
|
|
734
|
+
* @name FileControllerFindAll
|
|
735
|
+
* @summary List Files
|
|
736
|
+
* @request GET:/file
|
|
737
|
+
* @secure
|
|
738
|
+
*/
|
|
739
|
+
fileControllerFindAll: (params = {}) => this.request({
|
|
740
|
+
path: `/file`,
|
|
741
|
+
method: 'GET',
|
|
742
|
+
secure: true,
|
|
743
|
+
format: 'json',
|
|
744
|
+
...params,
|
|
745
|
+
}),
|
|
746
|
+
/**
|
|
747
|
+
* No description
|
|
748
|
+
*
|
|
749
|
+
* @tags Files
|
|
750
|
+
* @name FileControllerFindOne
|
|
751
|
+
* @summary Get File
|
|
752
|
+
* @request GET:/file/{id}
|
|
753
|
+
* @secure
|
|
754
|
+
*/
|
|
755
|
+
fileControllerFindOne: (id, params = {}) => this.request({
|
|
756
|
+
path: `/file/${id}`,
|
|
757
|
+
method: 'GET',
|
|
758
|
+
secure: true,
|
|
759
|
+
format: 'json',
|
|
760
|
+
...params,
|
|
761
|
+
}),
|
|
762
|
+
/**
|
|
763
|
+
* No description
|
|
764
|
+
*
|
|
765
|
+
* @tags Files
|
|
766
|
+
* @name FileControllerRemove
|
|
767
|
+
* @summary Delete File
|
|
768
|
+
* @request DELETE:/file/{id}
|
|
769
|
+
* @secure
|
|
770
|
+
*/
|
|
771
|
+
fileControllerRemove: (id, params = {}) => this.request({
|
|
772
|
+
path: `/file/${id}`,
|
|
773
|
+
method: 'DELETE',
|
|
774
|
+
secure: true,
|
|
775
|
+
format: 'json',
|
|
776
|
+
...params,
|
|
777
|
+
}),
|
|
646
778
|
};
|
|
647
779
|
}
|
|
648
780
|
exports.Api = Api;
|
package/dist/vapi.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Call, CreateAssistantDTO, OverrideAssistantDTO } from './api';
|
|
2
|
+
import { Call, CreateAssistantDTO, CreateSquadDTO, OverrideAssistantDTO } from './api';
|
|
3
|
+
import { DailyCall } from '@daily-co/daily-js';
|
|
3
4
|
import type { ChatCompletionMessageParam } from 'openai/resources';
|
|
4
5
|
import EventEmitter from 'events';
|
|
5
6
|
export interface AddMessageMessage {
|
|
@@ -10,7 +11,12 @@ export interface ControlMessages {
|
|
|
10
11
|
type: 'control';
|
|
11
12
|
control: 'mute-assistant' | 'unmute-assistant';
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
export interface SayMessage {
|
|
15
|
+
type: 'say';
|
|
16
|
+
message: string;
|
|
17
|
+
endCallAfterSpoken?: boolean;
|
|
18
|
+
}
|
|
19
|
+
type VapiClientToServerMessage = AddMessageMessage | ControlMessages | SayMessage;
|
|
14
20
|
type VapiEventNames = 'call-end' | 'call-start' | 'volume-level' | 'speech-start' | 'speech-end' | 'message' | 'error';
|
|
15
21
|
type VapiEventListeners = {
|
|
16
22
|
'call-end': () => void;
|
|
@@ -32,15 +38,17 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
32
38
|
private started;
|
|
33
39
|
private call;
|
|
34
40
|
private speakingTimeout;
|
|
35
|
-
private averageSpeechLevel;
|
|
36
41
|
constructor(apiToken: string, apiBaseUrl?: string);
|
|
37
42
|
private cleanup;
|
|
38
|
-
start(assistant
|
|
43
|
+
start(assistant?: CreateAssistantDTO | string, assistantOverrides?: OverrideAssistantDTO, squad?: CreateSquadDTO | string): Promise<Call | null>;
|
|
39
44
|
private onAppMessage;
|
|
40
45
|
private handleRemoteParticipantsAudioLevel;
|
|
41
46
|
stop(): void;
|
|
42
47
|
send(message: VapiClientToServerMessage): void;
|
|
43
48
|
setMuted(mute: boolean): void;
|
|
44
49
|
isMuted(): boolean;
|
|
50
|
+
say(message: string, endCallAfterSpoken?: boolean): void;
|
|
51
|
+
setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): void;
|
|
52
|
+
setOutputDeviceAsync(options: Parameters<DailyCall['setOutputDeviceAsync']>[0]): void;
|
|
45
53
|
}
|
|
46
54
|
export {};
|
package/dist/vapi.js
CHANGED
|
@@ -60,7 +60,6 @@ class Vapi extends VapiEventEmitter {
|
|
|
60
60
|
started = false;
|
|
61
61
|
call = null;
|
|
62
62
|
speakingTimeout = null;
|
|
63
|
-
averageSpeechLevel = 0;
|
|
64
63
|
constructor(apiToken, apiBaseUrl) {
|
|
65
64
|
super();
|
|
66
65
|
client_1.client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
|
|
@@ -72,7 +71,10 @@ class Vapi extends VapiEventEmitter {
|
|
|
72
71
|
this.call = null;
|
|
73
72
|
this.speakingTimeout = null;
|
|
74
73
|
}
|
|
75
|
-
async start(assistant, assistantOverrides) {
|
|
74
|
+
async start(assistant, assistantOverrides, squad) {
|
|
75
|
+
if (!assistant && !squad) {
|
|
76
|
+
throw new Error('Assistant or Squad must be provided.');
|
|
77
|
+
}
|
|
76
78
|
if (this.started) {
|
|
77
79
|
return null;
|
|
78
80
|
}
|
|
@@ -82,6 +84,8 @@ class Vapi extends VapiEventEmitter {
|
|
|
82
84
|
assistant: typeof assistant === 'string' ? undefined : assistant,
|
|
83
85
|
assistantId: typeof assistant === 'string' ? assistant : undefined,
|
|
84
86
|
assistantOverrides,
|
|
87
|
+
squad: typeof squad === 'string' ? undefined : squad,
|
|
88
|
+
squadId: typeof squad === 'string' ? squad : undefined,
|
|
85
89
|
})).data;
|
|
86
90
|
if (this.call) {
|
|
87
91
|
this.cleanup();
|
|
@@ -133,6 +137,22 @@ class Vapi extends VapiEventEmitter {
|
|
|
133
137
|
this.handleRemoteParticipantsAudioLevel(e);
|
|
134
138
|
});
|
|
135
139
|
this.call.on('app-message', (e) => this.onAppMessage(e));
|
|
140
|
+
this.call.on('nonfatal-error', (e) => {
|
|
141
|
+
// https://docs.daily.co/reference/daily-js/events/meeting-events#type-audio-processor-error
|
|
142
|
+
if (e?.type === 'audio-processor-error') {
|
|
143
|
+
this.call
|
|
144
|
+
?.updateInputSettings({
|
|
145
|
+
audio: {
|
|
146
|
+
processor: {
|
|
147
|
+
type: 'none',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
.then(() => {
|
|
152
|
+
this.call?.setLocalAudio(true);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
136
156
|
this.call.updateInputSettings({
|
|
137
157
|
audio: {
|
|
138
158
|
processor: {
|
|
@@ -218,5 +238,18 @@ class Vapi extends VapiEventEmitter {
|
|
|
218
238
|
throw error;
|
|
219
239
|
}
|
|
220
240
|
}
|
|
241
|
+
say(message, endCallAfterSpoken) {
|
|
242
|
+
this.send({
|
|
243
|
+
type: 'say',
|
|
244
|
+
message,
|
|
245
|
+
endCallAfterSpoken
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
setInputDevicesAsync(options) {
|
|
249
|
+
this.call?.setInputDevicesAsync(options);
|
|
250
|
+
}
|
|
251
|
+
setOutputDeviceAsync(options) {
|
|
252
|
+
this.call?.setOutputDeviceAsync(options);
|
|
253
|
+
}
|
|
221
254
|
}
|
|
222
255
|
exports.default = Vapi;
|
package/package.json
CHANGED
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 -
|
package/vapi.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Call, CreateAssistantDTO, OverrideAssistantDTO } from './api';
|
|
1
|
+
import { Call, CreateAssistantDTO, CreateSquadDTO, OverrideAssistantDTO } from './api';
|
|
2
2
|
import DailyIframe, {
|
|
3
3
|
DailyCall,
|
|
4
4
|
DailyEventObjectAppMessage,
|
|
@@ -50,7 +50,13 @@ export interface ControlMessages {
|
|
|
50
50
|
control: 'mute-assistant' | 'unmute-assistant';
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
export interface SayMessage {
|
|
54
|
+
type: 'say';
|
|
55
|
+
message: string;
|
|
56
|
+
endCallAfterSpoken?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type VapiClientToServerMessage = AddMessageMessage | ControlMessages | SayMessage;
|
|
54
60
|
|
|
55
61
|
type VapiEventNames =
|
|
56
62
|
| 'call-end'
|
|
@@ -97,7 +103,6 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
97
103
|
private started: boolean = false;
|
|
98
104
|
private call: DailyCall | null = null;
|
|
99
105
|
private speakingTimeout: NodeJS.Timeout | null = null;
|
|
100
|
-
private averageSpeechLevel: number = 0;
|
|
101
106
|
|
|
102
107
|
constructor(apiToken: string, apiBaseUrl?: string) {
|
|
103
108
|
super();
|
|
@@ -113,13 +118,17 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
async start(
|
|
116
|
-
assistant
|
|
121
|
+
assistant?: CreateAssistantDTO | string,
|
|
117
122
|
assistantOverrides?: OverrideAssistantDTO,
|
|
123
|
+
squad?: CreateSquadDTO | string,
|
|
118
124
|
): Promise<Call | null> {
|
|
125
|
+
if (!assistant && !squad) {
|
|
126
|
+
throw new Error('Assistant or Squad must be provided.');
|
|
127
|
+
}
|
|
128
|
+
|
|
119
129
|
if (this.started) {
|
|
120
130
|
return null;
|
|
121
131
|
}
|
|
122
|
-
|
|
123
132
|
this.started = true;
|
|
124
133
|
|
|
125
134
|
try {
|
|
@@ -128,6 +137,8 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
128
137
|
assistant: typeof assistant === 'string' ? undefined : assistant,
|
|
129
138
|
assistantId: typeof assistant === 'string' ? assistant : undefined,
|
|
130
139
|
assistantOverrides,
|
|
140
|
+
squad: typeof squad === 'string' ? undefined : squad,
|
|
141
|
+
squadId: typeof squad === 'string' ? squad : undefined,
|
|
131
142
|
})
|
|
132
143
|
).data;
|
|
133
144
|
|
|
@@ -187,6 +198,23 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
187
198
|
|
|
188
199
|
this.call.on('app-message', (e) => this.onAppMessage(e));
|
|
189
200
|
|
|
201
|
+
this.call.on('nonfatal-error', (e) => {
|
|
202
|
+
// https://docs.daily.co/reference/daily-js/events/meeting-events#type-audio-processor-error
|
|
203
|
+
if (e?.type === 'audio-processor-error') {
|
|
204
|
+
this.call
|
|
205
|
+
?.updateInputSettings({
|
|
206
|
+
audio: {
|
|
207
|
+
processor: {
|
|
208
|
+
type: 'none',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
.then(() => {
|
|
213
|
+
this.call?.setLocalAudio(true);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
190
218
|
this.call.updateInputSettings({
|
|
191
219
|
audio: {
|
|
192
220
|
processor: {
|
|
@@ -275,4 +303,21 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
275
303
|
throw error;
|
|
276
304
|
}
|
|
277
305
|
}
|
|
306
|
+
|
|
307
|
+
public say(message: string, endCallAfterSpoken?: boolean) {
|
|
308
|
+
this.send({
|
|
309
|
+
type:'say',
|
|
310
|
+
message,
|
|
311
|
+
endCallAfterSpoken
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
public setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]) {
|
|
317
|
+
this.call?.setInputDevicesAsync(options)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public setOutputDeviceAsync(options: Parameters<DailyCall['setOutputDeviceAsync']>[0]) {
|
|
321
|
+
this.call?.setOutputDeviceAsync(options)
|
|
322
|
+
}
|
|
278
323
|
}
|