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