@vanira/sdk 0.0.87 → 0.0.88

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,6 +1,6 @@
1
1
  var q = Object.defineProperty;
2
- var X = (i, e, t) => e in i ? q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var l = (i, e, t) => X(i, typeof e != "symbol" ? e + "" : e, t);
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 = (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 a = new TextDecoder().decode(n.data), r = JSON.parse(a);
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(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 te {
60
60
  };
61
61
  }
62
62
  }
63
- const ne = "https://api.vanira.io", c = {
63
+ const ie = "https://api.vanira.io", c = {
64
64
  Form: "vanira_form",
65
65
  Calendar: "vanira_calendar",
66
66
  Navigate: "vanira_navigate",
@@ -87,18 +87,18 @@ 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
- }, ie = Object.values(c), ae = new Set(ie);
91
- function K(i) {
92
- return !!i && ae.has(i);
90
+ }, ne = Object.values(c), ae = new Set(ne);
91
+ function K(n) {
92
+ return !!n && ae.has(n);
93
93
  }
94
- function J(i) {
95
- if (typeof i == "string")
94
+ function J(n) {
95
+ if (typeof n == "string")
96
96
  try {
97
- return JSON.parse(i);
97
+ return JSON.parse(n);
98
98
  } catch {
99
99
  return {};
100
100
  }
101
- return i && typeof i == "object" ? i : {};
101
+ return n && typeof n == "object" ? n : {};
102
102
  }
103
103
  const $ = {
104
104
  type_on_whiteboard: c.TypeText,
@@ -153,28 +153,28 @@ const $ = {
153
153
  vanira_signature_capture: c.KycSignatureCapture,
154
154
  vanira_kyc_signature: c.KycSignatureCapture
155
155
  };
156
- function re(i, e) {
157
- const t = i.commands ?? (e == null ? void 0 : e.commands) ?? i.construction ?? (e == null ? void 0 : e.construction) ?? i.geogebra_commands ?? (e == null ? void 0 : e.geogebra_commands) ?? i.script ?? (e == null ? void 0 : e.script);
158
- return Array.isArray(t) ? t.some((n) => String(n).trim().length > 0) : typeof t == "string" && t.trim().length > 0;
156
+ function re(n, e) {
157
+ 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);
158
+ return Array.isArray(t) ? t.some((i) => String(i).trim().length > 0) : typeof t == "string" && t.trim().length > 0;
159
159
  }
160
- function se(i, e) {
161
- const t = i.material_id ?? (e == null ? void 0 : e.material_id) ?? i.materialId ?? (e == null ? void 0 : e.materialId);
160
+ function se(n, e) {
161
+ const t = n.material_id ?? (e == null ? void 0 : e.material_id) ?? n.materialId ?? (e == null ? void 0 : e.materialId);
162
162
  return typeof t == "string" && t.trim().length > 0;
163
163
  }
164
- function oe(i, e) {
165
- const t = i.latex_text ?? (e == null ? void 0 : e.latex_text);
164
+ function oe(n, e) {
165
+ const t = n.latex_text ?? (e == null ? void 0 : e.latex_text);
166
166
  return typeof t == "string" && t.trim().length > 0;
167
167
  }
168
- function G(i, e) {
169
- const t = i.text_to_type ?? (e == null ? void 0 : e.text_to_type) ?? i.text ?? (e == null ? void 0 : e.text) ?? i.value ?? (e == null ? void 0 : e.value);
168
+ function G(n, e) {
169
+ 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
170
  return typeof t == "string" && t.trim().length > 0;
171
171
  }
172
- function ce(i, e) {
173
- const t = i.fields ?? (e == null ? void 0 : e.fields);
174
- return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((n) => n.trim()).filter(Boolean).length > 0 : !1;
172
+ function ce(n, e) {
173
+ const t = n.fields ?? (e == null ? void 0 : e.fields);
174
+ return Array.isArray(t) ? t.length > 0 : typeof t == "string" ? t.split(",").map((i) => i.trim()).filter(Boolean).length > 0 : !1;
175
175
  }
176
- function le(i, e) {
177
- const t = i == null ? void 0 : i.preset_id;
176
+ function le(n, e) {
177
+ const t = n == null ? void 0 : n.preset_id;
178
178
  if (typeof t == "string") {
179
179
  if (K(t)) return t;
180
180
  const r = j[t];
@@ -187,43 +187,43 @@ function le(i, e) {
187
187
  if (r) return r;
188
188
  }
189
189
  }
190
- function de(i, e, t) {
191
- const n = J(e);
192
- let a = le(i, n);
193
- if (a === c.Form && G(n, i) && !ce(n, i))
190
+ function de(n, e, t) {
191
+ const i = J(e);
192
+ let a = le(n, i);
193
+ if (a === c.Form && G(i, n) && !ce(i, n))
194
194
  return c.TypeText;
195
195
  if (a) return a;
196
196
  const r = String(t ?? "").trim().toLowerCase();
197
197
  if (r && $[r])
198
198
  return $[r];
199
- if (re(n, i) || se(n, i))
199
+ if (re(i, n) || se(i, n))
200
200
  return c.GeoGebra;
201
- if (oe(n, i))
201
+ if (oe(i, n))
202
202
  return c.WriteLatexText;
203
- if (G(n, i))
203
+ if (G(i, n))
204
204
  return c.TypeText;
205
205
  }
206
206
  const I = "vanira_latest_call_id", k = "vanira_prospect_id";
207
- function T(i) {
208
- return `vanira_latest_call_id_${i}`;
207
+ function T(n) {
208
+ return `vanira_latest_call_id_${n}`;
209
209
  }
210
- function b(i) {
211
- return `vanira_prospect_id_${i}`;
210
+ function b(n) {
211
+ return `vanira_prospect_id_${n}`;
212
212
  }
213
- function z(i) {
214
- return `vanira_call_meta_${i}`;
213
+ function z(n) {
214
+ return `vanira_call_meta_${n}`;
215
215
  }
216
- function S(i, e) {
217
- if (!i) return null;
216
+ function S(n, e) {
217
+ if (!n) return null;
218
218
  try {
219
- return i.getItem(e);
219
+ return n.getItem(e);
220
220
  } catch {
221
221
  return null;
222
222
  }
223
223
  }
224
- function W(i) {
225
- if (typeof window > "u" || !i) return null;
226
- const e = [], t = S(window.localStorage, z(i));
224
+ function W(n) {
225
+ if (typeof window > "u" || !n) return null;
226
+ const e = [], t = S(window.localStorage, z(n));
227
227
  if (t)
228
228
  try {
229
229
  const h = JSON.parse(t);
@@ -234,33 +234,33 @@ function W(i) {
234
234
  });
235
235
  } catch {
236
236
  }
237
- const n = (h, s, u) => {
237
+ const i = (h, _, s) => {
238
238
  h && e.push({
239
239
  callId: h,
240
- prospectId: s || void 0,
241
- updatedAt: u
240
+ prospectId: _ || void 0,
241
+ updatedAt: s
242
242
  });
243
- }, a = S(window.localStorage, b(i)), r = S(window.sessionStorage, b(i)), o = S(window.localStorage, k);
244
- return n(
245
- S(window.localStorage, T(i)),
243
+ }, a = S(window.localStorage, b(n)), r = S(window.sessionStorage, b(n)), o = S(window.localStorage, k);
244
+ return i(
245
+ S(window.localStorage, T(n)),
246
246
  a || o,
247
247
  2
248
- ), n(
249
- S(window.sessionStorage, T(i)),
248
+ ), i(
249
+ S(window.sessionStorage, T(n)),
250
250
  r || o,
251
251
  1
252
- ), n(S(window.localStorage, I), o, 0), n(S(window.sessionStorage, I), o, 0), e.length ? (e.sort((h, s) => s.updatedAt - h.updatedAt), e[0]) : null;
252
+ ), i(S(window.localStorage, I), o, 0), i(S(window.sessionStorage, I), o, 0), e.length ? (e.sort((h, _) => _.updatedAt - h.updatedAt), e[0]) : null;
253
253
  }
254
- function he(i, e, t) {
255
- var a, r, o, h, s, u, p, d, _;
256
- if (typeof window > "u" || !i || !e) return;
257
- const n = {
254
+ function he(n, e, t) {
255
+ var a, r, o, h, _, s, u, l, p;
256
+ if (typeof window > "u" || !n || !e) return;
257
+ const i = {
258
258
  callId: e,
259
259
  prospectId: t,
260
260
  updatedAt: Date.now()
261
261
  };
262
262
  try {
263
- (a = window.localStorage) == null || a.setItem(z(i), JSON.stringify(n)), (r = window.localStorage) == null || r.setItem(T(i), e), (o = window.sessionStorage) == null || o.setItem(T(i), e), t && ((h = window.localStorage) == null || h.setItem(b(i), t), (s = window.sessionStorage) == null || s.setItem(b(i), t)), (u = window.localStorage) == null || u.setItem(I, e), (p = window.sessionStorage) == null || p.setItem(I, e), t && ((d = window.localStorage) == null || d.setItem(k, t), (_ = window.sessionStorage) == null || _.setItem(k, t));
263
+ (a = window.localStorage) == null || a.setItem(z(n), JSON.stringify(i)), (r = window.localStorage) == null || r.setItem(T(n), e), (o = window.sessionStorage) == null || o.setItem(T(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(I, e), (u = window.sessionStorage) == null || u.setItem(I, e), t && ((l = window.localStorage) == null || l.setItem(k, t), (p = window.sessionStorage) == null || p.setItem(k, t));
264
264
  } catch {
265
265
  }
266
266
  }
@@ -269,101 +269,101 @@ const ue = /* @__PURE__ */ new Set([
269
269
  "clearAudio",
270
270
  "client_tool_cancel"
271
271
  ]);
272
- function pe(i) {
273
- if (!i || typeof i != "object") return !1;
274
- const e = i.event;
272
+ function pe(n) {
273
+ if (!n || typeof n != "object") return !1;
274
+ const e = n.event;
275
275
  return typeof e == "string" && ue.has(e);
276
276
  }
277
277
  const x = 16 * 1024, _e = 256 * 1024;
278
- function E(i, e) {
279
- return (i == null ? void 0 : i.readyState) === "open" && (e == null ? void 0 : e.readyState) === "open";
278
+ function E(n, e) {
279
+ return (n == null ? void 0 : n.readyState) === "open" && (e == null ? void 0 : e.readyState) === "open";
280
280
  }
281
- function me(i, e) {
281
+ function me(n, e) {
282
282
  return {
283
- control: (i == null ? void 0 : i.readyState) ?? "missing",
283
+ control: (n == null ? void 0 : n.readyState) ?? "missing",
284
284
  mediaBytes: (e == null ? void 0 : e.readyState) ?? "missing"
285
285
  };
286
286
  }
287
- async function fe(i, e, t = 8e3) {
288
- if (E(i, e))
287
+ async function fe(n, e, t = 8e3) {
288
+ if (E(n, e))
289
289
  return !0;
290
- const n = Date.now() + t;
291
- for (; Date.now() < n; ) {
292
- if (E(i, e))
290
+ const i = Date.now() + t;
291
+ for (; Date.now() < i; ) {
292
+ if (E(n, e))
293
293
  return !0;
294
294
  await new Promise((a) => setTimeout(a, 50));
295
295
  }
296
- return E(i, e);
296
+ return E(n, e);
297
297
  }
298
- async function H(i) {
299
- for (; i.bufferedAmount > _e; )
298
+ async function H(n) {
299
+ for (; n.bufferedAmount > _e; )
300
300
  await new Promise((e) => setTimeout(e, 10));
301
301
  }
302
- async function ye(i) {
302
+ async function ye(n) {
303
303
  const {
304
304
  bytes: e,
305
305
  filename: t,
306
- contentType: n,
306
+ contentType: i,
307
307
  reason: a,
308
308
  message: r,
309
309
  callId: o,
310
310
  mediaBytesChannel: h,
311
- sendControlEvent: s,
312
- uploadId: u = crypto.randomUUID(),
313
- uploadKind: p = "media"
314
- } = i, d = e.byteLength, _ = d === 0 ? 0 : Math.ceil(d / x);
315
- s("client_media_upload_start", {
311
+ sendControlEvent: _,
312
+ uploadId: s = crypto.randomUUID(),
313
+ uploadKind: u = "media"
314
+ } = n, l = e.byteLength, p = l === 0 ? 0 : Math.ceil(l / x);
315
+ _("client_media_upload_start", {
316
316
  data: {
317
- upload_id: u,
317
+ upload_id: s,
318
318
  call_id: o,
319
319
  reason: a,
320
320
  message: r,
321
321
  filename: t,
322
- content_type: n,
323
- size: d,
324
- chunk_count: _,
325
- upload_kind: p
322
+ content_type: i,
323
+ size: l,
324
+ chunk_count: p,
325
+ upload_kind: u
326
326
  }
327
327
  });
328
328
  const m = new Uint8Array(e);
329
- for (let f = 0; f < d; f += x) {
329
+ for (let f = 0; f < l; f += x) {
330
330
  await H(h);
331
- const w = Math.min(f + x, d);
331
+ const w = Math.min(f + x, l);
332
332
  h.send(m.subarray(f, w));
333
333
  }
334
- return await H(h), s("client_media_upload_complete", {
334
+ return await H(h), _("client_media_upload_complete", {
335
335
  data: {
336
- upload_id: u,
336
+ upload_id: s,
337
337
  call_id: o,
338
338
  reason: a,
339
339
  message: r,
340
- chunk_count: _,
341
- upload_kind: p
340
+ chunk_count: p,
341
+ upload_kind: u
342
342
  }
343
- }), { media_id: u, url: "", content_type: n };
343
+ }), { media_id: s, url: "", content_type: i };
344
344
  }
345
- async function Se(i) {
346
- return typeof i.arrayBuffer == "function" ? i.arrayBuffer() : new Response(i).arrayBuffer();
345
+ async function Se(n) {
346
+ return typeof n.arrayBuffer == "function" ? n.arrayBuffer() : new Response(n).arrayBuffer();
347
347
  }
348
348
  const we = 15e3, R = "vanira-connect-stall-prompt";
349
349
  let v = null;
350
- function ge(i = we) {
350
+ function ge(n = we) {
351
351
  typeof window > "u" || (g(!1), v = setTimeout(() => {
352
352
  v = null, ve(), window.dispatchEvent(new CustomEvent("vanira:connect-stall"));
353
- }, i));
353
+ }, n));
354
354
  }
355
- function g(i = !0) {
356
- v !== null && (clearTimeout(v), v = null), i && P();
355
+ function g(n = !0) {
356
+ v !== null && (clearTimeout(v), v = null), n && P();
357
357
  }
358
358
  function P() {
359
- var i;
360
- typeof document > "u" || (i = document.getElementById(R)) == null || i.remove();
359
+ var n;
360
+ typeof document > "u" || (n = document.getElementById(R)) == null || n.remove();
361
361
  }
362
362
  function ve() {
363
- var t, n;
363
+ var t, i;
364
364
  if (typeof document > "u" || document.getElementById(R)) return;
365
- const i = document.createElement("div");
366
- i.id = R, i.setAttribute("role", "alertdialog"), i.setAttribute("aria-modal", "true"), i.setAttribute("aria-labelledby", "vanira-stall-title"), i.style.cssText = [
365
+ const n = document.createElement("div");
366
+ n.id = R, n.setAttribute("role", "alertdialog"), n.setAttribute("aria-modal", "true"), n.setAttribute("aria-labelledby", "vanira-stall-title"), n.style.cssText = [
367
367
  "position:fixed",
368
368
  "inset:0",
369
369
  "z-index:2147483646",
@@ -399,11 +399,11 @@ function ve() {
399
399
  <p style="margin:12px 0 0;font-size:12px;color:#888">
400
400
  Tip: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac)
401
401
  </p>
402
- `, i.appendChild(e), document.body.appendChild(i), (t = e.querySelector("#vanira-stall-refresh")) == null || t.addEventListener("click", () => {
402
+ `, n.appendChild(e), document.body.appendChild(n), (t = e.querySelector("#vanira-stall-refresh")) == null || t.addEventListener("click", () => {
403
403
  P(), window.location.reload();
404
- }), (n = e.querySelector("#vanira-stall-dismiss")) == null || n.addEventListener("click", () => P());
404
+ }), (i = e.querySelector("#vanira-stall-dismiss")) == null || i.addEventListener("click", () => P());
405
405
  }
406
- function Ce(i) {
406
+ function Ce(n) {
407
407
  return null;
408
408
  }
409
409
  function C() {
@@ -411,16 +411,16 @@ function C() {
411
411
  }
412
412
  class Ie {
413
413
  constructor(e) {
414
- l(this, "active", !1);
415
- l(this, "initialSent", !1);
416
- l(this, "lastRoute", "");
417
- l(this, "sendContext");
418
- l(this, "isReady");
419
- l(this, "cleanupFns", []);
420
- l(this, "initialRetryTimer", null);
421
- l(this, "routePollTimer", null);
422
- l(this, "originalPushState", null);
423
- l(this, "originalReplaceState", null);
414
+ d(this, "active", !1);
415
+ d(this, "initialSent", !1);
416
+ d(this, "lastRoute", "");
417
+ d(this, "sendContext");
418
+ d(this, "isReady");
419
+ d(this, "cleanupFns", []);
420
+ d(this, "initialRetryTimer", null);
421
+ d(this, "routePollTimer", null);
422
+ d(this, "originalPushState", null);
423
+ d(this, "originalReplaceState", null);
424
424
  this.sendContext = e.sendContext, this.isReady = e.isReady ?? (() => !0);
425
425
  }
426
426
  start() {
@@ -456,11 +456,11 @@ class Ie {
456
456
  attachListeners() {
457
457
  const e = (r, o = 0) => {
458
458
  const h = () => {
459
- const s = C();
460
- s !== this.lastRoute && this.handleRouteChange(s, r);
459
+ const _ = C();
460
+ _ !== this.lastRoute && this.handleRouteChange(_, r);
461
461
  };
462
462
  o > 0 ? window.setTimeout(h, o) : queueMicrotask(h);
463
- }, t = () => e("popstate"), n = () => e("hashchange"), a = (r) => {
463
+ }, t = () => e("popstate"), i = () => e("hashchange"), a = (r) => {
464
464
  const o = r.detail;
465
465
  if ((o == null ? void 0 : o.initiated_by) === "agent") {
466
466
  e("vanira_navigate_agent", 120);
@@ -468,9 +468,9 @@ class Ie {
468
468
  }
469
469
  e("vanira_navigate", 120);
470
470
  };
471
- window.addEventListener("popstate", t), window.addEventListener("hashchange", n), window.addEventListener("vanira:navigate", a), this.cleanupFns.push(
471
+ window.addEventListener("popstate", t), window.addEventListener("hashchange", i), window.addEventListener("vanira:navigate", a), this.cleanupFns.push(
472
472
  () => window.removeEventListener("popstate", t),
473
- () => window.removeEventListener("hashchange", n),
473
+ () => window.removeEventListener("hashchange", i),
474
474
  () => window.removeEventListener("vanira:navigate", a)
475
475
  ), this.originalPushState = history.pushState.bind(history), this.originalReplaceState = history.replaceState.bind(history), history.pushState = (...r) => {
476
476
  this.originalPushState(...r), e("pushState");
@@ -484,15 +484,15 @@ class Ie {
484
484
  }
485
485
  handleRouteChange(e, t) {
486
486
  if (!this.active) return;
487
- const n = this.lastRoute;
488
- if (n === e) return;
487
+ const i = this.lastRoute;
488
+ if (i === e) return;
489
489
  if (this.lastRoute = e, !this.initialSent) {
490
490
  this.scheduleInitialContextSend();
491
491
  return;
492
492
  }
493
- !this.isReady() || Ce() || this.sendRouteContext("route_changed", n, t, "user");
493
+ !this.isReady() || Ce() || this.sendRouteContext("route_changed", i, t, "user");
494
494
  }
495
- sendRouteContext(e, t, n, a = "user") {
495
+ sendRouteContext(e, t, i, a = "user") {
496
496
  const r = C();
497
497
  this.lastRoute = r;
498
498
  const o = {
@@ -502,7 +502,7 @@ class Ie {
502
502
  current_page: r,
503
503
  user_action: e === "call_started" ? "call_started_on_page" : "user_navigated"
504
504
  };
505
- 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}.`, n && (o.navigation_source = n));
505
+ 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));
506
506
  try {
507
507
  this.sendContext(o);
508
508
  } catch {
@@ -511,57 +511,59 @@ class Ie {
511
511
  }
512
512
  const y = class y {
513
513
  constructor(e) {
514
- l(this, "serverUrl");
515
- l(this, "agentId");
516
- l(this, "callId");
517
- l(this, "prospectId");
518
- l(this, "apiKey");
519
- l(this, "backendUrl");
520
- l(this, "token");
521
- l(this, "prospectName");
522
- l(this, "extraDetails");
523
- l(this, "onConnected");
524
- l(this, "onDisconnected");
525
- l(this, "onError");
526
- l(this, "onTranscription");
527
- l(this, "onLocalStream");
514
+ d(this, "serverUrl");
515
+ d(this, "agentId");
516
+ d(this, "callId");
517
+ d(this, "prospectId");
518
+ d(this, "apiKey");
519
+ d(this, "backendUrl");
520
+ d(this, "token");
521
+ d(this, "prospectName");
522
+ d(this, "welcomeMessage");
523
+ d(this, "extraDetails");
524
+ d(this, "onConnected");
525
+ d(this, "onDisconnected");
526
+ d(this, "onError");
527
+ d(this, "onTranscription");
528
+ d(this, "onLocalStream");
528
529
  // @ts-ignore
529
- l(this, "onRemoteTrack");
530
- l(this, "onClientToolCall");
531
- l(this, "onSessionStarted");
532
- l(this, "sessionStartedEmitted", !1);
533
- l(this, "pc", null);
534
- l(this, "dataChannel", null);
535
- l(this, "mediaBytesChannel", null);
536
- l(this, "audioElement", null);
537
- l(this, "localStream", null);
538
- l(this, "micMuted", !1);
539
- l(this, "connected", !1);
540
- l(this, "appliedRemoteCandidates", /* @__PURE__ */ new Set());
541
- l(this, "remoteDescSet", !1);
542
- l(this, "pendingServerIce", []);
543
- l(this, "icePollStop", !1);
544
- l(this, "iceServers");
545
- l(this, "callSessionLoaded", !1);
546
- l(this, "connectGeneration", 0);
547
- l(this, "runtime");
548
- l(this, "sessionBehavior");
549
- l(this, "routeTracker", null);
550
- l(this, "_status", "idle");
551
- l(this, "listeners", /* @__PURE__ */ new Map());
530
+ d(this, "onRemoteTrack");
531
+ d(this, "onClientToolCall");
532
+ d(this, "onSessionStarted");
533
+ d(this, "sessionStartedEmitted", !1);
534
+ d(this, "pc", null);
535
+ d(this, "dataChannel", null);
536
+ d(this, "mediaBytesChannel", null);
537
+ d(this, "audioElement", null);
538
+ d(this, "localStream", null);
539
+ d(this, "micMuted", !1);
540
+ d(this, "connected", !1);
541
+ d(this, "appliedRemoteCandidates", /* @__PURE__ */ new Set());
542
+ d(this, "remoteDescSet", !1);
543
+ d(this, "pendingServerIce", []);
544
+ d(this, "icePollStop", !1);
545
+ d(this, "iceServers");
546
+ d(this, "callSessionLoaded", !1);
547
+ d(this, "connectGeneration", 0);
548
+ d(this, "runtime");
549
+ d(this, "sessionBehavior");
550
+ d(this, "routeTracker", null);
551
+ d(this, "_status", "idle");
552
+ d(this, "listeners", /* @__PURE__ */ new Map());
552
553
  /** Live vision config — auto-starts camera on connect when scope is full_call. */
553
- l(this, "liveVision");
554
- l(this, "liveVisionAutoStarted", !1);
555
- l(this, "connectStallTimeoutMs");
554
+ d(this, "liveVision");
555
+ d(this, "liveVisionAutoStarted", !1);
556
+ d(this, "connectStallTimeoutMs");
557
+ var _;
556
558
  if (!e.agentId) throw new Error("agentId is required");
557
- const t = !!(e.apiKey || e.token), n = !!(e.serverUrl && e.callId), a = y.normalizeIceServers(
559
+ const t = !!(e.apiKey || e.token), i = !!(e.serverUrl && e.callId), a = y.normalizeIceServers(
558
560
  e.iceServers
559
561
  );
560
- if (!t && !n)
562
+ if (!t && !i)
561
563
  throw new Error(
562
564
  "apiKey or token is required — or pass serverUrl and callId from a prior POST /calls/create"
563
565
  );
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 || ne).replace(/\/$/, ""), a.length && (this.iceServers = a), n && (this.callSessionLoaded = !0);
566
+ this.agentId = e.agentId, this.sessionBehavior = e.sessionBehavior, this.serverUrl = (e.serverUrl || "").replace(/\/$/, ""), this.apiKey = e.apiKey, this.token = e.token, this.prospectName = e.prospectName, this.welcomeMessage = ((_ = e.welcomeMessage) == null ? void 0 : _.trim()) || void 0, this.extraDetails = e.extraDetails, this.backendUrl = (e.backendUrl || ie).replace(/\/$/, ""), a.length && (this.iceServers = a), i && (this.callSessionLoaded = !0);
565
567
  const r = typeof window < "u";
566
568
  this.prospectId = e.prospectId;
567
569
  const o = e.sessionBehavior === "continue";
@@ -586,28 +588,28 @@ const y = class y {
586
588
  var s;
587
589
  g(), this._status = "disconnected", (s = e.onDisconnected) == null || s.call(e), this.emit("disconnected");
588
590
  }, this.onError = (s) => {
589
- var p;
591
+ var l;
590
592
  g(), this._status = "error";
591
593
  const u = typeof s == "string" ? s : (s == null ? void 0 : s.message) || "Connection error";
592
- (p = e.onError) == null || p.call(e, s), this.emit("error", u);
593
- }, this.onTranscription = (s, u, p) => {
594
- var d;
595
- (d = e.onTranscription) == null || d.call(e, s, u), this.emit("transcription", { text: s, isFinal: u, role: p });
594
+ (l = e.onError) == null || l.call(e, s), this.emit("error", u);
595
+ }, this.onTranscription = (s, u, l) => {
596
+ var p;
597
+ (p = e.onTranscription) == null || p.call(e, s, u), this.emit("transcription", { text: s, isFinal: u, role: l });
596
598
  }, this.onLocalStream = e.onLocalStream || (() => {
597
599
  }), this.onRemoteTrack = (s, u) => {
598
- var p;
599
- (p = e.onRemoteTrack) == null || p.call(e, s, u), this.emit("track", { track: s, stream: u });
600
+ var l;
601
+ (l = e.onRemoteTrack) == null || l.call(e, s, u), this.emit("track", { track: s, stream: u });
600
602
  }, this.onClientToolCall = (s) => {
601
- var d;
602
- (d = e.onClientToolCall) == null || d.call(e, s);
603
- const u = (s == null ? void 0 : s.data) || s, p = {
603
+ var p;
604
+ (p = e.onClientToolCall) == null || p.call(e, s);
605
+ const u = (s == null ? void 0 : s.data) || s, l = {
604
606
  name: String(u.name || u.tool_name || ""),
605
607
  arguments: u.arguments || u.args || {},
606
608
  tool_call_id: String(u.tool_call_id || u.call_id || ""),
607
609
  execution_mode: u.execution_mode === "blocking" ? "blocking" : "fire_and_forget",
608
610
  client_fields: u.client_fields || {}
609
611
  };
610
- p.name && p.tool_call_id && this.emit("tool_call", p);
612
+ l.name && l.tool_call_id && this.emit("tool_call", l);
611
613
  }, this.runtime = e.runtime, typeof window < "u" && e.trackRouteContext !== !1 && (this.routeTracker = new Ie({
612
614
  sendContext: (s) => this.sendContextUpdate(s),
613
615
  isReady: () => {
@@ -648,9 +650,9 @@ const y = class y {
648
650
  }
649
651
  try {
650
652
  this.appliedRemoteCandidates.clear(), this.remoteDescSet = !1, this.pendingServerIce = [], this.icePollStop = !1, this.stopRemoteIcePolling();
651
- const n = this.getIceServers();
653
+ const i = this.getIceServers();
652
654
  this.pc = new RTCPeerConnection({
653
- iceServers: n,
655
+ iceServers: i,
654
656
  iceTransportPolicy: "all"
655
657
  });
656
658
  let a;
@@ -664,77 +666,77 @@ const y = class y {
664
666
  channelCount: 1
665
667
  }
666
668
  });
667
- } catch (d) {
668
- if (d.name === "NotAllowedError" || d.name === "PermissionDeniedError" || (t = d.message) != null && t.includes("Permission denied")) {
669
- const _ = navigator.userAgent, m = /iPad|iPhone|iPod/.test(_) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
669
+ } catch (l) {
670
+ if (l.name === "NotAllowedError" || l.name === "PermissionDeniedError" || (t = l.message) != null && t.includes("Permission denied")) {
671
+ const p = navigator.userAgent, m = /iPad|iPhone|iPod/.test(p) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
670
672
  let f = "Microphone access denied. Please allow microphone access in your browser settings.";
671
- 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).");
673
+ 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
674
  const w = new Error(f);
673
- throw w.name = d.name, w;
675
+ throw w.name = l.name, w;
674
676
  }
675
- throw d;
677
+ throw l;
676
678
  }
677
679
  if (this.isConnectCancelled(e)) {
678
- a.getTracks().forEach((d) => d.stop());
680
+ a.getTracks().forEach((l) => l.stop());
679
681
  return;
680
682
  }
681
683
  if (this.localStream = a, !this.pc || this.isConnectCancelled(e)) {
682
- a.getTracks().forEach((d) => d.stop());
684
+ a.getTracks().forEach((l) => l.stop());
683
685
  return;
684
686
  }
685
- if (this.onLocalStream(a), a.getTracks().forEach((d) => {
686
- var _;
687
- (_ = this.pc) == null || _.addTrack(d, a);
687
+ if (this.onLocalStream(a), a.getTracks().forEach((l) => {
688
+ var p;
689
+ (p = this.pc) == null || p.addTrack(l, a);
688
690
  }), !this.pc)
689
691
  throw new Error("RTCPeerConnection was closed unexpectedly");
690
692
  this.dataChannel = this.pc.createDataChannel("control"), this.dataChannel.onopen = () => {
691
- var d;
692
- (d = this.routeTracker) == null || d.onChannelReady();
693
- }, this.dataChannel.onmessage = (d) => {
694
- if (typeof d.data == "string")
693
+ var l;
694
+ (l = this.routeTracker) == null || l.onChannelReady();
695
+ }, this.dataChannel.onmessage = (l) => {
696
+ if (typeof l.data == "string")
695
697
  try {
696
- this.handleControlEvent(JSON.parse(d.data));
698
+ this.handleControlEvent(JSON.parse(l.data));
697
699
  } catch {
698
700
  }
699
- else if (d.data instanceof ArrayBuffer)
701
+ else if (l.data instanceof ArrayBuffer)
700
702
  try {
701
- const _ = new TextDecoder().decode(d.data);
703
+ const p = new TextDecoder().decode(l.data);
702
704
  try {
703
- const m = JSON.parse(_);
705
+ const m = JSON.parse(p);
704
706
  pe(m) && this.handleControlEvent(m);
705
707
  } catch {
706
708
  }
707
709
  } catch {
708
710
  }
709
- else d.data instanceof Blob && d.data.text().then((_) => {
711
+ else l.data instanceof Blob && l.data.text().then((p) => {
710
712
  try {
711
- this.handleControlEvent(JSON.parse(_));
713
+ this.handleControlEvent(JSON.parse(p));
712
714
  } catch {
713
715
  }
714
716
  });
715
- }, this.dataChannel.onerror = (d) => {
717
+ }, this.dataChannel.onerror = (l) => {
716
718
  }, this.mediaBytesChannel = this.pc.createDataChannel("media-bytes", { ordered: !0 }), this.mediaBytesChannel.binaryType = "arraybuffer", this.mediaBytesChannel.onopen = () => {
717
- }, this.mediaBytesChannel.onerror = (d) => {
718
- }, this.pc.ontrack = (d) => {
719
- const _ = d.track, m = d.streams[0];
720
- _.kind === "audio" ? (this.audioElement = new Audio(), this.audioElement.srcObject = m, this.audioElement.play().catch((f) => {
719
+ }, this.mediaBytesChannel.onerror = (l) => {
720
+ }, this.pc.ontrack = (l) => {
721
+ const p = l.track, m = l.streams[0];
722
+ p.kind === "audio" ? (this.audioElement = new Audio(), this.audioElement.srcObject = m, this.audioElement.play().catch((f) => {
721
723
  }), this.audioElement.onended = () => {
722
724
  this.sendEvent("playedStream"), typeof window < "u" && window.dispatchEvent(new CustomEvent("vanira:agent-playback-ended"));
723
- }, this.onRemoteTrack(_, m)) : _.kind === "video" && this.onRemoteTrack(_, m);
725
+ }, this.onRemoteTrack(p, m)) : p.kind === "video" && this.onRemoteTrack(p, m);
724
726
  };
725
727
  const r = () => {
726
- var m, f, w, U, L, M, D, O, N, V, B;
727
- const d = ((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", _ = ((U = this.pc) == null ? void 0 : U.connectionState) === "failed" || ((L = this.pc) == null ? void 0 : L.iceConnectionState) === "failed" || ((M = this.pc) == null ? void 0 : M.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";
728
- ((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(), d && !this.connected ? (this.connected = !0, (B = this.routeTracker) == null || B.start(), this.onConnected()) : _ && this.connected && (this.connected = !1, this.liveVisionAutoStarted = !1, this.onDisconnected());
728
+ var m, f, w, U, M, L, D, O, N, V, B;
729
+ const l = ((m = this.pc) == null ? void 0 : m.connectionState) === "connected" || ((f = this.pc) == null ? void 0 : f.iceConnectionState) === "connected" || ((w = this.pc) == null ? void 0 : w.iceConnectionState) === "completed", p = ((U = this.pc) == null ? void 0 : U.connectionState) === "failed" || ((M = this.pc) == null ? void 0 : M.iceConnectionState) === "failed" || ((L = this.pc) == null ? void 0 : L.connectionState) === "closed" || ((D = this.pc) == null ? void 0 : D.iceConnectionState) === "closed" || ((O = this.pc) == null ? void 0 : O.connectionState) === "disconnected" || ((N = this.pc) == null ? void 0 : N.iceConnectionState) === "disconnected";
730
+ ((V = this.pc) == null ? void 0 : V.connectionState) === "connected" && this.stopRemoteIcePolling(), l && !this.connected ? (this.connected = !0, (B = this.routeTracker) == null || B.start(), this.onConnected()) : p && this.connected && (this.connected = !1, this.liveVisionAutoStarted = !1, this.onDisconnected());
729
731
  };
730
732
  this.pc.onconnectionstatechange = r, this.pc.oniceconnectionstatechange = r;
731
733
  const o = this.getIceTrickleUrl();
732
- this.pc.onicecandidate = (d) => {
733
- d.candidate && this.sendRemoteIceCandidate(d.candidate, o);
734
+ this.pc.onicecandidate = (l) => {
735
+ l.candidate && this.sendRemoteIceCandidate(l.candidate, o);
734
736
  };
735
737
  const h = await this.pc.createOffer();
736
738
  if (this.isConnectCancelled(e) || (await this.pc.setLocalDescription(h), this.isConnectCancelled(e))) return;
737
- const s = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`, u = await fetch(s, {
739
+ const _ = this.serverUrl.includes("?") ? this.serverUrl : `${this.serverUrl}/webrtc?agent=${this.agentId}_${this.callId}`, s = await fetch(_, {
738
740
  method: "POST",
739
741
  headers: { "Content-Type": "application/json" },
740
742
  body: JSON.stringify({
@@ -744,32 +746,32 @@ const y = class y {
744
746
  })
745
747
  });
746
748
  if (this.isConnectCancelled(e)) return;
747
- if (!u.ok) {
748
- const d = await u.json();
749
- throw new Error(d.error || `HTTP ${u.status}`);
749
+ if (!s.ok) {
750
+ const l = await s.json();
751
+ throw new Error(l.error || `HTTP ${s.status}`);
750
752
  }
751
- const { answer: p } = await u.json();
752
- if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(p), this.isConnectCancelled(e)) || (this.remoteDescSet = !0, await this.flushPendingServerIce(), this.isConnectCancelled(e))) return;
753
+ const { answer: u } = await s.json();
754
+ if (this.isConnectCancelled(e) || !this.pc || (await this.pc.setRemoteDescription(u), this.isConnectCancelled(e)) || (this.remoteDescSet = !0, await this.flushPendingServerIce(), this.isConnectCancelled(e))) return;
753
755
  this.startRemoteIcePolling(o);
754
- } catch (n) {
756
+ } catch (i) {
755
757
  if (this.isConnectCancelled(e)) return;
756
- throw this.disconnect(), this.onError(n.message || n), n;
758
+ throw this.disconnect(), this.onError(i.message || i), i;
757
759
  }
758
760
  }
759
761
  }
760
762
  createCallCacheKey(e, t) {
761
- const n = this.apiKey ? `key:${this.apiKey.slice(0, 16)}` : `token:${(this.token || "").slice(-16)}`;
763
+ const i = this.apiKey ? `key:${this.apiKey.slice(0, 16)}` : `token:${(this.token || "").slice(-16)}`;
762
764
  return [
763
765
  this.backendUrl,
764
766
  this.agentId,
765
767
  e,
766
768
  t || "",
767
769
  this.prospectId || "",
768
- n
770
+ i
769
771
  ].join("|");
770
772
  }
771
- async postCreateCall(e, t, n) {
772
- var h, s, u;
773
+ async postCreateCall(e, t, i) {
774
+ var h, _, s;
773
775
  const a = await fetch(`${this.backendUrl}/calls/create`, {
774
776
  method: "POST",
775
777
  headers: e,
@@ -777,16 +779,17 @@ const y = class y {
777
779
  agent_id: this.agentId,
778
780
  type: ((h = this.runtime) == null ? void 0 : h.callType) || "web",
779
781
  mode: t,
780
- ...(s = this.runtime) != null && s.runtimeName ? { runtime: this.runtime.runtimeName } : {},
782
+ ...(_ = this.runtime) != null && _.runtimeName ? { runtime: this.runtime.runtimeName } : {},
781
783
  prospect_id: this.prospectId,
782
784
  ...this.prospectName ? { prospect_name: this.prospectName } : {},
785
+ ...this.welcomeMessage ? { welcome_message: this.welcomeMessage } : {},
783
786
  ...this.extraDetails && Object.keys(this.extraDetails).length ? { extra_details: this.extraDetails } : {},
784
- ...n ? { call_id: n } : {}
787
+ ...i ? { call_id: i } : {}
785
788
  })
786
789
  });
787
790
  if (!a.ok) {
788
- const p = await a.json().catch(() => ({}));
789
- throw new Error(`[VaniraClient] createCall failed (${a.status}): ${((u = p == null ? void 0 : p.detail) == null ? void 0 : u.message) || (p == null ? void 0 : p.message) || a.statusText}`);
791
+ const u = await a.json().catch(() => ({}));
792
+ 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
793
  }
791
794
  const r = await a.json();
792
795
  if (!r.call_id || !r.worker_url)
@@ -818,9 +821,9 @@ const y = class y {
818
821
  throw new Error("[VaniraClient] apiKey or token is required to create a call session");
819
822
  const e = { "Content-Type": "application/json" };
820
823
  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, n = this.sessionBehavior === "continue" ? "continue" : "new", a = this.createCallCacheKey(n, t);
824
+ const t = this.sessionBehavior === "continue" ? this.callId : void 0, i = this.sessionBehavior === "continue" ? "continue" : "new", a = this.createCallCacheKey(i, t);
822
825
  let r = y.inflightCreates.get(a);
823
- r || (r = this.postCreateCall(e, n, t), y.inflightCreates.set(a, r), r.finally(() => {
826
+ r || (r = this.postCreateCall(e, i, t), y.inflightCreates.set(a, r), r.finally(() => {
824
827
  y.inflightCreates.get(a) === r && y.inflightCreates.delete(a);
825
828
  }));
826
829
  const o = await r;
@@ -834,11 +837,11 @@ const y = class y {
834
837
  static normalizeIceServers(e) {
835
838
  if (!Array.isArray(e)) return [];
836
839
  const t = [];
837
- for (const n of e) {
838
- const a = n == null ? void 0 : n.urls, r = Array.isArray(a) ? a.filter(Boolean) : typeof a == "string" && a.trim() ? [a.trim()] : [];
840
+ for (const i of e) {
841
+ const a = i == null ? void 0 : i.urls, r = Array.isArray(a) ? a.filter(Boolean) : typeof a == "string" && a.trim() ? [a.trim()] : [];
839
842
  if (!r.length) continue;
840
- const o = { urls: r.length === 1 ? r[0] : r }, h = n.username, s = n.credential;
841
- h && (o.username = h), s && (o.credential = s), t.push(o);
843
+ const o = { urls: r.length === 1 ? r[0] : r }, h = i.username, _ = i.credential;
844
+ h && (o.username = h), _ && (o.credential = _), t.push(o);
842
845
  }
843
846
  return t;
844
847
  }
@@ -865,13 +868,13 @@ const y = class y {
865
868
  }
866
869
  async sendRemoteIceCandidate(e, t) {
867
870
  try {
868
- const n = await fetch(t, {
871
+ const i = await fetch(t, {
869
872
  method: "POST",
870
873
  headers: { "Content-Type": "application/json" },
871
874
  body: JSON.stringify({ candidate: e.toJSON() })
872
875
  });
873
- if (n.ok) {
874
- const a = await n.json();
876
+ if (i.ok) {
877
+ const a = await i.json();
875
878
  await this.applyServerIceCandidates(a.candidates);
876
879
  }
877
880
  } catch {
@@ -885,9 +888,9 @@ const y = class y {
885
888
  return;
886
889
  }
887
890
  for (const t of e) {
888
- const n = JSON.stringify(t);
889
- if (!this.appliedRemoteCandidates.has(n)) {
890
- this.appliedRemoteCandidates.add(n);
891
+ const i = JSON.stringify(t);
892
+ if (!this.appliedRemoteCandidates.has(i)) {
893
+ this.appliedRemoteCandidates.add(i);
891
894
  try {
892
895
  await this.pc.addIceCandidate(t);
893
896
  } catch {
@@ -901,9 +904,9 @@ const y = class y {
901
904
  const e = this.pendingServerIce;
902
905
  this.pendingServerIce = [];
903
906
  for (const t of e) {
904
- const n = JSON.stringify(t);
905
- if (!this.appliedRemoteCandidates.has(n)) {
906
- this.appliedRemoteCandidates.add(n);
907
+ const i = JSON.stringify(t);
908
+ if (!this.appliedRemoteCandidates.has(i)) {
909
+ this.appliedRemoteCandidates.add(i);
907
910
  try {
908
911
  await this.pc.addIceCandidate(t);
909
912
  } catch {
@@ -915,10 +918,10 @@ const y = class y {
915
918
  this.icePollStop = !1, this.pollServerIce(e);
916
919
  }
917
920
  async pollServerIce(e) {
918
- var n;
921
+ var i;
919
922
  const t = Date.now() + 15e3;
920
923
  for (; !this.icePollStop && Date.now() < t; ) {
921
- const a = (n = this.pc) == null ? void 0 : n.connectionState;
924
+ const a = (i = this.pc) == null ? void 0 : i.connectionState;
922
925
  if (a === "connected" || a === "failed" || a === "closed") break;
923
926
  try {
924
927
  const r = await fetch(e, { method: "GET" });
@@ -938,16 +941,16 @@ const y = class y {
938
941
  * Send control event via DataChannel
939
942
  */
940
943
  sendEvent(e, t = {}) {
941
- var n;
942
- if (((n = this.dataChannel) == null ? void 0 : n.readyState) === "open") {
944
+ var i;
945
+ if (((i = this.dataChannel) == null ? void 0 : i.readyState) === "open") {
943
946
  const a = { event: e, ...t };
944
947
  this.dataChannel.send(JSON.stringify(a));
945
948
  }
946
949
  }
947
950
  /** Wait for control DataChannel, then send (live vision lifecycle events). */
948
- async sendEventWhenReady(e, t = {}, n = 1e4) {
951
+ async sendEventWhenReady(e, t = {}, i = 1e4) {
949
952
  var r;
950
- const a = Date.now() + n;
953
+ const a = Date.now() + i;
951
954
  for (; Date.now() < a; ) {
952
955
  if (((r = this.dataChannel) == null ? void 0 : r.readyState) === "open")
953
956
  return this.sendEvent(e, t), !0;
@@ -999,8 +1002,8 @@ const y = class y {
999
1002
  break;
1000
1003
  case "transcription":
1001
1004
  {
1002
- const n = e.data && typeof e.data == "object" ? e.data : {}, a = String(e.text ?? n.text ?? "").trim(), r = e.isFinal ?? e.is_final ?? n.isFinal ?? n.is_final, o = r === void 0 ? !0 : r === !0 || r === "true", h = String(
1003
- e.role ?? e.speaker ?? n.role ?? n.speaker ?? ""
1005
+ 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, o = r === void 0 ? !0 : r === !0 || r === "true", h = String(
1006
+ e.role ?? e.speaker ?? i.role ?? i.speaker ?? ""
1004
1007
  ).trim() || void 0;
1005
1008
  a && this.onTranscription(a, o, h);
1006
1009
  }
@@ -1013,12 +1016,12 @@ const y = class y {
1013
1016
  break;
1014
1017
  }
1015
1018
  case "client_tool_call": {
1016
- const n = e.tool_call || e.data || e, a = (n == null ? void 0 : n.tool_call_id) || (n == null ? void 0 : n.call_id) || e.tool_call_id || "";
1019
+ 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
1020
  a && ((t = this.dataChannel) == null ? void 0 : t.readyState) === "open" && this.dataChannel.send(JSON.stringify({
1018
1021
  event: "client_tool_ack",
1019
1022
  data: { tool_call_id: a }
1020
1023
  }));
1021
- const r = (n == null ? void 0 : n.arguments) || (n == null ? void 0 : n.args) || {}, o = (n == null ? void 0 : n.client_fields) || {}, h = (n == null ? void 0 : n.name) || (n == null ? void 0 : n.tool_name) || "", s = de(o, r, h);
1024
+ 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) || "", _ = de(o, r, h);
1022
1025
  if (h === "end_call") {
1023
1026
  a && this.sendToolResult(a, {
1024
1027
  status: "client_ack_end_call",
@@ -1026,13 +1029,13 @@ const y = class y {
1026
1029
  }), window.setTimeout(() => this.disconnect(), 120);
1027
1030
  break;
1028
1031
  }
1029
- if (s) {
1032
+ if (_) {
1030
1033
  window.dispatchEvent(new CustomEvent("vanira:preset", {
1031
- detail: { toolCall: n, client: this }
1032
- })), this.onClientToolCall(n);
1034
+ detail: { toolCall: i, client: this }
1035
+ })), this.onClientToolCall(i);
1033
1036
  break;
1034
1037
  }
1035
- this.onClientToolCall(n);
1038
+ this.onClientToolCall(i);
1036
1039
  break;
1037
1040
  }
1038
1041
  }
@@ -1056,10 +1059,10 @@ const y = class y {
1056
1059
  * Uses track.enabled (not pause) so audio resumes correctly when unmuted.
1057
1060
  */
1058
1061
  setMicrophoneMuted(e) {
1059
- var t, n;
1062
+ var t, i;
1060
1063
  this.micMuted = e, (t = this.localStream) == null || t.getAudioTracks().forEach((a) => {
1061
1064
  a.enabled = !e;
1062
- }), (n = this.pc) == null || n.getSenders().forEach((a) => {
1065
+ }), (i = this.pc) == null || i.getSenders().forEach((a) => {
1063
1066
  var r;
1064
1067
  ((r = a.track) == null ? void 0 : r.kind) === "audio" && (a.track.enabled = !e);
1065
1068
  });
@@ -1074,9 +1077,9 @@ const y = class y {
1074
1077
  return e !== this.connectGeneration;
1075
1078
  }
1076
1079
  /** Notify WidgetPresetRenderer to cancel in-flight board animations */
1077
- dispatchBoardAbort(e, t, n) {
1080
+ dispatchBoardAbort(e, t, i) {
1078
1081
  typeof window > "u" || window.dispatchEvent(new CustomEvent("vanira:board_abort", {
1079
- detail: { reason: e, toolCallId: t, presetId: n }
1082
+ detail: { reason: e, toolCallId: t, presetId: i }
1080
1083
  }));
1081
1084
  }
1082
1085
  /**
@@ -1165,8 +1168,8 @@ const y = class y {
1165
1168
  * @param reason Routing key for backend processing (default: 'general')
1166
1169
  * @param message Optional user text message about the file
1167
1170
  */
1168
- async uploadMedia(e, t = "general", n = "") {
1169
- return await fe(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t, n) : (me(this.dataChannel, this.mediaBytesChannel), this._uploadMediaViaHTTP(e, t, n));
1171
+ async uploadMedia(e, t = "general", i = "") {
1172
+ return await fe(this.dataChannel, this.mediaBytesChannel) ? this._uploadMediaViaDataChannel(e, t, i) : (me(this.dataChannel, this.mediaBytesChannel), this._uploadMediaViaHTTP(e, t, i));
1170
1173
  }
1171
1174
  /**
1172
1175
  * Upload a live vision / screen frame — HTTP only for now, never sends client_media_update.
@@ -1175,45 +1178,45 @@ const y = class y {
1175
1178
  * Frames require a real media_url (server rejects empty). WebRTC upload returns url="" until
1176
1179
  * the server adds client_media_upload_ready ack — use HTTP for frame JPEGs until then.
1177
1180
  */
1178
- async uploadMediaFrame(e, t = "camera_capture", n) {
1179
- const a = n && !(e instanceof File) ? new File([e], n, { type: e.type || "image/jpeg" }) : e, { media_id: r, url: o, contentType: h } = await this._postMediaUpload(a, t, !0);
1181
+ async uploadMediaFrame(e, t = "camera_capture", i) {
1182
+ const a = i && !(e instanceof File) ? new File([e], i, { type: e.type || "image/jpeg" }) : e, { media_id: r, url: o, contentType: h } = await this._postMediaUpload(a, t, !0);
1180
1183
  if (!r || !o)
1181
1184
  throw new Error("Frame upload failed: server response missing media_id or url");
1182
1185
  return { media_id: r, url: o, content_type: h };
1183
1186
  }
1184
1187
  /** WebRTC media-bytes path (control start/complete + binary chunks). */
1185
- async _uploadBytesViaDataChannel(e, t, n, a, r) {
1188
+ async _uploadBytesViaDataChannel(e, t, i, a, r) {
1186
1189
  if (!this.callId || !this.mediaBytesChannel)
1187
1190
  throw new Error("Upload failed: call not ready for WebRTC media upload.");
1188
- const o = r || (e instanceof File ? e.name : a === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (a === "frame" ? "image/jpeg" : "application/octet-stream"), s = await Se(e);
1191
+ const o = r || (e instanceof File ? e.name : a === "frame" ? "frame.jpg" : "upload.bin"), h = e.type || (a === "frame" ? "image/jpeg" : "application/octet-stream"), _ = await Se(e);
1189
1192
  return ye({
1190
- bytes: s,
1193
+ bytes: _,
1191
1194
  filename: o,
1192
1195
  contentType: h,
1193
1196
  reason: t,
1194
- message: n,
1197
+ message: i,
1195
1198
  callId: this.callId,
1196
1199
  mediaBytesChannel: this.mediaBytesChannel,
1197
- sendControlEvent: (u, p) => this.sendEvent(u, p),
1200
+ sendControlEvent: (s, u) => this.sendEvent(s, u),
1198
1201
  uploadKind: a
1199
1202
  });
1200
1203
  }
1201
- async _uploadMediaViaDataChannel(e, t, n) {
1202
- const a = await this._uploadBytesViaDataChannel(e, t, n, "media");
1204
+ async _uploadMediaViaDataChannel(e, t, i) {
1205
+ const a = await this._uploadBytesViaDataChannel(e, t, i, "media");
1203
1206
  return { media_id: a.media_id, url: a.url };
1204
1207
  }
1205
1208
  /** HTTP fallback — original uploadMedia behavior (unchanged). */
1206
- async _uploadMediaViaHTTP(e, t = "general", n = "") {
1209
+ async _uploadMediaViaHTTP(e, t = "general", i = "") {
1207
1210
  const { media_id: a, url: r, contentType: o } = await this._postMediaUpload(e, t, !0);
1208
1211
  return this.sendMediaUpdate({
1209
1212
  media_id: a,
1210
1213
  media_url: r,
1211
1214
  content_type: o,
1212
1215
  reason: t,
1213
- message: n
1216
+ message: i
1214
1217
  }), { media_id: a, url: r };
1215
1218
  }
1216
- async _postMediaUpload(e, t, n = !1) {
1219
+ async _postMediaUpload(e, t, i = !1) {
1217
1220
  if (!this.serverUrl)
1218
1221
  throw new Error("Upload failed: serverUrl is not set. Connect the VaniraClient first.");
1219
1222
  if (!this.callId)
@@ -1230,17 +1233,17 @@ const y = class y {
1230
1233
  body: o
1231
1234
  });
1232
1235
  if (!h.ok) {
1233
- let _ = `HTTP ${h.status}`;
1236
+ let p = `HTTP ${h.status}`;
1234
1237
  try {
1235
- _ = (await h.json()).error || _;
1238
+ p = (await h.json()).error || p;
1236
1239
  } catch {
1237
1240
  }
1238
- throw new Error(`Upload failed: ${_}`);
1241
+ throw new Error(`Upload failed: ${p}`);
1239
1242
  }
1240
- const s = await h.json(), u = s.media_id, p = s.url, d = s.content_type || e.type;
1241
- if (!u || !p)
1243
+ const _ = await h.json(), s = _.media_id, u = _.url, l = _.content_type || e.type;
1244
+ if (!s || !u)
1242
1245
  throw new Error("Upload failed: server response missing media_id or url");
1243
- return n ? { media_id: u, url: p, contentType: d } : { media_id: u, url: p, contentType: d };
1246
+ return i ? { media_id: s, url: u, contentType: l } : { media_id: s, url: u, contentType: l };
1244
1247
  }
1245
1248
  // ─── Event emitter (replaces retired VaniraAI) ───────────────────────────
1246
1249
  get status() {
@@ -1253,12 +1256,12 @@ const y = class y {
1253
1256
  return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), this;
1254
1257
  }
1255
1258
  off(e, t) {
1256
- var n;
1257
- return (n = this.listeners.get(e)) == null || n.delete(t), this;
1259
+ var i;
1260
+ return (i = this.listeners.get(e)) == null || i.delete(t), this;
1258
1261
  }
1259
1262
  emit(e, t) {
1260
- var n;
1261
- (n = this.listeners.get(e)) == null || n.forEach((a) => a(t));
1263
+ var i;
1264
+ (i = this.listeners.get(e)) == null || i.forEach((a) => a(t));
1262
1265
  }
1263
1266
  /** Alias for connect() — VaniraAI compatibility */
1264
1267
  async start() {
@@ -1288,7 +1291,7 @@ const y = class y {
1288
1291
  }
1289
1292
  };
1290
1293
  /** Dedupes concurrent POST /calls/create (e.g. React StrictMode double-mount). */
1291
- l(y, "inflightCreates", /* @__PURE__ */ new Map());
1294
+ d(y, "inflightCreates", /* @__PURE__ */ new Map());
1292
1295
  let A = y;
1293
1296
  const Te = {
1294
1297
  supportsAudioEndedEvent: !1,
@@ -1309,15 +1312,15 @@ const Te = {
1309
1312
  peer: new ee(),
1310
1313
  dataChannel: new te()
1311
1314
  };
1312
- function Y(i) {
1315
+ function Y(n) {
1313
1316
  return new A({
1314
- ...i,
1317
+ ...n,
1315
1318
  runtime: be
1316
1319
  });
1317
1320
  }
1318
1321
  const ke = Y;
1319
- function xe(i) {
1320
- return Y(i);
1322
+ function xe(n) {
1323
+ return Y(n);
1321
1324
  }
1322
1325
  const Re = xe;
1323
1326
  export {