@vanira/sdk 0.0.88 → 0.0.91
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 +226 -112
- package/dist/headless/index.js +17383 -13142
- package/dist/platforms/browser.cjs +9 -9
- package/dist/platforms/browser.js +685 -672
- package/dist/platforms/react-native.cjs +2 -2
- package/dist/platforms/react-native.js +317 -304
- package/dist/vanira-sdk.es.js +17795 -13546
- package/dist/vanira-sdk.js +258 -144
- package/dist/vanira-sdk.umd.js +268 -154
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var q = Object.defineProperty;
|
|
2
|
-
var X = (
|
|
3
|
-
var d = (
|
|
2
|
+
var X = (a, e, t) => e in a ? q(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => X(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
class Z {
|
|
5
5
|
pause() {
|
|
6
6
|
}
|
|
@@ -41,8 +41,8 @@ class te {
|
|
|
41
41
|
}
|
|
42
42
|
if (i.data instanceof ArrayBuffer) {
|
|
43
43
|
try {
|
|
44
|
-
const
|
|
45
|
-
(r == null ? void 0 : r.event) === "client_tool_call" && t.onMessage({ text:
|
|
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 te {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const ie = "https://api.vanira.io",
|
|
63
|
+
const ie = "https://api.vanira.io", s = {
|
|
64
64
|
Form: "vanira_form",
|
|
65
65
|
Calendar: "vanira_calendar",
|
|
66
66
|
Navigate: "vanira_navigate",
|
|
@@ -87,143 +87,156 @@ const ie = "https://api.vanira.io", c = {
|
|
|
87
87
|
KycDocumentCapture: "vanira_kyc_document_capture",
|
|
88
88
|
KycSelfieCapture: "vanira_kyc_selfie_capture",
|
|
89
89
|
KycSignatureCapture: "vanira_kyc_signature_capture"
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
}, ae = Object.values(s), ne = new Set(ae), re = /* @__PURE__ */ new Set([
|
|
91
|
+
s.KycDocumentCapture,
|
|
92
|
+
s.KycSelfieCapture,
|
|
93
|
+
s.KycSignatureCapture
|
|
94
|
+
]);
|
|
95
|
+
[
|
|
96
|
+
...re,
|
|
97
|
+
s.Form,
|
|
98
|
+
s.Upload,
|
|
99
|
+
s.Camera,
|
|
100
|
+
s.ClipRegion,
|
|
101
|
+
s.ScreenVision,
|
|
102
|
+
s.Navigate
|
|
103
|
+
];
|
|
104
|
+
function B(a) {
|
|
105
|
+
return !!a && ne.has(a);
|
|
93
106
|
}
|
|
94
|
-
function J(
|
|
95
|
-
if (typeof
|
|
107
|
+
function J(a) {
|
|
108
|
+
if (typeof a == "string")
|
|
96
109
|
try {
|
|
97
|
-
return JSON.parse(
|
|
110
|
+
return JSON.parse(a);
|
|
98
111
|
} catch {
|
|
99
112
|
return {};
|
|
100
113
|
}
|
|
101
|
-
return
|
|
114
|
+
return a && typeof a == "object" ? a : {};
|
|
102
115
|
}
|
|
103
116
|
const $ = {
|
|
104
|
-
type_on_whiteboard:
|
|
105
|
-
write_on_whiteboard:
|
|
106
|
-
write_on_white_board:
|
|
107
|
-
dom_typing_simulation:
|
|
108
|
-
write_latex_text:
|
|
109
|
-
write_latex_on_board:
|
|
110
|
-
latex_on_whiteboard:
|
|
111
|
-
show_geogebra:
|
|
112
|
-
geogebra_diagram:
|
|
113
|
-
geogebra:
|
|
114
|
-
erase_text:
|
|
115
|
-
dom_erase:
|
|
116
|
-
open_live_camera:
|
|
117
|
-
live_vision:
|
|
118
|
-
close_live_camera:
|
|
119
|
-
stop_live_camera:
|
|
120
|
-
open_live_screen:
|
|
121
|
-
close_live_screen:
|
|
122
|
-
screen_vision:
|
|
123
|
-
capture_screen_vision:
|
|
124
|
-
capture_screen:
|
|
125
|
-
tab_screenshot:
|
|
126
|
-
capture_tab:
|
|
127
|
-
capture_tab_screenshot:
|
|
128
|
-
screenshot_tab:
|
|
129
|
-
point_at:
|
|
130
|
-
point_at_screen:
|
|
131
|
-
draw_on_screen:
|
|
132
|
-
screen_draw:
|
|
133
|
-
clear_screen_draw:
|
|
134
|
-
clear_screen_annotations:
|
|
135
|
-
highlight_on_screen:
|
|
136
|
-
highlight_element_on_screen:
|
|
137
|
-
highlight_screen_element:
|
|
138
|
-
kyc_document_capture:
|
|
139
|
-
capture_id_document:
|
|
140
|
-
document_capture:
|
|
141
|
-
capture_kyc_document:
|
|
142
|
-
kyc_selfie_capture:
|
|
143
|
-
capture_selfie:
|
|
144
|
-
selfie_capture:
|
|
145
|
-
capture_kyc_selfie:
|
|
146
|
-
kyc_signature_capture:
|
|
147
|
-
capture_kyc_signature:
|
|
148
|
-
signature_capture:
|
|
117
|
+
type_on_whiteboard: s.TypeText,
|
|
118
|
+
write_on_whiteboard: s.TypeText,
|
|
119
|
+
write_on_white_board: s.TypeText,
|
|
120
|
+
dom_typing_simulation: s.TypeText,
|
|
121
|
+
write_latex_text: s.WriteLatexText,
|
|
122
|
+
write_latex_on_board: s.WriteLatexText,
|
|
123
|
+
latex_on_whiteboard: s.WriteLatexText,
|
|
124
|
+
show_geogebra: s.GeoGebra,
|
|
125
|
+
geogebra_diagram: s.GeoGebra,
|
|
126
|
+
geogebra: s.GeoGebra,
|
|
127
|
+
erase_text: s.EraseText,
|
|
128
|
+
dom_erase: s.EraseText,
|
|
129
|
+
open_live_camera: s.LiveVision,
|
|
130
|
+
live_vision: s.LiveVision,
|
|
131
|
+
close_live_camera: s.CloseLiveCamera,
|
|
132
|
+
stop_live_camera: s.CloseLiveCamera,
|
|
133
|
+
open_live_screen: s.LiveScreen,
|
|
134
|
+
close_live_screen: s.CloseLiveScreen,
|
|
135
|
+
screen_vision: s.ScreenVision,
|
|
136
|
+
capture_screen_vision: s.ScreenVision,
|
|
137
|
+
capture_screen: s.ScreenVision,
|
|
138
|
+
tab_screenshot: s.ScreenVision,
|
|
139
|
+
capture_tab: s.ScreenVision,
|
|
140
|
+
capture_tab_screenshot: s.ScreenVision,
|
|
141
|
+
screenshot_tab: s.ScreenVision,
|
|
142
|
+
point_at: s.PointAt,
|
|
143
|
+
point_at_screen: s.PointAt,
|
|
144
|
+
draw_on_screen: s.DrawOnScreen,
|
|
145
|
+
screen_draw: s.DrawOnScreen,
|
|
146
|
+
clear_screen_draw: s.ClearScreenDraw,
|
|
147
|
+
clear_screen_annotations: s.ClearScreenDraw,
|
|
148
|
+
highlight_on_screen: s.HighlightOnScreen,
|
|
149
|
+
highlight_element_on_screen: s.HighlightOnScreen,
|
|
150
|
+
highlight_screen_element: s.HighlightOnScreen,
|
|
151
|
+
kyc_document_capture: s.KycDocumentCapture,
|
|
152
|
+
capture_id_document: s.KycDocumentCapture,
|
|
153
|
+
document_capture: s.KycDocumentCapture,
|
|
154
|
+
capture_kyc_document: s.KycDocumentCapture,
|
|
155
|
+
kyc_selfie_capture: s.KycSelfieCapture,
|
|
156
|
+
capture_selfie: s.KycSelfieCapture,
|
|
157
|
+
selfie_capture: s.KycSelfieCapture,
|
|
158
|
+
capture_kyc_selfie: s.KycSelfieCapture,
|
|
159
|
+
kyc_signature_capture: s.KycSignatureCapture,
|
|
160
|
+
capture_kyc_signature: s.KycSignatureCapture,
|
|
161
|
+
signature_capture: s.KycSignatureCapture
|
|
149
162
|
}, j = {
|
|
150
|
-
vanira_tab_screenshot:
|
|
151
|
-
vanira_document_capture:
|
|
152
|
-
vanira_selfie_capture:
|
|
153
|
-
vanira_signature_capture:
|
|
154
|
-
vanira_kyc_signature:
|
|
163
|
+
vanira_tab_screenshot: s.ScreenVision,
|
|
164
|
+
vanira_document_capture: s.KycDocumentCapture,
|
|
165
|
+
vanira_selfie_capture: s.KycSelfieCapture,
|
|
166
|
+
vanira_signature_capture: s.KycSignatureCapture,
|
|
167
|
+
vanira_kyc_signature: s.KycSignatureCapture
|
|
155
168
|
};
|
|
156
|
-
function
|
|
157
|
-
const t =
|
|
169
|
+
function se(a, e) {
|
|
170
|
+
const t = a.commands ?? (e == null ? void 0 : e.commands) ?? a.construction ?? (e == null ? void 0 : e.construction) ?? a.geogebra_commands ?? (e == null ? void 0 : e.geogebra_commands) ?? a.script ?? (e == null ? void 0 : e.script);
|
|
158
171
|
return Array.isArray(t) ? t.some((i) => String(i).trim().length > 0) : typeof t == "string" && t.trim().length > 0;
|
|
159
172
|
}
|
|
160
|
-
function
|
|
161
|
-
const t =
|
|
173
|
+
function oe(a, e) {
|
|
174
|
+
const t = a.material_id ?? (e == null ? void 0 : e.material_id) ?? a.materialId ?? (e == null ? void 0 : e.materialId);
|
|
162
175
|
return typeof t == "string" && t.trim().length > 0;
|
|
163
176
|
}
|
|
164
|
-
function
|
|
165
|
-
const t =
|
|
177
|
+
function ce(a, e) {
|
|
178
|
+
const t = a.latex_text ?? (e == null ? void 0 : e.latex_text);
|
|
166
179
|
return typeof t == "string" && t.trim().length > 0;
|
|
167
180
|
}
|
|
168
|
-
function G(
|
|
169
|
-
const t =
|
|
181
|
+
function G(a, e) {
|
|
182
|
+
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);
|
|
170
183
|
return typeof t == "string" && t.trim().length > 0;
|
|
171
184
|
}
|
|
172
|
-
function
|
|
173
|
-
const t =
|
|
185
|
+
function le(a, e) {
|
|
186
|
+
const t = a.fields ?? (e == null ? void 0 : e.fields);
|
|
174
187
|
return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((i) => i.trim()).filter(Boolean).length > 0 : !1;
|
|
175
188
|
}
|
|
176
|
-
function
|
|
177
|
-
const t =
|
|
189
|
+
function de(a, e) {
|
|
190
|
+
const t = a == null ? void 0 : a.preset_id;
|
|
178
191
|
if (typeof t == "string") {
|
|
179
|
-
if (
|
|
192
|
+
if (B(t)) return t;
|
|
180
193
|
const r = j[t];
|
|
181
194
|
if (r) return r;
|
|
182
195
|
}
|
|
183
|
-
const
|
|
184
|
-
if (typeof
|
|
185
|
-
if (
|
|
186
|
-
const r = j[
|
|
196
|
+
const n = J(e).preset_id;
|
|
197
|
+
if (typeof n == "string") {
|
|
198
|
+
if (B(n)) return n;
|
|
199
|
+
const r = j[n];
|
|
187
200
|
if (r) return r;
|
|
188
201
|
}
|
|
189
202
|
}
|
|
190
|
-
function
|
|
203
|
+
function he(a, e, t) {
|
|
191
204
|
const i = J(e);
|
|
192
|
-
let
|
|
193
|
-
if (
|
|
194
|
-
return
|
|
195
|
-
if (
|
|
205
|
+
let n = de(a, i);
|
|
206
|
+
if (n === s.Form && G(i, a) && !le(i, a))
|
|
207
|
+
return s.TypeText;
|
|
208
|
+
if (n) return n;
|
|
196
209
|
const r = String(t ?? "").trim().toLowerCase();
|
|
197
210
|
if (r && $[r])
|
|
198
211
|
return $[r];
|
|
199
|
-
if (
|
|
200
|
-
return
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
-
if (G(i,
|
|
204
|
-
return
|
|
212
|
+
if (se(i, a) || oe(i, a))
|
|
213
|
+
return s.GeoGebra;
|
|
214
|
+
if (ce(i, a))
|
|
215
|
+
return s.WriteLatexText;
|
|
216
|
+
if (G(i, a))
|
|
217
|
+
return s.TypeText;
|
|
205
218
|
}
|
|
206
|
-
const
|
|
207
|
-
function
|
|
208
|
-
return `vanira_latest_call_id_${
|
|
219
|
+
const T = "vanira_latest_call_id", k = "vanira_prospect_id";
|
|
220
|
+
function I(a) {
|
|
221
|
+
return `vanira_latest_call_id_${a}`;
|
|
209
222
|
}
|
|
210
|
-
function b(
|
|
211
|
-
return `vanira_prospect_id_${
|
|
223
|
+
function b(a) {
|
|
224
|
+
return `vanira_prospect_id_${a}`;
|
|
212
225
|
}
|
|
213
|
-
function z(
|
|
214
|
-
return `vanira_call_meta_${
|
|
226
|
+
function z(a) {
|
|
227
|
+
return `vanira_call_meta_${a}`;
|
|
215
228
|
}
|
|
216
|
-
function S(
|
|
217
|
-
if (!
|
|
229
|
+
function S(a, e) {
|
|
230
|
+
if (!a) return null;
|
|
218
231
|
try {
|
|
219
|
-
return
|
|
232
|
+
return a.getItem(e);
|
|
220
233
|
} catch {
|
|
221
234
|
return null;
|
|
222
235
|
}
|
|
223
236
|
}
|
|
224
|
-
function W(
|
|
225
|
-
if (typeof window > "u" || !
|
|
226
|
-
const e = [], t = S(window.localStorage, z(
|
|
237
|
+
function W(a) {
|
|
238
|
+
if (typeof window > "u" || !a) return null;
|
|
239
|
+
const e = [], t = S(window.localStorage, z(a));
|
|
227
240
|
if (t)
|
|
228
241
|
try {
|
|
229
242
|
const h = JSON.parse(t);
|
|
@@ -234,89 +247,89 @@ function W(n) {
|
|
|
234
247
|
});
|
|
235
248
|
} catch {
|
|
236
249
|
}
|
|
237
|
-
const i = (h, _,
|
|
250
|
+
const i = (h, _, o) => {
|
|
238
251
|
h && e.push({
|
|
239
252
|
callId: h,
|
|
240
253
|
prospectId: _ || void 0,
|
|
241
|
-
updatedAt:
|
|
254
|
+
updatedAt: o
|
|
242
255
|
});
|
|
243
|
-
},
|
|
256
|
+
}, n = S(window.localStorage, b(a)), r = S(window.sessionStorage, b(a)), c = S(window.localStorage, k);
|
|
244
257
|
return i(
|
|
245
|
-
S(window.localStorage,
|
|
246
|
-
|
|
258
|
+
S(window.localStorage, I(a)),
|
|
259
|
+
n || c,
|
|
247
260
|
2
|
|
248
261
|
), i(
|
|
249
|
-
S(window.sessionStorage,
|
|
250
|
-
r ||
|
|
262
|
+
S(window.sessionStorage, I(a)),
|
|
263
|
+
r || c,
|
|
251
264
|
1
|
|
252
|
-
), i(S(window.localStorage,
|
|
265
|
+
), i(S(window.localStorage, T), c, 0), i(S(window.sessionStorage, T), c, 0), e.length ? (e.sort((h, _) => _.updatedAt - h.updatedAt), e[0]) : null;
|
|
253
266
|
}
|
|
254
|
-
function
|
|
255
|
-
var
|
|
256
|
-
if (typeof window > "u" || !
|
|
267
|
+
function ue(a, e, t) {
|
|
268
|
+
var n, r, c, h, _, o, u, l, p;
|
|
269
|
+
if (typeof window > "u" || !a || !e) return;
|
|
257
270
|
const i = {
|
|
258
271
|
callId: e,
|
|
259
272
|
prospectId: t,
|
|
260
273
|
updatedAt: Date.now()
|
|
261
274
|
};
|
|
262
275
|
try {
|
|
263
|
-
(
|
|
276
|
+
(n = window.localStorage) == null || n.setItem(z(a), JSON.stringify(i)), (r = window.localStorage) == null || r.setItem(I(a), e), (c = window.sessionStorage) == null || c.setItem(I(a), e), t && ((h = window.localStorage) == null || h.setItem(b(a), t), (_ = window.sessionStorage) == null || _.setItem(b(a), t)), (o = window.localStorage) == null || o.setItem(T, e), (u = window.sessionStorage) == null || u.setItem(T, e), t && ((l = window.localStorage) == null || l.setItem(k, t), (p = window.sessionStorage) == null || p.setItem(k, t));
|
|
264
277
|
} catch {
|
|
265
278
|
}
|
|
266
279
|
}
|
|
267
|
-
const
|
|
280
|
+
const pe = /* @__PURE__ */ new Set([
|
|
268
281
|
"client_tool_call",
|
|
269
282
|
"clearAudio",
|
|
270
283
|
"client_tool_cancel"
|
|
271
284
|
]);
|
|
272
|
-
function
|
|
273
|
-
if (!
|
|
274
|
-
const e =
|
|
275
|
-
return typeof e == "string" &&
|
|
285
|
+
function _e(a) {
|
|
286
|
+
if (!a || typeof a != "object") return !1;
|
|
287
|
+
const e = a.event;
|
|
288
|
+
return typeof e == "string" && pe.has(e);
|
|
276
289
|
}
|
|
277
|
-
const x = 16 * 1024,
|
|
278
|
-
function E(
|
|
279
|
-
return (
|
|
290
|
+
const x = 16 * 1024, me = 256 * 1024;
|
|
291
|
+
function E(a, e) {
|
|
292
|
+
return (a == null ? void 0 : a.readyState) === "open" && (e == null ? void 0 : e.readyState) === "open";
|
|
280
293
|
}
|
|
281
|
-
function
|
|
294
|
+
function fe(a, e) {
|
|
282
295
|
return {
|
|
283
|
-
control: (
|
|
296
|
+
control: (a == null ? void 0 : a.readyState) ?? "missing",
|
|
284
297
|
mediaBytes: (e == null ? void 0 : e.readyState) ?? "missing"
|
|
285
298
|
};
|
|
286
299
|
}
|
|
287
|
-
async function
|
|
288
|
-
if (E(
|
|
300
|
+
async function ye(a, e, t = 8e3) {
|
|
301
|
+
if (E(a, e))
|
|
289
302
|
return !0;
|
|
290
303
|
const i = Date.now() + t;
|
|
291
304
|
for (; Date.now() < i; ) {
|
|
292
|
-
if (E(
|
|
305
|
+
if (E(a, e))
|
|
293
306
|
return !0;
|
|
294
|
-
await new Promise((
|
|
307
|
+
await new Promise((n) => setTimeout(n, 50));
|
|
295
308
|
}
|
|
296
|
-
return E(
|
|
309
|
+
return E(a, e);
|
|
297
310
|
}
|
|
298
|
-
async function H(
|
|
299
|
-
for (;
|
|
311
|
+
async function H(a) {
|
|
312
|
+
for (; a.bufferedAmount > me; )
|
|
300
313
|
await new Promise((e) => setTimeout(e, 10));
|
|
301
314
|
}
|
|
302
|
-
async function
|
|
315
|
+
async function Se(a) {
|
|
303
316
|
const {
|
|
304
317
|
bytes: e,
|
|
305
318
|
filename: t,
|
|
306
319
|
contentType: i,
|
|
307
|
-
reason:
|
|
320
|
+
reason: n,
|
|
308
321
|
message: r,
|
|
309
|
-
callId:
|
|
322
|
+
callId: c,
|
|
310
323
|
mediaBytesChannel: h,
|
|
311
324
|
sendControlEvent: _,
|
|
312
|
-
uploadId:
|
|
325
|
+
uploadId: o = crypto.randomUUID(),
|
|
313
326
|
uploadKind: u = "media"
|
|
314
|
-
} =
|
|
327
|
+
} = a, l = e.byteLength, p = l === 0 ? 0 : Math.ceil(l / x);
|
|
315
328
|
_("client_media_upload_start", {
|
|
316
329
|
data: {
|
|
317
|
-
upload_id:
|
|
318
|
-
call_id:
|
|
319
|
-
reason:
|
|
330
|
+
upload_id: o,
|
|
331
|
+
call_id: c,
|
|
332
|
+
reason: n,
|
|
320
333
|
message: r,
|
|
321
334
|
filename: t,
|
|
322
335
|
content_type: i,
|
|
@@ -333,37 +346,37 @@ async function ye(n) {
|
|
|
333
346
|
}
|
|
334
347
|
return await H(h), _("client_media_upload_complete", {
|
|
335
348
|
data: {
|
|
336
|
-
upload_id:
|
|
337
|
-
call_id:
|
|
338
|
-
reason:
|
|
349
|
+
upload_id: o,
|
|
350
|
+
call_id: c,
|
|
351
|
+
reason: n,
|
|
339
352
|
message: r,
|
|
340
353
|
chunk_count: p,
|
|
341
354
|
upload_kind: u
|
|
342
355
|
}
|
|
343
|
-
}), { media_id:
|
|
356
|
+
}), { media_id: o, url: "", content_type: i };
|
|
344
357
|
}
|
|
345
|
-
async function
|
|
346
|
-
return typeof
|
|
358
|
+
async function we(a) {
|
|
359
|
+
return typeof a.arrayBuffer == "function" ? a.arrayBuffer() : new Response(a).arrayBuffer();
|
|
347
360
|
}
|
|
348
|
-
const
|
|
361
|
+
const ge = 15e3, R = "vanira-connect-stall-prompt";
|
|
349
362
|
let v = null;
|
|
350
|
-
function
|
|
363
|
+
function ve(a = ge) {
|
|
351
364
|
typeof window > "u" || (g(!1), v = setTimeout(() => {
|
|
352
|
-
v = null,
|
|
353
|
-
},
|
|
365
|
+
v = null, Ce(), window.dispatchEvent(new CustomEvent("vanira:connect-stall"));
|
|
366
|
+
}, a));
|
|
354
367
|
}
|
|
355
|
-
function g(
|
|
356
|
-
v !== null && (clearTimeout(v), v = null),
|
|
368
|
+
function g(a = !0) {
|
|
369
|
+
v !== null && (clearTimeout(v), v = null), a && P();
|
|
357
370
|
}
|
|
358
371
|
function P() {
|
|
359
|
-
var
|
|
360
|
-
typeof document > "u" || (
|
|
372
|
+
var a;
|
|
373
|
+
typeof document > "u" || (a = document.getElementById(R)) == null || a.remove();
|
|
361
374
|
}
|
|
362
|
-
function
|
|
375
|
+
function Ce() {
|
|
363
376
|
var t, i;
|
|
364
377
|
if (typeof document > "u" || document.getElementById(R)) return;
|
|
365
|
-
const
|
|
366
|
-
|
|
378
|
+
const a = document.createElement("div");
|
|
379
|
+
a.id = R, a.setAttribute("role", "alertdialog"), a.setAttribute("aria-modal", "true"), a.setAttribute("aria-labelledby", "vanira-stall-title"), a.style.cssText = [
|
|
367
380
|
"position:fixed",
|
|
368
381
|
"inset:0",
|
|
369
382
|
"z-index:2147483646",
|
|
@@ -399,11 +412,11 @@ function ve() {
|
|
|
399
412
|
<p style="margin:12px 0 0;font-size:12px;color:#888">
|
|
400
413
|
Tip: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac)
|
|
401
414
|
</p>
|
|
402
|
-
`,
|
|
415
|
+
`, a.appendChild(e), document.body.appendChild(a), (t = e.querySelector("#vanira-stall-refresh")) == null || t.addEventListener("click", () => {
|
|
403
416
|
P(), window.location.reload();
|
|
404
417
|
}), (i = e.querySelector("#vanira-stall-dismiss")) == null || i.addEventListener("click", () => P());
|
|
405
418
|
}
|
|
406
|
-
function
|
|
419
|
+
function Te(a) {
|
|
407
420
|
return null;
|
|
408
421
|
}
|
|
409
422
|
function C() {
|
|
@@ -454,24 +467,24 @@ class Ie {
|
|
|
454
467
|
}
|
|
455
468
|
}
|
|
456
469
|
attachListeners() {
|
|
457
|
-
const e = (r,
|
|
470
|
+
const e = (r, c = 0) => {
|
|
458
471
|
const h = () => {
|
|
459
472
|
const _ = C();
|
|
460
473
|
_ !== this.lastRoute && this.handleRouteChange(_, r);
|
|
461
474
|
};
|
|
462
|
-
|
|
463
|
-
}, t = () => e("popstate"), i = () => e("hashchange"),
|
|
464
|
-
const
|
|
465
|
-
if ((
|
|
475
|
+
c > 0 ? window.setTimeout(h, c) : queueMicrotask(h);
|
|
476
|
+
}, t = () => e("popstate"), i = () => e("hashchange"), n = (r) => {
|
|
477
|
+
const c = r.detail;
|
|
478
|
+
if ((c == null ? void 0 : c.initiated_by) === "agent") {
|
|
466
479
|
e("vanira_navigate_agent", 120);
|
|
467
480
|
return;
|
|
468
481
|
}
|
|
469
482
|
e("vanira_navigate", 120);
|
|
470
483
|
};
|
|
471
|
-
window.addEventListener("popstate", t), window.addEventListener("hashchange", i), window.addEventListener("vanira:navigate",
|
|
484
|
+
window.addEventListener("popstate", t), window.addEventListener("hashchange", i), window.addEventListener("vanira:navigate", n), this.cleanupFns.push(
|
|
472
485
|
() => window.removeEventListener("popstate", t),
|
|
473
486
|
() => window.removeEventListener("hashchange", i),
|
|
474
|
-
() => window.removeEventListener("vanira:navigate",
|
|
487
|
+
() => window.removeEventListener("vanira:navigate", n)
|
|
475
488
|
), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...r) => {
|
|
476
489
|
this.originalPushState(...r), e("pushState");
|
|
477
490
|
}, history.replaceState = (...r) => {
|
|
@@ -490,21 +503,21 @@ class Ie {
|
|
|
490
503
|
this.scheduleInitialContextSend();
|
|
491
504
|
return;
|
|
492
505
|
}
|
|
493
|
-
!this.isReady() ||
|
|
506
|
+
!this.isReady() || Te() || this.sendRouteContext("route_changed", i, t, "user");
|
|
494
507
|
}
|
|
495
|
-
sendRouteContext(e, t, i,
|
|
508
|
+
sendRouteContext(e, t, i, n = "user") {
|
|
496
509
|
const r = C();
|
|
497
510
|
this.lastRoute = r;
|
|
498
|
-
const
|
|
511
|
+
const c = {
|
|
499
512
|
ui_state: "page_navigation",
|
|
500
|
-
navigation_led_by:
|
|
513
|
+
navigation_led_by: n,
|
|
501
514
|
current_route: r,
|
|
502
515
|
current_page: r,
|
|
503
516
|
user_action: e === "call_started" ? "call_started_on_page" : "user_navigated"
|
|
504
517
|
};
|
|
505
|
-
e === "call_started" ?
|
|
518
|
+
e === "call_started" ? c.message = `User started the call while viewing ${r}.` : (c.previous_route = t ?? "", c.message = `User navigated from ${t || "(unknown)"} to ${r}.`, i && (c.navigation_source = i));
|
|
506
519
|
try {
|
|
507
|
-
this.sendContext(
|
|
520
|
+
this.sendContext(c);
|
|
508
521
|
} catch {
|
|
509
522
|
}
|
|
510
523
|
}
|
|
@@ -556,53 +569,53 @@ const y = class y {
|
|
|
556
569
|
d(this, "connectStallTimeoutMs");
|
|
557
570
|
var _;
|
|
558
571
|
if (!e.agentId) throw new Error("agentId is required");
|
|
559
|
-
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId),
|
|
572
|
+
const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), n = y.normalizeIceServers(
|
|
560
573
|
e.iceServers
|
|
561
574
|
);
|
|
562
575
|
if (!t && !i)
|
|
563
576
|
throw new Error(
|
|
564
577
|
"apiKey or token is required — or pass serverUrl and callId from a prior POST /calls/create"
|
|
565
578
|
);
|
|
566
|
-
this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.prospectName = e.prospectName, this.welcomeMessage = ((_ = e.welcomeMessage) == null ? void 0 : _.trim()) || void 0, this.extraDetails = e.extraDetails, this.backendUrl = (e.backendUrl || ie).replace(/\/$/, ""),
|
|
579
|
+
this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.prospectName = e.prospectName, this.welcomeMessage = ((_ = e.welcomeMessage) == null ? void 0 : _.trim()) || void 0, this.extraDetails = e.extraDetails, this.backendUrl = (e.backendUrl || ie).replace(/\/$/, ""), n.length && (this.iceServers = n), i && (this.callSessionLoaded = !0);
|
|
567
580
|
const r = typeof window < "u";
|
|
568
581
|
this.prospectId = e.prospectId;
|
|
569
|
-
const
|
|
570
|
-
if (
|
|
571
|
-
const
|
|
572
|
-
|
|
582
|
+
const c = e.sessionBehavior === "continue";
|
|
583
|
+
if (c && r && !e.callId) {
|
|
584
|
+
const o = W(this.agentId);
|
|
585
|
+
o && (e.callId || (this.callId = o.callId), !this.prospectId && o.prospectId && (this.prospectId = o.prospectId));
|
|
573
586
|
}
|
|
574
587
|
if (!this.prospectId && r)
|
|
575
588
|
try {
|
|
576
|
-
const
|
|
577
|
-
this.prospectId = (
|
|
589
|
+
const o = W(this.agentId);
|
|
590
|
+
this.prospectId = (o == null ? void 0 : o.prospectId) || window.sessionStorage && window.sessionStorage.getItem("vanira_prospect_id") || window.localStorage && window.localStorage.getItem("vanira_prospect_id") || void 0;
|
|
578
591
|
} catch {
|
|
579
592
|
}
|
|
580
|
-
e.callId ? this.callId = e.callId :
|
|
593
|
+
e.callId ? this.callId = e.callId : c || (this.callId = void 0);
|
|
581
594
|
const h = e.onSessionStarted;
|
|
582
|
-
this.onSessionStarted = (
|
|
583
|
-
h == null || h(
|
|
595
|
+
this.onSessionStarted = (o) => {
|
|
596
|
+
h == null || h(o), this.emit("session_started", o);
|
|
584
597
|
}, this.liveVision = e.liveVision, this.connectStallTimeoutMs = e.connectStallTimeoutMs ?? 15e3, this.onConnected = () => {
|
|
585
|
-
var
|
|
586
|
-
g(), this._status = "connected", (
|
|
598
|
+
var o;
|
|
599
|
+
g(), this._status = "connected", (o = e.onConnected) == null || o.call(e), this.emit("connected"), this.maybeAutoStartLiveCamera();
|
|
587
600
|
}, this.onDisconnected = () => {
|
|
588
|
-
var
|
|
589
|
-
g(), this._status = "disconnected", (
|
|
590
|
-
}, this.onError = (
|
|
601
|
+
var o;
|
|
602
|
+
g(), this._status = "disconnected", (o = e.onDisconnected) == null || o.call(e), this.emit("disconnected");
|
|
603
|
+
}, this.onError = (o) => {
|
|
591
604
|
var l;
|
|
592
605
|
g(), this._status = "error";
|
|
593
|
-
const u = typeof
|
|
594
|
-
(l = e.onError) == null || l.call(e,
|
|
595
|
-
}, this.onTranscription = (
|
|
606
|
+
const u = typeof o == "string" ? o : (o == null ? void 0 : o.message) || "Connection error";
|
|
607
|
+
(l = e.onError) == null || l.call(e, o), this.emit("error", u);
|
|
608
|
+
}, this.onTranscription = (o, u, l) => {
|
|
596
609
|
var p;
|
|
597
|
-
(p = e.onTranscription) == null || p.call(e,
|
|
610
|
+
(p = e.onTranscription) == null || p.call(e, o, u), this.emit("transcription", { text: o, isFinal: u, role: l });
|
|
598
611
|
}, this.onLocalStream = e.onLocalStream || (() => {
|
|
599
|
-
}), this.onRemoteTrack = (
|
|
612
|
+
}), this.onRemoteTrack = (o, u) => {
|
|
600
613
|
var l;
|
|
601
|
-
(l = e.onRemoteTrack) == null || l.call(e,
|
|
602
|
-
}, this.onClientToolCall = (
|
|
614
|
+
(l = e.onRemoteTrack) == null || l.call(e, o, u), this.emit("track", { track: o, stream: u });
|
|
615
|
+
}, this.onClientToolCall = (o) => {
|
|
603
616
|
var p;
|
|
604
|
-
(p = e.onClientToolCall) == null || p.call(e,
|
|
605
|
-
const u = (
|
|
617
|
+
(p = e.onClientToolCall) == null || p.call(e, o);
|
|
618
|
+
const u = (o == null ? void 0 : o.data) || o, l = {
|
|
606
619
|
name: String(u.name || u.tool_name || ""),
|
|
607
620
|
arguments: u.arguments || u.args || {},
|
|
608
621
|
tool_call_id: String(u.tool_call_id || u.call_id || ""),
|
|
@@ -611,10 +624,10 @@ const y = class y {
|
|
|
611
624
|
};
|
|
612
625
|
l.name && l.tool_call_id && this.emit("tool_call", l);
|
|
613
626
|
}, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new Ie({
|
|
614
|
-
sendContext: (
|
|
627
|
+
sendContext: (o) => this.sendContextUpdate(o),
|
|
615
628
|
isReady: () => {
|
|
616
|
-
var
|
|
617
|
-
return ((
|
|
629
|
+
var o;
|
|
630
|
+
return ((o = this.dataChannel) == null ? void 0 : o.readyState) === "open";
|
|
618
631
|
}
|
|
619
632
|
}));
|
|
620
633
|
}
|
|
@@ -636,7 +649,7 @@ const y = class y {
|
|
|
636
649
|
*/
|
|
637
650
|
async connect() {
|
|
638
651
|
var t;
|
|
639
|
-
this._status = "connecting", this.connectStallTimeoutMs > 0 &&
|
|
652
|
+
this._status = "connecting", this.connectStallTimeoutMs > 0 && ve(this.connectStallTimeoutMs);
|
|
640
653
|
const e = ++this.connectGeneration;
|
|
641
654
|
if (await this.loadCallSession(), !this.isConnectCancelled(e)) {
|
|
642
655
|
if (!this.serverUrl)
|
|
@@ -655,9 +668,9 @@ const y = class y {
|
|
|
655
668
|
iceServers: i,
|
|
656
669
|
iceTransportPolicy: "all"
|
|
657
670
|
});
|
|
658
|
-
let
|
|
671
|
+
let n;
|
|
659
672
|
try {
|
|
660
|
-
|
|
673
|
+
n = await navigator.mediaDevices.getUserMedia({
|
|
661
674
|
audio: {
|
|
662
675
|
echoCancellation: !0,
|
|
663
676
|
noiseSuppression: !0,
|
|
@@ -677,16 +690,16 @@ const y = class y {
|
|
|
677
690
|
throw l;
|
|
678
691
|
}
|
|
679
692
|
if (this.isConnectCancelled(e)) {
|
|
680
|
-
|
|
693
|
+
n.getTracks().forEach((l) => l.stop());
|
|
681
694
|
return;
|
|
682
695
|
}
|
|
683
|
-
if (this.localStream =
|
|
684
|
-
|
|
696
|
+
if (this.localStream = n, !this.pc || this.isConnectCancelled(e)) {
|
|
697
|
+
n.getTracks().forEach((l) => l.stop());
|
|
685
698
|
return;
|
|
686
699
|
}
|
|
687
|
-
if (this.onLocalStream(
|
|
700
|
+
if (this.onLocalStream(n), n.getTracks().forEach((l) => {
|
|
688
701
|
var p;
|
|
689
|
-
(p = this.pc) == null || p.addTrack(l,
|
|
702
|
+
(p = this.pc) == null || p.addTrack(l, n);
|
|
690
703
|
}), !this.pc)
|
|
691
704
|
throw new Error("RTCPeerConnection was closed unexpectedly");
|
|
692
705
|
this.dataChannel = this.pc.createDataChannel("control"), this.dataChannel.onopen = () => {
|
|
@@ -703,7 +716,7 @@ const y = class y {
|
|
|
703
716
|
const p = new TextDecoder().decode(l.data);
|
|
704
717
|
try {
|
|
705
718
|
const m = JSON.parse(p);
|
|
706
|
-
|
|
719
|
+
_e(m) && this.handleControlEvent(m);
|
|
707
720
|
} catch {
|
|
708
721
|
}
|
|
709
722
|
} catch {
|
|
@@ -725,18 +738,18 @@ const y = class y {
|
|
|
725
738
|
}, this.onRemoteTrack(p, m)) : p.kind === "video" && this.onRemoteTrack(p, m);
|
|
726
739
|
};
|
|
727
740
|
const r = () => {
|
|
728
|
-
var m, f, w, U, M, L, D, O, N, V,
|
|
741
|
+
var m, f, w, U, M, L, D, O, N, V, K;
|
|
729
742
|
const l = ((m = this.pc) == null ? void 0 : m.connectionState) === "connected" || ((f = this.pc) == null ? void 0 : f.iceConnectionState) === "connected" || ((w = this.pc) == null ? void 0 : w.iceConnectionState) === "completed", p = ((U = this.pc) == null ? void 0 : U.connectionState) === "failed" || ((M = this.pc) == null ? void 0 : M.iceConnectionState) === "failed" || ((L = this.pc) == null ? void 0 : L.connectionState) === "closed" || ((D = this.pc) == null ? void 0 : D.iceConnectionState) === "closed" || ((O = this.pc) == null ? void 0 : O.connectionState) === "disconnected" || ((N = this.pc) == null ? void 0 : N.iceConnectionState) === "disconnected";
|
|
730
|
-
((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (
|
|
743
|
+
((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (K = this.routeTracker) == null || K.start(), this.onConnected()) : p && this.connected && (this.connected = !1, this.liveVisionAutoStarted = !1, this.onDisconnected());
|
|
731
744
|
};
|
|
732
745
|
this.pc.onconnectionstatechange = r, this.pc.oniceconnectionstatechange = r;
|
|
733
|
-
const
|
|
746
|
+
const c = this.getIceTrickleUrl();
|
|
734
747
|
this.pc.onicecandidate = (l) => {
|
|
735
|
-
l.candidate && this.sendRemoteIceCandidate(l.candidate,
|
|
748
|
+
l.candidate && this.sendRemoteIceCandidate(l.candidate, c);
|
|
736
749
|
};
|
|
737
750
|
const h = await this.pc.createOffer();
|
|
738
751
|
if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(h), this.isConnectCancelled(e))) return;
|
|
739
|
-
const _ = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`,
|
|
752
|
+
const _ = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`, o = await fetch(_, {
|
|
740
753
|
method: "POST",
|
|
741
754
|
headers: { "Content-Type": "application/json" },
|
|
742
755
|
body: JSON.stringify({
|
|
@@ -746,13 +759,13 @@ const y = class y {
|
|
|
746
759
|
})
|
|
747
760
|
});
|
|
748
761
|
if (this.isConnectCancelled(e)) return;
|
|
749
|
-
if (!
|
|
750
|
-
const l = await
|
|
751
|
-
throw new Error(l.error || `HTTP ${
|
|
762
|
+
if (!o.ok) {
|
|
763
|
+
const l = await o.json();
|
|
764
|
+
throw new Error(l.error || `HTTP ${o.status}`);
|
|
752
765
|
}
|
|
753
|
-
const { answer: u } = await
|
|
766
|
+
const { answer: u } = await o.json();
|
|
754
767
|
if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(u), this.isConnectCancelled(e)) || (this.remoteDescSet = !0, await this.flushPendingServerIce(), this.isConnectCancelled(e))) return;
|
|
755
|
-
this.startRemoteIcePolling(
|
|
768
|
+
this.startRemoteIcePolling(c);
|
|
756
769
|
} catch (i) {
|
|
757
770
|
if (this.isConnectCancelled(e)) return;
|
|
758
771
|
throw this.disconnect(), this.onError(i.message || i), i;
|
|
@@ -771,8 +784,8 @@ const y = class y {
|
|
|
771
784
|
].join("|");
|
|
772
785
|
}
|
|
773
786
|
async postCreateCall(e, t, i) {
|
|
774
|
-
var h, _,
|
|
775
|
-
const
|
|
787
|
+
var h, _, o;
|
|
788
|
+
const n = await fetch(`${this.backendUrl}/calls/create`, {
|
|
776
789
|
method: "POST",
|
|
777
790
|
headers: e,
|
|
778
791
|
body: JSON.stringify({
|
|
@@ -787,25 +800,25 @@ const y = class y {
|
|
|
787
800
|
...i ? { call_id: i } : {}
|
|
788
801
|
})
|
|
789
802
|
});
|
|
790
|
-
if (!
|
|
791
|
-
const u = await
|
|
792
|
-
throw new Error(`[VaniraClient] createCall failed (${
|
|
803
|
+
if (!n.ok) {
|
|
804
|
+
const u = await n.json().catch(() => ({}));
|
|
805
|
+
throw new Error(`[VaniraClient] createCall failed (${n.status}): ${((o = u == null ? void 0 : u.detail) == null ? void 0 : o.message) || (u == null ? void 0 : u.message) || n.statusText}`);
|
|
793
806
|
}
|
|
794
|
-
const r = await
|
|
807
|
+
const r = await n.json();
|
|
795
808
|
if (!r.call_id || !r.worker_url)
|
|
796
809
|
throw new Error("[VaniraClient] /calls/create response missing call_id or worker_url");
|
|
797
|
-
const
|
|
798
|
-
if (!
|
|
810
|
+
const c = y.normalizeIceServers(r.ice_servers);
|
|
811
|
+
if (!c.length)
|
|
799
812
|
throw new Error("[VaniraClient] /calls/create response missing ice_servers");
|
|
800
813
|
return {
|
|
801
814
|
callId: r.call_id,
|
|
802
815
|
prospectId: r.prospect_id || this.prospectId,
|
|
803
816
|
serverUrl: r.worker_url.replace(/\/$/, ""),
|
|
804
|
-
iceServers:
|
|
817
|
+
iceServers: c
|
|
805
818
|
};
|
|
806
819
|
}
|
|
807
820
|
applyCreateCallSession(e) {
|
|
808
|
-
if (this.callId = e.callId, this.prospectId = e.prospectId || this.prospectId, this.serverUrl = e.serverUrl, this.iceServers = e.iceServers, this.callSessionLoaded = !0,
|
|
821
|
+
if (this.callId = e.callId, this.prospectId = e.prospectId || this.prospectId, this.serverUrl = e.serverUrl, this.iceServers = e.iceServers, this.callSessionLoaded = !0, ue(this.agentId, this.callId || "", this.prospectId), this.onSessionStarted && this.prospectId && this.callId && !this.sessionStartedEmitted)
|
|
809
822
|
try {
|
|
810
823
|
this.onSessionStarted({ prospectId: this.prospectId, callId: this.callId, serverUrl: this.serverUrl }), this.sessionStartedEmitted = !0;
|
|
811
824
|
} catch {
|
|
@@ -821,13 +834,13 @@ const y = class y {
|
|
|
821
834
|
throw new Error("[VaniraClient] apiKey or token is required to create a call session");
|
|
822
835
|
const e = { "Content-Type": "application/json" };
|
|
823
836
|
this.apiKey ? e["X-API-Key"] = this.apiKey : this.token && (e.Authorization = this.token.startsWith("Bearer ") ? this.token : `Bearer ${this.token}`);
|
|
824
|
-
const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new",
|
|
825
|
-
let r = y.inflightCreates.get(
|
|
826
|
-
r || (r = this.postCreateCall(e, i, t), y.inflightCreates.set(
|
|
827
|
-
y.inflightCreates.get(
|
|
837
|
+
const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new", n = this.createCallCacheKey(i, t);
|
|
838
|
+
let r = y.inflightCreates.get(n);
|
|
839
|
+
r || (r = this.postCreateCall(e, i, t), y.inflightCreates.set(n, r), r.finally(() => {
|
|
840
|
+
y.inflightCreates.get(n) === r && y.inflightCreates.delete(n);
|
|
828
841
|
}));
|
|
829
|
-
const
|
|
830
|
-
this.applyCreateCallSession(
|
|
842
|
+
const c = await r;
|
|
843
|
+
this.applyCreateCallSession(c);
|
|
831
844
|
}
|
|
832
845
|
getIceServers() {
|
|
833
846
|
var e;
|
|
@@ -838,10 +851,10 @@ const y = class y {
|
|
|
838
851
|
if (!Array.isArray(e)) return [];
|
|
839
852
|
const t = [];
|
|
840
853
|
for (const i of e) {
|
|
841
|
-
const
|
|
854
|
+
const n = i == null ? void 0 : i.urls, r = Array.isArray(n) ? n.filter(Boolean) : typeof n == "string" && n.trim() ? [n.trim()] : [];
|
|
842
855
|
if (!r.length) continue;
|
|
843
|
-
const
|
|
844
|
-
h && (
|
|
856
|
+
const c = { urls: r.length === 1 ? r[0] : r }, h = i.username, _ = i.credential;
|
|
857
|
+
h && (c.username = h), _ && (c.credential = _), t.push(c);
|
|
845
858
|
}
|
|
846
859
|
return t;
|
|
847
860
|
}
|
|
@@ -874,8 +887,8 @@ const y = class y {
|
|
|
874
887
|
body: JSON.stringify({ candidate: e.toJSON() })
|
|
875
888
|
});
|
|
876
889
|
if (i.ok) {
|
|
877
|
-
const
|
|
878
|
-
await this.applyServerIceCandidates(
|
|
890
|
+
const n = await i.json();
|
|
891
|
+
await this.applyServerIceCandidates(n.candidates);
|
|
879
892
|
}
|
|
880
893
|
} catch {
|
|
881
894
|
}
|
|
@@ -921,13 +934,13 @@ const y = class y {
|
|
|
921
934
|
var i;
|
|
922
935
|
const t = Date.now() + 15e3;
|
|
923
936
|
for (; !this.icePollStop && Date.now() < t; ) {
|
|
924
|
-
const
|
|
925
|
-
if (
|
|
937
|
+
const n = (i = this.pc) == null ? void 0 : i.connectionState;
|
|
938
|
+
if (n === "connected" || n === "failed" || n === "closed") break;
|
|
926
939
|
try {
|
|
927
940
|
const r = await fetch(e, { method: "GET" });
|
|
928
941
|
if (r.ok) {
|
|
929
|
-
const
|
|
930
|
-
if (await this.applyServerIceCandidates(
|
|
942
|
+
const c = await r.json();
|
|
943
|
+
if (await this.applyServerIceCandidates(c.candidates), c.done && (!c.candidates || c.candidates.length === 0)) break;
|
|
931
944
|
}
|
|
932
945
|
} catch {
|
|
933
946
|
}
|
|
@@ -943,18 +956,18 @@ const y = class y {
|
|
|
943
956
|
sendEvent(e, t = {}) {
|
|
944
957
|
var i;
|
|
945
958
|
if (((i = this.dataChannel) == null ? void 0 : i.readyState) === "open") {
|
|
946
|
-
const
|
|
947
|
-
this.dataChannel.send(JSON.stringify(
|
|
959
|
+
const n = { event: e, ...t };
|
|
960
|
+
this.dataChannel.send(JSON.stringify(n));
|
|
948
961
|
}
|
|
949
962
|
}
|
|
950
963
|
/** Wait for control DataChannel, then send (live vision lifecycle events). */
|
|
951
964
|
async sendEventWhenReady(e, t = {}, i = 1e4) {
|
|
952
965
|
var r;
|
|
953
|
-
const
|
|
954
|
-
for (; Date.now() <
|
|
966
|
+
const n = Date.now() + i;
|
|
967
|
+
for (; Date.now() < n; ) {
|
|
955
968
|
if (((r = this.dataChannel) == null ? void 0 : r.readyState) === "open")
|
|
956
969
|
return this.sendEvent(e, t), !0;
|
|
957
|
-
await new Promise((
|
|
970
|
+
await new Promise((c) => setTimeout(c, 50));
|
|
958
971
|
}
|
|
959
972
|
return !1;
|
|
960
973
|
}
|
|
@@ -969,7 +982,7 @@ const y = class y {
|
|
|
969
982
|
name: "open_live_camera",
|
|
970
983
|
tool_call_id: `lv_${crypto.randomUUID()}`,
|
|
971
984
|
execution_mode: "fire_and_forget",
|
|
972
|
-
client_fields: { preset_id:
|
|
985
|
+
client_fields: { preset_id: s.LiveVision },
|
|
973
986
|
arguments: {
|
|
974
987
|
mode: "live",
|
|
975
988
|
scope: t,
|
|
@@ -997,33 +1010,33 @@ const y = class y {
|
|
|
997
1010
|
this.dispatchBoardAbort(
|
|
998
1011
|
"User interrupted while LaTeX was writing",
|
|
999
1012
|
void 0,
|
|
1000
|
-
|
|
1013
|
+
s.WriteLatexText
|
|
1001
1014
|
);
|
|
1002
1015
|
break;
|
|
1003
1016
|
case "transcription":
|
|
1004
1017
|
{
|
|
1005
|
-
const i = e.data && typeof e.data == "object" ? e.data : {},
|
|
1018
|
+
const i = e.data && typeof e.data == "object" ? e.data : {}, n = String(e.text ?? i.text ?? "").trim(), r = e.isFinal ?? e.is_final ?? i.isFinal ?? i.is_final, c = r === void 0 ? !0 : r === !0 || r === "true", h = String(
|
|
1006
1019
|
e.role ?? e.speaker ?? i.role ?? i.speaker ?? ""
|
|
1007
1020
|
).trim() || void 0;
|
|
1008
|
-
|
|
1021
|
+
n && this.onTranscription(n, c, h);
|
|
1009
1022
|
}
|
|
1010
1023
|
break;
|
|
1011
1024
|
case "mark":
|
|
1012
1025
|
break;
|
|
1013
1026
|
case "client_tool_cancel": {
|
|
1014
|
-
const
|
|
1015
|
-
this.dispatchBoardAbort("Tool cancelled by server",
|
|
1027
|
+
const n = (e.data || e).tool_call_id || e.tool_call_id;
|
|
1028
|
+
this.dispatchBoardAbort("Tool cancelled by server", n);
|
|
1016
1029
|
break;
|
|
1017
1030
|
}
|
|
1018
1031
|
case "client_tool_call": {
|
|
1019
|
-
const i = e.tool_call || e.data || e,
|
|
1020
|
-
|
|
1032
|
+
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 || "";
|
|
1033
|
+
n && ((t = this.dataChannel) == null ? void 0 : t.readyState) === "open" && this.dataChannel.send(JSON.stringify({
|
|
1021
1034
|
event: "client_tool_ack",
|
|
1022
|
-
data: { tool_call_id:
|
|
1035
|
+
data: { tool_call_id: n }
|
|
1023
1036
|
}));
|
|
1024
|
-
const r = (i == null ? void 0 : i.arguments) || (i == null ? void 0 : i.args) || {},
|
|
1037
|
+
const r = (i == null ? void 0 : i.arguments) || (i == null ? void 0 : i.args) || {}, c = (i == null ? void 0 : i.client_fields) || {}, h = (i == null ? void 0 : i.name) || (i == null ? void 0 : i.tool_name) || "", _ = he(c, r, h);
|
|
1025
1038
|
if (h === "end_call") {
|
|
1026
|
-
|
|
1039
|
+
n && this.sendToolResult(n, {
|
|
1027
1040
|
status: "client_ack_end_call",
|
|
1028
1041
|
message: "Ending call."
|
|
1029
1042
|
}), window.setTimeout(() => this.disconnect(), 120);
|
|
@@ -1060,11 +1073,11 @@ const y = class y {
|
|
|
1060
1073
|
*/
|
|
1061
1074
|
setMicrophoneMuted(e) {
|
|
1062
1075
|
var t, i;
|
|
1063
|
-
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((
|
|
1064
|
-
|
|
1065
|
-
}), (i = this.pc) == null || i.getSenders().forEach((
|
|
1076
|
+
this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((n) => {
|
|
1077
|
+
n.enabled = !e;
|
|
1078
|
+
}), (i = this.pc) == null || i.getSenders().forEach((n) => {
|
|
1066
1079
|
var r;
|
|
1067
|
-
((r =
|
|
1080
|
+
((r = n.track) == null ? void 0 : r.kind) === "audio" && (n.track.enabled = !e);
|
|
1068
1081
|
});
|
|
1069
1082
|
}
|
|
1070
1083
|
isMicrophoneMuted() {
|
|
@@ -1169,7 +1182,7 @@ const y = class y {
|
|
|
1169
1182
|
* @param message Optional user text message about the file
|
|
1170
1183
|
*/
|
|
1171
1184
|
async uploadMedia(e, t = "general", i = "") {
|
|
1172
|
-
return await
|
|
1185
|
+
return await ye(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t, i) : (fe(this.dataChannel, this.mediaBytesChannel), this._uploadMediaViaHTTP(e, t, i));
|
|
1173
1186
|
}
|
|
1174
1187
|
/**
|
|
1175
1188
|
* Upload a live vision / screen frame — HTTP only for now, never sends client_media_update.
|
|
@@ -1179,58 +1192,58 @@ const y = class y {
|
|
|
1179
1192
|
* the server adds client_media_upload_ready ack — use HTTP for frame JPEGs until then.
|
|
1180
1193
|
*/
|
|
1181
1194
|
async uploadMediaFrame(e, t = "camera_capture", i) {
|
|
1182
|
-
const
|
|
1183
|
-
if (!r || !
|
|
1195
|
+
const n = i && !(e instanceof File) ? new File([e], i, { type: e.type || "image/jpeg" }) : e, { media_id: r, url: c, contentType: h } = await this._postMediaUpload(n, t, !0);
|
|
1196
|
+
if (!r || !c)
|
|
1184
1197
|
throw new Error("Frame upload failed: server response missing media_id or url");
|
|
1185
|
-
return { media_id: r, url:
|
|
1198
|
+
return { media_id: r, url: c, content_type: h };
|
|
1186
1199
|
}
|
|
1187
1200
|
/** WebRTC media-bytes path (control start/complete + binary chunks). */
|
|
1188
|
-
async _uploadBytesViaDataChannel(e, t, i,
|
|
1201
|
+
async _uploadBytesViaDataChannel(e, t, i, n, r) {
|
|
1189
1202
|
if (!this.callId || !this.mediaBytesChannel)
|
|
1190
1203
|
throw new Error("Upload failed: call not ready for WebRTC media upload.");
|
|
1191
|
-
const
|
|
1192
|
-
return
|
|
1204
|
+
const c = r || (e instanceof File ? e.name : n === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (n === "frame" ? "image/jpeg" : "application/octet-stream"), _ = await we(e);
|
|
1205
|
+
return Se({
|
|
1193
1206
|
bytes: _,
|
|
1194
|
-
filename:
|
|
1207
|
+
filename: c,
|
|
1195
1208
|
contentType: h,
|
|
1196
1209
|
reason: t,
|
|
1197
1210
|
message: i,
|
|
1198
1211
|
callId: this.callId,
|
|
1199
1212
|
mediaBytesChannel: this.mediaBytesChannel,
|
|
1200
|
-
sendControlEvent: (
|
|
1201
|
-
uploadKind:
|
|
1213
|
+
sendControlEvent: (o, u) => this.sendEvent(o, u),
|
|
1214
|
+
uploadKind: n
|
|
1202
1215
|
});
|
|
1203
1216
|
}
|
|
1204
1217
|
async _uploadMediaViaDataChannel(e, t, i) {
|
|
1205
|
-
const
|
|
1206
|
-
return { media_id:
|
|
1218
|
+
const n = await this._uploadBytesViaDataChannel(e, t, i, "media");
|
|
1219
|
+
return { media_id: n.media_id, url: n.url };
|
|
1207
1220
|
}
|
|
1208
1221
|
/** HTTP fallback — original uploadMedia behavior (unchanged). */
|
|
1209
1222
|
async _uploadMediaViaHTTP(e, t = "general", i = "") {
|
|
1210
|
-
const { media_id:
|
|
1223
|
+
const { media_id: n, url: r, contentType: c } = await this._postMediaUpload(e, t, !0);
|
|
1211
1224
|
return this.sendMediaUpdate({
|
|
1212
|
-
media_id:
|
|
1225
|
+
media_id: n,
|
|
1213
1226
|
media_url: r,
|
|
1214
|
-
content_type:
|
|
1227
|
+
content_type: c,
|
|
1215
1228
|
reason: t,
|
|
1216
1229
|
message: i
|
|
1217
|
-
}), { media_id:
|
|
1230
|
+
}), { media_id: n, url: r };
|
|
1218
1231
|
}
|
|
1219
1232
|
async _postMediaUpload(e, t, i = !1) {
|
|
1220
1233
|
if (!this.serverUrl)
|
|
1221
1234
|
throw new Error("Upload failed: serverUrl is not set. Connect the VaniraClient first.");
|
|
1222
1235
|
if (!this.callId)
|
|
1223
1236
|
throw new Error("Upload failed: callId is missing.");
|
|
1224
|
-
const
|
|
1225
|
-
if (!
|
|
1237
|
+
const n = this.getWorkerOrigin();
|
|
1238
|
+
if (!n)
|
|
1226
1239
|
throw new Error(
|
|
1227
1240
|
"Upload failed: worker_url is not set. Connect the call before uploading media."
|
|
1228
1241
|
);
|
|
1229
|
-
const r = `${
|
|
1230
|
-
|
|
1242
|
+
const r = `${n}/media/upload`, c = new FormData();
|
|
1243
|
+
c.append("file", e), c.append("call_id", this.callId), c.append("reason", t);
|
|
1231
1244
|
const h = await fetch(r, {
|
|
1232
1245
|
method: "POST",
|
|
1233
|
-
body:
|
|
1246
|
+
body: c
|
|
1234
1247
|
});
|
|
1235
1248
|
if (!h.ok) {
|
|
1236
1249
|
let p = `HTTP ${h.status}`;
|
|
@@ -1240,10 +1253,10 @@ const y = class y {
|
|
|
1240
1253
|
}
|
|
1241
1254
|
throw new Error(`Upload failed: ${p}`);
|
|
1242
1255
|
}
|
|
1243
|
-
const _ = await h.json(),
|
|
1244
|
-
if (!
|
|
1256
|
+
const _ = await h.json(), o = _.media_id, u = _.url, l = _.content_type || e.type;
|
|
1257
|
+
if (!o || !u)
|
|
1245
1258
|
throw new Error("Upload failed: server response missing media_id or url");
|
|
1246
|
-
return i ? { media_id:
|
|
1259
|
+
return i ? { media_id: o, url: u, contentType: l } : { media_id: o, url: u, contentType: l };
|
|
1247
1260
|
}
|
|
1248
1261
|
// ─── Event emitter (replaces retired VaniraAI) ───────────────────────────
|
|
1249
1262
|
get status() {
|
|
@@ -1261,7 +1274,7 @@ const y = class y {
|
|
|
1261
1274
|
}
|
|
1262
1275
|
emit(e, t) {
|
|
1263
1276
|
var i;
|
|
1264
|
-
(i = this.listeners.get(e)) == null || i.forEach((
|
|
1277
|
+
(i = this.listeners.get(e)) == null || i.forEach((n) => n(t));
|
|
1265
1278
|
}
|
|
1266
1279
|
/** Alias for connect() — VaniraAI compatibility */
|
|
1267
1280
|
async start() {
|
|
@@ -1293,7 +1306,7 @@ const y = class y {
|
|
|
1293
1306
|
/** Dedupes concurrent POST /calls/create (e.g. React StrictMode double-mount). */
|
|
1294
1307
|
d(y, "inflightCreates", /* @__PURE__ */ new Map());
|
|
1295
1308
|
let A = y;
|
|
1296
|
-
const
|
|
1309
|
+
const be = {
|
|
1297
1310
|
supportsAudioEndedEvent: !1,
|
|
1298
1311
|
supportsScreenShare: !1,
|
|
1299
1312
|
supportsDom: !1,
|
|
@@ -1301,28 +1314,28 @@ const Te = {
|
|
|
1301
1314
|
supportsCustomElements: !1,
|
|
1302
1315
|
supportsLocalStorage: !1,
|
|
1303
1316
|
supportsBroadcastChannel: !1
|
|
1304
|
-
},
|
|
1317
|
+
}, xe = {
|
|
1305
1318
|
name: "react-native",
|
|
1306
1319
|
callType: "web",
|
|
1307
1320
|
runtimeName: "react-native",
|
|
1308
1321
|
callIdPrefix: "rn_",
|
|
1309
|
-
capabilities:
|
|
1322
|
+
capabilities: be,
|
|
1310
1323
|
audio: new Q(),
|
|
1311
1324
|
media: new F(),
|
|
1312
1325
|
peer: new ee(),
|
|
1313
1326
|
dataChannel: new te()
|
|
1314
1327
|
};
|
|
1315
|
-
function Y(
|
|
1328
|
+
function Y(a) {
|
|
1316
1329
|
return new A({
|
|
1317
|
-
...
|
|
1318
|
-
runtime:
|
|
1330
|
+
...a,
|
|
1331
|
+
runtime: xe
|
|
1319
1332
|
});
|
|
1320
1333
|
}
|
|
1321
|
-
const
|
|
1322
|
-
function
|
|
1323
|
-
return Y(
|
|
1334
|
+
const Re = Y;
|
|
1335
|
+
function Ee(a) {
|
|
1336
|
+
return Y(a);
|
|
1324
1337
|
}
|
|
1325
|
-
const
|
|
1338
|
+
const Pe = Ee;
|
|
1326
1339
|
export {
|
|
1327
1340
|
Q as RNAudioAdapter,
|
|
1328
1341
|
te as RNDataChannelAdapter,
|
|
@@ -1331,10 +1344,10 @@ export {
|
|
|
1331
1344
|
A as VaniraAI,
|
|
1332
1345
|
A as VaniraClient,
|
|
1333
1346
|
A as WebRTCClient,
|
|
1334
|
-
|
|
1347
|
+
Re as createReactNativeAI,
|
|
1335
1348
|
Y as createReactNativeClient,
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1349
|
+
Pe as createVaniraAI,
|
|
1350
|
+
Ee as createVaniraClient,
|
|
1351
|
+
be as reactNativeCapabilities,
|
|
1352
|
+
xe as reactNativeRuntime
|
|
1340
1353
|
};
|