@xpert-ai/chatkit-ui5 0.4.2 → 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/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,
@@ -2511,6 +2583,16 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2511
2583
  }
2512
2584
  return onRequestPreview(request);
2513
2585
  },
2586
+ onConnectWorkspaceConnector: async (request) => {
2587
+ var _a2, _b2, _c2;
2588
+ const connect = (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.composer) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.onConnect;
2589
+ if (!connect) {
2590
+ __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2591
+ "Add composer.resources.onConnect to handle workspace Connector connections."
2592
+ ));
2593
+ }
2594
+ return connect(request);
2595
+ },
2514
2596
  onWorkbenchClientCommand: async ({
2515
2597
  commandKey,
2516
2598
  payload,
@@ -2521,9 +2603,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2521
2603
  var _a2, _b2;
2522
2604
  const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
2523
2605
  if (!onClientCommand) {
2524
- __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2525
- `No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
2526
- ));
2606
+ return { success: false, code: "unsupported", commandKey };
2527
2607
  }
2528
2608
  return onClientCommand({
2529
2609
  commandKey,
@@ -2765,6 +2845,20 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2765
2845
  closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
2766
2846
  wrapper.appendChild(closeButton);
2767
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
+ );
2768
2862
  __privateGet(this, _shadow).append(style);
2769
2863
  __privateGet(this, _messenger).on("left_header_icon_click", () => {
2770
2864
  var _a2, _b2, _c2;
@@ -2827,6 +2921,8 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2827
2921
  }
2828
2922
  });
2829
2923
  __privateGet(this, _messenger).on("unmount", () => {
2924
+ var _a2;
2925
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
2830
2926
  if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
2831
2927
  __privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
2832
2928
  __privateSet(this, _wrapper, void 0);
@@ -2848,9 +2944,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2848
2944
  }
2849
2945
  }
2850
2946
  disconnectedCallback() {
2851
- var _a2, _b2;
2852
- (_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
2853
- (_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(
2854
2951
  "click",
2855
2952
  __privateGet(this, _handleLauncherClose)
2856
2953
  );
@@ -2858,7 +2955,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2858
2955
  __privateGet(this, _petOverlay).destroy();
2859
2956
  }
2860
2957
  applySanitizedOptions(newOptions) {
2958
+ var _a2, _b2;
2861
2959
  __privateSet(this, _opts, newOptions);
2960
+ if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
2862
2961
  __privateSet(this, _petClosedByContextMenu, false);
2863
2962
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
2864
2963
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
@@ -2944,6 +3043,7 @@ _opts = new WeakMap();
2944
3043
  _frameUrl = new WeakMap();
2945
3044
  _frame = new WeakMap();
2946
3045
  _wrapper = new WeakMap();
3046
+ _windowDrag = new WeakMap();
2947
3047
  _launcherCloseButton = new WeakMap();
2948
3048
  _launcherOpen = new WeakMap();
2949
3049
  _chatMinimizedToPet = new WeakMap();
@@ -3007,7 +3107,8 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3007
3107
  };
3008
3108
  };
3009
3109
  getOverlayPetOptions_fn = function() {
3010
- 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") {
3011
3112
  return null;
3012
3113
  }
3013
3114
  let pet;