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