@onedeskpro/chatbot-core 0.2.0 → 0.3.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
@@ -6,16 +6,21 @@ var e = Object.defineProperty, t = (t, n) => {
6
6
  enumerable: !0
7
7
  });
8
8
  return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
- }, n = 3e4;
10
- function r(e) {
9
+ }, n = 3e4, r = 12e4;
10
+ function i(e) {
11
11
  return typeof e == "object" && !!e && typeof e.message == "string";
12
12
  }
13
- function i(e) {
14
- return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && r(e.apiError);
13
+ function a(e) {
14
+ if (typeof e != "object" || !e) return !1;
15
+ let t = e;
16
+ return typeof t.type == "string" && typeof t.url == "string" && typeof t.fileName == "string" && typeof t.size == "number";
15
17
  }
16
- var a = class {
18
+ function o(e) {
19
+ return e instanceof Error && "apiError" in e && "status" in e && typeof e.status == "number" && i(e.apiError);
20
+ }
21
+ var s = class {
17
22
  constructor(e) {
18
- this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4;
23
+ this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.apiKey = e.apiKey, this.timeoutMs = e.timeoutMs ?? 3e4, this.uploadTimeoutMs = e.uploadTimeoutMs ?? r;
19
24
  }
20
25
  fail(e, t, n, r) {
21
26
  let i = {
@@ -30,40 +35,40 @@ var a = class {
30
35
  status: t
31
36
  });
32
37
  }
33
- async request(e, t, n, i, a) {
34
- let o = new URL(`${this.baseUrl}${t}`);
35
- if (i) for (let [e, t] of Object.entries(i)) o.searchParams.set(e, t);
36
- let s = {
37
- "Content-Type": "application/json",
38
+ async request(e, t, n, r, a, o = this.timeoutMs) {
39
+ let s = new URL(`${this.baseUrl}${t}`);
40
+ if (r) for (let [e, t] of Object.entries(r)) s.searchParams.set(e, t);
41
+ let c = typeof FormData < "u" && n instanceof FormData, l = {
42
+ ...c ? {} : { "Content-Type": "application/json" },
38
43
  "X-API-Key": this.apiKey,
39
44
  ...a
40
- }, c = new AbortController(), l = setTimeout(() => c.abort(), this.timeoutMs), u;
45
+ }, u = new AbortController(), d = setTimeout(() => u.abort(), o), f;
41
46
  try {
42
- u = await fetch(o.toString(), {
47
+ f = await fetch(s.toString(), {
43
48
  method: e,
44
- headers: s,
45
- signal: c.signal,
46
- ...n === void 0 ? {} : { body: JSON.stringify(n) }
49
+ headers: l,
50
+ signal: u.signal,
51
+ ...n === void 0 ? {} : { body: c ? n : JSON.stringify(n) }
47
52
  });
48
53
  } catch (e) {
49
- c.signal.aborted && this.fail(`Request timed out after ${this.timeoutMs}ms.`, 0, "TIMEOUT", t), this.fail(e instanceof Error ? e.message : "Network request failed.", 0, "NETWORK_ERROR", t);
54
+ u.signal.aborted && this.fail(`Request timed out after ${o}ms.`, 0, "TIMEOUT", t), this.fail(e instanceof Error ? e.message : "Network request failed.", 0, "NETWORK_ERROR", t);
50
55
  } finally {
51
- clearTimeout(l);
56
+ clearTimeout(d);
52
57
  }
53
- let d = await u.text(), f = null;
54
- if (d) try {
55
- f = JSON.parse(d);
58
+ let p = await f.text(), m = null;
59
+ if (p) try {
60
+ m = JSON.parse(p);
56
61
  } catch {
57
- f = null;
62
+ m = null;
58
63
  }
59
- if (!u.ok) {
60
- if (r(f)) throw Object.assign(Error(f.message), {
61
- apiError: f,
62
- status: u.status
64
+ if (!f.ok) {
65
+ if (i(m)) throw Object.assign(Error(m.message), {
66
+ apiError: m,
67
+ status: f.status
63
68
  });
64
- this.fail(`Request failed with status ${u.status} ${u.statusText}`.trim(), u.status, "HTTP_ERROR", t);
69
+ this.fail(`Request failed with status ${f.status} ${f.statusText}`.trim(), f.status, "HTTP_ERROR", t);
65
70
  }
66
- return f === null && this.fail("The server returned an empty or malformed response.", u.status, "BAD_RESPONSE", t), f.data;
71
+ return m === null && this.fail("The server returned an empty or malformed response.", f.status, "BAD_RESPONSE", t), m.data;
67
72
  }
68
73
  async identify(e) {
69
74
  return this.request("POST", "/sdk/identify", e);
@@ -74,6 +79,12 @@ var a = class {
74
79
  async sendMessage(e) {
75
80
  return this.request("POST", "/sdk/chat", e);
76
81
  }
82
+ async uploadAttachment(e, t) {
83
+ let n = new FormData();
84
+ n.append("file", e, e.name);
85
+ let r = await this.request("POST", "/sdk/upload", n, void 0, { "X-Visitor-Token": t }, this.uploadTimeoutMs);
86
+ return a(r) || this.fail("The server returned an unexpected upload response.", 200, "BAD_RESPONSE", "/sdk/upload"), r;
87
+ }
77
88
  async fetchConfig() {
78
89
  return this.request("GET", "/sdk/config");
79
90
  }
@@ -83,7 +94,158 @@ var a = class {
83
94
  async fetchTicketStatus(e) {
84
95
  return this.request("GET", "/sdk/ticket-status", void 0, void 0, { "X-Visitor-Token": e });
85
96
  }
86
- }, o = "https://api.onedeskpro.com", s = class {
97
+ }, c = "https://api.onedeskpro.com", l = 10485760, u = 10;
98
+ //#endregion
99
+ //#region src/attachments.ts
100
+ function d(e) {
101
+ if (e.length > 10) return "You can send up to 10 files at a time.";
102
+ let t = e.find((e) => e.size > l);
103
+ if (t) {
104
+ let e = Math.round(l / 1048576);
105
+ return `"${t.name || "This file"}" is larger than ${e} MB.`;
106
+ }
107
+ return null;
108
+ }
109
+ function f(e) {
110
+ return /^(https?:\/\/|blob:)/i.test(e);
111
+ }
112
+ function p(e) {
113
+ return typeof URL > "u" || typeof URL.createObjectURL != "function" ? "" : URL.createObjectURL(e);
114
+ }
115
+ function m(e) {
116
+ e.startsWith("blob:") && typeof URL < "u" && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
117
+ }
118
+ function ee(e) {
119
+ return {
120
+ type: e.type || "application/octet-stream",
121
+ url: p(e),
122
+ fileName: e.name || "attachment",
123
+ size: e.size
124
+ };
125
+ }
126
+ function te(e) {
127
+ return !Number.isFinite(e) || e < 0 ? "" : e < 1024 ? `${e} B` : e < 1048576 ? `${(e / 1024).toFixed(+(e < 10240))} KB` : `${(e / 1048576).toFixed(1)} MB`;
128
+ }
129
+ function ne(e) {
130
+ if (!e || typeof e != "object") return [];
131
+ let t = e, n = t.attachments;
132
+ if (!Array.isArray(n) && t.message && typeof t.message == "object" && (n = t.message.attachments), !Array.isArray(n)) return [];
133
+ let r = [];
134
+ for (let e of n) {
135
+ if (!e || typeof e != "object") continue;
136
+ let t = e;
137
+ typeof t.url == "string" && /^https?:\/\//i.test(t.url) && r.push({
138
+ type: typeof t.type == "string" && t.type ? t.type : "application/octet-stream",
139
+ url: t.url,
140
+ fileName: typeof t.fileName == "string" && t.fileName ? t.fileName : "attachment",
141
+ size: typeof t.size == "number" && t.size >= 0 ? t.size : 0,
142
+ ...typeof t.durationSeconds == "number" ? { durationSeconds: t.durationSeconds } : {}
143
+ });
144
+ }
145
+ return r;
146
+ }
147
+ function re(e, t) {
148
+ let n = e.trim();
149
+ return n ? t.length === 0 ? !1 : t.some((e) => e.fileName === n) || /^\d+ files?$/.test(n) ? !0 : [
150
+ "Image",
151
+ "Video",
152
+ "Audio",
153
+ "Attachment"
154
+ ].includes(n) : !0;
155
+ }
156
+ //#endregion
157
+ //#region src/audio.ts
158
+ var h = 16e3;
159
+ function g(e) {
160
+ return (e ?? "").split(";")[0].trim().toLowerCase() || "audio/webm";
161
+ }
162
+ function ie(e) {
163
+ return e.includes("mpeg") || e.includes("mp3") ? "mp3" : e.includes("wav") ? "wav" : e.includes("mp4") || e.includes("m4a") ? "m4a" : e.includes("ogg") ? "ogg" : "webm";
164
+ }
165
+ function _(e) {
166
+ if (!Number.isFinite(e) || e < 0) return "0:00";
167
+ let t = Math.floor(e), n = Math.floor(t / 60), r = t % 60;
168
+ return `${n}:${String(r).padStart(2, "0")}`;
169
+ }
170
+ function ae() {
171
+ if (typeof window > "u") return null;
172
+ let e = window;
173
+ return e.AudioContext ?? e.webkitAudioContext ?? null;
174
+ }
175
+ function oe() {
176
+ if (typeof window > "u") return null;
177
+ let e = window;
178
+ return e.OfflineAudioContext ?? e.webkitOfflineAudioContext ?? null;
179
+ }
180
+ async function se(e) {
181
+ let t = ae();
182
+ if (!t) return null;
183
+ let n = new t();
184
+ try {
185
+ let t = await e.arrayBuffer();
186
+ return await n.decodeAudioData(t.slice(0));
187
+ } catch {
188
+ return null;
189
+ } finally {
190
+ await n.close().catch(() => void 0);
191
+ }
192
+ }
193
+ async function ce(e) {
194
+ let t = oe();
195
+ if (t) try {
196
+ let n = new t(1, Math.max(1, Math.ceil(e.duration * h)), h), r = n.createBufferSource();
197
+ return r.buffer = e, r.connect(n.destination), r.start(0), {
198
+ samples: (await n.startRendering()).getChannelData(0),
199
+ sampleRate: h
200
+ };
201
+ } catch {}
202
+ return {
203
+ samples: e.getChannelData(0),
204
+ sampleRate: e.sampleRate
205
+ };
206
+ }
207
+ function le(e, t) {
208
+ let n = e.length * 2, r = new ArrayBuffer(44 + n), i = new DataView(r), a = (e, t) => {
209
+ for (let n = 0; n < t.length; n++) i.setUint8(e + n, t.charCodeAt(n));
210
+ };
211
+ a(0, "RIFF"), i.setUint32(4, 36 + n, !0), a(8, "WAVE"), a(12, "fmt "), i.setUint32(16, 16, !0), i.setUint16(20, 1, !0), i.setUint16(22, 1, !0), i.setUint32(24, t, !0), i.setUint32(28, t * 2, !0), i.setUint16(32, 2, !0), i.setUint16(34, 16, !0), a(36, "data"), i.setUint32(40, n, !0);
212
+ let o = 44;
213
+ for (let t = 0; t < e.length; t++) {
214
+ let n = Math.max(-1, Math.min(1, e[t] ?? 0));
215
+ i.setInt16(o, Math.round(n < 0 ? n * 32768 : n * 32767), !0), o += 2;
216
+ }
217
+ return new Blob([r], { type: "audio/wav" });
218
+ }
219
+ function ue(e, t = 48) {
220
+ if (e.length === 0) return [];
221
+ let n = Math.max(1, Math.floor(e.length / t)), r = [], i = 0;
222
+ for (let a = 0; a < t; a++) {
223
+ let t = a * n, o = Math.min(t + n, e.length), s = 0;
224
+ for (let n = t; n < o; n++) {
225
+ let t = e[n] ?? 0;
226
+ s += t * t;
227
+ }
228
+ let c = o > t ? Math.sqrt(s / (o - t)) : 0;
229
+ r.push(c), c > i && (i = c);
230
+ }
231
+ return r.map((e) => i > 0 ? Math.max(8, Math.min(100, Math.round(e / i * 100))) : 8);
232
+ }
233
+ async function de(e) {
234
+ 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);
235
+ if (!i) return {
236
+ file: new File([e.blob], `voice-message-${t}.${ie(r)}`, { type: r }),
237
+ durationSeconds: n
238
+ };
239
+ let { samples: a, sampleRate: o } = await ce(i);
240
+ return {
241
+ file: new File([le(a, o)], `voice-message-${t}.wav`, { type: "audio/wav" }),
242
+ durationSeconds: Math.max(1, Math.round(i.duration || n)),
243
+ waveform: ue(a)
244
+ };
245
+ }
246
+ //#endregion
247
+ //#region src/event-emitter.ts
248
+ var fe = class {
87
249
  constructor() {
88
250
  this._listeners = {};
89
251
  }
@@ -101,82 +263,82 @@ var a = class {
101
263
  removeAllListeners() {
102
264
  for (let e of Object.keys(this._listeners)) delete this._listeners[e];
103
265
  }
104
- }, c = Object.create(null);
105
- c.open = "0", c.close = "1", c.ping = "2", c.pong = "3", c.message = "4", c.upgrade = "5", c.noop = "6";
106
- var l = Object.create(null);
107
- Object.keys(c).forEach((e) => {
108
- l[c[e]] = e;
266
+ }, v = Object.create(null);
267
+ v.open = "0", v.close = "1", v.ping = "2", v.pong = "3", v.message = "4", v.upgrade = "5", v.noop = "6";
268
+ var y = Object.create(null);
269
+ Object.keys(v).forEach((e) => {
270
+ y[v[e]] = e;
109
271
  });
110
- var u = {
272
+ var b = {
111
273
  type: "error",
112
274
  data: "parser error"
113
- }, d = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", f = typeof ArrayBuffer == "function", p = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, m = ({ type: e, data: t }, n, r) => d && t instanceof Blob ? n ? r(t) : ee(t, r) : f && (t instanceof ArrayBuffer || p(t)) ? n ? r(t) : ee(new Blob([t]), r) : r(c[e] + (t || "")), ee = (e, t) => {
275
+ }, 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) => {
114
276
  let n = new FileReader();
115
277
  return n.onload = function() {
116
278
  let e = n.result.split(",")[1];
117
279
  t("b" + (e || ""));
118
280
  }, n.readAsDataURL(e);
119
281
  };
120
- function te(e) {
282
+ function _e(e) {
121
283
  return e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
122
284
  }
123
- var h;
124
- function ne(e, t) {
125
- if (d && e.data instanceof Blob) return e.data.arrayBuffer().then(te).then(t);
126
- if (f && (e.data instanceof ArrayBuffer || p(e.data))) return t(te(e.data));
127
- m(e, !1, (e) => {
128
- h ||= new TextEncoder(), t(h.encode(e));
285
+ var ve;
286
+ function ye(e, t) {
287
+ if (pe && e.data instanceof Blob) return e.data.arrayBuffer().then(_e).then(t);
288
+ if (me && (e.data instanceof ArrayBuffer || he(e.data))) return t(_e(e.data));
289
+ x(e, !1, (e) => {
290
+ ve ||= new TextEncoder(), t(ve.encode(e));
129
291
  });
130
292
  }
131
293
  //#endregion
132
294
  //#region ../../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
133
- var re = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", g = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
134
- for (let e = 0; e < 64; e++) g[re.charCodeAt(e)] = e;
135
- var ie = (e) => {
295
+ var be = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", S = typeof Uint8Array > "u" ? [] : /* @__PURE__ */ new Uint8Array(256);
296
+ for (let e = 0; e < 64; e++) S[be.charCodeAt(e)] = e;
297
+ var xe = (e) => {
136
298
  let t = e.length * .75, n = e.length, r, i = 0, a, o, s, c;
137
299
  e[e.length - 1] === "=" && (t--, e[e.length - 2] === "=" && t--);
138
300
  let l = new ArrayBuffer(t), u = new Uint8Array(l);
139
- for (r = 0; r < n; r += 4) a = g[e.charCodeAt(r)], o = g[e.charCodeAt(r + 1)], s = g[e.charCodeAt(r + 2)], c = g[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
301
+ 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;
140
302
  return l;
141
- }, ae = typeof ArrayBuffer == "function", _ = (e, t) => {
303
+ }, Se = typeof ArrayBuffer == "function", C = (e, t) => {
142
304
  if (typeof e != "string") return {
143
305
  type: "message",
144
- data: v(e, t)
306
+ data: we(e, t)
145
307
  };
146
308
  let n = e.charAt(0);
147
309
  return n === "b" ? {
148
310
  type: "message",
149
- data: oe(e.substring(1), t)
150
- } : l[n] ? e.length > 1 ? {
151
- type: l[n],
311
+ data: Ce(e.substring(1), t)
312
+ } : y[n] ? e.length > 1 ? {
313
+ type: y[n],
152
314
  data: e.substring(1)
153
- } : { type: l[n] } : u;
154
- }, oe = (e, t) => ae ? v(ie(e), t) : {
315
+ } : { type: y[n] } : b;
316
+ }, Ce = (e, t) => Se ? we(xe(e), t) : {
155
317
  base64: !0,
156
318
  data: e
157
- }, v = (e, t) => {
319
+ }, we = (e, t) => {
158
320
  switch (t) {
159
321
  case "blob": return e instanceof Blob ? e : new Blob([e]);
160
322
  default: return e instanceof ArrayBuffer ? e : e.buffer;
161
323
  }
162
- }, y = "", se = (e, t) => {
324
+ }, Te = "", Ee = (e, t) => {
163
325
  let n = e.length, r = Array(n), i = 0;
164
326
  e.forEach((e, a) => {
165
- m(e, !1, (e) => {
166
- r[a] = e, ++i === n && t(r.join(y));
327
+ x(e, !1, (e) => {
328
+ r[a] = e, ++i === n && t(r.join(Te));
167
329
  });
168
330
  });
169
- }, ce = (e, t) => {
170
- let n = e.split(y), r = [];
331
+ }, De = (e, t) => {
332
+ let n = e.split(Te), r = [];
171
333
  for (let e = 0; e < n.length; e++) {
172
- let i = _(n[e], t);
334
+ let i = C(n[e], t);
173
335
  if (r.push(i), i.type === "error") break;
174
336
  }
175
337
  return r;
176
338
  };
177
- function le() {
339
+ function Oe() {
178
340
  return new TransformStream({ transform(e, t) {
179
- ne(e, (n) => {
341
+ ye(e, (n) => {
180
342
  let r = n.length, i;
181
343
  if (r < 126) i = /* @__PURE__ */ new Uint8Array(1), new DataView(i.buffer).setUint8(0, r);
182
344
  else if (r < 65536) {
@@ -192,44 +354,44 @@ function le() {
192
354
  });
193
355
  } });
194
356
  }
195
- var ue;
196
- function b(e) {
357
+ var ke;
358
+ function w(e) {
197
359
  return e.reduce((e, t) => e + t.length, 0);
198
360
  }
199
- function x(e, t) {
361
+ function T(e, t) {
200
362
  if (e[0].length === t) return e.shift();
201
363
  let n = new Uint8Array(t), r = 0;
202
364
  for (let i = 0; i < t; i++) n[i] = e[0][r++], r === e[0].length && (e.shift(), r = 0);
203
365
  return e.length && r < e[0].length && (e[0] = e[0].slice(r)), n;
204
366
  }
205
- function de(e, t) {
206
- ue ||= new TextDecoder();
367
+ function Ae(e, t) {
368
+ ke ||= new TextDecoder();
207
369
  let n = [], r = 0, i = -1, a = !1;
208
370
  return new TransformStream({ transform(o, s) {
209
371
  for (n.push(o);;) {
210
372
  if (r === 0) {
211
- if (b(n) < 1) break;
212
- let e = x(n, 1);
373
+ if (w(n) < 1) break;
374
+ let e = T(n, 1);
213
375
  a = (e[0] & 128) == 128, i = e[0] & 127, r = i < 126 ? 3 : i === 126 ? 1 : 2;
214
376
  } else if (r === 1) {
215
- if (b(n) < 2) break;
216
- let e = x(n, 2);
377
+ if (w(n) < 2) break;
378
+ let e = T(n, 2);
217
379
  i = new DataView(e.buffer, e.byteOffset, e.length).getUint16(0), r = 3;
218
380
  } else if (r === 2) {
219
- if (b(n) < 8) break;
220
- let e = x(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
381
+ if (w(n) < 8) break;
382
+ let e = T(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
221
383
  if (a > 2 ** 21 - 1) {
222
- s.enqueue(u);
384
+ s.enqueue(b);
223
385
  break;
224
386
  }
225
387
  i = a * 2 ** 32 + t.getUint32(4), r = 3;
226
388
  } else {
227
- if (b(n) < i) break;
228
- let e = x(n, i);
229
- s.enqueue(_(a ? e : ue.decode(e), t)), r = 0;
389
+ if (w(n) < i) break;
390
+ let e = T(n, i);
391
+ s.enqueue(C(a ? e : ke.decode(e), t)), r = 0;
230
392
  }
231
393
  if (i === 0 || i > e) {
232
- s.enqueue(u);
394
+ s.enqueue(b);
233
395
  break;
234
396
  }
235
397
  }
@@ -237,21 +399,21 @@ function de(e, t) {
237
399
  }
238
400
  //#endregion
239
401
  //#region ../../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
240
- function S(e) {
241
- if (e) return fe(e);
402
+ function E(e) {
403
+ if (e) return je(e);
242
404
  }
243
- function fe(e) {
244
- for (var t in S.prototype) e[t] = S.prototype[t];
405
+ function je(e) {
406
+ for (var t in E.prototype) e[t] = E.prototype[t];
245
407
  return e;
246
408
  }
247
- S.prototype.on = S.prototype.addEventListener = function(e, t) {
409
+ E.prototype.on = E.prototype.addEventListener = function(e, t) {
248
410
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + e] = this._callbacks["$" + e] || []).push(t), this;
249
- }, S.prototype.once = function(e, t) {
411
+ }, E.prototype.once = function(e, t) {
250
412
  function n() {
251
413
  this.off(e, n), t.apply(this, arguments);
252
414
  }
253
415
  return n.fn = t, this.on(e, n), this;
254
- }, S.prototype.off = S.prototype.removeListener = S.prototype.removeAllListeners = S.prototype.removeEventListener = function(e, t) {
416
+ }, E.prototype.off = E.prototype.removeListener = E.prototype.removeAllListeners = E.prototype.removeEventListener = function(e, t) {
255
417
  if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
256
418
  var n = this._callbacks["$" + e];
257
419
  if (!n) return this;
@@ -261,7 +423,7 @@ S.prototype.on = S.prototype.addEventListener = function(e, t) {
261
423
  break;
262
424
  }
263
425
  return n.length === 0 && delete this._callbacks["$" + e], this;
264
- }, S.prototype.emit = function(e) {
426
+ }, E.prototype.emit = function(e) {
265
427
  this._callbacks = this._callbacks || {};
266
428
  for (var t = Array(arguments.length - 1), n = this._callbacks["$" + e], r = 1; r < arguments.length; r++) t[r - 1] = arguments[r];
267
429
  if (n) {
@@ -269,43 +431,43 @@ S.prototype.on = S.prototype.addEventListener = function(e, t) {
269
431
  for (var r = 0, i = n.length; r < i; ++r) n[r].apply(this, t);
270
432
  }
271
433
  return this;
272
- }, S.prototype.emitReserved = S.prototype.emit, S.prototype.listeners = function(e) {
434
+ }, E.prototype.emitReserved = E.prototype.emit, E.prototype.listeners = function(e) {
273
435
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + e] || [];
274
- }, S.prototype.hasListeners = function(e) {
436
+ }, E.prototype.hasListeners = function(e) {
275
437
  return !!this.listeners(e).length;
276
438
  };
277
439
  //#endregion
278
440
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/globals.js
279
- var C = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), w = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), pe = "arraybuffer";
441
+ 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";
280
442
  //#endregion
281
443
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/util.js
282
- function me(e, ...t) {
444
+ function Ne(e, ...t) {
283
445
  return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
284
446
  }
285
- var he = w.setTimeout, ge = w.clearTimeout;
286
- function T(e, t) {
287
- t.useNativeTimers ? (e.setTimeoutFn = he.bind(w), e.clearTimeoutFn = ge.bind(w)) : (e.setTimeoutFn = w.setTimeout.bind(w), e.clearTimeoutFn = w.clearTimeout.bind(w));
447
+ var Pe = O.setTimeout, Fe = O.clearTimeout;
448
+ function k(e, t) {
449
+ t.useNativeTimers ? (e.setTimeoutFn = Pe.bind(O), e.clearTimeoutFn = Fe.bind(O)) : (e.setTimeoutFn = O.setTimeout.bind(O), e.clearTimeoutFn = O.clearTimeout.bind(O));
288
450
  }
289
- var _e = 1.33;
290
- function ve(e) {
291
- return typeof e == "string" ? ye(e) : Math.ceil((e.byteLength || e.size) * _e);
451
+ var Ie = 1.33;
452
+ function Le(e) {
453
+ return typeof e == "string" ? Re(e) : Math.ceil((e.byteLength || e.size) * Ie);
292
454
  }
293
- function ye(e) {
455
+ function Re(e) {
294
456
  let t = 0, n = 0;
295
457
  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);
296
458
  return n;
297
459
  }
298
- function be() {
460
+ function ze() {
299
461
  return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
300
462
  }
301
463
  //#endregion
302
464
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/contrib/parseqs.js
303
- function xe(e) {
465
+ function Be(e) {
304
466
  let t = "";
305
467
  for (let n in e) e.hasOwnProperty(n) && (t.length && (t += "&"), t += encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
306
468
  return t;
307
469
  }
308
- function Se(e) {
470
+ function Ve(e) {
309
471
  let t = {}, n = e.split("&");
310
472
  for (let e = 0, r = n.length; e < r; e++) {
311
473
  let r = n[e].split("=");
@@ -315,16 +477,16 @@ function Se(e) {
315
477
  }
316
478
  //#endregion
317
479
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transport.js
318
- var Ce = class extends Error {
480
+ var He = class extends Error {
319
481
  constructor(e, t, n) {
320
482
  super(e), this.description = t, this.context = n, this.type = "TransportError";
321
483
  }
322
- }, E = class extends S {
484
+ }, A = class extends E {
323
485
  constructor(e) {
324
- super(), this.writable = !1, T(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
486
+ super(), this.writable = !1, k(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
325
487
  }
326
488
  onError(e, t, n) {
327
- return super.emitReserved("error", new Ce(e, t, n)), this;
489
+ return super.emitReserved("error", new He(e, t, n)), this;
328
490
  }
329
491
  open() {
330
492
  return this.readyState = "opening", this.doOpen(), this;
@@ -339,7 +501,7 @@ var Ce = class extends Error {
339
501
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
340
502
  }
341
503
  onData(e) {
342
- let t = _(e, this.socket.binaryType);
504
+ let t = C(e, this.socket.binaryType);
343
505
  this.onPacket(t);
344
506
  }
345
507
  onPacket(e) {
@@ -360,10 +522,10 @@ var Ce = class extends Error {
360
522
  return this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80) ? ":" + this.opts.port : "";
361
523
  }
362
524
  _query(e) {
363
- let t = xe(e);
525
+ let t = Be(e);
364
526
  return t.length ? "?" + t : "";
365
527
  }
366
- }, we = class extends E {
528
+ }, Ue = class extends A {
367
529
  constructor() {
368
530
  super(...arguments), this._polling = !1;
369
531
  }
@@ -391,7 +553,7 @@ var Ce = class extends Error {
391
553
  this._polling = !0, this.doPoll(), this.emitReserved("poll");
392
554
  }
393
555
  onData(e) {
394
- ce(e, this.socket.binaryType).forEach((e) => {
556
+ De(e, this.socket.binaryType).forEach((e) => {
395
557
  if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
396
558
  this.onPacket(e);
397
559
  }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
@@ -403,7 +565,7 @@ var Ce = class extends Error {
403
565
  this.readyState === "open" ? e() : this.once("open", e);
404
566
  }
405
567
  write(e) {
406
- this.writable = !1, se(e, (e) => {
568
+ this.writable = !1, Ee(e, (e) => {
407
569
  this.doWrite(e, () => {
408
570
  this.writable = !0, this.emitReserved("drain");
409
571
  });
@@ -411,17 +573,17 @@ var Ce = class extends Error {
411
573
  }
412
574
  uri() {
413
575
  let e = this.opts.secure ? "https" : "http", t = this.query || {};
414
- return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = be()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
576
+ return !1 !== this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
415
577
  }
416
- }, Te = !1;
578
+ }, We = !1;
417
579
  try {
418
- Te = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
580
+ We = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
419
581
  } catch {}
420
- var Ee = Te;
582
+ var Ge = We;
421
583
  //#endregion
422
584
  //#region ../../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
423
- function De() {}
424
- var Oe = class extends we {
585
+ function Ke() {}
586
+ var qe = class extends Ue {
425
587
  constructor(e) {
426
588
  if (super(e), typeof location < "u") {
427
589
  let t = location.protocol === "https:", n = location.port;
@@ -443,13 +605,13 @@ var Oe = class extends we {
443
605
  this.onError("xhr poll error", e, t);
444
606
  }), this.pollXhr = e;
445
607
  }
446
- }, D = class e extends S {
608
+ }, j = class e extends E {
447
609
  constructor(e, t, n) {
448
- super(), this.createRequest = e, T(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data === void 0 ? null : n.data, this._create();
610
+ 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();
449
611
  }
450
612
  _create() {
451
613
  var t;
452
- let n = me(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
614
+ let n = Ne(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
453
615
  n.xdomain = !!this._opts.xd;
454
616
  let r = this._xhr = this.createRequest(n);
455
617
  try {
@@ -485,7 +647,7 @@ var Oe = class extends we {
485
647
  }
486
648
  _cleanup(t) {
487
649
  if (this._xhr !== void 0 && this._xhr !== null) {
488
- if (this._xhr.onreadystatechange = De, t) try {
650
+ if (this._xhr.onreadystatechange = Ke, t) try {
489
651
  this._xhr.abort();
490
652
  } catch {}
491
653
  typeof document < "u" && delete e.requests[this._index], this._xhr = null;
@@ -499,46 +661,46 @@ var Oe = class extends we {
499
661
  this._cleanup();
500
662
  }
501
663
  };
502
- if (D.requestsCount = 0, D.requests = {}, typeof document < "u") {
503
- if (typeof attachEvent == "function") attachEvent("onunload", O);
664
+ if (j.requestsCount = 0, j.requests = {}, typeof document < "u") {
665
+ if (typeof attachEvent == "function") attachEvent("onunload", Je);
504
666
  else if (typeof addEventListener == "function") {
505
- let e = "onpagehide" in w ? "pagehide" : "unload";
506
- addEventListener(e, O, !1);
667
+ let e = "onpagehide" in O ? "pagehide" : "unload";
668
+ addEventListener(e, Je, !1);
507
669
  }
508
670
  }
509
- function O() {
510
- for (let e in D.requests) D.requests.hasOwnProperty(e) && D.requests[e].abort();
671
+ function Je() {
672
+ for (let e in j.requests) j.requests.hasOwnProperty(e) && j.requests[e].abort();
511
673
  }
512
- var ke = (function() {
513
- let e = je({ xdomain: !1 });
674
+ var Ye = (function() {
675
+ let e = Ze({ xdomain: !1 });
514
676
  return e && e.responseType !== null;
515
- })(), Ae = class extends Oe {
677
+ })(), Xe = class extends qe {
516
678
  constructor(e) {
517
679
  super(e);
518
680
  let t = e && e.forceBase64;
519
- this.supportsBinary = ke && !t;
681
+ this.supportsBinary = Ye && !t;
520
682
  }
521
683
  request(e = {}) {
522
- return Object.assign(e, { xd: this.xd }, this.opts), new D(je, this.uri(), e);
684
+ return Object.assign(e, { xd: this.xd }, this.opts), new j(Ze, this.uri(), e);
523
685
  }
524
686
  };
525
- function je(e) {
687
+ function Ze(e) {
526
688
  let t = e.xdomain;
527
689
  try {
528
- if (typeof XMLHttpRequest < "u" && (!t || Ee)) return new XMLHttpRequest();
690
+ if (typeof XMLHttpRequest < "u" && (!t || Ge)) return new XMLHttpRequest();
529
691
  } catch {}
530
692
  if (!t) try {
531
- return new w[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
693
+ return new O[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
532
694
  } catch {}
533
695
  }
534
696
  //#endregion
535
697
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/transports/websocket.js
536
- var Me = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", Ne = class extends E {
698
+ var Qe = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative", $e = class extends A {
537
699
  get name() {
538
700
  return "websocket";
539
701
  }
540
702
  doOpen() {
541
- let e = this.uri(), t = this.opts.protocols, n = Me ? {} : me(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
703
+ 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");
542
704
  this.opts.extraHeaders && (n.headers = this.opts.extraHeaders);
543
705
  try {
544
706
  this.ws = this.createSocket(e, t, n);
@@ -559,11 +721,11 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
559
721
  this.writable = !1;
560
722
  for (let t = 0; t < e.length; t++) {
561
723
  let n = e[t], r = t === e.length - 1;
562
- m(n, this.supportsBinary, (e) => {
724
+ x(n, this.supportsBinary, (e) => {
563
725
  try {
564
726
  this.doWrite(n, e);
565
727
  } catch {}
566
- r && C(() => {
728
+ r && D(() => {
567
729
  this.writable = !0, this.emitReserved("drain");
568
730
  }, this.setTimeoutFn);
569
731
  });
@@ -574,18 +736,18 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
574
736
  }
575
737
  uri() {
576
738
  let e = this.opts.secure ? "wss" : "ws", t = this.query || {};
577
- return this.opts.timestampRequests && (t[this.opts.timestampParam] = be()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
739
+ return this.opts.timestampRequests && (t[this.opts.timestampParam] = ze()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
578
740
  }
579
- }, k = w.WebSocket || w.MozWebSocket, Pe = {
580
- websocket: class extends Ne {
741
+ }, M = O.WebSocket || O.MozWebSocket, et = {
742
+ websocket: class extends $e {
581
743
  createSocket(e, t, n) {
582
- return Me ? new k(e, t, n) : t ? new k(e, t) : new k(e);
744
+ return Qe ? new M(e, t, n) : t ? new M(e, t) : new M(e);
583
745
  }
584
746
  doWrite(e, t) {
585
747
  this.ws.send(t);
586
748
  }
587
749
  },
588
- webtransport: class extends E {
750
+ webtransport: class extends A {
589
751
  get name() {
590
752
  return "webtransport";
591
753
  }
@@ -601,7 +763,7 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
601
763
  this.onError("webtransport error", e);
602
764
  }), this._transport.ready.then(() => {
603
765
  this._transport.createBidirectionalStream().then((e) => {
604
- let t = de(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = le();
766
+ let t = Ae(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = Oe();
605
767
  r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
606
768
  let i = () => {
607
769
  n.read().then(({ done: e, value: t }) => {
@@ -619,7 +781,7 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
619
781
  for (let t = 0; t < e.length; t++) {
620
782
  let n = e[t], r = t === e.length - 1;
621
783
  this._writer.write(n).then(() => {
622
- r && C(() => {
784
+ r && D(() => {
623
785
  this.writable = !0, this.emitReserved("drain");
624
786
  }, this.setTimeoutFn);
625
787
  });
@@ -630,8 +792,8 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
630
792
  (e = this._transport) == null || e.close();
631
793
  }
632
794
  },
633
- polling: Ae
634
- }, Fe = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, Ie = [
795
+ polling: Xe
796
+ }, tt = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, nt = [
635
797
  "source",
636
798
  "protocol",
637
799
  "authority",
@@ -647,19 +809,19 @@ var Me = typeof navigator < "u" && typeof navigator.product == "string" && navig
647
809
  "query",
648
810
  "anchor"
649
811
  ];
650
- function A(e) {
812
+ function N(e) {
651
813
  if (e.length > 8e3) throw "URI too long";
652
814
  let t = e, n = e.indexOf("["), r = e.indexOf("]");
653
815
  n != -1 && r != -1 && (e = e.substring(0, n) + e.substring(n, r).replace(/:/g, ";") + e.substring(r, e.length));
654
- let i = Fe.exec(e || ""), a = {}, o = 14;
655
- for (; o--;) a[Ie[o]] = i[o] || "";
656
- 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 = Le(a, a.path), a.queryKey = Re(a, a.query), a;
816
+ let i = tt.exec(e || ""), a = {}, o = 14;
817
+ for (; o--;) a[nt[o]] = i[o] || "";
818
+ 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;
657
819
  }
658
- function Le(e, t) {
820
+ function rt(e, t) {
659
821
  let n = t.replace(/\/{2,9}/g, "/").split("/");
660
822
  return (t.slice(0, 1) == "/" || t.length === 0) && n.splice(0, 1), t.slice(-1) == "/" && n.splice(n.length - 1, 1), n;
661
823
  }
662
- function Re(e, t) {
824
+ function it(e, t) {
663
825
  let n = {};
664
826
  return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(e, t, r) {
665
827
  t && (n[t] = r);
@@ -667,17 +829,17 @@ function Re(e, t) {
667
829
  }
668
830
  //#endregion
669
831
  //#region ../../node_modules/.pnpm/engine.io-client@6.6.6_supports-color@8.1.1/node_modules/engine.io-client/build/esm/socket.js
670
- var j = typeof addEventListener == "function" && typeof removeEventListener == "function", M = [];
671
- j && addEventListener("offline", () => {
672
- M.forEach((e) => e());
832
+ var P = typeof addEventListener == "function" && typeof removeEventListener == "function", F = [];
833
+ P && addEventListener("offline", () => {
834
+ F.forEach((e) => e());
673
835
  }, !1);
674
- var N = class e extends S {
836
+ var I = class e extends E {
675
837
  constructor(e, t) {
676
- if (super(), this.binaryType = pe, 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) {
677
- let n = A(e);
838
+ 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) {
839
+ let n = N(e);
678
840
  t.hostname = n.host, t.secure = n.protocol === "https" || n.protocol === "wss", t.port = n.port, n.query && (t.query = n.query);
679
- } else t.host && (t.hostname = A(t.host).host);
680
- T(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) => {
841
+ } else t.host && (t.hostname = N(t.host).host);
842
+ 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) => {
681
843
  let t = e.prototype.name;
682
844
  this.transports.push(t), this._transportsByName[t] = e;
683
845
  }), this.opts = Object.assign({
@@ -692,11 +854,11 @@ var N = class e extends S {
692
854
  perMessageDeflate: { threshold: 1024 },
693
855
  transportOptions: {},
694
856
  closeOnBeforeunload: !1
695
- }, t), this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : ""), typeof this.opts.query == "string" && (this.opts.query = Se(this.opts.query)), j && (this.opts.closeOnBeforeunload && (this._beforeunloadEventListener = () => {
857
+ }, 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 = () => {
696
858
  this.transport && (this.transport.removeAllListeners(), this.transport.close());
697
859
  }, addEventListener("beforeunload", this._beforeunloadEventListener, !1)), this.hostname !== "localhost" && (this._offlineEventListener = () => {
698
860
  this._onClose("transport close", { description: "network connection lost" });
699
- }, M.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
861
+ }, F.push(this._offlineEventListener))), this.opts.withCredentials && (this._cookieJar = void 0), this._open();
700
862
  }
701
863
  createTransport(e) {
702
864
  let t = Object.assign({}, this.opts.query);
@@ -767,7 +929,7 @@ var N = class e extends S {
767
929
  let e = 1;
768
930
  for (let t = 0; t < this.writeBuffer.length; t++) {
769
931
  let n = this.writeBuffer[t].data;
770
- if (n && (e += ve(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
932
+ if (n && (e += Le(n)), t > 0 && e > this._maxPayload) return this.writeBuffer.slice(0, t);
771
933
  e += 2;
772
934
  }
773
935
  return this.writeBuffer;
@@ -775,7 +937,7 @@ var N = class e extends S {
775
937
  _hasPingExpired() {
776
938
  if (!this._pingTimeoutTime) return !0;
777
939
  let e = Date.now() > this._pingTimeoutTime;
778
- return e && (this._pingTimeoutTime = 0, C(() => {
940
+ return e && (this._pingTimeoutTime = 0, D(() => {
779
941
  this._onClose("ping timeout");
780
942
  }, this.setTimeoutFn)), e;
781
943
  }
@@ -813,16 +975,16 @@ var N = class e extends S {
813
975
  }
814
976
  _onClose(e, t) {
815
977
  if (this.readyState === "opening" || this.readyState === "open" || this.readyState === "closing") {
816
- if (this.clearTimeoutFn(this._pingTimeoutTimer), this.transport.removeAllListeners("close"), this.transport.close(), this.transport.removeAllListeners(), j && (this._beforeunloadEventListener && removeEventListener("beforeunload", this._beforeunloadEventListener, !1), this._offlineEventListener)) {
817
- let e = M.indexOf(this._offlineEventListener);
818
- e !== -1 && M.splice(e, 1);
978
+ 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)) {
979
+ let e = F.indexOf(this._offlineEventListener);
980
+ e !== -1 && F.splice(e, 1);
819
981
  }
820
982
  this.readyState = "closed", this.id = null, this.emitReserved("close", e, t), this.writeBuffer = [], this._prevBufferLen = 0;
821
983
  }
822
984
  }
823
985
  };
824
- N.protocol = 4;
825
- var ze = class extends N {
986
+ I.protocol = 4;
987
+ var at = class extends I {
826
988
  constructor() {
827
989
  super(...arguments), this._upgrades = [];
828
990
  }
@@ -831,7 +993,7 @@ var ze = class extends N {
831
993
  }
832
994
  _probe(e) {
833
995
  let t = this.createTransport(e), n = !1;
834
- N.priorWebsocketSuccess = !1;
996
+ I.priorWebsocketSuccess = !1;
835
997
  let r = () => {
836
998
  n || (t.send([{
837
999
  type: "ping",
@@ -840,7 +1002,7 @@ var ze = class extends N {
840
1002
  if (!n) {
841
1003
  if (e.type === "pong" && e.data === "probe") {
842
1004
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t) return;
843
- N.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1005
+ I.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
844
1006
  n || this.readyState !== "closed" && (l(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
845
1007
  });
846
1008
  } else {
@@ -881,54 +1043,54 @@ var ze = class extends N {
881
1043
  for (let n = 0; n < e.length; n++) ~this.transports.indexOf(e[n]) && t.push(e[n]);
882
1044
  return t;
883
1045
  }
884
- }, Be = class extends ze {
1046
+ }, ot = class extends at {
885
1047
  constructor(e, t = {}) {
886
1048
  let n = typeof e == "object", r = n ? { ...e } : { ...t };
887
1049
  (!r.transports || r.transports && typeof r.transports[0] == "string") && (r.transports = (r.transports || [
888
1050
  "polling",
889
1051
  "websocket",
890
1052
  "webtransport"
891
- ]).map((e) => Pe[e]).filter((e) => !!e)), super(n ? r : e, r);
1053
+ ]).map((e) => et[e]).filter((e) => !!e)), super(n ? r : e, r);
892
1054
  }
893
1055
  };
894
- Be.protocol;
1056
+ ot.protocol;
895
1057
  //#endregion
896
1058
  //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/url.js
897
- function Ve(e, t = "", n) {
1059
+ function st(e, t = "", n) {
898
1060
  let r = e;
899
- 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 = A(e)), r.port || (/^(http|ws)$/.test(r.protocol) ? r.port = "80" : /^(http|ws)s$/.test(r.protocol) && (r.port = "443")), r.path = r.path || "/";
1061
+ 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 || "/";
900
1062
  let i = r.host.indexOf(":") === -1 ? r.host : "[" + r.host + "]";
901
1063
  return r.id = r.protocol + "://" + i + ":" + r.port + t, r.href = r.protocol + "://" + i + (n && n.port === r.port ? "" : ":" + r.port), r;
902
1064
  }
903
1065
  //#endregion
904
1066
  //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/is-binary.js
905
- var He = typeof ArrayBuffer == "function", Ue = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e.buffer instanceof ArrayBuffer, P = Object.prototype.toString, We = typeof Blob == "function" || typeof Blob < "u" && P.call(Blob) === "[object BlobConstructor]", Ge = typeof File == "function" || typeof File < "u" && P.call(File) === "[object FileConstructor]";
906
- function F(e) {
907
- return He && (e instanceof ArrayBuffer || Ue(e)) || We && e instanceof Blob || Ge && e instanceof File;
1067
+ 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]";
1068
+ function L(e) {
1069
+ return ct && (e instanceof ArrayBuffer || lt(e)) || dt && e instanceof Blob || ft && e instanceof File;
908
1070
  }
909
- function I(e, t) {
1071
+ function R(e, t) {
910
1072
  if (!e || typeof e != "object") return !1;
911
1073
  if (Array.isArray(e)) {
912
- for (let t = 0, n = e.length; t < n; t++) if (I(e[t])) return !0;
1074
+ for (let t = 0, n = e.length; t < n; t++) if (R(e[t])) return !0;
913
1075
  return !1;
914
1076
  }
915
- if (F(e)) return !0;
916
- if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return I(e.toJSON(), !0);
917
- for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && I(e[t])) return !0;
1077
+ if (L(e)) return !0;
1078
+ if (e.toJSON && typeof e.toJSON == "function" && arguments.length === 1) return R(e.toJSON(), !0);
1079
+ for (let t in e) if (Object.prototype.hasOwnProperty.call(e, t) && R(e[t])) return !0;
918
1080
  return !1;
919
1081
  }
920
1082
  //#endregion
921
1083
  //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/binary.js
922
- function Ke(e) {
1084
+ function pt(e) {
923
1085
  let t = [], n = e.data, r = e;
924
- return r.data = L(n, t), r.attachments = t.length, {
1086
+ return r.data = z(n, t), r.attachments = t.length, {
925
1087
  packet: r,
926
1088
  buffers: t
927
1089
  };
928
1090
  }
929
- function L(e, t, n) {
1091
+ function z(e, t, n) {
930
1092
  if (!e) return e;
931
- if (F(e)) {
1093
+ if (L(e)) {
932
1094
  let n = {
933
1095
  _placeholder: !0,
934
1096
  num: t.length
@@ -937,56 +1099,56 @@ function L(e, t, n) {
937
1099
  }
938
1100
  if (Array.isArray(e)) {
939
1101
  let n = Array(e.length);
940
- for (let r = 0; r < e.length; r++) n[r] = L(e[r], t);
1102
+ for (let r = 0; r < e.length; r++) n[r] = z(e[r], t);
941
1103
  return n;
942
1104
  }
943
1105
  if (typeof e == "object" && !(e instanceof Date)) {
944
- if (e.toJSON && typeof e.toJSON == "function" && !n) return L(e.toJSON(), t, !0);
1106
+ if (e.toJSON && typeof e.toJSON == "function" && !n) return z(e.toJSON(), t, !0);
945
1107
  let r = {};
946
- for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = L(e[n], t));
1108
+ for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (r[n] = z(e[n], t));
947
1109
  return r;
948
1110
  }
949
1111
  return e;
950
1112
  }
951
- function qe(e, t) {
952
- return e.data = R(e.data, t), delete e.attachments, e;
1113
+ function mt(e, t) {
1114
+ return e.data = B(e.data, t), delete e.attachments, e;
953
1115
  }
954
- function R(e, t) {
1116
+ function B(e, t) {
955
1117
  if (!e) return e;
956
1118
  if (e && e._placeholder === !0) {
957
1119
  if (typeof e.num == "number" && e.num >= 0 && e.num < t.length) return t[e.num];
958
1120
  throw Error("illegal attachments");
959
1121
  }
960
- if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = R(e[n], t);
961
- else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = R(e[n], t));
1122
+ if (Array.isArray(e)) for (let n = 0; n < e.length; n++) e[n] = B(e[n], t);
1123
+ else if (typeof e == "object") for (let n in e) Object.prototype.hasOwnProperty.call(e, n) && (e[n] = B(e[n], t));
962
1124
  return e;
963
1125
  }
964
1126
  //#endregion
965
1127
  //#region ../../node_modules/.pnpm/socket.io-parser@4.2.7_supports-color@8.1.1/node_modules/socket.io-parser/build/esm/index.js
966
- var Je = /* @__PURE__ */ t({
967
- Decoder: () => Xe,
968
- Encoder: () => Ye,
969
- PacketType: () => B,
970
- isPacketValid: () => tt,
1128
+ var ht = /* @__PURE__ */ t({
1129
+ Decoder: () => vt,
1130
+ Encoder: () => _t,
1131
+ PacketType: () => V,
1132
+ isPacketValid: () => wt,
971
1133
  protocol: () => 5
972
- }), z = [
1134
+ }), gt = [
973
1135
  "connect",
974
1136
  "connect_error",
975
1137
  "disconnect",
976
1138
  "disconnecting",
977
1139
  "newListener",
978
1140
  "removeListener"
979
- ], B;
1141
+ ], V;
980
1142
  (function(e) {
981
1143
  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";
982
- })(B ||= {});
983
- var Ye = class {
1144
+ })(V ||= {});
1145
+ var _t = class {
984
1146
  constructor(e) {
985
1147
  this.replacer = e;
986
1148
  }
987
1149
  encode(e) {
988
- return (e.type === B.EVENT || e.type === B.ACK) && I(e) ? this.encodeAsBinary({
989
- type: e.type === B.EVENT ? B.BINARY_EVENT : B.BINARY_ACK,
1150
+ return (e.type === V.EVENT || e.type === V.ACK) && R(e) ? this.encodeAsBinary({
1151
+ type: e.type === V.EVENT ? V.BINARY_EVENT : V.BINARY_ACK,
990
1152
  nsp: e.nsp,
991
1153
  data: e.data,
992
1154
  id: e.id
@@ -994,13 +1156,13 @@ var Ye = class {
994
1156
  }
995
1157
  encodeAsString(e) {
996
1158
  let t = "" + e.type;
997
- return (e.type === B.BINARY_EVENT || e.type === B.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;
1159
+ 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;
998
1160
  }
999
1161
  encodeAsBinary(e) {
1000
- let t = Ke(e), n = this.encodeAsString(t.packet), r = t.buffers;
1162
+ let t = pt(e), n = this.encodeAsString(t.packet), r = t.buffers;
1001
1163
  return r.unshift(n), r;
1002
1164
  }
1003
- }, Xe = class e extends S {
1165
+ }, vt = class e extends E {
1004
1166
  constructor(e) {
1005
1167
  super(), this.opts = Object.assign({
1006
1168
  reviver: void 0,
@@ -1012,23 +1174,23 @@ var Ye = class {
1012
1174
  if (typeof e == "string") {
1013
1175
  if (this.reconstructor) throw Error("got plaintext data when reconstructing a packet");
1014
1176
  t = this.decodeString(e);
1015
- let n = t.type === B.BINARY_EVENT;
1016
- n || t.type === B.BINARY_ACK ? (t.type = n ? B.EVENT : B.ACK, this.reconstructor = new Ze(t)) : super.emitReserved("decoded", t);
1017
- } else if (F(e) || e.base64) {
1177
+ let n = t.type === V.BINARY_EVENT;
1178
+ n || t.type === V.BINARY_ACK ? (t.type = n ? V.EVENT : V.ACK, this.reconstructor = new yt(t)) : super.emitReserved("decoded", t);
1179
+ } else if (L(e) || e.base64) {
1018
1180
  if (this.reconstructor) t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
1019
1181
  else throw Error("got binary data when not reconstructing a packet");
1020
1182
  } else throw Error("Unknown type: " + e);
1021
1183
  }
1022
1184
  decodeString(t) {
1023
1185
  let n = 0, r = { type: Number(t.charAt(0)) };
1024
- if (B[r.type] === void 0) throw Error("unknown packet type " + r.type);
1025
- if (r.type === B.BINARY_EVENT || r.type === B.BINARY_ACK) {
1186
+ if (V[r.type] === void 0) throw Error("unknown packet type " + r.type);
1187
+ if (r.type === V.BINARY_EVENT || r.type === V.BINARY_ACK) {
1026
1188
  let e = n + 1;
1027
1189
  for (; t.charAt(++n) !== "-" && n != t.length;);
1028
1190
  let i = t.substring(e, n);
1029
1191
  if (i != Number(i) || t.charAt(n) !== "-") throw Error("Illegal attachments");
1030
1192
  let a = Number(i);
1031
- if (!V(a) || a < 1) throw Error("Illegal attachments");
1193
+ if (!xt(a) || a < 1) throw Error("Illegal attachments");
1032
1194
  if (a > this.opts.maxAttachments) throw Error("too many attachments");
1033
1195
  r.attachments = a;
1034
1196
  }
@@ -1066,25 +1228,25 @@ var Ye = class {
1066
1228
  }
1067
1229
  static isPayloadValid(e, t) {
1068
1230
  switch (e) {
1069
- case B.CONNECT: return H(t);
1070
- case B.DISCONNECT: return t === void 0;
1071
- case B.CONNECT_ERROR: return typeof t == "string" || H(t);
1072
- case B.EVENT:
1073
- case B.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && z.indexOf(t[0]) === -1);
1074
- case B.ACK:
1075
- case B.BINARY_ACK: return Array.isArray(t);
1231
+ case V.CONNECT: return H(t);
1232
+ case V.DISCONNECT: return t === void 0;
1233
+ case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1234
+ case V.EVENT:
1235
+ case V.BINARY_EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1236
+ case V.ACK:
1237
+ case V.BINARY_ACK: return Array.isArray(t);
1076
1238
  }
1077
1239
  }
1078
1240
  destroy() {
1079
1241
  this.reconstructor &&= (this.reconstructor.finishedReconstruction(), null);
1080
1242
  }
1081
- }, Ze = class {
1243
+ }, yt = class {
1082
1244
  constructor(e) {
1083
1245
  this.packet = e, this.buffers = [], this.reconPack = e;
1084
1246
  }
1085
1247
  takeBinaryData(e) {
1086
1248
  if (this.buffers.push(e), this.buffers.length === this.reconPack.attachments) {
1087
- let e = qe(this.reconPack, this.buffers);
1249
+ let e = mt(this.reconPack, this.buffers);
1088
1250
  return this.finishedReconstruction(), e;
1089
1251
  }
1090
1252
  return null;
@@ -1093,30 +1255,30 @@ var Ye = class {
1093
1255
  this.reconPack = null, this.buffers = [];
1094
1256
  }
1095
1257
  };
1096
- function Qe(e) {
1258
+ function bt(e) {
1097
1259
  return typeof e == "string";
1098
1260
  }
1099
- var V = Number.isInteger || function(e) {
1261
+ var xt = Number.isInteger || function(e) {
1100
1262
  return typeof e == "number" && isFinite(e) && Math.floor(e) === e;
1101
1263
  };
1102
- function $e(e) {
1103
- return e === void 0 || V(e);
1264
+ function St(e) {
1265
+ return e === void 0 || xt(e);
1104
1266
  }
1105
1267
  function H(e) {
1106
1268
  return Object.prototype.toString.call(e) === "[object Object]";
1107
1269
  }
1108
- function et(e, t) {
1270
+ function Ct(e, t) {
1109
1271
  switch (e) {
1110
- case B.CONNECT: return t === void 0 || H(t);
1111
- case B.DISCONNECT: return t === void 0;
1112
- case B.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && z.indexOf(t[0]) === -1);
1113
- case B.ACK: return Array.isArray(t);
1114
- case B.CONNECT_ERROR: return typeof t == "string" || H(t);
1272
+ case V.CONNECT: return t === void 0 || H(t);
1273
+ case V.DISCONNECT: return t === void 0;
1274
+ case V.EVENT: return Array.isArray(t) && (typeof t[0] == "number" || typeof t[0] == "string" && gt.indexOf(t[0]) === -1);
1275
+ case V.ACK: return Array.isArray(t);
1276
+ case V.CONNECT_ERROR: return typeof t == "string" || H(t);
1115
1277
  default: return !1;
1116
1278
  }
1117
1279
  }
1118
- function tt(e) {
1119
- return Qe(e.nsp) && $e(e.id) && et(e.type, e.data);
1280
+ function wt(e) {
1281
+ return bt(e.nsp) && St(e.id) && Ct(e.type, e.data);
1120
1282
  }
1121
1283
  //#endregion
1122
1284
  //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/on.js
@@ -1127,14 +1289,14 @@ function U(e, t, n) {
1127
1289
  }
1128
1290
  //#endregion
1129
1291
  //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/socket.js
1130
- var nt = Object.freeze({
1292
+ var Tt = Object.freeze({
1131
1293
  connect: 1,
1132
1294
  connect_error: 1,
1133
1295
  disconnect: 1,
1134
1296
  disconnecting: 1,
1135
1297
  newListener: 1,
1136
1298
  removeListener: 1
1137
- }), rt = class extends S {
1299
+ }), Et = class extends E {
1138
1300
  constructor(e, t, n) {
1139
1301
  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();
1140
1302
  }
@@ -1164,10 +1326,10 @@ var nt = Object.freeze({
1164
1326
  return e.unshift("message"), this.emit.apply(this, e), this;
1165
1327
  }
1166
1328
  emit(e, ...t) {
1167
- if (nt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1329
+ if (Tt.hasOwnProperty(e)) throw Error("\"" + e.toString() + "\" is a reserved event name");
1168
1330
  if (t.unshift(e), this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) return this._addToQueue(t), this;
1169
1331
  let n = {
1170
- type: B.EVENT,
1332
+ type: V.EVENT,
1171
1333
  data: t
1172
1334
  };
1173
1335
  if (n.options = {}, n.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
@@ -1225,7 +1387,7 @@ var nt = Object.freeze({
1225
1387
  }
1226
1388
  _sendConnectPacket(e) {
1227
1389
  this.packet({
1228
- type: B.CONNECT,
1390
+ type: V.CONNECT,
1229
1391
  data: this._pid ? Object.assign({
1230
1392
  pid: this._pid,
1231
1393
  offset: this._lastOffset
@@ -1248,21 +1410,21 @@ var nt = Object.freeze({
1248
1410
  }
1249
1411
  onpacket(e) {
1250
1412
  if (e.nsp === this.nsp) switch (e.type) {
1251
- case B.CONNECT:
1413
+ case V.CONNECT:
1252
1414
  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/)"));
1253
1415
  break;
1254
- case B.EVENT:
1255
- case B.BINARY_EVENT:
1416
+ case V.EVENT:
1417
+ case V.BINARY_EVENT:
1256
1418
  this.onevent(e);
1257
1419
  break;
1258
- case B.ACK:
1259
- case B.BINARY_ACK:
1420
+ case V.ACK:
1421
+ case V.BINARY_ACK:
1260
1422
  this.onack(e);
1261
1423
  break;
1262
- case B.DISCONNECT:
1424
+ case V.DISCONNECT:
1263
1425
  this.ondisconnect();
1264
1426
  break;
1265
- case B.CONNECT_ERROR:
1427
+ case V.CONNECT_ERROR:
1266
1428
  this.destroy();
1267
1429
  let t = Error(e.data.message);
1268
1430
  t.data = e.data.data, this.emitReserved("connect_error", t);
@@ -1283,7 +1445,7 @@ var nt = Object.freeze({
1283
1445
  let t = this, n = !1;
1284
1446
  return function(...r) {
1285
1447
  n || (n = !0, t.packet({
1286
- type: B.ACK,
1448
+ type: V.ACK,
1287
1449
  id: e,
1288
1450
  data: r
1289
1451
  }));
@@ -1308,7 +1470,7 @@ var nt = Object.freeze({
1308
1470
  this.subs &&= (this.subs.forEach((e) => e()), void 0), this.io._destroy(this);
1309
1471
  }
1310
1472
  disconnect() {
1311
- return this.connected && this.packet({ type: B.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1473
+ return this.connected && this.packet({ type: V.DISCONNECT }), this.destroy(), this.connected && this.onclose("io client disconnect"), this;
1312
1474
  }
1313
1475
  close() {
1314
1476
  return this.disconnect();
@@ -1386,14 +1548,14 @@ W.prototype.duration = function() {
1386
1548
  };
1387
1549
  //#endregion
1388
1550
  //#region ../../node_modules/.pnpm/socket.io-client@4.8.4_supports-color@8.1.1/node_modules/socket.io-client/build/esm/manager.js
1389
- var G = class extends S {
1551
+ var G = class extends E {
1390
1552
  constructor(e, t) {
1391
- super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, T(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({
1553
+ 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({
1392
1554
  min: this.reconnectionDelay(),
1393
1555
  max: this.reconnectionDelayMax(),
1394
1556
  jitter: this.randomizationFactor()
1395
1557
  }), this.timeout(t.timeout == null ? 2e4 : t.timeout), this._readyState = "closed", this.uri = e;
1396
- let n = t.parser || Je;
1558
+ let n = t.parser || ht;
1397
1559
  this.encoder = new n.Encoder(), this.decoder = new n.Decoder(), this._autoConnect = t.autoConnect !== !1, this._autoConnect && this.open();
1398
1560
  }
1399
1561
  reconnection(e) {
@@ -1422,7 +1584,7 @@ var G = class extends S {
1422
1584
  }
1423
1585
  open(e) {
1424
1586
  if (~this._readyState.indexOf("open")) return this;
1425
- this.engine = new Be(this.uri, this.opts);
1587
+ this.engine = new ot(this.uri, this.opts);
1426
1588
  let t = this.engine, n = this;
1427
1589
  this._readyState = "opening", this.skipReconnect = !1;
1428
1590
  let r = U(t, "open", function() {
@@ -1459,7 +1621,7 @@ var G = class extends S {
1459
1621
  }
1460
1622
  }
1461
1623
  ondecoded(e) {
1462
- C(() => {
1624
+ D(() => {
1463
1625
  this.emitReserved("packet", e);
1464
1626
  }, this.setTimeoutFn);
1465
1627
  }
@@ -1468,7 +1630,7 @@ var G = class extends S {
1468
1630
  }
1469
1631
  socket(e, t) {
1470
1632
  let n = this.nsps[e];
1471
- return n ? this._autoConnect && !n.active && n.connect() : (n = new rt(this, e, t), this.nsps[e] = n), n;
1633
+ return n ? this._autoConnect && !n.active && n.connect() : (n = new Et(this, e, t), this.nsps[e] = n), n;
1472
1634
  }
1473
1635
  _destroy(e) {
1474
1636
  let t = Object.keys(this.nsps);
@@ -1516,18 +1678,18 @@ var G = class extends S {
1516
1678
  }, K = {};
1517
1679
  function q(e, t) {
1518
1680
  typeof e == "object" && (t = e, e = void 0), t ||= {};
1519
- let n = Ve(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;
1681
+ 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;
1520
1682
  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);
1521
1683
  }
1522
1684
  Object.assign(q, {
1523
1685
  Manager: G,
1524
- Socket: rt,
1686
+ Socket: Et,
1525
1687
  io: q,
1526
1688
  connect: q
1527
1689
  });
1528
1690
  //#endregion
1529
1691
  //#region src/sdk-socket.ts
1530
- function it(e) {
1692
+ function Dt(e) {
1531
1693
  let t = e.replace(/\/$/, "");
1532
1694
  try {
1533
1695
  return `${new URL(t).origin}/sdk`;
@@ -1535,7 +1697,7 @@ function it(e) {
1535
1697
  return `${t}/sdk`;
1536
1698
  }
1537
1699
  }
1538
- var at = class {
1700
+ var Ot = class {
1539
1701
  constructor() {
1540
1702
  this.socket = null;
1541
1703
  }
@@ -1544,7 +1706,7 @@ var at = class {
1544
1706
  }
1545
1707
  connect(e) {
1546
1708
  this.disconnect();
1547
- let t = it(e.baseUrl);
1709
+ let t = Dt(e.baseUrl);
1548
1710
  this.socket = q(t, {
1549
1711
  auth: {
1550
1712
  apiKey: e.apiKey,
@@ -1569,40 +1731,181 @@ var at = class {
1569
1731
  this.socket &&= (this.socket.removeAllListeners(), this.socket.disconnect(), null);
1570
1732
  }
1571
1733
  }, J = "onedeskpro_visitor_token";
1572
- function ot(e) {
1734
+ function kt(e) {
1573
1735
  try {
1574
1736
  return typeof window < "u" ? window.localStorage.getItem(e) : null;
1575
1737
  } catch {
1576
1738
  return null;
1577
1739
  }
1578
1740
  }
1579
- function st(e, t) {
1741
+ function At(e, t) {
1580
1742
  try {
1581
1743
  typeof window < "u" && window.localStorage.setItem(e, t);
1582
1744
  } catch {}
1583
1745
  }
1584
- function ct(e) {
1746
+ function jt(e) {
1585
1747
  try {
1586
1748
  typeof window < "u" && window.localStorage.removeItem(e);
1587
1749
  } catch {}
1588
1750
  }
1589
- var lt = class {
1751
+ var Mt = class {
1590
1752
  constructor() {
1591
1753
  this.token = null, this.storageKey = J;
1592
1754
  }
1593
1755
  setScope(e) {
1594
- this.storageKey = e?.trim() ? `${J}:${e.trim()}` : J, this.token = ot(this.storageKey);
1756
+ this.storageKey = e?.trim() ? `${J}:${e.trim()}` : J, this.token = kt(this.storageKey);
1595
1757
  }
1596
1758
  get() {
1597
- return this.token ?? ot(this.storageKey);
1759
+ return this.token ?? kt(this.storageKey);
1598
1760
  }
1599
1761
  set(e) {
1600
- this.token = e, st(this.storageKey, e);
1762
+ this.token = e, At(this.storageKey, e);
1601
1763
  }
1602
1764
  clear() {
1603
- this.token = null, ct(this.storageKey);
1765
+ this.token = null, jt(this.storageKey);
1766
+ }
1767
+ }, Nt = 300, Pt = 250, Ft = 100, It = [
1768
+ "audio/webm;codecs=opus",
1769
+ "audio/webm",
1770
+ "audio/mp4",
1771
+ "audio/ogg;codecs=opus"
1772
+ ];
1773
+ function Lt() {
1774
+ return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? "audio/webm" : It.find((e) => MediaRecorder.isTypeSupported(e)) ?? "audio/webm";
1775
+ }
1776
+ function Rt(e) {
1777
+ let t = e instanceof DOMException ? e.name : "";
1778
+ return t === "NotAllowedError" || t === "PermissionDeniedError" || t === "SecurityError" ? "Microphone access was denied." : t === "NotFoundError" || t === "DevicesNotFoundError" ? "No microphone was found." : "Could not start recording.";
1779
+ }
1780
+ var Y = class e {
1781
+ constructor(e, t = 300) {
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 = {
1783
+ state: "idle",
1784
+ elapsedSeconds: 0,
1785
+ level: 0,
1786
+ result: null
1787
+ };
1788
+ }
1789
+ static isSupported() {
1790
+ return typeof navigator < "u" && typeof navigator.mediaDevices?.getUserMedia == "function" && typeof MediaRecorder < "u";
1604
1791
  }
1605
- }, Y = [
1792
+ getSnapshot() {
1793
+ return { ...this.snapshot };
1794
+ }
1795
+ async start() {
1796
+ if (!e.isSupported()) throw Error("Voice messages are not supported in this browser.");
1797
+ this.release(), this.chunks = [];
1798
+ let t;
1799
+ try {
1800
+ t = await navigator.mediaDevices.getUserMedia({ audio: !0 });
1801
+ } catch (e) {
1802
+ throw Error(Rt(e));
1803
+ }
1804
+ try {
1805
+ this.mimeType = Lt();
1806
+ let e = new MediaRecorder(t, { mimeType: this.mimeType });
1807
+ e.ondataavailable = (e) => {
1808
+ e.data.size > 0 && this.chunks.push(e.data);
1809
+ }, this.stream = t, this.recorder = e, this.startedAt = Date.now(), e.start(200);
1810
+ } catch (e) {
1811
+ throw t.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, Error(Rt(e));
1812
+ }
1813
+ this.startLevelMeter(t), this.tickTimer = setInterval(() => {
1814
+ this.update({ elapsedSeconds: Math.floor(this.elapsedMs() / 1e3) });
1815
+ }, Pt), this.maxTimer = setTimeout(() => void this.stop(), this.maxDurationSeconds * 1e3), this.update({
1816
+ state: "recording",
1817
+ elapsedSeconds: 0,
1818
+ level: 0,
1819
+ result: null
1820
+ });
1821
+ }
1822
+ async stop() {
1823
+ let e = this.recorder;
1824
+ if (!e || e.state === "inactive") return this.release(), null;
1825
+ let t = Math.max(1, Math.round(this.elapsedMs() / 1e3));
1826
+ this.clearTimers();
1827
+ let n = await new Promise((t) => {
1828
+ e.onstop = () => {
1829
+ let e = this.chunks;
1830
+ this.chunks = [], t(new Blob(e, { type: g(this.mimeType) }));
1831
+ };
1832
+ try {
1833
+ e.stop();
1834
+ } catch {
1835
+ t(new Blob(this.chunks, { type: g(this.mimeType) }));
1836
+ }
1837
+ });
1838
+ this.releaseMedia();
1839
+ let r = {
1840
+ blob: n,
1841
+ mimeType: g(this.mimeType),
1842
+ durationSeconds: t
1843
+ };
1844
+ return this.update({
1845
+ state: "preview",
1846
+ elapsedSeconds: t,
1847
+ level: 0,
1848
+ result: r
1849
+ }), r;
1850
+ }
1851
+ cancel() {
1852
+ this.release(), this.update({
1853
+ state: "idle",
1854
+ elapsedSeconds: 0,
1855
+ level: 0,
1856
+ result: null
1857
+ });
1858
+ }
1859
+ destroy() {
1860
+ this.release(), this.snapshot = {
1861
+ state: "idle",
1862
+ elapsedSeconds: 0,
1863
+ level: 0,
1864
+ result: null
1865
+ };
1866
+ }
1867
+ update(e) {
1868
+ this.snapshot = {
1869
+ ...this.snapshot,
1870
+ ...e
1871
+ }, this.onChange({ ...this.snapshot });
1872
+ }
1873
+ elapsedMs() {
1874
+ return this.startedAt > 0 ? Date.now() - this.startedAt : 0;
1875
+ }
1876
+ startLevelMeter(e) {
1877
+ let t = typeof window > "u" ? null : window, n = t?.AudioContext ?? t?.webkitAudioContext;
1878
+ if (n) try {
1879
+ let t = new n(), r = t.createAnalyser();
1880
+ r.fftSize = 256, t.createMediaStreamSource(e).connect(r), t.resume().catch(() => void 0), this.audioContext = t, this.analyser = r;
1881
+ let i = new Uint8Array(r.frequencyBinCount);
1882
+ this.levelTimer = setInterval(() => {
1883
+ r.getByteTimeDomainData(i);
1884
+ let e = 0;
1885
+ for (let t = 0; t < i.length; t++) {
1886
+ let n = ((i[t] ?? 128) - 128) / 128;
1887
+ e += n * n;
1888
+ }
1889
+ this.update({ level: Math.min(1, Math.sqrt(e / i.length) * 3.2) });
1890
+ }, Ft);
1891
+ } catch {}
1892
+ }
1893
+ clearTimers() {
1894
+ this.tickTimer && clearInterval(this.tickTimer), this.levelTimer && clearInterval(this.levelTimer), this.maxTimer && clearTimeout(this.maxTimer), this.tickTimer = null, this.levelTimer = null, this.maxTimer = null;
1895
+ }
1896
+ releaseMedia() {
1897
+ this.stream?.getTracks().forEach((e) => e.stop()), this.stream = null, this.recorder = null, this.analyser = null, this.audioContext &&= (this.audioContext.close().catch(() => void 0), null), this.startedAt = 0;
1898
+ }
1899
+ release() {
1900
+ if (this.clearTimers(), this.recorder && this.recorder.state !== "inactive") {
1901
+ this.recorder.onstop = null;
1902
+ try {
1903
+ this.recorder.stop();
1904
+ } catch {}
1905
+ }
1906
+ this.chunks = [], this.releaseMedia();
1907
+ }
1908
+ }, X = [
1606
1909
  {
1607
1910
  iso: "BD",
1608
1911
  name: "Bangladesh",
@@ -1969,8 +2272,8 @@ var lt = class {
1969
2272
  dial: "977",
1970
2273
  flag: "🇳🇵"
1971
2274
  }
1972
- ], ut = Y.find((e) => e.iso === "BD") ?? Y[0];
1973
- function dt(e, t) {
2275
+ ], zt = X.find((e) => e.iso === "BD") ?? X[0];
2276
+ function Bt(e, t) {
1974
2277
  let n = t.trim();
1975
2278
  if (n.startsWith("+")) {
1976
2279
  let e = n.replace(/\D/g, "");
@@ -1981,7 +2284,8 @@ function dt(e, t) {
1981
2284
  }
1982
2285
  //#endregion
1983
2286
  //#region src/widget/styles.ts
1984
- function ft(e, t) {
2287
+ var Vt = "(max-width: 640px), (max-height: 500px) and (pointer: coarse)";
2288
+ function Ht(e, t) {
1985
2289
  let n = `
1986
2290
  --ttcb-bg: #ffffff;
1987
2291
  --ttcb-bg-secondary: #f3f4f6;
@@ -2048,6 +2352,7 @@ function ft(e, t) {
2048
2352
  transition: opacity 0.2s ease, transform 0.25s ease, height 0.2s ease;
2049
2353
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2050
2354
  }
2355
+ .ttcb-panel:focus { outline: none; }
2051
2356
  .ttcb-panel.ttcb-mode-chat {
2052
2357
  height: 560px;
2053
2358
  }
@@ -2194,24 +2499,9 @@ function ft(e, t) {
2194
2499
  }
2195
2500
  @keyframes ttcb-spin { to { transform: rotate(360deg); } }
2196
2501
 
2197
- .ttcb-blocked {
2198
- display: flex; flex-direction: column; align-items: center;
2199
- justify-content: center; text-align: center;
2200
- padding: 32px 20px; flex: 1;
2201
- }
2202
- .ttcb-blocked-icon {
2203
- width: 44px; height: 44px; border-radius: 50%;
2204
- background: var(--ttcb-bg-secondary);
2205
- display: flex; align-items: center; justify-content: center;
2206
- margin-bottom: 14px;
2207
- }
2208
- .ttcb-blocked-icon svg { width: 20px; height: 20px; fill: var(--ttcb-text-muted); }
2209
- .ttcb-blocked-title { font-size: 14px; font-weight: 600; color: var(--ttcb-text); margin-bottom: 8px; }
2210
- .ttcb-blocked-desc { font-size: 12px; color: var(--ttcb-text-muted); line-height: 1.5; max-width: 220px; }
2211
-
2212
2502
  .ttcb-msg { display: flex; gap: 8px; max-width: 100%; }
2213
2503
  .ttcb-msg.human { flex-direction: row-reverse; }
2214
- .ttcb-msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 78%; }
2504
+ .ttcb-msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 78%; min-width: 0; }
2215
2505
  .ttcb-msg.human .ttcb-msg-body { align-items: flex-end; }
2216
2506
  .ttcb-msg-label {
2217
2507
  font-size: 11px; font-weight: 600; color: var(--ttcb-text-muted);
@@ -2481,29 +2771,234 @@ function ft(e, t) {
2481
2771
  flex-shrink: 0;
2482
2772
  }
2483
2773
 
2774
+ .ttcb-form { align-items: center; }
2775
+ .ttcb-attach { position: relative; flex-shrink: 0; }
2776
+ .ttcb-attach-btn {
2777
+ width: 38px; height: 38px; border-radius: 8px;
2778
+ border: 1px solid var(--ttcb-border);
2779
+ background: var(--ttcb-input-bg); color: var(--ttcb-text-muted);
2780
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2781
+ transition: color 0.15s, border-color 0.15s;
2782
+ }
2783
+ .ttcb-attach-btn:hover { color: var(--ttcb-text); }
2784
+ .ttcb-attach-btn:focus-visible { border-color: ${e}; outline: none; }
2785
+ .ttcb-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
2786
+ .ttcb-attach-btn svg { width: 18px; height: 18px; }
2787
+ .ttcb-attach-menu {
2788
+ display: none; position: absolute; left: 0; bottom: calc(100% + 8px);
2789
+ min-width: 170px; padding: 4px;
2790
+ background: var(--ttcb-bg);
2791
+ border: 1px solid var(--ttcb-border); border-radius: 12px;
2792
+ box-shadow: 0 8px 24px rgba(0,0,0,0.12);
2793
+ z-index: 1;
2794
+ }
2795
+ .ttcb-attach-menu.open { display: flex; flex-direction: column; }
2796
+ .ttcb-attach-item {
2797
+ display: flex; align-items: center; gap: 10px;
2798
+ padding: 9px 10px; border: none; border-radius: 8px;
2799
+ background: none; cursor: pointer;
2800
+ font-family: inherit; font-size: 13px; color: var(--ttcb-text);
2801
+ text-align: left; width: 100%;
2802
+ }
2803
+ .ttcb-attach-item:hover, .ttcb-attach-item:focus-visible {
2804
+ background: var(--ttcb-bg-secondary); outline: none;
2805
+ }
2806
+ .ttcb-attach-item svg { width: 16px; height: 16px; color: var(--ttcb-text-muted); flex-shrink: 0; }
2807
+ .ttcb-file-input { display: none; }
2808
+ .ttcb-form.hidden { display: none; }
2809
+ .ttcb-mic-btn {
2810
+ width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0;
2811
+ border: 1px solid var(--ttcb-border);
2812
+ background: var(--ttcb-input-bg); color: var(--ttcb-text-muted);
2813
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2814
+ transition: color 0.15s, border-color 0.15s;
2815
+ }
2816
+ .ttcb-mic-btn:hover { color: var(--ttcb-text); }
2817
+ .ttcb-mic-btn:focus-visible { border-color: ${e}; outline: none; }
2818
+ .ttcb-mic-btn:disabled { opacity: 0.5; cursor: not-allowed; }
2819
+ .ttcb-mic-btn svg { width: 18px; height: 18px; }
2820
+
2821
+ .ttcb-voice-bar, .ttcb-voice-preview {
2822
+ display: none; align-items: center; gap: 8px;
2823
+ padding: 6px 8px;
2824
+ border: 1px solid var(--ttcb-border); border-radius: 10px;
2825
+ background: var(--ttcb-input-bg);
2826
+ }
2827
+ .ttcb-voice-bar.visible, .ttcb-voice-preview.visible { display: flex; }
2828
+ .ttcb-voice-dot {
2829
+ width: 10px; height: 10px; border-radius: 50%; background: #ef4444; flex-shrink: 0;
2830
+ animation: ttcb-pulse 1.1s ease-in-out infinite;
2831
+ }
2832
+ @keyframes ttcb-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
2833
+ .ttcb-voice-time {
2834
+ font-size: 13px; font-weight: 500; color: var(--ttcb-text);
2835
+ font-variant-numeric: tabular-nums; flex-shrink: 0;
2836
+ }
2837
+ .ttcb-voice-meter {
2838
+ flex: 1; min-width: 0; height: 6px; border-radius: 999px;
2839
+ background: var(--ttcb-bg-secondary); overflow: hidden;
2840
+ }
2841
+ .ttcb-voice-level {
2842
+ display: block; height: 100%; width: 4%; border-radius: 999px;
2843
+ background: #ef4444; transition: width 0.1s linear;
2844
+ }
2845
+ .ttcb-voice-audio { flex: 1; min-width: 0; height: 32px; }
2846
+ .ttcb-voice-btn {
2847
+ width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
2848
+ border: 1px solid var(--ttcb-border);
2849
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted);
2850
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
2851
+ }
2852
+ .ttcb-voice-btn:hover { color: var(--ttcb-text); }
2853
+ .ttcb-voice-btn.primary { background: ${e}; border-color: ${e}; color: #fff; }
2854
+ .ttcb-voice-btn.primary:hover { opacity: 0.9; color: #fff; }
2855
+ .ttcb-voice-btn svg { width: 15px; height: 15px; }
2856
+ .ttcb-voice-btn.primary svg { fill: #fff; }
2857
+ .ttcb-voice-btn.primary svg[fill="none"] { fill: none; }
2858
+
2859
+ .ttcb-pending-tray { display: none; gap: 8px; flex-wrap: wrap; padding-bottom: 10px; }
2860
+ .ttcb-pending-tray.visible { display: flex; }
2861
+ .ttcb-pending-item {
2862
+ display: flex; align-items: center; gap: 8px; max-width: 100%;
2863
+ padding: 5px 6px 5px 5px;
2864
+ border: 1px solid var(--ttcb-border); border-radius: 10px;
2865
+ background: var(--ttcb-bg-secondary);
2866
+ font-size: 12px; color: var(--ttcb-text);
2867
+ }
2868
+ .ttcb-pending-thumb {
2869
+ width: 36px; height: 36px; border-radius: 6px; object-fit: cover;
2870
+ flex-shrink: 0; background: var(--ttcb-bg);
2871
+ }
2872
+ .ttcb-pending-icon {
2873
+ width: 36px; height: 36px; border-radius: 6px; flex-shrink: 0;
2874
+ display: flex; align-items: center; justify-content: center;
2875
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted);
2876
+ }
2877
+ .ttcb-pending-icon svg { width: 18px; height: 18px; }
2878
+ .ttcb-pending-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2879
+ .ttcb-pending-remove {
2880
+ width: 22px; height: 22px; border-radius: 50%; border: none; flex-shrink: 0;
2881
+ background: var(--ttcb-bg); color: var(--ttcb-text-muted); cursor: pointer;
2882
+ display: flex; align-items: center; justify-content: center;
2883
+ }
2884
+ .ttcb-pending-remove:hover { color: var(--ttcb-text); }
2885
+ .ttcb-pending-remove svg { width: 12px; height: 12px; fill: currentColor; }
2886
+ .ttcb-compose-error { display: none; font-size: 12px; color: #ef4444; padding-bottom: 8px; }
2887
+ .ttcb-compose-error.visible { display: block; }
2888
+
2889
+ .ttcb-attachments { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
2890
+ .ttcb-msg.human .ttcb-attachments { align-items: flex-end; }
2891
+ .ttcb-attachment-image {
2892
+ display: block; max-width: 220px; border-radius: 12px; overflow: hidden;
2893
+ border: 1px solid var(--ttcb-border); background: var(--ttcb-bg-secondary);
2894
+ }
2895
+ .ttcb-attachment-image img { display: block; max-width: 100%; max-height: 240px; object-fit: cover; }
2896
+ .ttcb-attachment-video { display: block; max-width: 220px; border-radius: 12px; background: #000; }
2897
+ .ttcb-attachment-voice { display: flex; flex-direction: column; gap: 2px; width: 220px; max-width: 100%; }
2898
+ .ttcb-attachment-audio { display: block; width: 100%; height: 36px; }
2899
+ .ttcb-attachment-duration { font-size: 11px; color: var(--ttcb-text-muted); padding-left: 2px; }
2900
+ .ttcb-attachment-file {
2901
+ display: flex; align-items: center; gap: 10px;
2902
+ padding: 8px 10px; max-width: 240px;
2903
+ border: 1px solid var(--ttcb-border); border-radius: 12px;
2904
+ background: var(--ttcb-bg); color: var(--ttcb-text);
2905
+ text-decoration: none; font-size: 13px;
2906
+ }
2907
+ a.ttcb-attachment-file:hover { border-color: ${e}; }
2908
+ .ttcb-attachment-icon {
2909
+ width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
2910
+ display: flex; align-items: center; justify-content: center;
2911
+ background: var(--ttcb-bg-secondary); color: var(--ttcb-text-muted);
2912
+ }
2913
+ .ttcb-attachment-icon svg { width: 16px; height: 16px; }
2914
+ .ttcb-attachment-meta { display: flex; flex-direction: column; min-width: 0; }
2915
+ .ttcb-attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
2916
+ .ttcb-attachment-size { font-size: 11px; color: var(--ttcb-text-muted); }
2917
+ .ttcb-msg.ttcb-pending .ttcb-attachments, .ttcb-msg.ttcb-pending .ttcb-bubble { opacity: 0.6; }
2918
+ .ttcb-msg-status { font-size: 11px; color: var(--ttcb-text-muted); padding: 0 2px; }
2919
+
2484
2920
  .ttcb-footer.hidden, .ttcb-messages.hidden { display: none; }
2485
2921
 
2486
- @media (max-width: 440px) {
2487
- .ttcb-panel { width: calc(100vw - 16px); right: 8px !important; left: 8px !important; bottom: 84px !important; }
2488
- .ttcb-fab.bottom-right { right: 16px; }
2489
- .ttcb-fab.bottom-left { left: 16px; }
2922
+ @media ${Vt} {
2923
+ .ttcb-fab.bottom-right { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2924
+ .ttcb-fab.bottom-left { left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
2925
+ /* The open panel covers the launcher; its own close button takes over. */
2926
+ .ttcb-fab.ttcb-open { display: none; }
2927
+
2928
+ /*
2929
+ * Full screen. Offsets instead of 100vw so a scrollbar never adds width, and
2930
+ * pinned to the visual viewport (--ttcb-vv-*, set by the widget) so the
2931
+ * on-screen keyboard shrinks the panel instead of pushing it off screen.
2932
+ */
2933
+ .ttcb-panel,
2934
+ .ttcb-panel.bottom-right,
2935
+ .ttcb-panel.bottom-left,
2936
+ .ttcb-panel.ttcb-mode-chat,
2937
+ .ttcb-panel.ttcb-mode-form,
2938
+ .ttcb-panel.ttcb-mode-compact {
2939
+ top: var(--ttcb-vv-top, 0px);
2940
+ left: var(--ttcb-vv-left, 0px);
2941
+ right: auto;
2942
+ bottom: auto;
2943
+ width: var(--ttcb-vv-width, 100%);
2944
+ height: var(--ttcb-vv-height, 100%);
2945
+ max-width: none;
2946
+ max-height: none;
2947
+ border: none;
2948
+ border-radius: 0;
2949
+ box-shadow: none;
2950
+ transition: opacity 0.2s ease, transform 0.25s ease;
2951
+ -webkit-text-size-adjust: 100%;
2952
+ text-size-adjust: 100%;
2953
+ }
2954
+ .ttcb-header {
2955
+ padding-top: max(14px, env(safe-area-inset-top, 0px));
2956
+ padding-left: max(16px, env(safe-area-inset-left, 0px));
2957
+ padding-right: max(16px, env(safe-area-inset-right, 0px));
2958
+ }
2959
+ .ttcb-close-btn { padding: 8px; }
2960
+ .ttcb-close-btn svg { width: 22px; height: 22px; }
2961
+ .ttcb-footer {
2962
+ padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
2963
+ padding-left: max(12px, env(safe-area-inset-left, 0px));
2964
+ padding-right: max(12px, env(safe-area-inset-right, 0px));
2965
+ }
2966
+ .ttcb-messages {
2967
+ overflow-x: hidden;
2968
+ overscroll-behavior: contain;
2969
+ }
2970
+ .ttcb-panel.ttcb-mode-form .ttcb-identify.visible {
2971
+ flex: 1 1 auto;
2972
+ min-height: 0;
2973
+ overflow-x: hidden;
2974
+ overscroll-behavior: contain;
2975
+ padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
2976
+ }
2977
+ .ttcb-country-list { overscroll-behavior: contain; }
2978
+ .ttcb-field-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
2979
+
2980
+ /* iOS zooms the page into any field under 16px, then leaves it zoomed and scrollable sideways. */
2981
+ .ttcb-input,
2982
+ .ttcb-identify-input,
2983
+ .ttcb-phone-national,
2984
+ .ttcb-country-search { font-size: 16px; }
2490
2985
  }
2491
2986
  `;
2492
2987
  }
2493
2988
  //#endregion
2494
2989
  //#region src/widget/render.ts
2495
- function X(e) {
2990
+ function Ut(e) {
2496
2991
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2497
2992
  }
2498
- function pt(e) {
2993
+ function Wt(e) {
2499
2994
  let t = [], n = e.replace(/```[\w]*\n?([\s\S]*?)```/g, (e, n) => {
2500
2995
  let r = t.length;
2501
- return t.push(`<pre><code>${X(n.trim())}</code></pre>`), `\x04${r}\x05`;
2996
+ return t.push(`<pre><code>${Ut(n.trim())}</code></pre>`), `\x04${r}\x05`;
2502
2997
  });
2503
2998
  n = n.replace(/`([^`\n]+)`/g, (e, n) => {
2504
2999
  let r = t.length;
2505
- return t.push(`<code>${X(n)}</code>`), `\x02${r}\x03`;
2506
- }), n = X(n);
3000
+ return t.push(`<code>${Ut(n)}</code>`), `\x02${r}\x03`;
3001
+ }), n = Ut(n);
2507
3002
  let r = n.split("\n"), i = [], a = "", o = () => {
2508
3003
  a &&= (i.push(`</${a}>`), "");
2509
3004
  };
@@ -2520,68 +3015,133 @@ function pt(e) {
2520
3015
  }).join("") : "";
2521
3016
  }).filter(Boolean).join(""), n = n.replace(/\x04(\d+)\x05/g, (e, n) => t[+n] ?? "").replace(/\x02(\d+)\x03/g, (e, n) => t[+n] ?? ""), n;
2522
3017
  }
2523
- function mt() {
2524
- return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z\"/>\n </svg>";
2525
- }
2526
- function ht() {
2527
- return "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z\"/>\n </svg>";
2528
- }
2529
- function gt() {
3018
+ function Gt() {
2530
3019
  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>";
2531
3020
  }
2532
- function _t() {
3021
+ function Kt() {
2533
3022
  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>";
2534
3023
  }
2535
- function vt() {
3024
+ function qt() {
2536
3025
  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>";
2537
3026
  }
2538
- function yt() {
3027
+ function Jt() {
2539
3028
  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>";
2540
3029
  }
2541
3030
  function Z() {
2542
3031
  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>";
2543
3032
  }
2544
- function bt() {
3033
+ function Yt() {
2545
3034
  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>";
2546
3035
  }
2547
- function xt() {
3036
+ function Xt() {
2548
3037
  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>";
2549
3038
  }
2550
- function St() {
3039
+ function Zt() {
2551
3040
  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>";
2552
3041
  }
2553
- function Ct() {
3042
+ function Qt() {
2554
3043
  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>";
2555
3044
  }
2556
- function wt() {
3045
+ function $t() {
2557
3046
  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>";
2558
3047
  }
2559
- function Tt() {
3048
+ function en() {
2560
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=\"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>";
2561
3050
  }
2562
- function Et() {
3051
+ function tn() {
2563
3052
  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>";
2564
3053
  }
2565
- function Dt() {
3054
+ function nn() {
2566
3055
  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>";
2567
3056
  }
2568
- function Ot() {
3057
+ function rn() {
2569
3058
  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>";
2570
3059
  }
2571
- function kt(e, t) {
2572
- let n = document.createElement("div");
2573
- n.className = `ttcb-msg ${t}`;
2574
- let r = document.createElement("div");
2575
- r.className = "ttcb-msg-avatar", r.innerHTML = t === "human" ? bt() : t === "agent" ? xt() : Z();
2576
- let i = document.createElement("div");
2577
- if (i.className = "ttcb-msg-body", t === "agent") {
3060
+ function an() {
3061
+ 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>";
3062
+ }
3063
+ function on() {
3064
+ 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>";
3065
+ }
3066
+ function sn() {
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 <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>";
3068
+ }
3069
+ function cn() {
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=\"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>";
3071
+ }
3072
+ function ln() {
3073
+ 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>";
3074
+ }
3075
+ function un() {
3076
+ 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>";
3077
+ }
3078
+ function dn() {
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=\"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>";
3080
+ }
3081
+ function fn(e) {
3082
+ let t = f(e.url) ? e.url : "", n = e.type.toLowerCase();
3083
+ if (t && n.startsWith("image/")) {
3084
+ let n = document.createElement("a");
3085
+ n.className = "ttcb-attachment ttcb-attachment-image", n.href = t, n.target = "_blank", n.rel = "noopener noreferrer", n.setAttribute("aria-label", `Open ${e.fileName}`);
3086
+ let r = document.createElement("img");
3087
+ return r.src = t, r.alt = e.fileName, r.loading = "lazy", n.appendChild(r), n;
3088
+ }
3089
+ if (t && n.startsWith("video/")) {
3090
+ let n = document.createElement("video");
3091
+ return n.className = "ttcb-attachment ttcb-attachment-video", n.controls = !0, n.preload = "metadata", n.src = t, n.setAttribute("aria-label", e.fileName), n;
3092
+ }
3093
+ if (t && n.startsWith("audio/")) {
3094
+ let n = document.createElement("div");
3095
+ n.className = "ttcb-attachment ttcb-attachment-voice";
3096
+ let r = document.createElement("audio");
3097
+ 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) {
3098
+ let t = document.createElement("span");
3099
+ t.className = "ttcb-attachment-duration", t.textContent = _(e.durationSeconds), n.appendChild(t);
3100
+ }
3101
+ return n;
3102
+ }
3103
+ let r = document.createElement(t ? "a" : "div");
3104
+ r.className = "ttcb-attachment ttcb-attachment-file", r instanceof HTMLAnchorElement && (r.href = t, r.target = "_blank", r.rel = "noopener noreferrer");
3105
+ let i = document.createElement("span");
3106
+ i.className = "ttcb-attachment-icon", i.setAttribute("aria-hidden", "true"), i.innerHTML = dn();
3107
+ let a = document.createElement("span");
3108
+ a.className = "ttcb-attachment-meta";
3109
+ let o = document.createElement("span");
3110
+ o.className = "ttcb-attachment-name", o.textContent = e.fileName, a.appendChild(o);
3111
+ let s = te(e.size);
3112
+ if (s) {
2578
3113
  let e = document.createElement("span");
2579
- e.className = "ttcb-msg-label", e.textContent = "Agent", i.appendChild(e);
3114
+ e.className = "ttcb-attachment-size", e.textContent = s, a.appendChild(e);
2580
3115
  }
3116
+ return r.appendChild(i), r.appendChild(a), r;
3117
+ }
3118
+ function pn(e) {
3119
+ let { type: t, content: n } = e, r = e.attachments ?? [], i = document.createElement("div");
3120
+ i.className = `ttcb-msg ${t}`, e.pending && i.classList.add("ttcb-pending");
2581
3121
  let a = document.createElement("div");
2582
- return a.className = "ttcb-bubble", t === "human" ? a.textContent = e : a.innerHTML = pt(e), i.appendChild(a), n.appendChild(r), n.appendChild(i), n;
3122
+ a.className = "ttcb-msg-avatar", a.innerHTML = t === "human" ? Yt() : t === "agent" ? Xt() : Z();
3123
+ let o = document.createElement("div");
3124
+ if (o.className = "ttcb-msg-body", t === "agent") {
3125
+ let e = document.createElement("span");
3126
+ e.className = "ttcb-msg-label", e.textContent = "Agent", o.appendChild(e);
3127
+ }
3128
+ if (r.length > 0) {
3129
+ let e = document.createElement("div");
3130
+ e.className = "ttcb-attachments";
3131
+ for (let t of r) e.appendChild(fn(t));
3132
+ o.appendChild(e);
3133
+ }
3134
+ if (r.length === 0 || !re(n, r)) {
3135
+ let e = document.createElement("div");
3136
+ e.className = "ttcb-bubble", t === "human" ? e.textContent = n : e.innerHTML = Wt(n), o.appendChild(e);
3137
+ }
3138
+ if (e.pending) {
3139
+ let e = document.createElement("span");
3140
+ e.className = "ttcb-msg-status", e.textContent = "Uploading…", o.appendChild(e);
3141
+ }
3142
+ return i.appendChild(a), i.appendChild(o), i;
2583
3143
  }
2584
- function At() {
3144
+ function mn() {
2585
3145
  let e = document.createElement("div");
2586
3146
  e.className = "ttcb-msg ai", e.id = "ttcb-typing";
2587
3147
  let t = document.createElement("div");
@@ -2591,24 +3151,40 @@ function At() {
2591
3151
  }
2592
3152
  //#endregion
2593
3153
  //#region src/widget/widget.ts
2594
- var jt = class {
3154
+ var hn = [
3155
+ "image/jpeg",
3156
+ "image/png",
3157
+ "image/gif",
3158
+ "video/mp4",
3159
+ "video/webm",
3160
+ "audio/ogg",
3161
+ "audio/mpeg",
3162
+ "audio/wav",
3163
+ "audio/x-m4a",
3164
+ "audio/aac",
3165
+ "audio/opus",
3166
+ "application/pdf",
3167
+ "text/csv"
3168
+ ].join(","), gn = "image/jpeg,image/png,image/gif", _n = class {
2595
3169
  constructor(e, t) {
2596
- this.selectedCountry = ut, this.countryOpen = !1, this.isOpen = !1, this.destroyed = !1, this.position = e.position ?? "bottom-right", this.callbacks = t, this.mount(e);
3170
+ 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);
2597
3171
  }
2598
3172
  mount(e) {
2599
- this.host = document.createElement("div"), this.host.id = "onedeskpro-chatbot-host", this.shadow = this.host.attachShadow({ mode: "closed" });
3173
+ this.host = document.createElement("div"), this.host.id = "onedeskpro-chatbot-host", this.host.style.display = "none", this.shadow = this.host.attachShadow({ mode: "closed" });
2600
3174
  let t = document.createElement("style");
2601
- t.textContent = ft(e.primaryColor ?? "#2563EB", e.theme ?? "auto"), this.shadow.appendChild(t);
2602
- let n = document.createElement("button");
2603
- n.className = `ttcb-fab ${this.position}`, n.setAttribute("aria-label", "Open chat"), n.innerHTML = _t(), n.addEventListener("click", () => this.toggle()), this.shadow.appendChild(n), this.panel = document.createElement("div"), this.panel.className = `ttcb-panel ${this.position} hidden ttcb-mode-compact`, 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";
2604
- let r = document.createElement("form");
2605
- r.className = "ttcb-form", r.addEventListener("submit", (e) => {
3175
+ 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());
3176
+ let n = document.createElement("form");
3177
+ n.className = "ttcb-form", n.addEventListener("submit", (e) => {
2606
3178
  e.preventDefault(), this.handleSend();
2607
- }), 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 = yt(), this.sendBtn.setAttribute("aria-label", "Send message"), r.appendChild(this.input), r.appendChild(this.sendBtn), this.footer.appendChild(r), this.panel.appendChild(this.footer), this.shadow.appendChild(this.panel), this.shadow.addEventListener("click", (e) => {
2608
- if (!this.countryOpen) return;
3179
+ }), 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) => {
2609
3180
  let t = e.target;
2610
- t && (this.dialBtn.contains(t) || this.countryPopover.contains(t)) || this.closeCountryPopover();
2611
- }), this.attachToDocument(), this.showInitialLoading(), e.autoOpen && this.open();
3181
+ 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());
3182
+ }), this.panel.addEventListener("keydown", (e) => {
3183
+ e.key === "Escape" && this.attachMenuOpen && (e.stopPropagation(), this.closeAttachMenu(), this.attachBtn.focus());
3184
+ }), this.attachToDocument(), this.showInitialLoading();
3185
+ }
3186
+ reveal() {
3187
+ this.host.style.removeProperty("display"), this.autoOpen && !this.isOpen && this.open();
2612
3188
  }
2613
3189
  buildHeader(e) {
2614
3190
  let t = document.createElement("div");
@@ -2622,7 +3198,7 @@ var jt = class {
2622
3198
  let a = document.createElement("div");
2623
3199
  a.className = "ttcb-header-title-row", this.headerTitle = document.createElement("span"), this.headerTitle.className = "ttcb-header-title", this.headerTitle.textContent = e.chatbotName ?? "AI Assistant";
2624
3200
  let o = document.createElement("span");
2625
- o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = Et(), a.appendChild(this.headerTitle), a.appendChild(o);
3201
+ o.className = "ttcb-verified", o.setAttribute("aria-label", "Verified"), o.innerHTML = tn(), a.appendChild(this.headerTitle), a.appendChild(o);
2626
3202
  let s = document.createElement("div");
2627
3203
  s.className = "ttcb-header-meta";
2628
3204
  let c = document.createElement("span");
@@ -2630,11 +3206,146 @@ var jt = class {
2630
3206
  let l = document.createElement("span");
2631
3207
  l.className = "ttcb-meta-sep", l.setAttribute("aria-hidden", "true");
2632
3208
  let u = document.createElement("span");
2633
- u.className = "ttcb-meta-replies", u.innerHTML = `${Dt()}<span>Replies instantly</span>`, s.appendChild(c), s.appendChild(l), s.appendChild(u), i.appendChild(a), i.appendChild(s);
3209
+ 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);
2634
3210
  let d = document.createElement("div");
2635
- 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 = Ot(), 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());
3211
+ 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());
2636
3212
  let f = document.createElement("button");
2637
- return f.className = "ttcb-close-btn", f.setAttribute("aria-label", "Close chat"), f.innerHTML = vt(), 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;
3213
+ 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;
3214
+ }
3215
+ buildAttachControls() {
3216
+ let e = document.createElement("div");
3217
+ 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) => {
3218
+ e.preventDefault(), e.stopPropagation(), this.toggleAttachMenu();
3219
+ }), 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");
3220
+ let t = [{
3221
+ label: "Attachment",
3222
+ icon: on(),
3223
+ input: this.attachFileInput
3224
+ }, {
3225
+ label: "Photo",
3226
+ icon: sn(),
3227
+ input: this.attachPhotoInput
3228
+ }];
3229
+ for (let e of t) {
3230
+ let t = document.createElement("button");
3231
+ t.type = "button", t.className = "ttcb-attach-item", t.setAttribute("role", "menuitem"), t.innerHTML = `${e.icon}<span>${e.label}</span>`, t.addEventListener("click", () => {
3232
+ this.closeAttachMenu(), e.input.click();
3233
+ }), this.attachMenu.appendChild(t);
3234
+ }
3235
+ return e.appendChild(this.attachBtn), e.appendChild(this.attachMenu), e.appendChild(this.attachFileInput), e.appendChild(this.attachPhotoInput), e;
3236
+ }
3237
+ createFileInput(e, t) {
3238
+ let n = document.createElement("input");
3239
+ return n.type = "file", n.multiple = !0, n.accept = e, n.className = "ttcb-file-input", n.tabIndex = -1, n.setAttribute("aria-label", t), n.addEventListener("change", () => {
3240
+ this.addPendingFiles(Array.from(n.files ?? [])), n.value = "";
3241
+ }), n;
3242
+ }
3243
+ toggleAttachMenu() {
3244
+ this.attachMenuOpen ? this.closeAttachMenu() : this.openAttachMenu();
3245
+ }
3246
+ openAttachMenu() {
3247
+ if (this.attachBtn.disabled) return;
3248
+ this.attachMenuOpen = !0, this.attachMenu.classList.add("open"), this.attachBtn.setAttribute("aria-expanded", "true");
3249
+ let e = this.attachMenu.querySelector(".ttcb-attach-item");
3250
+ queueMicrotask(() => e?.focus());
3251
+ }
3252
+ closeAttachMenu() {
3253
+ this.attachMenuOpen && (this.attachMenuOpen = !1, this.attachMenu.classList.remove("open"), this.attachBtn.setAttribute("aria-expanded", "false"));
3254
+ }
3255
+ addPendingFiles(e) {
3256
+ if (e.length === 0) return;
3257
+ let t = d([...this.pendingFiles.map((e) => e.file), ...e]);
3258
+ if (t) this.showComposeError(t);
3259
+ else {
3260
+ this.showComposeError("");
3261
+ for (let t of e) {
3262
+ let e = t.type.startsWith("image/") ? p(t) : "";
3263
+ this.pendingFiles.push({
3264
+ file: t,
3265
+ previewUrl: e
3266
+ });
3267
+ }
3268
+ this.renderPendingTray(), this.input.focus();
3269
+ }
3270
+ }
3271
+ removePendingFile(e) {
3272
+ let [t] = this.pendingFiles.splice(e, 1);
3273
+ t && m(t.previewUrl), this.renderPendingTray(), this.input.focus();
3274
+ }
3275
+ clearPendingFiles() {
3276
+ for (let e of this.pendingFiles) m(e.previewUrl);
3277
+ this.pendingFiles = [], this.renderPendingTray();
3278
+ }
3279
+ renderPendingTray() {
3280
+ this.pendingTray.innerHTML = "", this.pendingTray.classList.toggle("visible", this.pendingFiles.length > 0), this.pendingFiles.forEach((e, t) => {
3281
+ let n = document.createElement("div");
3282
+ if (n.className = "ttcb-pending-item", n.setAttribute("role", "listitem"), e.previewUrl) {
3283
+ let t = document.createElement("img");
3284
+ t.className = "ttcb-pending-thumb", t.src = e.previewUrl, t.alt = "", n.appendChild(t);
3285
+ } else {
3286
+ let e = document.createElement("span");
3287
+ e.className = "ttcb-pending-icon", e.setAttribute("aria-hidden", "true"), e.innerHTML = dn(), n.appendChild(e);
3288
+ }
3289
+ let r = document.createElement("span");
3290
+ r.className = "ttcb-pending-name", r.textContent = e.file.name || "attachment", r.title = e.file.name, n.appendChild(r);
3291
+ let i = document.createElement("button");
3292
+ 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);
3293
+ });
3294
+ }
3295
+ buildVoiceBar() {
3296
+ this.voiceBar = document.createElement("div"), this.voiceBar.className = "ttcb-voice-bar", this.voiceBar.setAttribute("role", "group"), this.voiceBar.setAttribute("aria-label", "Recording voice message");
3297
+ let e = document.createElement("span");
3298
+ 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";
3299
+ let t = document.createElement("div");
3300
+ 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;
3301
+ }
3302
+ buildVoicePreview() {
3303
+ 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;
3304
+ }
3305
+ createVoiceButton(e, t, n) {
3306
+ let r = document.createElement("button");
3307
+ return r.type = "button", r.className = "ttcb-voice-btn", r.setAttribute("aria-label", e), r.title = e, r.innerHTML = t, r.addEventListener("click", n), r;
3308
+ }
3309
+ async startVoice() {
3310
+ if (!this.micBtn.disabled) {
3311
+ if (this.closeAttachMenu(), this.showComposeError(""), !Y.isSupported()) this.showComposeError("Voice messages are not supported in this browser.");
3312
+ else {
3313
+ this.recorder?.destroy(), this.recorder = new Y((e) => this.renderVoice(e));
3314
+ try {
3315
+ await this.recorder.start();
3316
+ } catch (e) {
3317
+ this.showComposeError(e instanceof Error ? e.message : "Could not start recording."), this.recorder.destroy(), this.recorder = null, this.renderVoice({
3318
+ state: "idle",
3319
+ elapsedSeconds: 0,
3320
+ level: 0,
3321
+ result: null
3322
+ });
3323
+ }
3324
+ }
3325
+ }
3326
+ }
3327
+ async stopVoice() {
3328
+ await this.recorder?.stop();
3329
+ }
3330
+ cancelVoice() {
3331
+ this.recorder?.cancel(), this.recorder?.destroy(), this.recorder = null, this.renderVoice({
3332
+ state: "idle",
3333
+ elapsedSeconds: 0,
3334
+ level: 0,
3335
+ result: null
3336
+ }), this.input.focus();
3337
+ }
3338
+ sendVoice() {
3339
+ let e = this.recorder?.getSnapshot().result;
3340
+ e && (this.cancelVoice(), this.callbacks.onSendVoice(e));
3341
+ }
3342
+ renderVoice(e) {
3343
+ if (this.destroyed) return;
3344
+ let { state: t } = e;
3345
+ 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())));
3346
+ }
3347
+ showComposeError(e) {
3348
+ this.composeError.textContent = e, this.composeError.classList.toggle("visible", !!e);
2638
3349
  }
2639
3350
  setPanelMode(e) {
2640
3351
  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());
@@ -2651,7 +3362,7 @@ var jt = class {
2651
3362
  placeholder: "Your name",
2652
3363
  type: "text",
2653
3364
  autocomplete: "name",
2654
- icon: xt()
3365
+ icon: Xt()
2655
3366
  }), this.createPhoneField(t), this.emailInput = this.createIconField(t, {
2656
3367
  id: "email",
2657
3368
  label: "Email (optional)",
@@ -2660,10 +3371,10 @@ var jt = class {
2660
3371
  placeholder: "Email (optional)",
2661
3372
  type: "email",
2662
3373
  autocomplete: "email",
2663
- icon: St()
2664
- }), 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>${wt()}`, t.appendChild(this.identifySubmit), e.appendChild(t);
3374
+ icon: Zt()
3375
+ }), 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);
2665
3376
  let n = document.createElement("div");
2666
- n.className = "ttcb-trust", n.innerHTML = `${Tt()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
3377
+ n.className = "ttcb-trust", n.innerHTML = `${en()}<span>Encrypted connection • No spam, ever</span>`, e.appendChild(n);
2667
3378
  }
2668
3379
  createIconField(e, t) {
2669
3380
  let n = document.createElement("div");
@@ -2693,7 +3404,7 @@ var jt = class {
2693
3404
  let a = document.createElement("div");
2694
3405
  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);
2695
3406
  let o = document.createElement("span");
2696
- o.setAttribute("aria-hidden", "true"), o.innerHTML = Ct(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
3407
+ o.setAttribute("aria-hidden", "true"), o.innerHTML = Qt(), this.dialBtn.appendChild(o), this.dialBtn.addEventListener("click", (e) => {
2697
3408
  e.preventDefault(), e.stopPropagation(), this.toggleCountryPopover();
2698
3409
  }), 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);
2699
3410
  }
@@ -2710,7 +3421,7 @@ var jt = class {
2710
3421
  this.countryOpen = !1, this.countryPopover.classList.remove("open"), this.dialBtn.setAttribute("aria-expanded", "false");
2711
3422
  }
2712
3423
  renderCountryList() {
2713
- let e = this.countrySearch.value.trim().toLowerCase(), t = Y.filter((t) => !e || t.name.toLowerCase().includes(e) || t.dial.includes(e) || t.iso.toLowerCase().includes(e) || `+${t.dial}`.includes(e));
3424
+ let e = this.countrySearch.value.trim().toLowerCase(), t = X.filter((t) => !e || t.name.toLowerCase().includes(e) || t.dial.includes(e) || t.iso.toLowerCase().includes(e) || `+${t.dial}`.includes(e));
2714
3425
  this.countryList.innerHTML = "";
2715
3426
  for (let e of t) {
2716
3427
  let t = document.createElement("button");
@@ -2754,10 +3465,15 @@ var jt = class {
2754
3465
  }
2755
3466
  handleSend() {
2756
3467
  let e = this.input.value.trim();
2757
- e && !this.sendBtn.disabled && (this.input.value = "", this.callbacks.onSend(e), this.input.focus());
3468
+ if (!this.sendBtn.disabled) {
3469
+ if (this.pendingFiles.length > 0) {
3470
+ let t = this.pendingFiles.map((e) => e.file);
3471
+ this.clearPendingFiles(), this.showComposeError(""), this.input.value = "", this.callbacks.onSendAttachments(t, e), this.input.focus();
3472
+ } else e && (this.input.value = "", this.callbacks.onSend(e), this.input.focus());
3473
+ }
2758
3474
  }
2759
3475
  handleIdentifySubmit() {
2760
- let e = this.nameInput.value.trim(), t = dt(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
3476
+ let e = this.nameInput.value.trim(), t = Bt(this.selectedCountry.dial, this.phoneInput.value), n = this.emailInput.value.trim();
2761
3477
  !e || !t ? this.showIdentifyError("Name and phone are required.") : (this.showIdentifyError(""), this.callbacks.onIdentify({
2762
3478
  name: e,
2763
3479
  phone: t,
@@ -2766,38 +3482,70 @@ var jt = class {
2766
3482
  }
2767
3483
  appendMessage(e) {
2768
3484
  this.removeEmptyState();
2769
- let t = "message" in e ? e.message : e, n = kt(t.content, t.type);
2770
- this.messagesContainer.appendChild(n), this.scrollToBottom();
3485
+ let t = this.buildMessage(e);
3486
+ this.messagesContainer.appendChild(t), this.scrollToBottom();
3487
+ }
3488
+ replaceMessage(e, t) {
3489
+ let n = this.findMessageEl(e);
3490
+ n ? (n.replaceWith(this.buildMessage(t)), this.scrollToBottom()) : this.appendMessage(t);
3491
+ }
3492
+ removeMessage(e) {
3493
+ this.findMessageEl(e)?.remove();
3494
+ }
3495
+ buildMessage(e) {
3496
+ if ("message" in e) {
3497
+ let t = pn({
3498
+ ...e.message,
3499
+ pending: e.pending
3500
+ });
3501
+ return t.dataset.msgId = String(e.id), t;
3502
+ }
3503
+ return pn(e);
3504
+ }
3505
+ findMessageEl(e) {
3506
+ for (let t of this.messagesContainer.querySelectorAll(".ttcb-msg")) if (t.dataset.msgId === String(e)) return t;
3507
+ return null;
2771
3508
  }
2772
3509
  setMessages(e) {
2773
3510
  if (this.messagesContainer.innerHTML = "", e.length !== 0) {
2774
- for (let t of e) {
2775
- let e = kt(t.message.content, t.message.type);
2776
- this.messagesContainer.appendChild(e);
2777
- }
3511
+ for (let t of e) this.messagesContainer.appendChild(this.buildMessage(t));
2778
3512
  this.scrollToBottom();
2779
3513
  }
2780
3514
  }
2781
3515
  setLoading(e) {
2782
- if (this.sendBtn.disabled = e || this.input.disabled, e) this.shadow.getElementById("ttcb-typing") || (this.messagesContainer.appendChild(At()), this.scrollToBottom()), this.input.focus();
3516
+ 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();
2783
3517
  else {
2784
3518
  let e = this.shadow.getElementById("ttcb-typing");
2785
- e && e.remove(), this.input.disabled || this.input.focus();
3519
+ e && e.remove(), !this.input.disabled && !this.isFullScreen() && this.input.focus();
2786
3520
  }
2787
3521
  }
2788
3522
  setIdentifyLoading(e) {
2789
3523
  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);
2790
3524
  for (let t of this.identifyContainer.querySelectorAll(".ttcb-input-wrap")) t.classList.toggle("disabled", e);
2791
- this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${wt()}`, e && this.closeCountryPopover();
3525
+ this.identifySubmit.innerHTML = e ? "<span>Starting…</span>" : `<span>Start Chatting</span>${$t()}`, e && this.closeCountryPopover();
2792
3526
  }
2793
3527
  showIdentifyError(e) {
2794
3528
  this.identifyError.textContent = e;
2795
3529
  }
2796
3530
  open() {
2797
- this.isOpen = !0, this.panel.classList.remove("hidden"), this.identifyContainer.classList.contains("visible") ? this.nameInput.focus() : this.input.focus(), this.callbacks.onOpen();
3531
+ this.isOpen = !0, this.startViewportSync(), this.panel.classList.remove("hidden"), this.fab.classList.add("ttcb-open"), this.isFullScreen() ? this.panel.focus({ preventScroll: !0 }) : this.identifyContainer.classList.contains("visible") ? this.nameInput.focus() : this.input.focus(), this.callbacks.onOpen();
2798
3532
  }
2799
3533
  close() {
2800
- this.isOpen = !1, this.closeCountryPopover(), this.panel.classList.add("hidden"), this.callbacks.onClose();
3534
+ this.isOpen = !1, this.closeCountryPopover(), this.closeAttachMenu(), this.panel.classList.add("hidden"), this.fab.classList.remove("ttcb-open"), this.stopViewportSync?.(), this.stopViewportSync = null, this.fab.focus({ preventScroll: !0 }), this.callbacks.onClose();
3535
+ }
3536
+ isFullScreen() {
3537
+ return typeof window.matchMedia == "function" && window.matchMedia("(max-width: 640px), (max-height: 500px) and (pointer: coarse)").matches;
3538
+ }
3539
+ startViewportSync() {
3540
+ let e = window.visualViewport;
3541
+ if (!e || this.stopViewportSync) return;
3542
+ let t = () => {
3543
+ let t = this.messagesContainer, n = t.scrollHeight - t.scrollTop - t.clientHeight < 40;
3544
+ this.panel.style.setProperty("--ttcb-vv-top", `${e.offsetTop}px`), this.panel.style.setProperty("--ttcb-vv-left", `${e.offsetLeft}px`), this.panel.style.setProperty("--ttcb-vv-width", `${e.width}px`), this.panel.style.setProperty("--ttcb-vv-height", `${e.height}px`), n && this.scrollToBottom();
3545
+ };
3546
+ e.addEventListener("resize", t), e.addEventListener("scroll", t), t(), this.stopViewportSync = () => {
3547
+ e.removeEventListener("resize", t), e.removeEventListener("scroll", t);
3548
+ };
2801
3549
  }
2802
3550
  toggle() {
2803
3551
  this.isOpen ? this.close() : this.open();
@@ -2811,23 +3559,12 @@ var jt = class {
2811
3559
  content: e.welcomeMessage
2812
3560
  }) : this.showEmptyState(e.chatbotName ?? "AI Assistant"), this.setMode("ai");
2813
3561
  }
2814
- showBlocked(e, t) {
2815
- this.setPanelMode("compact"), this.closeCountryPopover(), this.identifyContainer.classList.remove("visible"), this.messagesContainer.classList.remove("hidden"), this.footer.classList.add("hidden"), this.messagesContainer.innerHTML = "";
2816
- let n = document.createElement("div");
2817
- n.className = "ttcb-blocked";
2818
- let r = document.createElement("div");
2819
- r.className = "ttcb-blocked-icon";
2820
- let i = document.createElement("p");
2821
- i.className = "ttcb-blocked-title";
2822
- let a = document.createElement("p");
2823
- a.className = "ttcb-blocked-desc", e === "no-prompt" ? (r.innerHTML = ht(), i.textContent = "Business Context Required", a.textContent = t ?? "Add a system prompt for this agent in the admin panel.") : e === "no-agent" ? (r.innerHTML = mt(), i.textContent = "Channel Not Connected", a.textContent = t ?? "Connect this Website channel under AI Agents → Connected Channels.") : e === "no-directories" || e === "no-collections" ? (r.innerHTML = ht(), i.textContent = "Knowledge Base Required", a.textContent = t ?? "Assign at least one knowledge-base collection to this agent in the admin panel.") : (r.innerHTML = mt(), i.textContent = "Chatbot Settings Required", a.textContent = t ?? "The chatbot has not been configured yet. Please set it up in the admin panel."), n.appendChild(r), n.appendChild(i), n.appendChild(a), this.messagesContainer.appendChild(n);
2824
- }
2825
3562
  clearMessages(e) {
2826
- this.messagesContainer.innerHTML = "", this.showEmptyState(e);
3563
+ this.messagesContainer.innerHTML = "", this.clearPendingFiles(), this.showComposeError(""), this.showEmptyState(e);
2827
3564
  }
2828
3565
  setMode(e, t) {
2829
3566
  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";
2830
- this.requestHumanBtn.classList.toggle("hidden", !a), this.newSessionBtn.classList.toggle("hidden", !o), this.input.disabled = s, s ? this.sendBtn.disabled = !0 : this.shadow.getElementById("ttcb-typing") || (this.sendBtn.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();
3567
+ 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();
2831
3568
  }
2832
3569
  showModeBanner(e, t) {
2833
3570
  this.modeBanner.textContent = e, this.modeBanner.className = `ttcb-mode-banner visible ${t}`;
@@ -2836,13 +3573,13 @@ var jt = class {
2836
3573
  this.modeBanner.textContent = "", this.modeBanner.className = "ttcb-mode-banner";
2837
3574
  }
2838
3575
  destroy() {
2839
- this.destroyed = !0, this.host.remove();
3576
+ this.destroyed = !0, this.stopViewportSync?.(), this.stopViewportSync = null, this.clearPendingFiles(), this.recorder?.destroy(), this.recorder = null, m(this.voicePreviewUrl), this.voicePreviewUrl = "", this.host.remove();
2840
3577
  }
2841
3578
  scrollToBottom() {
2842
3579
  this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
2843
3580
  }
2844
- }, Mt = {
2845
- apiBaseUrl: o,
3581
+ }, vn = {
3582
+ apiBaseUrl: c,
2846
3583
  chatbotName: "AI Assistant",
2847
3584
  primaryColor: "#2563EB",
2848
3585
  theme: "auto",
@@ -2853,11 +3590,23 @@ var jt = class {
2853
3590
  sessionId: "",
2854
3591
  requestTimeoutMs: n
2855
3592
  };
2856
- function Nt(e) {
3593
+ function yn(e) {
2857
3594
  return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
2858
3595
  }
2859
- var Pt = 0, Q = () => Date.now() * 1e3 + Pt++ % 1e3;
2860
- function Ft(e) {
3596
+ var bn = [
3597
+ 5e3,
3598
+ 15e3,
3599
+ 3e4,
3600
+ 6e4
3601
+ ];
3602
+ function xn(e) {
3603
+ return o(e) ? e.status === 0 || e.status >= 500 || e.apiError.code === "BAD_RESPONSE" : !1;
3604
+ }
3605
+ function Sn(e) {
3606
+ return o(e) ? e.apiError.message : e instanceof Error ? e.message : "Failed to load chatbot config.";
3607
+ }
3608
+ var Cn = 0, Q = () => Date.now() * 1e3 + Cn++ % 1e3;
3609
+ function wn(e) {
2861
3610
  if (!e || typeof e != "object") return null;
2862
3611
  let t = e;
2863
3612
  if (typeof t.textMessage == "string" && t.textMessage.trim()) return t.textMessage.trim();
@@ -2869,7 +3618,11 @@ function Ft(e) {
2869
3618
  }
2870
3619
  return null;
2871
3620
  }
2872
- function It(e) {
3621
+ function Tn(e) {
3622
+ let t = (e.attachments ?? []).map((e) => e.url).join("");
3623
+ return `${e.content}\u0000${t}`;
3624
+ }
3625
+ function En(e) {
2873
3626
  if (!e || typeof e != "object") return null;
2874
3627
  let t = e;
2875
3628
  if (typeof t.id == "string" && t.id) return t.id;
@@ -2879,9 +3632,9 @@ function It(e) {
2879
3632
  }
2880
3633
  return null;
2881
3634
  }
2882
- var Lt = class {
3635
+ var Dn = class {
2883
3636
  constructor() {
2884
- this.emitter = new s(), this.visitorTokens = new lt(), this.widget = null, this.sdkSocket = null, this.callerSetName = !1, this.hasActiveTicket = !1, this.lastPushId = null, this.initToken = 0, this._state = {
3637
+ 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 = {
2885
3638
  isOpen: !1,
2886
3639
  isLoading: !1,
2887
3640
  isReady: !1,
@@ -2915,22 +3668,61 @@ var Lt = class {
2915
3668
  async init(e) {
2916
3669
  if (!e.apiKey) throw Error("[onedeskpro-chatbot] `apiKey` is required to initialise the chatbot.");
2917
3670
  let t = ++this.initToken;
2918
- this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.callerSetName = e.chatbotName !== void 0, this.options = {
2919
- ...Mt,
2920
- ...Nt(e)
2921
- }, this.apiClient = new a({
3671
+ this.clearRetry(), this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.callerSetName = e.chatbotName !== void 0, this.options = {
3672
+ ...vn,
3673
+ ...yn(e)
3674
+ }, this.apiClient = new s({
2922
3675
  baseUrl: this.options.apiBaseUrl,
2923
3676
  apiKey: this.options.apiKey,
2924
3677
  timeoutMs: this.options.requestTimeoutMs
2925
3678
  }), this.hasActiveTicket = !1, this.setState({
3679
+ isReady: !1,
3680
+ blockReason: null,
2926
3681
  visitorToken: null,
2927
3682
  visitorName: null,
2928
3683
  needsIdentify: !0,
2929
3684
  messages: [],
2930
3685
  error: null,
2931
3686
  mode: "ai"
2932
- }), typeof window < "u" && typeof document < "u" && (this.widget = new jt(this.options, {
3687
+ }), await this.checkReadiness(t, 0);
3688
+ }
3689
+ async checkReadiness(e, t) {
3690
+ let n;
3691
+ try {
3692
+ n = await this.apiClient.fetchConfig();
3693
+ } catch (n) {
3694
+ if (e !== this.initToken) return;
3695
+ if (xn(n)) {
3696
+ this.setState({
3697
+ isReady: !1,
3698
+ blockReason: "server-unavailable",
3699
+ error: Sn(n)
3700
+ });
3701
+ let r = bn[t];
3702
+ if (r !== void 0) {
3703
+ this.retryTimer = setTimeout(() => {
3704
+ this.retryTimer = null, this.checkReadiness(e, t + 1);
3705
+ }, r);
3706
+ return;
3707
+ }
3708
+ } else this.handleConfigError(n);
3709
+ this.emitter.emit("ready");
3710
+ return;
3711
+ }
3712
+ if (e !== this.initToken) return;
3713
+ !this.callerSetName && n.agentName.trim() && (this.options.chatbotName = n.agentName);
3714
+ let r = n.blockReason ?? null, i = n.ready && r === null;
3715
+ this.setState({
3716
+ blockReason: r,
3717
+ isReady: i,
3718
+ error: null
3719
+ }), 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");
3720
+ }
3721
+ mountWidget() {
3722
+ typeof window < "u" && typeof document < "u" && (this.widget = new _n(this.options, {
2933
3723
  onSend: (e) => void this.sendMessage(e),
3724
+ onSendAttachments: (e, t) => void this.sendAttachments(e, t),
3725
+ onSendVoice: (e) => void this.sendVoice(e),
2934
3726
  onIdentify: (e) => void this.submitIdentify(e),
2935
3727
  onOpen: () => {
2936
3728
  this.setState({ isOpen: !0 }), this.emitter.emit("open");
@@ -2941,45 +3733,16 @@ var Lt = class {
2941
3733
  onReset: () => this.resetSession(),
2942
3734
  onRequestHuman: () => void this.requestHuman()
2943
3735
  }));
2944
- let n = null, r = null;
2945
- try {
2946
- n = await this.apiClient.fetchConfig();
2947
- } catch (e) {
2948
- r = e;
2949
- }
2950
- if (t !== this.initToken) return;
2951
- if (r) {
2952
- this.handleConfigError(r), this.emitter.emit("ready");
2953
- return;
2954
- }
2955
- if (!n) {
2956
- this.emitter.emit("ready");
2957
- return;
2958
- }
2959
- !this.callerSetName && n.agentName.trim() && (this.options.chatbotName = n.agentName);
2960
- let i = n.blockReason ?? null;
2961
- if (this.setState({
2962
- blockReason: i,
2963
- isReady: i === null,
2964
- error: null
2965
- }), i) this.widget?.showBlocked(i);
2966
- else if (this.visitorTokens.setScope(n.agentId), await this.resolveVisitorGate(t), t !== this.initToken) return;
2967
- this.emitter.emit("ready");
3736
+ }
3737
+ clearRetry() {
3738
+ this.retryTimer !== null && (clearTimeout(this.retryTimer), this.retryTimer = null);
2968
3739
  }
2969
3740
  handleConfigError(e) {
2970
- let t = i(e) ? e : null, n = t?.apiError.message ?? (e instanceof Error ? e.message : "Failed to load chatbot config."), r = t?.apiError.code, a = t?.status;
2971
- r === "agent_not_assigned" ? (this.setState({
2972
- isReady: !1,
2973
- blockReason: "no-agent",
2974
- error: n
2975
- }), this.widget?.showBlocked("no-agent")) : a === 403 ? (this.setState({
2976
- isReady: !1,
2977
- blockReason: null,
2978
- error: n
2979
- }), this.widget?.showBlocked(null, n)) : this.setState({
3741
+ let t = (o(e) ? e : null)?.apiError.code === "agent_not_assigned" ? "no-agent" : null;
3742
+ this.setState({
2980
3743
  isReady: !1,
2981
- blockReason: null,
2982
- error: n
3744
+ blockReason: t,
3745
+ error: Sn(e)
2983
3746
  });
2984
3747
  }
2985
3748
  async resolveVisitorGate(e) {
@@ -3011,7 +3774,7 @@ var Lt = class {
3011
3774
  }), this.widget?.readyToChat(this.options), this.connectSdkSocket(e), await this.restoreTicketStatus(e, n);
3012
3775
  }
3013
3776
  connectSdkSocket(e) {
3014
- this.sdkSocket ||= new at(), this.sdkSocket.connect({
3777
+ this.sdkSocket ||= new Ot(), this.sdkSocket.connect({
3015
3778
  baseUrl: this.options.apiBaseUrl,
3016
3779
  apiKey: this.options.apiKey,
3017
3780
  visitorToken: e,
@@ -3041,20 +3804,24 @@ var Lt = class {
3041
3804
  }
3042
3805
  handleMessageReceive(e) {
3043
3806
  if (this._state.mode === "ai") return;
3044
- let t = Ft(e);
3045
- if (!t) return;
3046
- let n = It(e), r = this._state.messages[this._state.messages.length - 1];
3047
- if (r?.message.content === t && (r.message.type === "ai" || r.message.type === "agent" && (!n || n === this.lastPushId))) return;
3048
- this.lastPushId = n;
3049
- let i = this.visitorTokens.get() ?? this._state.visitorToken ?? "", a = {
3807
+ let t = wn(e) ?? "", n = ne(e);
3808
+ if (!t && n.length === 0) return;
3809
+ let r = En(e), i = this._state.messages[this._state.messages.length - 1];
3810
+ if (i && Tn(i.message) === Tn({
3811
+ content: t,
3812
+ attachments: n
3813
+ }) && (i.message.type === "ai" || i.message.type === "agent" && (!r || r === this.lastPushId))) return;
3814
+ this.lastPushId = r;
3815
+ let a = this.visitorTokens.get() ?? this._state.visitorToken ?? "", o = {
3050
3816
  id: Q(),
3051
- sessionId: i,
3817
+ sessionId: a,
3052
3818
  message: {
3053
3819
  type: "agent",
3054
- content: t
3820
+ content: t,
3821
+ ...n.length > 0 ? { attachments: n } : {}
3055
3822
  }
3056
3823
  };
3057
- this.setState({ messages: [...this._state.messages, a] }), this.widget?.appendMessage(a), this.emitter.emit("message", a);
3824
+ this.setState({ messages: [...this._state.messages, o] }), this.widget?.appendMessage(o), this.emitter.emit("message", o);
3058
3825
  }
3059
3826
  async submitIdentify(e) {
3060
3827
  if (!this.apiClient || this._state.isLoading || !this._state.isReady) return;
@@ -3097,9 +3864,26 @@ var Lt = class {
3097
3864
  this.setState({ isLoading: !1 });
3098
3865
  }
3099
3866
  }
3100
- async sendMessage(e) {
3867
+ requireVisitorToken(e) {
3101
3868
  let t = this.visitorTokens.get() ?? this._state.visitorToken;
3102
- if (!this.apiClient || !t) throw Error("[onedeskpro-chatbot] Identify before sendMessage().");
3869
+ if (!this.apiClient || !t) throw Error(`[onedeskpro-chatbot] Identify before ${e}().`);
3870
+ return t;
3871
+ }
3872
+ pushLocalMessage(e) {
3873
+ this.setState({
3874
+ messages: [...this._state.messages, e],
3875
+ isLoading: !0,
3876
+ error: null
3877
+ }), this.widget?.appendMessage(e), this.emitter.emit("message", e);
3878
+ }
3879
+ replaceMessage(e, t) {
3880
+ this.setState({ messages: this._state.messages.map((n) => n.id === e ? t : n) }), this.widget?.replaceMessage(e, t);
3881
+ }
3882
+ removeMessage(e) {
3883
+ this.setState({ messages: this._state.messages.filter((t) => t.id !== e) }), this.widget?.removeMessage(e);
3884
+ }
3885
+ async sendMessage(e) {
3886
+ let t = this.requireVisitorToken("sendMessage");
3103
3887
  if (this._state.mode === "closed") {
3104
3888
  this.setState({ error: "Conversation is closed" });
3105
3889
  return;
@@ -3113,35 +3897,136 @@ var Lt = class {
3113
3897
  type: "human",
3114
3898
  content: n
3115
3899
  }
3116
- }, i = this._state.mode, a = i === "ai";
3117
- this.setState({
3118
- messages: [...this._state.messages, r],
3119
- isLoading: !0,
3120
- error: null
3121
- }), this.widget?.appendMessage(r), a && this.widget?.setLoading(!0), this.emitter.emit("message", r);
3900
+ }, i = this._state.mode;
3901
+ this.pushLocalMessage(r), i === "ai" && this.widget?.setLoading(!0), await this.deliver({
3902
+ chatInput: n,
3903
+ visitorToken: t
3904
+ }, i);
3905
+ }
3906
+ rejectSend(e) {
3907
+ this.setState({ error: e }), this.widget?.showComposeError(e), this.emitter.emit("error", Error(e));
3908
+ }
3909
+ async sendAttachments(e, t = "") {
3910
+ let n = this.requireVisitorToken("sendAttachments");
3911
+ if (this._state.mode === "closed") {
3912
+ this.setState({ error: "Conversation is closed" });
3913
+ return;
3914
+ }
3915
+ if (e.length === 0 || this._state.isLoading || this._state.needsIdentify) return;
3916
+ let r = d(e);
3917
+ r ? this.rejectSend(r) : await this.uploadThenDeliver({
3918
+ visitorToken: n,
3919
+ files: e,
3920
+ previews: e.map(ee),
3921
+ caption: t.trim()
3922
+ });
3923
+ }
3924
+ async sendVoice(e) {
3925
+ let t = this.requireVisitorToken("sendVoice");
3926
+ if (this._state.mode === "closed") {
3927
+ this.setState({ error: "Conversation is closed" });
3928
+ return;
3929
+ }
3930
+ if (!e?.blob || e.blob.size === 0 || this._state.isLoading || this._state.needsIdentify) return;
3931
+ let n;
3122
3932
  try {
3123
- let e = await this.apiClient.sendMessage({
3124
- chatInput: n,
3125
- visitorToken: t
3126
- });
3933
+ n = await de(e);
3934
+ } catch {
3935
+ this.rejectSend("Could not process the recording.");
3936
+ return;
3937
+ }
3938
+ if (n.file.size > 10485760) {
3939
+ this.rejectSend("This voice message is too long to send.");
3940
+ return;
3941
+ }
3942
+ let r = {
3943
+ durationSeconds: n.durationSeconds,
3944
+ ...n.waveform ? { waveform: n.waveform } : {}
3945
+ }, i = {
3946
+ type: n.file.type,
3947
+ url: p(n.file),
3948
+ fileName: n.file.name,
3949
+ size: n.file.size,
3950
+ ...r
3951
+ };
3952
+ await this.uploadThenDeliver({
3953
+ visitorToken: t,
3954
+ files: [n.file],
3955
+ previews: [i],
3956
+ caption: "",
3957
+ messageType: "voice",
3958
+ decorate: (e) => ({
3959
+ ...e,
3960
+ ...r
3961
+ })
3962
+ });
3963
+ }
3964
+ async uploadThenDeliver(e) {
3965
+ let { visitorToken: t, files: n, previews: r, caption: i } = e, a = {
3966
+ id: Q(),
3967
+ sessionId: t,
3968
+ message: {
3969
+ type: "human",
3970
+ content: i,
3971
+ attachments: r
3972
+ },
3973
+ pending: !0
3974
+ }, o = this._state.mode;
3975
+ this.pushLocalMessage(a);
3976
+ let s = [];
3977
+ try {
3978
+ for (let r of n) {
3979
+ let n = await this.apiClient.uploadAttachment(r, t);
3980
+ s.push(e.decorate ? e.decorate(n) : n);
3981
+ }
3982
+ } catch (e) {
3983
+ this.removeMessage(a.id);
3984
+ for (let e of r) m(e.url);
3985
+ let t = e instanceof Error ? e : Error(String(e));
3986
+ this.setState({
3987
+ error: t.message,
3988
+ isLoading: !1
3989
+ }), this.widget?.showComposeError(t.message), this.emitter.emit("error", t);
3990
+ return;
3991
+ }
3992
+ let c = {
3993
+ ...a,
3994
+ pending: !1,
3995
+ message: {
3996
+ ...a.message,
3997
+ attachments: s
3998
+ }
3999
+ };
4000
+ this.replaceMessage(a.id, c);
4001
+ for (let e of r) m(e.url);
4002
+ o === "ai" && this.widget?.setLoading(!0), await this.deliver({
4003
+ chatInput: i,
4004
+ visitorToken: t,
4005
+ attachments: s,
4006
+ ...e.messageType ? { messageType: e.messageType } : {}
4007
+ }, o);
4008
+ }
4009
+ async deliver(e, t) {
4010
+ try {
4011
+ let n = await this.apiClient.sendMessage(e);
3127
4012
  this.hasActiveTicket = !0;
3128
- let r = e.mode ?? i, a = [...this._state.messages], o = (e.text ?? "").trim();
3129
- if (r !== i && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), o) {
3130
- let t = a[a.length - 1];
3131
- if (t?.message.type !== "agent" && t?.message.type !== "ai" || t.message.content !== o) {
3132
- let t = {
4013
+ let r = n.mode ?? t, i = [...this._state.messages], a = (n.text ?? "").trim();
4014
+ if (r !== t && (this.setState({ mode: r }), this.syncWidgetMode(r), this.emitter.emit("ticket-status", { mode: r })), a) {
4015
+ let e = i[i.length - 1];
4016
+ if (e?.message.type !== "agent" && e?.message.type !== "ai" || e.message.content !== a) {
4017
+ let e = {
3133
4018
  id: Q(),
3134
- sessionId: e.sessionId,
4019
+ sessionId: n.sessionId,
3135
4020
  message: {
3136
4021
  type: "ai",
3137
- content: o
4022
+ content: a
3138
4023
  }
3139
4024
  };
3140
- a.push(t), this.widget?.appendMessage(t), this.emitter.emit("message", t);
4025
+ i.push(e), this.widget?.appendMessage(e), this.emitter.emit("message", e);
3141
4026
  }
3142
4027
  }
3143
4028
  this.setState({
3144
- messages: a,
4029
+ messages: i,
3145
4030
  isLoading: !1,
3146
4031
  mode: r
3147
4032
  }), this.syncWidgetMode(r);
@@ -3178,20 +4063,20 @@ var Lt = class {
3178
4063
  return { ...this._state };
3179
4064
  }
3180
4065
  destroy() {
3181
- this.initToken++, this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.setState({
4066
+ this.initToken++, this.clearRetry(), this.disconnectSdkSocket(), this.widget?.destroy(), this.widget = null, this.setState({
3182
4067
  isOpen: !1,
3183
4068
  isLoading: !1,
3184
4069
  isReady: !1,
3185
4070
  needsIdentify: !0
3186
4071
  });
3187
4072
  }
3188
- }, $ = null, Rt = {
4073
+ }, $ = null, On = {
3189
4074
  async init(e) {
3190
- return $ = new Lt(), await $.init(e), $;
4075
+ return $ = new Dn(), await $.init(e), $;
3191
4076
  },
3192
4077
  getInstance() {
3193
4078
  return $;
3194
4079
  }
3195
4080
  };
3196
4081
  //#endregion
3197
- export { a as ApiClient, Lt as ChatbotCore, o as DEFAULT_API_BASE_URL, n as DEFAULT_REQUEST_TIMEOUT_MS, s as EventEmitter, Rt as OnedeskProChatbot, at as SdkSocket, lt as SessionManager, i as isChatbotRequestError, it as resolveSdkSocketUrl };
4082
+ 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 };