@xpert-ai/chatkit-ui5 0.18.0 → 0.18.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/chatkit.cjs CHANGED
@@ -272,10 +272,12 @@ class HttpError extends Error {
272
272
  super(message);
273
273
  __publicField(this, "status");
274
274
  __publicField(this, "statusText");
275
+ __publicField(this, "retryAfterMs");
275
276
  __publicField(this, "metadata");
276
277
  this.name = "HttpError";
277
278
  this.statusText = res.statusText;
278
279
  this.status = res.status;
280
+ this.retryAfterMs = res.retryAfterMs;
279
281
  this.metadata = metadata;
280
282
  }
281
283
  static fromPossibleFrameSafeError(error) {
@@ -288,7 +290,8 @@ class HttpError extends Error {
288
290
  safeError.message,
289
291
  {
290
292
  status: safeError.status,
291
- statusText: safeError.statusText
293
+ statusText: safeError.statusText,
294
+ retryAfterMs: safeError.retryAfterMs
292
295
  },
293
296
  safeError.metadata
294
297
  );
@@ -306,11 +309,13 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
306
309
  __publicField(this, "stack");
307
310
  __publicField(this, "status");
308
311
  __publicField(this, "statusText");
312
+ __publicField(this, "retryAfterMs");
309
313
  __publicField(this, "metadata");
310
314
  this.message = message;
311
315
  this.stack = new Error(message).stack;
312
316
  this.status = res.status;
313
317
  this.statusText = res.statusText;
318
+ this.retryAfterMs = res.retryAfterMs;
314
319
  this.metadata = metadata;
315
320
  }
316
321
  static fromHttpError(error) {
@@ -318,7 +323,8 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
318
323
  error.message,
319
324
  {
320
325
  status: error.status,
321
- statusText: error.statusText
326
+ statusText: error.statusText,
327
+ retryAfterMs: error.retryAfterMs
322
328
  },
323
329
  error.metadata
324
330
  );
@@ -440,19 +446,42 @@ class FrameSafeIntegrationError {
440
446
  }
441
447
  }
442
448
  function serializeFrameError(error) {
449
+ if (error instanceof HttpError || error instanceof FrameSafeHttpError) {
450
+ try {
451
+ return structuredClone(
452
+ error instanceof HttpError ? FrameSafeHttpError.fromHttpError(error) : error
453
+ );
454
+ } catch {
455
+ }
456
+ }
457
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
458
+ const message = "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
459
+ return new FrameSafeHttpError(message, {
460
+ status: error.status,
461
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0,
462
+ retryAfterMs: readRetryAfterMs(error)
463
+ });
464
+ }
443
465
  try {
444
466
  return structuredClone(error);
445
467
  } catch {
446
468
  const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
447
- if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
448
- return new FrameSafeHttpError(message, {
449
- status: error.status,
450
- statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
451
- });
452
- }
453
469
  return new Error(message);
454
470
  }
455
471
  }
472
+ function readRetryAfterMs(error) {
473
+ if ("retryAfterMs" in error && typeof error.retryAfterMs === "number" && Number.isFinite(error.retryAfterMs)) {
474
+ return Math.max(0, error.retryAfterMs);
475
+ }
476
+ if (!("headers" in error) || !error.headers || typeof error.headers !== "object")
477
+ return;
478
+ const headers = error.headers;
479
+ if (!("get" in headers) || typeof headers.get !== "function") return;
480
+ const value = headers.get("Retry-After");
481
+ if (typeof value !== "string" || !value.trim()) return;
482
+ const duration = /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) * 1e3 : Date.parse(value) - Date.now();
483
+ return Number.isFinite(duration) ? Math.max(0, duration) : void 0;
484
+ }
456
485
  class BaseMessenger {
457
486
  constructor({
458
487
  handlers,