@xpert-ai/chatkit-ui5 0.4.1 → 0.4.2
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/chatkit.cjs +125 -23
- package/dist/chatkit.cjs.map +1 -1
- package/dist/chatkit.ui5.js +125 -23
- package/dist/chatkit.ui5.js.map +1 -1
- package/dist/index.js +125 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/chatkit.cjs
CHANGED
|
@@ -48,7 +48,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
48
48
|
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);
|
|
49
49
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
50
50
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
51
|
-
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, _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
|
+
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;
|
|
52
52
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
53
53
|
const chatkitTypes = require("@xpert-ai/chatkit-types");
|
|
54
54
|
class EventEmitter {
|
|
@@ -369,7 +369,7 @@ const fetchEventSourceWithRetry = async (url, params) => {
|
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
};
|
|
372
|
-
function
|
|
372
|
+
function createSecureChannelId() {
|
|
373
373
|
const cryptoRef = globalThis.crypto;
|
|
374
374
|
if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
|
|
375
375
|
return cryptoRef.randomUUID();
|
|
@@ -381,7 +381,30 @@ function safeRandomUUID() {
|
|
|
381
381
|
bytes[8] = bytes[8] & 63 | 128;
|
|
382
382
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
383
383
|
}
|
|
384
|
-
return
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
function safeRandomUUID() {
|
|
387
|
+
return createSecureChannelId() ?? `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
388
|
+
}
|
|
389
|
+
function isTrustedChatKitMessageEvent(event, { channelId, expectedOrigin, expectedSource }) {
|
|
390
|
+
const payload = event.data;
|
|
391
|
+
if (!payload || typeof payload !== "object" || !("__xpaiChatKit" in payload)) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
if (payload.__xpaiChatKit !== true) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
if (expectedOrigin !== "*" && event.origin !== expectedOrigin) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
if (event.source === expectedSource) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
const normalizedChannelId = channelId == null ? void 0 : channelId.trim();
|
|
404
|
+
if (normalizedChannelId) {
|
|
405
|
+
return "channelId" in payload && payload.channelId === normalizedChannelId;
|
|
406
|
+
}
|
|
407
|
+
return false;
|
|
385
408
|
}
|
|
386
409
|
let IntegrationError$1 = class IntegrationError extends Error {
|
|
387
410
|
constructor(message) {
|
|
@@ -415,10 +438,12 @@ class BaseMessenger {
|
|
|
415
438
|
handlers,
|
|
416
439
|
target,
|
|
417
440
|
targetOrigin,
|
|
441
|
+
channelId,
|
|
418
442
|
fetch: fetch2 = window.fetch
|
|
419
443
|
}) {
|
|
420
444
|
__publicField(this, "targetOrigin");
|
|
421
445
|
__publicField(this, "target");
|
|
446
|
+
__publicField(this, "channelId");
|
|
422
447
|
__publicField(this, "commandHandlers");
|
|
423
448
|
__publicField(this, "_fetch");
|
|
424
449
|
__publicField(this, "emitter", new EventEmitter());
|
|
@@ -449,7 +474,11 @@ class BaseMessenger {
|
|
|
449
474
|
));
|
|
450
475
|
__publicField(this, "handleMessage", async (event) => {
|
|
451
476
|
var _a2, _b2, _c2, _d;
|
|
452
|
-
if (!event
|
|
477
|
+
if (!isTrustedChatKitMessageEvent(event, {
|
|
478
|
+
channelId: this.channelId,
|
|
479
|
+
expectedOrigin: this.targetOrigin,
|
|
480
|
+
expectedSource: this.target()
|
|
481
|
+
})) {
|
|
453
482
|
return;
|
|
454
483
|
}
|
|
455
484
|
const data = event.data;
|
|
@@ -590,6 +619,7 @@ class BaseMessenger {
|
|
|
590
619
|
this.commandHandlers = handlers;
|
|
591
620
|
this.target = target;
|
|
592
621
|
this.targetOrigin = targetOrigin;
|
|
622
|
+
this.channelId = (channelId == null ? void 0 : channelId.trim()) || void 0;
|
|
593
623
|
this._fetch = (...args) => fetch2(...args);
|
|
594
624
|
}
|
|
595
625
|
setTargetOrigin(targetOrigin) {
|
|
@@ -599,6 +629,7 @@ class BaseMessenger {
|
|
|
599
629
|
var _a2;
|
|
600
630
|
const message = {
|
|
601
631
|
__xpaiChatKit: true,
|
|
632
|
+
...this.channelId ? { channelId: this.channelId } : {},
|
|
602
633
|
...data
|
|
603
634
|
};
|
|
604
635
|
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
@@ -714,6 +745,8 @@ const BASE_CAPABILITY_ALLOWLIST = [
|
|
|
714
745
|
"event.response.end",
|
|
715
746
|
"event.response.stop",
|
|
716
747
|
"event.thread.change",
|
|
748
|
+
"event.project.change",
|
|
749
|
+
"event.connectors.change",
|
|
717
750
|
"event.tool.change",
|
|
718
751
|
"event.thread.load.start",
|
|
719
752
|
"event.thread.load.end",
|
|
@@ -819,7 +852,7 @@ const BASE_CAPABILITY_DENYLIST = [
|
|
|
819
852
|
"widget.Map"
|
|
820
853
|
];
|
|
821
854
|
const PROFILE_TO_RULES = {
|
|
822
|
-
|
|
855
|
+
chatkit: {
|
|
823
856
|
allow: [...BASE_CAPABILITY_ALLOWLIST, "thread.item.image_generation"],
|
|
824
857
|
deny: BASE_CAPABILITY_DENYLIST
|
|
825
858
|
}
|
|
@@ -1153,6 +1186,7 @@ class PetOverlay {
|
|
|
1153
1186
|
this.lastDragPosition = null;
|
|
1154
1187
|
this.lastDragClientX = null;
|
|
1155
1188
|
this.dragAnimation = null;
|
|
1189
|
+
this.activePointerId = null;
|
|
1156
1190
|
this.isDragging = false;
|
|
1157
1191
|
this.isHovering = false;
|
|
1158
1192
|
this.movedDuringDrag = false;
|
|
@@ -1284,7 +1318,7 @@ class PetOverlay {
|
|
|
1284
1318
|
};
|
|
1285
1319
|
this.handlePointerDown = (event) => {
|
|
1286
1320
|
var _a2, _b2;
|
|
1287
|
-
if (event.button !== 0 || event.ctrlKey) {
|
|
1321
|
+
if (event.button !== 0 || event.ctrlKey || this.isDragging) {
|
|
1288
1322
|
return;
|
|
1289
1323
|
}
|
|
1290
1324
|
this.closeContextMenu();
|
|
@@ -1310,12 +1344,17 @@ class PetOverlay {
|
|
|
1310
1344
|
this.movedDuringDrag = false;
|
|
1311
1345
|
this.dragPosition = nextPosition;
|
|
1312
1346
|
this.isDragging = true;
|
|
1347
|
+
this.activePointerId = event.pointerId;
|
|
1313
1348
|
this.clearRestingDelayTimer();
|
|
1314
1349
|
this.isHovering = true;
|
|
1350
|
+
this.captureActivePointer();
|
|
1315
1351
|
this.installDragListeners();
|
|
1316
1352
|
this.rescheduleAnimation();
|
|
1317
1353
|
};
|
|
1318
1354
|
this.handlePointerMove = (event) => {
|
|
1355
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1319
1358
|
const nextPosition = this.getNextDragPosition(event);
|
|
1320
1359
|
const last = this.lastDragPosition;
|
|
1321
1360
|
if (last && (Math.abs(last.x - nextPosition.x) > DRAG_DIRECTION_THRESHOLD_PX || Math.abs(last.y - nextPosition.y) > DRAG_DIRECTION_THRESHOLD_PX)) {
|
|
@@ -1335,20 +1374,18 @@ class PetOverlay {
|
|
|
1335
1374
|
this.render();
|
|
1336
1375
|
};
|
|
1337
1376
|
this.handlePointerUp = (event) => {
|
|
1377
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1338
1380
|
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1339
|
-
this.
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
this.
|
|
1343
|
-
|
|
1344
|
-
this.persistPosition(finalPosition);
|
|
1345
|
-
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
1346
|
-
this.isHovering = true;
|
|
1347
|
-
this.rescheduleAnimation();
|
|
1348
|
-
} else {
|
|
1349
|
-
this.enterRestingAfterDelay();
|
|
1350
|
-
this.rescheduleAnimation();
|
|
1381
|
+
this.finishDrag(finalPosition, event);
|
|
1382
|
+
};
|
|
1383
|
+
this.handleLostPointerCapture = (event) => {
|
|
1384
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1385
|
+
return;
|
|
1351
1386
|
}
|
|
1387
|
+
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1388
|
+
this.finishDrag(finalPosition, event);
|
|
1352
1389
|
};
|
|
1353
1390
|
this.handleClick = () => {
|
|
1354
1391
|
var _a2;
|
|
@@ -1552,6 +1589,7 @@ class PetOverlay {
|
|
|
1552
1589
|
pet.addEventListener("pointerenter", this.handlePointerEnter);
|
|
1553
1590
|
pet.addEventListener("pointerleave", this.handlePointerLeave);
|
|
1554
1591
|
pet.addEventListener("pointerdown", this.handlePointerDown);
|
|
1592
|
+
pet.addEventListener("lostpointercapture", this.handleLostPointerCapture);
|
|
1555
1593
|
pet.addEventListener("contextmenu", this.handleContextMenu);
|
|
1556
1594
|
pet.addEventListener("click", this.handleClick);
|
|
1557
1595
|
overlay.append(style, pet);
|
|
@@ -1561,6 +1599,7 @@ class PetOverlay {
|
|
|
1561
1599
|
}
|
|
1562
1600
|
removeOverlay() {
|
|
1563
1601
|
var _a2;
|
|
1602
|
+
this.cancelActiveDrag();
|
|
1564
1603
|
this.clearRestingDelayTimer();
|
|
1565
1604
|
this.clearTimers();
|
|
1566
1605
|
this.closeContextMenu();
|
|
@@ -1577,6 +1616,10 @@ class PetOverlay {
|
|
|
1577
1616
|
"pointerdown",
|
|
1578
1617
|
this.handlePointerDown
|
|
1579
1618
|
);
|
|
1619
|
+
this.petElement.removeEventListener(
|
|
1620
|
+
"lostpointercapture",
|
|
1621
|
+
this.handleLostPointerCapture
|
|
1622
|
+
);
|
|
1580
1623
|
this.petElement.removeEventListener(
|
|
1581
1624
|
"contextmenu",
|
|
1582
1625
|
this.handleContextMenu
|
|
@@ -2294,6 +2337,34 @@ class PetOverlay {
|
|
|
2294
2337
|
this.render();
|
|
2295
2338
|
}
|
|
2296
2339
|
}
|
|
2340
|
+
captureActivePointer() {
|
|
2341
|
+
const pointerId = this.activePointerId;
|
|
2342
|
+
const pet = this.petElement;
|
|
2343
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.setPointerCapture) !== "function") {
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
try {
|
|
2347
|
+
pet.setPointerCapture(pointerId);
|
|
2348
|
+
} catch {
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
releaseActivePointer() {
|
|
2352
|
+
const pointerId = this.activePointerId;
|
|
2353
|
+
const pet = this.petElement;
|
|
2354
|
+
this.activePointerId = null;
|
|
2355
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.hasPointerCapture) !== "function" || typeof pet.releasePointerCapture !== "function") {
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
try {
|
|
2359
|
+
if (pet.hasPointerCapture(pointerId)) {
|
|
2360
|
+
pet.releasePointerCapture(pointerId);
|
|
2361
|
+
}
|
|
2362
|
+
} catch {
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
isActiveDragPointer(event) {
|
|
2366
|
+
return this.isDragging && event.pointerId === this.activePointerId;
|
|
2367
|
+
}
|
|
2297
2368
|
getNextDragPosition(event) {
|
|
2298
2369
|
if (!this.options) {
|
|
2299
2370
|
return { x: 0, y: 0 };
|
|
@@ -2308,12 +2379,35 @@ class PetOverlay {
|
|
|
2308
2379
|
chatkitTypes.normalizeBoundsPadding(this.options.position.boundsPadding)
|
|
2309
2380
|
);
|
|
2310
2381
|
}
|
|
2382
|
+
finishDrag(finalPosition, event) {
|
|
2383
|
+
this.isDragging = false;
|
|
2384
|
+
this.dragPosition = null;
|
|
2385
|
+
this.dragAnimation = null;
|
|
2386
|
+
this.lastDragClientX = null;
|
|
2387
|
+
this.removeDragListeners();
|
|
2388
|
+
this.releaseActivePointer();
|
|
2389
|
+
this.persistPosition(finalPosition);
|
|
2390
|
+
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
2391
|
+
this.isHovering = true;
|
|
2392
|
+
this.rescheduleAnimation();
|
|
2393
|
+
} else {
|
|
2394
|
+
this.enterRestingAfterDelay();
|
|
2395
|
+
this.rescheduleAnimation();
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
cancelActiveDrag() {
|
|
2399
|
+
this.isDragging = false;
|
|
2400
|
+
this.dragPosition = null;
|
|
2401
|
+
this.dragAnimation = null;
|
|
2402
|
+
this.lastDragPosition = null;
|
|
2403
|
+
this.lastDragClientX = null;
|
|
2404
|
+
this.removeDragListeners();
|
|
2405
|
+
this.releaseActivePointer();
|
|
2406
|
+
}
|
|
2311
2407
|
installDragListeners() {
|
|
2312
2408
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
2313
|
-
window.addEventListener("pointerup", this.handlePointerUp
|
|
2314
|
-
window.addEventListener("pointercancel", this.handlePointerUp
|
|
2315
|
-
once: true
|
|
2316
|
-
});
|
|
2409
|
+
window.addEventListener("pointerup", this.handlePointerUp);
|
|
2410
|
+
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
2317
2411
|
}
|
|
2318
2412
|
removeDragListeners() {
|
|
2319
2413
|
window.removeEventListener("pointermove", this.handlePointerMove);
|
|
@@ -2360,7 +2454,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
|
|
|
2360
2454
|
__privateAdd(this, _loaded, new Promise((resolve) => {
|
|
2361
2455
|
__privateSet(this, _resolveLoaded, resolve);
|
|
2362
2456
|
}));
|
|
2457
|
+
__privateAdd(this, _channelId, createSecureChannelId());
|
|
2363
2458
|
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
2459
|
+
channelId: __privateGet(this, _channelId) ?? void 0,
|
|
2364
2460
|
fetch: (...args) => {
|
|
2365
2461
|
var _a2;
|
|
2366
2462
|
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
@@ -2859,6 +2955,7 @@ _shadow = new WeakMap();
|
|
|
2859
2955
|
_petOverlay = new WeakMap();
|
|
2860
2956
|
_resolveLoaded = new WeakMap();
|
|
2861
2957
|
_loaded = new WeakMap();
|
|
2958
|
+
_channelId = new WeakMap();
|
|
2862
2959
|
_messenger = new WeakMap();
|
|
2863
2960
|
_ChatKitElementBase_instances = new WeakSet();
|
|
2864
2961
|
emitAndThrow_fn = function(error) {
|
|
@@ -3069,7 +3166,8 @@ maybeInit_fn = function() {
|
|
|
3069
3166
|
frameURL.hash = encodeBase64({
|
|
3070
3167
|
options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
|
|
3071
3168
|
referrer: window.location.origin,
|
|
3072
|
-
profile: this.profile
|
|
3169
|
+
profile: this.profile,
|
|
3170
|
+
...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}
|
|
3073
3171
|
});
|
|
3074
3172
|
__privateGet(this, _messenger).connect();
|
|
3075
3173
|
__privateGet(this, _frame).src = frameURL.toString();
|
|
@@ -3113,6 +3211,8 @@ const EVENT_HANDLER_MAP = {
|
|
|
3113
3211
|
"chatkit.response.start": "onResponseStart",
|
|
3114
3212
|
"chatkit.log": "onLog",
|
|
3115
3213
|
"chatkit.thread.change": "onThreadChange",
|
|
3214
|
+
"chatkit.project.change": "onProjectChange",
|
|
3215
|
+
"chatkit.connectors.change": "onConnectorsChange",
|
|
3116
3216
|
"chatkit.thread.load.start": "onThreadLoadStart",
|
|
3117
3217
|
"chatkit.thread.load.end": "onThreadLoadEnd",
|
|
3118
3218
|
"chatkit.ready": "onReady",
|
|
@@ -3124,6 +3224,8 @@ const UI5_EVENT_NAME_MAP = {
|
|
|
3124
3224
|
"chatkit.response.start": "responseStart",
|
|
3125
3225
|
"chatkit.log": "log",
|
|
3126
3226
|
"chatkit.thread.change": "threadChange",
|
|
3227
|
+
"chatkit.project.change": "projectChange",
|
|
3228
|
+
"chatkit.connectors.change": "connectorsChange",
|
|
3127
3229
|
"chatkit.thread.load.start": "threadLoadStart",
|
|
3128
3230
|
"chatkit.thread.load.end": "threadLoadEnd",
|
|
3129
3231
|
"chatkit.ready": "ready",
|