@onedeskpro/chatbot-core 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15,10 +15,21 @@ function a(e) {
15
15
  let t = e;
16
16
  return typeof t.type == "string" && typeof t.url == "string" && typeof t.fileName == "string" && typeof t.size == "number";
17
17
  }
18
- function o(e) {
18
+ var o = [
19
+ "ai",
20
+ "waiting",
21
+ "human",
22
+ "closed"
23
+ ];
24
+ function s(e) {
25
+ if (typeof e != "object" || !e) return !1;
26
+ let t = e;
27
+ return typeof t.mode == "string" && o.includes(t.mode) && (t.conversationId === void 0 || typeof t.conversationId == "string") && (t.agentName === void 0 || typeof t.agentName == "string");
28
+ }
29
+ function c(e) {
19
30
  return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && i(e.apiError);
20
31
  }
21
- var s = class {
32
+ var l = class {
22
33
  constructor(e) {
23
34
  this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4, this.uploadTimeoutMs = e.uploadTimeoutMs ?? r;
24
35
  }
@@ -91,33 +102,43 @@ var s = class {
91
102
  async requestHuman(e) {
92
103
  return this.request("POST", "/sdk/human-request", { visitorToken: e });
93
104
  }
105
+ async cancelHumanRequest(e) {
106
+ return this.postTicketAction("/sdk/human-request/cancel", e);
107
+ }
108
+ async closeConversation(e) {
109
+ return this.postTicketAction("/sdk/conversation/close", e);
110
+ }
111
+ async postTicketAction(e, t) {
112
+ let n = await this.request("POST", e, { visitorToken: t });
113
+ return s(n) || this.fail("The server returned an unexpected ticket status.", 200, "BAD_RESPONSE", e), n;
114
+ }
94
115
  async fetchTicketStatus(e) {
95
116
  return this.request("GET", "/sdk/ticket-status", void 0, void 0, { "X-Visitor-Token": e });
96
117
  }
97
- }, c = "https://api.onedeskpro.com", l = 10485760, u = 10;
118
+ }, u = "https://api.onedeskpro.com", d = 10485760, f = 10;
98
119
  // src/attachments.ts
99
- function d(e) {
120
+ function p(e) {
100
121
  if (e.length > 10) return "You can send up to 10 files at a time.";
101
- let t = e.find((e) => e.size > l);
122
+ let t = e.find((e) => e.size > d);
102
123
  if (t) {
103
- let e = Math.round(l / 1048576);
124
+ let e = Math.round(d / 1048576);
104
125
  return `"${t.name || "This file"}" is larger than ${e} MB.`;
105
126
  }
106
127
  return null;
107
128
  }
108
- function f(e) {
129
+ function m(e) {
109
130
  return /^(https?:\/\/|blob:)/i.test(e);
110
131
  }
111
- function p(e) {
132
+ function h(e) {
112
133
  return typeof URL > "u" || typeof URL.createObjectURL != "function" ? "" : URL.createObjectURL(e);
113
134
  }
114
- function m(e) {
135
+ function g(e) {
115
136
  e.startsWith("blob:") && typeof URL < "u" && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
116
137
  }
117
138
  function ee(e) {
118
139
  return {
119
140
  type: e.type || "application/octet-stream",
120
- url: p(e),
141
+ url: h(e),
121
142
  fileName: e.name || "attachment",
122
143
  size: e.size
123
144
  };
@@ -153,14 +174,14 @@ function re(e, t) {
153
174
  ].includes(n) : !0;
154
175
  }
155
176
  // src/audio.ts
156
- var h = 16e3;
157
- function g(e) {
177
+ var _ = 16e3;
178
+ function v(e) {
158
179
  return (e ?? "").split(";")[0].trim().toLowerCase() || "audio/webm";
159
180
  }
160
181
  function ie(e) {
161
182
  return e.includes("mpeg") || e.includes("mp3") ? "mp3" : e.includes("wav") ? "wav" : e.includes("mp4") || e.includes("m4a") ? "m4a" : e.includes("ogg") ? "ogg" : "webm";
162
183
  }
163
- function _(e) {
184
+ function y(e) {
164
185
  if (!Number.isFinite(e) || e < 0) return "0:00";
165
186
  let t = Math.floor(e), n = Math.floor(t / 60), r = t % 60;
166
187
  return `${n}:${String(r).padStart(2, "0")}`;
@@ -191,10 +212,10 @@ async function se(e) {
191
212
  async function ce(e) {
192
213
  let t = oe();
193
214
  if (t) try {
194
- let n = new t(1, Math.max(1, Math.ceil(e.duration * h)), h), r = n.createBufferSource();
215
+ let n = new t(1, Math.max(1, Math.ceil(e.duration * _)), _), r = n.createBufferSource();
195
216
  return r.buffer = e, r.connect(n.destination), r.start(0), {
196
217
  samples: (await n.startRendering()).getChannelData(0),
197
- sampleRate: h
218
+ sampleRate: _
198
219
  };
199
220
  } catch {}
200
221
  return {
@@ -229,7 +250,7 @@ function ue(e, t = 48) {
229
250
  return r.map((e) => i > 0 ? Math.max(8, Math.min(100, Math.round(e / i * 100))) : 8);
230
251
  }
231
252
  async function de(e) {
232
- let t = Date.now(), n = Math.max(1, Math.round(e.durationSeconds || 1)), r = g(e.mimeType ?? e.blob.type), i = await se(e.blob);
253
+ let t = Date.now(), n = Math.max(1, Math.round(e.durationSeconds || 1)), r = v(e.mimeType ?? e.blob.type), i = await se(e.blob);
233
254
  if (!i) return {
234
255
  file: new File([e.blob], `voice-message-${t}.${ie(r)}`, { type: r }),
235
256
  durationSeconds: n
@@ -260,81 +281,81 @@ var fe = class {
260
281
  removeAllListeners() {
261
282
  for (let e of Object.keys(this._listeners)) delete this._listeners[e];
262
283
  }
263
- }, v = Object.create(null);
264
- v.open = "0", v.close = "1", v.ping = "2", v.pong = "3", v.message = "4", v.upgrade = "5", v.noop = "6";
265
- var y = Object.create(null);
266
- Object.keys(v).forEach((e) => {
267
- y[v[e]] = e;
284
+ }, b = Object.create(null);
285
+ b.open = "0", b.close = "1", b.ping = "2", b.pong = "3", b.message = "4", b.upgrade = "5", b.noop = "6";
286
+ var x = Object.create(null);
287
+ Object.keys(b).forEach((e) => {
288
+ x[b[e]] = e;
268
289
  });
269
- var b = {
290
+ var pe = {
270
291
  type: "error",
271
292
  data: "parser error"
272
- }, pe = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", me = typeof ArrayBuffer == "function", he = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, x = ({ type: e, data: t }, n, r) => pe && t instanceof Blob ? n ? r(t) : ge(t, r) : me && (t instanceof ArrayBuffer || he(t)) ? n ? r(t) : ge(new Blob([t]), r) : r(v[e] + (t || "")), ge = (e, t) => {
293
+ }, me = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", he = typeof ArrayBuffer == "function", ge = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, S = ({ type: e, data: t }, n, r) => me && t instanceof Blob ? n ? r(t) : _e(t, r) : he && (t instanceof ArrayBuffer || ge(t)) ? n ? r(t) : _e(new Blob([t]), r) : r(b[e] + (t || "")), _e = (e, t) => {
273
294
  let n = new FileReader();
274
295
  return n.onload = function() {
275
296
  let e = n.result.split(",")[1];
276
297
  t("b" + (e || ""));
277
298
  }, n.readAsDataURL(e);
278
299
  };
279
- function _e(e) {
300
+ function ve(e) {
280
301
  return e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
281
302
  }
282
- var ve;
283
- function ye(e, t) {
284
- if (pe && e.data instanceof Blob) return e.data.arrayBuffer().then(_e).then(t);
285
- if (me && (e.data instanceof ArrayBuffer || he(e.data))) return t(_e(e.data));
286
- x(e, !1, (e) => {
287
- ve ||= new TextEncoder(), t(ve.encode(e));
303
+ var ye;
304
+ function be(e, t) {
305
+ if (me && e.data instanceof Blob) return e.data.arrayBuffer().then(ve).then(t);
306
+ if (he && (e.data instanceof ArrayBuffer || ge(e.data))) return t(ve(e.data));
307
+ S(e, !1, (e) => {
308
+ ye ||= new TextEncoder(), t(ye.encode(e));
288
309
  });
289
310
  }
290
311
  // ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
291
- var be = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", S = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
292
- for (let e = 0; e < 64; e++) S[be.charCodeAt(e)] = e;
293
- var xe = (e) => {
312
+ var xe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", C = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
313
+ for (let e = 0; e < 64; e++) C[xe.charCodeAt(e)] = e;
314
+ var Se = (e) => {
294
315
  let t = e.length * .75, n = e.length, r, i = 0, a, o, s, c;
295
316
  e[e.length - 1] === "=" && (t--, e[e.length - 2] === "=" && t--);
296
317
  let l = new ArrayBuffer(t), u = new Uint8Array(l);
297
- for (r = 0; r < n; r += 4) a = S[e.charCodeAt(r)], o = S[e.charCodeAt(r + 1)], s = S[e.charCodeAt(r + 2)], c = S[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
318
+ for (r = 0; r < n; r += 4) a = C[e.charCodeAt(r)], o = C[e.charCodeAt(r + 1)], s = C[e.charCodeAt(r + 2)], c = C[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
298
319
  return l;
299
- }, Se = typeof ArrayBuffer == "function", C = (e, t) => {
320
+ }, Ce = typeof ArrayBuffer == "function", w = (e, t) => {
300
321
  if (typeof e != "string") return {
301
322
  type: "message",
302
- data: we(e, t)
323
+ data: Te(e, t)
303
324
  };
304
325
  let n = e.charAt(0);
305
326
  return n === "b" ? {
306
327
  type: "message",
307
- data: Ce(e.substring(1), t)
308
- } : y[n] ? e.length > 1 ? {
309
- type: y[n],
328
+ data: we(e.substring(1), t)
329
+ } : x[n] ? e.length > 1 ? {
330
+ type: x[n],
310
331
  data: e.substring(1)
311
- } : { type: y[n] } : b;
312
- }, Ce = (e, t) => Se ? we(xe(e), t) : {
332
+ } : { type: x[n] } : pe;
333
+ }, we = (e, t) => Ce ? Te(Se(e), t) : {
313
334
  base64: !0,
314
335
  data: e
315
- }, we = (e, t) => {
336
+ }, Te = (e, t) => {
316
337
  switch (t) {
317
338
  case "blob": return e instanceof Blob ? e : new Blob([e]);
318
339
  default: return e instanceof ArrayBuffer ? e : e.buffer;
319
340
  }
320
- }, Te = "", Ee = (e, t) => {
341
+ }, Ee = "", De = (e, t) => {
321
342
  let n = e.length, r = Array(n), i = 0;
322
343
  e.forEach((e, a) => {
323
- x(e, !1, (e) => {
324
- r[a] = e, ++i === n && t(r.join(Te));
344
+ S(e, !1, (e) => {
345
+ r[a] = e, ++i === n && t(r.join(Ee));
325
346
  });
326
347
  });
327
- }, De = (e, t) => {
328
- let n = e.split(Te), r = [];
348
+ }, Oe = (e, t) => {
349
+ let n = e.split(Ee), r = [];
329
350
  for (let e = 0; e < n.length; e++) {
330
- let i = C(n[e], t);
351
+ let i = w(n[e], t);
331
352
  if (r.push(i), i.type === "error") break;
332
353
  }
333
354
  return r;
334
355
  };
335
- function Oe() {
356
+ function ke() {
336
357
  return new TransformStream({ transform(e, t) {
337
- ye(e, (n) => {
358
+ be(e, (n) => {
338
359
  let r = n.length, i;
339
360
  if (r < 126) i = /* @__PURE__ */ new Uint8Array(1), new DataView(i.buffer).setUint8(0, r);
340
361
  else if (r < 65536) {
@@ -350,65 +371,65 @@ function Oe() {
350
371
  });
351
372
  } });
352
373
  }
353
- var ke;
354
- function w(e) {
374
+ var Ae;
375
+ function T(e) {
355
376
  return e.reduce((e, t) => e + t.length, 0);
356
377
  }
357
- function T(e, t) {
378
+ function E(e, t) {
358
379
  if (e[0].length === t) return e.shift();
359
380
  let n = new Uint8Array(t), r = 0;
360
381
  for (let i = 0; i < t; i++) n[i] = e[0][r++], r === e[0].length && (e.shift(), r = 0);
361
382
  return e.length && r < e[0].length && (e[0] = e[0].slice(r)), n;
362
383
  }
363
- function Ae(e, t) {
364
- ke ||= new TextDecoder();
384
+ function je(e, t) {
385
+ Ae ||= new TextDecoder();
365
386
  let n = [], r = 0, i = -1, a = !1;
366
387
  return new TransformStream({ transform(o, s) {
367
388
  for (n.push(o);;) {
368
389
  if (r === 0) {
369
- if (w(n) < 1) break;
370
- let e = T(n, 1);
390
+ if (T(n) < 1) break;
391
+ let e = E(n, 1);
371
392
  a = (e[0] & 128) == 128, i = e[0] & 127, r = i < 126 ? 3 : i === 126 ? 1 : 2;
372
393
  } else if (r === 1) {
373
- if (w(n) < 2) break;
374
- let e = T(n, 2);
394
+ if (T(n) < 2) break;
395
+ let e = E(n, 2);
375
396
  i = new DataView(e.buffer, e.byteOffset, e.length).getUint16(0), r = 3;
376
397
  } else if (r === 2) {
377
- if (w(n) < 8) break;
378
- let e = T(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
398
+ if (T(n) < 8) break;
399
+ let e = E(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
379
400
  if (a > 2 ** 21 - 1) {
380
- s.enqueue(b);
401
+ s.enqueue(pe);
381
402
  break;
382
403
  }
383
404
  i = a * 2 ** 32 + t.getUint32(4), r = 3;
384
405
  } else {
385
- if (w(n) < i) break;
386
- let e = T(n, i);
387
- s.enqueue(C(a ? e : ke.decode(e), t)), r = 0;
406
+ if (T(n) < i) break;
407
+ let e = E(n, i);
408
+ s.enqueue(w(a ? e : Ae.decode(e), t)), r = 0;
388
409
  }
389
410
  if (i === 0 || i > e) {
390
- s.enqueue(b);
411
+ s.enqueue(pe);
391
412
  break;
392
413
  }
393
414
  }
394
415
  } });
395
416
  }
396
417
  // ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
397
- function E(e) {
398
- if (e) return je(e);
418
+ function D(e) {
419
+ if (e) return Me(e);
399
420
  }
400
- function je(e) {
401
- for (var t in E.prototype) e[t] = E.prototype[t];
421
+ function Me(e) {
422
+ for (var t in D.prototype) e[t] = D.prototype[t];
402
423
  return e;
403
424
  }
404
- E.prototype.on = E.prototype.addEventListener = function(e, t) {
425
+ D.prototype.on = D.prototype.addEventListener = function(e, t) {
405
426
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + e] = this._callbacks["$" + e] || []).push(t), this;
406
- }, E.prototype.once = function(e, t) {
427
+ }, D.prototype.once = function(e, t) {
407
428
  function n() {
408
429
  this.off(e, n), t.apply(this, arguments);
409
430
  }
410
431
  return n.fn = t, this.on(e, n), this;
411
- }, E.prototype.off = E.prototype.removeListener = E.prototype.removeAllListeners = E.prototype.removeEventListener = function(e, t) {
432
+ }, D.prototype.off = D.prototype.removeListener = D.prototype.removeAllListeners = D.prototype.removeEventListener = function(e, t) {
412
433
  if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
413
434
  var n = this._callbacks["$" + e];
414
435
  if (!n) return this;
@@ -418,7 +439,7 @@ E.prototype.on = E.prototype.addEventListener = function(e, t) {
418
439
  break;
419
440
  }
420
441
  return n.length === 0 && delete this._callbacks["$" + e], this;
421
- }, E.prototype.emit = function(e) {
442
+ }, D.prototype.emit = function(e) {
422
443
  this._callbacks = this._callbacks || {};
423
444
  for (var t = Array(arguments.length - 1), n = this._callbacks["$" + e], r = 1; r < arguments.length; r++) t[r - 1] = arguments[r];
424
445
  if (n) {
@@ -426,40 +447,40 @@ E.prototype.on = E.prototype.addEventListener = function(e, t) {
426
447
  for (var r = 0, i = n.length; r < i; ++r) n[r].apply(this, t);
427
448
  }
428
449
  return this;
429
- }, E.prototype.emitReserved = E.prototype.emit, E.prototype.listeners = function(e) {
450
+ }, D.prototype.emitReserved = D.prototype.emit, D.prototype.listeners = function(e) {
430
451
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + e] || [];
431
- }, E.prototype.hasListeners = function(e) {
452
+ }, D.prototype.hasListeners = function(e) {
432
453
  return !!this.listeners(e).length;
433
454
  };
434
455
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
435
- var D = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), O = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Me = "arraybuffer";
456
+ var O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), k = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ne = "arraybuffer";
436
457
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
437
- function Ne(e, ...t) {
458
+ function Pe(e, ...t) {
438
459
  return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
439
460
  }
440
- var Pe = O.setTimeout, Fe = O.clearTimeout;
441
- function k(e, t) {
442
- t.useNativeTimers ? (e.setTimeoutFn = Pe.bind(O), e.clearTimeoutFn = Fe.bind(O)) : (e.setTimeoutFn = O.setTimeout.bind(O), e.clearTimeoutFn = O.clearTimeout.bind(O));
443
- }
444
- var Ie = 1.33;
445
- function Le(e) {
446
- return typeof e == "string" ? Re(e) : Math.ceil((e.byteLength || e.size) * Ie);
461
+ var Fe = k.setTimeout, Ie = k.clearTimeout;
462
+ function A(e, t) {
463
+ t.useNativeTimers ? (e.setTimeoutFn = Fe.bind(k), e.clearTimeoutFn = Ie.bind(k)) : (e.setTimeoutFn = k.setTimeout.bind(k), e.clearTimeoutFn = k.clearTimeout.bind(k));
447
464
  }
465
+ var Le = 1.33;
448
466
  function Re(e) {
467
+ return typeof e == "string" ? ze(e) : Math.ceil((e.byteLength || e.size) * Le);
468
+ }
469
+ function ze(e) {
449
470
  let t = 0, n = 0;
450
471
  for (let r = 0, i = e.length; r < i; r++) t = e.charCodeAt(r), t < 128 ? n += 1 : t < 2048 ? n += 2 : t < 55296 || t >= 57344 ? n += 3 : (r++, n += 4);
451
472
  return n;
452
473
  }
453
- function ze() {
474
+ function Be() {
454
475
  return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
455
476
  }
456
477
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
457
- function Be(e) {
478
+ function Ve(e) {
458
479
  let t = "";
459
480
  for (let n in e) e.hasOwnProperty(n) && (t.length && (t += "&"), t += encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
460
481
  return t;
461
482
  }
462
- function Ve(e) {
483
+ function He(e) {
463
484
  let t = {}, n = e.split("&");
464
485
  for (let e = 0, r = n.length; e < r; e++) {
465
486
  let r = n[e].split("=");
@@ -468,16 +489,16 @@ function Ve(e) {
468
489
  return t;
469
490
  }
470
491
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
471
- var He = class extends Error {
492
+ var Ue = class extends Error {
472
493
  constructor(e, t, n) {
473
494
  super(e), this.description = t, this.context = n, this.type = "TransportError";
474
495
  }
475
- }, A = class extends E {
496
+ }, j = class extends D {
476
497
  constructor(e) {
477
- super(), this.writable = !1, k(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
498
+ super(), this.writable = !1, A(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
478
499
  }
479
500
  onError(e, t, n) {
480
- return super.emitReserved("error", new He(e, t, n)), this;
501
+ return super.emitReserved("error", new Ue(e, t, n)), this;
481
502
  }
482
503
  open() {
483
504
  return this.readyState = "opening", this.doOpen(), this;
@@ -492,7 +513,7 @@ var He = class extends Error {
492
513
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
493
514
  }
494
515
  onData(e) {
495
- let t = C(e, this.socket.binaryType);
516
+ let t = w(e, this.socket.binaryType);
496
517
  this.onPacket(t);
497
518
  }
498
519
  onPacket(e) {
@@ -513,10 +534,10 @@ var He = class extends Error {
513
534
  return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
514
535
  }
515
536
  _query(e) {
516
- let t = Be(e);
537
+ let t = Ve(e);
517
538
  return t.length ? "?" + t : "";
518
539
  }
519
- }, Ue = class extends A {
540
+ }, We = class extends j {
520
541
  constructor() {
521
542
  super(...arguments), this._polling = !1;
522
543
  }
@@ -544,7 +565,7 @@ var He = class extends Error {
544
565
  this._polling = !0, this.doPoll(), this.emitReserved("poll");
545
566
  }
546
567
  onData(e) {
547
- De(e, this.socket.binaryType).forEach((e) => {
568
+ Oe(e, this.socket.binaryType).forEach((e) => {
548
569
  if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
549
570
  this.onPacket(e);
550
571
  }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
@@ -556,7 +577,7 @@ var He = class extends Error {
556
577
  this.readyState === "open" ? e() : this.once("open", e);
557
578
  }
558
579
  write(e) {
559
- this.writable = !1, Ee(e, (e) => {
580
+ this.writable = !1, De(e, (e) => {
560
581
  this.doWrite(e, () => {
561
582
  this.writable = !0, this.emitReserved("drain");
562
583
  });
@@ -564,16 +585,16 @@ var He = class extends Error {
564
585
  }
565
586
  uri() {
566
587
  let e = this.opts.secure ? "https" : "http", t = this.query || {};
567
- return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
588
+ return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = Be()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
568
589
  }
569
- }, We = !1;
590
+ }, Ge = !1;
570
591
  try {
571
- We = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
592
+ Ge = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
572
593
  } catch {}
573
- var Ge = We;
594
+ var Ke = Ge;
574
595
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
575
- function Ke() {}
576
- var qe = class extends Ue {
596
+ function qe() {}
597
+ var Je = class extends We {
577
598
  constructor(e) {
578
599
  if (super(e), typeof location < "u") {
579
600
  let t = location.protocol === "https:", n = location.port;
@@ -595,13 +616,13 @@ var qe = class extends Ue {
595
616
  this.onError("xhr poll error", e, t);
596
617
  }), this.pollXhr = e;
597
618
  }
598
- }, j = class e extends E {
619
+ }, M = class e extends D {
599
620
  constructor(e, t, n) {
600
- super(), this.createRequest = e, k(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data === void 0 ? null : n.data, this._create();
621
+ super(), this.createRequest = e, A(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data === void 0 ? null : n.data, this._create();
601
622
  }
602
623
  _create() {
603
624
  var t;
604
- let n = Ne(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
625
+ let n = Pe(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
605
626
  n.xdomain = !!this._opts.xd;
606
627
  let r = this._xhr = this.createRequest(n);
607
628
  try {
@@ -637,7 +658,7 @@ var qe = class extends Ue {
637
658
  }
638
659
  _cleanup(t) {
639
660
  if (this._xhr !== void 0 && this._xhr !== null) {
640
- if (this._xhr.onreadystatechange = Ke, t) try {
661
+ if (this._xhr.onreadystatechange = qe, t) try {
641
662
  this._xhr.abort();
642
663
  } catch {}
643
664
  typeof document < "u" && delete e.requests[this._index], this._xhr = null;
@@ -651,45 +672,45 @@ var qe = class extends Ue {
651
672
  this._cleanup();
652
673
  }
653
674
  };
654
- if (j.requestsCount = 0, j.requests = {}, typeof document < "u") {
655
- if (typeof attachEvent == "function") attachEvent("onunload", Je);
675
+ if (M.requestsCount = 0, M.requests = {}, typeof document < "u") {
676
+ if (typeof attachEvent == "function") attachEvent("onunload", Ye);
656
677
  else if (typeof addEventListener == "function") {
657
- let e = "onpagehide" in O ? "pagehide" : "unload";
658
- addEventListener(e, Je, !1);
678
+ let e = "onpagehide" in k ? "pagehide" : "unload";
679
+ addEventListener(e, Ye, !1);
659
680
  }
660
681
  }
661
- function Je() {
662
- for (let e in j.requests) j.requests.hasOwnProperty(e) && j.requests[e].abort();
682
+ function Ye() {
683
+ for (let e in M.requests) M.requests.hasOwnProperty(e) && M.requests[e].abort();
663
684
  }
664
- var Ye = (function() {
665
- let e = Ze({ xdomain: !1 });
685
+ var Xe = (function() {
686
+ let e = Qe({ xdomain: !1 });
666
687
  return e && e.responseType !== null;
667
- })(), Xe = class extends qe {
688
+ })(), Ze = class extends Je {
668
689
  constructor(e) {
669
690
  super(e);
670
691
  let t = e && e.forceBase64;
671
- this.supportsBinary = Ye && !t;
692
+ this.supportsBinary = Xe && !t;
672
693
  }
673
694
  request(e = {}) {
674
- return Object.assign(e, { xd: this.xd }, this.opts), new j(Ze, this.uri(), e);
695
+ return Object.assign(e, { xd: this.xd }, this.opts), new M(Qe, this.uri(), e);
675
696
  }
676
697
  };
677
- function Ze(e) {
698
+ function Qe(e) {
678
699
  let t = e.xdomain;
679
700
  try {
680
- if (typeof XMLHttpRequest < "u" && (!t || Ge)) return new XMLHttpRequest();
701
+ if (typeof XMLHttpRequest < "u" && (!t || Ke)) return new XMLHttpRequest();
681
702
  } catch {}
682
703
  if (!t) try {
683
- return new O.ActiveXObject("Microsoft.XMLHTTP");
704
+ return new k.ActiveXObject("Microsoft.XMLHTTP");
684
705
  } catch {}
685
706
  }
686
707
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
687
- var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", $e = class extends A {
708
+ var $e = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", et = class extends j {
688
709
  get name() {
689
710
  return "websocket";
690
711
  }
691
712
  doOpen() {
692
- let e = this.uri(), t = this.opts.protocols, n = Qe ? {} : Ne(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
713
+ let e = this.uri(), t = this.opts.protocols, n = $e ? {} : Pe(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
693
714
  this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
694
715
  try {
695
716
  this.ws = this.createSocket(e, t, n);
@@ -710,11 +731,11 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
710
731
  this.writable = !1;
711
732
  for (let t = 0; t < e.length; t++) {
712
733
  let n = e[t], r = t === e.length - 1;
713
- x(n, this.supportsBinary, (e) => {
734
+ S(n, this.supportsBinary, (e) => {
714
735
  try {
715
736
  this.doWrite(n, e);
716
737
  } catch {}
717
- r && D(() => {
738
+ r && O(() => {
718
739
  this.writable = !0, this.emitReserved("drain");
719
740
  }, this.setTimeoutFn);
720
741
  });
@@ -725,18 +746,18 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
725
746
  }
726
747
  uri() {
727
748
  let e = this.opts.secure ? "wss" : "ws", t = this.query || {};
728
- return this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
749
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = Be()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
729
750
  }
730
- }, M = O.WebSocket || O.MozWebSocket, et = {
731
- websocket: class extends $e {
751
+ }, N = k.WebSocket || k.MozWebSocket, tt = {
752
+ websocket: class extends et {
732
753
  createSocket(e, t, n) {
733
- return Qe ? new M(e, t, n) : t ? new M(e, t) : new M(e);
754
+ return $e ? new N(e, t, n) : t ? new N(e, t) : new N(e);
734
755
  }
735
756
  doWrite(e, t) {
736
757
  this.ws.send(t);
737
758
  }
738
759
  },
739
- webtransport: class extends A {
760
+ webtransport: class extends j {
740
761
  get name() {
741
762
  return "webtransport";
742
763
  }
@@ -752,7 +773,7 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
752
773
  this.onError("webtransport error", e);
753
774
  }), this._transport.ready.then(() => {
754
775
  this._transport.createBidirectionalStream().then((e) => {
755
- let t = Ae(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = Oe();
776
+ let t = je(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = ke();
756
777
  r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
757
778
  let i = () => {
758
779
  n.read().then(({ done: e, value: t }) => {
@@ -770,7 +791,7 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
770
791
  for (let t = 0; t < e.length; t++) {
771
792
  let n = e[t], r = t === e.length - 1;
772
793
  this._writer.write(n).then(() => {
773
- r && D(() => {
794
+ r && O(() => {
774
795
  this.writable = !0, this.emitReserved("drain");
775
796
  }, this.setTimeoutFn);
776
797
  });
@@ -781,8 +802,8 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
781
802
  (e = this._transport) == null || e.close();
782
803
  }
783
804
  },
784
- polling: Xe
785
- }, tt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, nt = [
805
+ polling: Ze
806
+ }, nt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, rt = [
786
807
  "source",
787
808
  "protocol",
788
809
  "authority",
@@ -798,36 +819,36 @@ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navig
798
819
  "query",
799
820
  "anchor"
800
821
  ];
801
- function N(e) {
822
+ function P(e) {
802
823
  if (e.length > 8e3) throw "URI too long";
803
824
  let t = e, n = e.indexOf("["), r = e.indexOf("]");
804
825
  n != -1 && r != -1 && (e = e.substring(0, n) + e.substring(n, r).replace(/:/g, ";") + e.substring(r, e.length));
805
- let i = tt.exec(e || ""), a = {}, o = 14;
806
- for (; o--;) a[nt[o]] = i[o] || "";
807
- return n != -1 && r != -1 && (a.source = t, a.host = a.host.substring(1, a.host.length - 1).replace(/;/g, ":"), a.authority = a.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), a.ipv6uri = !0), a.pathNames = rt(a, a.path), a.queryKey = it(a, a.query), a;
826
+ let i = nt.exec(e || ""), a = {}, o = 14;
827
+ for (; o--;) a[rt[o]] = i[o] || "";
828
+ return n != -1 && r != -1 && (a.source = t, a.host = a.host.substring(1, a.host.length - 1).replace(/;/g, ":"), a.authority = a.authority.replace("[", "").replace("]", "").replace(/;/g, ":"), a.ipv6uri = !0), a.pathNames = it(a, a.path), a.queryKey = at(a, a.query), a;
808
829
  }
809
- function rt(e, t) {
830
+ function it(e, t) {
810
831
  let n = t.replace(/\/{2,9}/g, "/").split("/");
811
832
  return (t.slice(0, 1) == "/" || t.length === 0) && n.splice(0, 1), t.slice(-1) == "/" && n.splice(n.length - 1, 1), n;
812
833
  }
813
- function it(e, t) {
834
+ function at(e, t) {
814
835
  let n = {};
815
836
  return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(e, t, r) {
816
837
  t && (n[t] = r);
817
838
  }), n;
818
839
  }
819
840
  // ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
820
- var P = typeof addEventListener == "function" && typeof removeEventListener == "function", F = [];
821
- P && addEventListener("offline", () => {
822
- F.forEach((e) => e());
841
+ var F = typeof addEventListener == "function" && typeof removeEventListener == "function", I = [];
842
+ F && addEventListener("offline", () => {
843
+ I.forEach((e) => e());
823
844
  }, !1);
824
- var I = class e extends E {
845
+ var L = class e extends D {
825
846
  constructor(e, t) {
826
- if (super(), this.binaryType = Me, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = Infinity, e && typeof e == "object" && (t = e, e = null), e) {
827
- let n = N(e);
847
+ if (super(), this.binaryType = Ne, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = Infinity, e && typeof e == "object" && (t = e, e = null), e) {
848
+ let n = P(e);
828
849
  t.hostname = n.host, t.secure = n.protocol === "https" || n.protocol === "wss", t.port = n.port, n.query && (t.query = n.query);
829
- } else t.host && (t.hostname = N(t.host).host);
830
- k(this, t), this.secure = t.secure == null ? typeof location < "u" && location.protocol === "https:" : t.secure, 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((e) => {
850
+ } else t.host && (t.hostname = P(t.host).host);
851
+ A(this, t), this.secure = t.secure == null ? typeof location < "u" && location.protocol === "https:" : t.secure, 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((e) => {
831
852
  let t = e.prototype.name;
832
853
  this.transports.push(t), this._transportsByName[t] = e;
833
854
  }), this.opts = Object.assign({
@@ -842,11 +863,11 @@ var I = class e extends E {
842
863
  perMessageDeflate: { threshold: 1024 },
843
864
  transportOptions: {},
844
865
  closeOnBeforeunload: !1
845
- }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Ve(this.opts.query)), P && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
866
+ }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = He(this.opts.query)), F && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
846
867
  this.transport && (this.transport.removeAllListeners(), this.transport.close());
847
868
  }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
848
869
  this._onClose("transport close", { description: "network connection lost" });
849
- }, F.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
870
+ }, I.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
850
871
  }
851
872
  createTransport(e) {
852
873
  let t = Object.assign({}, this.opts.query);
@@ -917,7 +938,7 @@ var I = class e extends E {
917
938
  let e = 1;
918
939
  for (let t = 0; t < this.writeBuffer.length; t++) {
919
940
  let n = this.writeBuffer[t].data;
920
- if (n && (e += Le(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
941
+ if (n && (e += Re(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
921
942
  e += 2;
922
943
  }
923
944
  return this.writeBuffer;
@@ -925,7 +946,7 @@ var I = class e extends E {
925
946
  _hasPingExpired() {
926
947
  if (!this._pingTimeoutTime) return !0;
927
948
  let e = Date.now() > this._pingTimeoutTime;
928
- return e && (this._pingTimeoutTime = 0, D(() => {
949
+ return e && (this._pingTimeoutTime = 0, O(() => {
929
950
  this._onClose("ping timeout");
930
951
  }, this.setTimeoutFn)), e;
931
952
  }
@@ -963,16 +984,16 @@ var I = class e extends E {
963
984
  }
964
985
  _onClose(e, t) {
965
986
  if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
966
- if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), P && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
967
- let e = F.indexOf(this._offlineEventListener);
968
- e !== -1 && F.splice(e, 1);
987
+ if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), F && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
988
+ let e = I.indexOf(this._offlineEventListener);
989
+ e !== -1 && I.splice(e, 1);
969
990
  }
970
991
  this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
971
992
  }
972
993
  }
973
994
  };
974
- I.protocol = 4;
975
- var at = class extends I {
995
+ L.protocol = 4;
996
+ var ot = class extends L {
976
997
  constructor() {
977
998
  super(...arguments), this._upgrades = [];
978
999
  }
@@ -981,7 +1002,7 @@ var at = class extends I {
981
1002
  }
982
1003
  _probe(e) {
983
1004
  let t = this.createTransport(e), n = !1;
984
- I.priorWebsocketSuccess = !1;
1005
+ L.priorWebsocketSuccess = !1;
985
1006
  let r = () => {
986
1007
  n || (t.send([{
987
1008
  type: "ping",
@@ -990,7 +1011,7 @@ var at = class extends I {
990
1011
  if (!n) {
991
1012
  if (e.type === "pong" && e.data === "probe") {
992
1013
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) return;
993
- I.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1014
+ L.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
994
1015
  n || this.readyState !== "closed" && (l(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
995
1016
  });
996
1017
  } else {
@@ -1031,51 +1052,51 @@ var at = class extends I {
1031
1052
  for (let n = 0; n < e.length; n++) ~this.transports.indexOf(e[n]) && t.push(e[n]);
1032
1053
  return t;
1033
1054
  }
1034
- }, ot = class extends at {
1055
+ }, st = class extends ot {
1035
1056
  constructor(e, t = {}) {
1036
1057
  let n = typeof e == "object", r = n ? { ...e } : { ...t };
1037
1058
  (!r.transports || r.transports && typeof r.transports[0] == "string") && (r.transports = (r.transports || [
1038
1059
  "polling",
1039
1060
  "websocket",
1040
1061
  "webtransport"
1041
- ]).map((e) => et[e]).filter((e) => !!e)), super(n ? r : e, r);
1062
+ ]).map((e) => tt[e]).filter((e) => !!e)), super(n ? r : e, r);
1042
1063
  }
1043
1064
  };
1044
- ot.protocol;
1065
+ st.protocol;
1045
1066
  // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
1046
- function st(e, t = "", n) {
1067
+ function ct(e, t = "", n) {
1047
1068
  let r = e;
1048
- n ||= typeof location < "u" && location, e ??= n.protocol + "//" + n.host, typeof e == "string" && (e.charAt(0) === "/" && (e = e.charAt(1) === "/" ? n.protocol + e : n.host + e), /^(https?|wss?):\/\//.test(e) || (e = n === void 0 ? "https://" + e : n.protocol + "//" + e), r = N(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
1069
+ n ||= typeof location < "u" && location, e ??= n.protocol + "//" + n.host, typeof e == "string" && (e.charAt(0) === "/" && (e = e.charAt(1) === "/" ? n.protocol + e : n.host + e), /^(https?|wss?):\/\//.test(e) || (e = n === void 0 ? "https://" + e : n.protocol + "//" + e), r = P(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
1049
1070
  let i = r.host.indexOf(":") === -1 ? r.host : "[" + r.host + "]";
1050
1071
  return r.id = r.protocol + "://" + i + ":" + r.port + t, r.href = r.protocol + "://" + i + (n && n.port === r.port ? "" : ":" + r.port), r;
1051
1072
  }
1052
1073
  // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
1053
- var ct = typeof ArrayBuffer == "function", lt = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, ut = Object.prototype.toString, dt = typeof Blob == "function" || typeof Blob < "u" && ut.call(Blob) === "[object BlobConstructor]", ft = typeof File == "function" || typeof File < "u" && ut.call(File) === "[object FileConstructor]";
1054
- function L(e) {
1055
- return ct && (e instanceof ArrayBuffer || lt(e)) || dt && e instanceof Blob || ft && e instanceof File;
1074
+ var lt = typeof ArrayBuffer == "function", ut = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, dt = Object.prototype.toString, ft = typeof Blob == "function" || typeof Blob < "u" && dt.call(Blob) === "[object BlobConstructor]", pt = typeof File == "function" || typeof File < "u" && dt.call(File) === "[object FileConstructor]";
1075
+ function R(e) {
1076
+ return lt && (e instanceof ArrayBuffer || ut(e)) || ft && e instanceof Blob || pt && e instanceof File;
1056
1077
  }
1057
- function R(e, t) {
1078
+ function z(e, t) {
1058
1079
  if (!e || typeof e != "object") return !1;
1059
1080
  if (Array.isArray(e)) {
1060
- for (let t = 0, n = e.length; t < n; t++) if (R(e[t])) return !0;
1081
+ for (let t = 0, n = e.length; t < n; t++) if (z(e[t])) return !0;
1061
1082
  return !1;
1062
1083
  }
1063
- if (L(e)) return !0;
1064
- if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return R(e.toJSON(), !0);
1065
- for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && R(e[t])) return !0;
1084
+ if (R(e)) return !0;
1085
+ if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return z(e.toJSON(), !0);
1086
+ for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && z(e[t])) return !0;
1066
1087
  return !1;
1067
1088
  }
1068
1089
  // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
1069
- function pt(e) {
1090
+ function mt(e) {
1070
1091
  let t = [], n = e.data, r = e;
1071
- return r.data = z(n, t), r.attachments = t.length, {
1092
+ return r.data = B(n, t), r.attachments = t.length, {
1072
1093
  packet: r,
1073
1094
  buffers: t
1074
1095
  };
1075
1096
  }
1076
- function z(e, t, n) {
1097
+ function B(e, t, n) {
1077
1098
  if (!e) return e;
1078
- if (L(e)) {
1099
+ if (R(e)) {
1079
1100
  let n = {
1080
1101
  _placeholder: !0,
1081
1102
  num: t.length
@@ -1084,55 +1105,55 @@ function z(e, t, n) {
1084
1105
  }
1085
1106
  if (Array.isArray(e)) {
1086
1107
  let n = Array(e.length);
1087
- for (let r = 0; r < e.length; r++) n[r] = z(e[r], t);
1108
+ for (let r = 0; r < e.length; r++) n[r] = B(e[r], t);
1088
1109
  return n;
1089
1110
  }
1090
1111
  if (typeof e == "object" && !(e instanceof Date)) {
1091
- if (e.toJSON && typeof e.toJSON == "function" && !n) return z(e.toJSON(), t, !0);
1112
+ if (e.toJSON && typeof e.toJSON == "function" && !n) return B(e.toJSON(), t, !0);
1092
1113
  let r = {};
1093
- for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = z(e[n], t));
1114
+ for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = B(e[n], t));
1094
1115
  return r;
1095
1116
  }
1096
1117
  return e;
1097
1118
  }
1098
- function mt(e, t) {
1099
- return e.data = B(e.data, t), delete e.attachments, e;
1119
+ function ht(e, t) {
1120
+ return e.data = V(e.data, t), delete e.attachments, e;
1100
1121
  }
1101
- function B(e, t) {
1122
+ function V(e, t) {
1102
1123
  if (!e) return e;
1103
1124
  if (e && e._placeholder === !0) {
1104
1125
  if (typeof e.num == "number" && e.num >= 0 && e.num < t.length) return t[e.num];
1105
1126
  throw Error("illegal attachments");
1106
1127
  }
1107
- if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = B(e[n], t);
1108
- else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = B(e[n], t));
1128
+ if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = V(e[n], t);
1129
+ else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = V(e[n], t));
1109
1130
  return e;
1110
1131
  }
1111
1132
  // ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
1112
- var ht = /* @__PURE__ */ t({
1113
- Decoder: () => vt,
1114
- Encoder: () => _t,
1115
- PacketType: () => V,
1116
- isPacketValid: () => wt,
1133
+ var gt = /* @__PURE__ */ t({
1134
+ Decoder: () => yt,
1135
+ Encoder: () => vt,
1136
+ PacketType: () => H,
1137
+ isPacketValid: () => Tt,
1117
1138
  protocol: () => 5
1118
- }), gt = [
1139
+ }), _t = [
1119
1140
  "connect",
1120
1141
  "connect_error",
1121
1142
  "disconnect",
1122
1143
  "disconnecting",
1123
1144
  "newListener",
1124
1145
  "removeListener"
1125
- ], V;
1146
+ ], H;
1126
1147
  (function(e) {
1127
1148
  e[e.CONNECT = 0] = "CONNECT", e[e.DISCONNECT = 1] = "DISCONNECT", e[e.EVENT = 2] = "EVENT", e[e.ACK = 3] = "ACK", e[e.CONNECT_ERROR = 4] = "CONNECT_ERROR", e[e.BINARY_EVENT = 5] = "BINARY_EVENT", e[e.BINARY_ACK = 6] = "BINARY_ACK";
1128
- })(V ||= {});
1129
- var _t = class {
1149
+ })(H ||= {});
1150
+ var vt = class {
1130
1151
  constructor(e) {
1131
1152
  this.replacer = e;
1132
1153
  }
1133
1154
  encode(e) {
1134
- return (e.type === V.EVENT || e.type === V.ACK) && R(e) ? this.encodeAsBinary({
1135
- type: e.type === V.EVENT ? V.BINARY_EVENT : V.BINARY_ACK,
1155
+ return (e.type === H.EVENT || e.type === H.ACK) && z(e) ? this.encodeAsBinary({
1156
+ type: e.type === H.EVENT ? H.BINARY_EVENT : H.BINARY_ACK,
1136
1157
  nsp: e.nsp,
1137
1158
  data: e.data,
1138
1159
  id: e.id
@@ -1140,13 +1161,13 @@ var _t = class {
1140
1161
  }
1141
1162
  encodeAsString(e) {
1142
1163
  let t = "" + e.type;
1143
- return (e.type === V.BINARY_EVENT || e.type === V.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
1164
+ return (e.type === H.BINARY_EVENT || e.type === H.BINARY_ACK) && (t += e.attachments + "-"), e.nsp && e.nsp !== "/" && (t += e.nsp + ","), e.id != null && (t += e.id), e.data != null && (t += JSON.stringify(e.data, this.replacer)), t;
1144
1165
  }
1145
1166
  encodeAsBinary(e) {
1146
- let t = pt(e), n = this.encodeAsString(t.packet), r = t.buffers;
1167
+ let t = mt(e), n = this.encodeAsString(t.packet), r = t.buffers;
1147
1168
  return r.unshift(n), r;
1148
1169
  }
1149
- }, vt = class e extends E {
1170
+ }, yt = class e extends D {
1150
1171
  constructor(e) {
1151
1172
  super(), this.opts = Object.assign({
1152
1173
  reviver: void 0,
@@ -1158,23 +1179,23 @@ var _t = class {
1158
1179
  if (typeof e == "string") {
1159
1180
  if (this.reconstructor) throw Error("got plaintext data when reconstructing a packet");
1160
1181
  t = this.decodeString(e);
1161
- let n = t.type === V.BINARY_EVENT;
1162
- n || t.type === V.BINARY_ACK ? (t.type = n ? V.EVENT : V.ACK, this.reconstructor = new yt(t)) : super.emitReserved("decoded", t);
1163
- } else if (L(e) || e.base64) {
1182
+ let n = t.type === H.BINARY_EVENT;
1183
+ n || t.type === H.BINARY_ACK ? (t.type = n ? H.EVENT : H.ACK, this.reconstructor = new bt(t)) : super.emitReserved("decoded", t);
1184
+ } else if (R(e) || e.base64) {
1164
1185
  if (this.reconstructor) t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
1165
1186
  else throw Error("got binary data when not reconstructing a packet");
1166
1187
  } else throw Error("Unknown type: " + e);
1167
1188
  }
1168
1189
  decodeString(t) {
1169
1190
  let n = 0, r = { type: Number(t.charAt(0)) };
1170
- if (V[r.type] === void 0) throw Error("unknown packet type " + r.type);
1171
- if (r.type === V.BINARY_EVENT || r.type === V.BINARY_ACK) {
1191
+ if (H[r.type] === void 0) throw Error("unknown packet type " + r.type);
1192
+ if (r.type === H.BINARY_EVENT || r.type === H.BINARY_ACK) {
1172
1193
  let e = n + 1;
1173
1194
  for (; t.charAt(++n) !== "-" && n != t.length;);
1174
1195
  let i = t.substring(e, n);
1175
1196
  if (i != Number(i) || t.charAt(n) !== "-") throw Error("Illegal attachments");
1176
1197
  let a = Number(i);
1177
- if (!xt(a) || a < 1) throw Error("Illegal attachments");
1198
+ if (!St(a) || a < 1) throw Error("Illegal attachments");
1178
1199
  if (a > this.opts.maxAttachments) throw Error("too many attachments");
1179
1200
  r.attachments = a;
1180
1201
  }
@@ -1212,25 +1233,25 @@ var _t = class {
1212
1233
  }
1213
1234
  static isPayloadValid(e, t) {
1214
1235
  switch (e) {
1215
- case V.CONNECT: return H(t);
1216
- case V.DISCONNECT: return t === void 0;
1217
- case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1218
- case V.EVENT:
1219
- case V.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1220
- case V.ACK:
1221
- case V.BINARY_ACK: return Array.isArray(t);
1236
+ case H.CONNECT: return U(t);
1237
+ case H.DISCONNECT: return t === void 0;
1238
+ case H.CONNECT_ERROR: return typeof t == "string" || U(t);
1239
+ case H.EVENT:
1240
+ case H.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && _t.indexOf(t[0]) === -1);
1241
+ case H.ACK:
1242
+ case H.BINARY_ACK: return Array.isArray(t);
1222
1243
  }
1223
1244
  }
1224
1245
  destroy() {
1225
1246
  this.reconstructor &&= (this.reconstructor.finishedReconstruction(), null);
1226
1247
  }
1227
- }, yt = class {
1248
+ }, bt = class {
1228
1249
  constructor(e) {
1229
1250
  this.packet = e, this.buffers = [], this.reconPack = e;
1230
1251
  }
1231
1252
  takeBinaryData(e) {
1232
1253
  if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1233
- let e = mt(this.reconPack, this.buffers);
1254
+ let e = ht(this.reconPack, this.buffers);
1234
1255
  return this.finishedReconstruction(), e;
1235
1256
  }
1236
1257
  return null;
@@ -1239,46 +1260,46 @@ var _t = class {
1239
1260
  this.reconPack = null, this.buffers = [];
1240
1261
  }
1241
1262
  };
1242
- function bt(e) {
1263
+ function xt(e) {
1243
1264
  return typeof e == "string";
1244
1265
  }
1245
- var xt = Number.isInteger || function(e) {
1266
+ var St = Number.isInteger || function(e) {
1246
1267
  return typeof e == "number" && isFinite(e) && Math.floor(e) === e;
1247
1268
  };
1248
- function St(e) {
1249
- return e === void 0 || xt(e);
1269
+ function Ct(e) {
1270
+ return e === void 0 || St(e);
1250
1271
  }
1251
- function H(e) {
1272
+ function U(e) {
1252
1273
  return Object.prototype.toString.call(e) === "[object Object]";
1253
1274
  }
1254
- function Ct(e, t) {
1275
+ function wt(e, t) {
1255
1276
  switch (e) {
1256
- case V.CONNECT: return t === void 0 || H(t);
1257
- case V.DISCONNECT: return t === void 0;
1258
- case V.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1259
- case V.ACK: return Array.isArray(t);
1260
- case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1277
+ case H.CONNECT: return t === void 0 || U(t);
1278
+ case H.DISCONNECT: return t === void 0;
1279
+ case H.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && _t.indexOf(t[0]) === -1);
1280
+ case H.ACK: return Array.isArray(t);
1281
+ case H.CONNECT_ERROR: return typeof t == "string" || U(t);
1261
1282
  default: return !1;
1262
1283
  }
1263
1284
  }
1264
- function wt(e) {
1265
- return bt(e.nsp) && St(e.id) && Ct(e.type, e.data);
1285
+ function Tt(e) {
1286
+ return xt(e.nsp) && Ct(e.id) && wt(e.type, e.data);
1266
1287
  }
1267
1288
  // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
1268
- function U(e, t, n) {
1289
+ function W(e, t, n) {
1269
1290
  return e.on(t, n), function() {
1270
1291
  e.off(t, n);
1271
1292
  };
1272
1293
  }
1273
1294
  // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
1274
- var Tt = Object.freeze({
1295
+ var Et = Object.freeze({
1275
1296
  connect: 1,
1276
1297
  connect_error: 1,
1277
1298
  disconnect: 1,
1278
1299
  disconnecting: 1,
1279
1300
  newListener: 1,
1280
1301
  removeListener: 1
1281
- }), Et = class extends E {
1302
+ }), Dt = class extends D {
1282
1303
  constructor(e, t, n) {
1283
1304
  super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, n && n.auth && (this.auth = n.auth), this._opts = Object.assign({}, n), this.io._autoConnect && this.open();
1284
1305
  }
@@ -1289,10 +1310,10 @@ var Tt = Object.freeze({
1289
1310
  if (this.subs) return;
1290
1311
  let e = this.io;
1291
1312
  this.subs = [
1292
- U(e, "open", this.onopen.bind(this)),
1293
- U(e, "packet", this.onpacket.bind(this)),
1294
- U(e, "error", this.onerror.bind(this)),
1295
- U(e, "close", this.onclose.bind(this))
1313
+ W(e, "open", this.onopen.bind(this)),
1314
+ W(e, "packet", this.onpacket.bind(this)),
1315
+ W(e, "error", this.onerror.bind(this)),
1316
+ W(e, "close", this.onclose.bind(this))
1296
1317
  ];
1297
1318
  }
1298
1319
  get active() {
@@ -1308,10 +1329,10 @@ var Tt = Object.freeze({
1308
1329
  return e.unshift("message"), this.emit.apply(this, e), this;
1309
1330
  }
1310
1331
  emit(e, ...t) {
1311
- if (Tt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1332
+ if (Et.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1312
1333
  if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) return this._addToQueue(t), this;
1313
1334
  let n = {
1314
- type: V.EVENT,
1335
+ type: H.EVENT,
1315
1336
  data: t
1316
1337
  };
1317
1338
  if (n.options = {}, n.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
@@ -1369,7 +1390,7 @@ var Tt = Object.freeze({
1369
1390
  }
1370
1391
  _sendConnectPacket(e) {
1371
1392
  this.packet({
1372
- type: V.CONNECT,
1393
+ type: H.CONNECT,
1373
1394
  data: this._pid ? Object.assign({
1374
1395
  pid: this._pid,
1375
1396
  offset: this._lastOffset
@@ -1392,21 +1413,21 @@ var Tt = Object.freeze({
1392
1413
  }
1393
1414
  onpacket(e) {
1394
1415
  if (e.nsp === this.nsp) switch (e.type) {
1395
- case V.CONNECT:
1416
+ case H.CONNECT:
1396
1417
  e.data && e.data.sid ? this.onconnect(e.data.sid, e.data.pid) : this.emitReserved("connect_error", /* @__PURE__ */ Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
1397
1418
  break;
1398
- case V.EVENT:
1399
- case V.BINARY_EVENT:
1419
+ case H.EVENT:
1420
+ case H.BINARY_EVENT:
1400
1421
  this.onevent(e);
1401
1422
  break;
1402
- case V.ACK:
1403
- case V.BINARY_ACK:
1423
+ case H.ACK:
1424
+ case H.BINARY_ACK:
1404
1425
  this.onack(e);
1405
1426
  break;
1406
- case V.DISCONNECT:
1427
+ case H.DISCONNECT:
1407
1428
  this.ondisconnect();
1408
1429
  break;
1409
- case V.CONNECT_ERROR:
1430
+ case H.CONNECT_ERROR:
1410
1431
  this.destroy();
1411
1432
  let t = Error(e.data.message);
1412
1433
  t.data = e.data.data, this.emitReserved("connect_error", t);
@@ -1427,7 +1448,7 @@ var Tt = Object.freeze({
1427
1448
  let t = this, n = !1;
1428
1449
  return function(...r) {
1429
1450
  n || (n = !0, t.packet({
1430
- type: V.ACK,
1451
+ type: H.ACK,
1431
1452
  id: e,
1432
1453
  data: r
1433
1454
  }));
@@ -1452,7 +1473,7 @@ var Tt = Object.freeze({
1452
1473
  this.subs &&= (this.subs.forEach((e) => e()), void 0), this.io._destroy(this);
1453
1474
  }
1454
1475
  disconnect() {
1455
- return this.connected && this.packet({ type: V.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1476
+ return this.connected && this.packet({ type: H.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1456
1477
  }
1457
1478
  close() {
1458
1479
  return this.disconnect();
@@ -1508,34 +1529,34 @@ var Tt = Object.freeze({
1508
1529
  }
1509
1530
  };
1510
1531
  // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/contrib/backo2.js
1511
- function W(e) {
1532
+ function G(e) {
1512
1533
  e ||= {}, this.ms = e.min || 100, this.max = e.max || 1e4, this.factor = e.factor || 2, this.jitter = e.jitter > 0 && e.jitter <= 1 ? e.jitter : 0, this.attempts = 0;
1513
1534
  }
1514
- W.prototype.duration = function() {
1535
+ G.prototype.duration = function() {
1515
1536
  var e = this.ms * this.factor ** +this.attempts++;
1516
1537
  if (this.jitter) {
1517
1538
  var t = Math.random(), n = Math.floor(t * this.jitter * e);
1518
1539
  e = Math.floor(t * 10) & 1 ? e + n : e - n;
1519
1540
  }
1520
1541
  return Math.min(e, this.max) | 0;
1521
- }, W.prototype.reset = function() {
1542
+ }, G.prototype.reset = function() {
1522
1543
  this.attempts = 0;
1523
- }, W.prototype.setMin = function(e) {
1544
+ }, G.prototype.setMin = function(e) {
1524
1545
  this.ms = e;
1525
- }, W.prototype.setMax = function(e) {
1546
+ }, G.prototype.setMax = function(e) {
1526
1547
  this.max = e;
1527
- }, W.prototype.setJitter = function(e) {
1548
+ }, G.prototype.setJitter = function(e) {
1528
1549
  this.jitter = e;
1529
1550
  };
1530
1551
  // ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
1531
- var G = class extends E {
1552
+ var K = class extends D {
1532
1553
  constructor(e, t) {
1533
- super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, k(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || Infinity), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor(t.randomizationFactor ?? .5), this.backoff = new W({
1554
+ super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, A(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || Infinity), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor(t.randomizationFactor ?? .5), this.backoff = new G({
1534
1555
  min: this.reconnectionDelay(),
1535
1556
  max: this.reconnectionDelayMax(),
1536
1557
  jitter: this.randomizationFactor()
1537
1558
  }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
1538
- let n = t.parser || ht;
1559
+ let n = t.parser || gt;
1539
1560
  this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
1540
1561
  }
1541
1562
  reconnection(e) {
@@ -1564,14 +1585,14 @@ var G = class extends E {
1564
1585
  }
1565
1586
  open(e) {
1566
1587
  if (~this._readyState.indexOf("open")) return this;
1567
- this.engine = new ot(this.uri, this.opts);
1588
+ this.engine = new st(this.uri, this.opts);
1568
1589
  let t = this.engine, n = this;
1569
1590
  this._readyState = "opening", this.skipReconnect = !1;
1570
- let r = U(t, "open", function() {
1591
+ let r = W(t, "open", function() {
1571
1592
  n.onopen(), e && e();
1572
1593
  }), i = (t) => {
1573
1594
  this.cleanup(), this._readyState = "closed", this.emitReserved("error", t), e ? e(t) : this.maybeReconnectOnOpen();
1574
- }, a = U(t, "error", i);
1595
+ }, a = W(t, "error", i);
1575
1596
  if (!1 !== this._timeout) {
1576
1597
  let e = this._timeout, n = this.setTimeoutFn(() => {
1577
1598
  r(), i(/* @__PURE__ */ Error("timeout")), t.close();
@@ -1588,7 +1609,7 @@ var G = class extends E {
1588
1609
  onopen() {
1589
1610
  this.cleanup(), this._readyState = "open", this.emitReserved("open");
1590
1611
  let e = this.engine;
1591
- this.subs.push(U(e, "ping", this.onping.bind(this)), U(e, "data", this.ondata.bind(this)), U(e, "error", this.onerror.bind(this)), U(e, "close", this.onclose.bind(this)), U(this.decoder, "decoded", this.ondecoded.bind(this)));
1612
+ this.subs.push(W(e, "ping", this.onping.bind(this)), W(e, "data", this.ondata.bind(this)), W(e, "error", this.onerror.bind(this)), W(e, "close", this.onclose.bind(this)), W(this.decoder, "decoded", this.ondecoded.bind(this)));
1592
1613
  }
1593
1614
  onping() {
1594
1615
  this.emitReserved("ping");
@@ -1601,7 +1622,7 @@ var G = class extends E {
1601
1622
  }
1602
1623
  }
1603
1624
  ondecoded(e) {
1604
- D(() => {
1625
+ O(() => {
1605
1626
  this.emitReserved("packet", e);
1606
1627
  }, this.setTimeoutFn);
1607
1628
  }
@@ -1610,7 +1631,7 @@ var G = class extends E {
1610
1631
  }
1611
1632
  socket(e, t) {
1612
1633
  let n = this.nsps[e];
1613
- return n ? this._autoConnect && !n.active && n.connect() : (n = new Et(this, e, t), this.nsps[e] = n), n;
1634
+ return n ? this._autoConnect && !n.active && n.connect() : (n = new Dt(this, e, t), this.nsps[e] = n), n;
1614
1635
  }
1615
1636
  _destroy(e) {
1616
1637
  let t = Object.keys(this.nsps);
@@ -1655,20 +1676,20 @@ var G = class extends E {
1655
1676
  let e = this.backoff.attempts;
1656
1677
  this._reconnecting = !1, this.backoff.reset(), this.emitReserved("reconnect", e);
1657
1678
  }
1658
- }, K = {};
1659
- function q(e, t) {
1679
+ }, q = {};
1680
+ function J(e, t) {
1660
1681
  typeof e == "object" && (t = e, e = void 0), t ||= {};
1661
- let n = st(e, t.path || "/socket.io"), r = n.source, i = n.id, a = n.path, o = K[i] && a in K[i].nsps, s = t.forceNew || t["force new connection"] || !1 === t.multiplex || o, c;
1662
- return s ? c = new G(r, t) : (K[i] || (K[i] = new G(r, t)), c = K[i]), n.query && !t.query && (t.query = n.queryKey), c.socket(n.path, t);
1663
- }
1664
- Object.assign(q, {
1665
- Manager: G,
1666
- Socket: Et,
1667
- io: q,
1668
- connect: q
1682
+ let n = ct(e, t.path || "/socket.io"), r = n.source, i = n.id, a = n.path, o = q[i] && a in q[i].nsps, s = t.forceNew || t["force new connection"] || !1 === t.multiplex || o, c;
1683
+ return s ? c = new K(r, t) : (q[i] || (q[i] = new K(r, t)), c = q[i]), n.query && !t.query && (t.query = n.queryKey), c.socket(n.path, t);
1684
+ }
1685
+ Object.assign(J, {
1686
+ Manager: K,
1687
+ Socket: Dt,
1688
+ io: J,
1689
+ connect: J
1669
1690
  });
1670
1691
  // src/sdk-socket.ts
1671
- function Dt(e) {
1692
+ function Ot(e) {
1672
1693
  let t = e.replace(/\/$/, "");
1673
1694
  try {
1674
1695
  return `${new URL(t).origin}/sdk`;
@@ -1676,7 +1697,7 @@ function Dt(e) {
1676
1697
  return `${t}/sdk`;
1677
1698
  }
1678
1699
  }
1679
- var Ot = class {
1700
+ var kt = class {
1680
1701
  constructor() {
1681
1702
  this.socket = null;
1682
1703
  }
@@ -1685,8 +1706,8 @@ var Ot = class {
1685
1706
  }
1686
1707
  connect(e) {
1687
1708
  this.disconnect();
1688
- let t = Dt(e.baseUrl);
1689
- this.socket = q(t, {
1709
+ let t = Ot(e.baseUrl);
1710
+ this.socket = J(t, {
1690
1711
  auth: {
1691
1712
  apiKey: e.apiKey,
1692
1713
  visitorToken: e.visitorToken
@@ -1709,54 +1730,54 @@ var Ot = class {
1709
1730
  disconnect() {
1710
1731
  this.socket &&= (this.socket.removeAllListeners(), this.socket.disconnect(), null);
1711
1732
  }
1712
- }, J = "onedeskpro_visitor_token";
1713
- function kt(e) {
1733
+ }, Y = "onedeskpro_visitor_token";
1734
+ function At(e) {
1714
1735
  try {
1715
1736
  return typeof window < "u" ? window.localStorage.getItem(e) : null;
1716
1737
  } catch {
1717
1738
  return null;
1718
1739
  }
1719
1740
  }
1720
- function At(e, t) {
1741
+ function jt(e, t) {
1721
1742
  try {
1722
1743
  typeof window < "u" && window.localStorage.setItem(e, t);
1723
1744
  } catch {}
1724
1745
  }
1725
- function jt(e) {
1746
+ function Mt(e) {
1726
1747
  try {
1727
1748
  typeof window < "u" && window.localStorage.removeItem(e);
1728
1749
  } catch {}
1729
1750
  }
1730
- var Mt = class {
1751
+ var Nt = class {
1731
1752
  constructor() {
1732
- this.token = null, this.storageKey = J;
1753
+ this.token = null, this.storageKey = Y;
1733
1754
  }
1734
1755
  setScope(e) {
1735
- this.storageKey = e?.trim() ? `${J}:${e.trim()}` : J, this.token = kt(this.storageKey);
1756
+ this.storageKey = e?.trim() ? `${Y}:${e.trim()}` : Y, this.token = At(this.storageKey);
1736
1757
  }
1737
1758
  get() {
1738
- return this.token ?? kt(this.storageKey);
1759
+ return this.token ?? At(this.storageKey);
1739
1760
  }
1740
1761
  set(e) {
1741
- this.token = e, At(this.storageKey, e);
1762
+ this.token = e, jt(this.storageKey, e);
1742
1763
  }
1743
1764
  clear() {
1744
- this.token = null, jt(this.storageKey);
1765
+ this.token = null, Mt(this.storageKey);
1745
1766
  }
1746
- }, Nt = 300, Pt = 250, Ft = 100, It = [
1767
+ }, Pt = 300, Ft = 250, It = 100, Lt = [
1747
1768
  "audio/webm;codecs=opus",
1748
1769
  "audio/webm",
1749
1770
  "audio/mp4",
1750
1771
  "audio/ogg;codecs=opus"
1751
1772
  ];
1752
- function Lt() {
1753
- return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? "audio/webm" : It.find((e) => MediaRecorder.isTypeSupported(e)) ?? "audio/webm";
1773
+ function Rt() {
1774
+ return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? "audio/webm" : Lt.find((e) => MediaRecorder.isTypeSupported(e)) ?? "audio/webm";
1754
1775
  }
1755
- function Rt(e) {
1776
+ function zt(e) {
1756
1777
  let t = e instanceof DOMException ? e.name : "";
1757
1778
  return t === "NotAllowedError" || t === "PermissionDeniedError" || t === "SecurityError" ? "Microphone access was denied." : t === "NotFoundError" || t === "DevicesNotFoundError" ? "No microphone was found." : "Could not start recording.";
1758
1779
  }
1759
- var Y = class e {
1780
+ var Bt = class e {
1760
1781
  constructor(e, t = 300) {
1761
1782
  this.onChange = e, this.maxDurationSeconds = t, this.recorder = null, this.stream = null, this.chunks = [], this.mimeType = "audio/webm", this.startedAt = 0, this.tickTimer = null, this.levelTimer = null, this.maxTimer = null, this.audioContext = null, this.analyser = null, this.snapshot = {
1762
1783
  state: "idle",
@@ -1778,20 +1799,20 @@ var Y = class e {
1778
1799
  try {
1779
1800
  t = await navigator.mediaDevices.getUserMedia({ audio: !0 });
1780
1801
  } catch (e) {
1781
- throw Error(Rt(e));
1802
+ throw Error(zt(e));
1782
1803
  }
1783
1804
  try {
1784
- this.mimeType = Lt();
1805
+ this.mimeType = Rt();
1785
1806
  let e = new MediaRecorder(t, { mimeType: this.mimeType });
1786
1807
  e.ondataavailable = (e) => {
1787
1808
  e.data.size > 0 && this.chunks.push(e.data);
1788
1809
  }, this.stream = t, this.recorder = e, this.startedAt = Date.now(), e.start(200);
1789
1810
  } catch (e) {
1790
- throw t.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, Error(Rt(e));
1811
+ throw t.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, Error(zt(e));
1791
1812
  }
1792
1813
  this.startLevelMeter(t), this.tickTimer = setInterval(() => {
1793
1814
  this.update({ elapsedSeconds: Math.floor(this.elapsedMs() / 1e3) });
1794
- }, Pt), this.maxTimer = setTimeout(() => void this.stop(), this.maxDurationSeconds * 1e3), this.update({
1815
+ }, Ft), this.maxTimer = setTimeout(() => void this.stop(), this.maxDurationSeconds * 1e3), this.update({
1795
1816
  state: "recording",
1796
1817
  elapsedSeconds: 0,
1797
1818
  level: 0,
@@ -1806,18 +1827,18 @@ var Y = class e {
1806
1827
  let n = await new Promise((t) => {
1807
1828
  e.onstop = () => {
1808
1829
  let e = this.chunks;
1809
- this.chunks = [], t(new Blob(e, { type: g(this.mimeType) }));
1830
+ this.chunks = [], t(new Blob(e, { type: v(this.mimeType) }));
1810
1831
  };
1811
1832
  try {
1812
1833
  e.stop();
1813
1834
  } catch {
1814
- t(new Blob(this.chunks, { type: g(this.mimeType) }));
1835
+ t(new Blob(this.chunks, { type: v(this.mimeType) }));
1815
1836
  }
1816
1837
  });
1817
1838
  this.releaseMedia();
1818
1839
  let r = {
1819
1840
  blob: n,
1820
- mimeType: g(this.mimeType),
1841
+ mimeType: v(this.mimeType),
1821
1842
  durationSeconds: t
1822
1843
  };
1823
1844
  return this.update({
@@ -1866,7 +1887,7 @@ var Y = class e {
1866
1887
  e += n * n;
1867
1888
  }
1868
1889
  this.update({ level: Math.min(1, Math.sqrt(e / i.length) * 3.2) });
1869
- }, Ft);
1890
+ }, It);
1870
1891
  } catch {}
1871
1892
  }
1872
1893
  clearTimers() {
@@ -2251,8 +2272,8 @@ var Y = class e {
2251
2272
  dial: "977",
2252
2273
  flag: "🇳🇵"
2253
2274
  }
2254
- ], zt = X.find((e) => e.iso === "BD") ?? X[0];
2255
- function Bt(e, t) {
2275
+ ], Vt = X.find((e) => e.iso === "BD") ?? X[0];
2276
+ function Ht(e, t) {
2256
2277
  let n = t.trim();
2257
2278
  if (n.startsWith("+")) {
2258
2279
  let e = n.replace(/\D/g, "");
@@ -2262,8 +2283,8 @@ function Bt(e, t) {
2262
2283
  return !r || (r = r.replace(/^0+/, ""), !r) ? "" : `+${e}${r}`;
2263
2284
  }
2264
2285
  // src/widget/styles.ts
2265
- var Vt = "(max-width: 640px), (max-height: 500px) and (pointer: coarse)";
2266
- function Ht(e, t) {
2286
+ var Ut = "(max-width: 640px), (max-height: 500px) and (pointer: coarse)";
2287
+ function Wt(e, t) {
2267
2288
  let n = `
2268
2289
  --ttcb-bg: #ffffff;
2269
2290
  --ttcb-bg-secondary: #f3f4f6;
@@ -2428,7 +2449,8 @@ function Ht(e, t) {
2428
2449
  border-top: 1px solid var(--ttcb-border);
2429
2450
  flex-shrink: 0;
2430
2451
  }
2431
- .ttcb-mode-banner.visible { display: block; }
2452
+ .ttcb-mode-banner.visible { display: flex; align-items: center; gap: 8px; }
2453
+ .ttcb-mode-banner-text { flex: 1; min-width: 0; }
2432
2454
  .ttcb-mode-banner.waiting { color: var(--ttcb-text); }
2433
2455
  .ttcb-mode-banner.closed {
2434
2456
  color: var(--ttcb-text);
@@ -2436,6 +2458,37 @@ function Ht(e, t) {
2436
2458
  }
2437
2459
  .ttcb-mode-banner.human { color: var(--ttcb-text); }
2438
2460
 
2461
+ .ttcb-confirm-bar {
2462
+ display: none;
2463
+ padding: 10px 16px;
2464
+ font-size: 12px;
2465
+ line-height: 1.4;
2466
+ color: var(--ttcb-text);
2467
+ background: var(--ttcb-bg-secondary);
2468
+ border-top: 1px solid var(--ttcb-border);
2469
+ flex-shrink: 0;
2470
+ flex-wrap: wrap; align-items: center; gap: 8px;
2471
+ }
2472
+ .ttcb-confirm-bar.visible { display: flex; }
2473
+ .ttcb-confirm-text { flex: 1 1 160px; min-width: 0; }
2474
+ .ttcb-confirm-actions { display: flex; gap: 8px; flex-shrink: 0; }
2475
+ .ttcb-banner-btn {
2476
+ flex-shrink: 0;
2477
+ font: inherit; font-weight: 600;
2478
+ padding: 4px 10px; border-radius: 6px;
2479
+ border: 1px solid var(--ttcb-border);
2480
+ background: var(--ttcb-bg); color: var(--ttcb-text);
2481
+ cursor: pointer;
2482
+ }
2483
+ .ttcb-banner-btn:hover { background: var(--ttcb-bg-secondary); }
2484
+ .ttcb-banner-btn.primary { background: ${e}; border-color: ${e}; color: #fff; }
2485
+ .ttcb-banner-btn.primary:hover { opacity: 0.9; }
2486
+ .ttcb-banner-btn:focus-visible { outline: 2px solid ${e}; outline-offset: 2px; }
2487
+ .ttcb-banner-btn[aria-disabled="true"], .ttcb-new-session-btn[aria-disabled="true"] {
2488
+ opacity: 0.6; cursor: default;
2489
+ }
2490
+ .ttcb-banner-btn.hidden { display: none; }
2491
+
2439
2492
  .ttcb-messages {
2440
2493
  flex: 1; overflow-y: auto; padding: 16px;
2441
2494
  display: flex; flex-direction: column; gap: 12px;
@@ -2897,7 +2950,7 @@ function Ht(e, t) {
2897
2950
 
2898
2951
  .ttcb-footer.hidden, .ttcb-messages.hidden { display: none; }
2899
2952
 
2900
- @media ${Vt} {
2953
+ @media ${Ut} {
2901
2954
  .ttcb-fab.bottom-right { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2902
2955
  .ttcb-fab.bottom-left { left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2903
2956
  /* The open panel covers the launcher; its own close button takes over. */
@@ -2964,18 +3017,18 @@ function Ht(e, t) {
2964
3017
  `;
2965
3018
  }
2966
3019
  // src/widget/render.ts
2967
- function Ut(e) {
3020
+ function Gt(e) {
2968
3021
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2969
3022
  }
2970
- function Wt(e) {
3023
+ function Kt(e) {
2971
3024
  let t = [], n = e.replace(/```[\w]*\n?([\s\S]*?)```/g, (e, n) => {
2972
3025
  let r = t.length;
2973
- return t.push(`<pre><code>${Ut(n.trim())}</code></pre>`), `\x04${r}\x05`;
3026
+ return t.push(`<pre><code>${Gt(n.trim())}</code></pre>`), `\x04${r}\x05`;
2974
3027
  });
2975
3028
  n = n.replace(/`([^`\n]+)`/g, (e, n) => {
2976
3029
  let r = t.length;
2977
- return t.push(`<code>${Ut(n)}</code>`), `\x02${r}\x03`;
2978
- }), n = Ut(n);
3030
+ return t.push(`<code>${Gt(n)}</code>`), `\x02${r}\x03`;
3031
+ }), n = Gt(n);
2979
3032
  let r = n.split("\n"), i = [], a = "", o = () => {
2980
3033
  a &&= (i.push(`</${a}>`), "");
2981
3034
  };
@@ -2992,71 +3045,71 @@ function Wt(e) {
2992
3045
  }).join("") : "";
2993
3046
  }).filter(Boolean).join(""), n = n.replace(/\x04(\d+)\x05/g, (e, n) => t[+n] ?? "").replace(/\x02(\d+)\x03/g, (e, n) => t[+n] ?? ""), n;
2994
3047
  }
2995
- function Gt() {
3048
+ function qt() {
2996
3049
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/>\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"14\"/>\n <line x1=\"9\" y1=\"11\" x2=\"15\" y2=\"11\"/>\n </svg>";
2997
3050
  }
2998
- function Kt() {
3051
+ function Jt() {
2999
3052
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4C2.9 2 2 2.9 2 4v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z\"/>\n </svg>";
3000
3053
  }
3001
- function qt() {
3054
+ function Yt() {
3002
3055
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\"/>\n </svg>";
3003
3056
  }
3004
- function Jt() {
3057
+ function Xt() {
3005
3058
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n </svg>";
3006
3059
  }
3007
3060
  function Z() {
3008
3061
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3zm-2 10H6V7h12v12zm-9-6c-.83 0-1.5-.67-1.5-1.5S8.17 10 9 10s1.5.67 1.5 1.5S9.83 13 9 13zm6 0c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13z\"/>\n </svg>";
3009
3062
  }
3010
- function Yt() {
3063
+ function Zt() {
3011
3064
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z\"/>\n </svg>";
3012
3065
  }
3013
- function Xt() {
3066
+ function Qt() {
3014
3067
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2\"/>\n <circle cx=\"12\" cy=\"7\" r=\"4\"/>\n </svg>";
3015
3068
  }
3016
- function Zt() {
3069
+ function $t() {
3017
3070
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z\"/>\n <polyline points=\"22,6 12,13 2,6\"/>\n </svg>";
3018
3071
  }
3019
- function Qt() {
3072
+ function en() {
3020
3073
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <polyline points=\"6 9 12 15 18 9\"/>\n </svg>";
3021
3074
  }
3022
- function $t() {
3075
+ function tn() {
3023
3076
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>\n <polyline points=\"12 5 19 12 12 19\"/>\n </svg>";
3024
3077
  }
3025
- function en() {
3078
+ function nn() {
3026
3079
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z\"/>\n <polyline points=\"9 12 11 14 15 10\"/>\n </svg>";
3027
3080
  }
3028
- function tn() {
3081
+ function rn() {
3029
3082
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"currentColor\"/>\n <path d=\"M9 12l2 2 4-4\" fill=\"none\" stroke=\"#fff\" stroke-width=\"2.2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>";
3030
3083
  }
3031
- function nn() {
3084
+ function an() {
3032
3085
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path fill=\"#F59E0B\" d=\"M8 2.5l1.1 2.2 2.4.3-1.7 1.7.4 2.4L8 8l-2.2 1.1.4-2.4L4.5 5l2.4-.3L8 2.5z\"/>\n <path fill=\"#F59E0B\" d=\"M16 3.5l.8 1.6 1.8.2-1.3 1.3.3 1.8L16 7.5l-1.6.9.3-1.8-1.3-1.3 1.8-.2L16 3.5z\"/>\n <path fill=\"#FBBF24\" d=\"M12 11.5l1 2 2.2.3-1.6 1.6.4 2.2-2-1.1-2 1.1.4-2.2-1.6-1.6 2.2-.3 1-2z\"/>\n </svg>";
3033
3086
  }
3034
- function rn() {
3087
+ function on() {
3035
3088
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2\"/>\n <circle cx=\"9\" cy=\"7\" r=\"4\"/>\n <path d=\"M23 21v-2a4 4 0 0 0-3-3.87\"/>\n <path d=\"M16 3.13a4 4 0 0 1 0 7.75\"/>\n </svg>";
3036
3089
  }
3037
- function an() {
3090
+ function sn() {
3038
3091
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <line x1=\"12\" y1=\"5\" x2=\"12\" y2=\"19\"/>\n <line x1=\"5\" y1=\"12\" x2=\"19\" y2=\"12\"/>\n </svg>";
3039
3092
  }
3040
- function on() {
3093
+ function cn() {
3041
3094
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48\"/>\n </svg>";
3042
3095
  }
3043
- function sn() {
3096
+ function ln() {
3044
3097
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\" ry=\"2\"/>\n <circle cx=\"8.5\" cy=\"8.5\" r=\"1.5\"/>\n <polyline points=\"21 15 16 10 5 21\"/>\n </svg>";
3045
3098
  }
3046
- function cn() {
3099
+ function un() {
3047
3100
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z\"/>\n <path d=\"M19 10v2a7 7 0 0 1-14 0v-2\"/>\n <line x1=\"12\" y1=\"19\" x2=\"12\" y2=\"23\"/>\n <line x1=\"8\" y1=\"23\" x2=\"16\" y2=\"23\"/>\n </svg>";
3048
3101
  }
3049
- function ln() {
3102
+ function dn() {
3050
3103
  return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"2\" fill=\"currentColor\"/>\n </svg>";
3051
3104
  }
3052
- function un() {
3105
+ function fn() {
3053
3106
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <polyline points=\"3 6 5 6 21 6\"/>\n <path d=\"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6\"/>\n <path d=\"M10 11v6\"/>\n <path d=\"M14 11v6\"/>\n <path d=\"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2\"/>\n </svg>";
3054
3107
  }
3055
- function dn() {
3108
+ function pn() {
3056
3109
  return "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\"/>\n <polyline points=\"14 2 14 8 20 8\"/>\n </svg>";
3057
3110
  }
3058
- function fn(e) {
3059
- let t = f(e.url) ? e.url : "", n = e.type.toLowerCase();
3111
+ function mn(e) {
3112
+ let t = m(e.url) ? e.url : "", n = e.type.toLowerCase();
3060
3113
  if (t && n.startsWith("image/")) {
3061
3114
  let n = document.createElement("a");
3062
3115
  n.className = "ttcb-attachment ttcb-attachment-image", n.href = t, n.target = "_blank", n.rel = "noopener noreferrer", n.setAttribute("aria-label", `Open ${e.fileName}`);
@@ -3073,14 +3126,14 @@ function fn(e) {
3073
3126
  let r = document.createElement("audio");
3074
3127
  if (r.className = "ttcb-attachment-audio", r.controls = !0, r.preload = "metadata", r.src = t, r.setAttribute("aria-label", e.fileName), n.appendChild(r), typeof e.durationSeconds == "number" && e.durationSeconds > 0) {
3075
3128
  let t = document.createElement("span");
3076
- t.className = "ttcb-attachment-duration", t.textContent = _(e.durationSeconds), n.appendChild(t);
3129
+ t.className = "ttcb-attachment-duration", t.textContent = y(e.durationSeconds), n.appendChild(t);
3077
3130
  }
3078
3131
  return n;
3079
3132
  }
3080
3133
  let r = document.createElement(t ? "a" : "div");
3081
3134
  r.className = "ttcb-attachment ttcb-attachment-file", r instanceof HTMLAnchorElement && (r.href = t, r.target = "_blank", r.rel = "noopener noreferrer");
3082
3135
  let i = document.createElement("span");
3083
- i.className = "ttcb-attachment-icon", i.setAttribute("aria-hidden", "true"), i.innerHTML = dn();
3136
+ i.className = "ttcb-attachment-icon", i.setAttribute("aria-hidden", "true"), i.innerHTML = pn();
3084
3137
  let a = document.createElement("span");
3085
3138
  a.className = "ttcb-attachment-meta";
3086
3139
  let o = document.createElement("span");
@@ -3092,11 +3145,11 @@ function fn(e) {
3092
3145
  }
3093
3146
  return r.appendChild(i), r.appendChild(a), r;
3094
3147
  }
3095
- function pn(e) {
3148
+ function hn(e) {
3096
3149
  let { type: t, content: n } = e, r = e.attachments ?? [], i = document.createElement("div");
3097
3150
  i.className = `ttcb-msg ${t}`, e.pending && i.classList.add("ttcb-pending");
3098
3151
  let a = document.createElement("div");
3099
- a.className = "ttcb-msg-avatar", a.innerHTML = t === "human" ? Yt() : t === "agent" ? Xt() : Z();
3152
+ a.className = "ttcb-msg-avatar", a.innerHTML = t === "human" ? Zt() : t === "agent" ? Qt() : Z();
3100
3153
  let o = document.createElement("div");
3101
3154
  if (o.className = "ttcb-msg-body", t === "agent") {
3102
3155
  let e = document.createElement("span");
@@ -3105,12 +3158,12 @@ function pn(e) {
3105
3158
  if (r.length > 0) {
3106
3159
  let e = document.createElement("div");
3107
3160
  e.className = "ttcb-attachments";
3108
- for (let t of r) e.appendChild(fn(t));
3161
+ for (let t of r) e.appendChild(mn(t));
3109
3162
  o.appendChild(e);
3110
3163
  }
3111
3164
  if (r.length === 0 || !re(n, r)) {
3112
3165
  let e = document.createElement("div");
3113
- e.className = "ttcb-bubble", t === "human" ? e.textContent = n : e.innerHTML = Wt(n), o.appendChild(e);
3166
+ e.className = "ttcb-bubble", t === "human" ? e.textContent = n : e.innerHTML = Kt(n), o.appendChild(e);
3114
3167
  }
3115
3168
  if (e.pending) {
3116
3169
  let e = document.createElement("span");
@@ -3118,7 +3171,7 @@ function pn(e) {
3118
3171
  }
3119
3172
  return i.appendChild(a), i.appendChild(o), i;
3120
3173
  }
3121
- function mn() {
3174
+ function gn() {
3122
3175
  let e = document.createElement("div");
3123
3176
  e.className = "ttcb-msg ai", e.id = "ttcb-typing";
3124
3177
  let t = document.createElement("div");
@@ -3127,22 +3180,24 @@ function mn() {
3127
3180
  return n.className = "ttcb-typing", n.innerHTML = "<span></span><span></span><span></span>", e.appendChild(t), e.appendChild(n), e;
3128
3181
  }
3129
3182
  // src/widget/widget.ts
3130
- var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv", gn = "image/jpeg,image/png,image/gif", _n = class {
3183
+ var _n = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mpeg,audio/wav,audio/x-m4a,audio/aac,audio/opus,application/pdf,text/csv", vn = "image/jpeg,image/png,image/gif", yn = class {
3131
3184
  constructor(e, t) {
3132
- this.stopViewportSync = null, this.pendingFiles = [], this.attachMenuOpen = !1, this.recorder = null, this.voicePreviewUrl = "", this.selectedCountry = zt, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.autoOpen = e.autoOpen === !0, this.mount(e);
3185
+ this.stopViewportSync = null, this.confirmingNew = !1, this.actionPending = !1, this.ticketMode = "ai", this.pendingFiles = [], this.attachMenuOpen = !1, this.recorder = null, this.voicePreviewUrl = "", this.selectedCountry = Vt, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.autoOpen = e.autoOpen === !0, this.mount(e);
3133
3186
  }
3134
3187
  mount(e) {
3135
3188
  this.host = document.createElement("div"), this.host.id = "onedeskpro-chatbot-host", this.host.style.display = "none", this.shadow = this.host.attachShadow({ mode: "closed" });
3136
3189
  let t = document.createElement("style");
3137
- t.textContent = Ht(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t), this.fab = document.createElement("button"), this.fab.className = `ttcb-fab ${this.position}`, this.fab.setAttribute("aria-label", "Open chat"), this.fab.innerHTML = Kt(), this.fab.addEventListener("click", () => this.toggle()), this.shadow.appendChild(this.fab), this.panel = document.createElement("div"), this.panel.className = `ttcb-panel ${this.position} hidden ttcb-mode-compact`, this.panel.tabIndex = -1, this.panel.setAttribute("role", "dialog"), this.panel.setAttribute("aria-modal", "true"), this.panel.setAttribute("aria-label", e.chatbotName ?? "AI Assistant"), this.panel.appendChild(this.buildHeader(e)), this.identifyContainer = document.createElement("div"), this.identifyContainer.className = "ttcb-identify", this.buildIdentifyForm(this.identifyContainer), this.panel.appendChild(this.identifyContainer), this.messagesContainer = document.createElement("div"), this.messagesContainer.className = "ttcb-messages", this.messagesContainer.setAttribute("aria-live", "polite"), this.messagesContainer.setAttribute("aria-label", "Chat messages"), this.panel.appendChild(this.messagesContainer), this.modeBanner = document.createElement("div"), this.modeBanner.className = "ttcb-mode-banner", this.modeBanner.setAttribute("role", "status"), this.panel.appendChild(this.modeBanner), this.footer = document.createElement("div"), this.footer.className = "ttcb-footer", this.pendingTray = document.createElement("div"), this.pendingTray.className = "ttcb-pending-tray", this.pendingTray.setAttribute("role", "list"), this.pendingTray.setAttribute("aria-label", "Files to send"), this.footer.appendChild(this.pendingTray), this.composeError = document.createElement("p"), this.composeError.className = "ttcb-compose-error", this.composeError.setAttribute("role", "alert"), this.footer.appendChild(this.composeError), this.footer.appendChild(this.buildVoiceBar()), this.footer.appendChild(this.buildVoicePreview());
3190
+ t.textContent = Wt(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t), this.fab = document.createElement("button"), this.fab.className = `ttcb-fab ${this.position}`, this.fab.setAttribute("aria-label", "Open chat"), this.fab.innerHTML = Jt(), this.fab.addEventListener("click", () => this.toggle()), this.shadow.appendChild(this.fab), this.panel = document.createElement("div"), this.panel.className = `ttcb-panel ${this.position} hidden ttcb-mode-compact`, this.panel.tabIndex = -1, this.panel.setAttribute("role", "dialog"), this.panel.setAttribute("aria-modal", "true"), this.panel.setAttribute("aria-label", e.chatbotName ?? "AI Assistant"), this.panel.appendChild(this.buildHeader(e)), this.identifyContainer = document.createElement("div"), this.identifyContainer.className = "ttcb-identify", this.buildIdentifyForm(this.identifyContainer), this.panel.appendChild(this.identifyContainer), this.messagesContainer = document.createElement("div"), this.messagesContainer.className = "ttcb-messages", this.messagesContainer.setAttribute("aria-live", "polite"), this.messagesContainer.setAttribute("aria-label", "Chat messages"), this.panel.appendChild(this.messagesContainer), this.modeBanner = document.createElement("div"), this.modeBanner.className = "ttcb-mode-banner", this.modeBannerText = document.createElement("span"), this.modeBannerText.className = "ttcb-mode-banner-text", this.modeBannerText.setAttribute("role", "status"), this.cancelHumanBtn = this.buildBannerButton("Cancel request", () => {
3191
+ this.actionPending || this.callbacks.onCancelHumanRequest();
3192
+ }), this.cancelHumanBtn.classList.add("hidden"), this.modeBanner.appendChild(this.modeBannerText), this.modeBanner.appendChild(this.cancelHumanBtn), this.panel.appendChild(this.modeBanner), this.panel.appendChild(this.buildConfirmNewBar()), this.footer = document.createElement("div"), this.footer.className = "ttcb-footer", this.pendingTray = document.createElement("div"), this.pendingTray.className = "ttcb-pending-tray", this.pendingTray.setAttribute("role", "list"), this.pendingTray.setAttribute("aria-label", "Files to send"), this.footer.appendChild(this.pendingTray), this.composeError = document.createElement("p"), this.composeError.className = "ttcb-compose-error", this.composeError.setAttribute("role", "alert"), this.footer.appendChild(this.composeError), this.footer.appendChild(this.buildVoiceBar()), this.footer.appendChild(this.buildVoicePreview());
3138
3193
  let n = document.createElement("form");
3139
3194
  n.className = "ttcb-form", n.addEventListener("submit", (e) => {
3140
3195
  e.preventDefault(), this.handleSend();
3141
- }), this.composeForm = n, n.appendChild(this.buildAttachControls()), this.input = document.createElement("input"), this.input.type = "text", this.input.className = "ttcb-input", this.input.placeholder = e.placeholder ?? "Type your message…", this.input.setAttribute("aria-label", "Message input"), this.input.setAttribute("autocomplete", "off"), this.sendBtn = document.createElement("button"), this.sendBtn.type = "submit", this.sendBtn.className = "ttcb-send-btn", this.sendBtn.innerHTML = Jt(), this.sendBtn.setAttribute("aria-label", "Send message"), this.micBtn = document.createElement("button"), this.micBtn.type = "button", this.micBtn.className = "ttcb-mic-btn", this.micBtn.setAttribute("aria-label", "Record voice message"), this.micBtn.title = "Record voice message", this.micBtn.innerHTML = cn(), this.micBtn.addEventListener("click", () => void this.startVoice()), n.appendChild(this.input), n.appendChild(this.micBtn), n.appendChild(this.sendBtn), this.footer.appendChild(n), this.panel.appendChild(this.footer), this.shadow.appendChild(this.panel), this.shadow.addEventListener("click", (e) => {
3196
+ }), this.composeForm = n, n.appendChild(this.buildAttachControls()), this.input = document.createElement("input"), this.input.type = "text", this.input.className = "ttcb-input", this.input.placeholder = e.placeholder ?? "Type your message…", this.input.setAttribute("aria-label", "Message input"), this.input.setAttribute("autocomplete", "off"), this.sendBtn = document.createElement("button"), this.sendBtn.type = "submit", this.sendBtn.className = "ttcb-send-btn", this.sendBtn.innerHTML = Xt(), this.sendBtn.setAttribute("aria-label", "Send message"), this.micBtn = document.createElement("button"), this.micBtn.type = "button", this.micBtn.className = "ttcb-mic-btn", this.micBtn.setAttribute("aria-label", "Record voice message"), this.micBtn.title = "Record voice message", this.micBtn.innerHTML = un(), this.micBtn.addEventListener("click", () => void this.startVoice()), n.appendChild(this.input), n.appendChild(this.micBtn), n.appendChild(this.sendBtn), this.footer.appendChild(n), this.panel.appendChild(this.footer), this.shadow.appendChild(this.panel), this.shadow.addEventListener("click", (e) => {
3142
3197
  let t = e.target;
3143
3198
  this.attachMenuOpen && !(t && (this.attachBtn.contains(t) || this.attachMenu.contains(t))) && this.closeAttachMenu(), this.countryOpen && (t && (this.dialBtn.contains(t) || this.countryPopover.contains(t)) || this.closeCountryPopover());
3144
3199
  }), this.panel.addEventListener("keydown", (e) => {
3145
- e.key === "Escape" && this.attachMenuOpen && (e.stopPropagation(), this.closeAttachMenu(), this.attachBtn.focus());
3200
+ e.key === "Escape" && this.attachMenuOpen ? (e.stopPropagation(), this.closeAttachMenu(), this.attachBtn.focus()) : e.key === "Escape" && this.confirmingNew && (e.stopPropagation(), this.hideConfirmNew(), this.newSessionBtn.focus());
3146
3201
  }), this.attachToDocument(), this.showInitialLoading();
3147
3202
  }
3148
3203
  reveal() {
@@ -3160,7 +3215,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3160
3215
  let a = document.createElement("div");
3161
3216
  a.className = "ttcb-header-title-row", this.headerTitle = document.createElement("span"), this.headerTitle.className = "ttcb-header-title", this.headerTitle.textContent = e.chatbotName ?? "AI Assistant";
3162
3217
  let o = document.createElement("span");
3163
- o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = tn(), a.appendChild(this.headerTitle), a.appendChild(o);
3218
+ o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = rn(), a.appendChild(this.headerTitle), a.appendChild(o);
3164
3219
  let s = document.createElement("div");
3165
3220
  s.className = "ttcb-header-meta";
3166
3221
  let c = document.createElement("span");
@@ -3168,24 +3223,55 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3168
3223
  let l = document.createElement("span");
3169
3224
  l.className = "ttcb-meta-sep", l.setAttribute("aria-hidden", "true");
3170
3225
  let u = document.createElement("span");
3171
- u.className = "ttcb-meta-replies", u.innerHTML = `${nn()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
3226
+ u.className = "ttcb-meta-replies", u.innerHTML = `${an()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
3172
3227
  let d = document.createElement("div");
3173
- d.className = "ttcb-header-actions", this.requestHumanBtn = document.createElement("button"), this.requestHumanBtn.type = "button", this.requestHumanBtn.className = "ttcb-request-human-btn hidden", this.requestHumanBtn.id = "ttcb-request-human-btn", this.requestHumanBtn.setAttribute("aria-label", "Request human agent"), this.requestHumanBtn.title = "Request human agent", this.requestHumanBtn.innerHTML = rn(), this.requestHumanBtn.addEventListener("click", () => this.callbacks.onRequestHuman()), this.newSessionBtn = document.createElement("button"), this.newSessionBtn.className = "ttcb-new-session-btn hidden", this.newSessionBtn.setAttribute("aria-label", "New conversation"), this.newSessionBtn.title = "New conversation", this.newSessionBtn.innerHTML = Gt(), this.newSessionBtn.addEventListener("click", () => this.callbacks.onReset());
3228
+ d.className = "ttcb-header-actions", this.requestHumanBtn = document.createElement("button"), this.requestHumanBtn.type = "button", this.requestHumanBtn.className = "ttcb-request-human-btn hidden", this.requestHumanBtn.id = "ttcb-request-human-btn", this.requestHumanBtn.setAttribute("aria-label", "Request human agent"), this.requestHumanBtn.title = "Request human agent", this.requestHumanBtn.innerHTML = on(), this.requestHumanBtn.addEventListener("click", () => this.callbacks.onRequestHuman()), this.newSessionBtn = document.createElement("button"), this.newSessionBtn.type = "button", this.newSessionBtn.className = "ttcb-new-session-btn hidden", this.newSessionBtn.setAttribute("aria-label", "New conversation"), this.newSessionBtn.title = "New conversation", this.newSessionBtn.innerHTML = qt(), this.newSessionBtn.addEventListener("click", () => {
3229
+ this.actionPending || (this.ticketMode === "closed" ? this.callbacks.onNewConversation() : this.showConfirmNew());
3230
+ });
3174
3231
  let f = document.createElement("button");
3175
- return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = qt(), f.addEventListener("click", () => this.close()), d.appendChild(this.requestHumanBtn), d.appendChild(this.newSessionBtn), d.appendChild(f), t.appendChild(n), t.appendChild(i), t.appendChild(d), t;
3232
+ return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = Yt(), f.addEventListener("click", () => this.close()), d.appendChild(this.requestHumanBtn), d.appendChild(this.newSessionBtn), d.appendChild(f), t.appendChild(n), t.appendChild(i), t.appendChild(d), t;
3233
+ }
3234
+ buildBannerButton(e, t) {
3235
+ let n = document.createElement("button");
3236
+ return n.type = "button", n.className = "ttcb-banner-btn", n.textContent = e, n.addEventListener("click", t), n;
3237
+ }
3238
+ buildConfirmNewBar() {
3239
+ this.confirmNewBar = document.createElement("div"), this.confirmNewBar.className = "ttcb-confirm-bar", this.confirmNewBar.setAttribute("role", "group"), this.confirmNewBar.setAttribute("aria-label", "Start a new conversation");
3240
+ let e = document.createElement("span");
3241
+ e.className = "ttcb-confirm-text", e.textContent = "End this conversation and start a new one?", this.confirmNewBtn = this.buildBannerButton("Start new", () => {
3242
+ this.actionPending || (this.hideConfirmNew(), this.input.focus(), this.callbacks.onNewConversation());
3243
+ }), this.confirmNewBtn.classList.add("primary"), this.keepChattingBtn = this.buildBannerButton("Keep chatting", () => {
3244
+ this.hideConfirmNew(), this.newSessionBtn.focus();
3245
+ });
3246
+ let t = document.createElement("div");
3247
+ return t.className = "ttcb-confirm-actions", t.appendChild(this.confirmNewBtn), t.appendChild(this.keepChattingBtn), this.confirmNewBar.appendChild(e), this.confirmNewBar.appendChild(t), this.confirmNewBar;
3248
+ }
3249
+ showConfirmNew() {
3250
+ this.confirmingNew = !0, this.confirmNewBar.classList.add("visible"), queueMicrotask(() => this.keepChattingBtn.focus());
3251
+ }
3252
+ hideConfirmNew() {
3253
+ this.confirmingNew = !1, this.confirmNewBar.classList.remove("visible");
3254
+ }
3255
+ setActionPending(e) {
3256
+ this.actionPending = e;
3257
+ for (let t of [
3258
+ this.newSessionBtn,
3259
+ this.cancelHumanBtn,
3260
+ this.confirmNewBtn
3261
+ ]) t.setAttribute("aria-disabled", String(e));
3176
3262
  }
3177
3263
  buildAttachControls() {
3178
3264
  let e = document.createElement("div");
3179
- e.className = "ttcb-attach", this.attachBtn = document.createElement("button"), this.attachBtn.type = "button", this.attachBtn.className = "ttcb-attach-btn", this.attachBtn.setAttribute("aria-label", "Add attachment"), this.attachBtn.setAttribute("aria-haspopup", "menu"), this.attachBtn.setAttribute("aria-expanded", "false"), this.attachBtn.title = "Add attachment", this.attachBtn.innerHTML = an(), this.attachBtn.addEventListener("click", (e) => {
3265
+ e.className = "ttcb-attach", this.attachBtn = document.createElement("button"), this.attachBtn.type = "button", this.attachBtn.className = "ttcb-attach-btn", this.attachBtn.setAttribute("aria-label", "Add attachment"), this.attachBtn.setAttribute("aria-haspopup", "menu"), this.attachBtn.setAttribute("aria-expanded", "false"), this.attachBtn.title = "Add attachment", this.attachBtn.innerHTML = sn(), this.attachBtn.addEventListener("click", (e) => {
3180
3266
  e.preventDefault(), e.stopPropagation(), this.toggleAttachMenu();
3181
- }), this.attachMenu = document.createElement("div"), this.attachMenu.className = "ttcb-attach-menu", this.attachMenu.setAttribute("role", "menu"), this.attachFileInput = this.createFileInput(hn, "Choose files"), this.attachPhotoInput = this.createFileInput(gn, "Choose photos");
3267
+ }), this.attachMenu = document.createElement("div"), this.attachMenu.className = "ttcb-attach-menu", this.attachMenu.setAttribute("role", "menu"), this.attachFileInput = this.createFileInput(_n, "Choose files"), this.attachPhotoInput = this.createFileInput(vn, "Choose photos");
3182
3268
  let t = [{
3183
3269
  label: "Attachment",
3184
- icon: on(),
3270
+ icon: cn(),
3185
3271
  input: this.attachFileInput
3186
3272
  }, {
3187
3273
  label: "Photo",
3188
- icon: sn(),
3274
+ icon: ln(),
3189
3275
  input: this.attachPhotoInput
3190
3276
  }];
3191
3277
  for (let e of t) {
@@ -3216,12 +3302,12 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3216
3302
  }
3217
3303
  addPendingFiles(e) {
3218
3304
  if (e.length === 0) return;
3219
- let t = d([...this.pendingFiles.map((e) => e.file), ...e]);
3305
+ let t = p([...this.pendingFiles.map((e) => e.file), ...e]);
3220
3306
  if (t) this.showComposeError(t);
3221
3307
  else {
3222
3308
  this.showComposeError("");
3223
3309
  for (let t of e) {
3224
- let e = t.type.startsWith("image/") ? p(t) : "";
3310
+ let e = t.type.startsWith("image/") ? h(t) : "";
3225
3311
  this.pendingFiles.push({
3226
3312
  file: t,
3227
3313
  previewUrl: e
@@ -3232,10 +3318,10 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3232
3318
  }
3233
3319
  removePendingFile(e) {
3234
3320
  let [t] = this.pendingFiles.splice(e, 1);
3235
- t && m(t.previewUrl), this.renderPendingTray(), this.input.focus();
3321
+ t && g(t.previewUrl), this.renderPendingTray(), this.input.focus();
3236
3322
  }
3237
3323
  clearPendingFiles() {
3238
- for (let e of this.pendingFiles) m(e.previewUrl);
3324
+ for (let e of this.pendingFiles) g(e.previewUrl);
3239
3325
  this.pendingFiles = [], this.renderPendingTray();
3240
3326
  }
3241
3327
  renderPendingTray() {
@@ -3246,12 +3332,12 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3246
3332
  t.className = "ttcb-pending-thumb", t.src = e.previewUrl, t.alt = "", n.appendChild(t);
3247
3333
  } else {
3248
3334
  let e = document.createElement("span");
3249
- e.className = "ttcb-pending-icon", e.setAttribute("aria-hidden", "true"), e.innerHTML = dn(), n.appendChild(e);
3335
+ e.className = "ttcb-pending-icon", e.setAttribute("aria-hidden", "true"), e.innerHTML = pn(), n.appendChild(e);
3250
3336
  }
3251
3337
  let r = document.createElement("span");
3252
3338
  r.className = "ttcb-pending-name", r.textContent = e.file.name || "attachment", r.title = e.file.name, n.appendChild(r);
3253
3339
  let i = document.createElement("button");
3254
- i.type = "button", i.className = "ttcb-pending-remove", i.setAttribute("aria-label", `Remove ${e.file.name || "attachment"}`), i.innerHTML = qt(), i.addEventListener("click", () => this.removePendingFile(t)), n.appendChild(i), this.pendingTray.appendChild(n);
3340
+ i.type = "button", i.className = "ttcb-pending-remove", i.setAttribute("aria-label", `Remove ${e.file.name || "attachment"}`), i.innerHTML = Yt(), i.addEventListener("click", () => this.removePendingFile(t)), n.appendChild(i), this.pendingTray.appendChild(n);
3255
3341
  });
3256
3342
  }
3257
3343
  buildVoiceBar() {
@@ -3259,10 +3345,10 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3259
3345
  let e = document.createElement("span");
3260
3346
  e.className = "ttcb-voice-dot", e.setAttribute("aria-hidden", "true"), this.voiceTime = document.createElement("span"), this.voiceTime.className = "ttcb-voice-time", this.voiceTime.setAttribute("role", "timer"), this.voiceTime.textContent = "0:00";
3261
3347
  let t = document.createElement("div");
3262
- return t.className = "ttcb-voice-meter", t.setAttribute("aria-hidden", "true"), this.voiceLevel = document.createElement("span"), this.voiceLevel.className = "ttcb-voice-level", t.appendChild(this.voiceLevel), this.voiceCancelBtn = this.createVoiceButton("Cancel recording", un(), () => this.cancelVoice()), this.voiceStopBtn = this.createVoiceButton("Stop recording", ln(), () => void this.stopVoice()), this.voiceStopBtn.classList.add("primary"), this.voiceBar.appendChild(e), this.voiceBar.appendChild(this.voiceTime), this.voiceBar.appendChild(t), this.voiceBar.appendChild(this.voiceCancelBtn), this.voiceBar.appendChild(this.voiceStopBtn), this.voiceBar;
3348
+ return t.className = "ttcb-voice-meter", t.setAttribute("aria-hidden", "true"), this.voiceLevel = document.createElement("span"), this.voiceLevel.className = "ttcb-voice-level", t.appendChild(this.voiceLevel), this.voiceCancelBtn = this.createVoiceButton("Cancel recording", fn(), () => this.cancelVoice()), this.voiceStopBtn = this.createVoiceButton("Stop recording", dn(), () => void this.stopVoice()), this.voiceStopBtn.classList.add("primary"), this.voiceBar.appendChild(e), this.voiceBar.appendChild(this.voiceTime), this.voiceBar.appendChild(t), this.voiceBar.appendChild(this.voiceCancelBtn), this.voiceBar.appendChild(this.voiceStopBtn), this.voiceBar;
3263
3349
  }
3264
3350
  buildVoicePreview() {
3265
- return this.voicePreview = document.createElement("div"), this.voicePreview.className = "ttcb-voice-preview", this.voicePreview.setAttribute("role", "group"), this.voicePreview.setAttribute("aria-label", "Voice message preview"), this.voiceAudio = document.createElement("audio"), this.voiceAudio.className = "ttcb-voice-audio", this.voiceAudio.controls = !0, this.voiceAudio.preload = "metadata", this.voiceAudio.setAttribute("aria-label", "Recorded voice message"), this.voicePreviewTime = document.createElement("span"), this.voicePreviewTime.className = "ttcb-voice-time", this.voiceDiscardBtn = this.createVoiceButton("Discard voice message", un(), () => this.cancelVoice()), this.voiceSendBtn = this.createVoiceButton("Send voice message", Jt(), () => this.sendVoice()), this.voiceSendBtn.classList.add("primary"), this.voicePreview.appendChild(this.voiceAudio), this.voicePreview.appendChild(this.voicePreviewTime), this.voicePreview.appendChild(this.voiceDiscardBtn), this.voicePreview.appendChild(this.voiceSendBtn), this.voicePreview;
3351
+ return this.voicePreview = document.createElement("div"), this.voicePreview.className = "ttcb-voice-preview", this.voicePreview.setAttribute("role", "group"), this.voicePreview.setAttribute("aria-label", "Voice message preview"), this.voiceAudio = document.createElement("audio"), this.voiceAudio.className = "ttcb-voice-audio", this.voiceAudio.controls = !0, this.voiceAudio.preload = "metadata", this.voiceAudio.setAttribute("aria-label", "Recorded voice message"), this.voicePreviewTime = document.createElement("span"), this.voicePreviewTime.className = "ttcb-voice-time", this.voiceDiscardBtn = this.createVoiceButton("Discard voice message", fn(), () => this.cancelVoice()), this.voiceSendBtn = this.createVoiceButton("Send voice message", Xt(), () => this.sendVoice()), this.voiceSendBtn.classList.add("primary"), this.voicePreview.appendChild(this.voiceAudio), this.voicePreview.appendChild(this.voicePreviewTime), this.voicePreview.appendChild(this.voiceDiscardBtn), this.voicePreview.appendChild(this.voiceSendBtn), this.voicePreview;
3266
3352
  }
3267
3353
  createVoiceButton(e, t, n) {
3268
3354
  let r = document.createElement("button");
@@ -3270,9 +3356,9 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3270
3356
  }
3271
3357
  async startVoice() {
3272
3358
  if (!this.micBtn.disabled) {
3273
- if (this.closeAttachMenu(), this.showComposeError(""), !Y.isSupported()) this.showComposeError("Voice messages are not supported in this browser.");
3359
+ if (this.closeAttachMenu(), this.showComposeError(""), !Bt.isSupported()) this.showComposeError("Voice messages are not supported in this browser.");
3274
3360
  else {
3275
- this.recorder?.destroy(), this.recorder = new Y((e) => this.renderVoice(e));
3361
+ this.recorder?.destroy(), this.recorder = new Bt((e) => this.renderVoice(e));
3276
3362
  try {
3277
3363
  await this.recorder.start();
3278
3364
  } catch (e) {
@@ -3304,13 +3390,13 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3304
3390
  renderVoice(e) {
3305
3391
  if (this.destroyed) return;
3306
3392
  let { state: t } = e;
3307
- this.composeForm.classList.toggle("hidden", t !== "idle"), this.voiceBar.classList.toggle("visible", t === "recording"), this.voicePreview.classList.toggle("visible", t === "preview"), t === "recording" ? (this.voiceTime.textContent = _(e.elapsedSeconds), this.voiceLevel.style.width = `${Math.max(4, Math.round(e.level * 100))}%`) : (m(this.voicePreviewUrl), this.voicePreviewUrl = "", this.voiceAudio.removeAttribute("src"), t === "preview" && e.result && (this.voicePreviewUrl = p(new File([e.result.blob], "voice-preview", { type: e.result.blob.type })), this.voicePreviewUrl && (this.voiceAudio.src = this.voicePreviewUrl), this.voicePreviewTime.textContent = _(e.result.durationSeconds), queueMicrotask(() => this.voiceSendBtn.focus())));
3393
+ this.composeForm.classList.toggle("hidden", t !== "idle"), this.voiceBar.classList.toggle("visible", t === "recording"), this.voicePreview.classList.toggle("visible", t === "preview"), t === "recording" ? (this.voiceTime.textContent = y(e.elapsedSeconds), this.voiceLevel.style.width = `${Math.max(4, Math.round(e.level * 100))}%`) : (g(this.voicePreviewUrl), this.voicePreviewUrl = "", this.voiceAudio.removeAttribute("src"), t === "preview" && e.result && (this.voicePreviewUrl = h(new File([e.result.blob], "voice-preview", { type: e.result.blob.type })), this.voicePreviewUrl && (this.voiceAudio.src = this.voicePreviewUrl), this.voicePreviewTime.textContent = y(e.result.durationSeconds), queueMicrotask(() => this.voiceSendBtn.focus())));
3308
3394
  }
3309
3395
  showComposeError(e) {
3310
3396
  this.composeError.textContent = e, this.composeError.classList.toggle("visible", !!e);
3311
3397
  }
3312
3398
  setPanelMode(e) {
3313
- this.panel.classList.remove("ttcb-mode-form", "ttcb-mode-chat", "ttcb-mode-compact"), this.panel.classList.add(`ttcb-mode-${e}`), e !== "chat" && (this.requestHumanBtn.classList.add("hidden"), this.newSessionBtn.classList.add("hidden"), this.hideModeBanner());
3399
+ this.panel.classList.remove("ttcb-mode-form", "ttcb-mode-chat", "ttcb-mode-compact"), this.panel.classList.add(`ttcb-mode-${e}`), e !== "chat" && (this.requestHumanBtn.classList.add("hidden"), this.newSessionBtn.classList.add("hidden"), this.hideConfirmNew(), this.hideModeBanner());
3314
3400
  }
3315
3401
  buildIdentifyForm(e) {
3316
3402
  let t = document.createElement("form");
@@ -3324,7 +3410,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3324
3410
  placeholder: "Your name",
3325
3411
  type: "text",
3326
3412
  autocomplete: "name",
3327
- icon: Xt()
3413
+ icon: Qt()
3328
3414
  }), this.createPhoneField(t), this.emailInput = this.createIconField(t, {
3329
3415
  id: "email",
3330
3416
  label: "Email (optional)",
@@ -3333,10 +3419,10 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3333
3419
  placeholder: "Email (optional)",
3334
3420
  type: "email",
3335
3421
  autocomplete: "email",
3336
- icon: Zt()
3337
- }), this.identifyError = document.createElement("p"), this.identifyError.className = "ttcb-identify-error", t.appendChild(this.identifyError), this.identifySubmit = document.createElement("button"), this.identifySubmit.type = "submit", this.identifySubmit.className = "ttcb-identify-submit", this.identifySubmit.innerHTML = `<span>Start Chatting</span>${$t()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
3422
+ icon: $t()
3423
+ }), this.identifyError = document.createElement("p"), this.identifyError.className = "ttcb-identify-error", t.appendChild(this.identifyError), this.identifySubmit = document.createElement("button"), this.identifySubmit.type = "submit", this.identifySubmit.className = "ttcb-identify-submit", this.identifySubmit.innerHTML = `<span>Start Chatting</span>${tn()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
3338
3424
  let n = document.createElement("div");
3339
- n.className = "ttcb-trust", n.innerHTML = `${en()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
3425
+ n.className = "ttcb-trust", n.innerHTML = `${nn()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
3340
3426
  }
3341
3427
  createIconField(e, t) {
3342
3428
  let n = document.createElement("div");
@@ -3366,7 +3452,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3366
3452
  let a = document.createElement("div");
3367
3453
  a.className = "ttcb-phone-row", a.id = "ttcb-phone-row", this.dialBtn = document.createElement("button"), this.dialBtn.type = "button", this.dialBtn.className = "ttcb-dial-btn", this.dialBtn.setAttribute("aria-label", "Select country code"), this.dialBtn.setAttribute("aria-haspopup", "listbox"), this.dialBtn.setAttribute("aria-expanded", "false"), this.dialFlag = document.createElement("span"), this.dialFlag.className = "ttcb-dial-flag", this.dialCode = document.createElement("span"), this.dialCode.className = "ttcb-dial-code", this.syncDialButton(), this.dialBtn.appendChild(this.dialFlag), this.dialBtn.appendChild(this.dialCode);
3368
3454
  let o = document.createElement("span");
3369
- o.setAttribute("aria-hidden", "true"), o.innerHTML = Qt(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
3455
+ o.setAttribute("aria-hidden", "true"), o.innerHTML = en(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
3370
3456
  e.preventDefault(), e.stopPropagation(), this.toggleCountryPopover();
3371
3457
  }), this.phoneInput = document.createElement("input"), this.phoneInput.id = "ttcb-tel", this.phoneInput.name = "tel", this.phoneInput.type = "tel", this.phoneInput.className = "ttcb-phone-national", this.phoneInput.placeholder = "1712-345678", this.phoneInput.required = !0, this.phoneInput.autocomplete = "tel-national", this.phoneInput.setAttribute("inputmode", "tel"), a.appendChild(this.dialBtn), a.appendChild(this.phoneInput), this.countryPopover = document.createElement("div"), this.countryPopover.className = "ttcb-country-popover", this.countryPopover.setAttribute("role", "listbox"), this.countrySearch = document.createElement("input"), this.countrySearch.type = "search", this.countrySearch.className = "ttcb-country-search", this.countrySearch.placeholder = "Search country…", this.countrySearch.setAttribute("aria-label", "Search countries"), this.countrySearch.addEventListener("input", () => this.renderCountryList()), this.countryList = document.createElement("div"), this.countryList.className = "ttcb-country-list", this.countryPopover.appendChild(this.countrySearch), this.countryPopover.appendChild(this.countryList), this.renderCountryList(), t.appendChild(n), t.appendChild(a), t.appendChild(this.countryPopover), e.appendChild(t);
3372
3458
  }
@@ -3435,7 +3521,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3435
3521
  }
3436
3522
  }
3437
3523
  handleIdentifySubmit() {
3438
- let e = this.nameInput.value.trim(), t = Bt(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
3524
+ let e = this.nameInput.value.trim(), t = Ht(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
3439
3525
  !e || !t ? this.showIdentifyError("Name and phone are required.") : (this.showIdentifyError(""), this.callbacks.onIdentify({
3440
3526
  name: e,
3441
3527
  phone: t,
@@ -3456,13 +3542,13 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3456
3542
  }
3457
3543
  buildMessage(e) {
3458
3544
  if ("message" in e) {
3459
- let t = pn({
3545
+ let t = hn({
3460
3546
  ...e.message,
3461
3547
  pending: e.pending
3462
3548
  });
3463
3549
  return t.dataset.msgId = String(e.id), t;
3464
3550
  }
3465
- return pn(e);
3551
+ return hn(e);
3466
3552
  }
3467
3553
  findMessageEl(e) {
3468
3554
  for (let t of this.messagesContainer.querySelectorAll(".ttcb-msg")) if (t.dataset.msgId === String(e)) return t;
@@ -3475,7 +3561,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3475
3561
  }
3476
3562
  }
3477
3563
  setLoading(e) {
3478
- if (this.sendBtn.disabled = e || this.input.disabled, this.attachBtn.disabled = e || this.input.disabled, this.micBtn.disabled = e || this.input.disabled, e) this.closeAttachMenu(), this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(mn()), this.scrollToBottom()), this.isFullScreen() || this.input.focus();
3564
+ if (this.sendBtn.disabled = e || this.input.disabled, this.attachBtn.disabled = e || this.input.disabled, this.micBtn.disabled = e || this.input.disabled, e) this.closeAttachMenu(), this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(gn()), this.scrollToBottom()), this.isFullScreen() || this.input.focus();
3479
3565
  else {
3480
3566
  let e = this.shadow.getElementById("ttcb-typing");
3481
3567
  e && e.remove(), !this.input.disabled && !this.isFullScreen() && this.input.focus();
@@ -3484,7 +3570,7 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3484
3570
  setIdentifyLoading(e) {
3485
3571
  this.identifySubmit.disabled = e, this.nameInput.disabled = e, this.phoneInput.disabled = e, this.emailInput.disabled = e, this.dialBtn.disabled = e, this.shadow.getElementById("ttcb-phone-row")?.classList.toggle("disabled", e);
3486
3572
  for (let t of this.identifyContainer.querySelectorAll(".ttcb-input-wrap")) t.classList.toggle("disabled", e);
3487
- this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${$t()}`, e && this.closeCountryPopover();
3573
+ this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${tn()}`, e && this.closeCountryPopover();
3488
3574
  }
3489
3575
  showIdentifyError(e) {
3490
3576
  this.identifyError.textContent = e;
@@ -3522,26 +3608,30 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3522
3608
  }) : this.showEmptyState(e.chatbotName ?? "AI Assistant"), this.setMode("ai");
3523
3609
  }
3524
3610
  clearMessages(e) {
3525
- this.messagesContainer.innerHTML = "", this.clearPendingFiles(), this.showComposeError(""), this.showEmptyState(e);
3611
+ this.messagesContainer.innerHTML = "", this.clearPendingFiles(), this.showComposeError(""), this.hideConfirmNew(), this.showEmptyState(e);
3526
3612
  }
3527
3613
  setMode(e, t) {
3528
- let n = this.panel.classList.contains("ttcb-mode-chat"), r = t?.agentName, i = t?.canRequestHuman === !0, a = n && i, o = n && e === "closed", s = e === "closed";
3529
- this.requestHumanBtn.classList.toggle("hidden", !a), this.newSessionBtn.classList.toggle("hidden", !o), this.input.disabled = s, s ? (this.sendBtn.disabled = !0, this.attachBtn.disabled = !0, this.micBtn.disabled = !0, this.closeAttachMenu(), this.clearPendingFiles(), this.recorder && this.cancelVoice(), this.showComposeError("")) : this.shadow.getElementById("ttcb-typing") || (this.sendBtn.disabled = !1, this.attachBtn.disabled = !1, this.micBtn.disabled = !1), n ? e === "waiting" ? this.showModeBanner("Waiting for a human agent…", "waiting") : e === "closed" ? this.showModeBanner("This conversation is closed", "closed") : e === "human" && r?.trim() ? this.showModeBanner(`Connected with ${r.trim()}`, "human") : this.hideModeBanner() : this.hideModeBanner();
3614
+ let n = this.panel.classList.contains("ttcb-mode-chat"), r = t?.agentName, i = t?.canRequestHuman === !0, a = t?.canStartNew ?? e === "closed", o = n && i, s = n && a, c = e === "closed";
3615
+ this.ticketMode = e, this.requestHumanBtn.classList.toggle("hidden", !o), this.newSessionBtn.classList.toggle("hidden", !s), (!s || c) && this.hideConfirmNew(), this.input.disabled = c, c ? (this.sendBtn.disabled = !0, this.attachBtn.disabled = !0, this.micBtn.disabled = !0, this.closeAttachMenu(), this.clearPendingFiles(), this.recorder && this.cancelVoice(), this.showComposeError("")) : this.shadow.getElementById("ttcb-typing") || (this.sendBtn.disabled = !1, this.attachBtn.disabled = !1, this.micBtn.disabled = !1), n ? (e === "waiting" ? this.showModeBanner("Waiting for a human agent…", "waiting") : e === "closed" ? this.showModeBanner("This conversation is closed", "closed") : e === "human" && r?.trim() ? this.showModeBanner(`Connected with ${r.trim()}`, "human") : this.hideModeBanner(), this.rescueFocus()) : (this.hideModeBanner(), this.rescueFocus());
3530
3616
  }
3531
3617
  showModeBanner(e, t) {
3532
- this.modeBanner.textContent = e, this.modeBanner.className = `ttcb-mode-banner visible ${t}`;
3618
+ this.modeBannerText.textContent = e, this.modeBanner.className = `ttcb-mode-banner visible ${t}`, this.cancelHumanBtn.classList.toggle("hidden", t !== "waiting");
3533
3619
  }
3534
3620
  hideModeBanner() {
3535
- this.modeBanner.textContent = "", this.modeBanner.className = "ttcb-mode-banner";
3621
+ this.modeBannerText.textContent = "", this.modeBanner.className = "ttcb-mode-banner", this.cancelHumanBtn.classList.add("hidden");
3622
+ }
3623
+ rescueFocus() {
3624
+ let e = this.shadow.activeElement;
3625
+ e instanceof HTMLElement && (e.closest(".hidden") || e.closest(".ttcb-mode-banner:not(.visible)")) && (this.input.disabled ? this.panel.focus({ preventScroll: !0 }) : this.input.focus());
3536
3626
  }
3537
3627
  destroy() {
3538
- this.destroyed = !0, this.stopViewportSync?.(), this.stopViewportSync = null, this.clearPendingFiles(), this.recorder?.destroy(), this.recorder = null, m(this.voicePreviewUrl), this.voicePreviewUrl = "", this.host.remove();
3628
+ this.destroyed = !0, this.stopViewportSync?.(), this.stopViewportSync = null, this.clearPendingFiles(), this.recorder?.destroy(), this.recorder = null, g(this.voicePreviewUrl), this.voicePreviewUrl = "", this.host.remove();
3539
3629
  }
3540
3630
  scrollToBottom() {
3541
3631
  this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
3542
3632
  }
3543
- }, vn = {
3544
- apiBaseUrl: c,
3633
+ }, bn = {
3634
+ apiBaseUrl: u,
3545
3635
  chatbotName: "AI Assistant",
3546
3636
  primaryColor: "#2563EB",
3547
3637
  theme: "auto",
@@ -3552,23 +3642,23 @@ var hn = "image/jpeg,image/png,image/gif,video/mp4,video/webm,audio/ogg,audio/mp
3552
3642
  sessionId: "",
3553
3643
  requestTimeoutMs: n
3554
3644
  };
3555
- function yn(e) {
3645
+ function xn(e) {
3556
3646
  return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
3557
3647
  }
3558
- var bn = [
3648
+ var Sn = [
3559
3649
  5e3,
3560
3650
  15e3,
3561
3651
  3e4,
3562
3652
  6e4
3563
3653
  ];
3564
- function xn(e) {
3565
- return o(e) ? e.status === 0 || e.status >= 500 || e.apiError.code === "BAD_RESPONSE" : !1;
3566
- }
3567
- function Sn(e) {
3568
- return o(e) ? e.apiError.message : e instanceof Error ? e.message : "Failed to load chatbot config.";
3654
+ function Cn(e) {
3655
+ return c(e) ? e.status === 0 || e.status >= 500 || e.apiError.code === "BAD_RESPONSE" : !1;
3569
3656
  }
3570
- var Cn = 0, Q = () => Date.now() * 1e3 + Cn++ % 1e3;
3571
3657
  function wn(e) {
3658
+ return c(e) ? e.apiError.message : e instanceof Error ? e.message : "Failed to load chatbot config.";
3659
+ }
3660
+ var Tn = 0, Q = () => Date.now() * 1e3 + Tn++ % 1e3;
3661
+ function En(e) {
3572
3662
  if (!e || typeof e != "object") return null;
3573
3663
  let t = e;
3574
3664
  if (typeof t.textMessage == "string" && t.textMessage.trim()) return t.textMessage.trim();
@@ -3580,11 +3670,11 @@ function wn(e) {
3580
3670
  }
3581
3671
  return null;
3582
3672
  }
3583
- function Tn(e) {
3673
+ function Dn(e) {
3584
3674
  let t = (e.attachments ?? []).map((e) => e.url).join("");
3585
3675
  return `${e.content}\u0000${t}`;
3586
3676
  }
3587
- function En(e) {
3677
+ function On(e) {
3588
3678
  if (!e || typeof e != "object") return null;
3589
3679
  let t = e;
3590
3680
  if (typeof t.id == "string" && t.id) return t.id;
@@ -3594,9 +3684,9 @@ function En(e) {
3594
3684
  }
3595
3685
  return null;
3596
3686
  }
3597
- var Dn = class {
3687
+ var kn = class {
3598
3688
  constructor() {
3599
- this.emitter = new fe(), this.visitorTokens = new Mt(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.retryTimer = null, this.lastPushId = null, this.initToken = 0, this._state = {
3689
+ this.emitter = new fe(), this.visitorTokens = new Nt(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.retryTimer = null, this.lastPushId = null, this.endedConversationId = null, this.initToken = 0, this._state = {
3600
3690
  isOpen: !1,
3601
3691
  isLoading: !1,
3602
3692
  isReady: !1,
@@ -3624,20 +3714,24 @@ var Dn = class {
3624
3714
  syncWidgetMode(e, t) {
3625
3715
  this.widget?.setMode(e, {
3626
3716
  agentName: t,
3627
- canRequestHuman: e === "ai" && this.hasActiveTicket
3717
+ canRequestHuman: e === "ai" && this.hasActiveTicket,
3718
+ canStartNew: e === "closed" || this.hasActiveTicket
3628
3719
  });
3629
3720
  }
3721
+ isEndedConversation(e) {
3722
+ return e.mode === "closed" && !!e.conversationId && e.conversationId === this.endedConversationId;
3723
+ }
3630
3724
  async init(e) {
3631
3725
  if (!e.apiKey) throw Error("[onedeskpro-chatbot] `apiKey` is required to initialise the chatbot.");
3632
3726
  let t = ++this.initToken;
3633
3727
  this.clearRetry(), this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.callerSetName = e.chatbotName !== void 0, this.options = {
3634
- ...vn,
3635
- ...yn(e)
3636
- }, this.apiClient = new s({
3728
+ ...bn,
3729
+ ...xn(e)
3730
+ }, this.apiClient = new l({
3637
3731
  baseUrl: this.options.apiBaseUrl,
3638
3732
  apiKey: this.options.apiKey,
3639
3733
  timeoutMs: this.options.requestTimeoutMs
3640
- }), this.hasActiveTicket = !1, this.setState({
3734
+ }), this.hasActiveTicket = !1, this.endedConversationId = null, this.setState({
3641
3735
  isReady: !1,
3642
3736
  blockReason: null,
3643
3737
  visitorToken: null,
@@ -3654,13 +3748,13 @@ var Dn = class {
3654
3748
  n = await this.apiClient.fetchConfig();
3655
3749
  } catch (n) {
3656
3750
  if (e !== this.initToken) return;
3657
- if (xn(n)) {
3751
+ if (Cn(n)) {
3658
3752
  this.setState({
3659
3753
  isReady: !1,
3660
3754
  blockReason: "server-unavailable",
3661
- error: Sn(n)
3755
+ error: wn(n)
3662
3756
  });
3663
- let r = bn[t];
3757
+ let r = Sn[t];
3664
3758
  if (r !== void 0) {
3665
3759
  this.retryTimer = setTimeout(() => {
3666
3760
  this.retryTimer = null, this.checkReadiness(e, t + 1);
@@ -3681,7 +3775,7 @@ var Dn = class {
3681
3775
  }), i ? (this.mountWidget(), this.visitorTokens.setScope(n.agentId), await this.resolveVisitorGate(e), e === this.initToken && (this.widget?.reveal(), this.emitter.emit("ready"))) : this.emitter.emit("ready");
3682
3776
  }
3683
3777
  mountWidget() {
3684
- typeof window < "u" && typeof document < "u" && (this.widget = new _n(this.options, {
3778
+ typeof window < "u" && typeof document < "u" && (this.widget = new yn(this.options, {
3685
3779
  onSend: (e) => void this.sendMessage(e),
3686
3780
  onSendAttachments: (e, t) => void this.sendAttachments(e, t),
3687
3781
  onSendVoice: (e) => void this.sendVoice(e),
@@ -3692,19 +3786,20 @@ var Dn = class {
3692
3786
  onClose: () => {
3693
3787
  this.setState({ isOpen: !1 }), this.emitter.emit("close");
3694
3788
  },
3695
- onReset: () => this.resetSession(),
3696
- onRequestHuman: () => void this.requestHuman()
3789
+ onNewConversation: () => void this.startNewConversation(),
3790
+ onRequestHuman: () => void this.requestHuman(),
3791
+ onCancelHumanRequest: () => void this.cancelHumanRequest()
3697
3792
  }));
3698
3793
  }
3699
3794
  clearRetry() {
3700
3795
  this.retryTimer !== null && (clearTimeout(this.retryTimer), this.retryTimer = null);
3701
3796
  }
3702
3797
  handleConfigError(e) {
3703
- let t = (o(e) ? e : null)?.apiError.code === "agent_not_assigned" ? "no-agent" : null;
3798
+ let t = (c(e) ? e : null)?.apiError.code === "agent_not_assigned" ? "no-agent" : null;
3704
3799
  this.setState({
3705
3800
  isReady: !1,
3706
3801
  blockReason: t,
3707
- error: Sn(e)
3802
+ error: wn(e)
3708
3803
  });
3709
3804
  }
3710
3805
  async resolveVisitorGate(e) {
@@ -3736,7 +3831,7 @@ var Dn = class {
3736
3831
  }), this.widget?.readyToChat(this.options), this.connectSdkSocket(e), await this.restoreTicketStatus(e, n);
3737
3832
  }
3738
3833
  connectSdkSocket(e) {
3739
- this.sdkSocket ||= new Ot(), this.sdkSocket.connect({
3834
+ this.sdkSocket ||= new kt(), this.sdkSocket.connect({
3740
3835
  baseUrl: this.options.apiBaseUrl,
3741
3836
  apiKey: this.options.apiKey,
3742
3837
  visitorToken: e,
@@ -3757,19 +3852,19 @@ var Dn = class {
3757
3852
  async restoreTicketStatus(e, t) {
3758
3853
  try {
3759
3854
  let n = await this.apiClient.fetchTicketStatus(e);
3760
- if (t !== this.initToken) return;
3855
+ if (t !== this.initToken || this.isEndedConversation(n)) return;
3761
3856
  this.applyMode(n.mode, n);
3762
3857
  } catch {}
3763
3858
  }
3764
3859
  handleTicketStatus(e) {
3765
- e?.mode && this.applyMode(e.mode, e);
3860
+ e?.mode && !this.isEndedConversation(e) && this.applyMode(e.mode, e);
3766
3861
  }
3767
3862
  handleMessageReceive(e) {
3768
3863
  if (this._state.mode === "ai") return;
3769
- let t = wn(e) ?? "", n = ne(e);
3864
+ let t = En(e) ?? "", n = ne(e);
3770
3865
  if (!t && n.length === 0) return;
3771
- let r = En(e), i = this._state.messages[this._state.messages.length - 1];
3772
- if (i && Tn(i.message) === Tn({
3866
+ let r = On(e), i = this._state.messages[this._state.messages.length - 1];
3867
+ if (i && Dn(i.message) === Dn({
3773
3868
  content: t,
3774
3869
  attachments: n
3775
3870
  }) && (i.message.type === "ai" || i.message.type === "agent" && (!r || r === this.lastPushId))) return;
@@ -3826,6 +3921,50 @@ var Dn = class {
3826
3921
  this.setState({ isLoading: !1 });
3827
3922
  }
3828
3923
  }
3924
+ async cancelHumanRequest() {
3925
+ if (!this.apiClient || this._state.mode !== "waiting" || this._state.isLoading) return;
3926
+ let e = this.requireVisitorToken("cancelHumanRequest"), t = this.initToken;
3927
+ this.setState({
3928
+ isLoading: !0,
3929
+ error: null
3930
+ }), this.widget?.setActionPending(!0), this.widget?.showComposeError("");
3931
+ try {
3932
+ let n = await this.apiClient.cancelHumanRequest(e);
3933
+ if (t !== this.initToken) return;
3934
+ this.applyMode(n.mode, n), n.mode === "ai" && this.emitter.emit("human-request-cancelled");
3935
+ } catch (e) {
3936
+ if (t !== this.initToken) return;
3937
+ this.rejectAction(e, "Could not cancel the request. Please try again.");
3938
+ } finally {
3939
+ t === this.initToken && (this.setState({ isLoading: !1 }), this.widget?.setActionPending(!1));
3940
+ }
3941
+ }
3942
+ async startNewConversation() {
3943
+ if (!this.apiClient || !this._state.isReady || this._state.needsIdentify || this._state.isLoading) return;
3944
+ let e = this.requireVisitorToken("startNewConversation"), t = this.initToken;
3945
+ this.setState({
3946
+ isLoading: !0,
3947
+ error: null
3948
+ }), this.widget?.setActionPending(!0), this.widget?.showComposeError("");
3949
+ try {
3950
+ let n = await this.apiClient.closeConversation(e);
3951
+ if (t !== this.initToken) return;
3952
+ this.endedConversationId = n.mode === "closed" ? n.conversationId ?? null : null, this.hasActiveTicket = !1, this.setState({
3953
+ messages: [],
3954
+ error: null,
3955
+ mode: "ai"
3956
+ }), this.widget?.clearMessages(this.options.chatbotName), this.syncWidgetMode("ai"), this.emitter.emit("session-reset");
3957
+ } catch (e) {
3958
+ if (t !== this.initToken) return;
3959
+ this.rejectAction(e, "Could not start a new conversation. Please try again.");
3960
+ } finally {
3961
+ t === this.initToken && (this.setState({ isLoading: !1 }), this.widget?.setActionPending(!1));
3962
+ }
3963
+ }
3964
+ rejectAction(e, t) {
3965
+ let n = e instanceof Error ? e : Error(String(e));
3966
+ this.setState({ error: n.message }), this.widget?.showComposeError(t), this.emitter.emit("error", n);
3967
+ }
3829
3968
  requireVisitorToken(e) {
3830
3969
  let t = this.visitorTokens.get() ?? this._state.visitorToken;
3831
3970
  if (!this.apiClient || !t) throw Error(`[onedeskpro-chatbot] Identify before ${e}().`);
@@ -3875,7 +4014,7 @@ var Dn = class {
3875
4014
  return;
3876
4015
  }
3877
4016
  if (e.length === 0 || this._state.isLoading || this._state.needsIdentify) return;
3878
- let r = d(e);
4017
+ let r = p(e);
3879
4018
  r ? this.rejectSend(r) : await this.uploadThenDeliver({
3880
4019
  visitorToken: n,
3881
4020
  files: e,
@@ -3906,7 +4045,7 @@ var Dn = class {
3906
4045
  ...n.waveform ? { waveform: n.waveform } : {}
3907
4046
  }, i = {
3908
4047
  type: n.file.type,
3909
- url: p(n.file),
4048
+ url: h(n.file),
3910
4049
  fileName: n.file.name,
3911
4050
  size: n.file.size,
3912
4051
  ...r
@@ -3943,7 +4082,7 @@ var Dn = class {
3943
4082
  }
3944
4083
  } catch (e) {
3945
4084
  this.removeMessage(a.id);
3946
- for (let e of r) m(e.url);
4085
+ for (let e of r) g(e.url);
3947
4086
  let t = e instanceof Error ? e : Error(String(e));
3948
4087
  this.setState({
3949
4088
  error: t.message,
@@ -3960,7 +4099,7 @@ var Dn = class {
3960
4099
  }
3961
4100
  };
3962
4101
  this.replaceMessage(a.id, c);
3963
- for (let e of r) m(e.url);
4102
+ for (let e of r) g(e.url);
3964
4103
  o === "ai" && this.widget?.setLoading(!0), await this.deliver({
3965
4104
  chatInput: i,
3966
4105
  visitorToken: t,
@@ -3971,7 +4110,7 @@ var Dn = class {
3971
4110
  async deliver(e, t) {
3972
4111
  try {
3973
4112
  let n = await this.apiClient.sendMessage(e);
3974
- this.hasActiveTicket = !0;
4113
+ this.hasActiveTicket = !0, this.endedConversationId = null;
3975
4114
  let r = n.mode ?? t, i = [...this._state.messages], a = (n.text ?? "").trim();
3976
4115
  if (r !== t && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), a) {
3977
4116
  let e = i[i.length - 1];
@@ -4032,12 +4171,12 @@ var Dn = class {
4032
4171
  needsIdentify: !0
4033
4172
  });
4034
4173
  }
4035
- }, $ = null, On = {
4174
+ }, $ = null, An = {
4036
4175
  async init(e) {
4037
- return $ = new Dn(), await $.init(e), $;
4176
+ return $ = new kn(), await $.init(e), $;
4038
4177
  },
4039
4178
  getInstance() {
4040
4179
  return $;
4041
4180
  }
4042
4181
  };
4043
- export { s as ApiClient, Dn as ChatbotCore, c as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, fe as EventEmitter, On as OnedeskProChatbot, u as SDK_CHAT_MAX_ATTACHMENTS, l as SDK_UPLOAD_MAX_BYTES, Ot as SdkSocket, Mt as SessionManager, Nt as VOICE_MAX_DURATION_SECONDS, Y as VoiceRecorder, o as isChatbotRequestError, Dt as resolveSdkSocketUrl };
4182
+ export { l as ApiClient, kn as ChatbotCore, u as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, fe as EventEmitter, An as OnedeskProChatbot, f as SDK_CHAT_MAX_ATTACHMENTS, d as SDK_UPLOAD_MAX_BYTES, kt as SdkSocket, Nt as SessionManager, Pt as VOICE_MAX_DURATION_SECONDS, Bt as VoiceRecorder, c as isChatbotRequestError, Ot as resolveSdkSocketUrl };