@xpert-ai/chatkit-web-component 0.16.1 → 0.17.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.
@@ -430,6 +430,20 @@ class FrameSafeIntegrationError {
430
430
  this.stack = new Error(message).stack;
431
431
  }
432
432
  }
433
+ function serializeFrameError(error) {
434
+ try {
435
+ return structuredClone(error);
436
+ } catch {
437
+ const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
438
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
439
+ return new FrameSafeHttpError(message, {
440
+ status: error.status,
441
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
442
+ });
443
+ }
444
+ return new Error(message);
445
+ }
446
+ }
433
447
  class BaseMessenger {
434
448
  constructor({
435
449
  handlers,
@@ -627,7 +641,8 @@ class BaseMessenger {
627
641
  const message = {
628
642
  __xpaiChatKit: true,
629
643
  ...this.channelId ? { channelId: this.channelId } : {},
630
- ...data
644
+ ...data,
645
+ ...data.type === "response" && data.error !== void 0 ? { error: serializeFrameError(data.error) } : {}
631
646
  };
632
647
  (_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
633
648
  }