@xpert-ai/chatkit-ui5 0.17.1 → 0.18.1
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 +55 -12
- package/dist/chatkit.cjs.map +1 -1
- package/dist/chatkit.ui5.js +55 -12
- package/dist/chatkit.ui5.js.map +1 -1
- package/dist/index.js +56 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -47,8 +47,8 @@ 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, _focusMessage_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
|
-
import { normalizePetOptions, DEFAULT_PET_STORAGE_KEY, resolvePetCharacter, normalizeBoundsPadding, getPinnedPetPosition, clampPetPosition } from "@xpert-ai/chatkit-types";
|
|
50
|
+
var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _focusMessage_dec, _prepareLeave_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
|
+
import { normalizePetOptions, DEFAULT_PET_STORAGE_KEY, resolvePetCharacter, normalizeBoundsPadding, getPinnedPetPosition, clampPetPosition, getPetAssetsBaseUrl } from "@xpert-ai/chatkit-types";
|
|
52
52
|
class EventEmitter {
|
|
53
53
|
constructor() {
|
|
54
54
|
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
@@ -270,10 +270,12 @@ class HttpError extends Error {
|
|
|
270
270
|
super(message);
|
|
271
271
|
__publicField(this, "status");
|
|
272
272
|
__publicField(this, "statusText");
|
|
273
|
+
__publicField(this, "retryAfterMs");
|
|
273
274
|
__publicField(this, "metadata");
|
|
274
275
|
this.name = "HttpError";
|
|
275
276
|
this.statusText = res.statusText;
|
|
276
277
|
this.status = res.status;
|
|
278
|
+
this.retryAfterMs = res.retryAfterMs;
|
|
277
279
|
this.metadata = metadata;
|
|
278
280
|
}
|
|
279
281
|
static fromPossibleFrameSafeError(error) {
|
|
@@ -286,7 +288,8 @@ class HttpError extends Error {
|
|
|
286
288
|
safeError.message,
|
|
287
289
|
{
|
|
288
290
|
status: safeError.status,
|
|
289
|
-
statusText: safeError.statusText
|
|
291
|
+
statusText: safeError.statusText,
|
|
292
|
+
retryAfterMs: safeError.retryAfterMs
|
|
290
293
|
},
|
|
291
294
|
safeError.metadata
|
|
292
295
|
);
|
|
@@ -304,11 +307,13 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
|
304
307
|
__publicField(this, "stack");
|
|
305
308
|
__publicField(this, "status");
|
|
306
309
|
__publicField(this, "statusText");
|
|
310
|
+
__publicField(this, "retryAfterMs");
|
|
307
311
|
__publicField(this, "metadata");
|
|
308
312
|
this.message = message;
|
|
309
313
|
this.stack = new Error(message).stack;
|
|
310
314
|
this.status = res.status;
|
|
311
315
|
this.statusText = res.statusText;
|
|
316
|
+
this.retryAfterMs = res.retryAfterMs;
|
|
312
317
|
this.metadata = metadata;
|
|
313
318
|
}
|
|
314
319
|
static fromHttpError(error) {
|
|
@@ -316,7 +321,8 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
|
316
321
|
error.message,
|
|
317
322
|
{
|
|
318
323
|
status: error.status,
|
|
319
|
-
statusText: error.statusText
|
|
324
|
+
statusText: error.statusText,
|
|
325
|
+
retryAfterMs: error.retryAfterMs
|
|
320
326
|
},
|
|
321
327
|
error.metadata
|
|
322
328
|
);
|
|
@@ -438,19 +444,42 @@ class FrameSafeIntegrationError {
|
|
|
438
444
|
}
|
|
439
445
|
}
|
|
440
446
|
function serializeFrameError(error) {
|
|
447
|
+
if (error instanceof HttpError || error instanceof FrameSafeHttpError) {
|
|
448
|
+
try {
|
|
449
|
+
return structuredClone(
|
|
450
|
+
error instanceof HttpError ? FrameSafeHttpError.fromHttpError(error) : error
|
|
451
|
+
);
|
|
452
|
+
} catch {
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
|
|
456
|
+
const message = "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
|
|
457
|
+
return new FrameSafeHttpError(message, {
|
|
458
|
+
status: error.status,
|
|
459
|
+
statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0,
|
|
460
|
+
retryAfterMs: readRetryAfterMs(error)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
441
463
|
try {
|
|
442
464
|
return structuredClone(error);
|
|
443
465
|
} catch {
|
|
444
466
|
const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
|
|
445
|
-
if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
|
|
446
|
-
return new FrameSafeHttpError(message, {
|
|
447
|
-
status: error.status,
|
|
448
|
-
statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
467
|
return new Error(message);
|
|
452
468
|
}
|
|
453
469
|
}
|
|
470
|
+
function readRetryAfterMs(error) {
|
|
471
|
+
if ("retryAfterMs" in error && typeof error.retryAfterMs === "number" && Number.isFinite(error.retryAfterMs)) {
|
|
472
|
+
return Math.max(0, error.retryAfterMs);
|
|
473
|
+
}
|
|
474
|
+
if (!("headers" in error) || !error.headers || typeof error.headers !== "object")
|
|
475
|
+
return;
|
|
476
|
+
const headers = error.headers;
|
|
477
|
+
if (!("get" in headers) || typeof headers.get !== "function") return;
|
|
478
|
+
const value = headers.get("Retry-After");
|
|
479
|
+
if (typeof value !== "string" || !value.trim()) return;
|
|
480
|
+
const duration = /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) * 1e3 : Date.parse(value) - Date.now();
|
|
481
|
+
return Number.isFinite(duration) ? Math.max(0, duration) : void 0;
|
|
482
|
+
}
|
|
454
483
|
class BaseMessenger {
|
|
455
484
|
constructor({
|
|
456
485
|
handlers,
|
|
@@ -753,6 +782,7 @@ const BASE_CAPABILITY_ALLOWLIST = [
|
|
|
753
782
|
"command.setThreadId",
|
|
754
783
|
"command.focusComposer",
|
|
755
784
|
"command.focusMessage",
|
|
785
|
+
"command.prepareLeave",
|
|
756
786
|
"command.fetchUpdates",
|
|
757
787
|
"command.sendCustomAction",
|
|
758
788
|
"command.showHistory",
|
|
@@ -2502,7 +2532,7 @@ function requireCommandCapability(value, context) {
|
|
|
2502
2532
|
return value.apply(this, args);
|
|
2503
2533
|
};
|
|
2504
2534
|
}
|
|
2505
|
-
class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requireCommandCapability], _fetchUpdates_dec = [requireCommandCapability], _sendUserMessage_dec = [requireCommandCapability], _setComposerValue_dec = [requireCommandCapability], _setRuntimeCapabilities_dec = [requireCommandCapability], _setThreadId_dec = [requireCommandCapability], _focusMessage_dec = [requireCommandCapability], _shareThread_dec = [requireCommandCapability], _sendCustomAction_dec = [requireCommandCapability], _showHistory_dec = [requireCommandCapability], _hideHistory_dec = [requireCommandCapability], _setTrainingOptOut_dec = [requireCommandCapability], _c) {
|
|
2535
|
+
class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requireCommandCapability], _fetchUpdates_dec = [requireCommandCapability], _sendUserMessage_dec = [requireCommandCapability], _setComposerValue_dec = [requireCommandCapability], _setRuntimeCapabilities_dec = [requireCommandCapability], _setThreadId_dec = [requireCommandCapability], _prepareLeave_dec = [requireCommandCapability], _focusMessage_dec = [requireCommandCapability], _shareThread_dec = [requireCommandCapability], _sendCustomAction_dec = [requireCommandCapability], _showHistory_dec = [requireCommandCapability], _hideHistory_dec = [requireCommandCapability], _setTrainingOptOut_dec = [requireCommandCapability], _c) {
|
|
2506
2536
|
constructor({ profile }) {
|
|
2507
2537
|
super();
|
|
2508
2538
|
__runInitializers(_init, 5, this);
|
|
@@ -3048,6 +3078,11 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
|
|
|
3048
3078
|
await __privateGet(this, _loaded);
|
|
3049
3079
|
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setThreadId({ threadId }));
|
|
3050
3080
|
}
|
|
3081
|
+
async prepareLeave() {
|
|
3082
|
+
await __privateGet(this, _loaded);
|
|
3083
|
+
if (!__privateGet(this, _messenger)) return false;
|
|
3084
|
+
return __privateGet(this, _messenger).commands.prepareLeave();
|
|
3085
|
+
}
|
|
3051
3086
|
async focusMessage(request) {
|
|
3052
3087
|
await __privateGet(this, _loaded);
|
|
3053
3088
|
if (!__privateGet(this, _messenger)) return { success: false, code: "not_ready" };
|
|
@@ -3117,7 +3152,7 @@ getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
|
|
|
3117
3152
|
return null;
|
|
3118
3153
|
}
|
|
3119
3154
|
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) === "pet" && !normalizePetOptions(options.pet ?? null)) {
|
|
3120
|
-
return true;
|
|
3155
|
+
return typeof options.pet === "object" ? { ...options.pet, enabled: true } : true;
|
|
3121
3156
|
}
|
|
3122
3157
|
return options.pet ?? null;
|
|
3123
3158
|
};
|
|
@@ -3175,7 +3210,11 @@ resolvePetAssetUrl_fn = function(src) {
|
|
|
3175
3210
|
}
|
|
3176
3211
|
};
|
|
3177
3212
|
resolveOverlayPetOptions_fn = function(pet) {
|
|
3178
|
-
|
|
3213
|
+
var _a2;
|
|
3214
|
+
const assetsBaseUrl = getPetAssetsBaseUrl(pet ?? void 0) ?? getPetAssetsBaseUrl((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet);
|
|
3215
|
+
const normalized = normalizePetOptions(
|
|
3216
|
+
pet ? { ...pet === true ? {} : pet, assetsBaseUrl } : null
|
|
3217
|
+
);
|
|
3179
3218
|
if (!normalized) {
|
|
3180
3219
|
return null;
|
|
3181
3220
|
}
|
|
@@ -3321,6 +3360,7 @@ __decorateElement(_init, 1, "sendUserMessage", _sendUserMessage_dec, ChatKitElem
|
|
|
3321
3360
|
__decorateElement(_init, 1, "setComposerValue", _setComposerValue_dec, ChatKitElementBase);
|
|
3322
3361
|
__decorateElement(_init, 1, "setRuntimeCapabilities", _setRuntimeCapabilities_dec, ChatKitElementBase);
|
|
3323
3362
|
__decorateElement(_init, 1, "setThreadId", _setThreadId_dec, ChatKitElementBase);
|
|
3363
|
+
__decorateElement(_init, 1, "prepareLeave", _prepareLeave_dec, ChatKitElementBase);
|
|
3324
3364
|
__decorateElement(_init, 1, "focusMessage", _focusMessage_dec, ChatKitElementBase);
|
|
3325
3365
|
__decorateElement(_init, 1, "shareThread", _shareThread_dec, ChatKitElementBase);
|
|
3326
3366
|
__decorateElement(_init, 1, "sendCustomAction", _sendCustomAction_dec, ChatKitElementBase);
|
|
@@ -3537,6 +3577,9 @@ const ChatKit = ControlBase.extend("xpertai.chatkit.ui5.ChatKit", {
|
|
|
3537
3577
|
}
|
|
3538
3578
|
return methodRef.apply(el, args);
|
|
3539
3579
|
},
|
|
3580
|
+
async prepareLeave() {
|
|
3581
|
+
return await this._callMethod("prepareLeave") === true;
|
|
3582
|
+
},
|
|
3540
3583
|
focusComposer(...args) {
|
|
3541
3584
|
return this._callMethod("focusComposer", ...args);
|
|
3542
3585
|
},
|