@telnyx/ai-agent-lib 0.2.4 → 0.2.5

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.
@@ -35,6 +35,11 @@ export declare class AudioStreamMonitor {
35
35
  setMonitoredAudioStream(stream: MediaStream): void;
36
36
  private stopRemoteMonitor;
37
37
  private stopLocalMonitor;
38
+ /**
39
+ * Reset all latency tracking state for a fresh call.
40
+ * Should be called when a call ends to prevent stale data affecting the next call.
41
+ */
42
+ private resetLatencyState;
38
43
  stopAudioStreamMonitor(): void;
39
44
  /**
40
45
  * Monitor remote stream (agent's audio) for speech detection
package/dist/index.js CHANGED
@@ -63,8 +63,8 @@ var Dn = Jt((function(t) {
63
63
  e = Pn, n = function() {
64
64
  var i = function() {
65
65
  }, s = "undefined", a = typeof window !== s && typeof window.navigator !== s && /Trident\/|MSIE /.test(window.navigator.userAgent), o = ["trace", "debug", "info", "warn", "error"];
66
- function l(p, S) {
67
- var A = p[S];
66
+ function l(p, _) {
67
+ var A = p[_];
68
68
  if (typeof A.bind == "function") return A.bind(p);
69
69
  try {
70
70
  return Function.prototype.bind.call(A, p);
@@ -77,26 +77,26 @@ var Dn = Jt((function(t) {
77
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
- function h(p, S) {
80
+ function h(p, _) {
81
81
  for (var A = 0; A < o.length; A++) {
82
82
  var E = o[A];
83
- this[E] = A < p ? i : this.methodFactory(E, p, S);
83
+ this[E] = A < p ? i : this.methodFactory(E, p, _);
84
84
  }
85
85
  this.log = this.debug;
86
86
  }
87
- function f(p, S, A) {
87
+ function f(p, _, A) {
88
88
  return function() {
89
- typeof console !== s && (h.call(this, S, A), this[p].apply(this, arguments));
89
+ typeof console !== s && (h.call(this, _, A), this[p].apply(this, arguments));
90
90
  };
91
91
  }
92
- function v(p, S, A) {
92
+ function v(p, _, A) {
93
93
  return (function(E) {
94
94
  return E === "debug" && (E = "log"), typeof console !== s && (E === "trace" && a ? 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
- function _(p, S, A) {
97
+ function S(p, _, A) {
98
98
  var E, P = this;
99
- S = S ?? "WARN";
99
+ _ = _ ?? "WARN";
100
100
  var D = "loglevel";
101
101
  function q() {
102
102
  var x;
@@ -131,9 +131,9 @@ var Dn = Jt((function(t) {
131
131
  }
132
132
  })(x), h.call(P, x, p), typeof console === s && x < P.levels.SILENT) return "No console available for logging";
133
133
  }, P.setDefaultLevel = function(x) {
134
- S = x, q() || P.setLevel(x, !1);
134
+ _ = x, q() || P.setLevel(x, !1);
135
135
  }, P.resetLevel = function() {
136
- P.setLevel(S, !1), (function() {
136
+ P.setLevel(_, !1), (function() {
137
137
  if (typeof window !== s && D) {
138
138
  try {
139
139
  return void window.localStorage.removeItem(D);
@@ -151,13 +151,13 @@ var Dn = Jt((function(t) {
151
151
  P.setLevel(P.levels.SILENT, x);
152
152
  };
153
153
  var B = q();
154
- B == null && (B = S), P.setLevel(B, !1);
154
+ B == null && (B = _), P.setLevel(B, !1);
155
155
  }
156
- var w = new _(), C = {};
156
+ var w = new S(), C = {};
157
157
  w.getLogger = function(p) {
158
158
  if (typeof p != "symbol" && typeof p != "string" || p === "") throw new TypeError("You must supply a name when creating a logger.");
159
- var S = C[p];
160
- return S || (S = C[p] = new _(p, w.getLevel(), w.methodFactory)), S;
159
+ var _ = C[p];
160
+ return _ || (_ = C[p] = new S(p, w.getLevel(), w.methodFactory)), _;
161
161
  };
162
162
  var k = typeof window !== s ? window.log : void 0;
163
163
  return w.noConflict = function() {
@@ -534,7 +534,7 @@ const tt = (t) => navigator.mediaDevices.getUserMedia(t), ge = (t) => t && t ins
534
534
  }));
535
535
  }
536
536
  return n;
537
- })), _t = [[320, 240], [640, 360], [640, 480], [1280, 720], [1920, 1080]], je = (t, e, n) => O(void 0, void 0, void 0, (function* () {
537
+ })), St = [[320, 240], [640, 360], [640, 480], [1280, 720], [1920, 1080]], je = (t, e, n) => O(void 0, void 0, void 0, (function* () {
538
538
  const i = yield ke(n, !0);
539
539
  for (let s = 0; s < i.length; s++) {
540
540
  const { deviceId: a, label: o } = i[s];
@@ -582,7 +582,7 @@ const tt = (t) => navigator.mediaDevices.getUserMedia(t), ge = (t) => t && t ins
582
582
  s.enabled = !s.enabled;
583
583
  }
584
584
  }));
585
- }, St = (t) => {
585
+ }, _t = (t) => {
586
586
  ve(t, "audio", !0);
587
587
  }, st = (t) => {
588
588
  ve(t, "audio", !1);
@@ -608,20 +608,20 @@ function Kn() {
608
608
  const { browserInfo: t, name: e, version: n, supportAudio: i, supportVideo: s } = (function() {
609
609
  if (!window || !window.navigator || !window.navigator.userAgent) throw new Error("You should use @telnyx/webrtc in a web browser such as Chrome|Firefox|Safari");
610
610
  if (navigator.userAgent.match(/chrom(e|ium)/gim) && !navigator.userAgent.match(/OPR\/[0-9]{2}/gi) && !navigator.userAgent.match(/edg/gim)) {
611
- const f = navigator.userAgent.match(/chrom(e|ium)\/[0-9]+\./gim)[0].split("/"), v = f[0], _ = parseInt(f[1], 10);
612
- return { browserInfo: navigator.userAgent, name: v, version: _, supportAudio: !0, supportVideo: !0 };
611
+ const f = navigator.userAgent.match(/chrom(e|ium)\/[0-9]+\./gim)[0].split("/"), v = f[0], S = parseInt(f[1], 10);
612
+ return { browserInfo: navigator.userAgent, name: v, version: S, supportAudio: !0, supportVideo: !0 };
613
613
  }
614
614
  if (navigator.userAgent.match(/firefox/gim) && !navigator.userAgent.match(/OPR\/[0-9]{2}/gi) && !navigator.userAgent.match(/edg/gim)) {
615
- const f = navigator.userAgent.match(/firefox\/[0-9]+\./gim)[0].split("/"), v = f[0], _ = parseInt(f[1], 10);
616
- return { browserInfo: navigator.userAgent, name: v, version: _, supportAudio: !0, supportVideo: !1 };
615
+ const f = navigator.userAgent.match(/firefox\/[0-9]+\./gim)[0].split("/"), v = f[0], S = parseInt(f[1], 10);
616
+ return { browserInfo: navigator.userAgent, name: v, version: S, supportAudio: !0, supportVideo: !1 };
617
617
  }
618
618
  if (navigator.userAgent.match(/safari/gim) && !navigator.userAgent.match(/OPR\/[0-9]{2}/gi) && !navigator.userAgent.match(/edg/gim)) {
619
- const f = navigator.userAgent.match(/safari/gim)[0], v = navigator.userAgent.match(/version\/[0-9]+\./gim)[0].split("/"), _ = parseInt(v[1], 10);
620
- return { browserInfo: navigator.userAgent, name: f, version: _, supportAudio: !0, supportVideo: !0 };
619
+ const f = navigator.userAgent.match(/safari/gim)[0], v = navigator.userAgent.match(/version\/[0-9]+\./gim)[0].split("/"), S = parseInt(v[1], 10);
620
+ return { browserInfo: navigator.userAgent, name: f, version: S, supportAudio: !0, supportVideo: !0 };
621
621
  }
622
622
  if (navigator.userAgent.match(/edg/gim) && !navigator.userAgent.match(/OPR\/[0-9]{2}/gi)) {
623
- const f = navigator.userAgent.match(/edg\/[0-9]+\./gim)[0].split("/"), v = f[0], _ = parseInt(f[1], 10);
624
- return { browserInfo: navigator.userAgent, name: v, version: _, supportAudio: !0, supportVideo: !0 };
623
+ const f = navigator.userAgent.match(/edg\/[0-9]+\./gim)[0].split("/"), v = f[0], S = parseInt(f[1], 10);
624
+ return { browserInfo: navigator.userAgent, name: v, version: S, 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
627
  })(), a = window.RTCPeerConnection, o = window.RTCSessionDescription, l = window.RTCIceCandidate, d = window.navigator && window.navigator.mediaDevices, h = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia;
@@ -885,7 +885,7 @@ var Oe, rn = Jt((function(t, e) {
885
885
  return 0 < this._eventsCount ? Reflect.ownKeys(this._events) : [];
886
886
  };
887
887
  var f, v = new Uint8Array(16);
888
- function _() {
888
+ function S() {
889
889
  if (!f && !(f = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto))) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
890
890
  return f(v);
891
891
  }
@@ -897,8 +897,8 @@ var Oe, rn = Jt((function(t, e) {
897
897
  })(u)) throw TypeError("Stringified UUID is invalid");
898
898
  return u;
899
899
  }
900
- function S(r, c, u) {
901
- var g = (r = r || {}).random || (r.rng || _)();
900
+ function _(r, c, u) {
901
+ var g = (r = r || {}).random || (r.rng || S)();
902
902
  return g[6] = 64 | 15 & g[6], g[8] = 128 | 63 & g[8], p(g);
903
903
  }
904
904
  function A(r, c) {
@@ -1047,7 +1047,7 @@ var Oe, rn = Jt((function(t, e) {
1047
1047
  const T = c.getConfiguration();
1048
1048
  return T.iceServers && T.iceServers.forEach((function(I) {
1049
1049
  delete I.credential;
1050
- })), g || (g = S()), this.emitEvent({ event: "addConnection", tag: "peer", peerId: u, connectionId: g, data: { options: r, peerConfiguration: T } }), this.monitorPeer({ peerId: u, connectionId: g, pc: c, remote: b }), { connectionId: g };
1050
+ })), g || (g = _()), this.emitEvent({ event: "addConnection", tag: "peer", peerId: u, connectionId: g, data: { options: r, peerConfiguration: T } }), this.monitorPeer({ peerId: u, connectionId: g, pc: c, remote: b }), { connectionId: g };
1051
1051
  }
1052
1052
  getTimeline(r) {
1053
1053
  return this.timeline = this.timeline.sort(((c, u) => c.timestamp.getTime() - u.timestamp.getTime())), r ? this.timeline.filter(((c) => c.tag === r)) : this.timeline;
@@ -1308,11 +1308,11 @@ var Oe, rn = Jt((function(t, e) {
1308
1308
  var si = rn.WebRTCStats;
1309
1309
  function oi(t) {
1310
1310
  const { packetsLost: e, packetsReceived: n, jitter: i, rtt: s } = t, a = (function(h) {
1311
- const { jitter: f, rtt: v } = h, _ = f + v / 2;
1312
- return 0.024 * _ + 0.11 * (_ - 177.3) * (_ > 177.3 ? 1 : 0);
1311
+ const { jitter: f, rtt: v } = h, S = f + v / 2;
1312
+ return 0.024 * S + 0.11 * (S - 177.3) * (S > 177.3 ? 1 : 0);
1313
1313
  })({ rtt: s, jitter: i }), o = (function(h) {
1314
- const { packetsLost: f, packetsReceived: v } = h, _ = f / (v + f) * 100;
1315
- return 20 * Math.log(1 + _);
1314
+ const { packetsLost: f, packetsReceived: v } = h, S = f / (v + f) * 100;
1315
+ return 20 * Math.log(1 + S);
1316
1316
  })({ packetsLost: e, packetsReceived: n }), l = 93.2 - a - o + 0, d = 1 + 0.035 * l + 7e-6 * l * (l - 60) * (100 - l);
1317
1317
  return Math.min(Math.max(d, 1), 5);
1318
1318
  }
@@ -1341,9 +1341,9 @@ function Rt(t, e) {
1341
1341
  function di(t, e) {
1342
1342
  const n = me(), i = new si({ getStatsInterval: 1e3, rawStats: !1, statsObject: !0, filteredStats: !1, remote: !0, debug: !1, logLevel: "warn" }), s = (a) => O(this, void 0, void 0, (function* () {
1343
1343
  a.event === "stats" && F(L.StatsFrame, (function({ data: o }) {
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 = oi({ jitter: 1e3 * A, rtt: 1e3 * E, packetsLost: D, packetsReceived: P });
1346
- return { jitter: A, rtt: E, mos: q, quality: ri(q), inboundAudio: k.inbound[0], outboundAudio: k.outbound[0], remoteInboundAudio: S.inbound[0], remoteOutboundAudio: S.outbound[0] };
1344
+ var l, d, h, f, v, S, w, C;
1345
+ const { audio: k, remote: p } = o, { audio: _ } = p, A = (d = (l = _.inbound[0]) === null || l === void 0 ? void 0 : l.jitter) !== null && d !== void 0 ? d : 1 / 0, E = (f = (h = _.inbound[0]) === null || h === void 0 ? void 0 : h.roundTripTime) !== null && f !== void 0 ? f : 1 / 0, P = (S = (v = k.inbound[0]) === null || v === void 0 ? void 0 : v.packetsReceived) !== null && S !== void 0 ? S : -1, D = (C = (w = k.inbound[0]) === null || w === void 0 ? void 0 : w.packetsLost) !== null && C !== void 0 ? C : -1, q = oi({ jitter: 1e3 * A, rtt: 1e3 * E, packetsLost: D, packetsReceived: P });
1346
+ return { jitter: A, rtt: E, mos: q, quality: ri(q), inboundAudio: k.inbound[0], outboundAudio: k.outbound[0], remoteInboundAudio: _.inbound[0], remoteOutboundAudio: _.outbound[0] };
1347
1347
  })(a), t.uuid), yield t.execute(new li(n, a));
1348
1348
  }));
1349
1349
  return { start: (a, o, l) => O(this, void 0, void 0, (function* () {
@@ -1391,23 +1391,23 @@ class xt {
1391
1391
  if (this.isDebugEnabled && this.statsReporter) {
1392
1392
  const h = yield (function(f, v) {
1393
1393
  return O(this, void 0, void 0, (function* () {
1394
- const _ = { connectionState: f.connectionState, previousConnectionState: v, iceConnectionState: f.iceConnectionState, iceGatheringState: f.iceGatheringState, signalingState: f.signalingState }, w = f.getTransceivers();
1394
+ const S = { connectionState: f.connectionState, previousConnectionState: v, iceConnectionState: f.iceConnectionState, iceGatheringState: f.iceGatheringState, signalingState: f.signalingState }, w = f.getTransceivers();
1395
1395
  if (w.length > 0) {
1396
1396
  const C = w[0].sender, k = C?.transport;
1397
- k && (_.dtlsState = k.state);
1397
+ k && (S.dtlsState = k.state);
1398
1398
  }
1399
- f.sctp && (_.sctpState = f.sctp.state);
1399
+ f.sctp && (S.sctpState = f.sctp.state);
1400
1400
  try {
1401
1401
  const C = yield f.getStats();
1402
1402
  C.forEach(((k) => {
1403
- k.type === "candidate-pair" && k.state === "succeeded" && (_.candidatePairState = k.state, C.forEach(((p) => {
1404
- p.type === "local-candidate" && p.id === k.localCandidateId && (_.localCandidateType = p.candidateType, _.selectedCandidatePair = _.selectedCandidatePair || { local: {}, remote: {} }, _.selectedCandidatePair.local = { address: p.address, port: p.port, protocol: p.protocol, candidateType: p.candidateType }), p.type === "remote-candidate" && p.id === k.remoteCandidateId && (_.remoteCandidateType = p.candidateType, _.selectedCandidatePair = _.selectedCandidatePair || { local: {}, remote: {} }, _.selectedCandidatePair.remote = { address: p.address, port: p.port, protocol: p.protocol, candidateType: p.candidateType });
1405
- }))), k.type === "transport" && (_.dtlsCipher = k.dtlsCipher, _.srtpCipher = k.srtpCipher, _.tlsVersion = k.tlsVersion, k.dtlsState && (_.dtlsState = k.dtlsState));
1403
+ k.type === "candidate-pair" && k.state === "succeeded" && (S.candidatePairState = k.state, C.forEach(((p) => {
1404
+ p.type === "local-candidate" && p.id === k.localCandidateId && (S.localCandidateType = p.candidateType, S.selectedCandidatePair = S.selectedCandidatePair || { local: {}, remote: {} }, S.selectedCandidatePair.local = { address: p.address, port: p.port, protocol: p.protocol, candidateType: p.candidateType }), p.type === "remote-candidate" && p.id === k.remoteCandidateId && (S.remoteCandidateType = p.candidateType, S.selectedCandidatePair = S.selectedCandidatePair || { local: {}, remote: {} }, S.selectedCandidatePair.remote = { address: p.address, port: p.port, protocol: p.protocol, candidateType: p.candidateType });
1405
+ }))), k.type === "transport" && (S.dtlsCipher = k.dtlsCipher, S.srtpCipher = k.srtpCipher, S.tlsVersion = k.tlsVersion, k.dtlsState && (S.dtlsState = k.dtlsState));
1406
1406
  }));
1407
1407
  } catch (C) {
1408
1408
  y.error("Error gathering connection state details:", C);
1409
1409
  }
1410
- return _;
1410
+ return S;
1411
1411
  }));
1412
1412
  })(this.instance, this._prevConnectionState);
1413
1413
  this.statsReporter.reportConnectionStateChange(h);
@@ -1504,9 +1504,9 @@ class xt {
1504
1504
  }
1505
1505
  const { audioCodecs: l, videoCodecs: d } = ((h) => {
1506
1506
  const f = [], v = [];
1507
- return h && h.length !== 0 ? (h.forEach(((_) => {
1508
- const w = _.mimeType.toLocaleLowerCase();
1509
- w.startsWith("audio/") ? f.push(_) : w.startsWith("video/") && v.push(_);
1507
+ return h && h.length !== 0 ? (h.forEach(((S) => {
1508
+ const w = S.mimeType.toLocaleLowerCase();
1509
+ w.startsWith("audio/") ? f.push(S) : w.startsWith("video/") && v.push(S);
1510
1510
  })), { audioCodecs: f, videoCodecs: v }) : { audioCodecs: f, videoCodecs: v };
1511
1511
  })(this.options.preferred_codecs);
1512
1512
  if (this.isOffer && typeof this.instance.addTransceiver == "function") {
@@ -1636,24 +1636,24 @@ const Lt = We;
1636
1636
  class cn {
1637
1637
  constructor(e, n) {
1638
1638
  this.session = e, this.id = "", this.state = N[N.New], this.prevState = "", this.channels = [], this.role = et.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
- const S = p < 0 || !this._lastSerno || this._lastSerno && p === this._lastSerno + 1;
1640
- return S && p >= 0 && (this._lastSerno = p), S;
1639
+ const _ = p < 0 || !this._lastSerno || this._lastSerno && p === this._lastSerno + 1;
1640
+ return _ && p >= 0 && (this._lastSerno = p), _;
1641
1641
  }, this._doStats = () => {
1642
1642
  this.peer && this.peer.instance && this._statsBindings.length !== 0 && this.peer.instance.getStats().then(((p) => {
1643
- p.forEach(((S) => {
1643
+ p.forEach(((_) => {
1644
1644
  this._statsBindings.forEach(((A) => {
1645
1645
  if (A.callback) {
1646
1646
  if (A.constraints) {
1647
- for (var E in A.constraints) if (A.constraints.hasOwnProperty(E) && A.constraints[E] !== S[E]) return;
1647
+ for (var E in A.constraints) if (A.constraints.hasOwnProperty(E) && A.constraints[E] !== _[E]) return;
1648
1648
  }
1649
- A.callback(S);
1649
+ A.callback(_);
1650
1650
  }
1651
1651
  }));
1652
1652
  }));
1653
1653
  }));
1654
1654
  };
1655
- const { iceServers: i, speaker: s, micId: a, 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: a, 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 = Ct(this.options.ringtoneFile, "_ringtone"), this._ringback = Ct(this.options.ringbackFile, "_ringback"));
1655
+ const { iceServers: i, speaker: s, micId: a, micLabel: o, camId: l, camLabel: d, localElement: h, remoteElement: f, options: v, mediaConstraints: { audio: S, video: w }, ringtoneFile: C, ringbackFile: k } = e;
1656
+ this.options = Object.assign({}, Fn, { audio: S, video: w, iceServers: n?.iceServers && Array.isArray(n.iceServers) ? n.iceServers : i, localElement: h, remoteElement: f, micId: a, 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 = Ct(this.options.ringtoneFile, "_ringtone"), this._ringback = Ct(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"), a = (o) => `${o.toFixed(2)}ms`;
@@ -1745,7 +1745,7 @@ class cn {
1745
1745
  st(this.options.localStream);
1746
1746
  }
1747
1747
  unmuteAudio() {
1748
- St(this.options.localStream);
1748
+ _t(this.options.localStream);
1749
1749
  }
1750
1750
  toggleAudioMute() {
1751
1751
  wt(this.options.localStream);
@@ -1788,7 +1788,7 @@ class cn {
1788
1788
  st(this.options.remoteStream);
1789
1789
  }
1790
1790
  undeaf() {
1791
- St(this.options.remoteStream);
1791
+ _t(this.options.remoteStream);
1792
1792
  }
1793
1793
  toggleDeaf() {
1794
1794
  wt(this.options.remoteStream);
@@ -1876,8 +1876,8 @@ class cn {
1876
1876
  switch (i) {
1877
1877
  case "bootObj": {
1878
1878
  this._lastSerno = 0;
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));
1879
+ const { chatChannel: l, infoChannel: d, modChannel: h, laName: f, conferenceMemberID: v, role: S } = n;
1880
+ this._dispatchConferenceUpdate({ action: se.Join, conferenceName: f, participantId: Number(v), role: S }), 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) }, Le(s[C][1])));
1883
1883
  this._dispatchConferenceUpdate({ action: se.Bootstrap, participants: w });
@@ -2266,8 +2266,8 @@ class hi extends qn {
2266
2266
  try {
2267
2267
  return yield ((n) => O(void 0, void 0, void 0, (function* () {
2268
2268
  const i = [], s = yield Ue({ video: { deviceId: { exact: n } } }), a = s.getVideoTracks()[0];
2269
- for (let o = 0; o < _t.length; o++) {
2270
- const [l, d] = _t[o];
2269
+ for (let o = 0; o < St.length; o++) {
2270
+ const [l, d] = St[o];
2271
2271
  (yield a.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;
@@ -2397,17 +2397,17 @@ class J {
2397
2397
  }
2398
2398
  handleMessage(e) {
2399
2399
  var n;
2400
- const { session: i } = this, { id: s, method: a, params: o = {}, voice_sdk_id: l } = e, d = o?.callID, h = o?.eventChannel, f = o?.eventType, v = a === $.Attach, _ = a === $.Punt;
2400
+ const { session: i } = this, { id: s, method: a, params: o = {}, voice_sdk_id: l } = e, d = o?.callID, h = o?.eventChannel, f = o?.eventType, v = a === $.Attach, S = a === $.Punt;
2401
2401
  let w = !1;
2402
2402
  if (f === "channelPvtData") return this._handlePvtEvent(o.pvtData);
2403
2403
  if (d && i.calls.hasOwnProperty(d)) {
2404
2404
  if (!v) return i.calls[d].handleMessage(e), void this._ack(s, a);
2405
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()}][${d}] keeping call alive due to PUNT and keepConnectionAliveOnSocketClose. Disconnecting base session...`), this.session.socketDisconnect(), void this._ack(s, a);
2407
+ if (S && 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, a);
2408
2408
  const C = () => {
2409
- var S, A, E, P, D, 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 };
2409
+ var _, A, E, P, D, 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: (_ = i.options.debug) !== null && _ !== void 0 && _, 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;
@@ -2438,8 +2438,8 @@ class J {
2438
2438
  case $.Event:
2439
2439
  case "webrtc.event":
2440
2440
  if (!h) return void y.error("Verto received an unknown event:", o);
2441
- const S = i.relayProtocol, A = h.split(".")[0];
2442
- i._existsSubscription(S, h) ? F(S, o, h) : h === i.sessionid ? this._handleSessionEvent(o.eventData) : i._existsSubscription(S, A) ? F(S, o, A) : i.calls.hasOwnProperty(h) ? i.calls[h].handleMessage(e) : F(L.Notification, o, i.uuid);
2441
+ const _ = i.relayProtocol, A = h.split(".")[0];
2442
+ i._existsSubscription(_, h) ? F(_, o, h) : h === i.sessionid ? this._handleSessionEvent(o.eventData) : i._existsSubscription(_, A) ? F(_, o, A) : i.calls.hasOwnProperty(h) ? i.calls[h].handleMessage(e) : F(L.Notification, o, i.uuid);
2443
2443
  break;
2444
2444
  case $.Info:
2445
2445
  o.type = oe.generic, F(L.Notification, o, i.uuid);
@@ -2506,15 +2506,15 @@ class J {
2506
2506
  }
2507
2507
  _handlePvtEvent(e) {
2508
2508
  return O(this, void 0, void 0, (function* () {
2509
- const { session: n } = this, i = n.relayProtocol, { action: s, laChannel: a, laName: o, chatChannel: l, infoChannel: d, modChannel: h, conferenceMemberID: f, role: v, callID: _ } = e;
2509
+ const { session: n } = this, i = n.relayProtocol, { action: s, laChannel: a, laName: o, chatChannel: l, infoChannel: d, modChannel: h, conferenceMemberID: f, role: v, callID: S } = e;
2510
2510
  switch (s) {
2511
2511
  case "conference-liveArray-join": {
2512
2512
  const w = () => {
2513
2513
  n.vertoBroadcast({ nodeId: this.nodeId, channel: a, data: { liveArray: { command: "bootstrap", context: a, name: o } } });
2514
2514
  }, C = { nodeId: this.nodeId, channels: [a], handler: ({ data: p }) => {
2515
- const S = _ || this._retrieveCallId(p, a);
2516
- if (S && n.calls.hasOwnProperty(S)) {
2517
- const A = n.calls[S];
2515
+ const _ = S || this._retrieveCallId(p, a);
2516
+ if (_ && n.calls.hasOwnProperty(_)) {
2517
+ const A = n.calls[_];
2518
2518
  A._addChannel(a), A.extension = o, A.handleConferenceUpdate(p, e).then(((E) => {
2519
2519
  E === "INVALID_PACKET" && w();
2520
2520
  }));
@@ -2633,10 +2633,10 @@ function vi() {
2633
2633
  function s(d, h, f) {
2634
2634
  this.fn = d, this.context = h, this.once = f || !1;
2635
2635
  }
2636
- function a(d, h, f, v, _) {
2636
+ function a(d, h, f, v, S) {
2637
2637
  if (typeof f != "function")
2638
2638
  throw new TypeError("The listener must be a function");
2639
- var w = new s(f, v || d, _), C = n ? n + h : h;
2639
+ var w = new s(f, v || d, S), C = n ? n + h : h;
2640
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
2642
  function o(d, h) {
@@ -2655,18 +2655,18 @@ function vi() {
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
- for (var _ = 0, w = v.length, C = new Array(w); _ < w; _++)
2659
- C[_] = v[_].fn;
2658
+ for (var S = 0, w = v.length, C = new Array(w); S < w; S++)
2659
+ C[S] = v[S].fn;
2660
2660
  return C;
2661
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
- }, l.prototype.emit = function(h, f, v, _, w, C) {
2664
+ }, l.prototype.emit = function(h, f, v, S, w, C) {
2665
2665
  var k = n ? n + h : h;
2666
2666
  if (!this._events[k]) return !1;
2667
- var p = this._events[k], S = arguments.length, A, E;
2667
+ var p = this._events[k], _ = arguments.length, A, E;
2668
2668
  if (p.fn) {
2669
- switch (p.once && this.removeListener(h, p.fn, void 0, !0), S) {
2669
+ switch (p.once && this.removeListener(h, p.fn, void 0, !0), _) {
2670
2670
  case 1:
2671
2671
  return p.fn.call(p.context), !0;
2672
2672
  case 2:
@@ -2674,19 +2674,19 @@ function vi() {
2674
2674
  case 3:
2675
2675
  return p.fn.call(p.context, f, v), !0;
2676
2676
  case 4:
2677
- return p.fn.call(p.context, f, v, _), !0;
2677
+ return p.fn.call(p.context, f, v, S), !0;
2678
2678
  case 5:
2679
- return p.fn.call(p.context, f, v, _, w), !0;
2679
+ return p.fn.call(p.context, f, v, S, w), !0;
2680
2680
  case 6:
2681
- return p.fn.call(p.context, f, v, _, w, C), !0;
2681
+ return p.fn.call(p.context, f, v, S, w, C), !0;
2682
2682
  }
2683
- for (E = 1, A = new Array(S - 1); E < S; E++)
2683
+ for (E = 1, A = new Array(_ - 1); E < _; E++)
2684
2684
  A[E - 1] = arguments[E];
2685
2685
  p.fn.apply(p.context, A);
2686
2686
  } else {
2687
2687
  var P = p.length, D;
2688
2688
  for (E = 0; E < P; E++)
2689
- switch (p[E].once && this.removeListener(h, p[E].fn, void 0, !0), S) {
2689
+ switch (p[E].once && this.removeListener(h, p[E].fn, void 0, !0), _) {
2690
2690
  case 1:
2691
2691
  p[E].fn.call(p[E].context);
2692
2692
  break;
@@ -2697,10 +2697,10 @@ function vi() {
2697
2697
  p[E].fn.call(p[E].context, f, v);
2698
2698
  break;
2699
2699
  case 4:
2700
- p[E].fn.call(p[E].context, f, v, _);
2700
+ p[E].fn.call(p[E].context, f, v, S);
2701
2701
  break;
2702
2702
  default:
2703
- if (!A) for (D = 1, A = new Array(S - 1); D < S; D++)
2703
+ if (!A) for (D = 1, A = new Array(_ - 1); D < _; D++)
2704
2704
  A[D - 1] = arguments[D];
2705
2705
  p[E].fn.apply(p[E].context, A);
2706
2706
  }
@@ -2710,17 +2710,17 @@ function vi() {
2710
2710
  return a(this, h, f, v, !1);
2711
2711
  }, l.prototype.once = function(h, f, v) {
2712
2712
  return a(this, h, f, v, !0);
2713
- }, l.prototype.removeListener = function(h, f, v, _) {
2713
+ }, l.prototype.removeListener = function(h, f, v, S) {
2714
2714
  var w = n ? n + h : h;
2715
2715
  if (!this._events[w]) return this;
2716
2716
  if (!f)
2717
2717
  return o(this, w), this;
2718
2718
  var C = this._events[w];
2719
2719
  if (C.fn)
2720
- C.fn === f && (!_ || C.once) && (!v || C.context === v) && o(this, w);
2720
+ C.fn === f && (!S || C.once) && (!v || C.context === v) && o(this, w);
2721
2721
  else {
2722
- for (var k = 0, p = [], S = C.length; k < S; k++)
2723
- (C[k].fn !== f || _ && !C[k].once || v && C[k].context !== v) && p.push(C[k]);
2722
+ for (var k = 0, p = [], _ = C.length; k < _; k++)
2723
+ (C[k].fn !== f || S && !C[k].once || v && C[k].context !== v) && p.push(C[k]);
2724
2724
  p.length ? this._events[w] = p.length === 1 ? p[0] : p : o(this, w);
2725
2725
  }
2726
2726
  return this;
@@ -2747,14 +2747,14 @@ function bi() {
2747
2747
  "error"
2748
2748
  ], a = {}, o = null;
2749
2749
  function l(k, p) {
2750
- var S = k[p];
2751
- if (typeof S.bind == "function")
2752
- return S.bind(k);
2750
+ var _ = k[p];
2751
+ if (typeof _.bind == "function")
2752
+ return _.bind(k);
2753
2753
  try {
2754
- return Function.prototype.bind.call(S, k);
2754
+ return Function.prototype.bind.call(_, k);
2755
2755
  } catch {
2756
2756
  return function() {
2757
- return Function.prototype.apply.apply(S, [k, arguments]);
2757
+ return Function.prototype.apply.apply(_, [k, arguments]);
2758
2758
  };
2759
2759
  }
2760
2760
  }
@@ -2766,8 +2766,8 @@ function bi() {
2766
2766
  }
2767
2767
  function f() {
2768
2768
  for (var k = this.getLevel(), p = 0; p < s.length; p++) {
2769
- var S = s[p];
2770
- this[S] = p < k ? e : this.methodFactory(S, k, this.name);
2769
+ var _ = s[p];
2770
+ this[_] = p < k ? e : this.methodFactory(_, k, this.name);
2771
2771
  }
2772
2772
  if (this.log = this.debug, typeof console === n && k < this.levels.SILENT)
2773
2773
  return "No console available for logging";
@@ -2777,11 +2777,11 @@ function bi() {
2777
2777
  typeof console !== n && (f.call(this), this[k].apply(this, arguments));
2778
2778
  };
2779
2779
  }
2780
- function _(k, p, S) {
2780
+ function S(k, p, _) {
2781
2781
  return h(k) || v.apply(this, arguments);
2782
2782
  }
2783
2783
  function w(k, p) {
2784
- var S = this, A, E, P, D = "loglevel";
2784
+ var _ = this, A, E, P, D = "loglevel";
2785
2785
  typeof k == "string" ? D += ":" + k : typeof k == "symbol" && (D = void 0);
2786
2786
  function q(u) {
2787
2787
  var g = (s[u] || "silent").toUpperCase();
@@ -2812,7 +2812,7 @@ function bi() {
2812
2812
  )[1]);
2813
2813
  } catch {
2814
2814
  }
2815
- return S.levels[u] === void 0 && (u = void 0), u;
2815
+ return _.levels[u] === void 0 && (u = void 0), u;
2816
2816
  }
2817
2817
  }
2818
2818
  function x() {
@@ -2829,47 +2829,47 @@ function bi() {
2829
2829
  }
2830
2830
  function r(u) {
2831
2831
  var g = u;
2832
- if (typeof g == "string" && S.levels[g.toUpperCase()] !== void 0 && (g = S.levels[g.toUpperCase()]), typeof g == "number" && g >= 0 && g <= S.levels.SILENT)
2832
+ if (typeof g == "string" && _.levels[g.toUpperCase()] !== void 0 && (g = _.levels[g.toUpperCase()]), typeof g == "number" && g >= 0 && g <= _.levels.SILENT)
2833
2833
  return g;
2834
2834
  throw new TypeError("log.setLevel() called with invalid level: " + u);
2835
2835
  }
2836
- S.name = k, S.levels = {
2836
+ _.name = k, _.levels = {
2837
2837
  TRACE: 0,
2838
2838
  DEBUG: 1,
2839
2839
  INFO: 2,
2840
2840
  WARN: 3,
2841
2841
  ERROR: 4,
2842
2842
  SILENT: 5
2843
- }, S.methodFactory = p || _, S.getLevel = function() {
2843
+ }, _.methodFactory = p || S, _.getLevel = function() {
2844
2844
  return P ?? E ?? A;
2845
- }, S.setLevel = function(u, g) {
2846
- return P = r(u), g !== !1 && q(P), f.call(S);
2847
- }, S.setDefaultLevel = function(u) {
2848
- E = r(u), B() || S.setLevel(u, !1);
2849
- }, S.resetLevel = function() {
2850
- P = null, x(), f.call(S);
2851
- }, S.enableAll = function(u) {
2852
- S.setLevel(S.levels.TRACE, u);
2853
- }, S.disableAll = function(u) {
2854
- S.setLevel(S.levels.SILENT, u);
2855
- }, S.rebuild = function() {
2856
- if (o !== S && (A = r(o.getLevel())), f.call(S), o === S)
2845
+ }, _.setLevel = function(u, g) {
2846
+ return P = r(u), g !== !1 && q(P), f.call(_);
2847
+ }, _.setDefaultLevel = function(u) {
2848
+ E = r(u), B() || _.setLevel(u, !1);
2849
+ }, _.resetLevel = function() {
2850
+ P = null, x(), f.call(_);
2851
+ }, _.enableAll = function(u) {
2852
+ _.setLevel(_.levels.TRACE, u);
2853
+ }, _.disableAll = function(u) {
2854
+ _.setLevel(_.levels.SILENT, u);
2855
+ }, _.rebuild = function() {
2856
+ if (o !== _ && (A = r(o.getLevel())), f.call(_), o === _)
2857
2857
  for (var u in a)
2858
2858
  a[u].rebuild();
2859
2859
  }, A = r(
2860
2860
  o ? o.getLevel() : "WARN"
2861
2861
  );
2862
2862
  var c = B();
2863
- c != null && (P = r(c)), f.call(S);
2863
+ c != null && (P = r(c)), f.call(_);
2864
2864
  }
2865
2865
  o = new w(), o.getLogger = function(p) {
2866
2866
  if (typeof p != "symbol" && typeof p != "string" || p === "")
2867
2867
  throw new TypeError("You must supply a name when creating a logger.");
2868
- var S = a[p];
2869
- return S || (S = a[p] = new w(
2868
+ var _ = a[p];
2869
+ return _ || (_ = a[p] = new w(
2870
2870
  p,
2871
2871
  o.methodFactory
2872
- )), S;
2872
+ )), _;
2873
2873
  };
2874
2874
  var C = typeof window !== n ? window.log : void 0;
2875
2875
  return o.noConflict = function() {
@@ -2880,8 +2880,8 @@ function bi() {
2880
2880
  });
2881
2881
  })(Pe)), Pe.exports;
2882
2882
  }
2883
- var _i = bi();
2884
- const Si = /* @__PURE__ */ dn(_i), wi = () => (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace("Z", ""), z = Si.getLogger("telnyx-ai-agent"), Ci = z.methodFactory;
2883
+ var Si = bi();
2884
+ const _i = /* @__PURE__ */ dn(Si), wi = () => (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").replace("Z", ""), z = _i.getLogger("telnyx-ai-agent"), Ci = z.methodFactory;
2885
2885
  z.methodFactory = (t, e, n) => {
2886
2886
  const i = Ci(t, e, n);
2887
2887
  return function(...s) {
@@ -2951,8 +2951,15 @@ class Ai {
2951
2951
  stopLocalMonitor() {
2952
2952
  this.localIntervalId && (clearInterval(this.localIntervalId), this.localIntervalId = null), this.localSource?.disconnect(), this.localAudioContext?.close(), this.localAudioContext = null, this.localSource = null, this.localAnalyser = null;
2953
2953
  }
2954
+ /**
2955
+ * Reset all latency tracking state for a fresh call.
2956
+ * Should be called when a call ends to prevent stale data affecting the next call.
2957
+ */
2958
+ resetLatencyState() {
2959
+ this.thinkingStartTime = null, this.lastState = null, this.userIsSpeaking = !1, this.lastUserAudioTime = null, this.userSpeechStartTime = null, this.userSilenceStartTime = null, this.isFirstAgentSpeech = !0, this.monitorStartTime = null;
2960
+ }
2954
2961
  stopAudioStreamMonitor() {
2955
- this.stopRemoteMonitor(), this.stopLocalMonitor();
2962
+ this.stopRemoteMonitor(), this.stopLocalMonitor(), this.resetLatencyState();
2956
2963
  }
2957
2964
  /**
2958
2965
  * Monitor remote stream (agent's audio) for speech detection
@@ -3232,10 +3239,10 @@ class Nt extends ft {
3232
3239
  this.emit("conversation.agent.state", e);
3233
3240
  };
3234
3241
  }
3235
- var Me = { exports: {} }, _e = {};
3242
+ var Me = { exports: {} }, Se = {};
3236
3243
  var Ut;
3237
3244
  function Di() {
3238
- if (Ut) return _e;
3245
+ if (Ut) return Se;
3239
3246
  Ut = 1;
3240
3247
  var t = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
3241
3248
  function n(i, s, a) {
@@ -3253,9 +3260,9 @@ function Di() {
3253
3260
  props: a
3254
3261
  };
3255
3262
  }
3256
- return _e.Fragment = e, _e.jsx = n, _e.jsxs = n, _e;
3263
+ return Se.Fragment = e, Se.jsx = n, Se.jsxs = n, Se;
3257
3264
  }
3258
- var Se = {};
3265
+ var _e = {};
3259
3266
  var jt;
3260
3267
  function Ni() {
3261
3268
  return jt || (jt = 1, process.env.NODE_ENV !== "production" && (function() {
@@ -3269,7 +3276,7 @@ function Ni() {
3269
3276
  return "Fragment";
3270
3277
  case A:
3271
3278
  return "Profiler";
3272
- case S:
3279
+ case _:
3273
3280
  return "StrictMode";
3274
3281
  case q:
3275
3282
  return "Suspense";
@@ -3447,12 +3454,12 @@ React keys must be passed directly to JSX without using spread:
3447
3454
  );
3448
3455
  }
3449
3456
  function v(m) {
3450
- _(m) ? m._store && (m._store.validated = 1) : typeof m == "object" && m !== null && m.$$typeof === r && (m._payload.status === "fulfilled" ? _(m._payload.value) && m._payload.value._store && (m._payload.value._store.validated = 1) : m._store && (m._store.validated = 1));
3457
+ S(m) ? m._store && (m._store.validated = 1) : typeof m == "object" && m !== null && m.$$typeof === r && (m._payload.status === "fulfilled" ? S(m._payload.value) && m._payload.value._store && (m._payload.value._store.validated = 1) : m._store && (m._store.validated = 1));
3451
3458
  }
3452
- function _(m) {
3459
+ function S(m) {
3453
3460
  return typeof m == "object" && m !== null && m.$$typeof === C;
3454
3461
  }
3455
- var w = ut, C = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), S = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), E = Symbol.for("react.consumer"), P = Symbol.for("react.context"), D = Symbol.for("react.forward_ref"), q = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), r = Symbol.for("react.lazy"), c = Symbol.for("react.activity"), u = Symbol.for("react.client.reference"), g = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, b = Object.prototype.hasOwnProperty, T = Array.isArray, I = console.createTask ? console.createTask : function() {
3462
+ var w = ut, C = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), E = Symbol.for("react.consumer"), P = Symbol.for("react.context"), D = Symbol.for("react.forward_ref"), q = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), r = Symbol.for("react.lazy"), c = Symbol.for("react.activity"), u = Symbol.for("react.client.reference"), g = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, b = Object.prototype.hasOwnProperty, T = Array.isArray, I = console.createTask ? console.createTask : function() {
3456
3463
  return null;
3457
3464
  };
3458
3465
  w = {
@@ -3464,7 +3471,7 @@ React keys must be passed directly to JSX without using spread:
3464
3471
  w,
3465
3472
  a
3466
3473
  )(), ne = I(i(a)), G = {};
3467
- Se.Fragment = p, Se.jsx = function(m, M, U) {
3474
+ _e.Fragment = p, _e.jsx = function(m, M, U) {
3468
3475
  var V = 1e4 > g.recentlyCreatedOwnerStacks++;
3469
3476
  return f(
3470
3477
  m,
@@ -3474,7 +3481,7 @@ React keys must be passed directly to JSX without using spread:
3474
3481
  V ? Error("react-stack-top-frame") : ee,
3475
3482
  V ? I(i(m)) : ne
3476
3483
  );
3477
- }, Se.jsxs = function(m, M, U) {
3484
+ }, _e.jsxs = function(m, M, U) {
3478
3485
  var V = 1e4 > g.recentlyCreatedOwnerStacks++;
3479
3486
  return f(
3480
3487
  m,
@@ -3485,7 +3492,7 @@ React keys must be passed directly to JSX without using spread:
3485
3492
  V ? I(i(m)) : ne
3486
3493
  );
3487
3494
  };
3488
- })()), Se;
3495
+ })()), _e;
3489
3496
  }
3490
3497
  var Ft;
3491
3498
  function Ui() {
@@ -3576,9 +3583,9 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3576
3583
  do {
3577
3584
  o.f && h(o.f);
3578
3585
  const f = /* @__PURE__ */ new Set(), v = f.add.bind(f);
3579
- i.forEach((_) => {
3586
+ i.forEach((S) => {
3580
3587
  var w;
3581
- return (w = n.get(_)) == null ? void 0 : w.l.forEach(v);
3588
+ return (w = n.get(S)) == null ? void 0 : w.l.forEach(v);
3582
3589
  }), i.clear(), a.forEach(v), a.clear(), s.forEach(v), s.clear(), f.forEach(h), i.size && l(t);
3583
3590
  } while (i.size || a.size || s.size);
3584
3591
  if (d.length)
@@ -3586,25 +3593,25 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3586
3593
  }, Hi = (t) => {
3587
3594
  const e = X(t), n = e[1], i = e[2], s = e[3], a = e[11], o = e[14], l = e[17], d = [], h = /* @__PURE__ */ new WeakSet(), f = /* @__PURE__ */ new WeakSet(), v = Array.from(s);
3588
3595
  for (; v.length; ) {
3589
- const _ = v[v.length - 1], w = a(t, _);
3590
- if (f.has(_)) {
3596
+ const S = v[v.length - 1], w = a(t, S);
3597
+ if (f.has(S)) {
3591
3598
  v.pop();
3592
3599
  continue;
3593
3600
  }
3594
- if (h.has(_)) {
3595
- if (i.get(_) === w.n)
3596
- d.push([_, w]);
3597
- else if ((ce ? "production" : void 0) !== "production" && i.has(_))
3601
+ if (h.has(S)) {
3602
+ if (i.get(S) === w.n)
3603
+ d.push([S, w]);
3604
+ else if ((ce ? "production" : void 0) !== "production" && i.has(S))
3598
3605
  throw new Error("[Bug] invalidated atom exists");
3599
- f.add(_), v.pop();
3606
+ f.add(S), v.pop();
3600
3607
  continue;
3601
3608
  }
3602
- h.add(_);
3603
- for (const C of fn(_, w, n))
3609
+ h.add(S);
3610
+ for (const C of fn(S, w, n))
3604
3611
  h.has(C) || v.push(C);
3605
3612
  }
3606
- for (let _ = d.length - 1; _ >= 0; --_) {
3607
- const [w, C] = d[_];
3613
+ for (let S = d.length - 1; S >= 0; --S) {
3614
+ const [w, C] = d[S];
3608
3615
  let k = !1;
3609
3616
  for (const p of C.d.keys())
3610
3617
  if (p !== w && s.has(p)) {
@@ -3615,7 +3622,7 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3615
3622
  }
3616
3623
  }, ct = /* @__PURE__ */ new WeakSet(), qi = (t, e) => {
3617
3624
  var n, i;
3618
- const s = X(t), a = 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);
3625
+ const s = X(t), a = s[1], o = s[2], l = s[3], d = s[6], h = s[7], f = s[11], v = s[12], S = s[13], w = s[14], C = s[16], k = s[17], p = f(t, e);
3619
3626
  if ($t(p)) {
3620
3627
  if (a.has(e) && o.get(e) !== p.n)
3621
3628
  return p;
@@ -3629,9 +3636,9 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3629
3636
  return p;
3630
3637
  }
3631
3638
  p.d.clear();
3632
- let S = !0;
3639
+ let _ = !0;
3633
3640
  function A() {
3634
- a.has(e) && (k(t, e), _(t), v(t));
3641
+ a.has(e) && (k(t, e), S(t), v(t));
3635
3642
  }
3636
3643
  function E(x) {
3637
3644
  var r;
@@ -3648,7 +3655,7 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3648
3655
  try {
3649
3656
  return $e(c);
3650
3657
  } finally {
3651
- p.d.set(x, c.n), hn(p.v) && pn(e, p.v, c), a.has(e) && ((r = a.get(x)) == null || r.t.add(e)), S || A();
3658
+ p.d.set(x, c.n), hn(p.v) && pn(e, p.v, c), a.has(e) && ((r = a.get(x)) == null || r.t.add(e)), _ || A();
3652
3659
  }
3653
3660
  }
3654
3661
  let P, D;
@@ -3658,11 +3665,11 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3658
3665
  },
3659
3666
  get setSelf() {
3660
3667
  return (ce ? "production" : void 0) !== "production" && !rt(e) && console.warn("setSelf function cannot be used with read-only atom"), !D && rt(e) && (D = (...x) => {
3661
- if ((ce ? "production" : void 0) !== "production" && S && console.warn("setSelf function cannot be called in sync"), !S)
3668
+ if ((ce ? "production" : void 0) !== "production" && _ && console.warn("setSelf function cannot be called in sync"), !_)
3662
3669
  try {
3663
3670
  return C(t, e, ...x);
3664
3671
  } finally {
3665
- _(t), v(t);
3672
+ S(t), v(t);
3666
3673
  }
3667
3674
  }), D;
3668
3675
  }
@@ -3676,7 +3683,7 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3676
3683
  } catch (x) {
3677
3684
  return delete p.v, p.e = x, ++p.n, p;
3678
3685
  } finally {
3679
- 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));
3686
+ _ = !1, B !== p.n && o.get(e) === B && (o.set(e, p.n), l.add(e), (i = d.c) == null || i.call(d, e));
3680
3687
  }
3681
3688
  }, Ji = (t, e) => {
3682
3689
  const n = X(t), i = n[1], s = n[2], a = n[11], o = [e];
@@ -3688,9 +3695,9 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3688
3695
  }
3689
3696
  }
3690
3697
  }, gn = (t, e, ...n) => {
3691
- const i = X(t), s = i[3], a = i[6], o = i[8], l = i[11], d = i[12], h = i[13], f = i[14], v = i[15], _ = i[17];
3698
+ const i = X(t), s = i[3], a = i[6], o = i[8], l = i[11], d = i[12], h = i[13], f = i[14], v = i[15], S = i[17];
3692
3699
  let w = !0;
3693
- const C = (p) => $e(f(t, p)), k = (p, ...S) => {
3700
+ const C = (p) => $e(f(t, p)), k = (p, ..._) => {
3694
3701
  var A;
3695
3702
  const E = l(t, p);
3696
3703
  try {
@@ -3698,11 +3705,11 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3698
3705
  if (!un(p))
3699
3706
  throw new Error("atom not writable");
3700
3707
  (ce ? "production" : void 0) !== "production" && ct.add(t);
3701
- const P = E.n, D = S[0];
3702
- Ge(t, p, D), _(t, p), P !== E.n && (s.add(p), v(t, p), (A = a.c) == null || A.call(a, p));
3708
+ const P = E.n, D = _[0];
3709
+ Ge(t, p, D), S(t, p), P !== E.n && (s.add(p), v(t, p), (A = a.c) == null || A.call(a, p));
3703
3710
  return;
3704
3711
  } else
3705
- return gn(t, p, ...S);
3712
+ return gn(t, p, ..._);
3706
3713
  } finally {
3707
3714
  w || (h(t), d(t));
3708
3715
  }
@@ -3714,23 +3721,23 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3714
3721
  }
3715
3722
  }, Yi = (t, e) => {
3716
3723
  var n;
3717
- const i = X(t), s = i[1], a = i[3], o = i[6], l = i[11], d = i[15], h = i[18], f = i[19], v = l(t, e), _ = s.get(e);
3718
- if (_ && !hn(v.v)) {
3724
+ const i = X(t), s = i[1], a = i[3], o = i[6], l = i[11], d = i[15], h = i[18], f = i[19], v = l(t, e), S = s.get(e);
3725
+ if (S && !hn(v.v)) {
3719
3726
  for (const [w, C] of v.d)
3720
- if (!_.d.has(w)) {
3727
+ if (!S.d.has(w)) {
3721
3728
  const k = l(t, w);
3722
- h(t, w).t.add(e), _.d.add(w), C !== k.n && (a.add(w), d(t, w), (n = o.c) == null || n.call(o, w));
3729
+ h(t, w).t.add(e), S.d.add(w), C !== k.n && (a.add(w), d(t, w), (n = o.c) == null || n.call(o, w));
3723
3730
  }
3724
- for (const w of _.d)
3731
+ for (const w of S.d)
3725
3732
  if (!v.d.has(w)) {
3726
- _.d.delete(w);
3733
+ S.d.delete(w);
3727
3734
  const C = f(t, w);
3728
3735
  C?.t.delete(e);
3729
3736
  }
3730
3737
  }
3731
3738
  }, vn = (t, e) => {
3732
3739
  var n;
3733
- const i = X(t), s = i[1], a = 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);
3740
+ const i = X(t), s = i[1], a = i[4], o = i[6], l = i[10], d = i[11], h = i[12], f = i[13], v = i[14], S = i[16], w = d(t, e);
3734
3741
  let C = s.get(e);
3735
3742
  if (!C) {
3736
3743
  v(t, e);
@@ -3743,15 +3750,15 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3743
3750
  }, s.set(e, C), rt(e)) {
3744
3751
  const k = () => {
3745
3752
  let p = !0;
3746
- const S = (...A) => {
3753
+ const _ = (...A) => {
3747
3754
  try {
3748
- return _(t, e, ...A);
3755
+ return S(t, e, ...A);
3749
3756
  } finally {
3750
3757
  p || (f(t), h(t));
3751
3758
  }
3752
3759
  };
3753
3760
  try {
3754
- const A = l(t, e, S);
3761
+ const A = l(t, e, _);
3755
3762
  A && (C.u = () => {
3756
3763
  p = !0;
3757
3764
  try {
@@ -3775,13 +3782,13 @@ const Fi = (t, e, ...n) => e.read(...n), $i = (t, e, ...n) => e.write(...n), Bi
3775
3782
  let v = a.get(e);
3776
3783
  if (!v || v.l.size)
3777
3784
  return v;
3778
- let _ = !1;
3785
+ let S = !1;
3779
3786
  for (const w of v.t)
3780
3787
  if ((n = a.get(w)) != null && n.d.has(e)) {
3781
- _ = !0;
3788
+ S = !0;
3782
3789
  break;
3783
3790
  }
3784
- if (!_) {
3791
+ if (!S) {
3785
3792
  v.u && o.add(v.u), v = void 0, a.delete(e);
3786
3793
  for (const w of f.d.keys()) {
3787
3794
  const C = h(t, w);
@@ -3990,12 +3997,12 @@ function Je(t, e) {
3990
3997
  [n, t]
3991
3998
  );
3992
3999
  }
3993
- const _n = He([]);
4000
+ const Sn = He([]);
3994
4001
  function ms() {
3995
- return qe(_n);
4002
+ return qe(Sn);
3996
4003
  }
3997
4004
  function cs() {
3998
- return Je(_n);
4005
+ return Je(Sn);
3999
4006
  }
4000
4007
  const Ye = () => {
4001
4008
  const t = Vt(kn);
@@ -4012,12 +4019,12 @@ function ls() {
4012
4019
  };
4013
4020
  }, [t, e]), null;
4014
4021
  }
4015
- const Sn = He("connecting");
4022
+ const _n = He("connecting");
4016
4023
  function ys() {
4017
- return qe(Sn);
4024
+ return qe(_n);
4018
4025
  }
4019
4026
  function ds() {
4020
- return Je(Sn);
4027
+ return Je(_n);
4021
4028
  }
4022
4029
  function us() {
4023
4030
  const t = Ye(), e = ds();
@@ -4046,7 +4053,7 @@ const ps = () => {
4046
4053
  };
4047
4054
  }, [t, e]), null;
4048
4055
  }, Cn = He({ state: "listening" });
4049
- function _s() {
4056
+ function Ss() {
4050
4057
  return qe(Cn);
4051
4058
  }
4052
4059
  function fs() {
@@ -4063,7 +4070,7 @@ function gs() {
4063
4070
  };
4064
4071
  }, [t, e]), null;
4065
4072
  }
4066
- const kn = Gt(null), Ss = ({
4073
+ const kn = Gt(null), _s = ({
4067
4074
  children: t,
4068
4075
  agentId: e,
4069
4076
  environment: n,
@@ -4093,8 +4100,8 @@ export {
4093
4100
  kn as ClientContext,
4094
4101
  L as SwEvent,
4095
4102
  Nt as TelnyxAIAgent,
4096
- Ss as TelnyxAIAgentProvider,
4097
- _s as useAgentState,
4103
+ _s as TelnyxAIAgentProvider,
4104
+ Ss as useAgentState,
4098
4105
  Ye as useClient,
4099
4106
  ys as useConnectionState,
4100
4107
  bs as useConversation,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@telnyx/ai-agent-lib",
3
3
  "private": false,
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",