@vanira/sdk 0.0.87 → 0.0.88
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/dist/headless/index.cjs +1 -1
- package/dist/headless/index.js +36 -33
- package/dist/index.d.ts +4 -0
- package/dist/platforms/browser.cjs +1 -1
- package/dist/platforms/browser.js +36 -33
- package/dist/platforms/react-native.cjs +2 -2
- package/dist/platforms/react-native.js +301 -298
- package/dist/vanira-sdk.es.js +3885 -3879
- package/dist/vanira-sdk.js +1 -1
- package/dist/vanira-sdk.umd.js +85 -85
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var q = Object.defineProperty;
|
|
2
|
-
var X = (
|
|
3
|
-
var
|
|
2
|
+
var X = (n, e, t) => e in n ? q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var d = (n, e, t) => X(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
class Z {
|
|
5
5
|
pause() {
|
|
6
6
|
}
|
|
@@ -34,22 +34,22 @@ class ee {
|
|
|
34
34
|
}
|
|
35
35
|
class te {
|
|
36
36
|
bind(e, t) {
|
|
37
|
-
return e.onopen = () => t.onOpen(), e.onerror = (
|
|
38
|
-
if (typeof
|
|
39
|
-
t.onMessage({ text:
|
|
37
|
+
return e.onopen = () => t.onOpen(), e.onerror = (i) => t.onError(i), e.onmessage = (i) => {
|
|
38
|
+
if (typeof i.data == "string") {
|
|
39
|
+
t.onMessage({ text: i.data });
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
if (
|
|
42
|
+
if (i.data instanceof ArrayBuffer) {
|
|
43
43
|
try {
|
|
44
|
-
const a = new TextDecoder().decode(
|
|
44
|
+
const a = new TextDecoder().decode(i.data), r = JSON.parse(a);
|
|
45
45
|
(r == null ? void 0 : r.event) === "client_tool_call" && t.onMessage({ text: a });
|
|
46
46
|
} catch {
|
|
47
47
|
}
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
}, {
|
|
51
|
-
send(
|
|
52
|
-
e.readyState === "open" && e.send(
|
|
51
|
+
send(i) {
|
|
52
|
+
e.readyState === "open" && e.send(i);
|
|
53
53
|
},
|
|
54
54
|
isOpen() {
|
|
55
55
|
return e.readyState === "open";
|
|
@@ -60,7 +60,7 @@ class te {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const ie = "https://api.vanira.io", c = {
|
|
64
64
|
Form: "vanira_form",
|
|
65
65
|
Calendar: "vanira_calendar",
|
|
66
66
|
Navigate: "vanira_navigate",
|
|
@@ -87,18 +87,18 @@ const ne = "https://api.vanira.io", c = {
|
|
|
87
87
|
KycDocumentCapture: "vanira_kyc_document_capture",
|
|
88
88
|
KycSelfieCapture: "vanira_kyc_selfie_capture",
|
|
89
89
|
KycSignatureCapture: "vanira_kyc_signature_capture"
|
|
90
|
-
},
|
|
91
|
-
function K(
|
|
92
|
-
return !!
|
|
90
|
+
}, ne = Object.values(c), ae = new Set(ne);
|
|
91
|
+
function K(n) {
|
|
92
|
+
return !!n && ae.has(n);
|
|
93
93
|
}
|
|
94
|
-
function J(
|
|
95
|
-
if (typeof
|
|
94
|
+
function J(n) {
|
|
95
|
+
if (typeof n == "string")
|
|
96
96
|
try {
|
|
97
|
-
return JSON.parse(
|
|
97
|
+
return JSON.parse(n);
|
|
98
98
|
} catch {
|
|
99
99
|
return {};
|
|
100
100
|
}
|
|
101
|
-
return
|
|
101
|
+
return n && typeof n == "object" ? n : {};
|
|
102
102
|
}
|
|
103
103
|
const $ = {
|
|
104
104
|
type_on_whiteboard: c.TypeText,
|
|
@@ -153,28 +153,28 @@ const $ = {
|
|
|
153
153
|
vanira_signature_capture: c.KycSignatureCapture,
|
|
154
154
|
vanira_kyc_signature: c.KycSignatureCapture
|
|
155
155
|
};
|
|
156
|
-
function re(
|
|
157
|
-
const t =
|
|
158
|
-
return Array.isArray(t) ? t.some((
|
|
156
|
+
function re(n, e) {
|
|
157
|
+
const t = n.commands ?? (e == null ? void 0 : e.commands) ?? n.construction ?? (e == null ? void 0 : e.construction) ?? n.geogebra_commands ?? (e == null ? void 0 : e.geogebra_commands) ?? n.script ?? (e == null ? void 0 : e.script);
|
|
158
|
+
return Array.isArray(t) ? t.some((i) => String(i).trim().length > 0) : typeof t == "string" && t.trim().length > 0;
|
|
159
159
|
}
|
|
160
|
-
function se(
|
|
161
|
-
const t =
|
|
160
|
+
function se(n, e) {
|
|
161
|
+
const t = n.material_id ?? (e == null ? void 0 : e.material_id) ?? n.materialId ?? (e == null ? void 0 : e.materialId);
|
|
162
162
|
return typeof t == "string" && t.trim().length > 0;
|
|
163
163
|
}
|
|
164
|
-
function oe(
|
|
165
|
-
const t =
|
|
164
|
+
function oe(n, e) {
|
|
165
|
+
const t = n.latex_text ?? (e == null ? void 0 : e.latex_text);
|
|
166
166
|
return typeof t == "string" && t.trim().length > 0;
|
|
167
167
|
}
|
|
168
|
-
function G(
|
|
169
|
-
const t =
|
|
168
|
+
function G(n, e) {
|
|
169
|
+
const t = n.text_to_type ?? (e == null ? void 0 : e.text_to_type) ?? n.text ?? (e == null ? void 0 : e.text) ?? n.value ?? (e == null ? void 0 : e.value);
|
|
170
170
|
return typeof t == "string" && t.trim().length > 0;
|
|
171
171
|
}
|
|
172
|
-
function ce(
|
|
173
|
-
const t =
|
|
174
|
-
return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((
|
|
172
|
+
function ce(n, e) {
|
|
173
|
+
const t = n.fields ?? (e == null ? void 0 : e.fields);
|
|
174
|
+
return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((i) => i.trim()).filter(Boolean).length > 0 : !1;
|
|
175
175
|
}
|
|
176
|
-
function le(
|
|
177
|
-
const t =
|
|
176
|
+
function le(n, e) {
|
|
177
|
+
const t = n == null ? void 0 : n.preset_id;
|
|
178
178
|
if (typeof t == "string") {
|
|
179
179
|
if (K(t)) return t;
|
|
180
180
|
const r = j[t];
|
|
@@ -187,43 +187,43 @@ function le(i, e) {
|
|
|
187
187
|
if (r) return r;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function de(
|
|
191
|
-
const
|
|
192
|
-
let a = le(
|
|
193
|
-
if (a === c.Form && G(
|
|
190
|
+
function de(n, e, t) {
|
|
191
|
+
const i = J(e);
|
|
192
|
+
let a = le(n, i);
|
|
193
|
+
if (a === c.Form && G(i, n) && !ce(i, n))
|
|
194
194
|
return c.TypeText;
|
|
195
195
|
if (a) return a;
|
|
196
196
|
const r = String(t ?? "").trim().toLowerCase();
|
|
197
197
|
if (r && $[r])
|
|
198
198
|
return $[r];
|
|
199
|
-
if (re(
|
|
199
|
+
if (re(i, n) || se(i, n))
|
|
200
200
|
return c.GeoGebra;
|
|
201
|
-
if (oe(
|
|
201
|
+
if (oe(i, n))
|
|
202
202
|
return c.WriteLatexText;
|
|
203
|
-
if (G(
|
|
203
|
+
if (G(i, n))
|
|
204
204
|
return c.TypeText;
|
|
205
205
|
}
|
|
206
206
|
const I = "vanira_latest_call_id", k = "vanira_prospect_id";
|
|
207
|
-
function T(
|
|
208
|
-
return `vanira_latest_call_id_${
|
|
207
|
+
function T(n) {
|
|
208
|
+
return `vanira_latest_call_id_${n}`;
|
|
209
209
|
}
|
|
210
|
-
function b(
|
|
211
|
-
return `vanira_prospect_id_${
|
|
210
|
+
function b(n) {
|
|
211
|
+
return `vanira_prospect_id_${n}`;
|
|
212
212
|
}
|
|
213
|
-
function z(
|
|
214
|
-
return `vanira_call_meta_${
|
|
213
|
+
function z(n) {
|
|
214
|
+
return `vanira_call_meta_${n}`;
|
|
215
215
|
}
|
|
216
|
-
function S(
|
|
217
|
-
if (!
|
|
216
|
+
function S(n, e) {
|
|
217
|
+
if (!n) return null;
|
|
218
218
|
try {
|
|
219
|
-
return
|
|
219
|
+
return n.getItem(e);
|
|
220
220
|
} catch {
|
|
221
221
|
return null;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
function W(
|
|
225
|
-
if (typeof window > "u" || !
|
|
226
|
-
const e = [], t = S(window.localStorage, z(
|
|
224
|
+
function W(n) {
|
|
225
|
+
if (typeof window > "u" || !n) return null;
|
|
226
|
+
const e = [], t = S(window.localStorage, z(n));
|
|
227
227
|
if (t)
|
|
228
228
|
try {
|
|
229
229
|
const h = JSON.parse(t);
|
|
@@ -234,33 +234,33 @@ function W(i) {
|
|
|
234
234
|
});
|
|
235
235
|
} catch {
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const i = (h, _, s) => {
|
|
238
238
|
h && e.push({
|
|
239
239
|
callId: h,
|
|
240
|
-
prospectId:
|
|
241
|
-
updatedAt:
|
|
240
|
+
prospectId: _ || void 0,
|
|
241
|
+
updatedAt: s
|
|
242
242
|
});
|
|
243
|
-
}, a = S(window.localStorage, b(
|
|
244
|
-
return
|
|
245
|
-
S(window.localStorage, T(
|
|
243
|
+
}, a = S(window.localStorage, b(n)), r = S(window.sessionStorage, b(n)), o = S(window.localStorage, k);
|
|
244
|
+
return i(
|
|
245
|
+
S(window.localStorage, T(n)),
|
|
246
246
|
a || o,
|
|
247
247
|
2
|
|
248
|
-
),
|
|
249
|
-
S(window.sessionStorage, T(
|
|
248
|
+
), i(
|
|
249
|
+
S(window.sessionStorage, T(n)),
|
|
250
250
|
r || o,
|
|
251
251
|
1
|
|
252
|
-
),
|
|
252
|
+
), i(S(window.localStorage, I), o, 0), i(S(window.sessionStorage, I), o, 0), e.length ? (e.sort((h, _) => _.updatedAt - h.updatedAt), e[0]) : null;
|
|
253
253
|
}
|
|
254
|
-
function he(
|
|
255
|
-
var a, r, o, h, s, u,
|
|
256
|
-
if (typeof window > "u" || !
|
|
257
|
-
const
|
|
254
|
+
function he(n, e, t) {
|
|
255
|
+
var a, r, o, h, _, s, u, l, p;
|
|
256
|
+
if (typeof window > "u" || !n || !e) return;
|
|
257
|
+
const i = {
|
|
258
258
|
callId: e,
|
|
259
259
|
prospectId: t,
|
|
260
260
|
updatedAt: Date.now()
|
|
261
261
|
};
|
|
262
262
|
try {
|
|
263
|
-
(a = window.localStorage) == null || a.setItem(z(
|
|
263
|
+
(a = window.localStorage) == null || a.setItem(z(n), JSON.stringify(i)), (r = window.localStorage) == null || r.setItem(T(n), e), (o = window.sessionStorage) == null || o.setItem(T(n), e), t && ((h = window.localStorage) == null || h.setItem(b(n), t), (_ = window.sessionStorage) == null || _.setItem(b(n), t)), (s = window.localStorage) == null || s.setItem(I, e), (u = window.sessionStorage) == null || u.setItem(I, e), t && ((l = window.localStorage) == null || l.setItem(k, t), (p = window.sessionStorage) == null || p.setItem(k, t));
|
|
264
264
|
} catch {
|
|
265
265
|
}
|
|
266
266
|
}
|
|
@@ -269,101 +269,101 @@ const ue = /* @__PURE__ */ new Set([
|
|
|
269
269
|
"clearAudio",
|
|
270
270
|
"client_tool_cancel"
|
|
271
271
|
]);
|
|
272
|
-
function pe(
|
|
273
|
-
if (!
|
|
274
|
-
const e =
|
|
272
|
+
function pe(n) {
|
|
273
|
+
if (!n || typeof n != "object") return !1;
|
|
274
|
+
const e = n.event;
|
|
275
275
|
return typeof e == "string" && ue.has(e);
|
|
276
276
|
}
|
|
277
277
|
const x = 16 * 1024, _e = 256 * 1024;
|
|
278
|
-
function E(
|
|
279
|
-
return (
|
|
278
|
+
function E(n, e) {
|
|
279
|
+
return (n == null ? void 0 : n.readyState) === "open" && (e == null ? void 0 : e.readyState) === "open";
|
|
280
280
|
}
|
|
281
|
-
function me(
|
|
281
|
+
function me(n, e) {
|
|
282
282
|
return {
|
|
283
|
-
control: (
|
|
283
|
+
control: (n == null ? void 0 : n.readyState) ?? "missing",
|
|
284
284
|
mediaBytes: (e == null ? void 0 : e.readyState) ?? "missing"
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
async function fe(
|
|
288
|
-
if (E(
|
|
287
|
+
async function fe(n, e, t = 8e3) {
|
|
288
|
+
if (E(n, e))
|
|
289
289
|
return !0;
|
|
290
|
-
const
|
|
291
|
-
for (; Date.now() <
|
|
292
|
-
if (E(
|
|
290
|
+
const i = Date.now() + t;
|
|
291
|
+
for (; Date.now() < i; ) {
|
|
292
|
+
if (E(n, e))
|
|
293
293
|
return !0;
|
|
294
294
|
await new Promise((a) => setTimeout(a, 50));
|
|
295
295
|
}
|
|
296
|
-
return E(
|
|
296
|
+
return E(n, e);
|
|
297
297
|
}
|
|
298
|
-
async function H(
|
|
299
|
-
for (;
|
|
298
|
+
async function H(n) {
|
|
299
|
+
for (; n.bufferedAmount > _e; )
|
|
300
300
|
await new Promise((e) => setTimeout(e, 10));
|
|
301
301
|
}
|
|
302
|
-
async function ye(
|
|
302
|
+
async function ye(n) {
|
|
303
303
|
const {
|
|
304
304
|
bytes: e,
|
|
305
305
|
filename: t,
|
|
306
|
-
contentType:
|
|
306
|
+
contentType: i,
|
|
307
307
|
reason: a,
|
|
308
308
|
message: r,
|
|
309
309
|
callId: o,
|
|
310
310
|
mediaBytesChannel: h,
|
|
311
|
-
sendControlEvent:
|
|
312
|
-
uploadId:
|
|
313
|
-
uploadKind:
|
|
314
|
-
} =
|
|
315
|
-
|
|
311
|
+
sendControlEvent: _,
|
|
312
|
+
uploadId: s = crypto.randomUUID(),
|
|
313
|
+
uploadKind: u = "media"
|
|
314
|
+
} = n, l = e.byteLength, p = l === 0 ? 0 : Math.ceil(l / x);
|
|
315
|
+
_("client_media_upload_start", {
|
|
316
316
|
data: {
|
|
317
|
-
upload_id:
|
|
317
|
+
upload_id: s,
|
|
318
318
|
call_id: o,
|
|
319
319
|
reason: a,
|
|
320
320
|
message: r,
|
|
321
321
|
filename: t,
|
|
322
|
-
content_type:
|
|
323
|
-
size:
|
|
324
|
-
chunk_count:
|
|
325
|
-
upload_kind:
|
|
322
|
+
content_type: i,
|
|
323
|
+
size: l,
|
|
324
|
+
chunk_count: p,
|
|
325
|
+
upload_kind: u
|
|
326
326
|
}
|
|
327
327
|
});
|
|
328
328
|
const m = new Uint8Array(e);
|
|
329
|
-
for (let f = 0; f <
|
|
329
|
+
for (let f = 0; f < l; f += x) {
|
|
330
330
|
await H(h);
|
|
331
|
-
const w = Math.min(f + x,
|
|
331
|
+
const w = Math.min(f + x, l);
|
|
332
332
|
h.send(m.subarray(f, w));
|
|
333
333
|
}
|
|
334
|
-
return await H(h),
|
|
334
|
+
return await H(h), _("client_media_upload_complete", {
|
|
335
335
|
data: {
|
|
336
|
-
upload_id:
|
|
336
|
+
upload_id: s,
|
|
337
337
|
call_id: o,
|
|
338
338
|
reason: a,
|
|
339
339
|
message: r,
|
|
340
|
-
chunk_count:
|
|
341
|
-
upload_kind:
|
|
340
|
+
chunk_count: p,
|
|
341
|
+
upload_kind: u
|
|
342
342
|
}
|
|
343
|
-
}), { media_id:
|
|
343
|
+
}), { media_id: s, url: "", content_type: i };
|
|
344
344
|
}
|
|
345
|
-
async function Se(
|
|
346
|
-
return typeof
|
|
345
|
+
async function Se(n) {
|
|
346
|
+
return typeof n.arrayBuffer == "function" ? n.arrayBuffer() : new Response(n).arrayBuffer();
|
|
347
347
|
}
|
|
348
348
|
const we = 15e3, R = "vanira-connect-stall-prompt";
|
|
349
349
|
let v = null;
|
|
350
|
-
function ge(
|
|
350
|
+
function ge(n = we) {
|
|
351
351
|
typeof window > "u" || (g(!1), v = setTimeout(() => {
|
|
352
352
|
v = null, ve(), window.dispatchEvent(new CustomEvent("vanira:connect-stall"));
|
|
353
|
-
},
|
|
353
|
+
}, n));
|
|
354
354
|
}
|
|
355
|
-
function g(
|
|
356
|
-
v !== null && (clearTimeout(v), v = null),
|
|
355
|
+
function g(n = !0) {
|
|
356
|
+
v !== null && (clearTimeout(v), v = null), n && P();
|
|
357
357
|
}
|
|
358
358
|
function P() {
|
|
359
|
-
var
|
|
360
|
-
typeof document > "u" || (
|
|
359
|
+
var n;
|
|
360
|
+
typeof document > "u" || (n = document.getElementById(R)) == null || n.remove();
|
|
361
361
|
}
|
|
362
362
|
function ve() {
|
|
363
|
-
var t,
|
|
363
|
+
var t, i;
|
|
364
364
|
if (typeof document > "u" || document.getElementById(R)) return;
|
|
365
|
-
const
|
|
366
|
-
|
|
365
|
+
const n = document.createElement("div");
|
|
366
|
+
n.id = R, n.setAttribute("role", "alertdialog"), n.setAttribute("aria-modal", "true"), n.setAttribute("aria-labelledby", "vanira-stall-title"), n.style.cssText = [
|
|
367
367
|
"position:fixed",
|
|
368
368
|
"inset:0",
|
|
369
369
|
"z-index:2147483646",
|
|
@@ -399,11 +399,11 @@ function ve() {
|
|
|
399
399
|
<p style="margin:12px 0 0;font-size:12px;color:#888">
|
|
400
400
|
Tip: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac)
|
|
401
401
|
</p>
|
|
402
|
-
`,
|
|
402
|
+
`, n.appendChild(e), document.body.appendChild(n), (t = e.querySelector("#vanira-stall-refresh")) == null || t.addEventListener("click", () => {
|
|
403
403
|
P(), window.location.reload();
|
|
404
|
-
}), (
|
|
404
|
+
}), (i = e.querySelector("#vanira-stall-dismiss")) == null || i.addEventListener("click", () => P());
|
|
405
405
|
}
|
|
406
|
-
function Ce(
|
|
406
|
+
function Ce(n) {
|
|
407
407
|
return null;
|
|
408
408
|
}
|
|
409
409
|
function C() {
|
|
@@ -411,16 +411,16 @@ function C() {
|
|
|
411
411
|
}
|
|
412
412
|
class Ie {
|
|
413
413
|
constructor(e) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
414
|
+
d(this, "active", !1);
|
|
415
|
+
d(this, "initialSent", !1);
|
|
416
|
+
d(this, "lastRoute", "");
|
|
417
|
+
d(this, "sendContext");
|
|
418
|
+
d(this, "isReady");
|
|
419
|
+
d(this, "cleanupFns", []);
|
|
420
|
+
d(this, "initialRetryTimer", null);
|
|
421
|
+
d(this, "routePollTimer", null);
|
|
422
|
+
d(this, "originalPushState", null);
|
|
423
|
+
d(this, "originalReplaceState", null);
|
|
424
424
|
this.sendContext = e.sendContext, this.isReady = e.isReady ?? (() => !0);
|
|
425
425
|
}
|
|
426
426
|
start() {
|
|
@@ -456,11 +456,11 @@ class Ie {
|
|
|
456
456
|
attachListeners() {
|
|
457
457
|
const e = (r, o = 0) => {
|
|
458
458
|
const h = () => {
|
|
459
|
-
const
|
|
460
|
-
|
|
459
|
+
const _ = C();
|
|
460
|
+
_ !== this.lastRoute && this.handleRouteChange(_, r);
|
|
461
461
|
};
|
|
462
462
|
o > 0 ? window.setTimeout(h, o) : queueMicrotask(h);
|
|
463
|
-
}, t = () => e("popstate"),
|
|
463
|
+
}, t = () => e("popstate"), i = () => e("hashchange"), a = (r) => {
|
|
464
464
|
const o = r.detail;
|
|
465
465
|
if ((o == null ? void 0 : o.initiated_by) === "agent") {
|
|
466
466
|
e("vanira_navigate_agent", 120);
|
|
@@ -468,9 +468,9 @@ class Ie {
|
|
|
468
468
|
}
|
|
469
469
|
e("vanira_navigate", 120);
|
|
470
470
|
};
|
|
471
|
-
window.addEventListener("popstate", t), window.addEventListener("hashchange",
|
|
471
|
+
window.addEventListener("popstate", t), window.addEventListener("hashchange", i), window.addEventListener("vanira:navigate", a), this.cleanupFns.push(
|
|
472
472
|
() => window.removeEventListener("popstate", t),
|
|
473
|
-
() => window.removeEventListener("hashchange",
|
|
473
|
+
() => window.removeEventListener("hashchange", i),
|
|
474
474
|
() => window.removeEventListener("vanira:navigate", a)
|
|
475
475
|
), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...r) => {
|
|
476
476
|
this.originalPushState(...r), e("pushState");
|
|
@@ -484,15 +484,15 @@ class Ie {
|
|
|
484
484
|
}
|
|
485
485
|
handleRouteChange(e, t) {
|
|
486
486
|
if (!this.active) return;
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
487
|
+
const i = this.lastRoute;
|
|
488
|
+
if (i === e) return;
|
|
489
489
|
if (this.lastRoute = e, !this.initialSent) {
|
|
490
490
|
this.scheduleInitialContextSend();
|
|
491
491
|
return;
|
|
492
492
|
}
|
|
493
|
-
!this.isReady() || Ce() || this.sendRouteContext("route_changed",
|
|
493
|
+
!this.isReady() || Ce() || this.sendRouteContext("route_changed", i, t, "user");
|
|
494
494
|
}
|
|
495
|
-
sendRouteContext(e, t,
|
|
495
|
+
sendRouteContext(e, t, i, a = "user") {
|
|
496
496
|
const r = C();
|
|
497
497
|
this.lastRoute = r;
|
|
498
498
|
const o = {
|
|
@@ -502,7 +502,7 @@ class Ie {
|
|
|
502
502
|
current_page: r,
|
|
503
503
|
user_action: e === "call_started" ? "call_started_on_page" : "user_navigated"
|
|
504
504
|
};
|
|
505
|
-
e === "call_started" ? o.message = `User started the call while viewing ${r}.` : (o.previous_route = t ?? "", o.message = `User navigated from ${t || "(unknown)"} to ${r}.`,
|
|
505
|
+
e === "call_started" ? o.message = `User started the call while viewing ${r}.` : (o.previous_route = t ?? "", o.message = `User navigated from ${t || "(unknown)"} to ${r}.`, i && (o.navigation_source = i));
|
|
506
506
|
try {
|
|
507
507
|
this.sendContext(o);
|
|
508
508
|
} catch {
|
|
@@ -511,57 +511,59 @@ class Ie {
|
|
|
511
511
|
}
|
|
512
512
|
const y = class y {
|
|
513
513
|
constructor(e) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
514
|
+
d(this, "serverUrl");
|
|
515
|
+
d(this, "agentId");
|
|
516
|
+
d(this, "callId");
|
|
517
|
+
d(this, "prospectId");
|
|
518
|
+
d(this, "apiKey");
|
|
519
|
+
d(this, "backendUrl");
|
|
520
|
+
d(this, "token");
|
|
521
|
+
d(this, "prospectName");
|
|
522
|
+
d(this, "welcomeMessage");
|
|
523
|
+
d(this, "extraDetails");
|
|
524
|
+
d(this, "onConnected");
|
|
525
|
+
d(this, "onDisconnected");
|
|
526
|
+
d(this, "onError");
|
|
527
|
+
d(this, "onTranscription");
|
|
528
|
+
d(this, "onLocalStream");
|
|
528
529
|
// @ts-ignore
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
530
|
+
d(this, "onRemoteTrack");
|
|
531
|
+
d(this, "onClientToolCall");
|
|
532
|
+
d(this, "onSessionStarted");
|
|
533
|
+
d(this, "sessionStartedEmitted", !1);
|
|
534
|
+
d(this, "pc", null);
|
|
535
|
+
d(this, "dataChannel", null);
|
|
536
|
+
d(this, "mediaBytesChannel", null);
|
|
537
|
+
d(this, "audioElement", null);
|
|
538
|
+
d(this, "localStream", null);
|
|
539
|
+
d(this, "micMuted", !1);
|
|
540
|
+
d(this, "connected", !1);
|
|
541
|
+
d(this, "appliedRemoteCandidates", /* @__PURE__ */ new Set());
|
|
542
|
+
d(this, "remoteDescSet", !1);
|
|
543
|
+
d(this, "pendingServerIce", []);
|
|
544
|
+
d(this, "icePollStop", !1);
|
|
545
|
+
d(this, "iceServers");
|
|
546
|
+
d(this, "callSessionLoaded", !1);
|
|
547
|
+
d(this, "connectGeneration", 0);
|
|
548
|
+
d(this, "runtime");
|
|
549
|
+
d(this, "sessionBehavior");
|
|
550
|
+
d(this, "routeTracker", null);
|
|
551
|
+
d(this, "_status", "idle");
|
|
552
|
+
d(this, "listeners", /* @__PURE__ */ new Map());
|
|
552
553
|
/** Live vision config — auto-starts camera on connect when scope is full_call. */
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
554
|
+
d(this, "liveVision");
|
|
555
|
+
d(this, "liveVisionAutoStarted", !1);
|
|
556
|
+
d(this, "connectStallTimeoutMs");
|
|
557
|
+
var _;
|
|
556
558
|
if (!e.agentId) throw new Error("agentId is required");
|
|
557
|
-
const t = !!(e.apiKey || e.token),
|
|
559
|
+
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), a = y.normalizeIceServers(
|
|
558
560
|
e.iceServers
|
|
559
561
|
);
|
|
560
|
-
if (!t && !
|
|
562
|
+
if (!t && !i)
|
|
561
563
|
throw new Error(
|
|
562
564
|
"apiKey or token is required — or pass serverUrl and callId from a prior POST /calls/create"
|
|
563
565
|
);
|
|
564
|
-
this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.prospectName = e.prospectName, this.extraDetails = e.extraDetails, this.backendUrl = (e.backendUrl ||
|
|
566
|
+
this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.prospectName = e.prospectName, this.welcomeMessage = ((_ = e.welcomeMessage) == null ? void 0 : _.trim()) || void 0, this.extraDetails = e.extraDetails, this.backendUrl = (e.backendUrl || ie).replace(/\/$/, ""), a.length && (this.iceServers = a), i && (this.callSessionLoaded = !0);
|
|
565
567
|
const r = typeof window < "u";
|
|
566
568
|
this.prospectId = e.prospectId;
|
|
567
569
|
const o = e.sessionBehavior === "continue";
|
|
@@ -586,28 +588,28 @@ const y = class y {
|
|
|
586
588
|
var s;
|
|
587
589
|
g(), this._status = "disconnected", (s = e.onDisconnected) == null || s.call(e), this.emit("disconnected");
|
|
588
590
|
}, this.onError = (s) => {
|
|
589
|
-
var
|
|
591
|
+
var l;
|
|
590
592
|
g(), this._status = "error";
|
|
591
593
|
const u = typeof s == "string" ? s : (s == null ? void 0 : s.message) || "Connection error";
|
|
592
|
-
(
|
|
593
|
-
}, this.onTranscription = (s, u,
|
|
594
|
-
var
|
|
595
|
-
(
|
|
594
|
+
(l = e.onError) == null || l.call(e, s), this.emit("error", u);
|
|
595
|
+
}, this.onTranscription = (s, u, l) => {
|
|
596
|
+
var p;
|
|
597
|
+
(p = e.onTranscription) == null || p.call(e, s, u), this.emit("transcription", { text: s, isFinal: u, role: l });
|
|
596
598
|
}, this.onLocalStream = e.onLocalStream || (() => {
|
|
597
599
|
}), this.onRemoteTrack = (s, u) => {
|
|
598
|
-
var
|
|
599
|
-
(
|
|
600
|
+
var l;
|
|
601
|
+
(l = e.onRemoteTrack) == null || l.call(e, s, u), this.emit("track", { track: s, stream: u });
|
|
600
602
|
}, this.onClientToolCall = (s) => {
|
|
601
|
-
var
|
|
602
|
-
(
|
|
603
|
-
const u = (s == null ? void 0 : s.data) || s,
|
|
603
|
+
var p;
|
|
604
|
+
(p = e.onClientToolCall) == null || p.call(e, s);
|
|
605
|
+
const u = (s == null ? void 0 : s.data) || s, l = {
|
|
604
606
|
name: String(u.name || u.tool_name || ""),
|
|
605
607
|
arguments: u.arguments || u.args || {},
|
|
606
608
|
tool_call_id: String(u.tool_call_id || u.call_id || ""),
|
|
607
609
|
execution_mode: u.execution_mode === "blocking" ? "blocking" : "fire_and_forget",
|
|
608
610
|
client_fields: u.client_fields || {}
|
|
609
611
|
};
|
|
610
|
-
|
|
612
|
+
l.name && l.tool_call_id && this.emit("tool_call", l);
|
|
611
613
|
}, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new Ie({
|
|
612
614
|
sendContext: (s) => this.sendContextUpdate(s),
|
|
613
615
|
isReady: () => {
|
|
@@ -648,9 +650,9 @@ const y = class y {
|
|
|
648
650
|
}
|
|
649
651
|
try {
|
|
650
652
|
this.appliedRemoteCandidates.clear(), this.remoteDescSet = !1, this.pendingServerIce = [], this.icePollStop = !1, this.stopRemoteIcePolling();
|
|
651
|
-
const
|
|
653
|
+
const i = this.getIceServers();
|
|
652
654
|
this.pc = new RTCPeerConnection({
|
|
653
|
-
iceServers:
|
|
655
|
+
iceServers: i,
|
|
654
656
|
iceTransportPolicy: "all"
|
|
655
657
|
});
|
|
656
658
|
let a;
|
|
@@ -664,77 +666,77 @@ const y = class y {
|
|
|
664
666
|
channelCount: 1
|
|
665
667
|
}
|
|
666
668
|
});
|
|
667
|
-
} catch (
|
|
668
|
-
if (
|
|
669
|
-
const
|
|
669
|
+
} catch (l) {
|
|
670
|
+
if (l.name === "NotAllowedError" || l.name === "PermissionDeniedError" || (t = l.message) != null && t.includes("Permission denied")) {
|
|
671
|
+
const p = navigator.userAgent, m = /iPad|iPhone|iPod/.test(p) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
670
672
|
let f = "Microphone access denied. Please allow microphone access in your browser settings.";
|
|
671
|
-
m && (
|
|
673
|
+
m && (p.includes("CriOS") ? f = "Microphone access blocked. Please enable it in iOS Settings > Chrome > Microphone, then reload the page." : p.includes("FxiOS") ? f = "Microphone access blocked. Please enable it in iOS Settings > Firefox > Microphone, then reload the page." : f = "Microphone access blocked. Please enable it in iOS Settings > Safari > Microphone (or tap 'aA' > Website Settings > Allow Microphone).");
|
|
672
674
|
const w = new Error(f);
|
|
673
|
-
throw w.name =
|
|
675
|
+
throw w.name = l.name, w;
|
|
674
676
|
}
|
|
675
|
-
throw
|
|
677
|
+
throw l;
|
|
676
678
|
}
|
|
677
679
|
if (this.isConnectCancelled(e)) {
|
|
678
|
-
a.getTracks().forEach((
|
|
680
|
+
a.getTracks().forEach((l) => l.stop());
|
|
679
681
|
return;
|
|
680
682
|
}
|
|
681
683
|
if (this.localStream = a, !this.pc || this.isConnectCancelled(e)) {
|
|
682
|
-
a.getTracks().forEach((
|
|
684
|
+
a.getTracks().forEach((l) => l.stop());
|
|
683
685
|
return;
|
|
684
686
|
}
|
|
685
|
-
if (this.onLocalStream(a), a.getTracks().forEach((
|
|
686
|
-
var
|
|
687
|
-
(
|
|
687
|
+
if (this.onLocalStream(a), a.getTracks().forEach((l) => {
|
|
688
|
+
var p;
|
|
689
|
+
(p = this.pc) == null || p.addTrack(l, a);
|
|
688
690
|
}), !this.pc)
|
|
689
691
|
throw new Error("RTCPeerConnection was closed unexpectedly");
|
|
690
692
|
this.dataChannel = this.pc.createDataChannel("control"), this.dataChannel.onopen = () => {
|
|
691
|
-
var
|
|
692
|
-
(
|
|
693
|
-
}, this.dataChannel.onmessage = (
|
|
694
|
-
if (typeof
|
|
693
|
+
var l;
|
|
694
|
+
(l = this.routeTracker) == null || l.onChannelReady();
|
|
695
|
+
}, this.dataChannel.onmessage = (l) => {
|
|
696
|
+
if (typeof l.data == "string")
|
|
695
697
|
try {
|
|
696
|
-
this.handleControlEvent(JSON.parse(
|
|
698
|
+
this.handleControlEvent(JSON.parse(l.data));
|
|
697
699
|
} catch {
|
|
698
700
|
}
|
|
699
|
-
else if (
|
|
701
|
+
else if (l.data instanceof ArrayBuffer)
|
|
700
702
|
try {
|
|
701
|
-
const
|
|
703
|
+
const p = new TextDecoder().decode(l.data);
|
|
702
704
|
try {
|
|
703
|
-
const m = JSON.parse(
|
|
705
|
+
const m = JSON.parse(p);
|
|
704
706
|
pe(m) && this.handleControlEvent(m);
|
|
705
707
|
} catch {
|
|
706
708
|
}
|
|
707
709
|
} catch {
|
|
708
710
|
}
|
|
709
|
-
else
|
|
711
|
+
else l.data instanceof Blob && l.data.text().then((p) => {
|
|
710
712
|
try {
|
|
711
|
-
this.handleControlEvent(JSON.parse(
|
|
713
|
+
this.handleControlEvent(JSON.parse(p));
|
|
712
714
|
} catch {
|
|
713
715
|
}
|
|
714
716
|
});
|
|
715
|
-
}, this.dataChannel.onerror = (
|
|
717
|
+
}, this.dataChannel.onerror = (l) => {
|
|
716
718
|
}, this.mediaBytesChannel = this.pc.createDataChannel("media-bytes", { ordered: !0 }), this.mediaBytesChannel.binaryType = "arraybuffer", this.mediaBytesChannel.onopen = () => {
|
|
717
|
-
}, this.mediaBytesChannel.onerror = (
|
|
718
|
-
}, this.pc.ontrack = (
|
|
719
|
-
const
|
|
720
|
-
|
|
719
|
+
}, this.mediaBytesChannel.onerror = (l) => {
|
|
720
|
+
}, this.pc.ontrack = (l) => {
|
|
721
|
+
const p = l.track, m = l.streams[0];
|
|
722
|
+
p.kind === "audio" ? (this.audioElement = new Audio(), this.audioElement.srcObject = m, this.audioElement.play().catch((f) => {
|
|
721
723
|
}), this.audioElement.onended = () => {
|
|
722
724
|
this.sendEvent("playedStream"), typeof window < "u" && window.dispatchEvent(new CustomEvent("vanira:agent-playback-ended"));
|
|
723
|
-
}, this.onRemoteTrack(
|
|
725
|
+
}, this.onRemoteTrack(p, m)) : p.kind === "video" && this.onRemoteTrack(p, m);
|
|
724
726
|
};
|
|
725
727
|
const r = () => {
|
|
726
|
-
var m, f, w, U,
|
|
727
|
-
const
|
|
728
|
-
((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(),
|
|
728
|
+
var m, f, w, U, M, L, D, O, N, V, B;
|
|
729
|
+
const l = ((m = this.pc) == null ? void 0 : m.connectionState) === "connected" || ((f = this.pc) == null ? void 0 : f.iceConnectionState) === "connected" || ((w = this.pc) == null ? void 0 : w.iceConnectionState) === "completed", p = ((U = this.pc) == null ? void 0 : U.connectionState) === "failed" || ((M = this.pc) == null ? void 0 : M.iceConnectionState) === "failed" || ((L = this.pc) == null ? void 0 : L.connectionState) === "closed" || ((D = this.pc) == null ? void 0 : D.iceConnectionState) === "closed" || ((O = this.pc) == null ? void 0 : O.connectionState) === "disconnected" || ((N = this.pc) == null ? void 0 : N.iceConnectionState) === "disconnected";
|
|
730
|
+
((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (B = this.routeTracker) == null || B.start(), this.onConnected()) : p && this.connected && (this.connected = !1, this.liveVisionAutoStarted = !1, this.onDisconnected());
|
|
729
731
|
};
|
|
730
732
|
this.pc.onconnectionstatechange = r, this.pc.oniceconnectionstatechange = r;
|
|
731
733
|
const o = this.getIceTrickleUrl();
|
|
732
|
-
this.pc.onicecandidate = (
|
|
733
|
-
|
|
734
|
+
this.pc.onicecandidate = (l) => {
|
|
735
|
+
l.candidate && this.sendRemoteIceCandidate(l.candidate, o);
|
|
734
736
|
};
|
|
735
737
|
const h = await this.pc.createOffer();
|
|
736
738
|
if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(h), this.isConnectCancelled(e))) return;
|
|
737
|
-
const
|
|
739
|
+
const _ = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`, s = await fetch(_, {
|
|
738
740
|
method: "POST",
|
|
739
741
|
headers: { "Content-Type": "application/json" },
|
|
740
742
|
body: JSON.stringify({
|
|
@@ -744,32 +746,32 @@ const y = class y {
|
|
|
744
746
|
})
|
|
745
747
|
});
|
|
746
748
|
if (this.isConnectCancelled(e)) return;
|
|
747
|
-
if (!
|
|
748
|
-
const
|
|
749
|
-
throw new Error(
|
|
749
|
+
if (!s.ok) {
|
|
750
|
+
const l = await s.json();
|
|
751
|
+
throw new Error(l.error || `HTTP ${s.status}`);
|
|
750
752
|
}
|
|
751
|
-
const { answer:
|
|
752
|
-
if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(
|
|
753
|
+
const { answer: u } = await s.json();
|
|
754
|
+
if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(u), this.isConnectCancelled(e)) || (this.remoteDescSet = !0, await this.flushPendingServerIce(), this.isConnectCancelled(e))) return;
|
|
753
755
|
this.startRemoteIcePolling(o);
|
|
754
|
-
} catch (
|
|
756
|
+
} catch (i) {
|
|
755
757
|
if (this.isConnectCancelled(e)) return;
|
|
756
|
-
throw this.disconnect(), this.onError(
|
|
758
|
+
throw this.disconnect(), this.onError(i.message || i), i;
|
|
757
759
|
}
|
|
758
760
|
}
|
|
759
761
|
}
|
|
760
762
|
createCallCacheKey(e, t) {
|
|
761
|
-
const
|
|
763
|
+
const i = this.apiKey ? `key:${this.apiKey.slice(0, 16)}` : `token:${(this.token || "").slice(-16)}`;
|
|
762
764
|
return [
|
|
763
765
|
this.backendUrl,
|
|
764
766
|
this.agentId,
|
|
765
767
|
e,
|
|
766
768
|
t || "",
|
|
767
769
|
this.prospectId || "",
|
|
768
|
-
|
|
770
|
+
i
|
|
769
771
|
].join("|");
|
|
770
772
|
}
|
|
771
|
-
async postCreateCall(e, t,
|
|
772
|
-
var h,
|
|
773
|
+
async postCreateCall(e, t, i) {
|
|
774
|
+
var h, _, s;
|
|
773
775
|
const a = await fetch(`${this.backendUrl}/calls/create`, {
|
|
774
776
|
method: "POST",
|
|
775
777
|
headers: e,
|
|
@@ -777,16 +779,17 @@ const y = class y {
|
|
|
777
779
|
agent_id: this.agentId,
|
|
778
780
|
type: ((h = this.runtime) == null ? void 0 : h.callType) || "web",
|
|
779
781
|
mode: t,
|
|
780
|
-
...(
|
|
782
|
+
...(_ = this.runtime) != null && _.runtimeName ? { runtime: this.runtime.runtimeName } : {},
|
|
781
783
|
prospect_id: this.prospectId,
|
|
782
784
|
...this.prospectName ? { prospect_name: this.prospectName } : {},
|
|
785
|
+
...this.welcomeMessage ? { welcome_message: this.welcomeMessage } : {},
|
|
783
786
|
...this.extraDetails && Object.keys(this.extraDetails).length ? { extra_details: this.extraDetails } : {},
|
|
784
|
-
...
|
|
787
|
+
...i ? { call_id: i } : {}
|
|
785
788
|
})
|
|
786
789
|
});
|
|
787
790
|
if (!a.ok) {
|
|
788
|
-
const
|
|
789
|
-
throw new Error(`[VaniraClient] createCall failed (${a.status}): ${((
|
|
791
|
+
const u = await a.json().catch(() => ({}));
|
|
792
|
+
throw new Error(`[VaniraClient] createCall failed (${a.status}): ${((s = u == null ? void 0 : u.detail) == null ? void 0 : s.message) || (u == null ? void 0 : u.message) || a.statusText}`);
|
|
790
793
|
}
|
|
791
794
|
const r = await a.json();
|
|
792
795
|
if (!r.call_id || !r.worker_url)
|
|
@@ -818,9 +821,9 @@ const y = class y {
|
|
|
818
821
|
throw new Error("[VaniraClient] apiKey or token is required to create a call session");
|
|
819
822
|
const e = { "Content-Type": "application/json" };
|
|
820
823
|
this.apiKey ? e["X-API-Key"] = this.apiKey : this.token && (e.Authorization = this.token.startsWith("Bearer ") ? this.token : `Bearer ${this.token}`);
|
|
821
|
-
const t = this.sessionBehavior === "continue" ? this.callId : void 0,
|
|
824
|
+
const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new", a = this.createCallCacheKey(i, t);
|
|
822
825
|
let r = y.inflightCreates.get(a);
|
|
823
|
-
r || (r = this.postCreateCall(e,
|
|
826
|
+
r || (r = this.postCreateCall(e, i, t), y.inflightCreates.set(a, r), r.finally(() => {
|
|
824
827
|
y.inflightCreates.get(a) === r && y.inflightCreates.delete(a);
|
|
825
828
|
}));
|
|
826
829
|
const o = await r;
|
|
@@ -834,11 +837,11 @@ const y = class y {
|
|
|
834
837
|
static normalizeIceServers(e) {
|
|
835
838
|
if (!Array.isArray(e)) return [];
|
|
836
839
|
const t = [];
|
|
837
|
-
for (const
|
|
838
|
-
const a =
|
|
840
|
+
for (const i of e) {
|
|
841
|
+
const a = i == null ? void 0 : i.urls, r = Array.isArray(a) ? a.filter(Boolean) : typeof a == "string" && a.trim() ? [a.trim()] : [];
|
|
839
842
|
if (!r.length) continue;
|
|
840
|
-
const o = { urls: r.length === 1 ? r[0] : r }, h =
|
|
841
|
-
h && (o.username = h),
|
|
843
|
+
const o = { urls: r.length === 1 ? r[0] : r }, h = i.username, _ = i.credential;
|
|
844
|
+
h && (o.username = h), _ && (o.credential = _), t.push(o);
|
|
842
845
|
}
|
|
843
846
|
return t;
|
|
844
847
|
}
|
|
@@ -865,13 +868,13 @@ const y = class y {
|
|
|
865
868
|
}
|
|
866
869
|
async sendRemoteIceCandidate(e, t) {
|
|
867
870
|
try {
|
|
868
|
-
const
|
|
871
|
+
const i = await fetch(t, {
|
|
869
872
|
method: "POST",
|
|
870
873
|
headers: { "Content-Type": "application/json" },
|
|
871
874
|
body: JSON.stringify({ candidate: e.toJSON() })
|
|
872
875
|
});
|
|
873
|
-
if (
|
|
874
|
-
const a = await
|
|
876
|
+
if (i.ok) {
|
|
877
|
+
const a = await i.json();
|
|
875
878
|
await this.applyServerIceCandidates(a.candidates);
|
|
876
879
|
}
|
|
877
880
|
} catch {
|
|
@@ -885,9 +888,9 @@ const y = class y {
|
|
|
885
888
|
return;
|
|
886
889
|
}
|
|
887
890
|
for (const t of e) {
|
|
888
|
-
const
|
|
889
|
-
if (!this.appliedRemoteCandidates.has(
|
|
890
|
-
this.appliedRemoteCandidates.add(
|
|
891
|
+
const i = JSON.stringify(t);
|
|
892
|
+
if (!this.appliedRemoteCandidates.has(i)) {
|
|
893
|
+
this.appliedRemoteCandidates.add(i);
|
|
891
894
|
try {
|
|
892
895
|
await this.pc.addIceCandidate(t);
|
|
893
896
|
} catch {
|
|
@@ -901,9 +904,9 @@ const y = class y {
|
|
|
901
904
|
const e = this.pendingServerIce;
|
|
902
905
|
this.pendingServerIce = [];
|
|
903
906
|
for (const t of e) {
|
|
904
|
-
const
|
|
905
|
-
if (!this.appliedRemoteCandidates.has(
|
|
906
|
-
this.appliedRemoteCandidates.add(
|
|
907
|
+
const i = JSON.stringify(t);
|
|
908
|
+
if (!this.appliedRemoteCandidates.has(i)) {
|
|
909
|
+
this.appliedRemoteCandidates.add(i);
|
|
907
910
|
try {
|
|
908
911
|
await this.pc.addIceCandidate(t);
|
|
909
912
|
} catch {
|
|
@@ -915,10 +918,10 @@ const y = class y {
|
|
|
915
918
|
this.icePollStop = !1, this.pollServerIce(e);
|
|
916
919
|
}
|
|
917
920
|
async pollServerIce(e) {
|
|
918
|
-
var
|
|
921
|
+
var i;
|
|
919
922
|
const t = Date.now() + 15e3;
|
|
920
923
|
for (; !this.icePollStop && Date.now() < t; ) {
|
|
921
|
-
const a = (
|
|
924
|
+
const a = (i = this.pc) == null ? void 0 : i.connectionState;
|
|
922
925
|
if (a === "connected" || a === "failed" || a === "closed") break;
|
|
923
926
|
try {
|
|
924
927
|
const r = await fetch(e, { method: "GET" });
|
|
@@ -938,16 +941,16 @@ const y = class y {
|
|
|
938
941
|
* Send control event via DataChannel
|
|
939
942
|
*/
|
|
940
943
|
sendEvent(e, t = {}) {
|
|
941
|
-
var
|
|
942
|
-
if (((
|
|
944
|
+
var i;
|
|
945
|
+
if (((i = this.dataChannel) == null ? void 0 : i.readyState) === "open") {
|
|
943
946
|
const a = { event: e, ...t };
|
|
944
947
|
this.dataChannel.send(JSON.stringify(a));
|
|
945
948
|
}
|
|
946
949
|
}
|
|
947
950
|
/** Wait for control DataChannel, then send (live vision lifecycle events). */
|
|
948
|
-
async sendEventWhenReady(e, t = {},
|
|
951
|
+
async sendEventWhenReady(e, t = {}, i = 1e4) {
|
|
949
952
|
var r;
|
|
950
|
-
const a = Date.now() +
|
|
953
|
+
const a = Date.now() + i;
|
|
951
954
|
for (; Date.now() < a; ) {
|
|
952
955
|
if (((r = this.dataChannel) == null ? void 0 : r.readyState) === "open")
|
|
953
956
|
return this.sendEvent(e, t), !0;
|
|
@@ -999,8 +1002,8 @@ const y = class y {
|
|
|
999
1002
|
break;
|
|
1000
1003
|
case "transcription":
|
|
1001
1004
|
{
|
|
1002
|
-
const
|
|
1003
|
-
e.role ?? e.speaker ??
|
|
1005
|
+
const i = e.data && typeof e.data == "object" ? e.data : {}, a = String(e.text ?? i.text ?? "").trim(), r = e.isFinal ?? e.is_final ?? i.isFinal ?? i.is_final, o = r === void 0 ? !0 : r === !0 || r === "true", h = String(
|
|
1006
|
+
e.role ?? e.speaker ?? i.role ?? i.speaker ?? ""
|
|
1004
1007
|
).trim() || void 0;
|
|
1005
1008
|
a && this.onTranscription(a, o, h);
|
|
1006
1009
|
}
|
|
@@ -1013,12 +1016,12 @@ const y = class y {
|
|
|
1013
1016
|
break;
|
|
1014
1017
|
}
|
|
1015
1018
|
case "client_tool_call": {
|
|
1016
|
-
const
|
|
1019
|
+
const i = e.tool_call || e.data || e, a = (i == null ? void 0 : i.tool_call_id) || (i == null ? void 0 : i.call_id) || e.tool_call_id || "";
|
|
1017
1020
|
a && ((t = this.dataChannel) == null ? void 0 : t.readyState) === "open" && this.dataChannel.send(JSON.stringify({
|
|
1018
1021
|
event: "client_tool_ack",
|
|
1019
1022
|
data: { tool_call_id: a }
|
|
1020
1023
|
}));
|
|
1021
|
-
const r = (
|
|
1024
|
+
const r = (i == null ? void 0 : i.arguments) || (i == null ? void 0 : i.args) || {}, o = (i == null ? void 0 : i.client_fields) || {}, h = (i == null ? void 0 : i.name) || (i == null ? void 0 : i.tool_name) || "", _ = de(o, r, h);
|
|
1022
1025
|
if (h === "end_call") {
|
|
1023
1026
|
a && this.sendToolResult(a, {
|
|
1024
1027
|
status: "client_ack_end_call",
|
|
@@ -1026,13 +1029,13 @@ const y = class y {
|
|
|
1026
1029
|
}), window.setTimeout(() => this.disconnect(), 120);
|
|
1027
1030
|
break;
|
|
1028
1031
|
}
|
|
1029
|
-
if (
|
|
1032
|
+
if (_) {
|
|
1030
1033
|
window.dispatchEvent(new CustomEvent("vanira:preset", {
|
|
1031
|
-
detail: { toolCall:
|
|
1032
|
-
})), this.onClientToolCall(
|
|
1034
|
+
detail: { toolCall: i, client: this }
|
|
1035
|
+
})), this.onClientToolCall(i);
|
|
1033
1036
|
break;
|
|
1034
1037
|
}
|
|
1035
|
-
this.onClientToolCall(
|
|
1038
|
+
this.onClientToolCall(i);
|
|
1036
1039
|
break;
|
|
1037
1040
|
}
|
|
1038
1041
|
}
|
|
@@ -1056,10 +1059,10 @@ const y = class y {
|
|
|
1056
1059
|
* Uses track.enabled (not pause) so audio resumes correctly when unmuted.
|
|
1057
1060
|
*/
|
|
1058
1061
|
setMicrophoneMuted(e) {
|
|
1059
|
-
var t,
|
|
1062
|
+
var t, i;
|
|
1060
1063
|
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((a) => {
|
|
1061
1064
|
a.enabled = !e;
|
|
1062
|
-
}), (
|
|
1065
|
+
}), (i = this.pc) == null || i.getSenders().forEach((a) => {
|
|
1063
1066
|
var r;
|
|
1064
1067
|
((r = a.track) == null ? void 0 : r.kind) === "audio" && (a.track.enabled = !e);
|
|
1065
1068
|
});
|
|
@@ -1074,9 +1077,9 @@ const y = class y {
|
|
|
1074
1077
|
return e !== this.connectGeneration;
|
|
1075
1078
|
}
|
|
1076
1079
|
/** Notify WidgetPresetRenderer to cancel in-flight board animations */
|
|
1077
|
-
dispatchBoardAbort(e, t,
|
|
1080
|
+
dispatchBoardAbort(e, t, i) {
|
|
1078
1081
|
typeof window > "u" || window.dispatchEvent(new CustomEvent("vanira:board_abort", {
|
|
1079
|
-
detail: { reason: e, toolCallId: t, presetId:
|
|
1082
|
+
detail: { reason: e, toolCallId: t, presetId: i }
|
|
1080
1083
|
}));
|
|
1081
1084
|
}
|
|
1082
1085
|
/**
|
|
@@ -1165,8 +1168,8 @@ const y = class y {
|
|
|
1165
1168
|
* @param reason Routing key for backend processing (default: 'general')
|
|
1166
1169
|
* @param message Optional user text message about the file
|
|
1167
1170
|
*/
|
|
1168
|
-
async uploadMedia(e, t = "general",
|
|
1169
|
-
return await fe(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t,
|
|
1171
|
+
async uploadMedia(e, t = "general", i = "") {
|
|
1172
|
+
return await fe(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t, i) : (me(this.dataChannel, this.mediaBytesChannel), this._uploadMediaViaHTTP(e, t, i));
|
|
1170
1173
|
}
|
|
1171
1174
|
/**
|
|
1172
1175
|
* Upload a live vision / screen frame — HTTP only for now, never sends client_media_update.
|
|
@@ -1175,45 +1178,45 @@ const y = class y {
|
|
|
1175
1178
|
* Frames require a real media_url (server rejects empty). WebRTC upload returns url="" until
|
|
1176
1179
|
* the server adds client_media_upload_ready ack — use HTTP for frame JPEGs until then.
|
|
1177
1180
|
*/
|
|
1178
|
-
async uploadMediaFrame(e, t = "camera_capture",
|
|
1179
|
-
const a =
|
|
1181
|
+
async uploadMediaFrame(e, t = "camera_capture", i) {
|
|
1182
|
+
const a = i && !(e instanceof File) ? new File([e], i, { type: e.type || "image/jpeg" }) : e, { media_id: r, url: o, contentType: h } = await this._postMediaUpload(a, t, !0);
|
|
1180
1183
|
if (!r || !o)
|
|
1181
1184
|
throw new Error("Frame upload failed: server response missing media_id or url");
|
|
1182
1185
|
return { media_id: r, url: o, content_type: h };
|
|
1183
1186
|
}
|
|
1184
1187
|
/** WebRTC media-bytes path (control start/complete + binary chunks). */
|
|
1185
|
-
async _uploadBytesViaDataChannel(e, t,
|
|
1188
|
+
async _uploadBytesViaDataChannel(e, t, i, a, r) {
|
|
1186
1189
|
if (!this.callId || !this.mediaBytesChannel)
|
|
1187
1190
|
throw new Error("Upload failed: call not ready for WebRTC media upload.");
|
|
1188
|
-
const o = r || (e instanceof File ? e.name : a === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (a === "frame" ? "image/jpeg" : "application/octet-stream"),
|
|
1191
|
+
const o = r || (e instanceof File ? e.name : a === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (a === "frame" ? "image/jpeg" : "application/octet-stream"), _ = await Se(e);
|
|
1189
1192
|
return ye({
|
|
1190
|
-
bytes:
|
|
1193
|
+
bytes: _,
|
|
1191
1194
|
filename: o,
|
|
1192
1195
|
contentType: h,
|
|
1193
1196
|
reason: t,
|
|
1194
|
-
message:
|
|
1197
|
+
message: i,
|
|
1195
1198
|
callId: this.callId,
|
|
1196
1199
|
mediaBytesChannel: this.mediaBytesChannel,
|
|
1197
|
-
sendControlEvent: (
|
|
1200
|
+
sendControlEvent: (s, u) => this.sendEvent(s, u),
|
|
1198
1201
|
uploadKind: a
|
|
1199
1202
|
});
|
|
1200
1203
|
}
|
|
1201
|
-
async _uploadMediaViaDataChannel(e, t,
|
|
1202
|
-
const a = await this._uploadBytesViaDataChannel(e, t,
|
|
1204
|
+
async _uploadMediaViaDataChannel(e, t, i) {
|
|
1205
|
+
const a = await this._uploadBytesViaDataChannel(e, t, i, "media");
|
|
1203
1206
|
return { media_id: a.media_id, url: a.url };
|
|
1204
1207
|
}
|
|
1205
1208
|
/** HTTP fallback — original uploadMedia behavior (unchanged). */
|
|
1206
|
-
async _uploadMediaViaHTTP(e, t = "general",
|
|
1209
|
+
async _uploadMediaViaHTTP(e, t = "general", i = "") {
|
|
1207
1210
|
const { media_id: a, url: r, contentType: o } = await this._postMediaUpload(e, t, !0);
|
|
1208
1211
|
return this.sendMediaUpdate({
|
|
1209
1212
|
media_id: a,
|
|
1210
1213
|
media_url: r,
|
|
1211
1214
|
content_type: o,
|
|
1212
1215
|
reason: t,
|
|
1213
|
-
message:
|
|
1216
|
+
message: i
|
|
1214
1217
|
}), { media_id: a, url: r };
|
|
1215
1218
|
}
|
|
1216
|
-
async _postMediaUpload(e, t,
|
|
1219
|
+
async _postMediaUpload(e, t, i = !1) {
|
|
1217
1220
|
if (!this.serverUrl)
|
|
1218
1221
|
throw new Error("Upload failed: serverUrl is not set. Connect the VaniraClient first.");
|
|
1219
1222
|
if (!this.callId)
|
|
@@ -1230,17 +1233,17 @@ const y = class y {
|
|
|
1230
1233
|
body: o
|
|
1231
1234
|
});
|
|
1232
1235
|
if (!h.ok) {
|
|
1233
|
-
let
|
|
1236
|
+
let p = `HTTP ${h.status}`;
|
|
1234
1237
|
try {
|
|
1235
|
-
|
|
1238
|
+
p = (await h.json()).error || p;
|
|
1236
1239
|
} catch {
|
|
1237
1240
|
}
|
|
1238
|
-
throw new Error(`Upload failed: ${
|
|
1241
|
+
throw new Error(`Upload failed: ${p}`);
|
|
1239
1242
|
}
|
|
1240
|
-
const
|
|
1241
|
-
if (!
|
|
1243
|
+
const _ = await h.json(), s = _.media_id, u = _.url, l = _.content_type || e.type;
|
|
1244
|
+
if (!s || !u)
|
|
1242
1245
|
throw new Error("Upload failed: server response missing media_id or url");
|
|
1243
|
-
return
|
|
1246
|
+
return i ? { media_id: s, url: u, contentType: l } : { media_id: s, url: u, contentType: l };
|
|
1244
1247
|
}
|
|
1245
1248
|
// ─── Event emitter (replaces retired VaniraAI) ───────────────────────────
|
|
1246
1249
|
get status() {
|
|
@@ -1253,12 +1256,12 @@ const y = class y {
|
|
|
1253
1256
|
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), this;
|
|
1254
1257
|
}
|
|
1255
1258
|
off(e, t) {
|
|
1256
|
-
var
|
|
1257
|
-
return (
|
|
1259
|
+
var i;
|
|
1260
|
+
return (i = this.listeners.get(e)) == null || i.delete(t), this;
|
|
1258
1261
|
}
|
|
1259
1262
|
emit(e, t) {
|
|
1260
|
-
var
|
|
1261
|
-
(
|
|
1263
|
+
var i;
|
|
1264
|
+
(i = this.listeners.get(e)) == null || i.forEach((a) => a(t));
|
|
1262
1265
|
}
|
|
1263
1266
|
/** Alias for connect() — VaniraAI compatibility */
|
|
1264
1267
|
async start() {
|
|
@@ -1288,7 +1291,7 @@ const y = class y {
|
|
|
1288
1291
|
}
|
|
1289
1292
|
};
|
|
1290
1293
|
/** Dedupes concurrent POST /calls/create (e.g. React StrictMode double-mount). */
|
|
1291
|
-
|
|
1294
|
+
d(y, "inflightCreates", /* @__PURE__ */ new Map());
|
|
1292
1295
|
let A = y;
|
|
1293
1296
|
const Te = {
|
|
1294
1297
|
supportsAudioEndedEvent: !1,
|
|
@@ -1309,15 +1312,15 @@ const Te = {
|
|
|
1309
1312
|
peer: new ee(),
|
|
1310
1313
|
dataChannel: new te()
|
|
1311
1314
|
};
|
|
1312
|
-
function Y(
|
|
1315
|
+
function Y(n) {
|
|
1313
1316
|
return new A({
|
|
1314
|
-
...
|
|
1317
|
+
...n,
|
|
1315
1318
|
runtime: be
|
|
1316
1319
|
});
|
|
1317
1320
|
}
|
|
1318
1321
|
const ke = Y;
|
|
1319
|
-
function xe(
|
|
1320
|
-
return Y(
|
|
1322
|
+
function xe(n) {
|
|
1323
|
+
return Y(n);
|
|
1321
1324
|
}
|
|
1322
1325
|
const Re = xe;
|
|
1323
1326
|
export {
|