@vanira/sdk 0.0.84 → 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 +559 -166
- package/dist/headless/index.d.ts +3 -0
- package/dist/headless/index.js +43823 -4080
- package/dist/index.d.ts +43 -0
- package/dist/platforms/browser.cjs +41 -3
- package/dist/platforms/browser.d.ts +3 -0
- package/dist/platforms/browser.js +21303 -689
- package/dist/platforms/react-native.cjs +1 -1
- package/dist/platforms/react-native.js +384 -356
- package/dist/vanira-sdk.es.js +47457 -7701
- package/dist/vanira-sdk.js +579 -229
- package/dist/vanira-sdk.umd.js +612 -219
- package/package.json +8 -6
- package/dist/chunks/html2canvas.js +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (a, e, t) =>
|
|
4
|
-
class
|
|
1
|
+
var H = Object.defineProperty;
|
|
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 d = (a, e, t) => G(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
class z {
|
|
5
5
|
pause() {
|
|
6
6
|
}
|
|
7
7
|
cleanup() {
|
|
@@ -9,12 +9,12 @@ class H {
|
|
|
9
9
|
onEnded(e) {
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
class
|
|
12
|
+
class Y {
|
|
13
13
|
createRemotePlayer(e) {
|
|
14
|
-
return new
|
|
14
|
+
return new z();
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
class
|
|
17
|
+
class q {
|
|
18
18
|
async getUserAudio(e) {
|
|
19
19
|
return navigator.mediaDevices.getUserMedia({
|
|
20
20
|
audio: e
|
|
@@ -24,7 +24,7 @@ class Y {
|
|
|
24
24
|
e.getTracks().forEach((t) => t.stop());
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
class
|
|
27
|
+
class X {
|
|
28
28
|
create(e) {
|
|
29
29
|
return new globalThis.RTCPeerConnection({
|
|
30
30
|
iceServers: e.iceServers,
|
|
@@ -32,24 +32,24 @@ class q {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
class
|
|
35
|
+
class Z {
|
|
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
|
|
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;
|
|
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 F {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const Q = "https://api.vanira.io", c = {
|
|
64
64
|
Form: "vanira_form",
|
|
65
65
|
Calendar: "vanira_calendar",
|
|
66
66
|
Navigate: "vanira_navigate",
|
|
@@ -71,42 +71,26 @@ const X = "https://api.vanira.io", h = {
|
|
|
71
71
|
SelectOption: "vanira_select_option",
|
|
72
72
|
SetDate: "vanira_set_date",
|
|
73
73
|
TypeText: "vanira_type_text",
|
|
74
|
+
WriteLatexText: "vanira_write_latex_text",
|
|
74
75
|
EraseText: "vanira_erase_text",
|
|
75
|
-
Draw: "vanira_draw",
|
|
76
|
-
EraseDraw: "vanira_erase_draw",
|
|
77
76
|
LiveVision: "vanira_live_vision",
|
|
78
77
|
CloseLiveCamera: "vanira_close_live_camera",
|
|
79
78
|
LiveScreen: "vanira_live_screen",
|
|
80
79
|
CloseLiveScreen: "vanira_close_live_screen",
|
|
81
80
|
ClipRegion: "vanira_clip_region",
|
|
82
|
-
|
|
83
|
-
ScreenInk: "vanira_screen_ink",
|
|
84
|
-
ScreenCursor: "vanira_screen_cursor",
|
|
85
|
-
ScreenClick: "vanira_screen_click",
|
|
86
|
-
ClearScreenOverlay: "vanira_clear_screen_overlay",
|
|
87
|
-
PageScan: "vanira_page_scan",
|
|
81
|
+
ScreenVision: "vanira_screen_vision",
|
|
88
82
|
PointAt: "vanira_point_at",
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
DrawOnScreen: "vanira_draw_on_screen",
|
|
84
|
+
ClearScreenDraw: "vanira_clear_screen_draw",
|
|
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);
|
|
90
|
+
function V(a) {
|
|
91
|
+
return !!a && ee.has(a);
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
h.ScreenInk,
|
|
97
|
-
h.ScreenCursor,
|
|
98
|
-
h.ScreenClick,
|
|
99
|
-
h.ClearScreenOverlay,
|
|
100
|
-
h.PointAt,
|
|
101
|
-
h.OutlineTargets,
|
|
102
|
-
h.ClearGuide
|
|
103
|
-
]);
|
|
104
|
-
[
|
|
105
|
-
...ee,
|
|
106
|
-
h.PageScan,
|
|
107
|
-
h.TabScreenshot
|
|
108
|
-
];
|
|
109
|
-
function K(a) {
|
|
93
|
+
function j(a) {
|
|
110
94
|
if (typeof a == "string")
|
|
111
95
|
try {
|
|
112
96
|
return JSON.parse(a);
|
|
@@ -115,63 +99,95 @@ function K(a) {
|
|
|
115
99
|
}
|
|
116
100
|
return a && typeof a == "object" ? a : {};
|
|
117
101
|
}
|
|
118
|
-
const
|
|
119
|
-
type_on_whiteboard:
|
|
120
|
-
write_on_whiteboard:
|
|
121
|
-
write_on_white_board:
|
|
122
|
-
dom_typing_simulation:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
tab_screenshot:
|
|
138
|
-
capture_tab:
|
|
139
|
-
capture_tab_screenshot:
|
|
140
|
-
screenshot_tab:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
102
|
+
const N = {
|
|
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
|
|
147
151
|
};
|
|
148
|
-
function
|
|
152
|
+
function te(a, e) {
|
|
153
|
+
const t = a.latex_text ?? (e == null ? void 0 : e.latex_text);
|
|
154
|
+
return typeof t == "string" && t.trim().length > 0;
|
|
155
|
+
}
|
|
156
|
+
function K(a, e) {
|
|
149
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);
|
|
150
158
|
return typeof t == "string" && t.trim().length > 0;
|
|
151
159
|
}
|
|
152
|
-
function
|
|
160
|
+
function ie(a, e) {
|
|
153
161
|
const t = a.fields ?? (e == null ? void 0 : e.fields);
|
|
154
|
-
return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((
|
|
162
|
+
return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((i) => i.trim()).filter(Boolean).length > 0 : !1;
|
|
155
163
|
}
|
|
156
164
|
function ne(a, e) {
|
|
157
165
|
const t = a == null ? void 0 : a.preset_id;
|
|
158
|
-
if (typeof t == "string"
|
|
159
|
-
return t;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
if (typeof t == "string") {
|
|
167
|
+
if (V(t)) return t;
|
|
168
|
+
const r = D[t];
|
|
169
|
+
if (r) return r;
|
|
170
|
+
}
|
|
171
|
+
const n = j(e).preset_id;
|
|
172
|
+
if (typeof n == "string") {
|
|
173
|
+
if (V(n)) return n;
|
|
174
|
+
const r = D[n];
|
|
175
|
+
if (r) return r;
|
|
176
|
+
}
|
|
163
177
|
}
|
|
164
|
-
function
|
|
165
|
-
const
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
169
|
-
if (
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
return
|
|
173
|
-
if (
|
|
174
|
-
return
|
|
178
|
+
function ae(a, e, t) {
|
|
179
|
+
const i = j(e);
|
|
180
|
+
let n = ne(a, i);
|
|
181
|
+
if (n === c.Form && K(i, a) && !ie(i, a))
|
|
182
|
+
return c.TypeText;
|
|
183
|
+
if (n) return n;
|
|
184
|
+
const r = String(t ?? "").trim().toLowerCase();
|
|
185
|
+
if (r && N[r])
|
|
186
|
+
return N[r];
|
|
187
|
+
if (te(i, a))
|
|
188
|
+
return c.WriteLatexText;
|
|
189
|
+
if (K(i, a))
|
|
190
|
+
return c.TypeText;
|
|
175
191
|
}
|
|
176
192
|
const g = "vanira_latest_call_id", k = "vanira_prospect_id";
|
|
177
193
|
function C(a) {
|
|
@@ -180,10 +196,10 @@ function C(a) {
|
|
|
180
196
|
function I(a) {
|
|
181
197
|
return `vanira_prospect_id_${a}`;
|
|
182
198
|
}
|
|
183
|
-
function
|
|
199
|
+
function W(a) {
|
|
184
200
|
return `vanira_call_meta_${a}`;
|
|
185
201
|
}
|
|
186
|
-
function
|
|
202
|
+
function w(a, e) {
|
|
187
203
|
if (!a) return null;
|
|
188
204
|
try {
|
|
189
205
|
return a.getItem(e);
|
|
@@ -191,46 +207,46 @@ function S(a, e) {
|
|
|
191
207
|
return null;
|
|
192
208
|
}
|
|
193
209
|
}
|
|
194
|
-
function
|
|
210
|
+
function B(a) {
|
|
195
211
|
if (typeof window > "u" || !a) return null;
|
|
196
|
-
const e = [], t =
|
|
212
|
+
const e = [], t = w(window.localStorage, W(a));
|
|
197
213
|
if (t)
|
|
198
214
|
try {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
callId:
|
|
202
|
-
prospectId:
|
|
203
|
-
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
|
|
204
220
|
});
|
|
205
221
|
} catch {
|
|
206
222
|
}
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
callId:
|
|
210
|
-
prospectId:
|
|
223
|
+
const i = (h, s, u) => {
|
|
224
|
+
h && e.push({
|
|
225
|
+
callId: h,
|
|
226
|
+
prospectId: s || void 0,
|
|
211
227
|
updatedAt: u
|
|
212
228
|
});
|
|
213
|
-
},
|
|
214
|
-
return
|
|
215
|
-
|
|
216
|
-
|
|
229
|
+
}, n = w(window.localStorage, I(a)), r = w(window.sessionStorage, I(a)), o = w(window.localStorage, k);
|
|
230
|
+
return i(
|
|
231
|
+
w(window.localStorage, C(a)),
|
|
232
|
+
n || o,
|
|
217
233
|
2
|
|
218
|
-
),
|
|
219
|
-
|
|
220
|
-
|
|
234
|
+
), i(
|
|
235
|
+
w(window.sessionStorage, C(a)),
|
|
236
|
+
r || o,
|
|
221
237
|
1
|
|
222
|
-
),
|
|
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;
|
|
223
239
|
}
|
|
224
|
-
function
|
|
225
|
-
var
|
|
240
|
+
function re(a, e, t) {
|
|
241
|
+
var n, r, o, h, s, u, p, l, _;
|
|
226
242
|
if (typeof window > "u" || !a || !e) return;
|
|
227
|
-
const
|
|
243
|
+
const i = {
|
|
228
244
|
callId: e,
|
|
229
245
|
prospectId: t,
|
|
230
246
|
updatedAt: Date.now()
|
|
231
247
|
};
|
|
232
248
|
try {
|
|
233
|
-
(
|
|
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));
|
|
234
250
|
} catch {
|
|
235
251
|
}
|
|
236
252
|
}
|
|
@@ -239,57 +255,57 @@ const se = /* @__PURE__ */ new Set([
|
|
|
239
255
|
"clearAudio",
|
|
240
256
|
"client_tool_cancel"
|
|
241
257
|
]);
|
|
242
|
-
function
|
|
258
|
+
function oe(a) {
|
|
243
259
|
if (!a || typeof a != "object") return !1;
|
|
244
260
|
const e = a.event;
|
|
245
261
|
return typeof e == "string" && se.has(e);
|
|
246
262
|
}
|
|
247
|
-
const T = 16 * 1024,
|
|
263
|
+
const T = 16 * 1024, ce = 256 * 1024;
|
|
248
264
|
function E(a, e) {
|
|
249
265
|
return (a == null ? void 0 : a.readyState) === "open" && (e == null ? void 0 : e.readyState) === "open";
|
|
250
266
|
}
|
|
251
|
-
function
|
|
267
|
+
function le(a, e) {
|
|
252
268
|
return {
|
|
253
269
|
control: (a == null ? void 0 : a.readyState) ?? "missing",
|
|
254
270
|
mediaBytes: (e == null ? void 0 : e.readyState) ?? "missing"
|
|
255
271
|
};
|
|
256
272
|
}
|
|
257
|
-
async function
|
|
273
|
+
async function de(a, e, t = 8e3) {
|
|
258
274
|
if (E(a, e))
|
|
259
275
|
return !0;
|
|
260
|
-
const
|
|
261
|
-
for (; Date.now() <
|
|
276
|
+
const i = Date.now() + t;
|
|
277
|
+
for (; Date.now() < i; ) {
|
|
262
278
|
if (E(a, e))
|
|
263
279
|
return !0;
|
|
264
|
-
await new Promise((
|
|
280
|
+
await new Promise((n) => setTimeout(n, 50));
|
|
265
281
|
}
|
|
266
282
|
return E(a, e);
|
|
267
283
|
}
|
|
268
284
|
async function $(a) {
|
|
269
|
-
for (; a.bufferedAmount >
|
|
285
|
+
for (; a.bufferedAmount > ce; )
|
|
270
286
|
await new Promise((e) => setTimeout(e, 10));
|
|
271
287
|
}
|
|
272
|
-
async function
|
|
288
|
+
async function he(a) {
|
|
273
289
|
const {
|
|
274
290
|
bytes: e,
|
|
275
291
|
filename: t,
|
|
276
|
-
contentType:
|
|
277
|
-
reason:
|
|
278
|
-
message:
|
|
292
|
+
contentType: i,
|
|
293
|
+
reason: n,
|
|
294
|
+
message: r,
|
|
279
295
|
callId: o,
|
|
280
|
-
mediaBytesChannel:
|
|
281
|
-
sendControlEvent:
|
|
296
|
+
mediaBytesChannel: h,
|
|
297
|
+
sendControlEvent: s,
|
|
282
298
|
uploadId: u = crypto.randomUUID(),
|
|
283
299
|
uploadKind: p = "media"
|
|
284
300
|
} = a, l = e.byteLength, _ = l === 0 ? 0 : Math.ceil(l / T);
|
|
285
|
-
|
|
301
|
+
s("client_media_upload_start", {
|
|
286
302
|
data: {
|
|
287
303
|
upload_id: u,
|
|
288
304
|
call_id: o,
|
|
289
|
-
reason:
|
|
290
|
-
message:
|
|
305
|
+
reason: n,
|
|
306
|
+
message: r,
|
|
291
307
|
filename: t,
|
|
292
|
-
content_type:
|
|
308
|
+
content_type: i,
|
|
293
309
|
size: l,
|
|
294
310
|
chunk_count: _,
|
|
295
311
|
upload_kind: p
|
|
@@ -297,31 +313,31 @@ async function de(a) {
|
|
|
297
313
|
});
|
|
298
314
|
const m = new Uint8Array(e);
|
|
299
315
|
for (let f = 0; f < l; f += T) {
|
|
300
|
-
await $(
|
|
301
|
-
const
|
|
302
|
-
|
|
316
|
+
await $(h);
|
|
317
|
+
const S = Math.min(f + T, l);
|
|
318
|
+
h.send(m.subarray(f, S));
|
|
303
319
|
}
|
|
304
|
-
return await $(
|
|
320
|
+
return await $(h), s("client_media_upload_complete", {
|
|
305
321
|
data: {
|
|
306
322
|
upload_id: u,
|
|
307
323
|
call_id: o,
|
|
308
|
-
reason:
|
|
309
|
-
message:
|
|
324
|
+
reason: n,
|
|
325
|
+
message: r,
|
|
310
326
|
chunk_count: _,
|
|
311
327
|
upload_kind: p
|
|
312
328
|
}
|
|
313
|
-
}), { media_id: u, url: "", content_type:
|
|
329
|
+
}), { media_id: u, url: "", content_type: i };
|
|
314
330
|
}
|
|
315
|
-
async function
|
|
331
|
+
async function ue(a) {
|
|
316
332
|
return typeof a.arrayBuffer == "function" ? a.arrayBuffer() : new Response(a).arrayBuffer();
|
|
317
333
|
}
|
|
318
|
-
function
|
|
334
|
+
function pe(a) {
|
|
319
335
|
return null;
|
|
320
336
|
}
|
|
321
|
-
function
|
|
337
|
+
function v() {
|
|
322
338
|
return typeof window > "u" ? "/" : `${window.location.pathname}${window.location.search}${window.location.hash}` || "/";
|
|
323
339
|
}
|
|
324
|
-
class
|
|
340
|
+
class _e {
|
|
325
341
|
constructor(e) {
|
|
326
342
|
d(this, "active", !1);
|
|
327
343
|
d(this, "initialSent", !1);
|
|
@@ -336,7 +352,7 @@ class pe {
|
|
|
336
352
|
this.sendContext = e.sendContext, this.isReady = e.isReady ?? (() => !0);
|
|
337
353
|
}
|
|
338
354
|
start() {
|
|
339
|
-
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());
|
|
340
356
|
}
|
|
341
357
|
stop() {
|
|
342
358
|
if (!(!this.active && this.cleanupFns.length === 0)) {
|
|
@@ -366,62 +382,62 @@ class pe {
|
|
|
366
382
|
}
|
|
367
383
|
}
|
|
368
384
|
attachListeners() {
|
|
369
|
-
const e = (
|
|
370
|
-
const
|
|
371
|
-
const
|
|
372
|
-
|
|
385
|
+
const e = (r, o = 0) => {
|
|
386
|
+
const h = () => {
|
|
387
|
+
const s = v();
|
|
388
|
+
s !== this.lastRoute && this.handleRouteChange(s, r);
|
|
373
389
|
};
|
|
374
|
-
o > 0 ? window.setTimeout(
|
|
375
|
-
}, t = () => e("popstate"),
|
|
376
|
-
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;
|
|
377
393
|
if ((o == null ? void 0 : o.initiated_by) === "agent") {
|
|
378
394
|
e("vanira_navigate_agent", 120);
|
|
379
395
|
return;
|
|
380
396
|
}
|
|
381
397
|
e("vanira_navigate", 120);
|
|
382
398
|
};
|
|
383
|
-
window.addEventListener("popstate", t), window.addEventListener("hashchange",
|
|
399
|
+
window.addEventListener("popstate", t), window.addEventListener("hashchange", i), window.addEventListener("vanira:navigate", n), this.cleanupFns.push(
|
|
384
400
|
() => window.removeEventListener("popstate", t),
|
|
385
|
-
() => window.removeEventListener("hashchange",
|
|
386
|
-
() => window.removeEventListener("vanira:navigate",
|
|
387
|
-
), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...
|
|
388
|
-
this.originalPushState(...
|
|
389
|
-
}, history.replaceState = (...
|
|
390
|
-
this.originalReplaceState(...
|
|
401
|
+
() => window.removeEventListener("hashchange", i),
|
|
402
|
+
() => window.removeEventListener("vanira:navigate", n)
|
|
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");
|
|
391
407
|
}, this.routePollTimer = window.setInterval(() => {
|
|
392
408
|
if (!this.active) return;
|
|
393
|
-
const
|
|
394
|
-
|
|
409
|
+
const r = v();
|
|
410
|
+
r !== this.lastRoute && this.handleRouteChange(r, "location_poll");
|
|
395
411
|
}, 1e3);
|
|
396
412
|
}
|
|
397
413
|
handleRouteChange(e, t) {
|
|
398
414
|
if (!this.active) return;
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
415
|
+
const i = this.lastRoute;
|
|
416
|
+
if (i === e) return;
|
|
401
417
|
if (this.lastRoute = e, !this.initialSent) {
|
|
402
418
|
this.scheduleInitialContextSend();
|
|
403
419
|
return;
|
|
404
420
|
}
|
|
405
|
-
!this.isReady() ||
|
|
421
|
+
!this.isReady() || pe() || this.sendRouteContext("route_changed", i, t, "user");
|
|
406
422
|
}
|
|
407
|
-
sendRouteContext(e, t,
|
|
408
|
-
const
|
|
409
|
-
this.lastRoute =
|
|
423
|
+
sendRouteContext(e, t, i, n = "user") {
|
|
424
|
+
const r = v();
|
|
425
|
+
this.lastRoute = r;
|
|
410
426
|
const o = {
|
|
411
427
|
ui_state: "page_navigation",
|
|
412
|
-
navigation_led_by:
|
|
413
|
-
current_route:
|
|
414
|
-
current_page:
|
|
428
|
+
navigation_led_by: n,
|
|
429
|
+
current_route: r,
|
|
430
|
+
current_page: r,
|
|
415
431
|
user_action: e === "call_started" ? "call_started_on_page" : "user_navigated"
|
|
416
432
|
};
|
|
417
|
-
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));
|
|
418
434
|
try {
|
|
419
435
|
this.sendContext(o);
|
|
420
436
|
} catch {
|
|
421
437
|
}
|
|
422
438
|
}
|
|
423
439
|
}
|
|
424
|
-
const
|
|
440
|
+
const y = class y {
|
|
425
441
|
constructor(e) {
|
|
426
442
|
d(this, "serverUrl");
|
|
427
443
|
d(this, "agentId");
|
|
@@ -461,53 +477,53 @@ const w = class w {
|
|
|
461
477
|
d(this, "liveVision");
|
|
462
478
|
d(this, "liveVisionAutoStarted", !1);
|
|
463
479
|
if (!e.agentId) throw new Error("agentId is required");
|
|
464
|
-
const t = !!(e.apiKey || e.token),
|
|
480
|
+
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), n = y.normalizeIceServers(
|
|
465
481
|
e.iceServers
|
|
466
482
|
);
|
|
467
|
-
if (!t && !
|
|
483
|
+
if (!t && !i)
|
|
468
484
|
throw new Error(
|
|
469
485
|
"apiKey or token is required — or pass serverUrl and callId from a prior POST /calls/create"
|
|
470
486
|
);
|
|
471
|
-
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 ||
|
|
472
|
-
const
|
|
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);
|
|
488
|
+
const r = typeof window < "u";
|
|
473
489
|
this.prospectId = e.prospectId;
|
|
474
490
|
const o = e.sessionBehavior === "continue";
|
|
475
|
-
if (o &&
|
|
476
|
-
const
|
|
477
|
-
|
|
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));
|
|
478
494
|
}
|
|
479
|
-
if (!this.prospectId &&
|
|
495
|
+
if (!this.prospectId && r)
|
|
480
496
|
try {
|
|
481
|
-
const
|
|
482
|
-
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;
|
|
483
499
|
} catch {
|
|
484
500
|
}
|
|
485
501
|
e.callId ? this.callId = e.callId : o || (this.callId = void 0);
|
|
486
|
-
const
|
|
487
|
-
this.onSessionStarted = (
|
|
488
|
-
|
|
502
|
+
const h = e.onSessionStarted;
|
|
503
|
+
this.onSessionStarted = (s) => {
|
|
504
|
+
h == null || h(s), this.emit("session_started", s);
|
|
489
505
|
}, this.liveVision = e.liveVision, this.onConnected = () => {
|
|
490
|
-
var
|
|
491
|
-
this._status = "connected", (
|
|
506
|
+
var s;
|
|
507
|
+
this._status = "connected", (s = e.onConnected) == null || s.call(e), this.emit("connected"), this.maybeAutoStartLiveCamera();
|
|
492
508
|
}, this.onDisconnected = () => {
|
|
493
|
-
var
|
|
494
|
-
this._status = "disconnected", (
|
|
495
|
-
}, this.onError = (
|
|
509
|
+
var s;
|
|
510
|
+
this._status = "disconnected", (s = e.onDisconnected) == null || s.call(e), this.emit("disconnected");
|
|
511
|
+
}, this.onError = (s) => {
|
|
496
512
|
var p;
|
|
497
513
|
this._status = "error";
|
|
498
|
-
const u = typeof
|
|
499
|
-
(p = e.onError) == null || p.call(e,
|
|
500
|
-
}, 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) => {
|
|
501
517
|
var p;
|
|
502
|
-
(p = e.onTranscription) == null || p.call(e,
|
|
518
|
+
(p = e.onTranscription) == null || p.call(e, s, u), this.emit("transcription", { text: s, isFinal: u });
|
|
503
519
|
}, this.onLocalStream = e.onLocalStream || (() => {
|
|
504
|
-
}), this.onRemoteTrack = (
|
|
520
|
+
}), this.onRemoteTrack = (s, u) => {
|
|
505
521
|
var p;
|
|
506
|
-
(p = e.onRemoteTrack) == null || p.call(e,
|
|
507
|
-
}, this.onClientToolCall = (
|
|
522
|
+
(p = e.onRemoteTrack) == null || p.call(e, s, u), this.emit("track", { track: s, stream: u });
|
|
523
|
+
}, this.onClientToolCall = (s) => {
|
|
508
524
|
var l;
|
|
509
|
-
(l = e.onClientToolCall) == null || l.call(e,
|
|
510
|
-
const u = (
|
|
525
|
+
(l = e.onClientToolCall) == null || l.call(e, s);
|
|
526
|
+
const u = (s == null ? void 0 : s.data) || s, p = {
|
|
511
527
|
name: String(u.name || u.tool_name || ""),
|
|
512
528
|
arguments: u.arguments || u.args || {},
|
|
513
529
|
tool_call_id: String(u.tool_call_id || u.call_id || ""),
|
|
@@ -515,11 +531,11 @@ const w = class w {
|
|
|
515
531
|
client_fields: u.client_fields || {}
|
|
516
532
|
};
|
|
517
533
|
p.name && p.tool_call_id && this.emit("tool_call", p);
|
|
518
|
-
}, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new
|
|
519
|
-
sendContext: (
|
|
534
|
+
}, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new _e({
|
|
535
|
+
sendContext: (s) => this.sendContextUpdate(s),
|
|
520
536
|
isReady: () => {
|
|
521
|
-
var
|
|
522
|
-
return ((
|
|
537
|
+
var s;
|
|
538
|
+
return ((s = this.dataChannel) == null ? void 0 : s.readyState) === "open";
|
|
523
539
|
}
|
|
524
540
|
}));
|
|
525
541
|
}
|
|
@@ -555,14 +571,14 @@ const w = class w {
|
|
|
555
571
|
}
|
|
556
572
|
try {
|
|
557
573
|
this.appliedRemoteCandidates.clear(), this.stopRemoteIcePolling();
|
|
558
|
-
const
|
|
574
|
+
const i = this.getIceServers();
|
|
559
575
|
this.pc = new RTCPeerConnection({
|
|
560
|
-
iceServers:
|
|
576
|
+
iceServers: i,
|
|
561
577
|
iceTransportPolicy: "all"
|
|
562
578
|
});
|
|
563
|
-
let
|
|
579
|
+
let n;
|
|
564
580
|
try {
|
|
565
|
-
|
|
581
|
+
n = await navigator.mediaDevices.getUserMedia({
|
|
566
582
|
audio: {
|
|
567
583
|
echoCancellation: !0,
|
|
568
584
|
noiseSuppression: !0,
|
|
@@ -576,22 +592,22 @@ const w = class w {
|
|
|
576
592
|
const _ = navigator.userAgent, m = /iPad|iPhone|iPod/.test(_) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
577
593
|
let f = "Microphone access denied. Please allow microphone access in your browser settings.";
|
|
578
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).");
|
|
579
|
-
const
|
|
580
|
-
throw
|
|
595
|
+
const S = new Error(f);
|
|
596
|
+
throw S.name = l.name, S;
|
|
581
597
|
}
|
|
582
598
|
throw l;
|
|
583
599
|
}
|
|
584
600
|
if (this.isConnectCancelled(e)) {
|
|
585
|
-
|
|
601
|
+
n.getTracks().forEach((l) => l.stop());
|
|
586
602
|
return;
|
|
587
603
|
}
|
|
588
|
-
if (this.localStream =
|
|
589
|
-
|
|
604
|
+
if (this.localStream = n, !this.pc || this.isConnectCancelled(e)) {
|
|
605
|
+
n.getTracks().forEach((l) => l.stop());
|
|
590
606
|
return;
|
|
591
607
|
}
|
|
592
|
-
if (this.onLocalStream(
|
|
608
|
+
if (this.onLocalStream(n), n.getTracks().forEach((l) => {
|
|
593
609
|
var _;
|
|
594
|
-
(_ = this.pc) == null || _.addTrack(l,
|
|
610
|
+
(_ = this.pc) == null || _.addTrack(l, n);
|
|
595
611
|
}), !this.pc)
|
|
596
612
|
throw new Error("RTCPeerConnection was closed unexpectedly");
|
|
597
613
|
this.dataChannel = this.pc.createDataChannel("control"), this.dataChannel.onopen = () => {
|
|
@@ -608,7 +624,7 @@ const w = class w {
|
|
|
608
624
|
const _ = new TextDecoder().decode(l.data);
|
|
609
625
|
try {
|
|
610
626
|
const m = JSON.parse(_);
|
|
611
|
-
|
|
627
|
+
oe(m) && this.handleControlEvent(m);
|
|
612
628
|
} catch {
|
|
613
629
|
}
|
|
614
630
|
} catch {
|
|
@@ -629,12 +645,12 @@ const w = class w {
|
|
|
629
645
|
this.sendEvent("playedStream"), typeof window < "u" && window.dispatchEvent(new CustomEvent("vanira:agent-playback-ended"));
|
|
630
646
|
}, this.onRemoteTrack(_, m)) : _.kind === "video" && this.onRemoteTrack(_, m);
|
|
631
647
|
};
|
|
632
|
-
const
|
|
633
|
-
var m, f,
|
|
634
|
-
const l = ((m = this.pc) == null ? void 0 : m.connectionState) === "connected" || ((f = this.pc) == null ? void 0 : f.iceConnectionState) === "connected" || ((
|
|
635
|
-
((M = this.pc) == null ? void 0 : M.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (
|
|
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());
|
|
636
652
|
};
|
|
637
|
-
this.pc.onconnectionstatechange =
|
|
653
|
+
this.pc.onconnectionstatechange = r, this.pc.oniceconnectionstatechange = r;
|
|
638
654
|
const o = this.getIceTrickleUrl();
|
|
639
655
|
this.pc.onicecandidate = (l) => {
|
|
640
656
|
l.candidate && fetch(o, {
|
|
@@ -644,9 +660,9 @@ const w = class w {
|
|
|
644
660
|
}).catch((_) => {
|
|
645
661
|
});
|
|
646
662
|
};
|
|
647
|
-
const
|
|
648
|
-
if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(
|
|
649
|
-
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, {
|
|
650
666
|
method: "POST",
|
|
651
667
|
headers: { "Content-Type": "application/json" },
|
|
652
668
|
body: JSON.stringify({
|
|
@@ -663,56 +679,56 @@ const w = class w {
|
|
|
663
679
|
const { answer: p } = await u.json();
|
|
664
680
|
if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(p), this.isConnectCancelled(e))) return;
|
|
665
681
|
this.startRemoteIcePolling(o);
|
|
666
|
-
} catch (
|
|
682
|
+
} catch (i) {
|
|
667
683
|
if (this.isConnectCancelled(e)) return;
|
|
668
|
-
throw this.disconnect(), this.onError(
|
|
684
|
+
throw this.disconnect(), this.onError(i.message || i), i;
|
|
669
685
|
}
|
|
670
686
|
}
|
|
671
687
|
}
|
|
672
688
|
createCallCacheKey(e, t) {
|
|
673
|
-
const
|
|
689
|
+
const i = this.apiKey ? `key:${this.apiKey.slice(0, 16)}` : `token:${(this.token || "").slice(-16)}`;
|
|
674
690
|
return [
|
|
675
691
|
this.backendUrl,
|
|
676
692
|
this.agentId,
|
|
677
693
|
e,
|
|
678
694
|
t || "",
|
|
679
695
|
this.prospectId || "",
|
|
680
|
-
|
|
696
|
+
i
|
|
681
697
|
].join("|");
|
|
682
698
|
}
|
|
683
|
-
async postCreateCall(e, t,
|
|
684
|
-
var
|
|
685
|
-
const
|
|
699
|
+
async postCreateCall(e, t, i) {
|
|
700
|
+
var h, s, u;
|
|
701
|
+
const n = await fetch(`${this.backendUrl}/calls/create`, {
|
|
686
702
|
method: "POST",
|
|
687
703
|
headers: e,
|
|
688
704
|
body: JSON.stringify({
|
|
689
705
|
agent_id: this.agentId,
|
|
690
|
-
type: ((
|
|
706
|
+
type: ((h = this.runtime) == null ? void 0 : h.callType) || "web",
|
|
691
707
|
mode: t,
|
|
692
|
-
...(
|
|
708
|
+
...(s = this.runtime) != null && s.runtimeName ? { runtime: this.runtime.runtimeName } : {},
|
|
693
709
|
prospect_id: this.prospectId,
|
|
694
|
-
...
|
|
710
|
+
...i ? { call_id: i } : {}
|
|
695
711
|
})
|
|
696
712
|
});
|
|
697
|
-
if (!
|
|
698
|
-
const p = await
|
|
699
|
-
throw new Error(`[VaniraClient] createCall failed (${
|
|
713
|
+
if (!n.ok) {
|
|
714
|
+
const p = await n.json().catch(() => ({}));
|
|
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}`);
|
|
700
716
|
}
|
|
701
|
-
const
|
|
702
|
-
if (!
|
|
717
|
+
const r = await n.json();
|
|
718
|
+
if (!r.call_id || !r.worker_url)
|
|
703
719
|
throw new Error("[VaniraClient] /calls/create response missing call_id or worker_url");
|
|
704
|
-
const o =
|
|
720
|
+
const o = y.normalizeIceServers(r.ice_servers);
|
|
705
721
|
if (!o.length)
|
|
706
722
|
throw new Error("[VaniraClient] /calls/create response missing ice_servers");
|
|
707
723
|
return {
|
|
708
|
-
callId:
|
|
709
|
-
prospectId:
|
|
710
|
-
serverUrl:
|
|
724
|
+
callId: r.call_id,
|
|
725
|
+
prospectId: r.prospect_id || this.prospectId,
|
|
726
|
+
serverUrl: r.worker_url.replace(/\/$/, ""),
|
|
711
727
|
iceServers: o
|
|
712
728
|
};
|
|
713
729
|
}
|
|
714
730
|
applyCreateCallSession(e) {
|
|
715
|
-
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)
|
|
716
732
|
try {
|
|
717
733
|
this.onSessionStarted({ prospectId: this.prospectId, callId: this.callId, serverUrl: this.serverUrl }), this.sessionStartedEmitted = !0;
|
|
718
734
|
} catch {
|
|
@@ -728,12 +744,12 @@ const w = class w {
|
|
|
728
744
|
throw new Error("[VaniraClient] apiKey or token is required to create a call session");
|
|
729
745
|
const e = { "Content-Type": "application/json" };
|
|
730
746
|
this.apiKey ? e["X-API-Key"] = this.apiKey : this.token && (e.Authorization = this.token.startsWith("Bearer ") ? this.token : `Bearer ${this.token}`);
|
|
731
|
-
const t = this.sessionBehavior === "continue" ? this.callId : void 0,
|
|
732
|
-
let
|
|
733
|
-
|
|
734
|
-
|
|
747
|
+
const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new", n = this.createCallCacheKey(i, t);
|
|
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);
|
|
735
751
|
}));
|
|
736
|
-
const o = await
|
|
752
|
+
const o = await r;
|
|
737
753
|
this.applyCreateCallSession(o);
|
|
738
754
|
}
|
|
739
755
|
getIceServers() {
|
|
@@ -744,11 +760,11 @@ const w = class w {
|
|
|
744
760
|
static normalizeIceServers(e) {
|
|
745
761
|
if (!Array.isArray(e)) return [];
|
|
746
762
|
const t = [];
|
|
747
|
-
for (const
|
|
748
|
-
const
|
|
749
|
-
if (!
|
|
750
|
-
const o = { urls:
|
|
751
|
-
|
|
763
|
+
for (const i of e) {
|
|
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);
|
|
752
768
|
}
|
|
753
769
|
return t;
|
|
754
770
|
}
|
|
@@ -786,13 +802,13 @@ const w = class w {
|
|
|
786
802
|
try {
|
|
787
803
|
const t = await fetch(e);
|
|
788
804
|
if (!t.ok) return;
|
|
789
|
-
const { candidates:
|
|
790
|
-
for (const
|
|
791
|
-
const
|
|
792
|
-
if (!this.appliedRemoteCandidates.has(
|
|
793
|
-
this.appliedRemoteCandidates.add(
|
|
805
|
+
const { candidates: i } = await t.json();
|
|
806
|
+
for (const n of i || []) {
|
|
807
|
+
const r = JSON.stringify(n);
|
|
808
|
+
if (!this.appliedRemoteCandidates.has(r)) {
|
|
809
|
+
this.appliedRemoteCandidates.add(r);
|
|
794
810
|
try {
|
|
795
|
-
await this.pc.addIceCandidate(
|
|
811
|
+
await this.pc.addIceCandidate(n);
|
|
796
812
|
} catch {
|
|
797
813
|
}
|
|
798
814
|
}
|
|
@@ -808,18 +824,18 @@ const w = class w {
|
|
|
808
824
|
* Send control event via DataChannel
|
|
809
825
|
*/
|
|
810
826
|
sendEvent(e, t = {}) {
|
|
811
|
-
var
|
|
812
|
-
if (((
|
|
813
|
-
const
|
|
814
|
-
this.dataChannel.send(JSON.stringify(
|
|
827
|
+
var i;
|
|
828
|
+
if (((i = this.dataChannel) == null ? void 0 : i.readyState) === "open") {
|
|
829
|
+
const n = { event: e, ...t };
|
|
830
|
+
this.dataChannel.send(JSON.stringify(n));
|
|
815
831
|
}
|
|
816
832
|
}
|
|
817
833
|
/** Wait for control DataChannel, then send (live vision lifecycle events). */
|
|
818
|
-
async sendEventWhenReady(e, t = {},
|
|
819
|
-
var
|
|
820
|
-
const
|
|
821
|
-
for (; Date.now() <
|
|
822
|
-
if (((
|
|
834
|
+
async sendEventWhenReady(e, t = {}, i = 1e4) {
|
|
835
|
+
var r;
|
|
836
|
+
const n = Date.now() + i;
|
|
837
|
+
for (; Date.now() < n; ) {
|
|
838
|
+
if (((r = this.dataChannel) == null ? void 0 : r.readyState) === "open")
|
|
823
839
|
return this.sendEvent(e, t), !0;
|
|
824
840
|
await new Promise((o) => setTimeout(o, 50));
|
|
825
841
|
}
|
|
@@ -836,7 +852,7 @@ const w = class w {
|
|
|
836
852
|
name: "open_live_camera",
|
|
837
853
|
tool_call_id: `lv_${crypto.randomUUID()}`,
|
|
838
854
|
execution_mode: "fire_and_forget",
|
|
839
|
-
client_fields: { preset_id:
|
|
855
|
+
client_fields: { preset_id: c.LiveVision },
|
|
840
856
|
arguments: {
|
|
841
857
|
mode: "live",
|
|
842
858
|
scope: t,
|
|
@@ -868,31 +884,31 @@ const w = class w {
|
|
|
868
884
|
case "mark":
|
|
869
885
|
break;
|
|
870
886
|
case "client_tool_cancel": {
|
|
871
|
-
const
|
|
872
|
-
this.dispatchBoardAbort("Tool cancelled by server",
|
|
887
|
+
const n = (e.data || e).tool_call_id || e.tool_call_id;
|
|
888
|
+
this.dispatchBoardAbort("Tool cancelled by server", n);
|
|
873
889
|
break;
|
|
874
890
|
}
|
|
875
891
|
case "client_tool_call": {
|
|
876
|
-
const
|
|
877
|
-
|
|
892
|
+
const i = e.tool_call || e.data || e, n = (i == null ? void 0 : i.tool_call_id) || (i == null ? void 0 : i.call_id) || e.tool_call_id || "";
|
|
893
|
+
n && ((t = this.dataChannel) == null ? void 0 : t.readyState) === "open" && this.dataChannel.send(JSON.stringify({
|
|
878
894
|
event: "client_tool_ack",
|
|
879
|
-
data: { tool_call_id:
|
|
895
|
+
data: { tool_call_id: n }
|
|
880
896
|
}));
|
|
881
|
-
const
|
|
882
|
-
if (
|
|
883
|
-
|
|
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") {
|
|
899
|
+
n && this.sendToolResult(n, {
|
|
884
900
|
status: "client_ack_end_call",
|
|
885
901
|
message: "Ending call."
|
|
886
902
|
}), window.setTimeout(() => this.disconnect(), 120);
|
|
887
903
|
break;
|
|
888
904
|
}
|
|
889
|
-
if (
|
|
905
|
+
if (s) {
|
|
890
906
|
window.dispatchEvent(new CustomEvent("vanira:preset", {
|
|
891
|
-
detail: { toolCall:
|
|
892
|
-
})), this.onClientToolCall(
|
|
907
|
+
detail: { toolCall: i, client: this }
|
|
908
|
+
})), this.onClientToolCall(i);
|
|
893
909
|
break;
|
|
894
910
|
}
|
|
895
|
-
this.onClientToolCall(
|
|
911
|
+
this.onClientToolCall(i);
|
|
896
912
|
break;
|
|
897
913
|
}
|
|
898
914
|
}
|
|
@@ -916,12 +932,12 @@ const w = class w {
|
|
|
916
932
|
* Uses track.enabled (not pause) so audio resumes correctly when unmuted.
|
|
917
933
|
*/
|
|
918
934
|
setMicrophoneMuted(e) {
|
|
919
|
-
var t,
|
|
920
|
-
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((
|
|
921
|
-
|
|
922
|
-
}), (
|
|
923
|
-
var
|
|
924
|
-
((
|
|
935
|
+
var t, i;
|
|
936
|
+
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((n) => {
|
|
937
|
+
n.enabled = !e;
|
|
938
|
+
}), (i = this.pc) == null || i.getSenders().forEach((n) => {
|
|
939
|
+
var r;
|
|
940
|
+
((r = n.track) == null ? void 0 : r.kind) === "audio" && (n.track.enabled = !e);
|
|
925
941
|
});
|
|
926
942
|
}
|
|
927
943
|
isMicrophoneMuted() {
|
|
@@ -991,6 +1007,25 @@ const w = class w {
|
|
|
991
1007
|
triggerActionInterrupt() {
|
|
992
1008
|
this.sendEvent("action_interrupt");
|
|
993
1009
|
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Notify the server that uploaded media should enter the AI vision context (process_media).
|
|
1012
|
+
* Send after client_tool_result for blocking presets that also upload a snapshot.
|
|
1013
|
+
*/
|
|
1014
|
+
sendMediaUpdate(e) {
|
|
1015
|
+
if (!this.dataChannel || this.dataChannel.readyState !== "open")
|
|
1016
|
+
return !1;
|
|
1017
|
+
const t = {
|
|
1018
|
+
event: "client_media_update",
|
|
1019
|
+
data: {
|
|
1020
|
+
media_id: e.media_id,
|
|
1021
|
+
media_url: e.media_url,
|
|
1022
|
+
content_type: e.content_type,
|
|
1023
|
+
reason: e.reason,
|
|
1024
|
+
message: e.message ?? ""
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
return this.dataChannel.send(JSON.stringify(t)), !0;
|
|
1028
|
+
}
|
|
994
1029
|
/**
|
|
995
1030
|
* Upload file to media server without notifying the AI (no client_media_update).
|
|
996
1031
|
* Use for blocking presets — result goes in client_tool_result only.
|
|
@@ -1006,8 +1041,8 @@ const w = class w {
|
|
|
1006
1041
|
* @param reason Routing key for backend processing (default: 'general')
|
|
1007
1042
|
* @param message Optional user text message about the file
|
|
1008
1043
|
*/
|
|
1009
|
-
async uploadMedia(e, t = "general",
|
|
1010
|
-
return await
|
|
1044
|
+
async uploadMedia(e, t = "general", i = "") {
|
|
1045
|
+
return await de(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t, i) : (le(this.dataChannel, this.mediaBytesChannel), this._uploadMediaViaHTTP(e, t, i));
|
|
1011
1046
|
}
|
|
1012
1047
|
/**
|
|
1013
1048
|
* Upload a live vision / screen frame — HTTP only for now, never sends client_media_update.
|
|
@@ -1016,79 +1051,72 @@ const w = class w {
|
|
|
1016
1051
|
* Frames require a real media_url (server rejects empty). WebRTC upload returns url="" until
|
|
1017
1052
|
* the server adds client_media_upload_ready ack — use HTTP for frame JPEGs until then.
|
|
1018
1053
|
*/
|
|
1019
|
-
async uploadMediaFrame(e, t = "camera_capture",
|
|
1020
|
-
const
|
|
1021
|
-
if (!
|
|
1054
|
+
async uploadMediaFrame(e, t = "camera_capture", i) {
|
|
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)
|
|
1022
1057
|
throw new Error("Frame upload failed: server response missing media_id or url");
|
|
1023
|
-
return { media_id:
|
|
1058
|
+
return { media_id: r, url: o, content_type: h };
|
|
1024
1059
|
}
|
|
1025
1060
|
/** WebRTC media-bytes path (control start/complete + binary chunks). */
|
|
1026
|
-
async _uploadBytesViaDataChannel(e, t,
|
|
1061
|
+
async _uploadBytesViaDataChannel(e, t, i, n, r) {
|
|
1027
1062
|
if (!this.callId || !this.mediaBytesChannel)
|
|
1028
1063
|
throw new Error("Upload failed: call not ready for WebRTC media upload.");
|
|
1029
|
-
const o =
|
|
1030
|
-
return
|
|
1031
|
-
bytes:
|
|
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);
|
|
1065
|
+
return he({
|
|
1066
|
+
bytes: s,
|
|
1032
1067
|
filename: o,
|
|
1033
|
-
contentType:
|
|
1068
|
+
contentType: h,
|
|
1034
1069
|
reason: t,
|
|
1035
|
-
message:
|
|
1070
|
+
message: i,
|
|
1036
1071
|
callId: this.callId,
|
|
1037
1072
|
mediaBytesChannel: this.mediaBytesChannel,
|
|
1038
1073
|
sendControlEvent: (u, p) => this.sendEvent(u, p),
|
|
1039
|
-
uploadKind:
|
|
1074
|
+
uploadKind: n
|
|
1040
1075
|
});
|
|
1041
1076
|
}
|
|
1042
|
-
async _uploadMediaViaDataChannel(e, t,
|
|
1043
|
-
const
|
|
1044
|
-
return { media_id:
|
|
1077
|
+
async _uploadMediaViaDataChannel(e, t, i) {
|
|
1078
|
+
const n = await this._uploadBytesViaDataChannel(e, t, i, "media");
|
|
1079
|
+
return { media_id: n.media_id, url: n.url };
|
|
1045
1080
|
}
|
|
1046
1081
|
/** HTTP fallback — original uploadMedia behavior (unchanged). */
|
|
1047
|
-
async _uploadMediaViaHTTP(e, t = "general",
|
|
1048
|
-
const { media_id:
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
reason: t,
|
|
1057
|
-
message: n
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
this.dataChannel.send(JSON.stringify(c));
|
|
1061
|
-
}
|
|
1062
|
-
return { media_id: i, url: s };
|
|
1082
|
+
async _uploadMediaViaHTTP(e, t = "general", i = "") {
|
|
1083
|
+
const { media_id: n, url: r, contentType: o } = await this._postMediaUpload(e, t, !0);
|
|
1084
|
+
return this.sendMediaUpdate({
|
|
1085
|
+
media_id: n,
|
|
1086
|
+
media_url: r,
|
|
1087
|
+
content_type: o,
|
|
1088
|
+
reason: t,
|
|
1089
|
+
message: i
|
|
1090
|
+
}), { media_id: n, url: r };
|
|
1063
1091
|
}
|
|
1064
|
-
async _postMediaUpload(e, t,
|
|
1092
|
+
async _postMediaUpload(e, t, i = !1) {
|
|
1065
1093
|
if (!this.serverUrl)
|
|
1066
1094
|
throw new Error("Upload failed: serverUrl is not set. Connect the VaniraClient first.");
|
|
1067
1095
|
if (!this.callId)
|
|
1068
1096
|
throw new Error("Upload failed: callId is missing.");
|
|
1069
|
-
const
|
|
1070
|
-
if (!
|
|
1097
|
+
const n = this.getWorkerOrigin();
|
|
1098
|
+
if (!n)
|
|
1071
1099
|
throw new Error(
|
|
1072
1100
|
"Upload failed: worker_url is not set. Connect the call before uploading media."
|
|
1073
1101
|
);
|
|
1074
|
-
const
|
|
1102
|
+
const r = `${n}/media/upload`, o = new FormData();
|
|
1075
1103
|
o.append("file", e), o.append("call_id", this.callId), o.append("reason", t);
|
|
1076
|
-
const
|
|
1104
|
+
const h = await fetch(r, {
|
|
1077
1105
|
method: "POST",
|
|
1078
1106
|
body: o
|
|
1079
1107
|
});
|
|
1080
|
-
if (!
|
|
1081
|
-
let _ = `HTTP ${
|
|
1108
|
+
if (!h.ok) {
|
|
1109
|
+
let _ = `HTTP ${h.status}`;
|
|
1082
1110
|
try {
|
|
1083
|
-
_ = (await
|
|
1111
|
+
_ = (await h.json()).error || _;
|
|
1084
1112
|
} catch {
|
|
1085
1113
|
}
|
|
1086
1114
|
throw new Error(`Upload failed: ${_}`);
|
|
1087
1115
|
}
|
|
1088
|
-
const
|
|
1116
|
+
const s = await h.json(), u = s.media_id, p = s.url, l = s.content_type || e.type;
|
|
1089
1117
|
if (!u || !p)
|
|
1090
1118
|
throw new Error("Upload failed: server response missing media_id or url");
|
|
1091
|
-
return
|
|
1119
|
+
return i ? { media_id: u, url: p, contentType: l } : { media_id: u, url: p, contentType: l };
|
|
1092
1120
|
}
|
|
1093
1121
|
// ─── Event emitter (replaces retired VaniraAI) ───────────────────────────
|
|
1094
1122
|
get status() {
|
|
@@ -1101,12 +1129,12 @@ const w = class w {
|
|
|
1101
1129
|
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), this;
|
|
1102
1130
|
}
|
|
1103
1131
|
off(e, t) {
|
|
1104
|
-
var
|
|
1105
|
-
return (
|
|
1132
|
+
var i;
|
|
1133
|
+
return (i = this.listeners.get(e)) == null || i.delete(t), this;
|
|
1106
1134
|
}
|
|
1107
1135
|
emit(e, t) {
|
|
1108
|
-
var
|
|
1109
|
-
(
|
|
1136
|
+
var i;
|
|
1137
|
+
(i = this.listeners.get(e)) == null || i.forEach((n) => n(t));
|
|
1110
1138
|
}
|
|
1111
1139
|
/** Alias for connect() — VaniraAI compatibility */
|
|
1112
1140
|
async start() {
|
|
@@ -1136,9 +1164,9 @@ const w = class w {
|
|
|
1136
1164
|
}
|
|
1137
1165
|
};
|
|
1138
1166
|
/** Dedupes concurrent POST /calls/create (e.g. React StrictMode double-mount). */
|
|
1139
|
-
d(
|
|
1140
|
-
let R =
|
|
1141
|
-
const
|
|
1167
|
+
d(y, "inflightCreates", /* @__PURE__ */ new Map());
|
|
1168
|
+
let R = y;
|
|
1169
|
+
const me = {
|
|
1142
1170
|
supportsAudioEndedEvent: !1,
|
|
1143
1171
|
supportsScreenShare: !1,
|
|
1144
1172
|
supportsDom: !1,
|
|
@@ -1146,40 +1174,40 @@ const _e = {
|
|
|
1146
1174
|
supportsCustomElements: !1,
|
|
1147
1175
|
supportsLocalStorage: !1,
|
|
1148
1176
|
supportsBroadcastChannel: !1
|
|
1149
|
-
},
|
|
1177
|
+
}, fe = {
|
|
1150
1178
|
name: "react-native",
|
|
1151
1179
|
callType: "web",
|
|
1152
1180
|
runtimeName: "react-native",
|
|
1153
1181
|
callIdPrefix: "rn_",
|
|
1154
|
-
capabilities:
|
|
1155
|
-
audio: new
|
|
1156
|
-
media: new
|
|
1157
|
-
peer: new
|
|
1158
|
-
dataChannel: new
|
|
1182
|
+
capabilities: me,
|
|
1183
|
+
audio: new Y(),
|
|
1184
|
+
media: new q(),
|
|
1185
|
+
peer: new X(),
|
|
1186
|
+
dataChannel: new Z()
|
|
1159
1187
|
};
|
|
1160
1188
|
function J(a) {
|
|
1161
1189
|
return new R({
|
|
1162
1190
|
...a,
|
|
1163
|
-
runtime:
|
|
1191
|
+
runtime: fe
|
|
1164
1192
|
});
|
|
1165
1193
|
}
|
|
1166
1194
|
const Se = J;
|
|
1167
|
-
function
|
|
1195
|
+
function ye(a) {
|
|
1168
1196
|
return J(a);
|
|
1169
1197
|
}
|
|
1170
|
-
const ve =
|
|
1198
|
+
const ve = ye;
|
|
1171
1199
|
export {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1200
|
+
Y as RNAudioAdapter,
|
|
1201
|
+
Z as RNDataChannelAdapter,
|
|
1202
|
+
q as RNMediaAdapter,
|
|
1203
|
+
X as RNPeerAdapter,
|
|
1176
1204
|
R as VaniraAI,
|
|
1177
1205
|
R as VaniraClient,
|
|
1178
1206
|
R as WebRTCClient,
|
|
1179
1207
|
Se as createReactNativeAI,
|
|
1180
1208
|
J as createReactNativeClient,
|
|
1181
1209
|
ve as createVaniraAI,
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1210
|
+
ye as createVaniraClient,
|
|
1211
|
+
me as reactNativeCapabilities,
|
|
1212
|
+
fe as reactNativeRuntime
|
|
1185
1213
|
};
|