@xpert-ai/chatkit-web-component 0.6.0 → 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,
@@ -2776,9 +2848,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2776
2848
  var _a2, _b2;
2777
2849
  const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
2778
2850
  if (!onClientCommand) {
2779
- __privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
2780
- `No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
2781
- ));
2851
+ return { success: false, code: "unsupported", commandKey };
2782
2852
  }
2783
2853
  return onClientCommand({
2784
2854
  commandKey,
@@ -3020,6 +3090,20 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3020
3090
  closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
3021
3091
  wrapper.appendChild(closeButton);
3022
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
+ );
3023
3107
  __privateGet(this, _shadow).append(style);
3024
3108
  __privateGet(this, _messenger).on("left_header_icon_click", () => {
3025
3109
  var _a2, _b2, _c2;
@@ -3082,6 +3166,8 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3082
3166
  }
3083
3167
  });
3084
3168
  __privateGet(this, _messenger).on("unmount", () => {
3169
+ var _a2;
3170
+ (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
3085
3171
  if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
3086
3172
  __privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
3087
3173
  __privateSet(this, _wrapper, void 0);
@@ -3103,9 +3189,10 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3103
3189
  }
3104
3190
  }
3105
3191
  disconnectedCallback() {
3106
- var _a2, _b2;
3107
- (_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
3108
- (_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(
3109
3196
  "click",
3110
3197
  __privateGet(this, _handleLauncherClose)
3111
3198
  );
@@ -3113,7 +3200,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3113
3200
  __privateGet(this, _petOverlay).destroy();
3114
3201
  }
3115
3202
  applySanitizedOptions(newOptions) {
3203
+ var _a2, _b2;
3116
3204
  __privateSet(this, _opts, newOptions);
3205
+ if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
3117
3206
  __privateSet(this, _petClosedByContextMenu, false);
3118
3207
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
3119
3208
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
@@ -3199,6 +3288,7 @@ _opts = new WeakMap();
3199
3288
  _frameUrl = new WeakMap();
3200
3289
  _frame = new WeakMap();
3201
3290
  _wrapper = new WeakMap();
3291
+ _windowDrag = new WeakMap();
3202
3292
  _launcherCloseButton = new WeakMap();
3203
3293
  _launcherOpen = new WeakMap();
3204
3294
  _chatMinimizedToPet = new WeakMap();
@@ -3262,7 +3352,8 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3262
3352
  };
3263
3353
  };
3264
3354
  getOverlayPetOptions_fn = function() {
3265
- 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") {
3266
3357
  return null;
3267
3358
  }
3268
3359
  let pet;