@telnyx/ai-agent-lib 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12,25 +12,25 @@ function L(t, e, n, i) {
12
12
  return new (n || (n = Promise))((function(s, r) {
13
13
  function o(h) {
14
14
  try {
15
- l(i.next(h));
15
+ d(i.next(h));
16
16
  } catch (f) {
17
17
  r(f);
18
18
  }
19
19
  }
20
- function d(h) {
20
+ function l(h) {
21
21
  try {
22
- l(i.throw(h));
22
+ d(i.throw(h));
23
23
  } catch (f) {
24
24
  r(f);
25
25
  }
26
26
  }
27
- function l(h) {
27
+ function d(h) {
28
28
  var f;
29
29
  h.done ? s(h.value) : (f = h.value, f instanceof n ? f : new n((function(v) {
30
30
  v(f);
31
- }))).then(o, d);
31
+ }))).then(o, l);
32
32
  }
33
- l((i = i.apply(t, [])).next());
33
+ d((i = i.apply(t, [])).next());
34
34
  }));
35
35
  }
36
36
  var vt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), On = new Uint8Array(16);
@@ -44,9 +44,9 @@ function me(t, e, n) {
44
44
  typeof t == "string" && (e = t === "binary" ? new Array(16) : null, t = null);
45
45
  var s = (t = t || {}).random || (t.rng || Ln)();
46
46
  if (s[6] = 15 & s[6] | 64, s[8] = 63 & s[8] | 128, e) for (var r = 0; r < 16; ++r) e[i + r] = s[r];
47
- return e || (function(o, d) {
48
- var l = 0, h = qt;
49
- return [h[o[l++]], h[o[l++]], h[o[l++]], h[o[l++]], "-", h[o[l++]], h[o[l++]], "-", h[o[l++]], h[o[l++]], "-", h[o[l++]], h[o[l++]], "-", h[o[l++]], h[o[l++]], h[o[l++]], h[o[l++]], h[o[l++]], h[o[l++]]].join("");
47
+ return e || (function(o, l) {
48
+ var d = 0, h = qt;
49
+ return [h[o[d++]], h[o[d++]], h[o[d++]], h[o[d++]], "-", h[o[d++]], h[o[d++]], "-", h[o[d++]], h[o[d++]], "-", h[o[d++]], h[o[d++]], "-", h[o[d++]], h[o[d++]], h[o[d++]], h[o[d++]], h[o[d++]], h[o[d++]]].join("");
50
50
  })(s);
51
51
  }
52
52
  const mt = "wss://rtc.telnyx.com", Jt = { urls: "stun:stun.l.google.com:19302" }, Mn = [{ urls: "stun:stun.telnyx.com:3478" }, Jt, { urls: "turn:turn.telnyx.com:3478?transport=tcp", username: "testuser", credential: "testpassword" }], Pn = [{ urls: "stun:stundev.telnyx.com:3478" }, Jt, { urls: "turn:turndev.telnyx.com:3478?transport=tcp", username: "testuser", credential: "testpassword" }];
@@ -63,7 +63,7 @@ var Nn = Yt((function(t) {
63
63
  e = Dn, n = function() {
64
64
  var i = function() {
65
65
  }, s = "undefined", r = typeof window !== s && typeof window.navigator !== s && /Trident\/|MSIE /.test(window.navigator.userAgent), o = ["trace", "debug", "info", "warn", "error"];
66
- function d(p, S) {
66
+ function l(p, S) {
67
67
  var A = p[S];
68
68
  if (typeof A.bind == "function") return A.bind(p);
69
69
  try {
@@ -74,7 +74,7 @@ var Nn = Yt((function(t) {
74
74
  };
75
75
  }
76
76
  }
77
- function l() {
77
+ function d() {
78
78
  console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
79
79
  }
80
80
  function h(p, S) {
@@ -91,7 +91,7 @@ var Nn = Yt((function(t) {
91
91
  }
92
92
  function v(p, S, A) {
93
93
  return (function(E) {
94
- return E === "debug" && (E = "log"), typeof console !== s && (E === "trace" && r ? l : console[E] !== void 0 ? d(console, E) : console.log !== void 0 ? d(console, "log") : i);
94
+ return E === "debug" && (E = "log"), typeof console !== s && (E === "trace" && r ? d : console[E] !== void 0 ? l(console, E) : console.log !== void 0 ? l(console, "log") : i);
95
95
  })(p) || f.apply(this, arguments);
96
96
  }
97
97
  function _(p, S, A) {
@@ -178,13 +178,13 @@ y.methodFactory = (t, e, n) => {
178
178
  }, y.setLevel("info");
179
179
  const Oe = (t) => {
180
180
  const [e, n, i, s, r, o] = t;
181
- let d = {};
181
+ let l = {};
182
182
  try {
183
- d = JSON.parse(r.replace(/ID"/g, 'Id"'));
183
+ l = JSON.parse(r.replace(/ID"/g, 'Id"'));
184
184
  } catch {
185
185
  y.warn("Verto LA invalid media JSON string:", r);
186
186
  }
187
- return { participantId: Number(e), participantNumber: n, participantName: i, codec: s, media: d, participantData: o };
187
+ return { participantId: Number(e), participantNumber: n, participantName: i, codec: s, media: l, participantData: o };
188
188
  }, zt = (t) => {
189
189
  if (typeof t != "string") return t;
190
190
  try {
@@ -197,12 +197,12 @@ const Oe = (t) => {
197
197
  if (i) return { error: i };
198
198
  const { result: s = null } = n;
199
199
  if (s === null) return e !== null && (n.node_id = e), { result: n };
200
- const { code: r = null, node_id: o = null, result: d = null } = s;
201
- return r && r !== "200" ? { error: s } : d ? Kt(d, o) : { result: s };
200
+ const { code: r = null, node_id: o = null, result: l = null } = s;
201
+ return r && r !== "200" ? { error: s } : l ? Kt(l, o) : { result: s };
202
202
  }, Qt = (t, e) => Math.floor(Math.random() * (e - t + 1) + t), Ne = ({ login: t, passwd: e, password: n, login_token: i }) => !!(t && (e || n) || i), Ie = ({ anonymous_login: t }) => !!t && !!t.target_id && !!t.target_type, pt = (t) => {
203
203
  var e, n, i, s, r, o;
204
- let d = "", l = "";
205
- return !((n = (e = t?.result) === null || e === void 0 ? void 0 : e.params) === null || n === void 0) && n.state && (d = (s = (i = t?.result) === null || i === void 0 ? void 0 : i.params) === null || s === void 0 ? void 0 : s.state), !((r = t?.params) === null || r === void 0) && r.state && (l = (o = t?.params) === null || o === void 0 ? void 0 : o.state), d || l;
204
+ let l = "", d = "";
205
+ return !((n = (e = t?.result) === null || e === void 0 ? void 0 : e.params) === null || n === void 0) && n.state && (l = (s = (i = t?.result) === null || i === void 0 ? void 0 : i.params) === null || s === void 0 ? void 0 : s.state), !((r = t?.params) === null || r === void 0) && r.state && (d = (o = t?.params) === null || o === void 0 ? void 0 : o.state), l || d;
206
206
  };
207
207
  function yt({ debounceTime: t }) {
208
208
  let e, n;
@@ -221,14 +221,14 @@ const $n = (t, e) => {
221
221
  function fe() {
222
222
  return sessionStorage.getItem(ft);
223
223
  }
224
- var K, de, F;
224
+ var K, le, F;
225
225
  typeof window < "u" && window.addEventListener("beforeunload", (() => {
226
226
  sessionStorage.removeItem(ft);
227
227
  })), (function(t) {
228
228
  t.Offer = "offer", t.Answer = "answer";
229
229
  })(K || (K = {})), (function(t) {
230
230
  t.Inbound = "inbound", t.Outbound = "outbound";
231
- })(de || (de = {})), (function(t) {
231
+ })(le || (le = {})), (function(t) {
232
232
  t.Invite = "telnyx_rtc.invite", t.Attach = "telnyx_rtc.attach", t.Answer = "telnyx_rtc.answer", t.Info = "telnyx_rtc.info", t.Candidate = "telnyx_rtc.candidate", t.EndOfCandidates = "telnyx_rtc.endOfCandidates", t.Display = "telnyx_rtc.display", t.Media = "telnyx_rtc.media", t.Event = "telnyx_rtc.event", t.Bye = "telnyx_rtc.bye", t.Punt = "telnyx_rtc.punt", t.Broadcast = "telnyx_rtc.broadcast", t.Subscribe = "telnyx_rtc.subscribe", t.Unsubscribe = "telnyx_rtc.unsubscribe", t.ClientReady = "telnyx_rtc.clientReady", t.Modify = "telnyx_rtc.modify", t.Ringing = "telnyx_rtc.ringing", t.GatewayState = "telnyx_rtc.gatewayState", t.Ping = "telnyx_rtc.ping", t.Pong = "telnyx_rtc.pong";
233
233
  })(F || (F = {}));
234
234
  const oe = { generic: "event", [F.Display]: "participantData", [F.Attach]: "participantData", conferenceUpdate: "conferenceUpdate", callUpdate: "callUpdate", vertoClientReady: "vertoClientReady", userMediaError: "userMediaError", peerConnectionFailureError: "peerConnectionFailureError" }, Fn = { destinationNumber: "", remoteCallerName: "Outbound Call", remoteCallerNumber: "", callerName: "", callerNumber: "", audio: !0, useStereo: !1, debug: !1, debugOutput: "socket", attach: !1, screenShare: !1, userVariables: {}, mediaSettings: { useSdpASBandwidthKbps: !1, sdpASBandwidthKbps: 0 }, mutedMicOnStart: !1 };
@@ -244,14 +244,14 @@ var N, tt, se, ae, te;
244
244
  })(ae || (ae = {})), (function(t) {
245
245
  t.REGED = "REGED", t.UNREGED = "UNREGED", t.NOREG = "NOREG", t.FAILED = "FAILED", t.FAIL_WAIT = "FAIL_WAIT", t.REGISTER = "REGISTER", t.TRYING = "TRYING", t.EXPIRED = "EXPIRED", t.UNREGISTER = "UNREGISTER";
246
246
  })(te || (te = {}));
247
- const be = "GLOBAL", ie = {}, Ae = (t, e) => `${t}|${e}`, Xt = (t, e = be) => Ae(t, e) in ie, le = (t, e, n = be) => {
247
+ const be = "GLOBAL", ie = {}, Ae = (t, e) => `${t}|${e}`, Xt = (t, e = be) => Ae(t, e) in ie, de = (t, e, n = be) => {
248
248
  const i = Ae(t, n);
249
249
  i in ie || (ie[i] = []), ie[i].push(e);
250
250
  }, Zt = (t, e, n = be) => {
251
251
  const i = function(s) {
252
252
  ue(t, i, n), e(s);
253
253
  };
254
- return i.prototype.targetRef = e, le(t, i, n);
254
+ return i.prototype.targetRef = e, de(t, i, n);
255
255
  }, ue = (t, e, n = be) => {
256
256
  if (!Xt(t, n)) return !1;
257
257
  const i = Ae(t, n);
@@ -267,7 +267,7 @@ const be = "GLOBAL", ie = {}, Ae = (t, e) => `${t}|${e}`, Xt = (t, e = be) => Ae
267
267
  if (!Xt(t, n)) return s && $(t, e), !1;
268
268
  const r = Ae(t, n), o = ie[r].length;
269
269
  if (!o) return s && $(t, e), !1;
270
- for (let d = o - 1; d >= 0; d--) ie[r][d](e);
270
+ for (let l = o - 1; l >= 0; l--) ie[r][l](e);
271
271
  return s && $(t, e), !0;
272
272
  }, Ke = (t) => {
273
273
  const e = Ae(t, "");
@@ -279,7 +279,7 @@ class bt {
279
279
  constructor(e) {
280
280
  this.session = e, this.previousGatewayState = "", this._wsClient = null, this._host = mt, this._timers = {}, this._useCanaryRtcServer = !1, this._hasCanaryBeenUsed = !1, this.upDur = null, this.downDur = null;
281
281
  const { host: n, env: i, region: s, trickleIce: r, useCanaryRtcServer: o } = e.options;
282
- i && (this._host = i === "development" ? "wss://rtcdev.telnyx.com" : mt), n && (this._host = ((d) => `${Un.test(d) ? "" : "wss://"}${d}`)(n)), s && (this._host = this._host.replace(/rtc(dev)?/, `${s}.rtc$1`)), (r || o) && (this._useCanaryRtcServer = !0);
282
+ i && (this._host = i === "development" ? "wss://rtcdev.telnyx.com" : mt), n && (this._host = ((l) => `${Un.test(l) ? "" : "wss://"}${l}`)(n)), s && (this._host = this._host.replace(/rtc(dev)?/, `${s}.rtc$1`)), (r || o) && (this._useCanaryRtcServer = !0);
283
283
  }
284
284
  get connected() {
285
285
  return this._wsClient && this._wsClient.readyState === Gn;
@@ -305,13 +305,13 @@ class bt {
305
305
  this.session.options.rtcIp && this.session.options.rtcPort && (n = null, this._useCanaryRtcServer = !1, e.searchParams.set("rtc_ip", this.session.options.rtcIp), e.searchParams.set("rtc_port", this.session.options.rtcPort.toString())), n && e.searchParams.set("voice_sdk_id", n), this._useCanaryRtcServer && (e.searchParams.set("canary", "true"), n && !this._hasCanaryBeenUsed && (e.searchParams.delete("voice_sdk_id"), y.debug("first canary connection. Refreshing voice_sdk_id")), this._hasCanaryBeenUsed = !0), this._wsClient = new Bn(e.toString()), this._wsClient.onopen = (i) => $(O.SocketOpen, i, this.session.uuid), this._wsClient.onclose = (i) => $(O.SocketClose, i, this.session.uuid), this._wsClient.onerror = (i) => $(O.SocketError, { error: i, sessionId: this.session.sessionid }, this.session.uuid), this._wsClient.onmessage = (i) => {
306
306
  var s, r;
307
307
  const o = zt(i.data);
308
- var d;
308
+ var l;
309
309
  if (typeof o != "string") {
310
- if (o.voice_sdk_id && (d = o.voice_sdk_id, sessionStorage.setItem(ft, d)), this._unsetTimer(o.id), y.debug(`RECV:
310
+ if (o.voice_sdk_id && (l = o.voice_sdk_id, sessionStorage.setItem(ft, l)), this._unsetTimer(o.id), y.debug(`RECV:
311
311
  `, JSON.stringify(o, null, 2), `
312
312
  `), te[`${(r = (s = o?.result) === null || s === void 0 ? void 0 : s.params) === null || r === void 0 ? void 0 : r.state}`] || !$(o.id, o)) {
313
- const l = pt(o);
314
- $(O.SocketMessage, o, this.session.uuid), l && (this.previousGatewayState = l);
313
+ const d = pt(o);
314
+ $(O.SocketMessage, o, this.session.uuid), d && (this.previousGatewayState = d);
315
315
  }
316
316
  } else this._handleStringResponse(o);
317
317
  };
@@ -323,8 +323,8 @@ class bt {
323
323
  const { request: n } = e, i = new Promise(((s, r) => {
324
324
  if (n.hasOwnProperty("result")) return s();
325
325
  Zt(n.id, ((o) => {
326
- const { result: d, error: l } = Kt(o);
327
- return l ? r(l) : s(d);
326
+ const { result: l, error: d } = Kt(o);
327
+ return d ? r(d) : s(l);
328
328
  }));
329
329
  }));
330
330
  return y.debug(`SEND:
@@ -389,7 +389,7 @@ class tn extends Z {
389
389
  class Jn {
390
390
  constructor(e) {
391
391
  if (this.options = e, this.uuid = me(), this.sessionid = "", this.subscriptions = {}, this.signature = null, this.relayProtocol = null, this.contexts = [], this.timeoutErrorCode = -32e3, this.invalidMethodErrorCode = -32601, this.authenticationRequiredErrorCode = -32e3, this.connection = null, this._jwtAuth = !1, this._autoReconnect = !0, this._idle = !1, this._executeQueue = [], !this.validateOptions()) throw new Error("Invalid init options");
392
- e.debug && y.setLevel("debug"), this._onSocketOpen = this._onSocketOpen.bind(this), this.onNetworkClose = this.onNetworkClose.bind(this), this._onSocketMessage = this._onSocketMessage.bind(this), this._handleLoginError = this._handleLoginError.bind(this), this._attachListeners(), this.connection = new bt(this), this.registerAgent = new qn(this);
392
+ y.setLevel(e.debug ? "debug" : "info"), this._onSocketOpen = this._onSocketOpen.bind(this), this.onNetworkClose = this.onNetworkClose.bind(this), this._onSocketMessage = this._onSocketMessage.bind(this), this._handleLoginError = this._handleLoginError.bind(this), this._attachListeners(), this.connection = new bt(this), this.registerAgent = new qn(this);
393
393
  }
394
394
  get __logger() {
395
395
  return y;
@@ -424,7 +424,7 @@ class Jn {
424
424
  }));
425
425
  }
426
426
  on(e, n) {
427
- return le(e, n, this.uuid), this;
427
+ return de(e, n, this.uuid), this;
428
428
  }
429
429
  off(e, n) {
430
430
  return ue(e, n, this.uuid), this;
@@ -452,7 +452,7 @@ class Jn {
452
452
  this._existsSubscription(e, n) && (n ? (delete this.subscriptions[e][n], ue(e, null, n)) : (delete this.subscriptions[e], Ke(e)));
453
453
  }
454
454
  _addSubscription(e, n = null, i) {
455
- this._existsSubscription(e, i) || (this._existsSubscription(e) || (this.subscriptions[e] = {}), this.subscriptions[e][i] = {}, ye(n) && le(e, n, i));
455
+ this._existsSubscription(e, i) || (this._existsSubscription(e) || (this.subscriptions[e] = {}), this.subscriptions[e][i] = {}, ye(n) && de(e, n, i));
456
456
  }
457
457
  _existsSubscription(e, n) {
458
458
  return !(!this.subscriptions.hasOwnProperty(e) || !(!n || n && this.subscriptions[e].hasOwnProperty(n)));
@@ -481,7 +481,7 @@ class Jn {
481
481
  y.debug("Ping received"), this._pong = !0;
482
482
  }
483
483
  static on(e, n) {
484
- le(e, n);
484
+ de(e, n);
485
485
  }
486
486
  static off(e) {
487
487
  ue(e);
@@ -624,8 +624,8 @@ function Qn() {
624
624
  return { browserInfo: navigator.userAgent, name: v, version: _, supportAudio: !0, supportVideo: !0 };
625
625
  }
626
626
  throw new Error("This browser does not support @telnyx/webrtc. To see browser support list: `TelnyxRTC.webRTCSupportedBrowserList()`");
627
- })(), r = window.RTCPeerConnection, o = window.RTCSessionDescription, d = window.RTCIceCandidate, l = window.navigator && window.navigator.mediaDevices, h = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia;
628
- return { browserInfo: t, browserName: e, browserVersion: n, supportWebRTC: !!(r && o && d && l && h), supportWebRTCAudio: i, supportWebRTCVideo: s, supportRTCPeerConnection: !!r, supportSessionDescription: !!o, supportIceCandidate: !!d, supportMediaDevices: !!l, supportGetUserMedia: !!je };
627
+ })(), r = window.RTCPeerConnection, o = window.RTCSessionDescription, l = window.RTCIceCandidate, d = window.navigator && window.navigator.mediaDevices, h = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia;
628
+ return { browserInfo: t, browserName: e, browserVersion: n, supportWebRTC: !!(r && o && l && d && h), supportWebRTCAudio: i, supportWebRTCVideo: s, supportRTCPeerConnection: !!r, supportSessionDescription: !!o, supportIceCandidate: !!l, supportMediaDevices: !!d, supportGetUserMedia: !!je };
629
629
  } catch (t) {
630
630
  return t.message;
631
631
  }
@@ -657,12 +657,12 @@ function Et(t) {
657
657
  (function(t) {
658
658
  t.not_supported = "not supported", t.full = "full", t.partial = "partial";
659
659
  })(H || (H = {}));
660
- var sn = "2.25.12", We = sn;
660
+ var sn = "2.25.14", We = sn;
661
661
  class on extends Z {
662
662
  constructor(e, n, i, s, r = {}, o) {
663
663
  super(), this.method = "login";
664
- const d = { login: e, passwd: n, login_token: i, userVariables: r, reconnection: o, loginParams: {}, "User-Agent": { sdkVersion: We, data: navigator.userAgent } };
665
- s && (d.sessid = s), this.buildRequest({ method: this.method, params: d });
664
+ const l = { login: e, passwd: n, login_token: i, userVariables: r, reconnection: o, loginParams: {}, "User-Agent": { sdkVersion: We, data: navigator.userAgent } };
665
+ s && (l.sessid = s), this.buildRequest({ method: this.method, params: l });
666
666
  }
667
667
  }
668
668
  class Xn extends Z {
@@ -754,14 +754,14 @@ var Le, an = Yt((function(t, e) {
754
754
  } else I = T[c] = u, ++a._eventsCount;
755
755
  return a;
756
756
  }
757
- function d(a, c, u) {
757
+ function l(a, c, u) {
758
758
  function g() {
759
759
  a.removeListener(c, g), b || (b = !0, u.apply(a, arguments));
760
760
  }
761
761
  var b = !1;
762
762
  return g.listener = u, g;
763
763
  }
764
- function l(a) {
764
+ function d(a) {
765
765
  var c = this._events;
766
766
  if (c) {
767
767
  var u = c[a];
@@ -834,10 +834,10 @@ var Le, an = Yt((function(t, e) {
834
834
  return o(this, a, c, !0);
835
835
  }, s.prototype.once = function(a, c) {
836
836
  if (typeof c != "function") throw new TypeError('"listener" argument must be a function');
837
- return this.on(a, d(this, a, c)), this;
837
+ return this.on(a, l(this, a, c)), this;
838
838
  }, s.prototype.prependOnceListener = function(a, c) {
839
839
  if (typeof c != "function") throw new TypeError('"listener" argument must be a function');
840
- return this.prependListener(a, d(this, a, c)), this;
840
+ return this.prependListener(a, l(this, a, c)), this;
841
841
  }, s.prototype.removeListener = function(a, c) {
842
842
  var u, g, b, T, I;
843
843
  if (typeof c != "function") throw new TypeError('"listener" argument must be a function');
@@ -880,8 +880,8 @@ var Le, an = Yt((function(t, e) {
880
880
  return T;
881
881
  })(c) : [] : u = [], u;
882
882
  }, s.listenerCount = function(a, c) {
883
- return typeof a.listenerCount == "function" ? a.listenerCount(c) : l.call(a, c);
884
- }, s.prototype.listenerCount = l, s.prototype.eventNames = function() {
883
+ return typeof a.listenerCount == "function" ? a.listenerCount(c) : d.call(a, c);
884
+ }, s.prototype.listenerCount = d, s.prototype.eventNames = function() {
885
885
  return 0 < this._eventsCount ? Reflect.ownKeys(this._events) : [];
886
886
  };
887
887
  var f, v = new Uint8Array(16);
@@ -1313,8 +1313,8 @@ function ri(t) {
1313
1313
  })({ rtt: s, jitter: i }), o = (function(h) {
1314
1314
  const { packetsLost: f, packetsReceived: v } = h, _ = f / (v + f) * 100;
1315
1315
  return 20 * Math.log(1 + _);
1316
- })({ packetsLost: e, packetsReceived: n }), d = 93.2 - r - o + 0, l = 1 + 0.035 * d + 7e-6 * d * (d - 60) * (100 - d);
1317
- return Math.min(Math.max(l, 1), 5);
1316
+ })({ packetsLost: e, packetsReceived: n }), l = 93.2 - r - o + 0, d = 1 + 0.035 * l + 7e-6 * l * (l - 60) * (100 - l);
1317
+ return Math.min(Math.max(d, 1), 5);
1318
1318
  }
1319
1319
  function ai(t) {
1320
1320
  return isNaN(t) ? null : t > 4.2 ? "excellent" : t >= 4.1 && t <= 4.2 ? "good" : t >= 3.7 && t <= 4 ? "fair" : t >= 3.1 && t <= 3.6 ? "poor" : "bad";
@@ -1324,12 +1324,12 @@ class ci extends Re {
1324
1324
  super(), this.buildRequest({ type: "debug_report_start", debug_report_id: e, debug_report_version: 1, call_id: n });
1325
1325
  }
1326
1326
  }
1327
- class di extends Re {
1327
+ class li extends Re {
1328
1328
  constructor(e, n) {
1329
1329
  super(), this.buildRequest({ type: "debug_report_stop", debug_report_id: e, debug_report_version: 1, call_id: n });
1330
1330
  }
1331
1331
  }
1332
- class li extends Re {
1332
+ class di extends Re {
1333
1333
  constructor(e, n) {
1334
1334
  super(), this.buildRequest({ type: "debug_report_data", debug_report_id: e, debug_report_version: 1, debug_report_data: n });
1335
1335
  }
@@ -1341,19 +1341,19 @@ function xt(t, e) {
1341
1341
  function ui(t, e) {
1342
1342
  const n = me(), i = new oi({ getStatsInterval: 1e3, rawStats: !1, statsObject: !0, filteredStats: !1, remote: !0, debug: !1, logLevel: "warn" }), s = (r) => L(this, void 0, void 0, (function* () {
1343
1343
  r.event === "stats" && $(O.StatsFrame, (function({ data: o }) {
1344
- var d, l, h, f, v, _, w, C;
1345
- const { audio: k, remote: p } = o, { audio: S } = p, A = (l = (d = S.inbound[0]) === null || d === void 0 ? void 0 : d.jitter) !== null && l !== void 0 ? l : 1 / 0, E = (f = (h = S.inbound[0]) === null || h === void 0 ? void 0 : h.roundTripTime) !== null && f !== void 0 ? f : 1 / 0, P = (_ = (v = k.inbound[0]) === null || v === void 0 ? void 0 : v.packetsReceived) !== null && _ !== void 0 ? _ : -1, D = (C = (w = k.inbound[0]) === null || w === void 0 ? void 0 : w.packetsLost) !== null && C !== void 0 ? C : -1, q = ri({ jitter: 1e3 * A, rtt: 1e3 * E, packetsLost: D, packetsReceived: P });
1344
+ var l, d, h, f, v, _, w, C;
1345
+ const { audio: k, remote: p } = o, { audio: S } = p, A = (d = (l = S.inbound[0]) === null || l === void 0 ? void 0 : l.jitter) !== null && d !== void 0 ? d : 1 / 0, E = (f = (h = S.inbound[0]) === null || h === void 0 ? void 0 : h.roundTripTime) !== null && f !== void 0 ? f : 1 / 0, P = (_ = (v = k.inbound[0]) === null || v === void 0 ? void 0 : v.packetsReceived) !== null && _ !== void 0 ? _ : -1, D = (C = (w = k.inbound[0]) === null || w === void 0 ? void 0 : w.packetsLost) !== null && C !== void 0 ? C : -1, q = ri({ jitter: 1e3 * A, rtt: 1e3 * E, packetsLost: D, packetsReceived: P });
1346
1346
  return { jitter: A, rtt: E, mos: q, quality: ai(q), inboundAudio: k.inbound[0], outboundAudio: k.outbound[0], remoteInboundAudio: S.inbound[0], remoteOutboundAudio: S.outbound[0] };
1347
- })(r), t.uuid), yield t.execute(new li(n, r));
1347
+ })(r), t.uuid), yield t.execute(new di(n, r));
1348
1348
  }));
1349
- return { start: (r, o, d) => L(this, void 0, void 0, (function* () {
1350
- yield t.execute(new ci(n, e)), i.on("timeline", s), yield new Promise(((l) => setTimeout(l, 500))), i.addConnection({ pc: r, peerId: o, connectionId: d });
1349
+ return { start: (r, o, l) => L(this, void 0, void 0, (function* () {
1350
+ yield t.execute(new ci(n, e)), i.on("timeline", s), yield new Promise(((d) => setTimeout(d, 500))), i.addConnection({ pc: r, peerId: o, connectionId: l });
1351
1351
  })), stop: (r) => L(this, void 0, void 0, (function* () {
1352
1352
  const o = i.getTimeline();
1353
- $(O.StatsReport, o, t.uuid), r === "file" && (function(d, l) {
1354
- const h = new Blob([JSON.stringify(d)], { type: "application/json" }), f = URL.createObjectURL(h), v = document.createElement("a");
1355
- v.href = f, v.download = `${l}.json`, v.click(), URL.revokeObjectURL(f);
1356
- })(o, `webrtc-stats-${n}-${Date.now()}`), yield t.execute(new di(n, e)), i.removeAllPeers(), i.destroy();
1353
+ $(O.StatsReport, o, t.uuid), r === "file" && (function(l, d) {
1354
+ const h = new Blob([JSON.stringify(l)], { type: "application/json" }), f = URL.createObjectURL(h), v = document.createElement("a");
1355
+ v.href = f, v.download = `${d}.json`, v.click(), URL.revokeObjectURL(f);
1356
+ })(o, `webrtc-stats-${n}-${Date.now()}`), yield t.execute(new li(n, e)), i.removeAllPeers(), i.destroy();
1357
1357
  })), reportConnectionStateChange: (r) => {
1358
1358
  const o = { event: "connectionstatechange-detailed", tag: "connection", timestamp: (/* @__PURE__ */ new Date()).toISOString(), data: r };
1359
1359
  s(o);
@@ -1365,16 +1365,16 @@ function ui(t, e) {
1365
1365
  const cn = (t, e) => {
1366
1366
  const { contentType: n, canvasType: i, callID: s, canvasInfo: r = null, currentLayerIdx: o = -1 } = e;
1367
1367
  r && i !== "mcu-personal-canvas" && delete r.memberID;
1368
- const d = { type: oe.conferenceUpdate, call: t.calls[s], canvasInfo: hi(r), currentLayerIdx: o };
1368
+ const l = { type: oe.conferenceUpdate, call: t.calls[s], canvasInfo: hi(r), currentLayerIdx: o };
1369
1369
  switch (n) {
1370
1370
  case "layer-info": {
1371
- const l = Object.assign({ action: se.LayerInfo }, d);
1372
- $(O.Notification, l, t.uuid);
1371
+ const d = Object.assign({ action: se.LayerInfo }, l);
1372
+ $(O.Notification, d, t.uuid);
1373
1373
  break;
1374
1374
  }
1375
1375
  case "layout-info": {
1376
- const l = Object.assign({ action: se.LayoutInfo }, d);
1377
- $(O.Notification, l, t.uuid);
1376
+ const d = Object.assign({ action: se.LayoutInfo }, l);
1377
+ $(O.Notification, d, t.uuid);
1378
1378
  break;
1379
1379
  }
1380
1380
  }
@@ -1385,9 +1385,9 @@ const cn = (t, e) => {
1385
1385
  class Ot {
1386
1386
  constructor(e, n, i, s, r) {
1387
1387
  this.type = e, this.options = n, this.onSdpReadyTwice = null, this.statsReporter = null, this._negotiating = !1, this._prevConnectionState = null, this._restartedIceOnConnectionStateFailed = !1, this._sleepWakeupIntervalId = null, this.handleConnectionStateChange = (o) => L(this, void 0, void 0, (function* () {
1388
- const { connectionState: d } = this.instance;
1389
- if (y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}] Connection State changed: ${this._prevConnectionState} -> ${d}`), d === "failed" || d === "disconnected") {
1390
- const l = () => L(this, void 0, void 0, (function* () {
1388
+ const { connectionState: l } = this.instance;
1389
+ if (y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}] Connection State changed: ${this._prevConnectionState} -> ${l}`), l === "failed" || l === "disconnected") {
1390
+ const d = () => L(this, void 0, void 0, (function* () {
1391
1391
  if (this.isDebugEnabled && this.statsReporter) {
1392
1392
  const h = yield (function(f, v) {
1393
1393
  return L(this, void 0, void 0, (function* () {
@@ -1412,17 +1412,17 @@ class Ot {
1412
1412
  })(this.instance, this._prevConnectionState);
1413
1413
  this.statsReporter.reportConnectionStateChange(h);
1414
1414
  }
1415
- this._restartedIceOnConnectionStateFailed ? (y.debug("Peer Connection failed again after ICE restart. Recovering call via peer reconnection through error handling."), $(O.PeerConnectionFailureError, { error: new Error(`Peer Connection failed twice. previous state: ${this._prevConnectionState}, current state: ${d}`), sessionId: this._session.sessionid }, this.options.id)) : (this.instance.restartIce(), d === "failed" && (this._restartedIceOnConnectionStateFailed = !0, y.debug("ICE has been restarted on connection state failed.")), this._isTrickleIce() ? yield this.startTrickleIceNegotiation() : this.startNegotiation()), window.removeEventListener("online", l);
1415
+ this._restartedIceOnConnectionStateFailed ? (y.debug("Peer Connection failed again after ICE restart. Recovering call via peer reconnection through error handling."), $(O.PeerConnectionFailureError, { error: new Error(`Peer Connection failed twice. previous state: ${this._prevConnectionState}, current state: ${l}`), sessionId: this._session.sessionid }, this.options.id)) : (this.instance.restartIce(), l === "failed" && (this._restartedIceOnConnectionStateFailed = !0, y.debug("ICE has been restarted on connection state failed.")), this._isTrickleIce() ? yield this.startTrickleIceNegotiation() : this.startNegotiation()), window.removeEventListener("online", d);
1416
1416
  }));
1417
- navigator.onLine ? l() : window.addEventListener("online", l);
1417
+ navigator.onLine ? d() : window.addEventListener("online", d);
1418
1418
  }
1419
- this._prevConnectionState === "connected" && d === "disconnected" && (yield this._resetJitterBuffer()), this._prevConnectionState === "disconnected" && d === "connected" && (yield this._resetJitterBuffer()), this._prevConnectionState = d, this._isTrickleIce() && (d === "connecting" && performance.mark("peer-connection-connecting"), d === "connected" && (performance.mark("peer-connection-connected"), console.group("Performance Metrics"), console.table(this.trickleIcePerformanceMetrics), console.groupEnd(), performance.clearMarks())), this._restartNegotiationOnDeviceSleepWakeup();
1419
+ this._prevConnectionState === "connected" && l === "disconnected" && (yield this._resetJitterBuffer()), this._prevConnectionState === "disconnected" && l === "connected" && (yield this._resetJitterBuffer()), this._prevConnectionState = l, this._isTrickleIce() && (l === "connecting" && performance.mark("peer-connection-connecting"), l === "connected" && (performance.mark("peer-connection-connected"), console.group("Performance Metrics"), console.table(this.trickleIcePerformanceMetrics), console.groupEnd(), performance.clearMarks())), this._restartNegotiationOnDeviceSleepWakeup();
1420
1420
  })), this._handleIceConnectionStateChange = (o) => {
1421
1421
  y.debug(`[${(/* @__PURE__ */ new Date()).toISOString()}] ICE Connection State`, this.instance.iceConnectionState);
1422
1422
  }, this._handleIceGatheringStateChange = (o) => {
1423
1423
  y.debug(`[${(/* @__PURE__ */ new Date()).toISOString()}] ICE Gathering State`, this.instance.iceGatheringState);
1424
- }, this._setCodecs = (o, d) => {
1425
- if (o.setCodecPreferences) return o.setCodecPreferences(d);
1424
+ }, this._setCodecs = (o, l) => {
1425
+ if (o.setCodecPreferences) return o.setCodecPreferences(l);
1426
1426
  }, y.info("New Peer with type:", this.type, "Options:", this.options), this._constraints = { offerToReceiveAudio: !0, offerToReceiveVideo: !!n.video }, this._sdpReady = this._sdpReady.bind(this), this.handleSignalingStateChangeEvent = this.handleSignalingStateChangeEvent.bind(this), this.handleNegotiationNeededEvent = this.handleNegotiationNeededEvent.bind(this), this.handleTrackEvent = this.handleTrackEvent.bind(this), this.createPeerConnection = this.createPeerConnection.bind(this), this._session = i, this._trickleIceSdpFn = s, this._registerPeerEvents = r;
1427
1427
  }
1428
1428
  get isOffer() {
@@ -1454,8 +1454,8 @@ class Ot {
1454
1454
  }));
1455
1455
  }
1456
1456
  get trickleIcePerformanceMetrics() {
1457
- const e = performance.measure("new-call", "new-call-start", "new-call-end"), n = performance.measure("peer-creation", "peer-creation-start", "peer-creation-end"), i = performance.measure("ice-gathering", "ice-gathering-start", "ice-gathering-end"), s = performance.measure("sdp-send", "sdp-send-start", "sdp-send-end"), r = performance.measure("invite-send", "new-call-start", "sdp-send-start"), o = performance.measure("total-duration", "peer-creation-start", "sdp-send-end"), d = (l) => `${l.toFixed(2)}ms`;
1458
- return { "New Call": { duration: d(e.duration) }, "Peer Creation": { duration: d(n.duration) }, "ICE Gathering": { duration: d(i.duration) }, [this._isOffer() ? "Invite Send" : "Answer Send"]: { duration: d(r.duration) }, "SDP Send": { duration: d(s.duration) }, "Total Duration": { duration: d(o.duration) } };
1457
+ const e = performance.measure("new-call", "new-call-start", "new-call-end"), n = performance.measure("peer-creation", "peer-creation-start", "peer-creation-end"), i = performance.measure("ice-gathering", "ice-gathering-start", "ice-gathering-end"), s = performance.measure("sdp-send", "sdp-send-start", "sdp-send-end"), r = performance.measure("invite-send", "new-call-start", "sdp-send-start"), o = performance.measure("total-duration", "peer-creation-start", "sdp-send-end"), l = (d) => `${d.toFixed(2)}ms`;
1458
+ return { "New Call": { duration: l(e.duration) }, "Peer Creation": { duration: l(n.duration) }, "ICE Gathering": { duration: l(i.duration) }, [this._isOffer() ? "Invite Send" : "Answer Send"]: { duration: l(r.duration) }, "SDP Send": { duration: l(s.duration) }, "Total Duration": { duration: l(o.duration) } };
1459
1459
  }
1460
1460
  handleSignalingStateChangeEvent(e) {
1461
1461
  switch (y.info("signalingState:", this.instance.signalingState), this.instance.signalingState) {
@@ -1502,7 +1502,7 @@ class Ot {
1502
1502
  y.info("Local video tracks constraints: ", f.getConstraints());
1503
1503
  }));
1504
1504
  }
1505
- const { audioCodecs: d, videoCodecs: l } = ((h) => {
1505
+ const { audioCodecs: l, videoCodecs: d } = ((h) => {
1506
1506
  const f = [], v = [];
1507
1507
  return h && h.length !== 0 ? (h.forEach(((_) => {
1508
1508
  const w = _.mimeType.toLocaleLowerCase();
@@ -1514,12 +1514,12 @@ class Ot {
1514
1514
  o.forEach(((f) => {
1515
1515
  f.kind === "audio" && (this.options.userVariables.microphoneLabel = f.label), f.kind === "video" && (this.options.userVariables.cameraLabel = f.label);
1516
1516
  const v = this.instance.addTransceiver(f, h);
1517
- f.kind === "audio" && d.length > 0 && this._setCodecs(v, d), f.kind === "video" && l.length > 0 && this._setCodecs(v, l);
1517
+ f.kind === "audio" && l.length > 0 && this._setCodecs(v, l), f.kind === "video" && d.length > 0 && this._setCodecs(v, d);
1518
1518
  }));
1519
1519
  } else typeof this.instance.addTrack == "function" ? (o.forEach(((h) => {
1520
1520
  h.kind === "audio" && (this.options.userVariables.microphoneLabel = h.label), h.kind === "video" && (this.options.userVariables.cameraLabel = h.label), this.instance.addTrack(h, i);
1521
1521
  })), this.instance.getTransceivers().forEach(((h) => {
1522
- h.receiver.track.kind === "audio" && d.length > 0 && this._setCodecs(h, d), h.receiver.track.kind === "video" && l.length > 0 && this._setCodecs(h, l);
1522
+ h.receiver.track.kind === "audio" && l.length > 0 && this._setCodecs(h, l), h.receiver.track.kind === "video" && d.length > 0 && this._setCodecs(h, d);
1523
1523
  }))) : this.instance.addStream(i);
1524
1524
  s === !1 && Ee(n, i);
1525
1525
  }
@@ -1538,7 +1538,7 @@ class Ot {
1538
1538
  _createOffer() {
1539
1539
  return L(this, void 0, void 0, (function* () {
1540
1540
  if (this._isOffer()) {
1541
- this._constraints.offerToReceiveAudio = !!this.options.audio, this._constraints.offerToReceiveVideo = !!this.options.video, y.info("_createOffer - this._constraints", this._constraints);
1541
+ this._constraints.offerToReceiveAudio = this.options.audio !== !1, this._constraints.offerToReceiveVideo = !!this.options.video, y.info("_createOffer - this._constraints", this._constraints);
1542
1542
  try {
1543
1543
  const e = yield this.instance.createOffer(this._constraints);
1544
1544
  return yield this._setLocalDescription(e), this._isTrickleIce() || this._sdpReady(), e;
@@ -1580,8 +1580,8 @@ class Ot {
1580
1580
  if (ge(this.options.localStream)) return this.options.localStream;
1581
1581
  const e = yield (n = this.options, L(void 0, void 0, void 0, (function* () {
1582
1582
  let { audio: i = !0, micId: s, video: r = !1, camId: o } = n;
1583
- const { micLabel: d = "", camLabel: l = "" } = n;
1584
- return s && (s = yield Ue(s, d, ae.AudioIn).catch(((h) => null)), s && (typeof i == "boolean" && (i = {}), i.deviceId = { exact: s })), o && (o = yield Ue(o, l, ae.Video).catch(((h) => null)), o && (typeof r == "boolean" && (r = {}), r.deviceId = { exact: o })), { audio: i, video: r };
1583
+ const { micLabel: l = "", camLabel: d = "" } = n;
1584
+ return s && (s = yield Ue(s, l, ae.AudioIn).catch(((h) => null)), s && (typeof i == "boolean" && (i = {}), i.deviceId = { exact: s })), o && (o = yield Ue(o, d, ae.Video).catch(((h) => null)), o && (typeof r == "boolean" && (r = {}), r.deviceId = { exact: o })), { audio: i, video: r };
1585
1585
  })));
1586
1586
  var n;
1587
1587
  return je(e);
@@ -1633,7 +1633,7 @@ class Ot {
1633
1633
  }
1634
1634
  }
1635
1635
  const Lt = We;
1636
- class dn {
1636
+ class ln {
1637
1637
  constructor(e, n) {
1638
1638
  this.session = e, this.id = "", this.state = N[N.New], this.prevState = "", this.channels = [], this.role = tt.Participant, this.extension = null, this._state = N.New, this._prevState = N.New, this.gotAnswer = !1, this.gotEarly = !1, this._lastSerno = 0, this._targetNodeId = null, this._iceTimeout = null, this._iceDone = !1, this._statsBindings = [], this._statsIntervalId = null, this._pendingIceCandidates = [], this._isRemoteDescriptionSet = !1, this._checkConferenceSerno = (p) => {
1639
1639
  const S = p < 0 || !this._lastSerno || this._lastSerno && p === this._lastSerno + 1;
@@ -1652,8 +1652,8 @@ class dn {
1652
1652
  }));
1653
1653
  }));
1654
1654
  };
1655
- const { iceServers: i, speaker: s, micId: r, micLabel: o, camId: d, camLabel: l, localElement: h, remoteElement: f, options: v, mediaConstraints: { audio: _, video: w }, ringtoneFile: C, ringbackFile: k } = e;
1656
- this.options = Object.assign({}, Fn, { audio: _, video: w, iceServers: n?.iceServers && Array.isArray(n.iceServers) ? n.iceServers : i, localElement: h, remoteElement: f, micId: r, micLabel: o, camId: d, camLabel: l, speakerId: s, ringtoneFile: C, ringbackFile: k, debug: v.debug, debugOutput: v.debugOutput, trickleIce: v.trickleIce, prefetchIceCandidates: v.prefetchIceCandidates, keepConnectionAliveOnSocketClose: v.keepConnectionAliveOnSocketClose, mutedMicOnStart: v.mutedMicOnStart }, n), this._onMediaError = this._onMediaError.bind(this), this._onPeerConnectionFailureError = this._onPeerConnectionFailureError.bind(this), this._onTrickleIceSdp = this._onTrickleIceSdp.bind(this), this._registerPeerEvents = this._registerPeerEvents.bind(this), this._registerTrickleIcePeerEvents = this._registerTrickleIcePeerEvents.bind(this), this._init(), this.options && (this._ringtone = kt(this.options.ringtoneFile, "_ringtone"), this._ringback = kt(this.options.ringbackFile, "_ringback"));
1655
+ const { iceServers: i, speaker: s, micId: r, micLabel: o, camId: l, camLabel: d, localElement: h, remoteElement: f, options: v, mediaConstraints: { audio: _, video: w }, ringtoneFile: C, ringbackFile: k } = e;
1656
+ this.options = Object.assign({}, Fn, { audio: _, video: w, iceServers: n?.iceServers && Array.isArray(n.iceServers) ? n.iceServers : i, localElement: h, remoteElement: f, micId: r, micLabel: o, camId: l, camLabel: d, speakerId: s, ringtoneFile: C, ringbackFile: k, debug: v.debug, debugOutput: v.debugOutput, trickleIce: v.trickleIce, prefetchIceCandidates: v.prefetchIceCandidates, keepConnectionAliveOnSocketClose: v.keepConnectionAliveOnSocketClose, mutedMicOnStart: v.mutedMicOnStart }, n), this._onMediaError = this._onMediaError.bind(this), this._onPeerConnectionFailureError = this._onPeerConnectionFailureError.bind(this), this._onTrickleIceSdp = this._onTrickleIceSdp.bind(this), this._registerPeerEvents = this._registerPeerEvents.bind(this), this._registerTrickleIcePeerEvents = this._registerTrickleIcePeerEvents.bind(this), this._init(), this.options && (this._ringtone = kt(this.options.ringtoneFile, "_ringtone"), this._ringback = kt(this.options.ringbackFile, "_ringback"));
1657
1657
  }
1658
1658
  get performanceMetrics() {
1659
1659
  const e = performance.measure("peer-creation", "peer-creation-start", "peer-creation-end"), n = performance.measure("ice-gathering", "ice-gathering-start", "ice-gathering-end"), i = performance.measure("sdp-send", "sdp-send-start", "sdp-send-end"), s = performance.measure("total-duration", "peer-creation-start", "sdp-send-end"), r = (o) => `${o.toFixed(2)}ms`;
@@ -1685,13 +1685,13 @@ class dn {
1685
1685
  }
1686
1686
  invite() {
1687
1687
  return L(this, void 0, void 0, (function* () {
1688
- this.direction = de.Outbound, this.options.trickleIce && this._resetTrickleIceCandidateState(), performance.mark("peer-creation-start"), this.peer = new Ot(K.Offer, this.options, this.session, this._onTrickleIceSdp, this.options.trickleIce ? this._registerTrickleIcePeerEvents : this._registerPeerEvents), yield this.peer.init();
1688
+ this.direction = le.Outbound, this.options.trickleIce && this._resetTrickleIceCandidateState(), performance.mark("peer-creation-start"), this.peer = new Ot(K.Offer, this.options, this.session, this._onTrickleIceSdp, this.options.trickleIce ? this._registerTrickleIcePeerEvents : this._registerPeerEvents), yield this.peer.init();
1689
1689
  }));
1690
1690
  }
1691
1691
  answer(e = {}) {
1692
1692
  var n;
1693
1693
  return L(this, void 0, void 0, (function* () {
1694
- performance.mark("new-call-start"), this.stopRingtone(), this.direction = de.Inbound, ((n = e?.customHeaders) === null || n === void 0 ? void 0 : n.length) > 0 && (this.options = Object.assign(Object.assign({}, this.options), { customHeaders: e.customHeaders })), this.options.trickleIce && this._resetTrickleIceCandidateState(), performance.mark("peer-creation-start"), this.peer = new Ot(K.Answer, this.options, this.session, this._onTrickleIceSdp, this.options.trickleIce ? this._registerTrickleIcePeerEvents : this._registerPeerEvents), yield this.peer.init(), performance.mark("new-call-end");
1694
+ performance.mark("new-call-start"), this.stopRingtone(), this.direction = le.Inbound, ((n = e?.customHeaders) === null || n === void 0 ? void 0 : n.length) > 0 && (this.options = Object.assign(Object.assign({}, this.options), { customHeaders: e.customHeaders })), this.options.trickleIce && this._resetTrickleIceCandidateState(), performance.mark("peer-creation-start"), this.peer = new Ot(K.Answer, this.options, this.session, this._onTrickleIceSdp, this.options.trickleIce ? this._registerTrickleIcePeerEvents : this._registerPeerEvents), yield this.peer.init(), performance.mark("new-call-end");
1695
1695
  }));
1696
1696
  }
1697
1697
  playRingtone() {
@@ -1708,18 +1708,18 @@ class dn {
1708
1708
  }
1709
1709
  hangup(e, n) {
1710
1710
  var i, s, r;
1711
- let o = e || {}, d = n !== !1;
1711
+ let o = e || {}, l = n !== !1;
1712
1712
  this.cause = o.cause || "NORMAL_CLEARING", this.causeCode = o.causeCode || 16, this.sipCode = o.sipCode || null, this.sipReason = o.sipReason || null, this.sipCallId = o.sip_call_id || null, this.options.customHeaders = [...(i = this.options.customHeaders) !== null && i !== void 0 ? i : [], ...(r = (s = o?.dialogParams) === null || s === void 0 ? void 0 : s.customHeaders) !== null && r !== void 0 ? r : []], this.setState(N.Hangup);
1713
- const l = () => {
1713
+ const d = () => {
1714
1714
  var h;
1715
1715
  return (h = this.peer) === null || h === void 0 || h.close(), this.setState(N.Destroy);
1716
1716
  };
1717
- if (this.stopRingtone(), this.stopRingback(), d) {
1717
+ if (this.stopRingtone(), this.stopRingback(), l) {
1718
1718
  const h = new Zn({ sipCode: this.sipCode, sip_call_id: this.sipCallId, sessid: this.session.sessionid, dialogParams: this.options, cause: "USER_BUSY", causeCode: 17 });
1719
1719
  this._execute(h).catch(((f) => {
1720
1720
  y.error("telnyx_rtc.bye failed!", f), $(O.Error, { error: f, sessionId: this.session.sessionid }, this.session.uuid);
1721
- })).then(l.bind(this));
1722
- } else l();
1721
+ })).then(d.bind(this));
1722
+ } else d();
1723
1723
  }
1724
1724
  hold() {
1725
1725
  const e = new Qe({ sessid: this.session.sessionid, action: "hold", dialogParams: this.options });
@@ -1756,8 +1756,8 @@ class dn {
1756
1756
  if (s) {
1757
1757
  const r = yield nt({ audio: { deviceId: { exact: e } } }), o = r.getAudioTracks()[0];
1758
1758
  o.enabled = !n, s.replaceTrack(o), this.options.micId = e;
1759
- const { localStream: d } = this.options;
1760
- d.getAudioTracks().forEach(((l) => l.stop())), d.getVideoTracks().forEach(((l) => r.addTrack(l))), this.options.localStream = r;
1759
+ const { localStream: l } = this.options;
1760
+ l.getAudioTracks().forEach(((d) => d.stop())), l.getVideoTracks().forEach(((d) => r.addTrack(d))), this.options.localStream = r;
1761
1761
  }
1762
1762
  }));
1763
1763
  }
@@ -1779,8 +1779,8 @@ class dn {
1779
1779
  if (i) {
1780
1780
  const s = yield nt({ video: { deviceId: { exact: e } } }), r = s.getVideoTracks()[0];
1781
1781
  i.replaceTrack(r);
1782
- const { localElement: o, localStream: d } = this.options;
1783
- Ee(o, s), this.options.camId = e, d.getAudioTracks().forEach(((l) => s.addTrack(l))), d.getVideoTracks().forEach(((l) => l.stop())), this.options.localStream = s;
1782
+ const { localElement: o, localStream: l } = this.options;
1783
+ Ee(o, s), this.options.camId = e, l.getAudioTracks().forEach(((d) => s.addTrack(d))), l.getVideoTracks().forEach(((d) => d.stop())), this.options.localStream = s;
1784
1784
  }
1785
1785
  }));
1786
1786
  }
@@ -1803,7 +1803,7 @@ class dn {
1803
1803
  const o = r.getParameters();
1804
1804
  o.encodings || (o.encodings = [{ rid: "h" }]), y.info("Parameters: ", o), y.info("Setting max ", n === "audio" ? "audio" : "video", " bandwidth to: ", e, " [bps]"), o.encodings[0].maxBitrate = e, yield r.setParameters(o).then((() => {
1805
1805
  y.info(n === "audio" ? "New audio" : "New video", " bandwidth settings in use: ", r.getParameters());
1806
- })).catch(((d) => y.error(d)));
1806
+ })).catch(((l) => y.error(l)));
1807
1807
  } else y.error("Could not set bandwidth (reason: no " + n + " sender). Dynamic bandwidth can only be set when there is a call running - is there any call running?)");
1808
1808
  }));
1809
1809
  }
@@ -1819,7 +1819,7 @@ class dn {
1819
1819
  this._statsBindings.push(i), !this._statsIntervalId && this._startStats(2e3);
1820
1820
  }
1821
1821
  setState(e) {
1822
- switch (this._prevState = this._state, this._state = e, this.state = N[this._state].toLowerCase(), this.prevState = N[this._prevState].toLowerCase(), y.info(`Call ${this.id} state change from ${this.prevState} to ${this.state}`), this._dispatchNotification({ type: oe.callUpdate, call: this }), e) {
1822
+ switch (this._prevState = this._state, this._state = e, this.state = N[this._state].toLowerCase(), this.prevState = N[this._prevState].toLowerCase(), y.debug(`Call ${this.id} state change from ${this.prevState} to ${this.state}`), this._dispatchNotification({ type: oe.callUpdate, call: this }), e) {
1823
1823
  case N.Purge:
1824
1824
  y.debug(`Call ${this.id} hangup call due to purge state`), this.hangup({ cause: "PURGE", causeCode: "01" }, !1);
1825
1825
  break;
@@ -1846,9 +1846,9 @@ class dn {
1846
1846
  break;
1847
1847
  case F.Display:
1848
1848
  case F.Attach: {
1849
- const { display_name: r, display_number: o, display_direction: d } = i;
1849
+ const { display_name: r, display_number: o, display_direction: l } = i;
1850
1850
  this.extension = o;
1851
- const l = d === de.Inbound ? de.Outbound : de.Inbound, h = { type: oe[n], call: this, displayName: r, displayNumber: o, displayDirection: l };
1851
+ const d = l === le.Inbound ? le.Outbound : le.Inbound, h = { type: oe[n], call: this, displayName: r, displayNumber: o, displayDirection: d };
1852
1852
  $(O.Notification, h, this.id) || $(O.Notification, h, this.session.uuid);
1853
1853
  break;
1854
1854
  }
@@ -1876,8 +1876,8 @@ class dn {
1876
1876
  switch (i) {
1877
1877
  case "bootObj": {
1878
1878
  this._lastSerno = 0;
1879
- const { chatChannel: d, infoChannel: l, modChannel: h, laName: f, conferenceMemberID: v, role: _ } = n;
1880
- this._dispatchConferenceUpdate({ action: se.Join, conferenceName: f, participantId: Number(v), role: _ }), d && (yield this._subscribeConferenceChat(d)), l && (yield this._subscribeConferenceInfo(l));
1879
+ const { chatChannel: l, infoChannel: d, modChannel: h, laName: f, conferenceMemberID: v, role: _ } = n;
1880
+ this._dispatchConferenceUpdate({ action: se.Join, conferenceName: f, participantId: Number(v), role: _ }), l && (yield this._subscribeConferenceChat(l)), d && (yield this._subscribeConferenceInfo(d));
1881
1881
  const w = [];
1882
1882
  for (const C in s) w.push(Object.assign({ callId: s[C][0], index: Number(C) }, Oe(s[C][1])));
1883
1883
  this._dispatchConferenceUpdate({ action: se.Bootstrap, participants: w });
@@ -1908,8 +1908,8 @@ class dn {
1908
1908
  _subscribeConferenceChat(e) {
1909
1909
  return L(this, void 0, void 0, (function* () {
1910
1910
  const n = { nodeId: this.nodeId, channels: [e], handler: (s) => {
1911
- const { direction: r, from: o, fromDisplay: d, message: l, type: h } = s.data;
1912
- this._dispatchConferenceUpdate({ action: se.ChatMessage, direction: r, participantNumber: o, participantName: d, messageText: l, messageType: h, messageId: s.eventSerno });
1911
+ const { direction: r, from: o, fromDisplay: l, message: d, type: h } = s.data;
1912
+ this._dispatchConferenceUpdate({ action: se.ChatMessage, direction: r, participantNumber: o, participantName: l, messageText: d, messageType: h, messageId: s.eventSerno });
1913
1913
  } }, i = yield this.session.vertoSubscribe(n).catch(((s) => {
1914
1914
  y.error("ConfChat subscription error:", s);
1915
1915
  }));
@@ -1960,22 +1960,22 @@ class dn {
1960
1960
  `), void this._requestAnotherLocalDescription();
1961
1961
  (i = (n = this.peer) === null || n === void 0 ? void 0 : n.instance) === null || i === void 0 || i.removeEventListener("icecandidate", this._onIce), performance.mark("ice-gathering-end");
1962
1962
  let o = null;
1963
- const d = { sessid: this.session.sessionid, sdp: s, dialogParams: this.options, "User-Agent": `Web-${Lt}` };
1963
+ const l = { sessid: this.session.sessionid, sdp: s, dialogParams: this.options, "User-Agent": `Web-${Lt}` };
1964
1964
  switch (r) {
1965
1965
  case K.Offer:
1966
- this.setState(N.Requesting), o = new Tt(d);
1966
+ this.setState(N.Requesting), o = new Tt(l);
1967
1967
  break;
1968
1968
  case K.Answer:
1969
- this.setState(N.Answering), o = this.options.attach === !0 ? new rt(d) : new At(d);
1969
+ this.setState(N.Answering), o = this.options.attach === !0 ? new rt(l) : new At(l);
1970
1970
  break;
1971
1971
  default:
1972
1972
  return y.error(`${this.id} - Unknown local SDP type:`, e), this.hangup({}, !1);
1973
1973
  }
1974
- performance.mark("sdp-send-start"), this._execute(o).then(((l) => {
1975
- const { node_id: h = null } = l;
1974
+ performance.mark("sdp-send-start"), this._execute(o).then(((d) => {
1975
+ const { node_id: h = null } = d;
1976
1976
  this._targetNodeId = h, r === K.Offer ? this.setState(N.Trying) : this.setState(N.Active);
1977
- })).catch(((l) => {
1978
- y.error(`${this.id} - Sending ${r} error:`, l), this.hangup();
1977
+ })).catch(((d) => {
1978
+ y.error(`${this.id} - Sending ${r} error:`, d), this.hangup();
1979
1979
  })).finally((() => {
1980
1980
  performance.mark("sdp-send-end"), console.group("Performance Metrics"), console.table(this.performanceMetrics), console.groupEnd(), performance.clearMarks();
1981
1981
  }));
@@ -1996,8 +1996,8 @@ class dn {
1996
1996
  return y.error(`${this.id} - Unknown local SDP type:`, e), this.hangup({}, !1);
1997
1997
  }
1998
1998
  performance.mark("sdp-send-start"), this._execute(s).then(((o) => {
1999
- const { node_id: d = null } = o;
2000
- this._targetNodeId = d, i === K.Offer ? this.setState(N.Trying) : this.setState(N.Active);
1999
+ const { node_id: l = null } = o;
2000
+ this._targetNodeId = l, i === K.Offer ? this.setState(N.Trying) : this.setState(N.Active);
2001
2001
  })).catch(((o) => {
2002
2002
  y.error(`${this.id} - Sending ${i} error:`, o), this.hangup();
2003
2003
  })).finally((() => {
@@ -2095,7 +2095,7 @@ class dn {
2095
2095
  _init() {
2096
2096
  const { id: e, userVariables: n, remoteCallerNumber: i, onNotification: s } = this.options;
2097
2097
  var r;
2098
- this.options.id = e ? e.toString() : me(), this.id = this.options.id, n && (r = n, Object.keys(r).length !== 0) || (this.options.userVariables = this.session.options.userVariables || {}), i || (this.options.remoteCallerNumber = this.options.destinationNumber), this.session.calls[this.id] = this, le(O.MediaError, this._onMediaError, this.id), le(O.PeerConnectionFailureError, this._onPeerConnectionFailureError, this.id), ye(s) && le(O.Notification, s.bind(this), this.id), this.setState(N.New), y.info("New Call with Options:", this.options);
2098
+ this.options.id = e ? e.toString() : me(), this.id = this.options.id, n && (r = n, Object.keys(r).length !== 0) || (this.options.userVariables = this.session.options.userVariables || {}), i || (this.options.remoteCallerNumber = this.options.destinationNumber), this.session.calls[this.id] = this, de(O.MediaError, this._onMediaError, this.id), de(O.PeerConnectionFailureError, this._onPeerConnectionFailureError, this.id), ye(s) && de(O.Notification, s.bind(this), this.id), this.setState(N.New), y.info("New Call with Options:", this.options);
2099
2099
  }
2100
2100
  _finalize() {
2101
2101
  var e;
@@ -2107,10 +2107,10 @@ class dn {
2107
2107
  this._statsIntervalId = setInterval(this._doStats, e), y.info("Stats started");
2108
2108
  }
2109
2109
  _stopStats() {
2110
- this._statsIntervalId && (clearInterval(this._statsIntervalId), this._statsIntervalId = null), y.info("Stats stopped");
2110
+ this._statsIntervalId && (clearInterval(this._statsIntervalId), this._statsIntervalId = null), y.debug("Stats stopped");
2111
2111
  }
2112
2112
  }
2113
- dn.setStateTelnyx = (t) => {
2113
+ ln.setStateTelnyx = (t) => {
2114
2114
  if (t) {
2115
2115
  switch (t._state) {
2116
2116
  case N.Requesting:
@@ -2138,7 +2138,7 @@ dn.setStateTelnyx = (t) => {
2138
2138
  return t;
2139
2139
  }
2140
2140
  };
2141
- class he extends dn {
2141
+ class he extends ln {
2142
2142
  constructor() {
2143
2143
  super(...arguments), this._statsInterval = null, this.sendConversationMessage = (e, n) => this.session.execute(new si(e, n));
2144
2144
  }
@@ -2154,8 +2154,8 @@ class he extends dn {
2154
2154
  this.screenShare && this.screenShare.hangup();
2155
2155
  }));
2156
2156
  }));
2157
- const { remoteCallerName: s, remoteCallerNumber: r, callerName: o, callerNumber: d } = this.options, l = Object.assign({ screenShare: !0, localStream: n, destinationNumber: `${this.extension}-screen`, remoteCallerName: s, remoteCallerNumber: `${r}-screen`, callerName: `${o} (Screen)`, callerNumber: `${d} (Screen)` }, e);
2158
- return this.screenShare = new he(this.session, l), this.screenShare.invite(), this.screenShare;
2157
+ const { remoteCallerName: s, remoteCallerNumber: r, callerName: o, callerNumber: l } = this.options, d = Object.assign({ screenShare: !0, localStream: n, destinationNumber: `${this.extension}-screen`, remoteCallerName: s, remoteCallerNumber: `${r}-screen`, callerName: `${o} (Screen)`, callerNumber: `${l} (Screen)` }, e);
2158
+ return this.screenShare = new he(this.session, d), this.screenShare.invite(), this.screenShare;
2159
2159
  }));
2160
2160
  }
2161
2161
  stopScreenShare() {
@@ -2180,8 +2180,8 @@ class he extends dn {
2180
2180
  n.forEach(((o) => {
2181
2181
  s.includes(o.type) || (i += `
2182
2182
  ${o.type}
2183
- `, Object.keys(o).forEach(((d) => {
2184
- r.includes(d) || (i += ` ${d}: ${o[d]}
2183
+ `, Object.keys(o).forEach(((l) => {
2184
+ r.includes(l) || (i += ` ${l}: ${o[l]}
2185
2185
  `);
2186
2186
  })));
2187
2187
  })), y.info(i);
@@ -2190,7 +2190,7 @@ ${o.type}
2190
2190
  }
2191
2191
  class pi extends Jn {
2192
2192
  constructor(e) {
2193
- super(e), this.calls = {}, this.autoRecoverCalls = !0, this._iceServers = [], this._localElement = null, this._remoteElement = null, this._jwtAuth = !0, this._audioConstraints = !0, this._videoConstraints = !1, this._speaker = null, this._onlineHandler = null, this._offlineHandler = null, this._wasOffline = !1, this._videoConstraints = e.video || !1, this.iceServers = e.iceServers, this.ringtoneFile = e.ringtoneFile, this.ringbackFile = e.ringbackFile, this._setupNetworkListeners();
2193
+ super(e), this.calls = {}, this.autoRecoverCalls = !0, this._iceServers = [], this._localElement = null, this._remoteElement = null, this._jwtAuth = !0, this._audioConstraints = !0, this._previousAudioConstraints = !0, this._videoConstraints = !1, this._speaker = null, this._onlineHandler = null, this._offlineHandler = null, this._wasOffline = !1, this._videoConstraints = e.video || !1, this.iceServers = e.iceServers, this.ringtoneFile = e.ringtoneFile, this.ringbackFile = e.ringbackFile, this._setupNetworkListeners();
2194
2194
  }
2195
2195
  get reconnectDelay() {
2196
2196
  return 1e3;
@@ -2235,8 +2235,8 @@ class pi extends Jn {
2235
2235
  speedTest(e) {
2236
2236
  return new Promise(((n, i) => {
2237
2237
  if (Zt(O.SpeedTest, ((o) => {
2238
- const { upDur: d, downDur: l } = o, h = l ? 8 * e / (l / 1e3) / 1024 : 0;
2239
- n({ upDur: d, downDur: l, upKps: (d ? 8 * e / (d / 1e3) / 1024 : 0).toFixed(0), downKps: h.toFixed(0) });
2238
+ const { upDur: l, downDur: d } = o, h = d ? 8 * e / (d / 1e3) / 1024 : 0;
2239
+ n({ upDur: l, downDur: d, upKps: (l ? 8 * e / (l / 1e3) / 1024 : 0).toFixed(0), downKps: h.toFixed(0) });
2240
2240
  }), this.uuid), !(e = Number(e))) return i(`Invalid parameter 'bytes': ${e}`);
2241
2241
  this.executeRaw(`#SPU ${e}`);
2242
2242
  let s = e / 1024;
@@ -2267,8 +2267,8 @@ class pi extends Jn {
2267
2267
  return yield ((n) => L(void 0, void 0, void 0, (function* () {
2268
2268
  const i = [], s = yield je({ video: { deviceId: { exact: n } } }), r = s.getVideoTracks()[0];
2269
2269
  for (let o = 0; o < St.length; o++) {
2270
- const [d, l] = St[o];
2271
- (yield r.applyConstraints({ width: { exact: d }, height: { exact: l } }).then((() => !0)).catch((() => !1))) && i.push({ resolution: `${d}x${l}`, width: d, height: l });
2270
+ const [l, d] = St[o];
2271
+ (yield r.applyConstraints({ width: { exact: l }, height: { exact: d } }).then((() => !0)).catch((() => !1))) && i.push({ resolution: `${l}x${d}`, width: l, height: d });
2272
2272
  }
2273
2273
  return Te(s), i;
2274
2274
  })))(e);
@@ -2284,21 +2284,21 @@ class pi extends Jn {
2284
2284
  return L(this, void 0, void 0, (function* () {
2285
2285
  if (!e) throw new Error("You need to provide the settings object");
2286
2286
  const { micId: n, micLabel: i } = e, s = Ht(e, ["micId", "micLabel"]);
2287
- return zn(s), this._audioConstraints = yield ((r, o, d, l) => L(void 0, void 0, void 0, (function* () {
2288
- const { deviceId: h } = l;
2287
+ return zn(s), this._audioConstraints = yield ((r, o, l, d) => L(void 0, void 0, void 0, (function* () {
2288
+ const { deviceId: h } = d;
2289
2289
  if (h === void 0 && (r || o)) {
2290
- const f = yield Ue(r, o, d).catch(((v) => null));
2291
- f && (l.deviceId = { exact: f });
2290
+ const f = yield Ue(r, o, l).catch(((v) => null));
2291
+ f && (d.deviceId = { exact: f });
2292
2292
  }
2293
- return l;
2293
+ return d;
2294
2294
  })))(n, i, "audioinput", s), this.micId = n, this.micLabel = i, this._audioConstraints;
2295
2295
  }));
2296
2296
  }
2297
2297
  disableMicrophone() {
2298
- this._audioConstraints = !1;
2298
+ this._previousAudioConstraints = this._audioConstraints, this._audioConstraints = !1;
2299
2299
  }
2300
2300
  enableMicrophone() {
2301
- this._audioConstraints = !0;
2301
+ this._audioConstraints = this._previousAudioConstraints || !0;
2302
2302
  }
2303
2303
  set iceServers(e) {
2304
2304
  if (e && Array.isArray(e)) this._iceServers = e;
@@ -2335,20 +2335,20 @@ class pi extends Jn {
2335
2335
  }
2336
2336
  vertoSubscribe({ nodeId: e, channels: n = [], handler: i }) {
2337
2337
  return L(this, void 0, void 0, (function* () {
2338
- if (!(n = n.filter(((l) => l && !this._existsSubscription(this.relayProtocol, l)))).length) return {};
2338
+ if (!(n = n.filter(((d) => d && !this._existsSubscription(this.relayProtocol, d)))).length) return {};
2339
2339
  const s = new ni({ sessid: this.sessionid, eventChannel: n });
2340
2340
  e && (s.targetNodeId = e);
2341
- const r = yield this.execute(s), { unauthorized: o = [], subscribed: d = [] } = st(r);
2342
- return o.length && o.forEach(((l) => this._removeSubscription(this.relayProtocol, l))), d.forEach(((l) => this._addSubscription(this.relayProtocol, i, l))), r;
2341
+ const r = yield this.execute(s), { unauthorized: o = [], subscribed: l = [] } = st(r);
2342
+ return o.length && o.forEach(((d) => this._removeSubscription(this.relayProtocol, d))), l.forEach(((d) => this._addSubscription(this.relayProtocol, i, d))), r;
2343
2343
  }));
2344
2344
  }
2345
2345
  vertoUnsubscribe({ nodeId: e, channels: n = [] }) {
2346
2346
  return L(this, void 0, void 0, (function* () {
2347
- if (!(n = n.filter(((d) => d && this._existsSubscription(this.relayProtocol, d)))).length) return {};
2347
+ if (!(n = n.filter(((l) => l && this._existsSubscription(this.relayProtocol, l)))).length) return {};
2348
2348
  const i = new ii({ sessid: this.sessionid, eventChannel: n });
2349
2349
  e && (i.targetNodeId = e);
2350
2350
  const s = yield this.execute(i), { unsubscribed: r = [], notSubscribed: o = [] } = st(s);
2351
- return r.forEach(((d) => this._removeSubscription(this.relayProtocol, d))), o.forEach(((d) => this._removeSubscription(this.relayProtocol, d))), s;
2351
+ return r.forEach(((l) => this._removeSubscription(this.relayProtocol, l))), o.forEach(((l) => this._removeSubscription(this.relayProtocol, l))), s;
2352
2352
  }));
2353
2353
  }
2354
2354
  _setupNetworkListeners() {
@@ -2370,21 +2370,21 @@ class Mt {
2370
2370
  this.code = n, this.message = e;
2371
2371
  }
2372
2372
  }
2373
- class ln extends Z {
2373
+ class dn extends Z {
2374
2374
  constructor(e) {
2375
2375
  super(), this.method = "anonymous_login";
2376
- const { target_type: n, target_id: i, target_version_id: s, userVariables: r, sessionId: o, reconnection: d } = e, l = { target_type: n, target_id: i, userVariables: r, reconnection: d, "User-Agent": { sdkVersion: We, data: navigator.userAgent } };
2377
- o && (l.sessid = o), s && (l.target_version_id = s), this.buildRequest({ method: this.method, params: l });
2376
+ const { target_type: n, target_id: i, target_version_id: s, userVariables: r, sessionId: o, reconnection: l } = e, d = { target_type: n, target_id: i, userVariables: r, reconnection: l, "User-Agent": { sdkVersion: We, data: navigator.userAgent } };
2377
+ o && (d.sessid = o), s && (d.target_version_id = s), this.buildRequest({ method: this.method, params: d });
2378
2378
  }
2379
2379
  }
2380
2380
  const fi = We;
2381
2381
  class J {
2382
2382
  constructor(e) {
2383
2383
  this.session = e, this.handleLogin = () => L(this, void 0, void 0, (function* () {
2384
- const { login: n, password: i, passwd: s, login_token: r, userVariables: o } = this.session.options, d = new on(n, i || s, r, this.session.sessionid, o, !!fe()), l = yield this.session.execute(d).catch(this.session.handleLoginError);
2385
- l && (this.session.sessionid = l.sessid);
2384
+ const { login: n, password: i, passwd: s, login_token: r, userVariables: o } = this.session.options, l = new on(n, i || s, r, this.session.sessionid, o, !!fe()), d = yield this.session.execute(l).catch(this.session.handleLoginError);
2385
+ d && (this.session.sessionid = d.sessid);
2386
2386
  })), this.handleAnonymousLogin = () => L(this, void 0, void 0, (function* () {
2387
- const { anonymous_login: n } = this.session.options, i = new ln({ target_id: n.target_id, target_type: n.target_type, target_version_id: n.target_version_id, sessionId: this.session.sessionid, userVariables: this.session.options.userVariables, reconnection: !!fe() }), s = yield this.session.execute(i).catch(this.session.handleLoginError);
2387
+ const { anonymous_login: n } = this.session.options, i = new dn({ target_id: n.target_id, target_type: n.target_type, target_version_id: n.target_version_id, sessionId: this.session.sessionid, userVariables: this.session.options.userVariables, reconnection: !!fe() }), s = yield this.session.execute(i).catch(this.session.handleLoginError);
2388
2388
  s && (this.session.sessionid = s.sessid);
2389
2389
  }));
2390
2390
  }
@@ -2397,21 +2397,21 @@ class J {
2397
2397
  }
2398
2398
  handleMessage(e) {
2399
2399
  var n;
2400
- const { session: i } = this, { id: s, method: r, params: o = {}, voice_sdk_id: d } = e, l = o?.callID, h = o?.eventChannel, f = o?.eventType, v = r === F.Attach, _ = r === F.Punt;
2400
+ const { session: i } = this, { id: s, method: r, params: o = {}, voice_sdk_id: l } = e, d = o?.callID, h = o?.eventChannel, f = o?.eventType, v = r === F.Attach, _ = r === F.Punt;
2401
2401
  let w = !1;
2402
2402
  if (f === "channelPvtData") return this._handlePvtEvent(o.pvtData);
2403
- if (l && i.calls.hasOwnProperty(l)) {
2404
- if (!v) return i.calls[l].handleMessage(e), void this._ack(s, r);
2405
- w = (i.options.keepConnectionAliveOnSocketClose || i.calls[l].options.keepConnectionAliveOnSocketClose) && !!(!((n = this.session.calls[l].peer) === null || n === void 0) && n.instance), w ? y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${l}] re-attaching call due to ATTACH and keepConnectionAliveOnSocketClose`) : (y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${l}] Hanging up the call due to ATTACH`), i.calls[l].hangup({}, !1));
2403
+ if (d && i.calls.hasOwnProperty(d)) {
2404
+ if (!v) return i.calls[d].handleMessage(e), void this._ack(s, r);
2405
+ w = (i.options.keepConnectionAliveOnSocketClose || i.calls[d].options.keepConnectionAliveOnSocketClose) && !!(!((n = this.session.calls[d].peer) === null || n === void 0) && n.instance), w ? y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${d}] re-attaching call due to ATTACH and keepConnectionAliveOnSocketClose`) : (y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${d}] Hanging up the call due to ATTACH`), i.calls[d].hangup({}, !1));
2406
2406
  }
2407
- if (_ && i.options.keepConnectionAliveOnSocketClose) return y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${l}] keeping call alive due to PUNT and keepConnectionAliveOnSocketClose. Disconnecting base session...`), this.session.socketDisconnect(), void this._ack(s, r);
2407
+ if (_ && i.options.keepConnectionAliveOnSocketClose) return y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${d}] keeping call alive due to PUNT and keepConnectionAliveOnSocketClose. Disconnecting base session...`), this.session.socketDisconnect(), void this._ack(s, r);
2408
2408
  const C = () => {
2409
2409
  var S, A, E, P, D, q;
2410
- const B = { id: l, audio: !0, video: i.options.video, remoteSdp: o.sdp, destinationNumber: o.callee_id_number, remoteCallerName: o.caller_id_name, remoteCallerNumber: o.caller_id_number, callerName: o.callee_id_name, callerNumber: o.callee_id_number, attach: v, mediaSettings: o.mediaSettings, debug: (S = i.options.debug) !== null && S !== void 0 && S, debugOutput: (A = i.options.debugOutput) !== null && A !== void 0 ? A : "socket", trickleIce: (E = i.options.trickleIce) !== null && E !== void 0 && E, prefetchIceCandidates: (P = i.options.prefetchIceCandidates) !== null && P !== void 0 && P, forceRelayCandidate: (D = i.options.forceRelayCandidate) !== null && D !== void 0 && D, keepConnectionAliveOnSocketClose: (q = i.options.keepConnectionAliveOnSocketClose) !== null && q !== void 0 && q };
2410
+ const B = { id: d, audio: !0, video: i.options.video, remoteSdp: o.sdp, destinationNumber: o.callee_id_number, remoteCallerName: o.caller_id_name, remoteCallerNumber: o.caller_id_number, callerName: o.callee_id_name, callerNumber: o.callee_id_number, attach: v, mediaSettings: o.mediaSettings, debug: (S = i.options.debug) !== null && S !== void 0 && S, debugOutput: (A = i.options.debugOutput) !== null && A !== void 0 ? A : "socket", trickleIce: (E = i.options.trickleIce) !== null && E !== void 0 && E, prefetchIceCandidates: (P = i.options.prefetchIceCandidates) !== null && P !== void 0 && P, forceRelayCandidate: (D = i.options.forceRelayCandidate) !== null && D !== void 0 && D, keepConnectionAliveOnSocketClose: (q = i.options.keepConnectionAliveOnSocketClose) !== null && q !== void 0 && q };
2411
2411
  o.telnyx_call_control_id && (B.telnyxCallControlId = o.telnyx_call_control_id), o.telnyx_session_id && (B.telnyxSessionId = o.telnyx_session_id), o.telnyx_leg_id && (B.telnyxLegId = o.telnyx_leg_id), o.client_state && (B.clientState = o.client_state), o.dialogParams && o.dialogParams.custom_headers && o.dialogParams.custom_headers.length && (B.customHeaders = o.dialogParams.custom_headers);
2412
2412
  const x = new he(i, B);
2413
2413
  return x.nodeId = this.nodeId, x;
2414
- }, k = new en(d), p = new tn(d);
2414
+ }, k = new en(l), p = new tn(l);
2415
2415
  switch (r) {
2416
2416
  case F.Ping:
2417
2417
  this.session.setPingReceived(), this.session.execute(p).then((() => {
@@ -2425,12 +2425,12 @@ class J {
2425
2425
  break;
2426
2426
  case F.Invite: {
2427
2427
  const E = C();
2428
- E.playRingtone(), E.setState(N.Ringing), E.direction = de.Inbound, this._ack(s, r);
2428
+ E.playRingtone(), E.setState(N.Ringing), E.direction = le.Inbound, this._ack(s, r);
2429
2429
  break;
2430
2430
  }
2431
2431
  case F.Attach: {
2432
- if (w) return void this.session.execute(new rt({ sessid: this.session.sessionid, sdp: this.session.calls[l].peer.instance.localDescription.sdp, dialogParams: this.session.calls[l].options, "User-Agent": `Web-${fi}` }));
2433
- y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${l}] Re-creating call instance.`);
2432
+ if (w) return void this.session.execute(new rt({ sessid: this.session.sessionid, sdp: this.session.calls[d].peer.instance.localDescription.sdp, dialogParams: this.session.calls[d].options, "User-Agent": `Web-${fi}` }));
2433
+ y.info(`[${(/* @__PURE__ */ new Date()).toISOString()}][${d}] Re-creating call instance.`);
2434
2434
  const E = C();
2435
2435
  this.session.autoRecoverCalls ? E.answer() : E.setState(N.Recovering), E.handleMessage(e);
2436
2436
  break;
@@ -2506,7 +2506,7 @@ class J {
2506
2506
  }
2507
2507
  _handlePvtEvent(e) {
2508
2508
  return L(this, void 0, void 0, (function* () {
2509
- const { session: n } = this, i = n.relayProtocol, { action: s, laChannel: r, laName: o, chatChannel: d, infoChannel: l, modChannel: h, conferenceMemberID: f, role: v, callID: _ } = e;
2509
+ const { session: n } = this, i = n.relayProtocol, { action: s, laChannel: r, laName: o, chatChannel: l, infoChannel: d, modChannel: h, conferenceMemberID: f, role: v, callID: _ } = e;
2510
2510
  switch (s) {
2511
2511
  case "conference-liveArray-join": {
2512
2512
  const w = () => {
@@ -2534,7 +2534,7 @@ class J {
2534
2534
  $(O.Notification, p, k, !1) || $(O.Notification, p, n.uuid), w === null && ue(O.Notification, null, k);
2535
2535
  }
2536
2536
  }
2537
- const C = [r, d, l, h];
2537
+ const C = [r, l, d, h];
2538
2538
  n.vertoUnsubscribe({ nodeId: this.nodeId, channels: C }).then((({ unsubscribedChannels: k = [] }) => {
2539
2539
  w && (w.channels = w.channels.filter(((p) => !k.includes(p))));
2540
2540
  })).catch(((k) => {
@@ -2564,11 +2564,11 @@ class gi extends pi {
2564
2564
  constructor(e) {
2565
2565
  super(e), this.relayProtocol = "verto-protocol", this.timeoutErrorCode = -329990, this.handleLoginOnSocketOpen = () => L(this, void 0, void 0, (function* () {
2566
2566
  this._idle = !1;
2567
- const { login: n, password: i, passwd: s, login_token: r, userVariables: o, autoReconnect: d = !0 } = this.options, l = new on(n, i || s, r, this.sessionid, o, !!fe()), h = yield this.execute(l).catch(this._handleLoginError);
2568
- h && (this._autoReconnect = d, this.sessionid = h.sessid);
2567
+ const { login: n, password: i, passwd: s, login_token: r, userVariables: o, autoReconnect: l = !0 } = this.options, d = new on(n, i || s, r, this.sessionid, o, !!fe()), h = yield this.execute(d).catch(this._handleLoginError);
2568
+ h && (this._autoReconnect = l, this.sessionid = h.sessid);
2569
2569
  })), this.handleAnonymousLoginOnSocketOpen = () => L(this, void 0, void 0, (function* () {
2570
2570
  this._idle = !1;
2571
- const { anonymous_login: n } = this.options, i = new ln({ target_id: n.target_id, target_type: n.target_type, target_version_id: n.target_version_id, sessionId: this.sessionid, userVariables: this.options.userVariables, reconnection: !!fe() }), s = yield this.execute(i).catch(this._handleLoginError);
2571
+ const { anonymous_login: n } = this.options, i = new dn({ target_id: n.target_id, target_type: n.target_type, target_version_id: n.target_version_id, sessionId: this.sessionid, userVariables: this.options.userVariables, reconnection: !!fe() }), s = yield this.execute(i).catch(this._handleLoginError);
2572
2572
  s && (this.sessionid = s.sessid);
2573
2573
  })), window.addEventListener("beforeunload", ((n) => {
2574
2574
  this.calls && Object.keys(this.calls).forEach(((i) => {
@@ -2630,38 +2630,38 @@ function mi() {
2630
2630
  function i() {
2631
2631
  }
2632
2632
  Object.create && (i.prototype = /* @__PURE__ */ Object.create(null), new i().__proto__ || (n = !1));
2633
- function s(l, h, f) {
2634
- this.fn = l, this.context = h, this.once = f || !1;
2633
+ function s(d, h, f) {
2634
+ this.fn = d, this.context = h, this.once = f || !1;
2635
2635
  }
2636
- function r(l, h, f, v, _) {
2636
+ function r(d, h, f, v, _) {
2637
2637
  if (typeof f != "function")
2638
2638
  throw new TypeError("The listener must be a function");
2639
- var w = new s(f, v || l, _), C = n ? n + h : h;
2640
- return l._events[C] ? l._events[C].fn ? l._events[C] = [l._events[C], w] : l._events[C].push(w) : (l._events[C] = w, l._eventsCount++), l;
2639
+ var w = new s(f, v || d, _), C = n ? n + h : h;
2640
+ return d._events[C] ? d._events[C].fn ? d._events[C] = [d._events[C], w] : d._events[C].push(w) : (d._events[C] = w, d._eventsCount++), d;
2641
2641
  }
2642
- function o(l, h) {
2643
- --l._eventsCount === 0 ? l._events = new i() : delete l._events[h];
2642
+ function o(d, h) {
2643
+ --d._eventsCount === 0 ? d._events = new i() : delete d._events[h];
2644
2644
  }
2645
- function d() {
2645
+ function l() {
2646
2646
  this._events = new i(), this._eventsCount = 0;
2647
2647
  }
2648
- d.prototype.eventNames = function() {
2648
+ l.prototype.eventNames = function() {
2649
2649
  var h = [], f, v;
2650
2650
  if (this._eventsCount === 0) return h;
2651
2651
  for (v in f = this._events)
2652
2652
  e.call(f, v) && h.push(n ? v.slice(1) : v);
2653
2653
  return Object.getOwnPropertySymbols ? h.concat(Object.getOwnPropertySymbols(f)) : h;
2654
- }, d.prototype.listeners = function(h) {
2654
+ }, l.prototype.listeners = function(h) {
2655
2655
  var f = n ? n + h : h, v = this._events[f];
2656
2656
  if (!v) return [];
2657
2657
  if (v.fn) return [v.fn];
2658
2658
  for (var _ = 0, w = v.length, C = new Array(w); _ < w; _++)
2659
2659
  C[_] = v[_].fn;
2660
2660
  return C;
2661
- }, d.prototype.listenerCount = function(h) {
2661
+ }, l.prototype.listenerCount = function(h) {
2662
2662
  var f = n ? n + h : h, v = this._events[f];
2663
2663
  return v ? v.fn ? 1 : v.length : 0;
2664
- }, d.prototype.emit = function(h, f, v, _, w, C) {
2664
+ }, l.prototype.emit = function(h, f, v, _, w, C) {
2665
2665
  var k = n ? n + h : h;
2666
2666
  if (!this._events[k]) return !1;
2667
2667
  var p = this._events[k], S = arguments.length, A, E;
@@ -2706,11 +2706,11 @@ function mi() {
2706
2706
  }
2707
2707
  }
2708
2708
  return !0;
2709
- }, d.prototype.on = function(h, f, v) {
2709
+ }, l.prototype.on = function(h, f, v) {
2710
2710
  return r(this, h, f, v, !1);
2711
- }, d.prototype.once = function(h, f, v) {
2711
+ }, l.prototype.once = function(h, f, v) {
2712
2712
  return r(this, h, f, v, !0);
2713
- }, d.prototype.removeListener = function(h, f, v, _) {
2713
+ }, l.prototype.removeListener = function(h, f, v, _) {
2714
2714
  var w = n ? n + h : h;
2715
2715
  if (!this._events[w]) return this;
2716
2716
  if (!f)
@@ -2724,10 +2724,10 @@ function mi() {
2724
2724
  p.length ? this._events[w] = p.length === 1 ? p[0] : p : o(this, w);
2725
2725
  }
2726
2726
  return this;
2727
- }, d.prototype.removeAllListeners = function(h) {
2727
+ }, l.prototype.removeAllListeners = function(h) {
2728
2728
  var f;
2729
2729
  return h ? (f = n ? n + h : h, this._events[f] && o(this, f)) : (this._events = new i(), this._eventsCount = 0), this;
2730
- }, d.prototype.off = d.prototype.removeListener, d.prototype.addListener = d.prototype.on, d.prefixed = n, d.EventEmitter = d, t.exports = d;
2730
+ }, l.prototype.off = l.prototype.removeListener, l.prototype.addListener = l.prototype.on, l.prefixed = n, l.EventEmitter = l, t.exports = l;
2731
2731
  })(Xe)), Xe.exports;
2732
2732
  }
2733
2733
  var yi = mi();
@@ -2746,7 +2746,7 @@ function _i() {
2746
2746
  "warn",
2747
2747
  "error"
2748
2748
  ], r = {}, o = null;
2749
- function d(k, p) {
2749
+ function l(k, p) {
2750
2750
  var S = k[p];
2751
2751
  if (typeof S.bind == "function")
2752
2752
  return S.bind(k);
@@ -2758,11 +2758,11 @@ function _i() {
2758
2758
  };
2759
2759
  }
2760
2760
  }
2761
- function l() {
2761
+ function d() {
2762
2762
  console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
2763
2763
  }
2764
2764
  function h(k) {
2765
- return k === "debug" && (k = "log"), typeof console === n ? !1 : k === "trace" && i ? l : console[k] !== void 0 ? d(console, k) : console.log !== void 0 ? d(console, "log") : e;
2765
+ return k === "debug" && (k = "log"), typeof console === n ? !1 : k === "trace" && i ? d : console[k] !== void 0 ? l(console, k) : console.log !== void 0 ? l(console, "log") : e;
2766
2766
  }
2767
2767
  function f() {
2768
2768
  for (var k = this.getLevel(), p = 0; p < s.length; p++) {
@@ -2913,6 +2913,10 @@ class Ti {
2913
2913
  // Local stream (user) state tracking
2914
2914
  userIsSpeaking = !1;
2915
2915
  lastUserAudioTime = null;
2916
+ // Latency measurement tracking
2917
+ userSilenceStartTime = null;
2918
+ isFirstAgentSpeech = !0;
2919
+ monitorStartTime = null;
2916
2920
  constructor() {
2917
2921
  }
2918
2922
  updateAgentState = Ii((e) => {
@@ -2952,7 +2956,7 @@ class Ti {
2952
2956
  z.debug("Remote monitor: no stream, skipping");
2953
2957
  return;
2954
2958
  }
2955
- this.remoteAudioContext = new AudioContext(), z.debug("Remote AudioContext state:", this.remoteAudioContext.state), this.remoteAudioContext.state === "suspended" && (z.debug("Resuming suspended AudioContext..."), this.remoteAudioContext.resume().then(() => {
2959
+ this.monitorStartTime = performance.now(), this.remoteAudioContext = new AudioContext(), z.debug("Remote AudioContext state:", this.remoteAudioContext.state), this.remoteAudioContext.state === "suspended" && (z.debug("Resuming suspended AudioContext..."), this.remoteAudioContext.resume().then(() => {
2956
2960
  z.debug("AudioContext resumed, state:", this.remoteAudioContext?.state);
2957
2961
  })), this.remoteSource = this.remoteAudioContext.createMediaStreamSource(
2958
2962
  this.remoteStream
@@ -2963,11 +2967,16 @@ class Ti {
2963
2967
  let i = !1;
2964
2968
  const s = () => {
2965
2969
  this.remoteAnalyser?.getByteFrequencyData(n);
2966
- const r = n.reduce((d, l) => d + l, 0) / n.length, o = r >= Ze;
2970
+ const r = n.reduce((l, d) => l + d, 0) / n.length, o = r >= Ze;
2967
2971
  if (Math.random() < 0.01 && z.debug("Remote audio volume:", r, "threshold:", Ze, "above:", o), o)
2968
- if (!i && this.thinkingStartTime !== null) {
2969
- const d = performance.now() - this.thinkingStartTime;
2970
- this.thinkingStartTime = null, this.updateAgentState({ state: "speaking", latencyMs: d });
2972
+ if (i)
2973
+ this.updateAgentState({ state: "speaking" });
2974
+ else if (this.isFirstAgentSpeech && this.monitorStartTime !== null) {
2975
+ const l = performance.now() - this.monitorStartTime;
2976
+ this.isFirstAgentSpeech = !1, this.thinkingStartTime = null, this.userSilenceStartTime = null, this.updateAgentState({ state: "speaking", greetingLatencyMs: l });
2977
+ } else if (this.userSilenceStartTime !== null) {
2978
+ const l = performance.now() - this.userSilenceStartTime;
2979
+ this.thinkingStartTime = null, this.userSilenceStartTime = null, this.updateAgentState({ state: "speaking", userPerceivedLatencyMs: l });
2971
2980
  } else
2972
2981
  this.updateAgentState({ state: "speaking" });
2973
2982
  else
@@ -2998,7 +3007,7 @@ class Ti {
2998
3007
  else if (s && this.userIsSpeaking)
2999
3008
  this.lastUserAudioTime = performance.now();
3000
3009
  else if (!s && this.userIsSpeaking && this.lastUserAudioTime !== null && performance.now() - this.lastUserAudioTime > Ei) {
3001
- this.userIsSpeaking = !1, this.thinkingStartTime = performance.now();
3010
+ this.userIsSpeaking = !1, this.userSilenceStartTime = this.lastUserAudioTime, this.thinkingStartTime = performance.now();
3002
3011
  const o = (/* @__PURE__ */ new Date()).toISOString();
3003
3012
  this.updateAgentState({ state: "thinking", thinkingStartedAt: o });
3004
3013
  }
@@ -3172,19 +3181,19 @@ class jt extends gt {
3172
3181
  customHeaders: s,
3173
3182
  audio: r,
3174
3183
  ...o
3175
- } = e || {}, d = s ? [...s] : [];
3176
- this.versionId && d.push({
3184
+ } = e || {}, l = s ? [...s] : [];
3185
+ this.versionId && l.push({
3177
3186
  name: "X-AI-Assistant-Version-ID",
3178
3187
  value: this.versionId
3179
3188
  });
3180
- const l = this.telnyxRTC.newCall({
3189
+ const d = this.telnyxRTC.newCall({
3181
3190
  destinationNumber: "xxx",
3182
3191
  ...o,
3183
- audio: r,
3192
+ audio: r ?? !0,
3184
3193
  preferred_codecs: [i],
3185
- customHeaders: d.length > 0 ? d : void 0
3194
+ customHeaders: l.length > 0 ? l : void 0
3186
3195
  });
3187
- this.emit("conversation.update", { call: l, type: "callUpdate" });
3196
+ this.emit("conversation.update", { call: d, type: "callUpdate" });
3188
3197
  }
3189
3198
  /**
3190
3199
  * Ends the current active conversation with the AI agent.
@@ -3230,8 +3239,8 @@ function Pi() {
3230
3239
  var o = null;
3231
3240
  if (r !== void 0 && (o = "" + r), s.key !== void 0 && (o = "" + s.key), "key" in s) {
3232
3241
  r = {};
3233
- for (var d in s)
3234
- d !== "key" && (r[d] = s[d]);
3242
+ for (var l in s)
3243
+ l !== "key" && (r[l] = s[l]);
3235
3244
  } else r = s;
3236
3245
  return s = r.ref, {
3237
3246
  $$typeof: t,
@@ -3335,7 +3344,7 @@ function Di() {
3335
3344
  }
3336
3345
  return m.key !== void 0;
3337
3346
  }
3338
- function d(m, M) {
3347
+ function l(m, M) {
3339
3348
  function j() {
3340
3349
  R || (R = !0, console.error(
3341
3350
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
@@ -3347,7 +3356,7 @@ function Di() {
3347
3356
  configurable: !0
3348
3357
  });
3349
3358
  }
3350
- function l() {
3359
+ function d() {
3351
3360
  var m = t(this.type);
3352
3361
  return U[m] || (U[m] = !0, console.error(
3353
3362
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
@@ -3363,7 +3372,7 @@ function Di() {
3363
3372
  _owner: V
3364
3373
  }, (W !== void 0 ? W : null) !== null ? Object.defineProperty(m, "ref", {
3365
3374
  enumerable: !1,
3366
- get: l
3375
+ get: d
3367
3376
  }) : Object.defineProperty(m, "ref", { enumerable: !1, value: null }), m._store = {}, Object.defineProperty(m._store, "validated", {
3368
3377
  configurable: !1,
3369
3378
  enumerable: !1,
@@ -3422,7 +3431,7 @@ React keys must be passed directly to JSX without using spread:
3422
3431
  for (var ze in M)
3423
3432
  ze !== "key" && (j[ze] = M[ze]);
3424
3433
  } else j = M;
3425
- return W && d(
3434
+ return W && l(
3426
3435
  j,
3427
3436
  typeof m == "function" ? m.displayName || m.name || "Unknown" : m
3428
3437
  ), h(
@@ -3551,14 +3560,14 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3551
3560
  const i = X(t), s = i[0], r = i[6], o = i[9];
3552
3561
  if ((ce ? "production" : void 0) !== "production" && !e)
3553
3562
  throw new Error("Atom is undefined or null");
3554
- let d = s.get(e);
3555
- return d || (d = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 }, s.set(e, d), (n = r.i) == null || n.call(r, e), o?.(t, e)), d;
3563
+ let l = s.get(e);
3564
+ return l || (l = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 }, s.set(e, l), (n = r.i) == null || n.call(r, e), o?.(t, e)), l;
3556
3565
  }, Gi = (t) => {
3557
- const e = X(t), n = e[1], i = e[3], s = e[4], r = e[5], o = e[6], d = e[13], l = [], h = (f) => {
3566
+ const e = X(t), n = e[1], i = e[3], s = e[4], r = e[5], o = e[6], l = e[13], d = [], h = (f) => {
3558
3567
  try {
3559
3568
  f();
3560
3569
  } catch (v) {
3561
- l.push(v);
3570
+ d.push(v);
3562
3571
  }
3563
3572
  };
3564
3573
  do {
@@ -3567,12 +3576,12 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3567
3576
  i.forEach((_) => {
3568
3577
  var w;
3569
3578
  return (w = n.get(_)) == null ? void 0 : w.l.forEach(v);
3570
- }), i.clear(), r.forEach(v), r.clear(), s.forEach(v), s.clear(), f.forEach(h), i.size && d(t);
3579
+ }), i.clear(), r.forEach(v), r.clear(), s.forEach(v), s.clear(), f.forEach(h), i.size && l(t);
3571
3580
  } while (i.size || r.size || s.size);
3572
- if (l.length)
3573
- throw new AggregateError(l);
3581
+ if (d.length)
3582
+ throw new AggregateError(d);
3574
3583
  }, Wi = (t) => {
3575
- const e = X(t), n = e[1], i = e[2], s = e[3], r = e[11], o = e[14], d = e[17], l = [], h = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new WeakSet(), v = Array.from(s);
3584
+ const e = X(t), n = e[1], i = e[2], s = e[3], r = e[11], o = e[14], l = e[17], d = [], h = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new WeakSet(), v = Array.from(s);
3576
3585
  for (; v.length; ) {
3577
3586
  const _ = v[v.length - 1], w = r(t, _);
3578
3587
  if (f.has(_)) {
@@ -3581,7 +3590,7 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3581
3590
  }
3582
3591
  if (h.has(_)) {
3583
3592
  if (i.get(_) === w.n)
3584
- l.push([_, w]);
3593
+ d.push([_, w]);
3585
3594
  else if ((ce ? "production" : void 0) !== "production" && i.has(_))
3586
3595
  throw new Error("[Bug] invalidated atom exists");
3587
3596
  f.add(_), v.pop();
@@ -3591,19 +3600,19 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3591
3600
  for (const C of gn(_, w, n))
3592
3601
  h.has(C) || v.push(C);
3593
3602
  }
3594
- for (let _ = l.length - 1; _ >= 0; --_) {
3595
- const [w, C] = l[_];
3603
+ for (let _ = d.length - 1; _ >= 0; --_) {
3604
+ const [w, C] = d[_];
3596
3605
  let k = !1;
3597
3606
  for (const p of C.d.keys())
3598
3607
  if (p !== w && s.has(p)) {
3599
3608
  k = !0;
3600
3609
  break;
3601
3610
  }
3602
- k && (o(t, w), d(t, w)), i.delete(w);
3611
+ k && (o(t, w), l(t, w)), i.delete(w);
3603
3612
  }
3604
- }, dt = /* @__PURE__ */ new WeakSet(), Hi = (t, e) => {
3613
+ }, lt = /* @__PURE__ */ new WeakSet(), Hi = (t, e) => {
3605
3614
  var n, i;
3606
- const s = X(t), r = s[1], o = s[2], d = s[3], l = s[6], h = s[7], f = s[11], v = s[12], _ = s[13], w = s[14], C = s[16], k = s[17], p = f(t, e);
3615
+ const s = X(t), r = s[1], o = s[2], l = s[3], d = s[6], h = s[7], f = s[11], v = s[12], _ = s[13], w = s[14], C = s[16], k = s[17], p = f(t, e);
3607
3616
  if (Bt(p)) {
3608
3617
  if (r.has(e) && o.get(e) !== p.n)
3609
3618
  return p;
@@ -3656,43 +3665,43 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3656
3665
  }
3657
3666
  }, B = p.n;
3658
3667
  try {
3659
- (ce ? "production" : void 0) !== "production" && dt.delete(t);
3668
+ (ce ? "production" : void 0) !== "production" && lt.delete(t);
3660
3669
  const x = h(t, e, E, q);
3661
- return (ce ? "production" : void 0) !== "production" && dt.has(t) && console.warn(
3670
+ return (ce ? "production" : void 0) !== "production" && lt.has(t) && console.warn(
3662
3671
  "Detected store mutation during atom read. This is not supported."
3663
- ), Ge(t, e, x), Ve(x) && (ct(x, () => P?.abort()), x.then(A, A)), (n = l.r) == null || n.call(l, e), p;
3672
+ ), Ge(t, e, x), Ve(x) && (ct(x, () => P?.abort()), x.then(A, A)), (n = d.r) == null || n.call(d, e), p;
3664
3673
  } catch (x) {
3665
3674
  return delete p.v, p.e = x, ++p.n, p;
3666
3675
  } finally {
3667
- S = !1, B !== p.n && o.get(e) === B && (o.set(e, p.n), d.add(e), (i = l.c) == null || i.call(l, e));
3676
+ S = !1, B !== p.n && o.get(e) === B && (o.set(e, p.n), l.add(e), (i = d.c) == null || i.call(d, e));
3668
3677
  }
3669
3678
  }, qi = (t, e) => {
3670
3679
  const n = X(t), i = n[1], s = n[2], r = n[11], o = [e];
3671
3680
  for (; o.length; ) {
3672
- const d = o.pop(), l = r(t, d);
3673
- for (const h of gn(d, l, i)) {
3681
+ const l = o.pop(), d = r(t, l);
3682
+ for (const h of gn(l, d, i)) {
3674
3683
  const f = r(t, h);
3675
3684
  s.set(h, f.n), o.push(h);
3676
3685
  }
3677
3686
  }
3678
3687
  }, vn = (t, e, ...n) => {
3679
- const i = X(t), s = i[3], r = i[6], o = i[8], d = i[11], l = i[12], h = i[13], f = i[14], v = i[15], _ = i[17];
3688
+ const i = X(t), s = i[3], r = i[6], o = i[8], l = i[11], d = i[12], h = i[13], f = i[14], v = i[15], _ = i[17];
3680
3689
  let w = !0;
3681
3690
  const C = (p) => Fe(f(t, p)), k = (p, ...S) => {
3682
3691
  var A;
3683
- const E = d(t, p);
3692
+ const E = l(t, p);
3684
3693
  try {
3685
3694
  if (p === e) {
3686
3695
  if (!hn(p))
3687
3696
  throw new Error("atom not writable");
3688
- (ce ? "production" : void 0) !== "production" && dt.add(t);
3697
+ (ce ? "production" : void 0) !== "production" && lt.add(t);
3689
3698
  const P = E.n, D = S[0];
3690
3699
  Ge(t, p, D), _(t, p), P !== E.n && (s.add(p), v(t, p), (A = r.c) == null || A.call(r, p));
3691
3700
  return;
3692
3701
  } else
3693
3702
  return vn(t, p, ...S);
3694
3703
  } finally {
3695
- w || (h(t), l(t));
3704
+ w || (h(t), d(t));
3696
3705
  }
3697
3706
  };
3698
3707
  try {
@@ -3702,12 +3711,12 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3702
3711
  }
3703
3712
  }, Ji = (t, e) => {
3704
3713
  var n;
3705
- const i = X(t), s = i[1], r = i[3], o = i[6], d = i[11], l = i[15], h = i[18], f = i[19], v = d(t, e), _ = s.get(e);
3714
+ const i = X(t), s = i[1], r = i[3], o = i[6], l = i[11], d = i[15], h = i[18], f = i[19], v = l(t, e), _ = s.get(e);
3706
3715
  if (_ && !pn(v.v)) {
3707
3716
  for (const [w, C] of v.d)
3708
3717
  if (!_.d.has(w)) {
3709
- const k = d(t, w);
3710
- h(t, w).t.add(e), _.d.add(w), C !== k.n && (r.add(w), l(t, w), (n = o.c) == null || n.call(o, w));
3718
+ const k = l(t, w);
3719
+ h(t, w).t.add(e), _.d.add(w), C !== k.n && (r.add(w), d(t, w), (n = o.c) == null || n.call(o, w));
3711
3720
  }
3712
3721
  for (const w of _.d)
3713
3722
  if (!v.d.has(w)) {
@@ -3718,7 +3727,7 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3718
3727
  }
3719
3728
  }, mn = (t, e) => {
3720
3729
  var n;
3721
- const i = X(t), s = i[1], r = i[4], o = i[6], d = i[10], l = i[11], h = i[12], f = i[13], v = i[14], _ = i[16], w = l(t, e);
3730
+ const i = X(t), s = i[1], r = i[4], o = i[6], l = i[10], d = i[11], h = i[12], f = i[13], v = i[14], _ = i[16], w = d(t, e);
3722
3731
  let C = s.get(e);
3723
3732
  if (!C) {
3724
3733
  v(t, e);
@@ -3739,7 +3748,7 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3739
3748
  }
3740
3749
  };
3741
3750
  try {
3742
- const A = d(t, e, S);
3751
+ const A = l(t, e, S);
3743
3752
  A && (C.u = () => {
3744
3753
  p = !0;
3745
3754
  try {
@@ -3759,7 +3768,7 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3759
3768
  return C;
3760
3769
  }, Yi = (t, e) => {
3761
3770
  var n, i;
3762
- const s = X(t), r = s[1], o = s[5], d = s[6], l = s[11], h = s[19], f = l(t, e);
3771
+ const s = X(t), r = s[1], o = s[5], l = s[6], d = s[11], h = s[19], f = d(t, e);
3763
3772
  let v = r.get(e);
3764
3773
  if (!v || v.l.size)
3765
3774
  return v;
@@ -3775,18 +3784,18 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3775
3784
  const C = h(t, w);
3776
3785
  C?.t.delete(e);
3777
3786
  }
3778
- (i = d.u) == null || i.call(d, e);
3787
+ (i = l.u) == null || i.call(l, e);
3779
3788
  return;
3780
3789
  }
3781
3790
  return v;
3782
3791
  }, Ge = (t, e, n) => {
3783
3792
  const i = X(t)[11], s = i(t, e), r = "v" in s, o = s.v;
3784
3793
  if (Ve(n))
3785
- for (const d of s.d.keys())
3794
+ for (const l of s.d.keys())
3786
3795
  fn(
3787
3796
  e,
3788
3797
  n,
3789
- i(t, d)
3798
+ i(t, l)
3790
3799
  );
3791
3800
  s.v = n, delete s.e, (!r || !Object.is(o, s.v)) && (++s.n, Ve(o) && ji(o));
3792
3801
  }, zi = (t, e) => {
@@ -3800,9 +3809,9 @@ const Ui = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Fi
3800
3809
  r(t), s(t);
3801
3810
  }
3802
3811
  }, Qi = (t, e, n) => {
3803
- const i = X(t), s = i[12], r = i[18], o = i[19], l = r(t, e).l;
3804
- return l.add(n), s(t), () => {
3805
- l.delete(n), o(t, e), s(t);
3812
+ const i = X(t), s = i[12], r = i[18], o = i[19], d = r(t, e).l;
3813
+ return d.add(n), s(t), () => {
3814
+ d.delete(n), o(t, e), s(t);
3806
3815
  };
3807
3816
  }, yn = /* @__PURE__ */ new WeakMap(), X = (t) => {
3808
3817
  const e = yn.get(t);
@@ -3899,7 +3908,7 @@ const ss = {}, os = Wt(
3899
3908
  function _n(t) {
3900
3909
  return Gt(os) || is();
3901
3910
  }
3902
- const lt = (t) => typeof t?.then == "function", ut = (t) => {
3911
+ const dt = (t) => typeof t?.then == "function", ut = (t) => {
3903
3912
  t.status || (t.status = "pending", t.then(
3904
3913
  (e) => {
3905
3914
  t.status = "fulfilled", t.value = e;
@@ -3921,21 +3930,21 @@ const lt = (t) => typeof t?.then == "function", ut = (t) => {
3921
3930
  let r = t;
3922
3931
  const o = (h) => (f) => {
3923
3932
  r === h && i(f);
3924
- }, d = (h) => (f) => {
3933
+ }, l = (h) => (f) => {
3925
3934
  r === h && s(f);
3926
- }, l = () => {
3935
+ }, d = () => {
3927
3936
  try {
3928
3937
  const h = e();
3929
- lt(h) ? (et.set(h, n), r = h, h.then(o(h), d(h)), ct(h, l)) : i(h);
3938
+ dt(h) ? (et.set(h, n), r = h, h.then(o(h), l(h)), ct(h, d)) : i(h);
3930
3939
  } catch (h) {
3931
3940
  s(h);
3932
3941
  }
3933
3942
  };
3934
- t.then(o(t), d(t)), ct(t, l);
3943
+ t.then(o(t), l(t)), ct(t, d);
3935
3944
  }), et.set(t, n)), n;
3936
3945
  };
3937
3946
  function qe(t, e) {
3938
- const { delay: n, unstable_promiseStatus: i = !ht.use } = {}, s = _n(), [[r, o, d], l] = Tn(
3947
+ const { delay: n, unstable_promiseStatus: i = !ht.use } = {}, s = _n(), [[r, o, l], d] = Tn(
3939
3948
  (f) => {
3940
3949
  const v = s.get(t);
3941
3950
  return Object.is(f[0], v) && f[1] === s && f[2] === t ? f : [v, s, t];
@@ -3944,24 +3953,24 @@ function qe(t, e) {
3944
3953
  () => [s.get(t), s, t]
3945
3954
  );
3946
3955
  let h = r;
3947
- if ((o !== s || d !== t) && (l(), h = s.get(t)), pe(() => {
3956
+ if ((o !== s || l !== t) && (d(), h = s.get(t)), pe(() => {
3948
3957
  const f = s.sub(t, () => {
3949
3958
  if (i)
3950
3959
  try {
3951
3960
  const v = s.get(t);
3952
- lt(v) && ut(
3961
+ dt(v) && ut(
3953
3962
  Vt(v, () => s.get(t))
3954
3963
  );
3955
3964
  } catch {
3956
3965
  }
3957
3966
  if (typeof n == "number") {
3958
- setTimeout(l, n);
3967
+ setTimeout(d, n);
3959
3968
  return;
3960
3969
  }
3961
- l();
3970
+ d();
3962
3971
  });
3963
- return l(), f;
3964
- }, [s, t, n, i]), An(h), lt(h)) {
3972
+ return d(), f;
3973
+ }, [s, t, n, i]), An(h), dt(h)) {
3965
3974
  const f = Vt(h, () => s.get(t));
3966
3975
  return i && ut(f), rs(f);
3967
3976
  }
@@ -4004,11 +4013,11 @@ const wn = He("connecting");
4004
4013
  function ms() {
4005
4014
  return qe(wn);
4006
4015
  }
4007
- function ds() {
4016
+ function ls() {
4008
4017
  return Je(wn);
4009
4018
  }
4010
- function ls() {
4011
- const t = Ye(), e = ds();
4019
+ function ds() {
4020
+ const t = Ye(), e = ls();
4012
4021
  return pe(() => {
4013
4022
  const n = () => e("connected"), i = () => e("disconnected"), s = () => e("error");
4014
4023
  return t.addListener("agent.connected", n), t.addListener("agent.disconnected", i), t.addListener("agent.error", s), () => {
@@ -4061,16 +4070,16 @@ const In = Wt(null), _s = ({
4061
4070
  const [r, o] = xn(() => new jt({ agentId: e, environment: n, versionId: i, debug: s }));
4062
4071
  return pe(() => {
4063
4072
  if (!r) {
4064
- const d = new jt({ agentId: e, environment: n, versionId: i });
4065
- return o(d), () => {
4066
- d.disconnect();
4073
+ const l = new jt({ agentId: e, environment: n, versionId: i });
4074
+ return o(l), () => {
4075
+ l.disconnect();
4067
4076
  };
4068
4077
  }
4069
4078
  }, [e, r, n, i]), pe(() => {
4070
4079
  r?.connect();
4071
4080
  }, [r]), /* @__PURE__ */ we.jsxs(In.Provider, { value: r, children: [
4072
4081
  /* @__PURE__ */ we.jsx(cs, {}),
4073
- /* @__PURE__ */ we.jsx(ls, {}),
4082
+ /* @__PURE__ */ we.jsx(ds, {}),
4074
4083
  /* @__PURE__ */ we.jsx(hs, {}),
4075
4084
  /* @__PURE__ */ we.jsx(fs, {}),
4076
4085
  t
@@ -4086,7 +4095,7 @@ export {
4086
4095
  ms as useConnectionState,
4087
4096
  ys as useConversation,
4088
4097
  ps as useSetAgentState,
4089
- ds as useSetConnectionState,
4098
+ ls as useSetConnectionState,
4090
4099
  us as useSetConversation,
4091
4100
  as as useSetTranscript,
4092
4101
  vs as useTranscript