@vapi-ai/web 2.3.8 → 2.3.10
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/api.ts +14627 -5325
- package/daily-guards.ts +81 -0
- package/dist/api.d.ts +13039 -4225
- package/dist/api.js +568 -504
- package/dist/daily-guards.d.ts +11 -0
- package/dist/daily-guards.js +50 -0
- package/dist/vapi.d.ts +2 -1
- package/dist/vapi.js +7 -9
- package/package.json +2 -2
- package/vapi.ts +13 -9
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DailyCall, DailyAdvancedConfig, DailyFactoryOptions } from '@daily-co/daily-js';
|
|
2
|
+
export interface SafeDailyAdvancedConfig extends Omit<DailyAdvancedConfig, 'alwaysIncludeMicInPermissionPrompt'> {
|
|
3
|
+
alwaysIncludeMicInPermissionPrompt?: true;
|
|
4
|
+
}
|
|
5
|
+
export interface SafeDailyFactoryOptions extends Omit<DailyFactoryOptions, 'audioSource'> {
|
|
6
|
+
audioSource?: string | boolean | MediaStreamTrack;
|
|
7
|
+
}
|
|
8
|
+
export declare function createSafeDailyConfig(config?: Pick<DailyAdvancedConfig, 'avoidEval' | 'alwaysIncludeMicInPermissionPrompt'>): SafeDailyAdvancedConfig;
|
|
9
|
+
export declare function safeSetLocalAudio(call: DailyCall | null, enabled: boolean): void;
|
|
10
|
+
export declare function safeSetInputDevicesAsync(call: DailyCall | null, options: Parameters<DailyCall['setInputDevicesAsync']>[0]): Promise<void>;
|
|
11
|
+
export declare function createSafeDailyFactoryOptions(options?: Pick<DailyFactoryOptions, 'audioSource' | 'startAudioOff'>): SafeDailyFactoryOptions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSafeDailyConfig = createSafeDailyConfig;
|
|
4
|
+
exports.safeSetLocalAudio = safeSetLocalAudio;
|
|
5
|
+
exports.safeSetInputDevicesAsync = safeSetInputDevicesAsync;
|
|
6
|
+
exports.createSafeDailyFactoryOptions = createSafeDailyFactoryOptions;
|
|
7
|
+
function createSafeDailyConfig(config) {
|
|
8
|
+
if (!config)
|
|
9
|
+
return {};
|
|
10
|
+
const { alwaysIncludeMicInPermissionPrompt, ...rest } = config;
|
|
11
|
+
// Force true or remove the property entirely. This can cause Chrome 140+ issues
|
|
12
|
+
if (alwaysIncludeMicInPermissionPrompt === false) {
|
|
13
|
+
console.warn('[Vapi] alwaysIncludeMicInPermissionPrompt:false detected. ' +
|
|
14
|
+
'This can cause Chrome 140+ issues. Removing the property.');
|
|
15
|
+
return rest;
|
|
16
|
+
}
|
|
17
|
+
return config;
|
|
18
|
+
}
|
|
19
|
+
function safeSetLocalAudio(call, enabled) {
|
|
20
|
+
if (!call) {
|
|
21
|
+
throw new Error('Call object is not available.');
|
|
22
|
+
}
|
|
23
|
+
// Never use forceDiscardTrack. This can cause Chrome 140+ issues
|
|
24
|
+
call.setLocalAudio(enabled);
|
|
25
|
+
}
|
|
26
|
+
async function safeSetInputDevicesAsync(call, options) {
|
|
27
|
+
if (!call) {
|
|
28
|
+
throw new Error('Call object is not available.');
|
|
29
|
+
}
|
|
30
|
+
// Validate audioSource
|
|
31
|
+
if ('audioSource' in options && options.audioSource === false) {
|
|
32
|
+
console.warn('[Vapi] setInputDevicesAsync with audioSource:false detected. ' +
|
|
33
|
+
'This can cause Chrome 140+ issues. Using default device instead.');
|
|
34
|
+
const { audioSource, ...safeOptions } = options;
|
|
35
|
+
await call.setInputDevicesAsync(safeOptions);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await call.setInputDevicesAsync(options);
|
|
39
|
+
}
|
|
40
|
+
function createSafeDailyFactoryOptions(options) {
|
|
41
|
+
if (!options)
|
|
42
|
+
return {};
|
|
43
|
+
// Ensure audioSource is never false
|
|
44
|
+
if (options.audioSource === false) {
|
|
45
|
+
console.warn('[Vapi] audioSource:false detected in factory options. ' +
|
|
46
|
+
'This can cause Chrome 140+ issues. Defaulting to true.');
|
|
47
|
+
return { ...options, audioSource: true };
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
package/dist/vapi.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Call, CreateSquadDTO, CreateAssistantDTO, AssistantOverrides, CreateWor
|
|
|
5
5
|
export interface AddMessageMessage {
|
|
6
6
|
type: 'add-message';
|
|
7
7
|
message: ChatCompletionMessageParam;
|
|
8
|
+
triggerResponseEnabled?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export interface ControlMessages {
|
|
10
11
|
type: 'control';
|
|
@@ -83,7 +84,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
83
84
|
setMuted(mute: boolean): void;
|
|
84
85
|
isMuted(): boolean;
|
|
85
86
|
say(message: string, endCallAfterSpoken?: boolean, interruptionsEnabled?: boolean, interruptAssistantEnabled?: boolean): void;
|
|
86
|
-
setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): void
|
|
87
|
+
setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): Promise<void>;
|
|
87
88
|
increaseMicLevel(gain: number): Promise<void>;
|
|
88
89
|
setOutputDeviceAsync(options: Parameters<DailyCall['setOutputDeviceAsync']>[0]): void;
|
|
89
90
|
getDailyCallObject(): DailyCall | null;
|
package/dist/vapi.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const daily_js_1 = __importDefault(require("@daily-co/daily-js"));
|
|
7
7
|
const events_1 = __importDefault(require("events"));
|
|
8
8
|
const client_1 = require("./client");
|
|
9
|
+
const daily_guards_1 = require("./daily-guards");
|
|
9
10
|
async function startAudioPlayer(player, track) {
|
|
10
11
|
player.muted = false;
|
|
11
12
|
player.autoplay = true;
|
|
@@ -67,8 +68,8 @@ class Vapi extends VapiEventEmitter {
|
|
|
67
68
|
super();
|
|
68
69
|
client_1.client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
|
|
69
70
|
client_1.client.setSecurityData(apiToken);
|
|
70
|
-
this.dailyCallConfig = dailyCallConfig
|
|
71
|
-
this.dailyCallObject = dailyCallObject
|
|
71
|
+
this.dailyCallConfig = (0, daily_guards_1.createSafeDailyConfig)(dailyCallConfig);
|
|
72
|
+
this.dailyCallObject = (0, daily_guards_1.createSafeDailyFactoryOptions)(dailyCallObject);
|
|
72
73
|
}
|
|
73
74
|
cleanup() {
|
|
74
75
|
this.started = false;
|
|
@@ -455,7 +456,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
455
456
|
},
|
|
456
457
|
})
|
|
457
458
|
.then(() => {
|
|
458
|
-
this.call
|
|
459
|
+
(0, daily_guards_1.safeSetLocalAudio)(this.call, true);
|
|
459
460
|
});
|
|
460
461
|
}
|
|
461
462
|
});
|
|
@@ -593,10 +594,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
593
594
|
this.call?.sendAppMessage(JSON.stringify(message));
|
|
594
595
|
}
|
|
595
596
|
setMuted(mute) {
|
|
596
|
-
|
|
597
|
-
throw new Error('Call object is not available.');
|
|
598
|
-
}
|
|
599
|
-
this.call.setLocalAudio(!mute);
|
|
597
|
+
(0, daily_guards_1.safeSetLocalAudio)(this.call, !mute);
|
|
600
598
|
}
|
|
601
599
|
isMuted() {
|
|
602
600
|
if (!this.call) {
|
|
@@ -614,7 +612,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
614
612
|
});
|
|
615
613
|
}
|
|
616
614
|
setInputDevicesAsync(options) {
|
|
617
|
-
this.call
|
|
615
|
+
return (0, daily_guards_1.safeSetInputDevicesAsync)(this.call, options);
|
|
618
616
|
}
|
|
619
617
|
async increaseMicLevel(gain) {
|
|
620
618
|
if (!this.call) {
|
|
@@ -630,7 +628,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
630
628
|
const destination = audioContext.createMediaStreamDestination();
|
|
631
629
|
gainNode.connect(destination);
|
|
632
630
|
const [boostedTrack] = destination.stream.getAudioTracks();
|
|
633
|
-
await this.call
|
|
631
|
+
await (0, daily_guards_1.safeSetInputDevicesAsync)(this.call, { audioSource: boostedTrack });
|
|
634
632
|
}
|
|
635
633
|
catch (error) {
|
|
636
634
|
console.error("Error adjusting microphone level:", error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vapi-ai/web",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/vapi.js",
|
|
6
6
|
"types": "dist/vapi.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"node": ">=18.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@daily-co/daily-js": "^0.
|
|
33
|
+
"@daily-co/daily-js": "^0.83.1",
|
|
34
34
|
"events": "^3.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
package/vapi.ts
CHANGED
|
@@ -21,10 +21,17 @@ import {
|
|
|
21
21
|
WorkflowOverrides,
|
|
22
22
|
} from './api';
|
|
23
23
|
import { client } from './client';
|
|
24
|
+
import {
|
|
25
|
+
createSafeDailyConfig,
|
|
26
|
+
createSafeDailyFactoryOptions,
|
|
27
|
+
safeSetLocalAudio,
|
|
28
|
+
safeSetInputDevicesAsync,
|
|
29
|
+
} from './daily-guards';
|
|
24
30
|
|
|
25
31
|
export interface AddMessageMessage {
|
|
26
32
|
type: 'add-message';
|
|
27
33
|
message: ChatCompletionMessageParam;
|
|
34
|
+
triggerResponseEnabled?: boolean;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export interface ControlMessages {
|
|
@@ -205,8 +212,8 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
205
212
|
super();
|
|
206
213
|
client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
|
|
207
214
|
client.setSecurityData(apiToken);
|
|
208
|
-
this.dailyCallConfig = dailyCallConfig
|
|
209
|
-
this.dailyCallObject = dailyCallObject
|
|
215
|
+
this.dailyCallConfig = createSafeDailyConfig(dailyCallConfig);
|
|
216
|
+
this.dailyCallObject = createSafeDailyFactoryOptions(dailyCallObject);
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
private cleanup() {
|
|
@@ -648,7 +655,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
648
655
|
},
|
|
649
656
|
})
|
|
650
657
|
.then(() => {
|
|
651
|
-
this.call
|
|
658
|
+
safeSetLocalAudio(this.call, true);
|
|
652
659
|
});
|
|
653
660
|
}
|
|
654
661
|
});
|
|
@@ -804,10 +811,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
804
811
|
}
|
|
805
812
|
|
|
806
813
|
public setMuted(mute: boolean) {
|
|
807
|
-
|
|
808
|
-
throw new Error('Call object is not available.');
|
|
809
|
-
}
|
|
810
|
-
this.call.setLocalAudio(!mute);
|
|
814
|
+
safeSetLocalAudio(this.call, !mute);
|
|
811
815
|
}
|
|
812
816
|
|
|
813
817
|
public isMuted() {
|
|
@@ -831,7 +835,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
831
835
|
public setInputDevicesAsync(
|
|
832
836
|
options: Parameters<DailyCall['setInputDevicesAsync']>[0],
|
|
833
837
|
) {
|
|
834
|
-
this.call
|
|
838
|
+
return safeSetInputDevicesAsync(this.call, options);
|
|
835
839
|
}
|
|
836
840
|
|
|
837
841
|
public async increaseMicLevel(gain: number) {
|
|
@@ -854,7 +858,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
854
858
|
gainNode.connect(destination);
|
|
855
859
|
|
|
856
860
|
const [boostedTrack] = destination.stream.getAudioTracks();
|
|
857
|
-
await this.call
|
|
861
|
+
await safeSetInputDevicesAsync(this.call, { audioSource: boostedTrack });
|
|
858
862
|
} catch (error) {
|
|
859
863
|
console.error("Error adjusting microphone level:", error);
|
|
860
864
|
}
|