@xpert-ai/chatkit-web-component 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/xpert-chatkit.js
CHANGED
|
@@ -269,10 +269,12 @@ class HttpError extends Error {
|
|
|
269
269
|
super(message);
|
|
270
270
|
__publicField(this, "status");
|
|
271
271
|
__publicField(this, "statusText");
|
|
272
|
+
__publicField(this, "retryAfterMs");
|
|
272
273
|
__publicField(this, "metadata");
|
|
273
274
|
this.name = "HttpError";
|
|
274
275
|
this.statusText = res.statusText;
|
|
275
276
|
this.status = res.status;
|
|
277
|
+
this.retryAfterMs = res.retryAfterMs;
|
|
276
278
|
this.metadata = metadata;
|
|
277
279
|
}
|
|
278
280
|
static fromPossibleFrameSafeError(error) {
|
|
@@ -285,7 +287,8 @@ class HttpError extends Error {
|
|
|
285
287
|
safeError.message,
|
|
286
288
|
{
|
|
287
289
|
status: safeError.status,
|
|
288
|
-
statusText: safeError.statusText
|
|
290
|
+
statusText: safeError.statusText,
|
|
291
|
+
retryAfterMs: safeError.retryAfterMs
|
|
289
292
|
},
|
|
290
293
|
safeError.metadata
|
|
291
294
|
);
|
|
@@ -303,11 +306,13 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
|
303
306
|
__publicField(this, "stack");
|
|
304
307
|
__publicField(this, "status");
|
|
305
308
|
__publicField(this, "statusText");
|
|
309
|
+
__publicField(this, "retryAfterMs");
|
|
306
310
|
__publicField(this, "metadata");
|
|
307
311
|
this.message = message;
|
|
308
312
|
this.stack = new Error(message).stack;
|
|
309
313
|
this.status = res.status;
|
|
310
314
|
this.statusText = res.statusText;
|
|
315
|
+
this.retryAfterMs = res.retryAfterMs;
|
|
311
316
|
this.metadata = metadata;
|
|
312
317
|
}
|
|
313
318
|
static fromHttpError(error) {
|
|
@@ -315,7 +320,8 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
|
315
320
|
error.message,
|
|
316
321
|
{
|
|
317
322
|
status: error.status,
|
|
318
|
-
statusText: error.statusText
|
|
323
|
+
statusText: error.statusText,
|
|
324
|
+
retryAfterMs: error.retryAfterMs
|
|
319
325
|
},
|
|
320
326
|
error.metadata
|
|
321
327
|
);
|
|
@@ -437,19 +443,42 @@ class FrameSafeIntegrationError {
|
|
|
437
443
|
}
|
|
438
444
|
}
|
|
439
445
|
function serializeFrameError(error) {
|
|
446
|
+
if (error instanceof HttpError || error instanceof FrameSafeHttpError) {
|
|
447
|
+
try {
|
|
448
|
+
return structuredClone(
|
|
449
|
+
error instanceof HttpError ? FrameSafeHttpError.fromHttpError(error) : error
|
|
450
|
+
);
|
|
451
|
+
} catch {
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
|
|
455
|
+
const message = "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
|
|
456
|
+
return new FrameSafeHttpError(message, {
|
|
457
|
+
status: error.status,
|
|
458
|
+
statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0,
|
|
459
|
+
retryAfterMs: readRetryAfterMs(error)
|
|
460
|
+
});
|
|
461
|
+
}
|
|
440
462
|
try {
|
|
441
463
|
return structuredClone(error);
|
|
442
464
|
} catch {
|
|
443
465
|
const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
|
|
444
|
-
if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
|
|
445
|
-
return new FrameSafeHttpError(message, {
|
|
446
|
-
status: error.status,
|
|
447
|
-
statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
466
|
return new Error(message);
|
|
451
467
|
}
|
|
452
468
|
}
|
|
469
|
+
function readRetryAfterMs(error) {
|
|
470
|
+
if ("retryAfterMs" in error && typeof error.retryAfterMs === "number" && Number.isFinite(error.retryAfterMs)) {
|
|
471
|
+
return Math.max(0, error.retryAfterMs);
|
|
472
|
+
}
|
|
473
|
+
if (!("headers" in error) || !error.headers || typeof error.headers !== "object")
|
|
474
|
+
return;
|
|
475
|
+
const headers = error.headers;
|
|
476
|
+
if (!("get" in headers) || typeof headers.get !== "function") return;
|
|
477
|
+
const value = headers.get("Retry-After");
|
|
478
|
+
if (typeof value !== "string" || !value.trim()) return;
|
|
479
|
+
const duration = /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) * 1e3 : Date.parse(value) - Date.now();
|
|
480
|
+
return Number.isFinite(duration) ? Math.max(0, duration) : void 0;
|
|
481
|
+
}
|
|
453
482
|
class BaseMessenger {
|
|
454
483
|
constructor({
|
|
455
484
|
handlers,
|