@vapi-ai/web 2.3.9 → 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.
@@ -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
@@ -84,7 +84,7 @@ export default class Vapi extends VapiEventEmitter {
84
84
  setMuted(mute: boolean): void;
85
85
  isMuted(): boolean;
86
86
  say(message: string, endCallAfterSpoken?: boolean, interruptionsEnabled?: boolean, interruptAssistantEnabled?: boolean): void;
87
- setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): void;
87
+ setInputDevicesAsync(options: Parameters<DailyCall['setInputDevicesAsync']>[0]): Promise<void>;
88
88
  increaseMicLevel(gain: number): Promise<void>;
89
89
  setOutputDeviceAsync(options: Parameters<DailyCall['setOutputDeviceAsync']>[0]): void;
90
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?.setLocalAudio(true);
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
- if (!this.call) {
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?.setInputDevicesAsync(options);
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.setInputDevicesAsync({ audioSource: boostedTrack });
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.9",
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.80.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,6 +21,12 @@ 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';
@@ -206,8 +212,8 @@ export default class Vapi extends VapiEventEmitter {
206
212
  super();
207
213
  client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
208
214
  client.setSecurityData(apiToken);
209
- this.dailyCallConfig = dailyCallConfig ?? {};
210
- this.dailyCallObject = dailyCallObject ?? {};
215
+ this.dailyCallConfig = createSafeDailyConfig(dailyCallConfig);
216
+ this.dailyCallObject = createSafeDailyFactoryOptions(dailyCallObject);
211
217
  }
212
218
 
213
219
  private cleanup() {
@@ -649,7 +655,7 @@ export default class Vapi extends VapiEventEmitter {
649
655
  },
650
656
  })
651
657
  .then(() => {
652
- this.call?.setLocalAudio(true);
658
+ safeSetLocalAudio(this.call, true);
653
659
  });
654
660
  }
655
661
  });
@@ -805,10 +811,7 @@ export default class Vapi extends VapiEventEmitter {
805
811
  }
806
812
 
807
813
  public setMuted(mute: boolean) {
808
- if (!this.call) {
809
- throw new Error('Call object is not available.');
810
- }
811
- this.call.setLocalAudio(!mute);
814
+ safeSetLocalAudio(this.call, !mute);
812
815
  }
813
816
 
814
817
  public isMuted() {
@@ -832,7 +835,7 @@ export default class Vapi extends VapiEventEmitter {
832
835
  public setInputDevicesAsync(
833
836
  options: Parameters<DailyCall['setInputDevicesAsync']>[0],
834
837
  ) {
835
- this.call?.setInputDevicesAsync(options);
838
+ return safeSetInputDevicesAsync(this.call, options);
836
839
  }
837
840
 
838
841
  public async increaseMicLevel(gain: number) {
@@ -855,7 +858,7 @@ export default class Vapi extends VapiEventEmitter {
855
858
  gainNode.connect(destination);
856
859
 
857
860
  const [boostedTrack] = destination.stream.getAudioTracks();
858
- await this.call.setInputDevicesAsync({ audioSource: boostedTrack });
861
+ await safeSetInputDevicesAsync(this.call, { audioSource: boostedTrack });
859
862
  } catch (error) {
860
863
  console.error("Error adjusting microphone level:", error);
861
864
  }