@xpert-ai/chatkit-ui5 0.16.2 → 0.17.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/index.js CHANGED
@@ -382,7 +382,13 @@ function createSecureChannelId() {
382
382
  return null;
383
383
  }
384
384
  function safeRandomUUID() {
385
- return createSecureChannelId() ?? `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
385
+ const id = createSecureChannelId();
386
+ if (id === null) {
387
+ throw new Error(
388
+ "ChatKit requires crypto.randomUUID or crypto.getRandomValues to generate secure UUIDs."
389
+ );
390
+ }
391
+ return id;
386
392
  }
387
393
  function isTrustedChatKitMessageEvent(event, { channelId, expectedOrigin, expectedSource }) {
388
394
  const payload = event.data;
@@ -431,6 +437,20 @@ class FrameSafeIntegrationError {
431
437
  this.stack = new Error(message).stack;
432
438
  }
433
439
  }
440
+ function serializeFrameError(error) {
441
+ try {
442
+ return structuredClone(error);
443
+ } catch {
444
+ const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
445
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
446
+ return new FrameSafeHttpError(message, {
447
+ status: error.status,
448
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
449
+ });
450
+ }
451
+ return new Error(message);
452
+ }
453
+ }
434
454
  class BaseMessenger {
435
455
  constructor({
436
456
  handlers,
@@ -628,7 +648,8 @@ class BaseMessenger {
628
648
  const message = {
629
649
  __xpaiChatKit: true,
630
650
  ...this.channelId ? { channelId: this.channelId } : {},
631
- ...data
651
+ ...data,
652
+ ...data.type === "response" && data.error !== void 0 ? { error: serializeFrameError(data.error) } : {}
632
653
  };
633
654
  (_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
634
655
  }
@@ -2601,6 +2622,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2601
2622
  }
2602
2623
  return connect(request);
2603
2624
  },
2625
+ onWorkbenchNavigationChange: async (navigation) => {
2626
+ var _a2, _b2, _c2;
2627
+ await ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onNavigationChange) == null ? void 0 : _c2.call(_b2, navigation));
2628
+ },
2604
2629
  onWorkbenchClientCommand: async ({
2605
2630
  commandKey,
2606
2631
  payload,