@xpert-ai/chatkit-web-component 0.16.2 → 0.18.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.
@@ -385,7 +385,13 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
385
385
  return null;
386
386
  }
387
387
  function safeRandomUUID() {
388
- return createSecureChannelId() ?? `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
388
+ const id = createSecureChannelId();
389
+ if (id === null) {
390
+ throw new Error(
391
+ "ChatKit requires crypto.randomUUID or crypto.getRandomValues to generate secure UUIDs."
392
+ );
393
+ }
394
+ return id;
389
395
  }
390
396
  function isTrustedChatKitMessageEvent(event, { channelId, expectedOrigin, expectedSource }) {
391
397
  const payload = event.data;
@@ -434,6 +440,20 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
434
440
  this.stack = new Error(message).stack;
435
441
  }
436
442
  }
443
+ function serializeFrameError(error) {
444
+ try {
445
+ return structuredClone(error);
446
+ } catch {
447
+ const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
448
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
449
+ return new FrameSafeHttpError(message, {
450
+ status: error.status,
451
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
452
+ });
453
+ }
454
+ return new Error(message);
455
+ }
456
+ }
437
457
  class BaseMessenger {
438
458
  constructor({
439
459
  handlers,
@@ -631,7 +651,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
631
651
  const message = {
632
652
  __xpaiChatKit: true,
633
653
  ...this.channelId ? { channelId: this.channelId } : {},
634
- ...data
654
+ ...data,
655
+ ...data.type === "response" && data.error !== void 0 ? { error: serializeFrameError(data.error) } : {}
635
656
  };
636
657
  (_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
637
658
  }
@@ -2850,6 +2871,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2850
2871
  }
2851
2872
  return connect(request);
2852
2873
  },
2874
+ onWorkbenchNavigationChange: async (navigation) => {
2875
+ var _a2, _b2, _c2;
2876
+ await ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onNavigationChange) == null ? void 0 : _c2.call(_b2, navigation));
2877
+ },
2853
2878
  onWorkbenchClientCommand: async ({
2854
2879
  commandKey,
2855
2880
  payload,