translation-chat-sdk 0.1.3 → 0.1.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.
@@ -1,18 +1,18 @@
1
- import { jsx as d, jsxs as y, Fragment as Pe } from "react/jsx-runtime";
2
- import { createContext as De, useRef as G, useState as Z, useMemo as U, useEffect as me, useContext as Ie } from "react";
3
- const C = /* @__PURE__ */ Object.create(null);
4
- C.open = "0";
5
- C.close = "1";
6
- C.ping = "2";
7
- C.pong = "3";
8
- C.message = "4";
9
- C.upgrade = "5";
10
- C.noop = "6";
11
- const M = /* @__PURE__ */ Object.create(null);
12
- Object.keys(C).forEach((n) => {
13
- M[C[n]] = n;
1
+ import { jsx as d, jsxs as k, Fragment as Pe } from "react/jsx-runtime";
2
+ import { createContext as De, useRef as W, useState as Z, useMemo as M, useEffect as me, useContext as Ie, forwardRef as qe, useImperativeHandle as Ue } from "react";
3
+ const x = /* @__PURE__ */ Object.create(null);
4
+ x.open = "0";
5
+ x.close = "1";
6
+ x.ping = "2";
7
+ x.pong = "3";
8
+ x.message = "4";
9
+ x.upgrade = "5";
10
+ x.noop = "6";
11
+ const V = /* @__PURE__ */ Object.create(null);
12
+ Object.keys(x).forEach((n) => {
13
+ V[x[n]] = n;
14
14
  });
15
- const ee = { type: "error", data: "parser error" }, _e = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", ye = typeof ArrayBuffer == "function", we = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n && n.buffer instanceof ArrayBuffer, oe = ({ type: n, data: e }, t, s) => _e && e instanceof Blob ? t ? s(e) : fe(e, s) : ye && (e instanceof ArrayBuffer || we(e)) ? t ? s(e) : fe(new Blob([e]), s) : s(C[n] + (e || "")), fe = (n, e) => {
15
+ const ee = { type: "error", data: "parser error" }, _e = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", ye = typeof ArrayBuffer == "function", we = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n && n.buffer instanceof ArrayBuffer, oe = ({ type: n, data: e }, t, s) => _e && e instanceof Blob ? t ? s(e) : fe(e, s) : ye && (e instanceof ArrayBuffer || we(e)) ? t ? s(e) : fe(new Blob([e]), s) : s(x[n] + (e || "")), fe = (n, e) => {
16
16
  const t = new FileReader();
17
17
  return t.onload = function() {
18
18
  const s = t.result.split(",")[1];
@@ -22,27 +22,27 @@ const ee = { type: "error", data: "parser error" }, _e = typeof Blob == "functio
22
22
  function de(n) {
23
23
  return n instanceof Uint8Array ? n : n instanceof ArrayBuffer ? new Uint8Array(n) : new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
24
24
  }
25
- let J;
26
- function qe(n, e) {
25
+ let Q;
26
+ function Me(n, e) {
27
27
  if (_e && n.data instanceof Blob)
28
28
  return n.data.arrayBuffer().then(de).then(e);
29
29
  if (ye && (n.data instanceof ArrayBuffer || we(n.data)))
30
30
  return e(de(n.data));
31
31
  oe(n, !1, (t) => {
32
- J || (J = new TextEncoder()), e(J.encode(t));
32
+ Q || (Q = new TextEncoder()), e(Q.encode(t));
33
33
  });
34
34
  }
35
- const pe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", D = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
35
+ const pe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", I = typeof Uint8Array > "u" ? [] : new Uint8Array(256);
36
36
  for (let n = 0; n < pe.length; n++)
37
- D[pe.charCodeAt(n)] = n;
38
- const Ue = (n) => {
37
+ I[pe.charCodeAt(n)] = n;
38
+ const Ve = (n) => {
39
39
  let e = n.length * 0.75, t = n.length, s, i = 0, r, o, a, l;
40
40
  n[n.length - 1] === "=" && (e--, n[n.length - 2] === "=" && e--);
41
- const h = new ArrayBuffer(e), p = new Uint8Array(h);
41
+ const h = new ArrayBuffer(e), f = new Uint8Array(h);
42
42
  for (s = 0; s < t; s += 4)
43
- r = D[n.charCodeAt(s)], o = D[n.charCodeAt(s + 1)], a = D[n.charCodeAt(s + 2)], l = D[n.charCodeAt(s + 3)], p[i++] = r << 2 | o >> 4, p[i++] = (o & 15) << 4 | a >> 2, p[i++] = (a & 3) << 6 | l & 63;
43
+ r = I[n.charCodeAt(s)], o = I[n.charCodeAt(s + 1)], a = I[n.charCodeAt(s + 2)], l = I[n.charCodeAt(s + 3)], f[i++] = r << 2 | o >> 4, f[i++] = (o & 15) << 4 | a >> 2, f[i++] = (a & 3) << 6 | l & 63;
44
44
  return h;
45
- }, Me = typeof ArrayBuffer == "function", ce = (n, e) => {
45
+ }, Fe = typeof ArrayBuffer == "function", ce = (n, e) => {
46
46
  if (typeof n != "string")
47
47
  return {
48
48
  type: "message",
@@ -51,16 +51,16 @@ const Ue = (n) => {
51
51
  const t = n.charAt(0);
52
52
  return t === "b" ? {
53
53
  type: "message",
54
- data: Ve(n.substring(1), e)
55
- } : M[t] ? n.length > 1 ? {
56
- type: M[t],
54
+ data: He(n.substring(1), e)
55
+ } : V[t] ? n.length > 1 ? {
56
+ type: V[t],
57
57
  data: n.substring(1)
58
58
  } : {
59
- type: M[t]
59
+ type: V[t]
60
60
  } : ee;
61
- }, Ve = (n, e) => {
62
- if (Me) {
63
- const t = Ue(n);
61
+ }, He = (n, e) => {
62
+ if (Fe) {
63
+ const t = Ve(n);
64
64
  return ke(t, e);
65
65
  } else
66
66
  return { base64: !0, data: n };
@@ -72,7 +72,7 @@ const Ue = (n) => {
72
72
  default:
73
73
  return n instanceof ArrayBuffer ? n : n.buffer;
74
74
  }
75
- }, be = "", Fe = (n, e) => {
75
+ }, be = "", Ke = (n, e) => {
76
76
  const t = n.length, s = new Array(t);
77
77
  let i = 0;
78
78
  n.forEach((r, o) => {
@@ -80,7 +80,7 @@ const Ue = (n) => {
80
80
  s[o] = a, ++i === t && e(s.join(be));
81
81
  });
82
82
  });
83
- }, He = (n, e) => {
83
+ }, We = (n, e) => {
84
84
  const t = n.split(be), s = [];
85
85
  for (let i = 0; i < t.length; i++) {
86
86
  const r = ce(t[i], e);
@@ -89,10 +89,10 @@ const Ue = (n) => {
89
89
  }
90
90
  return s;
91
91
  };
92
- function Ke() {
92
+ function $e() {
93
93
  return new TransformStream({
94
94
  transform(n, e) {
95
- qe(n, (t) => {
95
+ Me(n, (t) => {
96
96
  const s = t.length;
97
97
  let i;
98
98
  if (s < 126)
@@ -111,11 +111,11 @@ function Ke() {
111
111
  }
112
112
  });
113
113
  }
114
- let Q;
115
- function I(n) {
114
+ let X;
115
+ function q(n) {
116
116
  return n.reduce((e, t) => e + t.length, 0);
117
117
  }
118
- function q(n, e) {
118
+ function U(n, e) {
119
119
  if (n[0].length === e)
120
120
  return n.shift();
121
121
  const t = new Uint8Array(e);
@@ -124,37 +124,37 @@ function q(n, e) {
124
124
  t[i] = n[0][s++], s === n[0].length && (n.shift(), s = 0);
125
125
  return n.length && s < n[0].length && (n[0] = n[0].slice(s)), t;
126
126
  }
127
- function $e(n, e) {
128
- Q || (Q = new TextDecoder());
127
+ function Ye(n, e) {
128
+ X || (X = new TextDecoder());
129
129
  const t = [];
130
130
  let s = 0, i = -1, r = !1;
131
131
  return new TransformStream({
132
132
  transform(o, a) {
133
133
  for (t.push(o); ; ) {
134
134
  if (s === 0) {
135
- if (I(t) < 1)
135
+ if (q(t) < 1)
136
136
  break;
137
- const l = q(t, 1);
137
+ const l = U(t, 1);
138
138
  r = (l[0] & 128) === 128, i = l[0] & 127, i < 126 ? s = 3 : i === 126 ? s = 1 : s = 2;
139
139
  } else if (s === 1) {
140
- if (I(t) < 2)
140
+ if (q(t) < 2)
141
141
  break;
142
- const l = q(t, 2);
142
+ const l = U(t, 2);
143
143
  i = new DataView(l.buffer, l.byteOffset, l.length).getUint16(0), s = 3;
144
144
  } else if (s === 2) {
145
- if (I(t) < 8)
145
+ if (q(t) < 8)
146
146
  break;
147
- const l = q(t, 8), h = new DataView(l.buffer, l.byteOffset, l.length), p = h.getUint32(0);
148
- if (p > Math.pow(2, 21) - 1) {
147
+ const l = U(t, 8), h = new DataView(l.buffer, l.byteOffset, l.length), f = h.getUint32(0);
148
+ if (f > Math.pow(2, 21) - 1) {
149
149
  a.enqueue(ee);
150
150
  break;
151
151
  }
152
- i = p * Math.pow(2, 32) + h.getUint32(4), s = 3;
152
+ i = f * Math.pow(2, 32) + h.getUint32(4), s = 3;
153
153
  } else {
154
- if (I(t) < i)
154
+ if (q(t) < i)
155
155
  break;
156
- const l = q(t, i);
157
- a.enqueue(ce(r ? l : Q.decode(l), e)), s = 0;
156
+ const l = U(t, i);
157
+ a.enqueue(ce(r ? l : X.decode(l), e)), s = 0;
158
158
  }
159
159
  if (i === 0 || i > n) {
160
160
  a.enqueue(ee);
@@ -165,24 +165,24 @@ function $e(n, e) {
165
165
  });
166
166
  }
167
167
  const ve = 4;
168
- function m(n) {
169
- if (n) return We(n);
168
+ function w(n) {
169
+ if (n) return ze(n);
170
170
  }
171
- function We(n) {
172
- for (var e in m.prototype)
173
- n[e] = m.prototype[e];
171
+ function ze(n) {
172
+ for (var e in w.prototype)
173
+ n[e] = w.prototype[e];
174
174
  return n;
175
175
  }
176
- m.prototype.on = m.prototype.addEventListener = function(n, e) {
176
+ w.prototype.on = w.prototype.addEventListener = function(n, e) {
177
177
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
178
178
  };
179
- m.prototype.once = function(n, e) {
179
+ w.prototype.once = function(n, e) {
180
180
  function t() {
181
181
  this.off(n, t), e.apply(this, arguments);
182
182
  }
183
183
  return t.fn = e, this.on(n, t), this;
184
184
  };
185
- m.prototype.off = m.prototype.removeListener = m.prototype.removeAllListeners = m.prototype.removeEventListener = function(n, e) {
185
+ w.prototype.off = w.prototype.removeListener = w.prototype.removeAllListeners = w.prototype.removeEventListener = function(n, e) {
186
186
  if (this._callbacks = this._callbacks || {}, arguments.length == 0)
187
187
  return this._callbacks = {}, this;
188
188
  var t = this._callbacks["$" + n];
@@ -196,7 +196,7 @@ m.prototype.off = m.prototype.removeListener = m.prototype.removeAllListeners =
196
196
  }
197
197
  return t.length === 0 && delete this._callbacks["$" + n], this;
198
198
  };
199
- m.prototype.emit = function(n) {
199
+ w.prototype.emit = function(n) {
200
200
  this._callbacks = this._callbacks || {};
201
201
  for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + n], s = 1; s < arguments.length; s++)
202
202
  e[s - 1] = arguments[s];
@@ -207,26 +207,26 @@ m.prototype.emit = function(n) {
207
207
  }
208
208
  return this;
209
209
  };
210
- m.prototype.emitReserved = m.prototype.emit;
211
- m.prototype.listeners = function(n) {
210
+ w.prototype.emitReserved = w.prototype.emit;
211
+ w.prototype.listeners = function(n) {
212
212
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
213
213
  };
214
- m.prototype.hasListeners = function(n) {
214
+ w.prototype.hasListeners = function(n) {
215
215
  return !!this.listeners(n).length;
216
216
  };
217
- const $ = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), v = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ye = "arraybuffer";
217
+ const Y = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), E = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Je = "arraybuffer";
218
218
  function Ee(n, ...e) {
219
219
  return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
220
220
  }
221
- const ze = v.setTimeout, Je = v.clearTimeout;
222
- function W(n, e) {
223
- e.useNativeTimers ? (n.setTimeoutFn = ze.bind(v), n.clearTimeoutFn = Je.bind(v)) : (n.setTimeoutFn = v.setTimeout.bind(v), n.clearTimeoutFn = v.clearTimeout.bind(v));
221
+ const Qe = E.setTimeout, Xe = E.clearTimeout;
222
+ function z(n, e) {
223
+ e.useNativeTimers ? (n.setTimeoutFn = Qe.bind(E), n.clearTimeoutFn = Xe.bind(E)) : (n.setTimeoutFn = E.setTimeout.bind(E), n.clearTimeoutFn = E.clearTimeout.bind(E));
224
224
  }
225
- const Qe = 1.33;
226
- function Xe(n) {
227
- return typeof n == "string" ? je(n) : Math.ceil((n.byteLength || n.size) * Qe);
225
+ const je = 1.33;
226
+ function Ge(n) {
227
+ return typeof n == "string" ? Ze(n) : Math.ceil((n.byteLength || n.size) * je);
228
228
  }
229
- function je(n) {
229
+ function Ze(n) {
230
230
  let e = 0, t = 0;
231
231
  for (let s = 0, i = n.length; s < i; s++)
232
232
  e = n.charCodeAt(s), e < 128 ? t += 1 : e < 2048 ? t += 2 : e < 55296 || e >= 57344 ? t += 3 : (s++, t += 4);
@@ -235,13 +235,13 @@ function je(n) {
235
235
  function Te() {
236
236
  return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
237
237
  }
238
- function Ge(n) {
238
+ function et(n) {
239
239
  let e = "";
240
240
  for (let t in n)
241
241
  n.hasOwnProperty(t) && (e.length && (e += "&"), e += encodeURIComponent(t) + "=" + encodeURIComponent(n[t]));
242
242
  return e;
243
243
  }
244
- function Ze(n) {
244
+ function tt(n) {
245
245
  let e = {}, t = n.split("&");
246
246
  for (let s = 0, i = t.length; s < i; s++) {
247
247
  let r = t[s].split("=");
@@ -249,12 +249,12 @@ function Ze(n) {
249
249
  }
250
250
  return e;
251
251
  }
252
- class et extends Error {
252
+ class st extends Error {
253
253
  constructor(e, t, s) {
254
254
  super(e), this.description = t, this.context = s, this.type = "TransportError";
255
255
  }
256
256
  }
257
- class ae extends m {
257
+ class ae extends w {
258
258
  /**
259
259
  * Transport abstract constructor.
260
260
  *
@@ -262,7 +262,7 @@ class ae extends m {
262
262
  * @protected
263
263
  */
264
264
  constructor(e) {
265
- super(), this.writable = !1, W(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
265
+ super(), this.writable = !1, z(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
266
266
  }
267
267
  /**
268
268
  * Emits an error.
@@ -274,7 +274,7 @@ class ae extends m {
274
274
  * @protected
275
275
  */
276
276
  onError(e, t, s) {
277
- return super.emitReserved("error", new et(e, t, s)), this;
277
+ return super.emitReserved("error", new st(e, t, s)), this;
278
278
  }
279
279
  /**
280
280
  * Opens the transport.
@@ -348,11 +348,11 @@ class ae extends m {
348
348
  return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
349
349
  }
350
350
  _query(e) {
351
- const t = Ge(e);
351
+ const t = et(e);
352
352
  return t.length ? "?" + t : "";
353
353
  }
354
354
  }
355
- class tt extends ae {
355
+ class nt extends ae {
356
356
  constructor() {
357
357
  super(...arguments), this._polling = !1;
358
358
  }
@@ -408,7 +408,7 @@ class tt extends ae {
408
408
  return this.onClose({ description: "transport closed by the server" }), !1;
409
409
  this.onPacket(s);
410
410
  };
411
- He(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
411
+ We(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
412
412
  }
413
413
  /**
414
414
  * For polling, send a close packet.
@@ -428,7 +428,7 @@ class tt extends ae {
428
428
  * @protected
429
429
  */
430
430
  write(e) {
431
- this.writable = !1, Fe(e, (t) => {
431
+ this.writable = !1, Ke(e, (t) => {
432
432
  this.doWrite(t, () => {
433
433
  this.writable = !0, this.emitReserved("drain");
434
434
  });
@@ -449,10 +449,10 @@ try {
449
449
  Ce = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
450
450
  } catch {
451
451
  }
452
- const st = Ce;
453
- function nt() {
452
+ const it = Ce;
453
+ function rt() {
454
454
  }
455
- class it extends tt {
455
+ class ot extends nt {
456
456
  /**
457
457
  * XHR Polling constructor.
458
458
  *
@@ -494,7 +494,7 @@ class it extends tt {
494
494
  }), this.pollXhr = e;
495
495
  }
496
496
  }
497
- class T extends m {
497
+ class C extends w {
498
498
  /**
499
499
  * Request constructor
500
500
  *
@@ -502,7 +502,7 @@ class T extends m {
502
502
  * @package
503
503
  */
504
504
  constructor(e, t, s) {
505
- super(), this.createRequest = e, W(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
505
+ super(), this.createRequest = e, z(this, s), this._opts = s, this._method = s.method || "GET", this._uri = t, this._data = s.data !== void 0 ? s.data : null, this._create();
506
506
  }
507
507
  /**
508
508
  * Creates the XHR object and sends the request.
@@ -548,7 +548,7 @@ class T extends m {
548
548
  }, 0);
549
549
  return;
550
550
  }
551
- typeof document < "u" && (this._index = T.requestsCount++, T.requests[this._index] = this);
551
+ typeof document < "u" && (this._index = C.requestsCount++, C.requests[this._index] = this);
552
552
  }
553
553
  /**
554
554
  * Called upon error.
@@ -565,12 +565,12 @@ class T extends m {
565
565
  */
566
566
  _cleanup(e) {
567
567
  if (!(typeof this._xhr > "u" || this._xhr === null)) {
568
- if (this._xhr.onreadystatechange = nt, e)
568
+ if (this._xhr.onreadystatechange = rt, e)
569
569
  try {
570
570
  this._xhr.abort();
571
571
  } catch {
572
572
  }
573
- typeof document < "u" && delete T.requests[this._index], this._xhr = null;
573
+ typeof document < "u" && delete C.requests[this._index], this._xhr = null;
574
574
  }
575
575
  }
576
576
  /**
@@ -591,56 +591,56 @@ class T extends m {
591
591
  this._cleanup();
592
592
  }
593
593
  }
594
- T.requestsCount = 0;
595
- T.requests = {};
594
+ C.requestsCount = 0;
595
+ C.requests = {};
596
596
  if (typeof document < "u") {
597
597
  if (typeof attachEvent == "function")
598
598
  attachEvent("onunload", ge);
599
599
  else if (typeof addEventListener == "function") {
600
- const n = "onpagehide" in v ? "pagehide" : "unload";
600
+ const n = "onpagehide" in E ? "pagehide" : "unload";
601
601
  addEventListener(n, ge, !1);
602
602
  }
603
603
  }
604
604
  function ge() {
605
- for (let n in T.requests)
606
- T.requests.hasOwnProperty(n) && T.requests[n].abort();
605
+ for (let n in C.requests)
606
+ C.requests.hasOwnProperty(n) && C.requests[n].abort();
607
607
  }
608
- const rt = function() {
609
- const n = Se({
608
+ const ct = function() {
609
+ const n = xe({
610
610
  xdomain: !1
611
611
  });
612
612
  return n && n.responseType !== null;
613
613
  }();
614
- class ot extends it {
614
+ class at extends ot {
615
615
  constructor(e) {
616
616
  super(e);
617
617
  const t = e && e.forceBase64;
618
- this.supportsBinary = rt && !t;
618
+ this.supportsBinary = ct && !t;
619
619
  }
620
620
  request(e = {}) {
621
- return Object.assign(e, { xd: this.xd }, this.opts), new T(Se, this.uri(), e);
621
+ return Object.assign(e, { xd: this.xd }, this.opts), new C(xe, this.uri(), e);
622
622
  }
623
623
  }
624
- function Se(n) {
624
+ function xe(n) {
625
625
  const e = n.xdomain;
626
626
  try {
627
- if (typeof XMLHttpRequest < "u" && (!e || st))
627
+ if (typeof XMLHttpRequest < "u" && (!e || it))
628
628
  return new XMLHttpRequest();
629
629
  } catch {
630
630
  }
631
631
  if (!e)
632
632
  try {
633
- return new v[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
633
+ return new E[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
634
634
  } catch {
635
635
  }
636
636
  }
637
- const xe = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
638
- class ct extends ae {
637
+ const Se = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
638
+ class ht extends ae {
639
639
  get name() {
640
640
  return "websocket";
641
641
  }
642
642
  doOpen() {
643
- const e = this.uri(), t = this.opts.protocols, s = xe ? {} : Ee(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
643
+ const e = this.uri(), t = this.opts.protocols, s = Se ? {} : Ee(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
644
644
  this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
645
645
  try {
646
646
  this.ws = this.createSocket(e, t, s);
@@ -671,7 +671,7 @@ class ct extends ae {
671
671
  this.doWrite(s, r);
672
672
  } catch {
673
673
  }
674
- i && $(() => {
674
+ i && Y(() => {
675
675
  this.writable = !0, this.emitReserved("drain");
676
676
  }, this.setTimeoutFn);
677
677
  });
@@ -691,16 +691,16 @@ class ct extends ae {
691
691
  return this.opts.timestampRequests && (t[this.opts.timestampParam] = Te()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
692
692
  }
693
693
  }
694
- const X = v.WebSocket || v.MozWebSocket;
695
- class at extends ct {
694
+ const j = E.WebSocket || E.MozWebSocket;
695
+ class ut extends ht {
696
696
  createSocket(e, t, s) {
697
- return xe ? new X(e, t, s) : t ? new X(e, t) : new X(e);
697
+ return Se ? new j(e, t, s) : t ? new j(e, t) : new j(e);
698
698
  }
699
699
  doWrite(e, t) {
700
700
  this.ws.send(t);
701
701
  }
702
702
  }
703
- class ht extends ae {
703
+ class lt extends ae {
704
704
  get name() {
705
705
  return "webtransport";
706
706
  }
@@ -716,7 +716,7 @@ class ht extends ae {
716
716
  this.onError("webtransport error", e);
717
717
  }), this._transport.ready.then(() => {
718
718
  this._transport.createBidirectionalStream().then((e) => {
719
- const t = $e(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), i = Ke();
719
+ const t = Ye(Number.MAX_SAFE_INTEGER, this.socket.binaryType), s = e.readable.pipeThrough(t).getReader(), i = $e();
720
720
  i.readable.pipeTo(e.writable), this._writer = i.writable.getWriter();
721
721
  const r = () => {
722
722
  s.read().then(({ done: a, value: l }) => {
@@ -735,7 +735,7 @@ class ht extends ae {
735
735
  for (let t = 0; t < e.length; t++) {
736
736
  const s = e[t], i = t === e.length - 1;
737
737
  this._writer.write(s).then(() => {
738
- i && $(() => {
738
+ i && Y(() => {
739
739
  this.writable = !0, this.emitReserved("drain");
740
740
  }, this.setTimeoutFn);
741
741
  });
@@ -746,11 +746,11 @@ class ht extends ae {
746
746
  (e = this._transport) === null || e === void 0 || e.close();
747
747
  }
748
748
  }
749
- const ut = {
750
- websocket: at,
751
- webtransport: ht,
752
- polling: ot
753
- }, lt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, ft = [
749
+ const ft = {
750
+ websocket: ut,
751
+ webtransport: lt,
752
+ polling: at
753
+ }, dt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, pt = [
754
754
  "source",
755
755
  "protocol",
756
756
  "authority",
@@ -771,26 +771,26 @@ function te(n) {
771
771
  throw "URI too long";
772
772
  const e = n, t = n.indexOf("["), s = n.indexOf("]");
773
773
  t != -1 && s != -1 && (n = n.substring(0, t) + n.substring(t, s).replace(/:/g, ";") + n.substring(s, n.length));
774
- let i = lt.exec(n || ""), r = {}, o = 14;
774
+ let i = dt.exec(n || ""), r = {}, o = 14;
775
775
  for (; o--; )
776
- r[ft[o]] = i[o] || "";
777
- return t != -1 && s != -1 && (r.source = e, r.host = r.host.substring(1, r.host.length - 1).replace(/;/g, ":"), r.authority = r.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), r.ipv6uri = !0), r.pathNames = dt(r, r.path), r.queryKey = pt(r, r.query), r;
776
+ r[pt[o]] = i[o] || "";
777
+ return t != -1 && s != -1 && (r.source = e, r.host = r.host.substring(1, r.host.length - 1).replace(/;/g, ":"), r.authority = r.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), r.ipv6uri = !0), r.pathNames = gt(r, r.path), r.queryKey = mt(r, r.query), r;
778
778
  }
779
- function dt(n, e) {
779
+ function gt(n, e) {
780
780
  const t = /\/{2,9}/g, s = e.replace(t, "/").split("/");
781
781
  return (e.slice(0, 1) == "/" || e.length === 0) && s.splice(0, 1), e.slice(-1) == "/" && s.splice(s.length - 1, 1), s;
782
782
  }
783
- function pt(n, e) {
783
+ function mt(n, e) {
784
784
  const t = {};
785
785
  return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(s, i, r) {
786
786
  i && (t[i] = r);
787
787
  }), t;
788
788
  }
789
- const se = typeof addEventListener == "function" && typeof removeEventListener == "function", V = [];
789
+ const se = typeof addEventListener == "function" && typeof removeEventListener == "function", F = [];
790
790
  se && addEventListener("offline", () => {
791
- V.forEach((n) => n());
791
+ F.forEach((n) => n());
792
792
  }, !1);
793
- class A extends m {
793
+ class A extends w {
794
794
  /**
795
795
  * Socket constructor.
796
796
  *
@@ -798,11 +798,11 @@ class A extends m {
798
798
  * @param {Object} opts - options
799
799
  */
800
800
  constructor(e, t) {
801
- if (super(), this.binaryType = Ye, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
801
+ if (super(), this.binaryType = Je, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = 1 / 0, e && typeof e == "object" && (t = e, e = null), e) {
802
802
  const s = te(e);
803
803
  t.hostname = s.host, t.secure = s.protocol === "https" || s.protocol === "wss", t.port = s.port, s.query && (t.query = s.query);
804
804
  } else t.host && (t.hostname = te(t.host).host);
805
- W(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
805
+ z(this, t), this.secure = t.secure != null ? t.secure : typeof location < "u" && location.protocol === "https:", t.hostname && !t.port && (t.port = this.secure ? "443" : "80"), this.hostname = t.hostname || (typeof location < "u" ? location.hostname : "localhost"), this.port = t.port || (typeof location < "u" && location.port ? location.port : this.secure ? "443" : "80"), this.transports = [], this._transportsByName = {}, t.transports.forEach((s) => {
806
806
  const i = s.prototype.name;
807
807
  this.transports.push(i), this._transportsByName[i] = s;
808
808
  }), this.opts = Object.assign({
@@ -819,13 +819,13 @@ class A extends m {
819
819
  },
820
820
  transportOptions: {},
821
821
  closeOnBeforeunload: !1
822
- }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Ze(this.opts.query)), se && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
822
+ }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = tt(this.opts.query)), se && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
823
823
  this.transport && (this.transport.removeAllListeners(), this.transport.close());
824
824
  }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
825
825
  this._onClose("transport close", {
826
826
  description: "network connection lost"
827
827
  });
828
- }, V.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
828
+ }, F.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
829
829
  }
830
830
  /**
831
831
  * Creates transport of the given type.
@@ -954,7 +954,7 @@ class A extends m {
954
954
  let t = 1;
955
955
  for (let s = 0; s < this.writeBuffer.length; s++) {
956
956
  const i = this.writeBuffer[s].data;
957
- if (i && (t += Xe(i)), s > 0 && t > this._maxPayload)
957
+ if (i && (t += Ge(i)), s > 0 && t > this._maxPayload)
958
958
  return this.writeBuffer.slice(0, s);
959
959
  t += 2;
960
960
  }
@@ -974,7 +974,7 @@ class A extends m {
974
974
  if (!this._pingTimeoutTime)
975
975
  return !0;
976
976
  const e = Date.now() > this._pingTimeoutTime;
977
- return e && (this._pingTimeoutTime = 0, $(() => {
977
+ return e && (this._pingTimeoutTime = 0, Y(() => {
978
978
  this._onClose("ping timeout");
979
979
  }, this.setTimeoutFn)), e;
980
980
  }
@@ -1053,15 +1053,15 @@ class A extends m {
1053
1053
  _onClose(e, t) {
1054
1054
  if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
1055
1055
  if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), se && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
1056
- const s = V.indexOf(this._offlineEventListener);
1057
- s !== -1 && V.splice(s, 1);
1056
+ const s = F.indexOf(this._offlineEventListener);
1057
+ s !== -1 && F.splice(s, 1);
1058
1058
  }
1059
1059
  this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
1060
1060
  }
1061
1061
  }
1062
1062
  }
1063
1063
  A.protocol = ve;
1064
- class gt extends A {
1064
+ class _t extends A {
1065
1065
  constructor() {
1066
1066
  super(...arguments), this._upgrades = [];
1067
1067
  }
@@ -1080,26 +1080,26 @@ class gt extends A {
1080
1080
  let t = this.createTransport(e), s = !1;
1081
1081
  A.priorWebsocketSuccess = !1;
1082
1082
  const i = () => {
1083
- s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (g) => {
1083
+ s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (m) => {
1084
1084
  if (!s)
1085
- if (g.type === "pong" && g.data === "probe") {
1085
+ if (m.type === "pong" && m.data === "probe") {
1086
1086
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1087
1087
  return;
1088
1088
  A.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1089
- s || this.readyState !== "closed" && (p(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1089
+ s || this.readyState !== "closed" && (f(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1090
1090
  });
1091
1091
  } else {
1092
- const _ = new Error("probe error");
1093
- _.transport = t.name, this.emitReserved("upgradeError", _);
1092
+ const y = new Error("probe error");
1093
+ y.transport = t.name, this.emitReserved("upgradeError", y);
1094
1094
  }
1095
1095
  }));
1096
1096
  };
1097
1097
  function r() {
1098
- s || (s = !0, p(), t.close(), t = null);
1098
+ s || (s = !0, f(), t.close(), t = null);
1099
1099
  }
1100
- const o = (g) => {
1101
- const _ = new Error("probe error: " + g);
1102
- _.transport = t.name, r(), this.emitReserved("upgradeError", _);
1100
+ const o = (m) => {
1101
+ const y = new Error("probe error: " + m);
1102
+ y.transport = t.name, r(), this.emitReserved("upgradeError", y);
1103
1103
  };
1104
1104
  function a() {
1105
1105
  o("transport closed");
@@ -1107,10 +1107,10 @@ class gt extends A {
1107
1107
  function l() {
1108
1108
  o("socket closed");
1109
1109
  }
1110
- function h(g) {
1111
- t && g.name !== t.name && r();
1110
+ function h(m) {
1111
+ t && m.name !== t.name && r();
1112
1112
  }
1113
- const p = () => {
1113
+ const f = () => {
1114
1114
  t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", a), this.off("close", l), this.off("upgrading", h);
1115
1115
  };
1116
1116
  t.once("open", i), t.once("error", o), t.once("close", a), this.once("close", l), this.once("upgrading", h), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
@@ -1133,41 +1133,41 @@ class gt extends A {
1133
1133
  return t;
1134
1134
  }
1135
1135
  }
1136
- let mt = class extends gt {
1136
+ let yt = class extends _t {
1137
1137
  constructor(e, t = {}) {
1138
1138
  const s = typeof e == "object" ? e : t;
1139
- (!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((i) => ut[i]).filter((i) => !!i)), super(e, s);
1139
+ (!s.transports || s.transports && typeof s.transports[0] == "string") && (s.transports = (s.transports || ["polling", "websocket", "webtransport"]).map((i) => ft[i]).filter((i) => !!i)), super(e, s);
1140
1140
  }
1141
1141
  };
1142
- function _t(n, e = "", t) {
1142
+ function wt(n, e = "", t) {
1143
1143
  let s = n;
1144
1144
  t = t || typeof location < "u" && location, n == null && (n = t.protocol + "//" + t.host), typeof n == "string" && (n.charAt(0) === "/" && (n.charAt(1) === "/" ? n = t.protocol + n : n = t.host + n), /^(https?|wss?):\/\//.test(n) || (typeof t < "u" ? n = t.protocol + "//" + n : n = "https://" + n), s = te(n)), s.port || (/^(http|ws)$/.test(s.protocol) ? s.port = "80" : /^(http|ws)s$/.test(s.protocol) && (s.port = "443")), s.path = s.path || "/";
1145
1145
  const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
1146
1146
  return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
1147
1147
  }
1148
- const yt = typeof ArrayBuffer == "function", wt = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, Ne = Object.prototype.toString, kt = typeof Blob == "function" || typeof Blob < "u" && Ne.call(Blob) === "[object BlobConstructor]", bt = typeof File == "function" || typeof File < "u" && Ne.call(File) === "[object FileConstructor]";
1148
+ const kt = typeof ArrayBuffer == "function", bt = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, Ne = Object.prototype.toString, vt = typeof Blob == "function" || typeof Blob < "u" && Ne.call(Blob) === "[object BlobConstructor]", Et = typeof File == "function" || typeof File < "u" && Ne.call(File) === "[object FileConstructor]";
1149
1149
  function he(n) {
1150
- return yt && (n instanceof ArrayBuffer || wt(n)) || kt && n instanceof Blob || bt && n instanceof File;
1150
+ return kt && (n instanceof ArrayBuffer || bt(n)) || vt && n instanceof Blob || Et && n instanceof File;
1151
1151
  }
1152
- function F(n, e) {
1152
+ function H(n, e) {
1153
1153
  if (!n || typeof n != "object")
1154
1154
  return !1;
1155
1155
  if (Array.isArray(n)) {
1156
1156
  for (let t = 0, s = n.length; t < s; t++)
1157
- if (F(n[t]))
1157
+ if (H(n[t]))
1158
1158
  return !0;
1159
1159
  return !1;
1160
1160
  }
1161
1161
  if (he(n))
1162
1162
  return !0;
1163
1163
  if (n.toJSON && typeof n.toJSON == "function" && arguments.length === 1)
1164
- return F(n.toJSON(), !0);
1164
+ return H(n.toJSON(), !0);
1165
1165
  for (const t in n)
1166
- if (Object.prototype.hasOwnProperty.call(n, t) && F(n[t]))
1166
+ if (Object.prototype.hasOwnProperty.call(n, t) && H(n[t]))
1167
1167
  return !0;
1168
1168
  return !1;
1169
1169
  }
1170
- function vt(n) {
1170
+ function Tt(n) {
1171
1171
  const e = [], t = n.data, s = n;
1172
1172
  return s.data = ne(t, e), s.attachments = e.length, { packet: s, buffers: e };
1173
1173
  }
@@ -1190,7 +1190,7 @@ function ne(n, e) {
1190
1190
  }
1191
1191
  return n;
1192
1192
  }
1193
- function Et(n, e) {
1193
+ function Ct(n, e) {
1194
1194
  return n.data = ie(n.data, e), delete n.attachments, n;
1195
1195
  }
1196
1196
  function ie(n, e) {
@@ -1221,12 +1221,12 @@ const Ae = [
1221
1221
  // used by the Node.js EventEmitter
1222
1222
  "removeListener"
1223
1223
  // used by the Node.js EventEmitter
1224
- ], Tt = 5;
1224
+ ], xt = 5;
1225
1225
  var u;
1226
1226
  (function(n) {
1227
1227
  n[n.CONNECT = 0] = "CONNECT", n[n.DISCONNECT = 1] = "DISCONNECT", n[n.EVENT = 2] = "EVENT", n[n.ACK = 3] = "ACK", n[n.CONNECT_ERROR = 4] = "CONNECT_ERROR", n[n.BINARY_EVENT = 5] = "BINARY_EVENT", n[n.BINARY_ACK = 6] = "BINARY_ACK";
1228
1228
  })(u || (u = {}));
1229
- class Ct {
1229
+ class St {
1230
1230
  /**
1231
1231
  * Encoder constructor
1232
1232
  *
@@ -1242,7 +1242,7 @@ class Ct {
1242
1242
  * @param {Object} obj - packet object
1243
1243
  */
1244
1244
  encode(e) {
1245
- return (e.type === u.EVENT || e.type === u.ACK) && F(e) ? this.encodeAsBinary({
1245
+ return (e.type === u.EVENT || e.type === u.ACK) && H(e) ? this.encodeAsBinary({
1246
1246
  type: e.type === u.EVENT ? u.BINARY_EVENT : u.BINARY_ACK,
1247
1247
  nsp: e.nsp,
1248
1248
  data: e.data,
@@ -1262,11 +1262,11 @@ class Ct {
1262
1262
  * a list of buffers.
1263
1263
  */
1264
1264
  encodeAsBinary(e) {
1265
- const t = vt(e), s = this.encodeAsString(t.packet), i = t.buffers;
1265
+ const t = Tt(e), s = this.encodeAsString(t.packet), i = t.buffers;
1266
1266
  return i.unshift(s), i;
1267
1267
  }
1268
1268
  }
1269
- class ue extends m {
1269
+ class ue extends w {
1270
1270
  /**
1271
1271
  * Decoder constructor
1272
1272
  *
@@ -1287,7 +1287,7 @@ class ue extends m {
1287
1287
  throw new Error("got plaintext data when reconstructing a packet");
1288
1288
  t = this.decodeString(e);
1289
1289
  const s = t.type === u.BINARY_EVENT;
1290
- s || t.type === u.BINARY_ACK ? (t.type = s ? u.EVENT : u.ACK, this.reconstructor = new St(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
1290
+ s || t.type === u.BINARY_ACK ? (t.type = s ? u.EVENT : u.ACK, this.reconstructor = new Nt(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
1291
1291
  } else if (he(e) || e.base64)
1292
1292
  if (this.reconstructor)
1293
1293
  t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
@@ -1358,11 +1358,11 @@ class ue extends m {
1358
1358
  static isPayloadValid(e, t) {
1359
1359
  switch (e) {
1360
1360
  case u.CONNECT:
1361
- return K(t);
1361
+ return $(t);
1362
1362
  case u.DISCONNECT:
1363
1363
  return t === void 0;
1364
1364
  case u.CONNECT_ERROR:
1365
- return typeof t == "string" || K(t);
1365
+ return typeof t == "string" || $(t);
1366
1366
  case u.EVENT:
1367
1367
  case u.BINARY_EVENT:
1368
1368
  return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && Ae.indexOf(t[0]) === -1);
@@ -1378,7 +1378,7 @@ class ue extends m {
1378
1378
  this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
1379
1379
  }
1380
1380
  }
1381
- class St {
1381
+ class Nt {
1382
1382
  constructor(e) {
1383
1383
  this.packet = e, this.buffers = [], this.reconPack = e;
1384
1384
  }
@@ -1392,7 +1392,7 @@ class St {
1392
1392
  */
1393
1393
  takeBinaryData(e) {
1394
1394
  if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1395
- const t = Et(this.reconPack, this.buffers);
1395
+ const t = Ct(this.reconPack, this.buffers);
1396
1396
  return this.finishedReconstruction(), t;
1397
1397
  }
1398
1398
  return null;
@@ -1404,22 +1404,22 @@ class St {
1404
1404
  this.reconPack = null, this.buffers = [];
1405
1405
  }
1406
1406
  }
1407
- function xt(n) {
1407
+ function At(n) {
1408
1408
  return typeof n == "string";
1409
1409
  }
1410
- const Nt = Number.isInteger || function(n) {
1410
+ const Rt = Number.isInteger || function(n) {
1411
1411
  return typeof n == "number" && isFinite(n) && Math.floor(n) === n;
1412
1412
  };
1413
- function At(n) {
1414
- return n === void 0 || Nt(n);
1413
+ function Ot(n) {
1414
+ return n === void 0 || Rt(n);
1415
1415
  }
1416
- function K(n) {
1416
+ function $(n) {
1417
1417
  return Object.prototype.toString.call(n) === "[object Object]";
1418
1418
  }
1419
- function Rt(n, e) {
1419
+ function Bt(n, e) {
1420
1420
  switch (n) {
1421
1421
  case u.CONNECT:
1422
- return e === void 0 || K(e);
1422
+ return e === void 0 || $(e);
1423
1423
  case u.DISCONNECT:
1424
1424
  return e === void 0;
1425
1425
  case u.EVENT:
@@ -1427,30 +1427,30 @@ function Rt(n, e) {
1427
1427
  case u.ACK:
1428
1428
  return Array.isArray(e);
1429
1429
  case u.CONNECT_ERROR:
1430
- return typeof e == "string" || K(e);
1430
+ return typeof e == "string" || $(e);
1431
1431
  default:
1432
1432
  return !1;
1433
1433
  }
1434
1434
  }
1435
- function Ot(n) {
1436
- return xt(n.nsp) && At(n.id) && Rt(n.type, n.data);
1435
+ function Lt(n) {
1436
+ return At(n.nsp) && Ot(n.id) && Bt(n.type, n.data);
1437
1437
  }
1438
- const Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1438
+ const Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1439
1439
  __proto__: null,
1440
1440
  Decoder: ue,
1441
- Encoder: Ct,
1441
+ Encoder: St,
1442
1442
  get PacketType() {
1443
1443
  return u;
1444
1444
  },
1445
- isPacketValid: Ot,
1446
- protocol: Tt
1445
+ isPacketValid: Lt,
1446
+ protocol: xt
1447
1447
  }, Symbol.toStringTag, { value: "Module" }));
1448
- function E(n, e, t) {
1448
+ function T(n, e, t) {
1449
1449
  return n.on(e, t), function() {
1450
1450
  n.off(e, t);
1451
1451
  };
1452
1452
  }
1453
- const Lt = Object.freeze({
1453
+ const Dt = Object.freeze({
1454
1454
  connect: 1,
1455
1455
  connect_error: 1,
1456
1456
  disconnect: 1,
@@ -1459,7 +1459,7 @@ const Lt = Object.freeze({
1459
1459
  newListener: 1,
1460
1460
  removeListener: 1
1461
1461
  });
1462
- class Re extends m {
1462
+ class Re extends w {
1463
1463
  /**
1464
1464
  * `Socket` constructor.
1465
1465
  */
@@ -1493,10 +1493,10 @@ class Re extends m {
1493
1493
  return;
1494
1494
  const e = this.io;
1495
1495
  this.subs = [
1496
- E(e, "open", this.onopen.bind(this)),
1497
- E(e, "packet", this.onpacket.bind(this)),
1498
- E(e, "error", this.onerror.bind(this)),
1499
- E(e, "close", this.onclose.bind(this))
1496
+ T(e, "open", this.onopen.bind(this)),
1497
+ T(e, "packet", this.onpacket.bind(this)),
1498
+ T(e, "error", this.onerror.bind(this)),
1499
+ T(e, "close", this.onclose.bind(this))
1500
1500
  ];
1501
1501
  }
1502
1502
  /**
@@ -1575,7 +1575,7 @@ class Re extends m {
1575
1575
  */
1576
1576
  emit(e, ...t) {
1577
1577
  var s, i, r;
1578
- if (Lt.hasOwnProperty(e))
1578
+ if (Dt.hasOwnProperty(e))
1579
1579
  throw new Error('"' + e.toString() + '" is a reserved event name');
1580
1580
  if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile)
1581
1581
  return this._addToQueue(t), this;
@@ -1584,8 +1584,8 @@ class Re extends m {
1584
1584
  data: t
1585
1585
  };
1586
1586
  if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1587
- const p = this.ids++, g = t.pop();
1588
- this._registerAckCallback(p, g), o.id = p;
1587
+ const f = this.ids++, m = t.pop();
1588
+ this._registerAckCallback(f, m), o.id = f;
1589
1589
  }
1590
1590
  const a = (i = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || i === void 0 ? void 0 : i.writable, l = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
1591
1591
  return this.flags.volatile && !a || (l ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
@@ -2051,10 +2051,10 @@ class Re extends m {
2051
2051
  }
2052
2052
  }
2053
2053
  }
2054
- function O(n) {
2054
+ function B(n) {
2055
2055
  n = n || {}, this.ms = n.min || 100, this.max = n.max || 1e4, this.factor = n.factor || 2, this.jitter = n.jitter > 0 && n.jitter <= 1 ? n.jitter : 0, this.attempts = 0;
2056
2056
  }
2057
- O.prototype.duration = function() {
2057
+ B.prototype.duration = function() {
2058
2058
  var n = this.ms * Math.pow(this.factor, this.attempts++);
2059
2059
  if (this.jitter) {
2060
2060
  var e = Math.random(), t = Math.floor(e * this.jitter * n);
@@ -2062,27 +2062,27 @@ O.prototype.duration = function() {
2062
2062
  }
2063
2063
  return Math.min(n, this.max) | 0;
2064
2064
  };
2065
- O.prototype.reset = function() {
2065
+ B.prototype.reset = function() {
2066
2066
  this.attempts = 0;
2067
2067
  };
2068
- O.prototype.setMin = function(n) {
2068
+ B.prototype.setMin = function(n) {
2069
2069
  this.ms = n;
2070
2070
  };
2071
- O.prototype.setMax = function(n) {
2071
+ B.prototype.setMax = function(n) {
2072
2072
  this.max = n;
2073
2073
  };
2074
- O.prototype.setJitter = function(n) {
2074
+ B.prototype.setJitter = function(n) {
2075
2075
  this.jitter = n;
2076
2076
  };
2077
- class re extends m {
2077
+ class re extends w {
2078
2078
  constructor(e, t) {
2079
2079
  var s;
2080
- super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, W(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new O({
2080
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, z(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new B({
2081
2081
  min: this.reconnectionDelay(),
2082
2082
  max: this.reconnectionDelayMax(),
2083
2083
  jitter: this.randomizationFactor()
2084
2084
  }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
2085
- const i = t.parser || Bt;
2085
+ const i = t.parser || Pt;
2086
2086
  this.encoder = new i.Encoder(), this.decoder = new i.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
2087
2087
  }
2088
2088
  reconnection(e) {
@@ -2125,14 +2125,14 @@ class re extends m {
2125
2125
  open(e) {
2126
2126
  if (~this._readyState.indexOf("open"))
2127
2127
  return this;
2128
- this.engine = new mt(this.uri, this.opts);
2128
+ this.engine = new yt(this.uri, this.opts);
2129
2129
  const t = this.engine, s = this;
2130
2130
  this._readyState = "opening", this.skipReconnect = !1;
2131
- const i = E(t, "open", function() {
2131
+ const i = T(t, "open", function() {
2132
2132
  s.onopen(), e && e();
2133
2133
  }), r = (a) => {
2134
2134
  this.cleanup(), this._readyState = "closed", this.emitReserved("error", a), e ? e(a) : this.maybeReconnectOnOpen();
2135
- }, o = E(t, "error", r);
2135
+ }, o = T(t, "error", r);
2136
2136
  if (this._timeout !== !1) {
2137
2137
  const a = this._timeout, l = this.setTimeoutFn(() => {
2138
2138
  i(), r(new Error("timeout")), t.close();
@@ -2161,12 +2161,12 @@ class re extends m {
2161
2161
  this.cleanup(), this._readyState = "open", this.emitReserved("open");
2162
2162
  const e = this.engine;
2163
2163
  this.subs.push(
2164
- E(e, "ping", this.onping.bind(this)),
2165
- E(e, "data", this.ondata.bind(this)),
2166
- E(e, "error", this.onerror.bind(this)),
2167
- E(e, "close", this.onclose.bind(this)),
2164
+ T(e, "ping", this.onping.bind(this)),
2165
+ T(e, "data", this.ondata.bind(this)),
2166
+ T(e, "error", this.onerror.bind(this)),
2167
+ T(e, "close", this.onclose.bind(this)),
2168
2168
  // @ts-ignore
2169
- E(this.decoder, "decoded", this.ondecoded.bind(this))
2169
+ T(this.decoder, "decoded", this.ondecoded.bind(this))
2170
2170
  );
2171
2171
  }
2172
2172
  /**
@@ -2195,7 +2195,7 @@ class re extends m {
2195
2195
  * @private
2196
2196
  */
2197
2197
  ondecoded(e) {
2198
- $(() => {
2198
+ Y(() => {
2199
2199
  this.emitReserved("packet", e);
2200
2200
  }, this.setTimeoutFn);
2201
2201
  }
@@ -2312,23 +2312,23 @@ class re extends m {
2312
2312
  this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
2313
2313
  }
2314
2314
  }
2315
- const P = {};
2316
- function H(n, e) {
2315
+ const D = {};
2316
+ function K(n, e) {
2317
2317
  typeof n == "object" && (e = n, n = void 0), e = e || {};
2318
- const t = _t(n, e.path || "/socket.io"), s = t.source, i = t.id, r = t.path, o = P[i] && r in P[i].nsps, a = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
2318
+ const t = wt(n, e.path || "/socket.io"), s = t.source, i = t.id, r = t.path, o = D[i] && r in D[i].nsps, a = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
2319
2319
  let l;
2320
- return a ? l = new re(s, e) : (P[i] || (P[i] = new re(s, e)), l = P[i]), t.query && !e.query && (e.query = t.queryKey), l.socket(t.path, e);
2320
+ return a ? l = new re(s, e) : (D[i] || (D[i] = new re(s, e)), l = D[i]), t.query && !e.query && (e.query = t.queryKey), l.socket(t.path, e);
2321
2321
  }
2322
- Object.assign(H, {
2322
+ Object.assign(K, {
2323
2323
  Manager: re,
2324
2324
  Socket: Re,
2325
- io: H,
2326
- connect: H
2325
+ io: K,
2326
+ connect: K
2327
2327
  });
2328
2328
  function N() {
2329
2329
  return `${Date.now().toString(36)}-${Math.random().toString(16).slice(2, 8)}`;
2330
2330
  }
2331
- class Pt {
2331
+ class It {
2332
2332
  constructor(e) {
2333
2333
  this.socket = null, this.reconnectAttempts = 0, this.listeners = /* @__PURE__ */ new Map(), this.lastContext = null, this.config = {
2334
2334
  reconnectAttempts: 5,
@@ -2372,7 +2372,7 @@ class Pt {
2372
2372
  var r;
2373
2373
  if ((r = this.socket) != null && r.connected) return;
2374
2374
  const e = new URL(this.config.websocketUrl), t = e.pathname === "/" ? "/socket.io" : e.pathname, s = e.origin, i = await this.getToken();
2375
- return this.socket = H(s, {
2375
+ return this.socket = K(s, {
2376
2376
  path: t,
2377
2377
  transports: ["websocket", "polling"],
2378
2378
  autoConnect: !1,
@@ -2499,7 +2499,7 @@ class Pt {
2499
2499
  }, this.config.reconnectDelayMs);
2500
2500
  }
2501
2501
  }
2502
- function Dt(n) {
2502
+ function qt(n) {
2503
2503
  return n.map((e) => {
2504
2504
  const t = {
2505
2505
  id: N(),
@@ -2529,14 +2529,14 @@ function Dt(n) {
2529
2529
  }), [s, ...i];
2530
2530
  }).flat().sort((e, t) => e.timestamp.getTime() - t.timestamp.getTime());
2531
2531
  }
2532
- const Oe = De(null), It = { connected: !1, connecting: !1 };
2533
- function Kt({ config: n, children: e }) {
2534
- const t = G(null), s = G(/* @__PURE__ */ new Map()), [i, r] = Z({
2532
+ const Oe = De(null), Ut = { connected: !1, connecting: !1 };
2533
+ function Yt({ config: n, children: e }) {
2534
+ const t = W(null), s = W(/* @__PURE__ */ new Map()), [i, r] = Z({
2535
2535
  messages: [],
2536
- connection: It,
2536
+ connection: Ut,
2537
2537
  latestPatchOffer: null,
2538
2538
  isSubmitting: !1
2539
- }), o = U(
2539
+ }), o = M(
2540
2540
  () => ({
2541
2541
  reconnectAttempts: 5,
2542
2542
  reconnectDelayMs: 1500,
@@ -2545,17 +2545,17 @@ function Kt({ config: n, children: e }) {
2545
2545
  [n]
2546
2546
  );
2547
2547
  me(() => {
2548
- const h = new Pt(o);
2548
+ const h = new It(o);
2549
2549
  t.current = h;
2550
- const p = h.on("connection", (c) => {
2551
- r((f) => ({ ...f, connection: c }));
2552
- }), g = h.on("chat-response", (c) => {
2553
- r((f) => {
2554
- const b = [...f.messages];
2555
- let S = b.find(
2556
- (k) => k.instructionId === c.instruction_id && k.type === "ai-chat"
2550
+ const f = h.on("connection", (c) => {
2551
+ r((g) => ({ ...g, connection: c }));
2552
+ }), m = h.on("chat-response", (c) => {
2553
+ r((g) => {
2554
+ const p = [...g.messages];
2555
+ let _ = p.find(
2556
+ (v) => v.instructionId === c.instruction_id && v.type === "ai-chat"
2557
2557
  );
2558
- S || (S = {
2558
+ _ || (_ = {
2559
2559
  id: N(),
2560
2560
  type: "ai-chat",
2561
2561
  content: "",
@@ -2563,23 +2563,23 @@ function Kt({ config: n, children: e }) {
2563
2563
  instructionId: c.instruction_id,
2564
2564
  pageNum: c.page_num,
2565
2565
  isStreaming: !0
2566
- }, b.push(S));
2567
- const x = {
2568
- ...S,
2569
- content: (S.content || "") + (c.chunk_text || ""),
2566
+ }, p.push(_));
2567
+ const S = {
2568
+ ..._,
2569
+ content: (_.content || "") + (c.chunk_text || ""),
2570
2570
  isStreaming: !c.is_final
2571
- }, R = b.map(
2572
- (k) => k.id === S.id ? x : k
2571
+ }, R = p.map(
2572
+ (v) => v.id === _.id ? S : v
2573
2573
  );
2574
2574
  return {
2575
- ...f,
2575
+ ...g,
2576
2576
  messages: R,
2577
- isSubmitting: c.is_final ? !1 : f.isSubmitting
2577
+ isSubmitting: c.is_final ? !1 : g.isSubmitting
2578
2578
  };
2579
2579
  });
2580
- }), _ = h.on("patch-offer", (c) => {
2581
- var S;
2582
- const f = `${c.trans_doc_id}-${c.instruction_id}`, b = s.current.get(f) ?? {
2580
+ }), y = h.on("patch-offer", (c) => {
2581
+ var _;
2582
+ const g = `${c.trans_doc_id}-${c.instruction_id}`, p = s.current.get(g) ?? {
2583
2583
  trans_doc_id: c.trans_doc_id,
2584
2584
  page_num: c.page_num,
2585
2585
  instruction_id: c.instruction_id,
@@ -2589,13 +2589,13 @@ function Kt({ config: n, children: e }) {
2589
2589
  is_page_level: !c.region_coordinates,
2590
2590
  selection_id: c.selection_id
2591
2591
  };
2592
- if (b.new_suggestion += c.region_replacement_text_chunk || "", c.selection_id && !b.selection_id && (b.selection_id = c.selection_id), s.current.set(f, b), r((x) => {
2592
+ if (p.new_suggestion += c.region_replacement_text_chunk || "", c.selection_id && !p.selection_id && (p.selection_id = c.selection_id), s.current.set(g, p), r((S) => {
2593
2593
  var le;
2594
- const R = [...x.messages];
2595
- let k = R.find(
2596
- (L) => L.instructionId === c.instruction_id && L.type === "ai-patch"
2594
+ const R = [...S.messages];
2595
+ let v = R.find(
2596
+ (P) => P.instructionId === c.instruction_id && P.type === "ai-patch"
2597
2597
  );
2598
- k || (k = {
2598
+ v || (v = {
2599
2599
  id: N(),
2600
2600
  type: "ai-patch",
2601
2601
  content: "",
@@ -2609,36 +2609,36 @@ function Kt({ config: n, children: e }) {
2609
2609
  regionText: c.region_original_text,
2610
2610
  isComplete: !1
2611
2611
  }
2612
- }, R.push(k));
2612
+ }, R.push(v));
2613
2613
  const Be = {
2614
- ...k,
2615
- content: (k.content || "") + (c.region_replacement_text_chunk || ""),
2614
+ ...v,
2615
+ content: (v.content || "") + (c.region_replacement_text_chunk || ""),
2616
2616
  isStreaming: !c.is_final,
2617
2617
  patchData: {
2618
- ...k.patchData,
2619
- improvedText: (((le = k.patchData) == null ? void 0 : le.improvedText) || "") + (c.region_replacement_text_chunk || ""),
2618
+ ...v.patchData,
2619
+ improvedText: (((le = v.patchData) == null ? void 0 : le.improvedText) || "") + (c.region_replacement_text_chunk || ""),
2620
2620
  regionText: c.region_original_text,
2621
2621
  isComplete: c.is_final
2622
2622
  }
2623
- }, Le = R.map((L) => L.id === k.id ? Be : L);
2623
+ }, Le = R.map((P) => P.id === v.id ? Be : P);
2624
2624
  return {
2625
- ...x,
2625
+ ...S,
2626
2626
  messages: Le,
2627
- isSubmitting: c.is_final ? !1 : x.isSubmitting
2627
+ isSubmitting: c.is_final ? !1 : S.isSubmitting
2628
2628
  };
2629
2629
  }), c.is_final) {
2630
- const x = s.current.get(f);
2631
- x && ((S = o.onPatchOffer) == null || S.call(o, x), r((R) => ({ ...R, latestPatchOffer: x }))), s.current.delete(f);
2630
+ const S = s.current.get(g);
2631
+ S && ((_ = o.onPatchOffer) == null || _.call(o, S), r((R) => ({ ...R, latestPatchOffer: S }))), s.current.delete(g);
2632
2632
  }
2633
- }), w = h.on("chat-history-response", (c) => {
2633
+ }), b = h.on("chat-history-response", (c) => {
2634
2634
  if (c.status === "success") {
2635
- const f = Dt(c.messages);
2636
- r((b) => ({ ...b, messages: f }));
2635
+ const g = qt(c.messages);
2636
+ r((p) => ({ ...p, messages: g }));
2637
2637
  } else
2638
- r((f) => ({
2639
- ...f,
2638
+ r((g) => ({
2639
+ ...g,
2640
2640
  messages: [
2641
- ...f.messages,
2641
+ ...g.messages,
2642
2642
  {
2643
2643
  id: N(),
2644
2644
  type: "system",
@@ -2647,12 +2647,12 @@ function Kt({ config: n, children: e }) {
2647
2647
  }
2648
2648
  ]
2649
2649
  }));
2650
- }), B = h.on("instruction-error", (c) => {
2651
- r((f) => ({
2652
- ...f,
2650
+ }), O = h.on("instruction-error", (c) => {
2651
+ r((g) => ({
2652
+ ...g,
2653
2653
  isSubmitting: !1,
2654
2654
  messages: [
2655
- ...f.messages,
2655
+ ...g.messages,
2656
2656
  {
2657
2657
  id: N(),
2658
2658
  type: "error",
@@ -2661,14 +2661,14 @@ function Kt({ config: n, children: e }) {
2661
2661
  }
2662
2662
  ]
2663
2663
  }));
2664
- }), Y = h.on("page-translation-response", (c) => {
2665
- var f;
2666
- (f = o.onPageTranslationResponse) == null || f.call(o, c);
2667
- }), z = h.on(
2664
+ }), L = h.on("page-translation-response", (c) => {
2665
+ var g;
2666
+ (g = o.onPageTranslationResponse) == null || g.call(o, c);
2667
+ }), J = h.on(
2668
2668
  "bulk-translation-response",
2669
2669
  (c) => {
2670
- var f;
2671
- (f = o.onBulkTranslationResponse) == null || f.call(o, c);
2670
+ var g;
2671
+ (g = o.onBulkTranslationResponse) == null || g.call(o, c);
2672
2672
  }
2673
2673
  );
2674
2674
  return h.connect().then(() => {
@@ -2676,32 +2676,32 @@ function Kt({ config: n, children: e }) {
2676
2676
  if (c)
2677
2677
  return h.requestChatHistory(c);
2678
2678
  }).catch((c) => {
2679
- var f, b;
2680
- return (b = (f = o.logger) == null ? void 0 : f.warn) == null ? void 0 : b.call(f, "chat-sdk connect failed", c);
2679
+ var g, p;
2680
+ return (p = (g = o.logger) == null ? void 0 : g.warn) == null ? void 0 : p.call(g, "chat-sdk connect failed", c);
2681
2681
  }), () => {
2682
- p(), g(), _(), w(), B(), Y(), z(), h.disconnect();
2682
+ f(), m(), y(), b(), O(), L(), J(), h.disconnect();
2683
2683
  };
2684
2684
  }, [o]);
2685
- const a = U(
2685
+ const a = M(
2686
2686
  () => ({
2687
2687
  async submitInstruction(h) {
2688
- const p = t.current;
2689
- if (!p) throw new Error("SDK not ready");
2690
- const g = o.contextProvider();
2691
- if (!g) throw new Error("contextProvider returned null");
2692
- r((_) => {
2693
- var w;
2688
+ const f = t.current;
2689
+ if (!f) throw new Error("SDK not ready");
2690
+ const m = o.contextProvider();
2691
+ if (!m) throw new Error("contextProvider returned null");
2692
+ r((y) => {
2693
+ var b;
2694
2694
  return {
2695
- ..._,
2695
+ ...y,
2696
2696
  isSubmitting: !0,
2697
2697
  messages: [
2698
- ..._.messages,
2698
+ ...y.messages,
2699
2699
  {
2700
2700
  id: N(),
2701
2701
  type: "user",
2702
2702
  content: h,
2703
2703
  timestamp: /* @__PURE__ */ new Date(),
2704
- contextText: (w = g.highlighted_region) == null ? void 0 : w.text
2704
+ contextText: (b = m.highlighted_region) == null ? void 0 : b.text
2705
2705
  },
2706
2706
  {
2707
2707
  id: N(),
@@ -2712,24 +2712,24 @@ function Kt({ config: n, children: e }) {
2712
2712
  }
2713
2713
  ]
2714
2714
  };
2715
- }), await p.submitInstruction(h, g);
2715
+ }), await f.submitInstruction(h, m);
2716
2716
  },
2717
- async submitInstructionWithContext(h, p) {
2718
- const g = t.current;
2719
- if (!g) throw new Error("SDK not ready");
2720
- r((_) => {
2721
- var w;
2717
+ async submitInstructionWithContext(h, f) {
2718
+ const m = t.current;
2719
+ if (!m) throw new Error("SDK not ready");
2720
+ r((y) => {
2721
+ var b;
2722
2722
  return {
2723
- ..._,
2723
+ ...y,
2724
2724
  isSubmitting: !0,
2725
2725
  messages: [
2726
- ..._.messages,
2726
+ ...y.messages,
2727
2727
  {
2728
2728
  id: N(),
2729
2729
  type: "user",
2730
2730
  content: h,
2731
2731
  timestamp: /* @__PURE__ */ new Date(),
2732
- contextText: (w = p.highlighted_region) == null ? void 0 : w.text
2732
+ contextText: (b = f.highlighted_region) == null ? void 0 : b.text
2733
2733
  },
2734
2734
  {
2735
2735
  id: N(),
@@ -2740,41 +2740,41 @@ function Kt({ config: n, children: e }) {
2740
2740
  }
2741
2741
  ]
2742
2742
  };
2743
- }), await g.submitInstruction(h, p);
2743
+ }), await m.submitInstruction(h, f);
2744
2744
  },
2745
2745
  async requestChatHistory() {
2746
2746
  const h = t.current;
2747
2747
  if (!h) throw new Error("SDK not ready");
2748
- const p = o.contextProvider();
2749
- if (!p) throw new Error("contextProvider returned null");
2750
- await h.requestChatHistory(p);
2748
+ const f = o.contextProvider();
2749
+ if (!f) throw new Error("contextProvider returned null");
2750
+ await h.requestChatHistory(f);
2751
2751
  },
2752
- async sendPatchDecision(h, p, g, _) {
2753
- const w = t.current;
2754
- if (!w) throw new Error("SDK not ready");
2755
- await w.sendPatchDecision({ trans_doc_id: h, page_num: p, instruction_id: g, decision: _ }), r((B) => ({ ...B, latestPatchOffer: null }));
2752
+ async sendPatchDecision(h, f, m, y) {
2753
+ const b = t.current;
2754
+ if (!b) throw new Error("SDK not ready");
2755
+ await b.sendPatchDecision({ trans_doc_id: h, page_num: f, instruction_id: m, decision: y }), r((O) => ({ ...O, latestPatchOffer: null }));
2756
2756
  },
2757
- async requestPageTranslation(h, p) {
2758
- const g = t.current;
2759
- if (!g) throw new Error("SDK not ready");
2760
- return await g.requestPageTranslation({ trans_doc_id: h, page_num: p }), !0;
2757
+ async requestPageTranslation(h, f) {
2758
+ const m = t.current;
2759
+ if (!m) throw new Error("SDK not ready");
2760
+ return await m.requestPageTranslation({ trans_doc_id: h, page_num: f }), !0;
2761
2761
  },
2762
- async requestBulkTranslation(h, p) {
2763
- const g = t.current;
2764
- if (!g) throw new Error("SDK not ready");
2765
- return await g.requestBulkTranslation({ trans_doc_id: h, page_list: p }), !0;
2762
+ async requestBulkTranslation(h, f) {
2763
+ const m = t.current;
2764
+ if (!m) throw new Error("SDK not ready");
2765
+ return await m.requestBulkTranslation({ trans_doc_id: h, page_list: f }), !0;
2766
2766
  },
2767
2767
  async cancelBulkTranslation(h) {
2768
- const p = t.current;
2769
- if (!p) throw new Error("SDK not ready");
2770
- return await p.cancelBulkTranslation(h), !0;
2768
+ const f = t.current;
2769
+ if (!f) throw new Error("SDK not ready");
2770
+ return await f.cancelBulkTranslation(h), !0;
2771
2771
  },
2772
2772
  clearMessages() {
2773
2773
  r((h) => ({ ...h, messages: [] }));
2774
2774
  }
2775
2775
  }),
2776
2776
  [o]
2777
- ), l = U(
2777
+ ), l = M(
2778
2778
  () => ({
2779
2779
  ...i,
2780
2780
  ...a
@@ -2783,120 +2783,141 @@ function Kt({ config: n, children: e }) {
2783
2783
  );
2784
2784
  return /* @__PURE__ */ d(Oe.Provider, { value: l, children: e });
2785
2785
  }
2786
- function qt() {
2786
+ function Mt() {
2787
2787
  const n = Ie(Oe);
2788
2788
  if (!n) throw new Error("useChat must be used within ChatProvider");
2789
2789
  return n;
2790
2790
  }
2791
- function Ut() {
2792
- return qt();
2791
+ function Vt() {
2792
+ return Mt();
2793
2793
  }
2794
- function $t({ title: n = "AI Assistance", placeholder: e = "Ask anything...", height: t = "500px" }) {
2795
- const { messages: s, connection: i, submitInstruction: r, isSubmitting: o } = Ut(), [a, l] = Z(""), [h, p] = Z(null), g = G(null), _ = !i.connected || o, w = U(
2796
- () => [...s].sort((c, f) => c.timestamp.getTime() - f.timestamp.getTime()),
2797
- [s]
2798
- );
2799
- me(() => {
2800
- g.current && (g.current.scrollTop = g.current.scrollHeight);
2801
- }, [w]);
2802
- const B = async (c) => {
2803
- c.preventDefault();
2804
- const f = a.trim();
2805
- f && (await r(f), l(""), p(null));
2806
- }, Y = (c, f = 40) => c.length > f ? `${c.slice(0, f)}...` : c, z = () => {
2807
- p(null);
2808
- };
2809
- return /* @__PURE__ */ y("div", { className: "chat-sdk", style: { height: t }, children: [
2810
- /* @__PURE__ */ y("div", { className: "chat-sdk__header", children: [
2811
- /* @__PURE__ */ d("div", { className: "chat-sdk__title", children: n }),
2812
- /* @__PURE__ */ y("div", { className: "chat-sdk__status", children: [
2813
- /* @__PURE__ */ d("span", { className: `chat-sdk__status-dot ${i.connected ? "connected" : "disconnected"}` }),
2814
- i.connected ? "Connected" : i.connecting ? "Connecting..." : "Disconnected"
2815
- ] })
2816
- ] }),
2817
- /* @__PURE__ */ d("div", { className: "chat-sdk__messages", ref: g, children: w.length === 0 ? /* @__PURE__ */ d("div", { className: "chat-sdk__empty", children: "Welcome! Ask anything about the translation." }) : w.map((c) => /* @__PURE__ */ d(Mt, { message: c }, c.id)) }),
2818
- /* @__PURE__ */ y("div", { className: "chat-sdk__composer", children: [
2819
- /* @__PURE__ */ y("div", { className: "chat-sdk__input-bar", children: [
2820
- h && /* @__PURE__ */ d("div", { className: "chat-sdk__input-context", children: /* @__PURE__ */ y("div", { className: "chat-sdk__context-chip", children: [
2821
- /* @__PURE__ */ d("span", { className: "chat-sdk__context-text", children: Y(h) }),
2822
- /* @__PURE__ */ d(
2823
- "button",
2824
- {
2825
- type: "button",
2826
- className: "chat-sdk__context-remove",
2827
- onClick: z,
2828
- "aria-label": "Remove context",
2829
- children: /* @__PURE__ */ d("svg", { width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", children: /* @__PURE__ */ d("path", { d: "M1 1L9 9M9 1L1 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) })
2830
- }
2831
- )
2832
- ] }) }),
2833
- /* @__PURE__ */ y("form", { className: "chat-sdk__form", onSubmit: B, children: [
2834
- /* @__PURE__ */ d("div", { className: "chat-sdk__input-wrapper", children: /* @__PURE__ */ d(
2835
- "textarea",
2836
- {
2837
- className: "chat-sdk__input",
2838
- placeholder: e,
2839
- value: a,
2840
- onChange: (c) => l(c.target.value),
2841
- disabled: _,
2842
- rows: 1
2843
- }
2844
- ) }),
2845
- /* @__PURE__ */ y("div", { className: "chat-sdk__actions", children: [
2846
- /* @__PURE__ */ d("button", { type: "button", className: "chat-sdk__add-btn", "aria-label": "Add context", children: /* @__PURE__ */ d("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ d("path", { d: "M8 3V13M3 8H13", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }) }),
2794
+ const Ft = qe(
2795
+ ({ title: n = "AI Assistance", placeholder: e = "Ask anything...", height: t = "500px" }, s) => {
2796
+ const { messages: i, connection: r, submitInstructionWithContext: o, isSubmitting: a } = Vt(), [l, h] = Z(""), [f, m] = Z(null), y = W(null), b = W(null), O = !r.connected || a, L = M(
2797
+ () => [...i].sort((p, _) => p.timestamp.getTime() - _.timestamp.getTime()),
2798
+ [i]
2799
+ );
2800
+ me(() => {
2801
+ y.current && (y.current.scrollTop = y.current.scrollHeight);
2802
+ }, [L]), Ue(s, () => ({
2803
+ focus: () => {
2804
+ var p;
2805
+ (p = b.current) == null || p.focus();
2806
+ },
2807
+ setContext: (p) => {
2808
+ m(p), p && setTimeout(() => {
2809
+ var _;
2810
+ return (_ = b.current) == null ? void 0 : _.focus();
2811
+ }, 0);
2812
+ },
2813
+ clearContext: () => {
2814
+ m(null);
2815
+ }
2816
+ }), []);
2817
+ const J = async (p) => {
2818
+ p.preventDefault();
2819
+ const _ = l.trim();
2820
+ _ && (f ? await o(_, f.context) : await o(_, {
2821
+ trans_doc_id: "",
2822
+ page_num: 0
2823
+ }), h(""), m(null));
2824
+ }, c = (p, _ = 40) => p.length > _ ? `${p.slice(0, _)}...` : p, g = () => {
2825
+ m(null);
2826
+ };
2827
+ return /* @__PURE__ */ k("div", { className: "chat-sdk", style: { height: t }, children: [
2828
+ /* @__PURE__ */ k("div", { className: "chat-sdk__header", children: [
2829
+ /* @__PURE__ */ d("div", { className: "chat-sdk__title", children: n }),
2830
+ /* @__PURE__ */ k("div", { className: "chat-sdk__status", children: [
2831
+ /* @__PURE__ */ d("span", { className: `chat-sdk__status-dot ${r.connected ? "connected" : "disconnected"}` }),
2832
+ r.connected ? "Connected" : r.connecting ? "Connecting..." : "Disconnected"
2833
+ ] })
2834
+ ] }),
2835
+ /* @__PURE__ */ d("div", { className: "chat-sdk__messages", ref: y, children: L.length === 0 ? /* @__PURE__ */ d("div", { className: "chat-sdk__empty", children: "Welcome! Ask anything about the translation." }) : L.map((p) => /* @__PURE__ */ d(Ht, { message: p }, p.id)) }),
2836
+ /* @__PURE__ */ k("div", { className: "chat-sdk__composer", children: [
2837
+ /* @__PURE__ */ k("div", { className: "chat-sdk__input-bar", children: [
2838
+ f && /* @__PURE__ */ d("div", { className: "chat-sdk__input-context", children: /* @__PURE__ */ k("div", { className: "chat-sdk__context-chip", children: [
2839
+ /* @__PURE__ */ d("span", { className: "chat-sdk__context-text", children: c(f.text) }),
2847
2840
  /* @__PURE__ */ d(
2848
2841
  "button",
2849
2842
  {
2850
- className: "chat-sdk__send",
2851
- type: "submit",
2852
- disabled: !a.trim() || _,
2853
- "aria-label": "Send message",
2854
- children: /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ d("path", { d: "M7 12V2M7 2L3 6M7 2L11 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
2843
+ type: "button",
2844
+ className: "chat-sdk__context-remove",
2845
+ onClick: g,
2846
+ "aria-label": "Remove context",
2847
+ children: /* @__PURE__ */ d("svg", { width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", children: /* @__PURE__ */ d("path", { d: "M1 1L9 9M9 1L1 9", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) })
2855
2848
  }
2856
2849
  )
2850
+ ] }) }),
2851
+ /* @__PURE__ */ k("form", { className: "chat-sdk__form", onSubmit: J, children: [
2852
+ /* @__PURE__ */ d("div", { className: "chat-sdk__input-wrapper", children: /* @__PURE__ */ d(
2853
+ "textarea",
2854
+ {
2855
+ ref: b,
2856
+ className: "chat-sdk__input",
2857
+ placeholder: e,
2858
+ value: l,
2859
+ onChange: (p) => h(p.target.value),
2860
+ disabled: O,
2861
+ rows: 1
2862
+ }
2863
+ ) }),
2864
+ /* @__PURE__ */ k("div", { className: "chat-sdk__actions", children: [
2865
+ /* @__PURE__ */ d("button", { type: "button", className: "chat-sdk__add-btn", "aria-label": "Add context", children: /* @__PURE__ */ d("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ d("path", { d: "M8 3V13M3 8H13", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }) }),
2866
+ /* @__PURE__ */ d(
2867
+ "button",
2868
+ {
2869
+ className: "chat-sdk__send",
2870
+ type: "submit",
2871
+ disabled: !l.trim() || O,
2872
+ "aria-label": "Send message",
2873
+ children: /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ d("path", { d: "M7 12V2M7 2L3 6M7 2L11 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
2874
+ }
2875
+ )
2876
+ ] })
2857
2877
  ] })
2878
+ ] }),
2879
+ r.error && /* @__PURE__ */ k("div", { className: "chat-sdk__error", children: [
2880
+ "⚠️ ",
2881
+ r.error
2858
2882
  ] })
2859
- ] }),
2860
- i.error && /* @__PURE__ */ y("div", { className: "chat-sdk__error", children: [
2861
- "⚠️ ",
2862
- i.error
2863
2883
  ] })
2864
- ] })
2865
- ] });
2866
- }
2867
- function Mt({ message: n }) {
2884
+ ] });
2885
+ }
2886
+ );
2887
+ Ft.displayName = "ChatWidget";
2888
+ function Ht({ message: n }) {
2868
2889
  var r;
2869
2890
  const e = n.type === "user", t = n.type === "loading", s = n.type === "ai-patch", i = (o, a = 40) => o.length > a ? `${o.slice(0, a)}...` : o;
2870
- return e ? /* @__PURE__ */ y("div", { className: "chat-sdk__user-container", children: [
2891
+ return e ? /* @__PURE__ */ k("div", { className: "chat-sdk__user-container", children: [
2871
2892
  n.contextText && /* @__PURE__ */ d("div", { className: "chat-sdk__user-context", children: /* @__PURE__ */ d("div", { className: "chat-sdk__context-chip chat-sdk__context-chip--display", children: /* @__PURE__ */ d("span", { className: "chat-sdk__context-text", children: i(n.contextText) }) }) }),
2872
2893
  /* @__PURE__ */ d("div", { className: "chat-sdk__bubble user", children: /* @__PURE__ */ d("div", { className: "chat-sdk__bubble-body", children: n.content }) })
2873
- ] }) : /* @__PURE__ */ d("div", { className: "chat-sdk__ai-container", children: /* @__PURE__ */ d("div", { className: "chat-sdk__ai-response", children: s && ((r = n.patchData) != null && r.originalText) ? /* @__PURE__ */ y("div", { className: "chat-sdk__patch", children: [
2894
+ ] }) : /* @__PURE__ */ d("div", { className: "chat-sdk__ai-container", children: /* @__PURE__ */ d("div", { className: "chat-sdk__ai-response", children: s && ((r = n.patchData) != null && r.originalText) ? /* @__PURE__ */ k("div", { className: "chat-sdk__patch", children: [
2874
2895
  /* @__PURE__ */ d("div", { className: "chat-sdk__ai-title", children: "I have a suggestion for you." }),
2875
- /* @__PURE__ */ y("div", { className: "chat-sdk__patch-content", children: [
2896
+ /* @__PURE__ */ k("div", { className: "chat-sdk__patch-content", children: [
2876
2897
  /* @__PURE__ */ d("div", { className: "chat-sdk__patch-label", children: "Original" }),
2877
2898
  /* @__PURE__ */ d("div", { className: "chat-sdk__patch-block", children: n.patchData.originalText }),
2878
2899
  /* @__PURE__ */ d("div", { className: "chat-sdk__patch-label", children: "Improved" }),
2879
- /* @__PURE__ */ y("div", { className: "chat-sdk__patch-block", children: [
2900
+ /* @__PURE__ */ k("div", { className: "chat-sdk__patch-block", children: [
2880
2901
  n.patchData.improvedText,
2881
- n.isStreaming && /* @__PURE__ */ d(j, {})
2902
+ n.isStreaming && /* @__PURE__ */ d(G, {})
2882
2903
  ] })
2883
2904
  ] })
2884
- ] }) : /* @__PURE__ */ d(Pe, { children: n.content && /* @__PURE__ */ y("div", { className: "chat-sdk__ai-body", children: [
2905
+ ] }) : /* @__PURE__ */ d(Pe, { children: n.content && /* @__PURE__ */ k("div", { className: "chat-sdk__ai-body", children: [
2885
2906
  n.content,
2886
- t && /* @__PURE__ */ d(j, {}),
2887
- n.isStreaming && !t && /* @__PURE__ */ d(j, {})
2907
+ t && /* @__PURE__ */ d(G, {}),
2908
+ n.isStreaming && !t && /* @__PURE__ */ d(G, {})
2888
2909
  ] }) }) }) });
2889
2910
  }
2890
- function j() {
2891
- return /* @__PURE__ */ y("span", { className: "chat-sdk__stream", children: [
2911
+ function G() {
2912
+ return /* @__PURE__ */ k("span", { className: "chat-sdk__stream", children: [
2892
2913
  /* @__PURE__ */ d("span", {}),
2893
2914
  /* @__PURE__ */ d("span", {}),
2894
2915
  /* @__PURE__ */ d("span", {})
2895
2916
  ] });
2896
2917
  }
2897
2918
  export {
2898
- Kt as ChatProvider,
2899
- $t as ChatWidget,
2900
- Ut as useChat
2919
+ Yt as ChatProvider,
2920
+ Ft as ChatWidget,
2921
+ Vt as useChat
2901
2922
  };
2902
2923
  //# sourceMappingURL=translation-chat-sdk.es.js.map