@vapi-ai/web 2.3.9 → 2.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/api.ts +5864 -4194
- package/daily-guards.ts +81 -0
- package/dist/api.d.ts +7858 -6678
- package/dist/api.js +532 -445
- package/dist/daily-guards.d.ts +11 -0
- package/dist/daily-guards.js +50 -0
- package/dist/vapi.d.ts +2 -2
- package/dist/vapi.js +21 -18
- package/package.json +2 -2
- package/vapi.ts +26 -18
package/daily-guards.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DailyCall,
|
|
3
|
+
DailyAdvancedConfig,
|
|
4
|
+
DailyFactoryOptions,
|
|
5
|
+
} from '@daily-co/daily-js';
|
|
6
|
+
|
|
7
|
+
export interface SafeDailyAdvancedConfig extends Omit<DailyAdvancedConfig, 'alwaysIncludeMicInPermissionPrompt'> {
|
|
8
|
+
alwaysIncludeMicInPermissionPrompt?: true; // Only allow true
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SafeDailyFactoryOptions extends Omit<DailyFactoryOptions, 'audioSource'> {
|
|
12
|
+
audioSource?: string | boolean | MediaStreamTrack;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createSafeDailyConfig(
|
|
16
|
+
config?: Pick<DailyAdvancedConfig, 'avoidEval' | 'alwaysIncludeMicInPermissionPrompt'>
|
|
17
|
+
): SafeDailyAdvancedConfig {
|
|
18
|
+
if (!config) return {};
|
|
19
|
+
|
|
20
|
+
const { alwaysIncludeMicInPermissionPrompt, ...rest } = config;
|
|
21
|
+
|
|
22
|
+
// Force true or remove the property entirely. This can cause Chrome 140+ issues
|
|
23
|
+
if (alwaysIncludeMicInPermissionPrompt === false) {
|
|
24
|
+
console.warn(
|
|
25
|
+
'[Vapi] alwaysIncludeMicInPermissionPrompt:false detected. ' +
|
|
26
|
+
'This can cause Chrome 140+ issues. Removing the property.'
|
|
27
|
+
);
|
|
28
|
+
return rest;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return config as SafeDailyAdvancedConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function safeSetLocalAudio(call: DailyCall | null, enabled: boolean): void {
|
|
35
|
+
if (!call) {
|
|
36
|
+
throw new Error('Call object is not available.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Never use forceDiscardTrack. This can cause Chrome 140+ issues
|
|
40
|
+
call.setLocalAudio(enabled);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function safeSetInputDevicesAsync(
|
|
44
|
+
call: DailyCall | null,
|
|
45
|
+
options: Parameters<DailyCall['setInputDevicesAsync']>[0]
|
|
46
|
+
): Promise<void> {
|
|
47
|
+
if (!call) {
|
|
48
|
+
throw new Error('Call object is not available.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Validate audioSource
|
|
52
|
+
if ('audioSource' in options && options.audioSource === false) {
|
|
53
|
+
console.warn(
|
|
54
|
+
'[Vapi] setInputDevicesAsync with audioSource:false detected. ' +
|
|
55
|
+
'This can cause Chrome 140+ issues. Using default device instead.'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const { audioSource, ...safeOptions } = options;
|
|
59
|
+
await call.setInputDevicesAsync(safeOptions);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await call.setInputDevicesAsync(options);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createSafeDailyFactoryOptions(
|
|
67
|
+
options?: Pick<DailyFactoryOptions, 'audioSource' | 'startAudioOff'>
|
|
68
|
+
): SafeDailyFactoryOptions {
|
|
69
|
+
if (!options) return {};
|
|
70
|
+
|
|
71
|
+
// Ensure audioSource is never false
|
|
72
|
+
if (options.audioSource === false) {
|
|
73
|
+
console.warn(
|
|
74
|
+
'[Vapi] audioSource:false detected in factory options. ' +
|
|
75
|
+
'This can cause Chrome 140+ issues. Defaulting to true.'
|
|
76
|
+
);
|
|
77
|
+
return { ...options, audioSource: true };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return options;
|
|
81
|
+
}
|