@vapi-ai/web 1.0.253 → 1.0.256
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 +21 -3
- package/api.ts +681 -229
- package/dist/api.d.ts +590 -212
- package/dist/api.js +470 -326
- package/dist/client.js +2 -11
- package/dist/vapi.js +90 -108
- package/package.json +2 -2
- package/tsconfig.json +1 -1
- package/vapi.ts +3 -1
package/dist/client.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.client = void 0;
|
|
13
4
|
const api_1 = require("./api");
|
|
@@ -16,7 +7,7 @@ const api = new api_1.Api({
|
|
|
16
7
|
baseApiParams: {
|
|
17
8
|
secure: true,
|
|
18
9
|
},
|
|
19
|
-
securityWorker: (securityData) =>
|
|
10
|
+
securityWorker: async (securityData) => {
|
|
20
11
|
if (securityData) {
|
|
21
12
|
return {
|
|
22
13
|
headers: {
|
|
@@ -24,6 +15,6 @@ const api = new api_1.Api({
|
|
|
24
15
|
},
|
|
25
16
|
};
|
|
26
17
|
}
|
|
27
|
-
}
|
|
18
|
+
},
|
|
28
19
|
});
|
|
29
20
|
exports.client = api;
|
package/dist/vapi.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -17,26 +8,22 @@ const events_1 = __importDefault(require("events"));
|
|
|
17
8
|
const client_1 = require("./client");
|
|
18
9
|
function destroyAudioPlayer(participantId) {
|
|
19
10
|
const player = document.querySelector(`audio[data-participant-id="${participantId}"]`);
|
|
20
|
-
player
|
|
11
|
+
player?.remove();
|
|
21
12
|
}
|
|
22
|
-
function startPlayer(player, track) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
});
|
|
13
|
+
async function startPlayer(player, track) {
|
|
14
|
+
player.muted = false;
|
|
15
|
+
player.autoplay = true;
|
|
16
|
+
if (track != null) {
|
|
17
|
+
player.srcObject = new MediaStream([track]);
|
|
18
|
+
await player.play();
|
|
19
|
+
}
|
|
31
20
|
}
|
|
32
|
-
function buildAudioPlayer(track, participantId) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return player;
|
|
39
|
-
});
|
|
21
|
+
async function buildAudioPlayer(track, participantId) {
|
|
22
|
+
const player = document.createElement("audio");
|
|
23
|
+
player.dataset.participantId = participantId;
|
|
24
|
+
document.body.appendChild(player);
|
|
25
|
+
await startPlayer(player, track);
|
|
26
|
+
return player;
|
|
40
27
|
}
|
|
41
28
|
function subscribeToTracks(e, call) {
|
|
42
29
|
if (e.participant.local)
|
|
@@ -70,98 +57,95 @@ class VapiEventEmitter extends events_1.default {
|
|
|
70
57
|
}
|
|
71
58
|
}
|
|
72
59
|
class Vapi extends VapiEventEmitter {
|
|
60
|
+
started = false;
|
|
61
|
+
call = null;
|
|
62
|
+
speakingTimeout = null;
|
|
63
|
+
averageSpeechLevel = 0;
|
|
73
64
|
constructor(apiToken, apiBaseUrl) {
|
|
74
65
|
super();
|
|
75
|
-
|
|
76
|
-
this.call = null;
|
|
77
|
-
this.speakingTimeout = null;
|
|
78
|
-
this.averageSpeechLevel = 0;
|
|
79
|
-
client_1.client.baseUrl = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : "https://api.vapi.ai";
|
|
66
|
+
client_1.client.baseUrl = apiBaseUrl ?? "https://api.vapi.ai";
|
|
80
67
|
client_1.client.setSecurityData(apiToken);
|
|
81
68
|
}
|
|
82
69
|
cleanup() {
|
|
83
|
-
var _a;
|
|
84
70
|
this.started = false;
|
|
85
|
-
|
|
71
|
+
this.call?.destroy();
|
|
86
72
|
this.call = null;
|
|
87
73
|
this.speakingTimeout = null;
|
|
88
74
|
}
|
|
89
|
-
start(assistant) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.call.on("left-meeting", () => {
|
|
107
|
-
this.emit("call-end");
|
|
108
|
-
this.cleanup();
|
|
109
|
-
});
|
|
110
|
-
this.call.on("participant-left", (e) => {
|
|
111
|
-
if (!e)
|
|
112
|
-
return;
|
|
113
|
-
destroyAudioPlayer(e.participant.session_id);
|
|
114
|
-
});
|
|
115
|
-
this.call.on("error", () => {
|
|
116
|
-
// Ignore error
|
|
117
|
-
});
|
|
118
|
-
this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
var _b, _c, _d;
|
|
120
|
-
if (!e || !e.participant)
|
|
121
|
-
return;
|
|
122
|
-
if ((_b = e.participant) === null || _b === void 0 ? void 0 : _b.local)
|
|
123
|
-
return;
|
|
124
|
-
if (e.track.kind !== "audio")
|
|
125
|
-
return;
|
|
126
|
-
yield buildAudioPlayer(e.track, e.participant.session_id);
|
|
127
|
-
if (((_c = e === null || e === void 0 ? void 0 : e.participant) === null || _c === void 0 ? void 0 : _c.user_name) !== "Vapi Speaker")
|
|
128
|
-
return;
|
|
129
|
-
(_d = this.call) === null || _d === void 0 ? void 0 : _d.sendAppMessage("playable");
|
|
130
|
-
this.emit("call-start");
|
|
131
|
-
}));
|
|
132
|
-
this.call.on("participant-joined", (e) => {
|
|
133
|
-
if (!e || !this.call)
|
|
134
|
-
return;
|
|
135
|
-
subscribeToTracks(e, this.call);
|
|
136
|
-
});
|
|
137
|
-
yield this.call.join({
|
|
138
|
-
url: webCall.webCallUrl,
|
|
139
|
-
subscribeToTracksAutomatically: false,
|
|
140
|
-
});
|
|
141
|
-
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
142
|
-
this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
|
|
143
|
-
this.call.on("app-message", (e) => this.onAppMessage(e));
|
|
144
|
-
this.call.updateInputSettings({
|
|
145
|
-
audio: {
|
|
146
|
-
processor: {
|
|
147
|
-
type: "noise-cancellation",
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
return webCall;
|
|
152
|
-
}
|
|
153
|
-
catch (e) {
|
|
154
|
-
console.error(e);
|
|
155
|
-
this.emit("error", e);
|
|
75
|
+
async start(assistant) {
|
|
76
|
+
if (this.started) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
this.started = true;
|
|
80
|
+
try {
|
|
81
|
+
const webCall = (await client_1.client.call.callControllerCreateWebCall({
|
|
82
|
+
assistant: typeof assistant === "string" ? undefined : assistant,
|
|
83
|
+
assistantId: typeof assistant === "string" ? assistant : undefined,
|
|
84
|
+
})).data;
|
|
85
|
+
this.call = daily_js_1.default.createCallObject({
|
|
86
|
+
audioSource: true,
|
|
87
|
+
videoSource: false,
|
|
88
|
+
});
|
|
89
|
+
this.call.iframe()?.style.setProperty("display", "none");
|
|
90
|
+
this.call.on("left-meeting", () => {
|
|
91
|
+
this.emit("call-end");
|
|
156
92
|
this.cleanup();
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
93
|
+
});
|
|
94
|
+
this.call.on("participant-left", (e) => {
|
|
95
|
+
if (!e)
|
|
96
|
+
return;
|
|
97
|
+
destroyAudioPlayer(e.participant.session_id);
|
|
98
|
+
});
|
|
99
|
+
this.call.on("error", () => {
|
|
100
|
+
// Ignore error
|
|
101
|
+
});
|
|
102
|
+
this.call.on("track-started", async (e) => {
|
|
103
|
+
if (!e || !e.participant)
|
|
104
|
+
return;
|
|
105
|
+
if (e.participant?.local)
|
|
106
|
+
return;
|
|
107
|
+
if (e.track.kind !== "audio")
|
|
108
|
+
return;
|
|
109
|
+
await buildAudioPlayer(e.track, e.participant.session_id);
|
|
110
|
+
if (e?.participant?.user_name !== "Vapi Speaker")
|
|
111
|
+
return;
|
|
112
|
+
this.call?.sendAppMessage("playable");
|
|
113
|
+
});
|
|
114
|
+
this.call.on("participant-joined", (e) => {
|
|
115
|
+
if (!e || !this.call)
|
|
116
|
+
return;
|
|
117
|
+
subscribeToTracks(e, this.call);
|
|
118
|
+
});
|
|
119
|
+
await this.call.join({
|
|
120
|
+
url: webCall.webCallUrl,
|
|
121
|
+
subscribeToTracksAutomatically: false,
|
|
122
|
+
});
|
|
123
|
+
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
124
|
+
this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
|
|
125
|
+
this.call.on("app-message", (e) => this.onAppMessage(e));
|
|
126
|
+
this.call.updateInputSettings({
|
|
127
|
+
audio: {
|
|
128
|
+
processor: {
|
|
129
|
+
type: "noise-cancellation",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return webCall;
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
console.error(e);
|
|
137
|
+
this.emit("error", e);
|
|
138
|
+
this.cleanup();
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
160
141
|
}
|
|
161
142
|
onAppMessage(e) {
|
|
162
143
|
if (!e)
|
|
163
144
|
return;
|
|
164
145
|
try {
|
|
146
|
+
if (e.data === "listening") {
|
|
147
|
+
return this.emit("call-start");
|
|
148
|
+
}
|
|
165
149
|
const parsedMessage = JSON.parse(e.data);
|
|
166
150
|
this.emit("message", parsedMessage);
|
|
167
151
|
}
|
|
@@ -188,14 +172,12 @@ class Vapi extends VapiEventEmitter {
|
|
|
188
172
|
}, 1000);
|
|
189
173
|
}
|
|
190
174
|
stop() {
|
|
191
|
-
var _a;
|
|
192
175
|
this.started = false;
|
|
193
|
-
|
|
176
|
+
this.call?.destroy();
|
|
194
177
|
this.call = null;
|
|
195
178
|
}
|
|
196
179
|
send(message) {
|
|
197
|
-
|
|
198
|
-
(_a = this.call) === null || _a === void 0 ? void 0 : _a.sendAppMessage(JSON.stringify(message));
|
|
180
|
+
this.call?.sendAppMessage(JSON.stringify(message));
|
|
199
181
|
}
|
|
200
182
|
}
|
|
201
183
|
exports.default = Vapi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vapi-ai/web",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.256",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/vapi.js",
|
|
6
6
|
"types": "dist/vapi.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
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.57.3",
|
|
26
26
|
"events": "^3.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
12
|
|
|
13
13
|
/* Language and Environment */
|
|
14
|
-
"target": "
|
|
14
|
+
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
17
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
package/vapi.ts
CHANGED
|
@@ -165,7 +165,6 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
165
165
|
|
|
166
166
|
if (e?.participant?.user_name !== "Vapi Speaker") return;
|
|
167
167
|
this.call?.sendAppMessage("playable");
|
|
168
|
-
this.emit("call-start");
|
|
169
168
|
});
|
|
170
169
|
|
|
171
170
|
this.call.on("participant-joined", (e) => {
|
|
@@ -204,6 +203,9 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
204
203
|
private onAppMessage(e?: DailyEventObjectAppMessage) {
|
|
205
204
|
if (!e) return;
|
|
206
205
|
try {
|
|
206
|
+
if (e.data === "listening") {
|
|
207
|
+
return this.emit("call-start");
|
|
208
|
+
}
|
|
207
209
|
const parsedMessage = JSON.parse(e.data);
|
|
208
210
|
this.emit("message", parsedMessage);
|
|
209
211
|
} catch (e) {
|