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