@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/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, _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, _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() {
|
|
@@ -367,7 +367,7 @@ const fetchEventSourceWithRetry = async (url, params) => {
|
|
|
367
367
|
}
|
|
368
368
|
});
|
|
369
369
|
};
|
|
370
|
-
function
|
|
370
|
+
function createSecureChannelId() {
|
|
371
371
|
const cryptoRef = globalThis.crypto;
|
|
372
372
|
if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
|
|
373
373
|
return cryptoRef.randomUUID();
|
|
@@ -379,7 +379,30 @@ function safeRandomUUID() {
|
|
|
379
379
|
bytes[8] = bytes[8] & 63 | 128;
|
|
380
380
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
381
381
|
}
|
|
382
|
-
return
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
function safeRandomUUID() {
|
|
385
|
+
return createSecureChannelId() ?? `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
386
|
+
}
|
|
387
|
+
function isTrustedChatKitMessageEvent(event, { channelId, expectedOrigin, expectedSource }) {
|
|
388
|
+
const payload = event.data;
|
|
389
|
+
if (!payload || typeof payload !== "object" || !("__xpaiChatKit" in payload)) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (payload.__xpaiChatKit !== true) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
if (expectedOrigin !== "*" && event.origin !== expectedOrigin) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
if (event.source === expectedSource) {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
const normalizedChannelId = channelId == null ? void 0 : channelId.trim();
|
|
402
|
+
if (normalizedChannelId) {
|
|
403
|
+
return "channelId" in payload && payload.channelId === normalizedChannelId;
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
383
406
|
}
|
|
384
407
|
let IntegrationError$1 = class IntegrationError extends Error {
|
|
385
408
|
constructor(message) {
|
|
@@ -413,10 +436,12 @@ class BaseMessenger {
|
|
|
413
436
|
handlers,
|
|
414
437
|
target,
|
|
415
438
|
targetOrigin,
|
|
439
|
+
channelId,
|
|
416
440
|
fetch: fetch2 = window.fetch
|
|
417
441
|
}) {
|
|
418
442
|
__publicField(this, "targetOrigin");
|
|
419
443
|
__publicField(this, "target");
|
|
444
|
+
__publicField(this, "channelId");
|
|
420
445
|
__publicField(this, "commandHandlers");
|
|
421
446
|
__publicField(this, "_fetch");
|
|
422
447
|
__publicField(this, "emitter", new EventEmitter());
|
|
@@ -447,7 +472,11 @@ class BaseMessenger {
|
|
|
447
472
|
));
|
|
448
473
|
__publicField(this, "handleMessage", async (event) => {
|
|
449
474
|
var _a2, _b2, _c2, _d;
|
|
450
|
-
if (!event
|
|
475
|
+
if (!isTrustedChatKitMessageEvent(event, {
|
|
476
|
+
channelId: this.channelId,
|
|
477
|
+
expectedOrigin: this.targetOrigin,
|
|
478
|
+
expectedSource: this.target()
|
|
479
|
+
})) {
|
|
451
480
|
return;
|
|
452
481
|
}
|
|
453
482
|
const data = event.data;
|
|
@@ -588,6 +617,7 @@ class BaseMessenger {
|
|
|
588
617
|
this.commandHandlers = handlers;
|
|
589
618
|
this.target = target;
|
|
590
619
|
this.targetOrigin = targetOrigin;
|
|
620
|
+
this.channelId = (channelId == null ? void 0 : channelId.trim()) || void 0;
|
|
591
621
|
this._fetch = (...args) => fetch2(...args);
|
|
592
622
|
}
|
|
593
623
|
setTargetOrigin(targetOrigin) {
|
|
@@ -597,6 +627,7 @@ class BaseMessenger {
|
|
|
597
627
|
var _a2;
|
|
598
628
|
const message = {
|
|
599
629
|
__xpaiChatKit: true,
|
|
630
|
+
...this.channelId ? { channelId: this.channelId } : {},
|
|
600
631
|
...data
|
|
601
632
|
};
|
|
602
633
|
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
@@ -712,6 +743,8 @@ const BASE_CAPABILITY_ALLOWLIST = [
|
|
|
712
743
|
"event.response.end",
|
|
713
744
|
"event.response.stop",
|
|
714
745
|
"event.thread.change",
|
|
746
|
+
"event.project.change",
|
|
747
|
+
"event.connectors.change",
|
|
715
748
|
"event.tool.change",
|
|
716
749
|
"event.thread.load.start",
|
|
717
750
|
"event.thread.load.end",
|
|
@@ -817,7 +850,7 @@ const BASE_CAPABILITY_DENYLIST = [
|
|
|
817
850
|
"widget.Map"
|
|
818
851
|
];
|
|
819
852
|
const PROFILE_TO_RULES = {
|
|
820
|
-
|
|
853
|
+
chatkit: {
|
|
821
854
|
allow: [...BASE_CAPABILITY_ALLOWLIST, "thread.item.image_generation"],
|
|
822
855
|
deny: BASE_CAPABILITY_DENYLIST
|
|
823
856
|
}
|
|
@@ -1151,6 +1184,7 @@ class PetOverlay {
|
|
|
1151
1184
|
this.lastDragPosition = null;
|
|
1152
1185
|
this.lastDragClientX = null;
|
|
1153
1186
|
this.dragAnimation = null;
|
|
1187
|
+
this.activePointerId = null;
|
|
1154
1188
|
this.isDragging = false;
|
|
1155
1189
|
this.isHovering = false;
|
|
1156
1190
|
this.movedDuringDrag = false;
|
|
@@ -1282,7 +1316,7 @@ class PetOverlay {
|
|
|
1282
1316
|
};
|
|
1283
1317
|
this.handlePointerDown = (event) => {
|
|
1284
1318
|
var _a2, _b2;
|
|
1285
|
-
if (event.button !== 0 || event.ctrlKey) {
|
|
1319
|
+
if (event.button !== 0 || event.ctrlKey || this.isDragging) {
|
|
1286
1320
|
return;
|
|
1287
1321
|
}
|
|
1288
1322
|
this.closeContextMenu();
|
|
@@ -1308,12 +1342,17 @@ class PetOverlay {
|
|
|
1308
1342
|
this.movedDuringDrag = false;
|
|
1309
1343
|
this.dragPosition = nextPosition;
|
|
1310
1344
|
this.isDragging = true;
|
|
1345
|
+
this.activePointerId = event.pointerId;
|
|
1311
1346
|
this.clearRestingDelayTimer();
|
|
1312
1347
|
this.isHovering = true;
|
|
1348
|
+
this.captureActivePointer();
|
|
1313
1349
|
this.installDragListeners();
|
|
1314
1350
|
this.rescheduleAnimation();
|
|
1315
1351
|
};
|
|
1316
1352
|
this.handlePointerMove = (event) => {
|
|
1353
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1317
1356
|
const nextPosition = this.getNextDragPosition(event);
|
|
1318
1357
|
const last = this.lastDragPosition;
|
|
1319
1358
|
if (last && (Math.abs(last.x - nextPosition.x) > DRAG_DIRECTION_THRESHOLD_PX || Math.abs(last.y - nextPosition.y) > DRAG_DIRECTION_THRESHOLD_PX)) {
|
|
@@ -1333,20 +1372,18 @@ class PetOverlay {
|
|
|
1333
1372
|
this.render();
|
|
1334
1373
|
};
|
|
1335
1374
|
this.handlePointerUp = (event) => {
|
|
1375
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1336
1378
|
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1337
|
-
this.
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
this.
|
|
1341
|
-
|
|
1342
|
-
this.persistPosition(finalPosition);
|
|
1343
|
-
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
1344
|
-
this.isHovering = true;
|
|
1345
|
-
this.rescheduleAnimation();
|
|
1346
|
-
} else {
|
|
1347
|
-
this.enterRestingAfterDelay();
|
|
1348
|
-
this.rescheduleAnimation();
|
|
1379
|
+
this.finishDrag(finalPosition, event);
|
|
1380
|
+
};
|
|
1381
|
+
this.handleLostPointerCapture = (event) => {
|
|
1382
|
+
if (!this.isActiveDragPointer(event)) {
|
|
1383
|
+
return;
|
|
1349
1384
|
}
|
|
1385
|
+
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1386
|
+
this.finishDrag(finalPosition, event);
|
|
1350
1387
|
};
|
|
1351
1388
|
this.handleClick = () => {
|
|
1352
1389
|
var _a2;
|
|
@@ -1550,6 +1587,7 @@ class PetOverlay {
|
|
|
1550
1587
|
pet.addEventListener("pointerenter", this.handlePointerEnter);
|
|
1551
1588
|
pet.addEventListener("pointerleave", this.handlePointerLeave);
|
|
1552
1589
|
pet.addEventListener("pointerdown", this.handlePointerDown);
|
|
1590
|
+
pet.addEventListener("lostpointercapture", this.handleLostPointerCapture);
|
|
1553
1591
|
pet.addEventListener("contextmenu", this.handleContextMenu);
|
|
1554
1592
|
pet.addEventListener("click", this.handleClick);
|
|
1555
1593
|
overlay.append(style, pet);
|
|
@@ -1559,6 +1597,7 @@ class PetOverlay {
|
|
|
1559
1597
|
}
|
|
1560
1598
|
removeOverlay() {
|
|
1561
1599
|
var _a2;
|
|
1600
|
+
this.cancelActiveDrag();
|
|
1562
1601
|
this.clearRestingDelayTimer();
|
|
1563
1602
|
this.clearTimers();
|
|
1564
1603
|
this.closeContextMenu();
|
|
@@ -1575,6 +1614,10 @@ class PetOverlay {
|
|
|
1575
1614
|
"pointerdown",
|
|
1576
1615
|
this.handlePointerDown
|
|
1577
1616
|
);
|
|
1617
|
+
this.petElement.removeEventListener(
|
|
1618
|
+
"lostpointercapture",
|
|
1619
|
+
this.handleLostPointerCapture
|
|
1620
|
+
);
|
|
1578
1621
|
this.petElement.removeEventListener(
|
|
1579
1622
|
"contextmenu",
|
|
1580
1623
|
this.handleContextMenu
|
|
@@ -2292,6 +2335,34 @@ class PetOverlay {
|
|
|
2292
2335
|
this.render();
|
|
2293
2336
|
}
|
|
2294
2337
|
}
|
|
2338
|
+
captureActivePointer() {
|
|
2339
|
+
const pointerId = this.activePointerId;
|
|
2340
|
+
const pet = this.petElement;
|
|
2341
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.setPointerCapture) !== "function") {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
try {
|
|
2345
|
+
pet.setPointerCapture(pointerId);
|
|
2346
|
+
} catch {
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
releaseActivePointer() {
|
|
2350
|
+
const pointerId = this.activePointerId;
|
|
2351
|
+
const pet = this.petElement;
|
|
2352
|
+
this.activePointerId = null;
|
|
2353
|
+
if (pointerId === null || typeof (pet == null ? void 0 : pet.hasPointerCapture) !== "function" || typeof pet.releasePointerCapture !== "function") {
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
try {
|
|
2357
|
+
if (pet.hasPointerCapture(pointerId)) {
|
|
2358
|
+
pet.releasePointerCapture(pointerId);
|
|
2359
|
+
}
|
|
2360
|
+
} catch {
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
isActiveDragPointer(event) {
|
|
2364
|
+
return this.isDragging && event.pointerId === this.activePointerId;
|
|
2365
|
+
}
|
|
2295
2366
|
getNextDragPosition(event) {
|
|
2296
2367
|
if (!this.options) {
|
|
2297
2368
|
return { x: 0, y: 0 };
|
|
@@ -2306,12 +2377,35 @@ class PetOverlay {
|
|
|
2306
2377
|
normalizeBoundsPadding(this.options.position.boundsPadding)
|
|
2307
2378
|
);
|
|
2308
2379
|
}
|
|
2380
|
+
finishDrag(finalPosition, event) {
|
|
2381
|
+
this.isDragging = false;
|
|
2382
|
+
this.dragPosition = null;
|
|
2383
|
+
this.dragAnimation = null;
|
|
2384
|
+
this.lastDragClientX = null;
|
|
2385
|
+
this.removeDragListeners();
|
|
2386
|
+
this.releaseActivePointer();
|
|
2387
|
+
this.persistPosition(finalPosition);
|
|
2388
|
+
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
2389
|
+
this.isHovering = true;
|
|
2390
|
+
this.rescheduleAnimation();
|
|
2391
|
+
} else {
|
|
2392
|
+
this.enterRestingAfterDelay();
|
|
2393
|
+
this.rescheduleAnimation();
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
cancelActiveDrag() {
|
|
2397
|
+
this.isDragging = false;
|
|
2398
|
+
this.dragPosition = null;
|
|
2399
|
+
this.dragAnimation = null;
|
|
2400
|
+
this.lastDragPosition = null;
|
|
2401
|
+
this.lastDragClientX = null;
|
|
2402
|
+
this.removeDragListeners();
|
|
2403
|
+
this.releaseActivePointer();
|
|
2404
|
+
}
|
|
2309
2405
|
installDragListeners() {
|
|
2310
2406
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
2311
|
-
window.addEventListener("pointerup", this.handlePointerUp
|
|
2312
|
-
window.addEventListener("pointercancel", this.handlePointerUp
|
|
2313
|
-
once: true
|
|
2314
|
-
});
|
|
2407
|
+
window.addEventListener("pointerup", this.handlePointerUp);
|
|
2408
|
+
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
2315
2409
|
}
|
|
2316
2410
|
removeDragListeners() {
|
|
2317
2411
|
window.removeEventListener("pointermove", this.handlePointerMove);
|
|
@@ -2358,7 +2452,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
|
|
|
2358
2452
|
__privateAdd(this, _loaded, new Promise((resolve) => {
|
|
2359
2453
|
__privateSet(this, _resolveLoaded, resolve);
|
|
2360
2454
|
}));
|
|
2455
|
+
__privateAdd(this, _channelId, createSecureChannelId());
|
|
2361
2456
|
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
2457
|
+
channelId: __privateGet(this, _channelId) ?? void 0,
|
|
2362
2458
|
fetch: (...args) => {
|
|
2363
2459
|
var _a2;
|
|
2364
2460
|
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
@@ -2857,6 +2953,7 @@ _shadow = new WeakMap();
|
|
|
2857
2953
|
_petOverlay = new WeakMap();
|
|
2858
2954
|
_resolveLoaded = new WeakMap();
|
|
2859
2955
|
_loaded = new WeakMap();
|
|
2956
|
+
_channelId = new WeakMap();
|
|
2860
2957
|
_messenger = new WeakMap();
|
|
2861
2958
|
_ChatKitElementBase_instances = new WeakSet();
|
|
2862
2959
|
emitAndThrow_fn = function(error) {
|
|
@@ -3067,7 +3164,8 @@ maybeInit_fn = function() {
|
|
|
3067
3164
|
frameURL.hash = encodeBase64({
|
|
3068
3165
|
options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
|
|
3069
3166
|
referrer: window.location.origin,
|
|
3070
|
-
profile: this.profile
|
|
3167
|
+
profile: this.profile,
|
|
3168
|
+
...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}
|
|
3071
3169
|
});
|
|
3072
3170
|
__privateGet(this, _messenger).connect();
|
|
3073
3171
|
__privateGet(this, _frame).src = frameURL.toString();
|
|
@@ -3111,6 +3209,8 @@ const EVENT_HANDLER_MAP = {
|
|
|
3111
3209
|
"chatkit.response.start": "onResponseStart",
|
|
3112
3210
|
"chatkit.log": "onLog",
|
|
3113
3211
|
"chatkit.thread.change": "onThreadChange",
|
|
3212
|
+
"chatkit.project.change": "onProjectChange",
|
|
3213
|
+
"chatkit.connectors.change": "onConnectorsChange",
|
|
3114
3214
|
"chatkit.thread.load.start": "onThreadLoadStart",
|
|
3115
3215
|
"chatkit.thread.load.end": "onThreadLoadEnd",
|
|
3116
3216
|
"chatkit.ready": "onReady",
|
|
@@ -3122,6 +3222,8 @@ const UI5_EVENT_NAME_MAP = {
|
|
|
3122
3222
|
"chatkit.response.start": "responseStart",
|
|
3123
3223
|
"chatkit.log": "log",
|
|
3124
3224
|
"chatkit.thread.change": "threadChange",
|
|
3225
|
+
"chatkit.project.change": "projectChange",
|
|
3226
|
+
"chatkit.connectors.change": "connectorsChange",
|
|
3125
3227
|
"chatkit.thread.load.start": "threadLoadStart",
|
|
3126
3228
|
"chatkit.thread.load.end": "threadLoadEnd",
|
|
3127
3229
|
"chatkit.ready": "ready",
|