@xpert-ai/chatkit-web-component 0.5.4 → 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.
@@ -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
  class EventEmitter {
52
52
  constructor() {
53
53
  __publicField(this, "callbacks", /* @__PURE__ */ new Map());
@@ -893,6 +893,59 @@ const getCapabilities = (profile) => {
893
893
  }
894
894
  return { commands, events, backend, threadItems, errors, widgets };
895
895
  };
896
+ function parseWindowDragRegions(value) {
897
+ 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)
898
+ return null;
899
+ const regions = [];
900
+ for (const rect of value.regions) {
901
+ 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)
902
+ return null;
903
+ regions.push({
904
+ x: rect.x,
905
+ y: rect.y,
906
+ width: rect.width,
907
+ height: rect.height
908
+ });
909
+ }
910
+ return { width: value.width, height: value.height, regions };
911
+ }
912
+ class WindowDragOverlay {
913
+ constructor(wrapper, enabled) {
914
+ this.wrapper = wrapper;
915
+ this.enabled = enabled;
916
+ this.size = { width: 0, height: 0 };
917
+ this.layer = document.createElement("div");
918
+ this.layer.setAttribute("aria-hidden", "true");
919
+ this.layer.dataset.slot = "chatkit-window-drag";
920
+ this.layer.style.cssText = "position:absolute;inset:0;pointer-events:none;overflow:hidden;";
921
+ wrapper.append(this.layer);
922
+ this.observer = new ResizeObserver(() => {
923
+ if (this.wrapper.clientWidth !== this.size.width || this.wrapper.clientHeight !== this.size.height)
924
+ this.clear();
925
+ });
926
+ this.observer.observe(wrapper);
927
+ }
928
+ update(input) {
929
+ this.clear();
930
+ if (!this.enabled()) return;
931
+ const value = parseWindowDragRegions(input);
932
+ if (!value || Math.abs(value.width - this.wrapper.clientWidth) > 1 || Math.abs(value.height - this.wrapper.clientHeight) > 1)
933
+ return;
934
+ this.size = { width: value.width, height: value.height };
935
+ for (const rect of value.regions) {
936
+ const region = document.createElement("div");
937
+ 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;`;
938
+ this.layer.append(region);
939
+ }
940
+ }
941
+ clear() {
942
+ this.layer.replaceChildren();
943
+ }
944
+ destroy() {
945
+ this.observer.disconnect();
946
+ this.layer.remove();
947
+ }
948
+ }
896
949
  class ChatFrameMessenger extends BaseMessenger {
897
950
  // Messenger running in outer can always handle commands coming from inner
898
951
  canReceiveCommand(_) {
@@ -2681,6 +2734,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2681
2734
  __privateAdd(this, _frameUrl);
2682
2735
  __privateAdd(this, _frame);
2683
2736
  __privateAdd(this, _wrapper);
2737
+ __privateAdd(this, _windowDrag);
2684
2738
  __privateAdd(this, _launcherCloseButton);
2685
2739
  __privateAdd(this, _launcherOpen, false);
2686
2740
  __privateAdd(this, _chatMinimizedToPet, false);
@@ -2731,6 +2785,24 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2731
2785
  input.click();
2732
2786
  });
2733
2787
  },
2788
+ onApprovalDecision: async (input) => {
2789
+ var _a2, _b2;
2790
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onDecision;
2791
+ if (!handler)
2792
+ throw new IntegrationError2(
2793
+ "Add approvals.onDecision to handle host approvals."
2794
+ );
2795
+ return handler(input);
2796
+ },
2797
+ onApprovalAction: async (input) => {
2798
+ var _a2, _b2;
2799
+ const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onAction;
2800
+ if (!handler)
2801
+ throw new IntegrationError2(
2802
+ "Add approvals.onAction to handle approval actions."
2803
+ );
2804
+ return handler(input);
2805
+ },
2734
2806
  onClientToolCall: async ({
2735
2807
  name,
2736
2808
  params,
@@ -2756,6 +2828,16 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2756
2828
  }
2757
2829
  return onRequestPreview(request);
2758
2830
  },
2831
+ onConnectWorkspaceConnector: async (request) => {
2832
+ var _a2, _b2, _c2;
2833
+ const connect = (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.composer) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.onConnect;
2834
+ if (!connect) {
2835
+ __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2836
+ "Add composer.resources.onConnect to handle workspace Connector connections."
2837
+ ));
2838
+ }
2839
+ return connect(request);
2840
+ },
2759
2841
  onWorkbenchClientCommand: async ({
2760
2842
  commandKey,
2761
2843
  payload,
@@ -2766,9 +2848,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2766
2848
  var _a2, _b2;
2767
2849
  const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
2768
2850
  if (!onClientCommand) {
2769
- __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2770
- `No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
2771
- ));
2851
+ return { success: false, code: "unsupported", commandKey };
2772
2852
  }
2773
2853
  return onClientCommand({
2774
2854
  commandKey,
@@ -3010,6 +3090,20 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3010
3090
  closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
3011
3091
  wrapper.appendChild(closeButton);
3012
3092
  __privateSet(this, _launcherCloseButton, closeButton);
3093
+ __privateSet(this, _windowDrag, new WindowDragOverlay(
3094
+ wrapper,
3095
+ () => {
3096
+ var _a2, _b2;
3097
+ return ((_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.windowDrag) === true;
3098
+ }
3099
+ ));
3100
+ __privateGet(this, _messenger).on(
3101
+ "window_drag_regions",
3102
+ (data) => {
3103
+ var _a2;
3104
+ return (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.update(data);
3105
+ }
3106
+ );
3013
3107
  __privateGet(this, _shadow).append(style);
3014
3108
  __privateGet(this, _messenger).on("left_header_icon_click", () => {
3015
3109
  var _a2, _b2, _c2;
@@ -3072,6 +3166,8 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3072
3166
  }
3073
3167
  });
3074
3168
  __privateGet(this, _messenger).on("unmount", () => {
3169
+ var _a2;
3170
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
3075
3171
  if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
3076
3172
  __privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
3077
3173
  __privateSet(this, _wrapper, void 0);
@@ -3093,9 +3189,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3093
3189
  }
3094
3190
  }
3095
3191
  disconnectedCallback() {
3096
- var _a2, _b2;
3097
- (_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
3098
- (_b2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _b2.removeEventListener(
3192
+ var _a2, _b2, _c2;
3193
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
3194
+ (_b2 = __privateGet(this, _frame)) == null ? void 0 : _b2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
3195
+ (_c2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _c2.removeEventListener(
3099
3196
  "click",
3100
3197
  __privateGet(this, _handleLauncherClose)
3101
3198
  );
@@ -3103,7 +3200,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3103
3200
  __privateGet(this, _petOverlay).destroy();
3104
3201
  }
3105
3202
  applySanitizedOptions(newOptions) {
3203
+ var _a2, _b2;
3106
3204
  __privateSet(this, _opts, newOptions);
3205
+ if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
3107
3206
  __privateSet(this, _petClosedByContextMenu, false);
3108
3207
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
3109
3208
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
@@ -3189,6 +3288,7 @@ _opts = new WeakMap();
3189
3288
  _frameUrl = new WeakMap();
3190
3289
  _frame = new WeakMap();
3191
3290
  _wrapper = new WeakMap();
3291
+ _windowDrag = new WeakMap();
3192
3292
  _launcherCloseButton = new WeakMap();
3193
3293
  _launcherOpen = new WeakMap();
3194
3294
  _chatMinimizedToPet = new WeakMap();
@@ -3252,7 +3352,8 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3252
3352
  };
3253
3353
  };
3254
3354
  getOverlayPetOptions_fn = function() {
3255
- if (__privateGet(this, _petClosedByContextMenu)) {
3355
+ var _a2;
3356
+ if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3256
3357
  return null;
3257
3358
  }
3258
3359
  let pet;