@xpert-ai/chatkit-ui5 0.4.3 → 0.7.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/chatkit.cjs CHANGED
@@ -48,7 +48,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
48
48
  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);
49
49
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
50
50
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
51
- 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;
51
+ 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;
52
52
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
53
53
  const chatkitTypes = require("@xpert-ai/chatkit-types");
54
54
  class EventEmitter {
@@ -896,6 +896,59 @@ const getCapabilities = (profile) => {
896
896
  }
897
897
  return { commands, events, backend, threadItems, errors, widgets };
898
898
  };
899
+ function parseWindowDragRegions(value) {
900
+ 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)
901
+ return null;
902
+ const regions = [];
903
+ for (const rect of value.regions) {
904
+ 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)
905
+ return null;
906
+ regions.push({
907
+ x: rect.x,
908
+ y: rect.y,
909
+ width: rect.width,
910
+ height: rect.height
911
+ });
912
+ }
913
+ return { width: value.width, height: value.height, regions };
914
+ }
915
+ class WindowDragOverlay {
916
+ constructor(wrapper, enabled) {
917
+ this.wrapper = wrapper;
918
+ this.enabled = enabled;
919
+ this.size = { width: 0, height: 0 };
920
+ this.layer = document.createElement("div");
921
+ this.layer.setAttribute("aria-hidden", "true");
922
+ this.layer.dataset.slot = "chatkit-window-drag";
923
+ this.layer.style.cssText = "position:absolute;inset:0;pointer-events:none;overflow:hidden;";
924
+ wrapper.append(this.layer);
925
+ this.observer = new ResizeObserver(() => {
926
+ if (this.wrapper.clientWidth !== this.size.width || this.wrapper.clientHeight !== this.size.height)
927
+ this.clear();
928
+ });
929
+ this.observer.observe(wrapper);
930
+ }
931
+ update(input) {
932
+ this.clear();
933
+ if (!this.enabled()) return;
934
+ const value = parseWindowDragRegions(input);
935
+ if (!value || Math.abs(value.width - this.wrapper.clientWidth) > 1 || Math.abs(value.height - this.wrapper.clientHeight) > 1)
936
+ return;
937
+ this.size = { width: value.width, height: value.height };
938
+ for (const rect of value.regions) {
939
+ const region = document.createElement("div");
940
+ 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;`;
941
+ this.layer.append(region);
942
+ }
943
+ }
944
+ clear() {
945
+ this.layer.replaceChildren();
946
+ }
947
+ destroy() {
948
+ this.observer.disconnect();
949
+ this.layer.remove();
950
+ }
951
+ }
899
952
  class ChatFrameMessenger extends BaseMessenger {
900
953
  // Messenger running in outer can always handle commands coming from inner
901
954
  canReceiveCommand(_) {
@@ -2438,6 +2491,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2438
2491
  __privateAdd(this, _frameUrl);
2439
2492
  __privateAdd(this, _frame);
2440
2493
  __privateAdd(this, _wrapper);
2494
+ __privateAdd(this, _windowDrag);
2441
2495
  __privateAdd(this, _launcherCloseButton);
2442
2496
  __privateAdd(this, _launcherOpen, false);
2443
2497
  __privateAdd(this, _chatMinimizedToPet, false);
@@ -2488,6 +2542,24 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2488
2542
  input.click();
2489
2543
  });
2490
2544
  },
2545
+ onApprovalDecision: async (input) => {
2546
+ var _a2, _b2;
2547
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onDecision;
2548
+ if (!handler)
2549
+ throw new IntegrationError2(
2550
+ "Add approvals.onDecision to handle host approvals."
2551
+ );
2552
+ return handler(input);
2553
+ },
2554
+ onApprovalAction: async (input) => {
2555
+ var _a2, _b2;
2556
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onAction;
2557
+ if (!handler)
2558
+ throw new IntegrationError2(
2559
+ "Add approvals.onAction to handle approval actions."
2560
+ );
2561
+ return handler(input);
2562
+ },
2491
2563
  onClientToolCall: async ({
2492
2564
  name,
2493
2565
  params,
@@ -2533,9 +2605,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2533
2605
  var _a2, _b2;
2534
2606
  const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
2535
2607
  if (!onClientCommand) {
2536
- __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2537
- `No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
2538
- ));
2608
+ return { success: false, code: "unsupported", commandKey };
2539
2609
  }
2540
2610
  return onClientCommand({
2541
2611
  commandKey,
@@ -2777,6 +2847,20 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2777
2847
  closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
2778
2848
  wrapper.appendChild(closeButton);
2779
2849
  __privateSet(this, _launcherCloseButton, closeButton);
2850
+ __privateSet(this, _windowDrag, new WindowDragOverlay(
2851
+ wrapper,
2852
+ () => {
2853
+ var _a2, _b2;
2854
+ return ((_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.windowDrag) === true;
2855
+ }
2856
+ ));
2857
+ __privateGet(this, _messenger).on(
2858
+ "window_drag_regions",
2859
+ (data) => {
2860
+ var _a2;
2861
+ return (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.update(data);
2862
+ }
2863
+ );
2780
2864
  __privateGet(this, _shadow).append(style);
2781
2865
  __privateGet(this, _messenger).on("left_header_icon_click", () => {
2782
2866
  var _a2, _b2, _c2;
@@ -2839,6 +2923,8 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2839
2923
  }
2840
2924
  });
2841
2925
  __privateGet(this, _messenger).on("unmount", () => {
2926
+ var _a2;
2927
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
2842
2928
  if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
2843
2929
  __privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
2844
2930
  __privateSet(this, _wrapper, void 0);
@@ -2860,9 +2946,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2860
2946
  }
2861
2947
  }
2862
2948
  disconnectedCallback() {
2863
- var _a2, _b2;
2864
- (_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
2865
- (_b2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _b2.removeEventListener(
2949
+ var _a2, _b2, _c2;
2950
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
2951
+ (_b2 = __privateGet(this, _frame)) == null ? void 0 : _b2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
2952
+ (_c2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _c2.removeEventListener(
2866
2953
  "click",
2867
2954
  __privateGet(this, _handleLauncherClose)
2868
2955
  );
@@ -2870,7 +2957,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2870
2957
  __privateGet(this, _petOverlay).destroy();
2871
2958
  }
2872
2959
  applySanitizedOptions(newOptions) {
2960
+ var _a2, _b2;
2873
2961
  __privateSet(this, _opts, newOptions);
2962
+ if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
2874
2963
  __privateSet(this, _petClosedByContextMenu, false);
2875
2964
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
2876
2965
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
@@ -2956,6 +3045,7 @@ _opts = new WeakMap();
2956
3045
  _frameUrl = new WeakMap();
2957
3046
  _frame = new WeakMap();
2958
3047
  _wrapper = new WeakMap();
3048
+ _windowDrag = new WeakMap();
2959
3049
  _launcherCloseButton = new WeakMap();
2960
3050
  _launcherOpen = new WeakMap();
2961
3051
  _chatMinimizedToPet = new WeakMap();
@@ -3019,7 +3109,8 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3019
3109
  };
3020
3110
  };
3021
3111
  getOverlayPetOptions_fn = function() {
3022
- if (__privateGet(this, _petClosedByContextMenu)) {
3112
+ var _a2;
3113
+ if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3023
3114
  return null;
3024
3115
  }
3025
3116
  let pet;