@vanira/sdk 0.0.84 → 0.0.86

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