@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.
|
@@ -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(_) {
|
|
@@ -2685,6 +2738,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2685
2738
|
__privateAdd(this, _frameUrl);
|
|
2686
2739
|
__privateAdd(this, _frame);
|
|
2687
2740
|
__privateAdd(this, _wrapper);
|
|
2741
|
+
__privateAdd(this, _windowDrag);
|
|
2688
2742
|
__privateAdd(this, _launcherCloseButton);
|
|
2689
2743
|
__privateAdd(this, _launcherOpen, false);
|
|
2690
2744
|
__privateAdd(this, _chatMinimizedToPet, false);
|
|
@@ -2735,6 +2789,24 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2735
2789
|
input.click();
|
|
2736
2790
|
});
|
|
2737
2791
|
},
|
|
2792
|
+
onApprovalDecision: async (input) => {
|
|
2793
|
+
var _a2, _b2;
|
|
2794
|
+
const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onDecision;
|
|
2795
|
+
if (!handler)
|
|
2796
|
+
throw new IntegrationError(
|
|
2797
|
+
"Add approvals.onDecision to handle host approvals."
|
|
2798
|
+
);
|
|
2799
|
+
return handler(input);
|
|
2800
|
+
},
|
|
2801
|
+
onApprovalAction: async (input) => {
|
|
2802
|
+
var _a2, _b2;
|
|
2803
|
+
const handler = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.approvals) == null ? void 0 : _b2.onAction;
|
|
2804
|
+
if (!handler)
|
|
2805
|
+
throw new IntegrationError(
|
|
2806
|
+
"Add approvals.onAction to handle approval actions."
|
|
2807
|
+
);
|
|
2808
|
+
return handler(input);
|
|
2809
|
+
},
|
|
2738
2810
|
onClientToolCall: async ({
|
|
2739
2811
|
name,
|
|
2740
2812
|
params,
|
|
@@ -2760,6 +2832,16 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2760
2832
|
}
|
|
2761
2833
|
return onRequestPreview(request);
|
|
2762
2834
|
},
|
|
2835
|
+
onConnectWorkspaceConnector: async (request) => {
|
|
2836
|
+
var _a2, _b2, _c2;
|
|
2837
|
+
const connect = (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.composer) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.onConnect;
|
|
2838
|
+
if (!connect) {
|
|
2839
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError(
|
|
2840
|
+
"Add composer.resources.onConnect to handle workspace Connector connections."
|
|
2841
|
+
));
|
|
2842
|
+
}
|
|
2843
|
+
return connect(request);
|
|
2844
|
+
},
|
|
2763
2845
|
onWorkbenchClientCommand: async ({
|
|
2764
2846
|
commandKey,
|
|
2765
2847
|
payload,
|
|
@@ -2770,9 +2852,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2770
2852
|
var _a2, _b2;
|
|
2771
2853
|
const onClientCommand = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.workbench) == null ? void 0 : _b2.onClientCommand;
|
|
2772
2854
|
if (!onClientCommand) {
|
|
2773
|
-
|
|
2774
|
-
`No handler for workbench client command "${commandKey}". Add workbench.onClientCommand to your ChatKit options.`
|
|
2775
|
-
));
|
|
2855
|
+
return { success: false, code: "unsupported", commandKey };
|
|
2776
2856
|
}
|
|
2777
2857
|
return onClientCommand({
|
|
2778
2858
|
commandKey,
|
|
@@ -3014,6 +3094,20 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3014
3094
|
closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
|
|
3015
3095
|
wrapper.appendChild(closeButton);
|
|
3016
3096
|
__privateSet(this, _launcherCloseButton, closeButton);
|
|
3097
|
+
__privateSet(this, _windowDrag, new WindowDragOverlay(
|
|
3098
|
+
wrapper,
|
|
3099
|
+
() => {
|
|
3100
|
+
var _a2, _b2;
|
|
3101
|
+
return ((_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.windowDrag) === true;
|
|
3102
|
+
}
|
|
3103
|
+
));
|
|
3104
|
+
__privateGet(this, _messenger).on(
|
|
3105
|
+
"window_drag_regions",
|
|
3106
|
+
(data) => {
|
|
3107
|
+
var _a2;
|
|
3108
|
+
return (_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.update(data);
|
|
3109
|
+
}
|
|
3110
|
+
);
|
|
3017
3111
|
__privateGet(this, _shadow).append(style);
|
|
3018
3112
|
__privateGet(this, _messenger).on("left_header_icon_click", () => {
|
|
3019
3113
|
var _a2, _b2, _c2;
|
|
@@ -3076,6 +3170,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3076
3170
|
}
|
|
3077
3171
|
});
|
|
3078
3172
|
__privateGet(this, _messenger).on("unmount", () => {
|
|
3173
|
+
var _a2;
|
|
3174
|
+
(_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
|
|
3079
3175
|
if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
|
|
3080
3176
|
__privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
|
|
3081
3177
|
__privateSet(this, _wrapper, void 0);
|
|
@@ -3097,9 +3193,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3097
3193
|
}
|
|
3098
3194
|
}
|
|
3099
3195
|
disconnectedCallback() {
|
|
3100
|
-
var _a2, _b2;
|
|
3101
|
-
(_a2 = __privateGet(this,
|
|
3102
|
-
(_b2 = __privateGet(this,
|
|
3196
|
+
var _a2, _b2, _c2;
|
|
3197
|
+
(_a2 = __privateGet(this, _windowDrag)) == null ? void 0 : _a2.destroy();
|
|
3198
|
+
(_b2 = __privateGet(this, _frame)) == null ? void 0 : _b2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
|
|
3199
|
+
(_c2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _c2.removeEventListener(
|
|
3103
3200
|
"click",
|
|
3104
3201
|
__privateGet(this, _handleLauncherClose)
|
|
3105
3202
|
);
|
|
@@ -3107,7 +3204,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3107
3204
|
__privateGet(this, _petOverlay).destroy();
|
|
3108
3205
|
}
|
|
3109
3206
|
applySanitizedOptions(newOptions) {
|
|
3207
|
+
var _a2, _b2;
|
|
3110
3208
|
__privateSet(this, _opts, newOptions);
|
|
3209
|
+
if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
|
|
3111
3210
|
__privateSet(this, _petClosedByContextMenu, false);
|
|
3112
3211
|
__privateGet(this, _petOverlay).setLocale(newOptions.locale);
|
|
3113
3212
|
__privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
|
|
@@ -3193,6 +3292,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3193
3292
|
_frameUrl = new WeakMap();
|
|
3194
3293
|
_frame = new WeakMap();
|
|
3195
3294
|
_wrapper = new WeakMap();
|
|
3295
|
+
_windowDrag = new WeakMap();
|
|
3196
3296
|
_launcherCloseButton = new WeakMap();
|
|
3197
3297
|
_launcherOpen = new WeakMap();
|
|
3198
3298
|
_chatMinimizedToPet = new WeakMap();
|
|
@@ -3256,7 +3356,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3256
3356
|
};
|
|
3257
3357
|
};
|
|
3258
3358
|
getOverlayPetOptions_fn = function() {
|
|
3259
|
-
|
|
3359
|
+
var _a2;
|
|
3360
|
+
if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
|
|
3260
3361
|
return null;
|
|
3261
3362
|
}
|
|
3262
3363
|
let pet;
|