@xpert-ai/chatkit-ui5 0.4.3 → 0.8.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
@@ -47,7 +47,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
47
47
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
48
48
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
49
49
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
50
- var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setRuntimeCapabilities_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _channelId, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
50
+ var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setRuntimeCapabilities_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _windowDrag, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _channelId, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
51
51
  import { normalizePetOptions, DEFAULT_PET_STORAGE_KEY, resolvePetCharacter, normalizeBoundsPadding, getPinnedPetPosition, clampPetPosition } from "@xpert-ai/chatkit-types";
52
52
  class EventEmitter {
53
53
  constructor() {
@@ -894,6 +894,59 @@ const getCapabilities = (profile) => {
894
894
  }
895
895
  return { commands, events, backend, threadItems, errors, widgets };
896
896
  };
897
+ function parseWindowDragRegions(value) {
898
+ if (!value || typeof value !== "object" || !("width" in value) || typeof value.width !== "number" || !Number.isFinite(value.width) || value.width <= 0 || !("height" in value) || typeof value.height !== "number" || !Number.isFinite(value.height) || value.height <= 0 || !("regions" in value) || !Array.isArray(value.regions) || value.regions.length > 128)
899
+ return null;
900
+ const regions = [];
901
+ for (const rect of value.regions) {
902
+ if (!rect || typeof rect !== "object" || typeof rect.x !== "number" || !Number.isFinite(rect.x) || rect.x < 0 || typeof rect.y !== "number" || !Number.isFinite(rect.y) || rect.y < 0 || typeof rect.width !== "number" || !Number.isFinite(rect.width) || rect.width <= 0 || typeof rect.height !== "number" || !Number.isFinite(rect.height) || rect.height <= 0 || rect.x + rect.width > value.width + 1 || rect.y + rect.height > Math.min(value.height, 96) + 1)
903
+ return null;
904
+ regions.push({
905
+ x: rect.x,
906
+ y: rect.y,
907
+ width: rect.width,
908
+ height: rect.height
909
+ });
910
+ }
911
+ return { width: value.width, height: value.height, regions };
912
+ }
913
+ class WindowDragOverlay {
914
+ constructor(wrapper, enabled) {
915
+ this.wrapper = wrapper;
916
+ this.enabled = enabled;
917
+ this.size = { width: 0, height: 0 };
918
+ this.layer = document.createElement("div");
919
+ this.layer.setAttribute("aria-hidden", "true");
920
+ this.layer.dataset.slot = "chatkit-window-drag";
921
+ this.layer.style.cssText = "position:absolute;inset:0;pointer-events:none;overflow:hidden;";
922
+ wrapper.append(this.layer);
923
+ this.observer = new ResizeObserver(() => {
924
+ if (this.wrapper.clientWidth !== this.size.width || this.wrapper.clientHeight !== this.size.height)
925
+ this.clear();
926
+ });
927
+ this.observer.observe(wrapper);
928
+ }
929
+ update(input) {
930
+ this.clear();
931
+ if (!this.enabled()) return;
932
+ const value = parseWindowDragRegions(input);
933
+ if (!value || Math.abs(value.width - this.wrapper.clientWidth) > 1 || Math.abs(value.height - this.wrapper.clientHeight) > 1)
934
+ return;
935
+ this.size = { width: value.width, height: value.height };
936
+ for (const rect of value.regions) {
937
+ const region = document.createElement("div");
938
+ region.style.cssText = `position:absolute;left:${rect.x}px;top:${rect.y}px;width:${rect.width}px;height:${rect.height}px;pointer-events:auto;user-select:none;-webkit-app-region:drag;`;
939
+ this.layer.append(region);
940
+ }
941
+ }
942
+ clear() {
943
+ this.layer.replaceChildren();
944
+ }
945
+ destroy() {
946
+ this.observer.disconnect();
947
+ this.layer.remove();
948
+ }
949
+ }
897
950
  class ChatFrameMessenger extends BaseMessenger {
898
951
  // Messenger running in outer can always handle commands coming from inner
899
952
  canReceiveCommand(_) {
@@ -2436,6 +2489,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2436
2489
  __privateAdd(this, _frameUrl);
2437
2490
  __privateAdd(this, _frame);
2438
2491
  __privateAdd(this, _wrapper);
2492
+ __privateAdd(this, _windowDrag);
2439
2493
  __privateAdd(this, _launcherCloseButton);
2440
2494
  __privateAdd(this, _launcherOpen, false);
2441
2495
  __privateAdd(this, _chatMinimizedToPet, false);
@@ -2486,6 +2540,24 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2486
2540
  input.click();
2487
2541
  });
2488
2542
  },
2543
+ onApprovalDecision: async (input) => {
2544
+ var _a2, _b2;
2545
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onDecision;
2546
+ if (!handler)
2547
+ throw new IntegrationError2(
2548
+ "Add approvals.onDecision to handle host approvals."
2549
+ );
2550
+ return handler(input);
2551
+ },
2552
+ onApprovalAction: async (input) => {
2553
+ var _a2, _b2;
2554
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onAction;
2555
+ if (!handler)
2556
+ throw new IntegrationError2(
2557
+ "Add approvals.onAction to handle approval actions."
2558
+ );
2559
+ return handler(input);
2560
+ },
2489
2561
  onClientToolCall: async ({
2490
2562
  name,
2491
2563
  params,
@@ -2531,9 +2603,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2531
2603
  var _a2, _b2;
2532
2604
  const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
2533
2605
  if (!onClientCommand) {
2534
- __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2535
- `No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
2536
- ));
2606
+ return { success: false, code: "unsupported", commandKey };
2537
2607
  }
2538
2608
  return onClientCommand({
2539
2609
  commandKey,
@@ -2775,6 +2845,20 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2775
2845
  closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
2776
2846
  wrapper.appendChild(closeButton);
2777
2847
  __privateSet(this, _launcherCloseButton, closeButton);
2848
+ __privateSet(this, _windowDrag, new WindowDragOverlay(
2849
+ wrapper,
2850
+ () => {
2851
+ var _a2, _b2;
2852
+ return ((_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.windowDrag) === true;
2853
+ }
2854
+ ));
2855
+ __privateGet(this, _messenger).on(
2856
+ "window_drag_regions",
2857
+ (data) => {
2858
+ var _a2;
2859
+ return (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.update(data);
2860
+ }
2861
+ );
2778
2862
  __privateGet(this, _shadow).append(style);
2779
2863
  __privateGet(this, _messenger).on("left_header_icon_click", () => {
2780
2864
  var _a2, _b2, _c2;
@@ -2837,6 +2921,8 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2837
2921
  }
2838
2922
  });
2839
2923
  __privateGet(this, _messenger).on("unmount", () => {
2924
+ var _a2;
2925
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
2840
2926
  if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
2841
2927
  __privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
2842
2928
  __privateSet(this, _wrapper, void 0);
@@ -2858,9 +2944,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2858
2944
  }
2859
2945
  }
2860
2946
  disconnectedCallback() {
2861
- var _a2, _b2;
2862
- (_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
2863
- (_b2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _b2.removeEventListener(
2947
+ var _a2, _b2, _c2;
2948
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
2949
+ (_b2 = __privateGet(this, _frame)) == null ? void 0 : _b2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
2950
+ (_c2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _c2.removeEventListener(
2864
2951
  "click",
2865
2952
  __privateGet(this, _handleLauncherClose)
2866
2953
  );
@@ -2868,7 +2955,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2868
2955
  __privateGet(this, _petOverlay).destroy();
2869
2956
  }
2870
2957
  applySanitizedOptions(newOptions) {
2958
+ var _a2, _b2;
2871
2959
  __privateSet(this, _opts, newOptions);
2960
+ if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
2872
2961
  __privateSet(this, _petClosedByContextMenu, false);
2873
2962
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
2874
2963
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
@@ -2954,6 +3043,7 @@ _opts = new WeakMap();
2954
3043
  _frameUrl = new WeakMap();
2955
3044
  _frame = new WeakMap();
2956
3045
  _wrapper = new WeakMap();
3046
+ _windowDrag = new WeakMap();
2957
3047
  _launcherCloseButton = new WeakMap();
2958
3048
  _launcherOpen = new WeakMap();
2959
3049
  _chatMinimizedToPet = new WeakMap();
@@ -3017,7 +3107,8 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3017
3107
  };
3018
3108
  };
3019
3109
  getOverlayPetOptions_fn = function() {
3020
- if (__privateGet(this, _petClosedByContextMenu)) {
3110
+ var _a2;
3111
+ if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3021
3112
  return null;
3022
3113
  }
3023
3114
  let pet;