@vanira/sdk 0.0.85 → 0.0.86
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 +139 -59
- package/dist/headless/index.js +9557 -8709
- package/dist/platforms/browser.cjs +6 -6
- package/dist/platforms/browser.js +216 -198
- package/dist/platforms/react-native.cjs +1 -1
- package/dist/platforms/react-native.js +309 -291
- package/dist/vanira-sdk.es.js +9519 -8671
- package/dist/vanira-sdk.js +167 -87
- package/dist/vanira-sdk.umd.js +171 -91
- package/package.json +4 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var H = Object.defineProperty;
|
|
2
2
|
var G = (a, e, t) => e in a ? H(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
-
var
|
|
3
|
+
var d = (a, e, t) => G(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
class z {
|
|
5
5
|
pause() {
|
|
6
6
|
}
|
|
@@ -41,8 +41,8 @@ class Z {
|
|
|
41
41
|
}
|
|
42
42
|
if (i.data instanceof ArrayBuffer) {
|
|
43
43
|
try {
|
|
44
|
-
const n = new TextDecoder().decode(i.data),
|
|
45
|
-
(
|
|
44
|
+
const n = new TextDecoder().decode(i.data), r = JSON.parse(n);
|
|
45
|
+
(r == null ? void 0 : r.event) === "client_tool_call" && t.onMessage({ text: n });
|
|
46
46
|
} catch {
|
|
47
47
|
}
|
|
48
48
|
return;
|
|
@@ -60,7 +60,7 @@ class Z {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const Q = "https://api.vanira.io",
|
|
63
|
+
const Q = "https://api.vanira.io", c = {
|
|
64
64
|
Form: "vanira_form",
|
|
65
65
|
Calendar: "vanira_calendar",
|
|
66
66
|
Navigate: "vanira_navigate",
|
|
@@ -82,8 +82,11 @@ const Q = "https://api.vanira.io", u = {
|
|
|
82
82
|
PointAt: "vanira_point_at",
|
|
83
83
|
DrawOnScreen: "vanira_draw_on_screen",
|
|
84
84
|
ClearScreenDraw: "vanira_clear_screen_draw",
|
|
85
|
-
HighlightOnScreen: "vanira_highlight_on_screen"
|
|
86
|
-
|
|
85
|
+
HighlightOnScreen: "vanira_highlight_on_screen",
|
|
86
|
+
KycDocumentCapture: "vanira_kyc_document_capture",
|
|
87
|
+
KycSelfieCapture: "vanira_kyc_selfie_capture",
|
|
88
|
+
KycSignatureCapture: "vanira_kyc_signature_capture"
|
|
89
|
+
}, F = Object.values(c), ee = new Set(F);
|
|
87
90
|
function V(a) {
|
|
88
91
|
return !!a && ee.has(a);
|
|
89
92
|
}
|
|
@@ -97,45 +100,60 @@ function j(a) {
|
|
|
97
100
|
return a && typeof a == "object" ? a : {};
|
|
98
101
|
}
|
|
99
102
|
const N = {
|
|
100
|
-
type_on_whiteboard:
|
|
101
|
-
write_on_whiteboard:
|
|
102
|
-
write_on_white_board:
|
|
103
|
-
dom_typing_simulation:
|
|
104
|
-
write_latex_text:
|
|
105
|
-
write_latex_on_board:
|
|
106
|
-
latex_on_whiteboard:
|
|
107
|
-
erase_text:
|
|
108
|
-
dom_erase:
|
|
109
|
-
open_live_camera:
|
|
110
|
-
live_vision:
|
|
111
|
-
close_live_camera:
|
|
112
|
-
stop_live_camera:
|
|
113
|
-
open_live_screen:
|
|
114
|
-
close_live_screen:
|
|
115
|
-
screen_vision:
|
|
116
|
-
capture_screen_vision:
|
|
117
|
-
capture_screen:
|
|
118
|
-
tab_screenshot:
|
|
119
|
-
capture_tab:
|
|
120
|
-
capture_tab_screenshot:
|
|
121
|
-
screenshot_tab:
|
|
122
|
-
point_at:
|
|
123
|
-
point_at_screen:
|
|
124
|
-
draw_on_screen:
|
|
125
|
-
screen_draw:
|
|
126
|
-
clear_screen_draw:
|
|
127
|
-
clear_screen_annotations:
|
|
128
|
-
highlight_on_screen:
|
|
129
|
-
highlight_element_on_screen:
|
|
130
|
-
highlight_screen_element:
|
|
131
|
-
|
|
132
|
-
|
|
103
|
+
type_on_whiteboard: c.TypeText,
|
|
104
|
+
write_on_whiteboard: c.TypeText,
|
|
105
|
+
write_on_white_board: c.TypeText,
|
|
106
|
+
dom_typing_simulation: c.TypeText,
|
|
107
|
+
write_latex_text: c.WriteLatexText,
|
|
108
|
+
write_latex_on_board: c.WriteLatexText,
|
|
109
|
+
latex_on_whiteboard: c.WriteLatexText,
|
|
110
|
+
erase_text: c.EraseText,
|
|
111
|
+
dom_erase: c.EraseText,
|
|
112
|
+
open_live_camera: c.LiveVision,
|
|
113
|
+
live_vision: c.LiveVision,
|
|
114
|
+
close_live_camera: c.CloseLiveCamera,
|
|
115
|
+
stop_live_camera: c.CloseLiveCamera,
|
|
116
|
+
open_live_screen: c.LiveScreen,
|
|
117
|
+
close_live_screen: c.CloseLiveScreen,
|
|
118
|
+
screen_vision: c.ScreenVision,
|
|
119
|
+
capture_screen_vision: c.ScreenVision,
|
|
120
|
+
capture_screen: c.ScreenVision,
|
|
121
|
+
tab_screenshot: c.ScreenVision,
|
|
122
|
+
capture_tab: c.ScreenVision,
|
|
123
|
+
capture_tab_screenshot: c.ScreenVision,
|
|
124
|
+
screenshot_tab: c.ScreenVision,
|
|
125
|
+
point_at: c.PointAt,
|
|
126
|
+
point_at_screen: c.PointAt,
|
|
127
|
+
draw_on_screen: c.DrawOnScreen,
|
|
128
|
+
screen_draw: c.DrawOnScreen,
|
|
129
|
+
clear_screen_draw: c.ClearScreenDraw,
|
|
130
|
+
clear_screen_annotations: c.ClearScreenDraw,
|
|
131
|
+
highlight_on_screen: c.HighlightOnScreen,
|
|
132
|
+
highlight_element_on_screen: c.HighlightOnScreen,
|
|
133
|
+
highlight_screen_element: c.HighlightOnScreen,
|
|
134
|
+
kyc_document_capture: c.KycDocumentCapture,
|
|
135
|
+
capture_id_document: c.KycDocumentCapture,
|
|
136
|
+
document_capture: c.KycDocumentCapture,
|
|
137
|
+
capture_kyc_document: c.KycDocumentCapture,
|
|
138
|
+
kyc_selfie_capture: c.KycSelfieCapture,
|
|
139
|
+
capture_selfie: c.KycSelfieCapture,
|
|
140
|
+
selfie_capture: c.KycSelfieCapture,
|
|
141
|
+
capture_kyc_selfie: c.KycSelfieCapture,
|
|
142
|
+
kyc_signature_capture: c.KycSignatureCapture,
|
|
143
|
+
capture_kyc_signature: c.KycSignatureCapture,
|
|
144
|
+
signature_capture: c.KycSignatureCapture
|
|
145
|
+
}, D = {
|
|
146
|
+
vanira_tab_screenshot: c.ScreenVision,
|
|
147
|
+
vanira_document_capture: c.KycDocumentCapture,
|
|
148
|
+
vanira_selfie_capture: c.KycSelfieCapture,
|
|
149
|
+
vanira_signature_capture: c.KycSignatureCapture,
|
|
150
|
+
vanira_kyc_signature: c.KycSignatureCapture
|
|
133
151
|
};
|
|
134
152
|
function te(a, e) {
|
|
135
153
|
const t = a.latex_text ?? (e == null ? void 0 : e.latex_text);
|
|
136
154
|
return typeof t == "string" && t.trim().length > 0;
|
|
137
155
|
}
|
|
138
|
-
function
|
|
156
|
+
function K(a, e) {
|
|
139
157
|
const t = a.text_to_type ?? (e == null ? void 0 : e.text_to_type) ?? a.text ?? (e == null ? void 0 : e.text) ?? a.value ?? (e == null ? void 0 : e.value);
|
|
140
158
|
return typeof t == "string" && t.trim().length > 0;
|
|
141
159
|
}
|
|
@@ -147,31 +165,31 @@ function ne(a, e) {
|
|
|
147
165
|
const t = a == null ? void 0 : a.preset_id;
|
|
148
166
|
if (typeof t == "string") {
|
|
149
167
|
if (V(t)) return t;
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
168
|
+
const r = D[t];
|
|
169
|
+
if (r) return r;
|
|
152
170
|
}
|
|
153
171
|
const n = j(e).preset_id;
|
|
154
172
|
if (typeof n == "string") {
|
|
155
173
|
if (V(n)) return n;
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
174
|
+
const r = D[n];
|
|
175
|
+
if (r) return r;
|
|
158
176
|
}
|
|
159
177
|
}
|
|
160
178
|
function ae(a, e, t) {
|
|
161
179
|
const i = j(e);
|
|
162
180
|
let n = ne(a, i);
|
|
163
|
-
if (n ===
|
|
164
|
-
return
|
|
181
|
+
if (n === c.Form && K(i, a) && !ie(i, a))
|
|
182
|
+
return c.TypeText;
|
|
165
183
|
if (n) return n;
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
return N[
|
|
184
|
+
const r = String(t ?? "").trim().toLowerCase();
|
|
185
|
+
if (r && N[r])
|
|
186
|
+
return N[r];
|
|
169
187
|
if (te(i, a))
|
|
170
|
-
return
|
|
171
|
-
if (
|
|
172
|
-
return
|
|
188
|
+
return c.WriteLatexText;
|
|
189
|
+
if (K(i, a))
|
|
190
|
+
return c.TypeText;
|
|
173
191
|
}
|
|
174
|
-
const g = "vanira_latest_call_id",
|
|
192
|
+
const g = "vanira_latest_call_id", k = "vanira_prospect_id";
|
|
175
193
|
function C(a) {
|
|
176
194
|
return `vanira_latest_call_id_${a}`;
|
|
177
195
|
}
|
|
@@ -181,7 +199,7 @@ function I(a) {
|
|
|
181
199
|
function W(a) {
|
|
182
200
|
return `vanira_call_meta_${a}`;
|
|
183
201
|
}
|
|
184
|
-
function
|
|
202
|
+
function w(a, e) {
|
|
185
203
|
if (!a) return null;
|
|
186
204
|
try {
|
|
187
205
|
return a.getItem(e);
|
|
@@ -189,38 +207,38 @@ function S(a, e) {
|
|
|
189
207
|
return null;
|
|
190
208
|
}
|
|
191
209
|
}
|
|
192
|
-
function
|
|
210
|
+
function B(a) {
|
|
193
211
|
if (typeof window > "u" || !a) return null;
|
|
194
|
-
const e = [], t =
|
|
212
|
+
const e = [], t = w(window.localStorage, W(a));
|
|
195
213
|
if (t)
|
|
196
214
|
try {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
callId:
|
|
200
|
-
prospectId:
|
|
201
|
-
updatedAt:
|
|
215
|
+
const h = JSON.parse(t);
|
|
216
|
+
h != null && h.callId && e.push({
|
|
217
|
+
callId: h.callId,
|
|
218
|
+
prospectId: h.prospectId,
|
|
219
|
+
updatedAt: h.updatedAt || 0
|
|
202
220
|
});
|
|
203
221
|
} catch {
|
|
204
222
|
}
|
|
205
|
-
const i = (
|
|
206
|
-
|
|
207
|
-
callId:
|
|
208
|
-
prospectId:
|
|
209
|
-
updatedAt:
|
|
223
|
+
const i = (h, s, u) => {
|
|
224
|
+
h && e.push({
|
|
225
|
+
callId: h,
|
|
226
|
+
prospectId: s || void 0,
|
|
227
|
+
updatedAt: u
|
|
210
228
|
});
|
|
211
|
-
}, n =
|
|
229
|
+
}, n = w(window.localStorage, I(a)), r = w(window.sessionStorage, I(a)), o = w(window.localStorage, k);
|
|
212
230
|
return i(
|
|
213
|
-
|
|
231
|
+
w(window.localStorage, C(a)),
|
|
214
232
|
n || o,
|
|
215
233
|
2
|
|
216
234
|
), i(
|
|
217
|
-
|
|
218
|
-
|
|
235
|
+
w(window.sessionStorage, C(a)),
|
|
236
|
+
r || o,
|
|
219
237
|
1
|
|
220
|
-
), i(
|
|
238
|
+
), i(w(window.localStorage, g), o, 0), i(w(window.sessionStorage, g), o, 0), e.length ? (e.sort((h, s) => s.updatedAt - h.updatedAt), e[0]) : null;
|
|
221
239
|
}
|
|
222
|
-
function
|
|
223
|
-
var n,
|
|
240
|
+
function re(a, e, t) {
|
|
241
|
+
var n, r, o, h, s, u, p, l, _;
|
|
224
242
|
if (typeof window > "u" || !a || !e) return;
|
|
225
243
|
const i = {
|
|
226
244
|
callId: e,
|
|
@@ -228,11 +246,11 @@ function se(a, e, t) {
|
|
|
228
246
|
updatedAt: Date.now()
|
|
229
247
|
};
|
|
230
248
|
try {
|
|
231
|
-
(n = window.localStorage) == null || n.setItem(W(a), JSON.stringify(i)), (
|
|
249
|
+
(n = window.localStorage) == null || n.setItem(W(a), JSON.stringify(i)), (r = window.localStorage) == null || r.setItem(C(a), e), (o = window.sessionStorage) == null || o.setItem(C(a), e), t && ((h = window.localStorage) == null || h.setItem(I(a), t), (s = window.sessionStorage) == null || s.setItem(I(a), t)), (u = window.localStorage) == null || u.setItem(g, e), (p = window.sessionStorage) == null || p.setItem(g, e), t && ((l = window.localStorage) == null || l.setItem(k, t), (_ = window.sessionStorage) == null || _.setItem(k, t));
|
|
232
250
|
} catch {
|
|
233
251
|
}
|
|
234
252
|
}
|
|
235
|
-
const
|
|
253
|
+
const se = /* @__PURE__ */ new Set([
|
|
236
254
|
"client_tool_call",
|
|
237
255
|
"clearAudio",
|
|
238
256
|
"client_tool_cancel"
|
|
@@ -240,7 +258,7 @@ const re = /* @__PURE__ */ new Set([
|
|
|
240
258
|
function oe(a) {
|
|
241
259
|
if (!a || typeof a != "object") return !1;
|
|
242
260
|
const e = a.event;
|
|
243
|
-
return typeof e == "string" &&
|
|
261
|
+
return typeof e == "string" && se.has(e);
|
|
244
262
|
}
|
|
245
263
|
const T = 16 * 1024, ce = 256 * 1024;
|
|
246
264
|
function E(a, e) {
|
|
@@ -263,7 +281,7 @@ async function de(a, e, t = 8e3) {
|
|
|
263
281
|
}
|
|
264
282
|
return E(a, e);
|
|
265
283
|
}
|
|
266
|
-
async function
|
|
284
|
+
async function $(a) {
|
|
267
285
|
for (; a.bufferedAmount > ce; )
|
|
268
286
|
await new Promise((e) => setTimeout(e, 10));
|
|
269
287
|
}
|
|
@@ -273,42 +291,42 @@ async function he(a) {
|
|
|
273
291
|
filename: t,
|
|
274
292
|
contentType: i,
|
|
275
293
|
reason: n,
|
|
276
|
-
message:
|
|
294
|
+
message: r,
|
|
277
295
|
callId: o,
|
|
278
|
-
mediaBytesChannel:
|
|
279
|
-
sendControlEvent:
|
|
280
|
-
uploadId:
|
|
296
|
+
mediaBytesChannel: h,
|
|
297
|
+
sendControlEvent: s,
|
|
298
|
+
uploadId: u = crypto.randomUUID(),
|
|
281
299
|
uploadKind: p = "media"
|
|
282
|
-
} = a,
|
|
283
|
-
|
|
300
|
+
} = a, l = e.byteLength, _ = l === 0 ? 0 : Math.ceil(l / T);
|
|
301
|
+
s("client_media_upload_start", {
|
|
284
302
|
data: {
|
|
285
|
-
upload_id:
|
|
303
|
+
upload_id: u,
|
|
286
304
|
call_id: o,
|
|
287
305
|
reason: n,
|
|
288
|
-
message:
|
|
306
|
+
message: r,
|
|
289
307
|
filename: t,
|
|
290
308
|
content_type: i,
|
|
291
|
-
size:
|
|
309
|
+
size: l,
|
|
292
310
|
chunk_count: _,
|
|
293
311
|
upload_kind: p
|
|
294
312
|
}
|
|
295
313
|
});
|
|
296
314
|
const m = new Uint8Array(e);
|
|
297
|
-
for (let f = 0; f <
|
|
298
|
-
await
|
|
299
|
-
const
|
|
300
|
-
|
|
315
|
+
for (let f = 0; f < l; f += T) {
|
|
316
|
+
await $(h);
|
|
317
|
+
const S = Math.min(f + T, l);
|
|
318
|
+
h.send(m.subarray(f, S));
|
|
301
319
|
}
|
|
302
|
-
return await
|
|
320
|
+
return await $(h), s("client_media_upload_complete", {
|
|
303
321
|
data: {
|
|
304
|
-
upload_id:
|
|
322
|
+
upload_id: u,
|
|
305
323
|
call_id: o,
|
|
306
324
|
reason: n,
|
|
307
|
-
message:
|
|
325
|
+
message: r,
|
|
308
326
|
chunk_count: _,
|
|
309
327
|
upload_kind: p
|
|
310
328
|
}
|
|
311
|
-
}), { media_id:
|
|
329
|
+
}), { media_id: u, url: "", content_type: i };
|
|
312
330
|
}
|
|
313
331
|
async function ue(a) {
|
|
314
332
|
return typeof a.arrayBuffer == "function" ? a.arrayBuffer() : new Response(a).arrayBuffer();
|
|
@@ -316,25 +334,25 @@ async function ue(a) {
|
|
|
316
334
|
function pe(a) {
|
|
317
335
|
return null;
|
|
318
336
|
}
|
|
319
|
-
function
|
|
337
|
+
function v() {
|
|
320
338
|
return typeof window > "u" ? "/" : `${window.location.pathname}${window.location.search}${window.location.hash}` || "/";
|
|
321
339
|
}
|
|
322
340
|
class _e {
|
|
323
341
|
constructor(e) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
342
|
+
d(this, "active", !1);
|
|
343
|
+
d(this, "initialSent", !1);
|
|
344
|
+
d(this, "lastRoute", "");
|
|
345
|
+
d(this, "sendContext");
|
|
346
|
+
d(this, "isReady");
|
|
347
|
+
d(this, "cleanupFns", []);
|
|
348
|
+
d(this, "initialRetryTimer", null);
|
|
349
|
+
d(this, "routePollTimer", null);
|
|
350
|
+
d(this, "originalPushState", null);
|
|
351
|
+
d(this, "originalReplaceState", null);
|
|
334
352
|
this.sendContext = e.sendContext, this.isReady = e.isReady ?? (() => !0);
|
|
335
353
|
}
|
|
336
354
|
start() {
|
|
337
|
-
typeof window > "u" || this.active || (this.active = !0, this.initialSent = !1, this.lastRoute =
|
|
355
|
+
typeof window > "u" || this.active || (this.active = !0, this.initialSent = !1, this.lastRoute = v(), this.attachListeners(), this.scheduleInitialContextSend());
|
|
338
356
|
}
|
|
339
357
|
stop() {
|
|
340
358
|
if (!(!this.active && this.cleanupFns.length === 0)) {
|
|
@@ -364,14 +382,14 @@ class _e {
|
|
|
364
382
|
}
|
|
365
383
|
}
|
|
366
384
|
attachListeners() {
|
|
367
|
-
const e = (
|
|
368
|
-
const
|
|
369
|
-
const
|
|
370
|
-
|
|
385
|
+
const e = (r, o = 0) => {
|
|
386
|
+
const h = () => {
|
|
387
|
+
const s = v();
|
|
388
|
+
s !== this.lastRoute && this.handleRouteChange(s, r);
|
|
371
389
|
};
|
|
372
|
-
o > 0 ? window.setTimeout(
|
|
373
|
-
}, t = () => e("popstate"), i = () => e("hashchange"), n = (
|
|
374
|
-
const o =
|
|
390
|
+
o > 0 ? window.setTimeout(h, o) : queueMicrotask(h);
|
|
391
|
+
}, t = () => e("popstate"), i = () => e("hashchange"), n = (r) => {
|
|
392
|
+
const o = r.detail;
|
|
375
393
|
if ((o == null ? void 0 : o.initiated_by) === "agent") {
|
|
376
394
|
e("vanira_navigate_agent", 120);
|
|
377
395
|
return;
|
|
@@ -382,14 +400,14 @@ class _e {
|
|
|
382
400
|
() => window.removeEventListener("popstate", t),
|
|
383
401
|
() => window.removeEventListener("hashchange", i),
|
|
384
402
|
() => window.removeEventListener("vanira:navigate", n)
|
|
385
|
-
), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...
|
|
386
|
-
this.originalPushState(...
|
|
387
|
-
}, history.replaceState = (...
|
|
388
|
-
this.originalReplaceState(...
|
|
403
|
+
), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...r) => {
|
|
404
|
+
this.originalPushState(...r), e("pushState");
|
|
405
|
+
}, history.replaceState = (...r) => {
|
|
406
|
+
this.originalReplaceState(...r), e("replaceState");
|
|
389
407
|
}, this.routePollTimer = window.setInterval(() => {
|
|
390
408
|
if (!this.active) return;
|
|
391
|
-
const
|
|
392
|
-
|
|
409
|
+
const r = v();
|
|
410
|
+
r !== this.lastRoute && this.handleRouteChange(r, "location_poll");
|
|
393
411
|
}, 1e3);
|
|
394
412
|
}
|
|
395
413
|
handleRouteChange(e, t) {
|
|
@@ -403,63 +421,63 @@ class _e {
|
|
|
403
421
|
!this.isReady() || pe() || this.sendRouteContext("route_changed", i, t, "user");
|
|
404
422
|
}
|
|
405
423
|
sendRouteContext(e, t, i, n = "user") {
|
|
406
|
-
const
|
|
407
|
-
this.lastRoute =
|
|
424
|
+
const r = v();
|
|
425
|
+
this.lastRoute = r;
|
|
408
426
|
const o = {
|
|
409
427
|
ui_state: "page_navigation",
|
|
410
428
|
navigation_led_by: n,
|
|
411
|
-
current_route:
|
|
412
|
-
current_page:
|
|
429
|
+
current_route: r,
|
|
430
|
+
current_page: r,
|
|
413
431
|
user_action: e === "call_started" ? "call_started_on_page" : "user_navigated"
|
|
414
432
|
};
|
|
415
|
-
e === "call_started" ? o.message = `User started the call while viewing ${
|
|
433
|
+
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));
|
|
416
434
|
try {
|
|
417
435
|
this.sendContext(o);
|
|
418
436
|
} catch {
|
|
419
437
|
}
|
|
420
438
|
}
|
|
421
439
|
}
|
|
422
|
-
const
|
|
440
|
+
const y = class y {
|
|
423
441
|
constructor(e) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
442
|
+
d(this, "serverUrl");
|
|
443
|
+
d(this, "agentId");
|
|
444
|
+
d(this, "callId");
|
|
445
|
+
d(this, "prospectId");
|
|
446
|
+
d(this, "apiKey");
|
|
447
|
+
d(this, "backendUrl");
|
|
448
|
+
d(this, "token");
|
|
449
|
+
d(this, "onConnected");
|
|
450
|
+
d(this, "onDisconnected");
|
|
451
|
+
d(this, "onError");
|
|
452
|
+
d(this, "onTranscription");
|
|
453
|
+
d(this, "onLocalStream");
|
|
436
454
|
// @ts-ignore
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
d(this, "onRemoteTrack");
|
|
456
|
+
d(this, "onClientToolCall");
|
|
457
|
+
d(this, "onSessionStarted");
|
|
458
|
+
d(this, "sessionStartedEmitted", !1);
|
|
459
|
+
d(this, "pc", null);
|
|
460
|
+
d(this, "dataChannel", null);
|
|
461
|
+
d(this, "mediaBytesChannel", null);
|
|
462
|
+
d(this, "audioElement", null);
|
|
463
|
+
d(this, "localStream", null);
|
|
464
|
+
d(this, "micMuted", !1);
|
|
465
|
+
d(this, "connected", !1);
|
|
466
|
+
d(this, "icePollInterval", null);
|
|
467
|
+
d(this, "appliedRemoteCandidates", /* @__PURE__ */ new Set());
|
|
468
|
+
d(this, "iceServers");
|
|
469
|
+
d(this, "callSessionLoaded", !1);
|
|
470
|
+
d(this, "connectGeneration", 0);
|
|
471
|
+
d(this, "runtime");
|
|
472
|
+
d(this, "sessionBehavior");
|
|
473
|
+
d(this, "routeTracker", null);
|
|
474
|
+
d(this, "_status", "idle");
|
|
475
|
+
d(this, "listeners", /* @__PURE__ */ new Map());
|
|
458
476
|
/** Live vision config — auto-starts camera on connect when scope is full_call. */
|
|
459
|
-
|
|
460
|
-
|
|
477
|
+
d(this, "liveVision");
|
|
478
|
+
d(this, "liveVisionAutoStarted", !1);
|
|
461
479
|
if (!e.agentId) throw new Error("agentId is required");
|
|
462
|
-
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), n =
|
|
480
|
+
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), n = y.normalizeIceServers(
|
|
463
481
|
e.iceServers
|
|
464
482
|
);
|
|
465
483
|
if (!t && !i)
|
|
@@ -467,57 +485,57 @@ const w = class w {
|
|
|
467
485
|
"apiKey or token is required — or pass serverUrl and callId from a prior POST /calls/create"
|
|
468
486
|
);
|
|
469
487
|
this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.backendUrl = (e.backendUrl || Q).replace(/\/$/, ""), n.length && (this.iceServers = n), i && (this.callSessionLoaded = !0);
|
|
470
|
-
const
|
|
488
|
+
const r = typeof window < "u";
|
|
471
489
|
this.prospectId = e.prospectId;
|
|
472
490
|
const o = e.sessionBehavior === "continue";
|
|
473
|
-
if (o &&
|
|
474
|
-
const
|
|
475
|
-
|
|
491
|
+
if (o && r && !e.callId) {
|
|
492
|
+
const s = B(this.agentId);
|
|
493
|
+
s && (e.callId || (this.callId = s.callId), !this.prospectId && s.prospectId && (this.prospectId = s.prospectId));
|
|
476
494
|
}
|
|
477
|
-
if (!this.prospectId &&
|
|
495
|
+
if (!this.prospectId && r)
|
|
478
496
|
try {
|
|
479
|
-
const
|
|
480
|
-
this.prospectId = (
|
|
497
|
+
const s = B(this.agentId);
|
|
498
|
+
this.prospectId = (s == null ? void 0 : s.prospectId) || window.sessionStorage && window.sessionStorage.getItem("vanira_prospect_id") || window.localStorage && window.localStorage.getItem("vanira_prospect_id") || void 0;
|
|
481
499
|
} catch {
|
|
482
500
|
}
|
|
483
501
|
e.callId ? this.callId = e.callId : o || (this.callId = void 0);
|
|
484
|
-
const
|
|
485
|
-
this.onSessionStarted = (
|
|
486
|
-
|
|
502
|
+
const h = e.onSessionStarted;
|
|
503
|
+
this.onSessionStarted = (s) => {
|
|
504
|
+
h == null || h(s), this.emit("session_started", s);
|
|
487
505
|
}, this.liveVision = e.liveVision, this.onConnected = () => {
|
|
488
|
-
var
|
|
489
|
-
this._status = "connected", (
|
|
506
|
+
var s;
|
|
507
|
+
this._status = "connected", (s = e.onConnected) == null || s.call(e), this.emit("connected"), this.maybeAutoStartLiveCamera();
|
|
490
508
|
}, this.onDisconnected = () => {
|
|
491
|
-
var
|
|
492
|
-
this._status = "disconnected", (
|
|
493
|
-
}, this.onError = (
|
|
509
|
+
var s;
|
|
510
|
+
this._status = "disconnected", (s = e.onDisconnected) == null || s.call(e), this.emit("disconnected");
|
|
511
|
+
}, this.onError = (s) => {
|
|
494
512
|
var p;
|
|
495
513
|
this._status = "error";
|
|
496
|
-
const
|
|
497
|
-
(p = e.onError) == null || p.call(e,
|
|
498
|
-
}, this.onTranscription = (
|
|
514
|
+
const u = typeof s == "string" ? s : (s == null ? void 0 : s.message) || "Connection error";
|
|
515
|
+
(p = e.onError) == null || p.call(e, s), this.emit("error", u);
|
|
516
|
+
}, this.onTranscription = (s, u) => {
|
|
499
517
|
var p;
|
|
500
|
-
(p = e.onTranscription) == null || p.call(e,
|
|
518
|
+
(p = e.onTranscription) == null || p.call(e, s, u), this.emit("transcription", { text: s, isFinal: u });
|
|
501
519
|
}, this.onLocalStream = e.onLocalStream || (() => {
|
|
502
|
-
}), this.onRemoteTrack = (
|
|
520
|
+
}), this.onRemoteTrack = (s, u) => {
|
|
503
521
|
var p;
|
|
504
|
-
(p = e.onRemoteTrack) == null || p.call(e,
|
|
505
|
-
}, this.onClientToolCall = (
|
|
506
|
-
var
|
|
507
|
-
(
|
|
508
|
-
const
|
|
509
|
-
name: String(
|
|
510
|
-
arguments:
|
|
511
|
-
tool_call_id: String(
|
|
512
|
-
execution_mode:
|
|
513
|
-
client_fields:
|
|
522
|
+
(p = e.onRemoteTrack) == null || p.call(e, s, u), this.emit("track", { track: s, stream: u });
|
|
523
|
+
}, this.onClientToolCall = (s) => {
|
|
524
|
+
var l;
|
|
525
|
+
(l = e.onClientToolCall) == null || l.call(e, s);
|
|
526
|
+
const u = (s == null ? void 0 : s.data) || s, p = {
|
|
527
|
+
name: String(u.name || u.tool_name || ""),
|
|
528
|
+
arguments: u.arguments || u.args || {},
|
|
529
|
+
tool_call_id: String(u.tool_call_id || u.call_id || ""),
|
|
530
|
+
execution_mode: u.execution_mode === "blocking" ? "blocking" : "fire_and_forget",
|
|
531
|
+
client_fields: u.client_fields || {}
|
|
514
532
|
};
|
|
515
533
|
p.name && p.tool_call_id && this.emit("tool_call", p);
|
|
516
534
|
}, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new _e({
|
|
517
|
-
sendContext: (
|
|
535
|
+
sendContext: (s) => this.sendContextUpdate(s),
|
|
518
536
|
isReady: () => {
|
|
519
|
-
var
|
|
520
|
-
return ((
|
|
537
|
+
var s;
|
|
538
|
+
return ((s = this.dataChannel) == null ? void 0 : s.readyState) === "open";
|
|
521
539
|
}
|
|
522
540
|
}));
|
|
523
541
|
}
|
|
@@ -569,41 +587,41 @@ const w = class w {
|
|
|
569
587
|
channelCount: 1
|
|
570
588
|
}
|
|
571
589
|
});
|
|
572
|
-
} catch (
|
|
573
|
-
if (
|
|
590
|
+
} catch (l) {
|
|
591
|
+
if (l.name === "NotAllowedError" || l.name === "PermissionDeniedError" || (t = l.message) != null && t.includes("Permission denied")) {
|
|
574
592
|
const _ = navigator.userAgent, m = /iPad|iPhone|iPod/.test(_) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
575
593
|
let f = "Microphone access denied. Please allow microphone access in your browser settings.";
|
|
576
594
|
m && (_.includes("CriOS") ? f = "Microphone access blocked. Please enable it in iOS Settings > Chrome > Microphone, then reload the page." : _.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).");
|
|
577
|
-
const
|
|
578
|
-
throw
|
|
595
|
+
const S = new Error(f);
|
|
596
|
+
throw S.name = l.name, S;
|
|
579
597
|
}
|
|
580
|
-
throw
|
|
598
|
+
throw l;
|
|
581
599
|
}
|
|
582
600
|
if (this.isConnectCancelled(e)) {
|
|
583
|
-
n.getTracks().forEach((
|
|
601
|
+
n.getTracks().forEach((l) => l.stop());
|
|
584
602
|
return;
|
|
585
603
|
}
|
|
586
604
|
if (this.localStream = n, !this.pc || this.isConnectCancelled(e)) {
|
|
587
|
-
n.getTracks().forEach((
|
|
605
|
+
n.getTracks().forEach((l) => l.stop());
|
|
588
606
|
return;
|
|
589
607
|
}
|
|
590
|
-
if (this.onLocalStream(n), n.getTracks().forEach((
|
|
608
|
+
if (this.onLocalStream(n), n.getTracks().forEach((l) => {
|
|
591
609
|
var _;
|
|
592
|
-
(_ = this.pc) == null || _.addTrack(
|
|
610
|
+
(_ = this.pc) == null || _.addTrack(l, n);
|
|
593
611
|
}), !this.pc)
|
|
594
612
|
throw new Error("RTCPeerConnection was closed unexpectedly");
|
|
595
613
|
this.dataChannel = this.pc.createDataChannel("control"), this.dataChannel.onopen = () => {
|
|
596
|
-
var
|
|
597
|
-
(
|
|
598
|
-
}, this.dataChannel.onmessage = (
|
|
599
|
-
if (typeof
|
|
614
|
+
var l;
|
|
615
|
+
(l = this.routeTracker) == null || l.onChannelReady();
|
|
616
|
+
}, this.dataChannel.onmessage = (l) => {
|
|
617
|
+
if (typeof l.data == "string")
|
|
600
618
|
try {
|
|
601
|
-
this.handleControlEvent(JSON.parse(
|
|
619
|
+
this.handleControlEvent(JSON.parse(l.data));
|
|
602
620
|
} catch {
|
|
603
621
|
}
|
|
604
|
-
else if (
|
|
622
|
+
else if (l.data instanceof ArrayBuffer)
|
|
605
623
|
try {
|
|
606
|
-
const _ = new TextDecoder().decode(
|
|
624
|
+
const _ = new TextDecoder().decode(l.data);
|
|
607
625
|
try {
|
|
608
626
|
const m = JSON.parse(_);
|
|
609
627
|
oe(m) && this.handleControlEvent(m);
|
|
@@ -611,40 +629,40 @@ const w = class w {
|
|
|
611
629
|
}
|
|
612
630
|
} catch {
|
|
613
631
|
}
|
|
614
|
-
else
|
|
632
|
+
else l.data instanceof Blob && l.data.text().then((_) => {
|
|
615
633
|
try {
|
|
616
634
|
this.handleControlEvent(JSON.parse(_));
|
|
617
635
|
} catch {
|
|
618
636
|
}
|
|
619
637
|
});
|
|
620
|
-
}, this.dataChannel.onerror = (
|
|
638
|
+
}, this.dataChannel.onerror = (l) => {
|
|
621
639
|
}, this.mediaBytesChannel = this.pc.createDataChannel("media-bytes", { ordered: !0 }), this.mediaBytesChannel.binaryType = "arraybuffer", this.mediaBytesChannel.onopen = () => {
|
|
622
|
-
}, this.mediaBytesChannel.onerror = (
|
|
623
|
-
}, this.pc.ontrack = (
|
|
624
|
-
const _ =
|
|
640
|
+
}, this.mediaBytesChannel.onerror = (l) => {
|
|
641
|
+
}, this.pc.ontrack = (l) => {
|
|
642
|
+
const _ = l.track, m = l.streams[0];
|
|
625
643
|
_.kind === "audio" ? (this.audioElement = new Audio(), this.audioElement.srcObject = m, this.audioElement.play().catch((f) => {
|
|
626
644
|
}), this.audioElement.onended = () => {
|
|
627
645
|
this.sendEvent("playedStream"), typeof window < "u" && window.dispatchEvent(new CustomEvent("vanira:agent-playback-ended"));
|
|
628
646
|
}, this.onRemoteTrack(_, m)) : _.kind === "video" && this.onRemoteTrack(_, m);
|
|
629
647
|
};
|
|
630
|
-
const
|
|
631
|
-
var m, f,
|
|
632
|
-
const
|
|
633
|
-
((M = this.pc) == null ? void 0 : M.connectionState) === "connected" && this.stopRemoteIcePolling(),
|
|
648
|
+
const r = () => {
|
|
649
|
+
var m, f, S, b, x, A, P, U, L, M, O;
|
|
650
|
+
const l = ((m = this.pc) == null ? void 0 : m.connectionState) === "connected" || ((f = this.pc) == null ? void 0 : f.iceConnectionState) === "connected" || ((S = this.pc) == null ? void 0 : S.iceConnectionState) === "completed", _ = ((b = this.pc) == null ? void 0 : b.connectionState) === "failed" || ((x = this.pc) == null ? void 0 : x.iceConnectionState) === "failed" || ((A = this.pc) == null ? void 0 : A.connectionState) === "closed" || ((P = this.pc) == null ? void 0 : P.iceConnectionState) === "closed" || ((U = this.pc) == null ? void 0 : U.connectionState) === "disconnected" || ((L = this.pc) == null ? void 0 : L.iceConnectionState) === "disconnected";
|
|
651
|
+
((M = this.pc) == null ? void 0 : M.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (O = this.routeTracker) == null || O.start(), this.onConnected()) : _ && this.connected && (this.connected = !1, this.liveVisionAutoStarted = !1, this.onDisconnected());
|
|
634
652
|
};
|
|
635
|
-
this.pc.onconnectionstatechange =
|
|
653
|
+
this.pc.onconnectionstatechange = r, this.pc.oniceconnectionstatechange = r;
|
|
636
654
|
const o = this.getIceTrickleUrl();
|
|
637
|
-
this.pc.onicecandidate = (
|
|
638
|
-
|
|
655
|
+
this.pc.onicecandidate = (l) => {
|
|
656
|
+
l.candidate && fetch(o, {
|
|
639
657
|
method: "POST",
|
|
640
658
|
headers: { "Content-Type": "application/json" },
|
|
641
|
-
body: JSON.stringify({ candidate:
|
|
659
|
+
body: JSON.stringify({ candidate: l.candidate.toJSON() })
|
|
642
660
|
}).catch((_) => {
|
|
643
661
|
});
|
|
644
662
|
};
|
|
645
|
-
const
|
|
646
|
-
if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(
|
|
647
|
-
const
|
|
663
|
+
const h = await this.pc.createOffer();
|
|
664
|
+
if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(h), this.isConnectCancelled(e))) return;
|
|
665
|
+
const s = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`, u = await fetch(s, {
|
|
648
666
|
method: "POST",
|
|
649
667
|
headers: { "Content-Type": "application/json" },
|
|
650
668
|
body: JSON.stringify({
|
|
@@ -654,11 +672,11 @@ const w = class w {
|
|
|
654
672
|
})
|
|
655
673
|
});
|
|
656
674
|
if (this.isConnectCancelled(e)) return;
|
|
657
|
-
if (!
|
|
658
|
-
const
|
|
659
|
-
throw new Error(
|
|
675
|
+
if (!u.ok) {
|
|
676
|
+
const l = await u.json();
|
|
677
|
+
throw new Error(l.error || `HTTP ${u.status}`);
|
|
660
678
|
}
|
|
661
|
-
const { answer: p } = await
|
|
679
|
+
const { answer: p } = await u.json();
|
|
662
680
|
if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(p), this.isConnectCancelled(e))) return;
|
|
663
681
|
this.startRemoteIcePolling(o);
|
|
664
682
|
} catch (i) {
|
|
@@ -679,38 +697,38 @@ const w = class w {
|
|
|
679
697
|
].join("|");
|
|
680
698
|
}
|
|
681
699
|
async postCreateCall(e, t, i) {
|
|
682
|
-
var
|
|
700
|
+
var h, s, u;
|
|
683
701
|
const n = await fetch(`${this.backendUrl}/calls/create`, {
|
|
684
702
|
method: "POST",
|
|
685
703
|
headers: e,
|
|
686
704
|
body: JSON.stringify({
|
|
687
705
|
agent_id: this.agentId,
|
|
688
|
-
type: ((
|
|
706
|
+
type: ((h = this.runtime) == null ? void 0 : h.callType) || "web",
|
|
689
707
|
mode: t,
|
|
690
|
-
...(
|
|
708
|
+
...(s = this.runtime) != null && s.runtimeName ? { runtime: this.runtime.runtimeName } : {},
|
|
691
709
|
prospect_id: this.prospectId,
|
|
692
710
|
...i ? { call_id: i } : {}
|
|
693
711
|
})
|
|
694
712
|
});
|
|
695
713
|
if (!n.ok) {
|
|
696
714
|
const p = await n.json().catch(() => ({}));
|
|
697
|
-
throw new Error(`[VaniraClient] createCall failed (${n.status}): ${((
|
|
715
|
+
throw new Error(`[VaniraClient] createCall failed (${n.status}): ${((u = p == null ? void 0 : p.detail) == null ? void 0 : u.message) || (p == null ? void 0 : p.message) || n.statusText}`);
|
|
698
716
|
}
|
|
699
|
-
const
|
|
700
|
-
if (!
|
|
717
|
+
const r = await n.json();
|
|
718
|
+
if (!r.call_id || !r.worker_url)
|
|
701
719
|
throw new Error("[VaniraClient] /calls/create response missing call_id or worker_url");
|
|
702
|
-
const o =
|
|
720
|
+
const o = y.normalizeIceServers(r.ice_servers);
|
|
703
721
|
if (!o.length)
|
|
704
722
|
throw new Error("[VaniraClient] /calls/create response missing ice_servers");
|
|
705
723
|
return {
|
|
706
|
-
callId:
|
|
707
|
-
prospectId:
|
|
708
|
-
serverUrl:
|
|
724
|
+
callId: r.call_id,
|
|
725
|
+
prospectId: r.prospect_id || this.prospectId,
|
|
726
|
+
serverUrl: r.worker_url.replace(/\/$/, ""),
|
|
709
727
|
iceServers: o
|
|
710
728
|
};
|
|
711
729
|
}
|
|
712
730
|
applyCreateCallSession(e) {
|
|
713
|
-
if (this.callId = e.callId, this.prospectId = e.prospectId || this.prospectId, this.serverUrl = e.serverUrl, this.iceServers = e.iceServers, this.callSessionLoaded = !0,
|
|
731
|
+
if (this.callId = e.callId, this.prospectId = e.prospectId || this.prospectId, this.serverUrl = e.serverUrl, this.iceServers = e.iceServers, this.callSessionLoaded = !0, re(this.agentId, this.callId || "", this.prospectId), this.onSessionStarted && this.prospectId && this.callId && !this.sessionStartedEmitted)
|
|
714
732
|
try {
|
|
715
733
|
this.onSessionStarted({ prospectId: this.prospectId, callId: this.callId, serverUrl: this.serverUrl }), this.sessionStartedEmitted = !0;
|
|
716
734
|
} catch {
|
|
@@ -727,11 +745,11 @@ const w = class w {
|
|
|
727
745
|
const e = { "Content-Type": "application/json" };
|
|
728
746
|
this.apiKey ? e["X-API-Key"] = this.apiKey : this.token && (e.Authorization = this.token.startsWith("Bearer ") ? this.token : `Bearer ${this.token}`);
|
|
729
747
|
const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new", n = this.createCallCacheKey(i, t);
|
|
730
|
-
let
|
|
731
|
-
|
|
732
|
-
|
|
748
|
+
let r = y.inflightCreates.get(n);
|
|
749
|
+
r || (r = this.postCreateCall(e, i, t), y.inflightCreates.set(n, r), r.finally(() => {
|
|
750
|
+
y.inflightCreates.get(n) === r && y.inflightCreates.delete(n);
|
|
733
751
|
}));
|
|
734
|
-
const o = await
|
|
752
|
+
const o = await r;
|
|
735
753
|
this.applyCreateCallSession(o);
|
|
736
754
|
}
|
|
737
755
|
getIceServers() {
|
|
@@ -743,10 +761,10 @@ const w = class w {
|
|
|
743
761
|
if (!Array.isArray(e)) return [];
|
|
744
762
|
const t = [];
|
|
745
763
|
for (const i of e) {
|
|
746
|
-
const n = i == null ? void 0 : i.urls,
|
|
747
|
-
if (!
|
|
748
|
-
const o = { urls:
|
|
749
|
-
|
|
764
|
+
const n = i == null ? void 0 : i.urls, r = Array.isArray(n) ? n.filter(Boolean) : typeof n == "string" && n.trim() ? [n.trim()] : [];
|
|
765
|
+
if (!r.length) continue;
|
|
766
|
+
const o = { urls: r.length === 1 ? r[0] : r }, h = i.username, s = i.credential;
|
|
767
|
+
h && (o.username = h), s && (o.credential = s), t.push(o);
|
|
750
768
|
}
|
|
751
769
|
return t;
|
|
752
770
|
}
|
|
@@ -786,9 +804,9 @@ const w = class w {
|
|
|
786
804
|
if (!t.ok) return;
|
|
787
805
|
const { candidates: i } = await t.json();
|
|
788
806
|
for (const n of i || []) {
|
|
789
|
-
const
|
|
790
|
-
if (!this.appliedRemoteCandidates.has(
|
|
791
|
-
this.appliedRemoteCandidates.add(
|
|
807
|
+
const r = JSON.stringify(n);
|
|
808
|
+
if (!this.appliedRemoteCandidates.has(r)) {
|
|
809
|
+
this.appliedRemoteCandidates.add(r);
|
|
792
810
|
try {
|
|
793
811
|
await this.pc.addIceCandidate(n);
|
|
794
812
|
} catch {
|
|
@@ -814,10 +832,10 @@ const w = class w {
|
|
|
814
832
|
}
|
|
815
833
|
/** Wait for control DataChannel, then send (live vision lifecycle events). */
|
|
816
834
|
async sendEventWhenReady(e, t = {}, i = 1e4) {
|
|
817
|
-
var
|
|
835
|
+
var r;
|
|
818
836
|
const n = Date.now() + i;
|
|
819
837
|
for (; Date.now() < n; ) {
|
|
820
|
-
if (((
|
|
838
|
+
if (((r = this.dataChannel) == null ? void 0 : r.readyState) === "open")
|
|
821
839
|
return this.sendEvent(e, t), !0;
|
|
822
840
|
await new Promise((o) => setTimeout(o, 50));
|
|
823
841
|
}
|
|
@@ -834,7 +852,7 @@ const w = class w {
|
|
|
834
852
|
name: "open_live_camera",
|
|
835
853
|
tool_call_id: `lv_${crypto.randomUUID()}`,
|
|
836
854
|
execution_mode: "fire_and_forget",
|
|
837
|
-
client_fields: { preset_id:
|
|
855
|
+
client_fields: { preset_id: c.LiveVision },
|
|
838
856
|
arguments: {
|
|
839
857
|
mode: "live",
|
|
840
858
|
scope: t,
|
|
@@ -876,15 +894,15 @@ const w = class w {
|
|
|
876
894
|
event: "client_tool_ack",
|
|
877
895
|
data: { tool_call_id: n }
|
|
878
896
|
}));
|
|
879
|
-
const
|
|
880
|
-
if (
|
|
897
|
+
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) || "", s = ae(o, r, h);
|
|
898
|
+
if (h === "end_call") {
|
|
881
899
|
n && this.sendToolResult(n, {
|
|
882
900
|
status: "client_ack_end_call",
|
|
883
901
|
message: "Ending call."
|
|
884
902
|
}), window.setTimeout(() => this.disconnect(), 120);
|
|
885
903
|
break;
|
|
886
904
|
}
|
|
887
|
-
if (
|
|
905
|
+
if (s) {
|
|
888
906
|
window.dispatchEvent(new CustomEvent("vanira:preset", {
|
|
889
907
|
detail: { toolCall: i, client: this }
|
|
890
908
|
})), this.onClientToolCall(i);
|
|
@@ -918,8 +936,8 @@ const w = class w {
|
|
|
918
936
|
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((n) => {
|
|
919
937
|
n.enabled = !e;
|
|
920
938
|
}), (i = this.pc) == null || i.getSenders().forEach((n) => {
|
|
921
|
-
var
|
|
922
|
-
((
|
|
939
|
+
var r;
|
|
940
|
+
((r = n.track) == null ? void 0 : r.kind) === "audio" && (n.track.enabled = !e);
|
|
923
941
|
});
|
|
924
942
|
}
|
|
925
943
|
isMicrophoneMuted() {
|
|
@@ -1034,25 +1052,25 @@ const w = class w {
|
|
|
1034
1052
|
* the server adds client_media_upload_ready ack — use HTTP for frame JPEGs until then.
|
|
1035
1053
|
*/
|
|
1036
1054
|
async uploadMediaFrame(e, t = "camera_capture", i) {
|
|
1037
|
-
const n = i && !(e instanceof File) ? new File([e], i, { type: e.type || "image/jpeg" }) : e, { media_id:
|
|
1038
|
-
if (!
|
|
1055
|
+
const n = i && !(e instanceof File) ? new File([e], i, { type: e.type || "image/jpeg" }) : e, { media_id: r, url: o, contentType: h } = await this._postMediaUpload(n, t, !0);
|
|
1056
|
+
if (!r || !o)
|
|
1039
1057
|
throw new Error("Frame upload failed: server response missing media_id or url");
|
|
1040
|
-
return { media_id:
|
|
1058
|
+
return { media_id: r, url: o, content_type: h };
|
|
1041
1059
|
}
|
|
1042
1060
|
/** WebRTC media-bytes path (control start/complete + binary chunks). */
|
|
1043
|
-
async _uploadBytesViaDataChannel(e, t, i, n,
|
|
1061
|
+
async _uploadBytesViaDataChannel(e, t, i, n, r) {
|
|
1044
1062
|
if (!this.callId || !this.mediaBytesChannel)
|
|
1045
1063
|
throw new Error("Upload failed: call not ready for WebRTC media upload.");
|
|
1046
|
-
const o =
|
|
1064
|
+
const o = r || (e instanceof File ? e.name : n === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (n === "frame" ? "image/jpeg" : "application/octet-stream"), s = await ue(e);
|
|
1047
1065
|
return he({
|
|
1048
|
-
bytes:
|
|
1066
|
+
bytes: s,
|
|
1049
1067
|
filename: o,
|
|
1050
|
-
contentType:
|
|
1068
|
+
contentType: h,
|
|
1051
1069
|
reason: t,
|
|
1052
1070
|
message: i,
|
|
1053
1071
|
callId: this.callId,
|
|
1054
1072
|
mediaBytesChannel: this.mediaBytesChannel,
|
|
1055
|
-
sendControlEvent: (
|
|
1073
|
+
sendControlEvent: (u, p) => this.sendEvent(u, p),
|
|
1056
1074
|
uploadKind: n
|
|
1057
1075
|
});
|
|
1058
1076
|
}
|
|
@@ -1062,14 +1080,14 @@ const w = class w {
|
|
|
1062
1080
|
}
|
|
1063
1081
|
/** HTTP fallback — original uploadMedia behavior (unchanged). */
|
|
1064
1082
|
async _uploadMediaViaHTTP(e, t = "general", i = "") {
|
|
1065
|
-
const { media_id: n, url:
|
|
1083
|
+
const { media_id: n, url: r, contentType: o } = await this._postMediaUpload(e, t, !0);
|
|
1066
1084
|
return this.sendMediaUpdate({
|
|
1067
1085
|
media_id: n,
|
|
1068
|
-
media_url:
|
|
1086
|
+
media_url: r,
|
|
1069
1087
|
content_type: o,
|
|
1070
1088
|
reason: t,
|
|
1071
1089
|
message: i
|
|
1072
|
-
}), { media_id: n, url:
|
|
1090
|
+
}), { media_id: n, url: r };
|
|
1073
1091
|
}
|
|
1074
1092
|
async _postMediaUpload(e, t, i = !1) {
|
|
1075
1093
|
if (!this.serverUrl)
|
|
@@ -1081,24 +1099,24 @@ const w = class w {
|
|
|
1081
1099
|
throw new Error(
|
|
1082
1100
|
"Upload failed: worker_url is not set. Connect the call before uploading media."
|
|
1083
1101
|
);
|
|
1084
|
-
const
|
|
1102
|
+
const r = `${n}/media/upload`, o = new FormData();
|
|
1085
1103
|
o.append("file", e), o.append("call_id", this.callId), o.append("reason", t);
|
|
1086
|
-
const
|
|
1104
|
+
const h = await fetch(r, {
|
|
1087
1105
|
method: "POST",
|
|
1088
1106
|
body: o
|
|
1089
1107
|
});
|
|
1090
|
-
if (!
|
|
1091
|
-
let _ = `HTTP ${
|
|
1108
|
+
if (!h.ok) {
|
|
1109
|
+
let _ = `HTTP ${h.status}`;
|
|
1092
1110
|
try {
|
|
1093
|
-
_ = (await
|
|
1111
|
+
_ = (await h.json()).error || _;
|
|
1094
1112
|
} catch {
|
|
1095
1113
|
}
|
|
1096
1114
|
throw new Error(`Upload failed: ${_}`);
|
|
1097
1115
|
}
|
|
1098
|
-
const
|
|
1099
|
-
if (!
|
|
1116
|
+
const s = await h.json(), u = s.media_id, p = s.url, l = s.content_type || e.type;
|
|
1117
|
+
if (!u || !p)
|
|
1100
1118
|
throw new Error("Upload failed: server response missing media_id or url");
|
|
1101
|
-
return i ? { media_id:
|
|
1119
|
+
return i ? { media_id: u, url: p, contentType: l } : { media_id: u, url: p, contentType: l };
|
|
1102
1120
|
}
|
|
1103
1121
|
// ─── Event emitter (replaces retired VaniraAI) ───────────────────────────
|
|
1104
1122
|
get status() {
|
|
@@ -1146,8 +1164,8 @@ const w = class w {
|
|
|
1146
1164
|
}
|
|
1147
1165
|
};
|
|
1148
1166
|
/** Dedupes concurrent POST /calls/create (e.g. React StrictMode double-mount). */
|
|
1149
|
-
|
|
1150
|
-
let
|
|
1167
|
+
d(y, "inflightCreates", /* @__PURE__ */ new Map());
|
|
1168
|
+
let R = y;
|
|
1151
1169
|
const me = {
|
|
1152
1170
|
supportsAudioEndedEvent: !1,
|
|
1153
1171
|
supportsScreenShare: !1,
|
|
@@ -1168,28 +1186,28 @@ const me = {
|
|
|
1168
1186
|
dataChannel: new Z()
|
|
1169
1187
|
};
|
|
1170
1188
|
function J(a) {
|
|
1171
|
-
return new
|
|
1189
|
+
return new R({
|
|
1172
1190
|
...a,
|
|
1173
1191
|
runtime: fe
|
|
1174
1192
|
});
|
|
1175
1193
|
}
|
|
1176
|
-
const
|
|
1177
|
-
function
|
|
1194
|
+
const Se = J;
|
|
1195
|
+
function ye(a) {
|
|
1178
1196
|
return J(a);
|
|
1179
1197
|
}
|
|
1180
|
-
const
|
|
1198
|
+
const ve = ye;
|
|
1181
1199
|
export {
|
|
1182
1200
|
Y as RNAudioAdapter,
|
|
1183
1201
|
Z as RNDataChannelAdapter,
|
|
1184
1202
|
q as RNMediaAdapter,
|
|
1185
1203
|
X as RNPeerAdapter,
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1204
|
+
R as VaniraAI,
|
|
1205
|
+
R as VaniraClient,
|
|
1206
|
+
R as WebRTCClient,
|
|
1207
|
+
Se as createReactNativeAI,
|
|
1190
1208
|
J as createReactNativeClient,
|
|
1191
|
-
|
|
1192
|
-
|
|
1209
|
+
ve as createVaniraAI,
|
|
1210
|
+
ye as createVaniraClient,
|
|
1193
1211
|
me as reactNativeCapabilities,
|
|
1194
1212
|
fe as reactNativeRuntime
|
|
1195
1213
|
};
|