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