@xpert-ai/chatkit-web-component 0.19.1 → 0.19.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.
@@ -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, _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;
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, _hostLauncherEnabled, _launcherVisible, _shadow, _petOverlay, _resolveLoaded, _loaded, _channelId, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, effectivePet_fn, innerOptions_fn, updateFrameOptions_fn, isLauncherHidden_fn, requestLauncherVisibility_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_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());
@@ -1296,6 +1296,7 @@ const PET_SUMMARY_FONT_FAMILY = 'system-ui, -apple-system, BlinkMacSystemFont, "
1296
1296
  const PET_OVERLAY_COPY = {
1297
1297
  "en-US": {
1298
1298
  closePetMenuItem: "Close pet",
1299
+ reopenPet: "Show pet",
1299
1300
  hideMessage: "Hide message",
1300
1301
  expandMessage: "Expand message",
1301
1302
  collapseMessage: "Collapse message",
@@ -1308,6 +1309,7 @@ const PET_OVERLAY_COPY = {
1308
1309
  },
1309
1310
  "zh-CN": {
1310
1311
  closePetMenuItem: "关闭宠物",
1312
+ reopenPet: "显示宠物",
1311
1313
  hideMessage: "隐藏消息",
1312
1314
  expandMessage: "展开消息",
1313
1315
  collapseMessage: "收起消息",
@@ -1518,6 +1520,7 @@ function parseThreadSummaryLogPayload(value) {
1518
1520
  }
1519
1521
  class PetOverlay {
1520
1522
  constructor(root, options) {
1523
+ this.reopenButton = null;
1521
1524
  this.overlayElement = null;
1522
1525
  this.petElement = null;
1523
1526
  this.contextMenuElement = null;
@@ -1765,6 +1768,7 @@ class PetOverlay {
1765
1768
  this.root = root;
1766
1769
  this.onActivate = options == null ? void 0 : options.onActivate;
1767
1770
  this.onClose = options == null ? void 0 : options.onClose;
1771
+ this.onReopen = options == null ? void 0 : options.onReopen;
1768
1772
  this.onReply = options == null ? void 0 : options.onReply;
1769
1773
  this.onThreadSummaryActivate = options == null ? void 0 : options.onThreadSummaryActivate;
1770
1774
  this.connect();
@@ -1808,6 +1812,44 @@ class PetOverlay {
1808
1812
  this.resolveCharacter();
1809
1813
  this.render();
1810
1814
  }
1815
+ setReopenVisible(visible, zIndex) {
1816
+ var _a2, _b2, _c2, _d, _e, _f;
1817
+ if (!visible) {
1818
+ (_a2 = this.reopenButton) == null ? void 0 : _a2.remove();
1819
+ this.reopenButton = null;
1820
+ return;
1821
+ }
1822
+ if (!this.reopenButton) {
1823
+ const button2 = document.createElement("button");
1824
+ button2.type = "button";
1825
+ button2.addEventListener("click", () => {
1826
+ var _a3;
1827
+ return (_a3 = this.onReopen) == null ? void 0 : _a3.call(this);
1828
+ });
1829
+ this.root.append(button2);
1830
+ this.reopenButton = button2;
1831
+ }
1832
+ const button = this.reopenButton;
1833
+ const theme = typeof this.theme === "object" ? this.theme : null;
1834
+ const metrics = getSummaryThemeMetrics(this.theme);
1835
+ button.textContent = this.copy.reopenPet;
1836
+ Object.assign(button.style, {
1837
+ position: "fixed",
1838
+ insetInlineEnd: `${PET_SUMMARY_MARGIN}px`,
1839
+ bottom: `${PET_SUMMARY_MARGIN}px`,
1840
+ zIndex: String(zIndex ?? ((_b2 = normalizePetOptions(true)) == null ? void 0 : _b2.position.zIndex)),
1841
+ pointerEvents: "auto",
1842
+ cursor: "pointer",
1843
+ colorScheme: typeof this.theme === "string" ? this.theme : (theme == null ? void 0 : theme.colorScheme) ?? "light",
1844
+ color: ((_d = (_c2 = theme == null ? void 0 : theme.color) == null ? void 0 : _c2.surface) == null ? void 0 : _d.foreground) ?? "ButtonText",
1845
+ background: ((_f = (_e = theme == null ? void 0 : theme.color) == null ? void 0 : _e.surface) == null ? void 0 : _f.background) ?? "ButtonFace",
1846
+ border: "1px solid ButtonBorder",
1847
+ borderRadius: `${metrics.radius}px`,
1848
+ padding: metrics.padding,
1849
+ fontFamily: metrics.fontFamily,
1850
+ fontSize: `${metrics.bodySize}px`
1851
+ });
1852
+ }
1811
1853
  setState(state) {
1812
1854
  var _a2;
1813
1855
  const previous = this.lastAutoState;
@@ -1871,6 +1913,7 @@ class PetOverlay {
1871
1913
  return;
1872
1914
  }
1873
1915
  this.connected = false;
1916
+ this.setReopenVisible(false);
1874
1917
  this.clearRestingDelayTimer();
1875
1918
  this.clearTimers();
1876
1919
  this.removeDragListeners();
@@ -2778,9 +2821,6 @@ class PetOverlay {
2778
2821
  window.removeEventListener("pointercancel", this.handlePointerUp);
2779
2822
  }
2780
2823
  }
2781
- function getInnerOptions(options) {
2782
- return removeMethods(options);
2783
- }
2784
2824
  function requireCommandCapability(value, context) {
2785
2825
  const command = String(context.name);
2786
2826
  return function(...args) {
@@ -2807,10 +2847,13 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2807
2847
  __privateAdd(this, _chatMinimizedToPet, false);
2808
2848
  __privateAdd(this, _framePetOptionsOverride);
2809
2849
  __privateAdd(this, _petClosedByContextMenu, false);
2850
+ __privateAdd(this, _hostLauncherEnabled, true);
2851
+ __privateAdd(this, _launcherVisible, true);
2810
2852
  __privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
2811
2853
  __privateAdd(this, _petOverlay, new PetOverlay(__privateGet(this, _shadow), {
2812
2854
  onActivate: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetActivate_fn).call(this),
2813
2855
  onClose: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetClose_fn).call(this),
2856
+ onReopen: () => __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, true),
2814
2857
  onReply: (text) => __privateMethod(this, _ChatKitElementBase_instances, handlePetReply_fn).call(this, text),
2815
2858
  onThreadSummaryActivate: (threadId) => void __privateMethod(this, _ChatKitElementBase_instances, handlePetThreadSummaryActivate_fn).call(this, threadId)
2816
2859
  }));
@@ -3003,6 +3046,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3003
3046
  }
3004
3047
  connectedCallback() {
3005
3048
  __privateGet(this, _petOverlay).connect();
3049
+ if (__privateGet(this, _opts)) __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3006
3050
  const style = document.createElement("style");
3007
3051
  style.textContent = `
3008
3052
  :host {
@@ -3281,19 +3325,26 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3281
3325
  __privateGet(this, _petOverlay).destroy();
3282
3326
  }
3283
3327
  applySanitizedOptions(newOptions) {
3284
- var _a2, _b2;
3328
+ var _a2, _b2, _c2, _d;
3329
+ const sessionChanged = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.sessionKey) !== newOptions.sessionKey || ((_b2 = __privateGet(this, _opts)) == null ? void 0 : _b2.api.xpertId) !== newOptions.api.xpertId || __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, newOptions);
3330
+ const pet = newOptions.pet;
3331
+ const enabled = typeof pet === "boolean" ? pet : (pet == null ? void 0 : pet.enabled) ?? true;
3332
+ if (sessionChanged || enabled !== __privateGet(this, _hostLauncherEnabled)) {
3333
+ __privateSet(this, _launcherVisible, enabled);
3334
+ }
3335
+ __privateSet(this, _hostLauncherEnabled, enabled);
3336
+ if (sessionChanged) {
3337
+ __privateSet(this, _framePetOptionsOverride, void 0);
3338
+ __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3339
+ }
3285
3340
  __privateSet(this, _opts, newOptions);
3286
- if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
3341
+ if (!((_c2 = newOptions.header) == null ? void 0 : _c2.windowDrag)) (_d = __privateGet(this, _windowDrag)) == null ? void 0 : _d.clear();
3287
3342
  __privateSet(this, _petClosedByContextMenu, false);
3288
3343
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
3289
3344
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3290
3345
  if (__privateGet(this, _initialized)) {
3291
3346
  __privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
3292
- __privateGet(this, _loaded).then(() => {
3293
- __privateGet(this, _messenger).commands.setOptions(
3294
- getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, newOptions))
3295
- );
3296
- });
3347
+ __privateMethod(this, _ChatKitElementBase_instances, updateFrameOptions_fn).call(this);
3297
3348
  } else {
3298
3349
  __privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
3299
3350
  }
@@ -3385,6 +3436,8 @@ _launcherOpen = new WeakMap();
3385
3436
  _chatMinimizedToPet = new WeakMap();
3386
3437
  _framePetOptionsOverride = new WeakMap();
3387
3438
  _petClosedByContextMenu = new WeakMap();
3439
+ _hostLauncherEnabled = new WeakMap();
3440
+ _launcherVisible = new WeakMap();
3388
3441
  _shadow = new WeakMap();
3389
3442
  _petOverlay = new WeakMap();
3390
3443
  _resolveLoaded = new WeakMap();
@@ -3407,14 +3460,9 @@ setOptionsDataAttributes_fn = function(options) {
3407
3460
  getDisplayMode_fn = function(options = __privateGet(this, _opts)) {
3408
3461
  return (options == null ? void 0 : options.displayMode) === "pet" ? "pet" : "chat";
3409
3462
  };
3410
- getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
3411
- if (!options) {
3412
- return null;
3413
- }
3414
- if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) === "pet" && !normalizePetOptions(options.pet ?? null)) {
3415
- return typeof options.pet === "object" ? { ...options.pet, enabled: true } : true;
3416
- }
3417
- return options.pet ?? null;
3463
+ getConfiguredPetOptions_fn = function() {
3464
+ if (!__privateGet(this, _opts)) return null;
3465
+ return __privateMethod(this, _ChatKitElementBase_instances, effectivePet_fn).call(this, __privateGet(this, _opts)) ?? (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" ? true : null);
3418
3466
  };
3419
3467
  mergeConfiguredPetPositionDefaults_fn = function(pet) {
3420
3468
  if (!pet) {
@@ -3442,9 +3490,41 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3442
3490
  }
3443
3491
  };
3444
3492
  };
3493
+ effectivePet_fn = function(options) {
3494
+ const pet = options.pet;
3495
+ if (options.displayMode !== "pet" || __privateGet(this, _launcherVisible) === __privateGet(this, _hostLauncherEnabled)) {
3496
+ return pet;
3497
+ }
3498
+ return typeof pet === "object" ? { ...pet, enabled: __privateGet(this, _launcherVisible) } : __privateGet(this, _launcherVisible);
3499
+ };
3500
+ innerOptions_fn = function(options) {
3501
+ return removeMethods({
3502
+ ...options,
3503
+ pet: __privateMethod(this, _ChatKitElementBase_instances, effectivePet_fn).call(this, options)
3504
+ });
3505
+ };
3506
+ updateFrameOptions_fn = function() {
3507
+ __privateGet(this, _loaded).then(() => {
3508
+ if (__privateGet(this, _opts))
3509
+ __privateGet(this, _messenger).commands.setOptions(__privateMethod(this, _ChatKitElementBase_instances, innerOptions_fn).call(this, __privateGet(this, _opts)));
3510
+ });
3511
+ };
3512
+ isLauncherHidden_fn = function() {
3513
+ return __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !__privateGet(this, _launcherVisible);
3514
+ };
3515
+ requestLauncherVisibility_fn = function(visible) {
3516
+ __privateSet(this, _launcherVisible, visible);
3517
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3518
+ __privateMethod(this, _ChatKitElementBase_instances, updateFrameOptions_fn).call(this);
3519
+ this.dispatchEvent(
3520
+ new CustomEvent("chatkit.pet.launcher.visibility.change", {
3521
+ detail: { visible }
3522
+ })
3523
+ );
3524
+ };
3445
3525
  getOverlayPetOptions_fn = function() {
3446
3526
  var _a2;
3447
- if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3527
+ if (__privateMethod(this, _ChatKitElementBase_instances, isLauncherHidden_fn).call(this) || __privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3448
3528
  return null;
3449
3529
  }
3450
3530
  let pet;
@@ -3454,7 +3534,7 @@ getOverlayPetOptions_fn = function() {
3454
3534
  pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3455
3535
  }
3456
3536
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !normalizePetOptions(pet ?? null)) {
3457
- pet = true;
3537
+ pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3458
3538
  }
3459
3539
  return __privateMethod(this, _ChatKitElementBase_instances, resolveOverlayPetOptions_fn).call(this, pet);
3460
3540
  };
@@ -3489,19 +3569,6 @@ resolveOverlayPetOptions_fn = function(pet) {
3489
3569
  imageRendering: normalized.imageRendering
3490
3570
  };
3491
3571
  };
3492
- getFrameOptions_fn = function(options) {
3493
- const pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this, options);
3494
- if (pet === (options.pet ?? null)) {
3495
- return options;
3496
- }
3497
- const nextOptions = { ...options };
3498
- if (pet === null) {
3499
- delete nextOptions.pet;
3500
- } else {
3501
- nextOptions.pet = pet;
3502
- }
3503
- return nextOptions;
3504
- };
3505
3572
  setLauncherOpen_fn = function(open) {
3506
3573
  __privateSet(this, _launcherOpen, open);
3507
3574
  if (open) {
@@ -3520,9 +3587,14 @@ setChatMinimizedToPet_fn = function(minimized) {
3520
3587
  }
3521
3588
  };
3522
3589
  syncPetOverlayOptions_fn = function() {
3523
- var _a2;
3590
+ var _a2, _b2, _c2;
3591
+ if (__privateMethod(this, _ChatKitElementBase_instances, isLauncherHidden_fn).call(this)) __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3524
3592
  const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
3525
3593
  __privateGet(this, _petOverlay).setOptions(overlayPetOptions, (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.theme);
3594
+ __privateGet(this, _petOverlay).setReopenVisible(
3595
+ __privateMethod(this, _ChatKitElementBase_instances, isLauncherHidden_fn).call(this),
3596
+ typeof ((_b2 = __privateGet(this, _opts)) == null ? void 0 : _b2.pet) === "object" ? (_c2 = __privateGet(this, _opts).pet.position) == null ? void 0 : _c2.zIndex : void 0
3597
+ );
3526
3598
  if (!overlayPetOptions) {
3527
3599
  __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3528
3600
  }
@@ -3543,14 +3615,14 @@ handlePetActivate_fn = function() {
3543
3615
  __privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
3544
3616
  };
3545
3617
  handlePetClose_fn = function() {
3546
- __privateSet(this, _petClosedByContextMenu, true);
3547
- __privateSet(this, _framePetOptionsOverride, null);
3548
- __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3549
3618
  __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3550
- __privateGet(this, _petOverlay).setOptions(null);
3551
3619
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
3620
+ __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, false);
3552
3621
  return;
3553
3622
  }
3623
+ __privateSet(this, _petClosedByContextMenu, true);
3624
+ __privateSet(this, _framePetOptionsOverride, null);
3625
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3554
3626
  __privateGet(this, _loaded).then(() => __privateGet(this, _messenger).commands.setPetEnabled({ enabled: false })).catch(() => void 0);
3555
3627
  };
3556
3628
  handlePetReply_fn = async function(text) {
@@ -3603,7 +3675,7 @@ maybeInit_fn = function() {
3603
3675
  const frameURL = new URL(__privateMethod(this, _ChatKitElementBase_instances, getFrameUrl_fn).call(this), window.location.origin);
3604
3676
  __privateGet(this, _messenger).setTargetOrigin(frameURL.origin);
3605
3677
  frameURL.hash = encodeBase64({
3606
- options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
3678
+ options: __privateMethod(this, _ChatKitElementBase_instances, innerOptions_fn).call(this, __privateGet(this, _opts)),
3607
3679
  referrer: window.location.origin,
3608
3680
  profile: this.profile,
3609
3681
  ...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}