@xpert-ai/chatkit-web-component 0.19.1 → 0.19.3

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, _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;
54
+ 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;
55
55
  class EventEmitter {
56
56
  constructor() {
57
57
  __publicField(this, "callbacks", /* @__PURE__ */ new Map());
@@ -1300,6 +1300,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1300
1300
  const PET_OVERLAY_COPY = {
1301
1301
  "en-US": {
1302
1302
  closePetMenuItem: "Close pet",
1303
+ reopenPet: "Show pet",
1303
1304
  hideMessage: "Hide message",
1304
1305
  expandMessage: "Expand message",
1305
1306
  collapseMessage: "Collapse message",
@@ -1312,6 +1313,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1312
1313
  },
1313
1314
  "zh-CN": {
1314
1315
  closePetMenuItem: "关闭宠物",
1316
+ reopenPet: "显示宠物",
1315
1317
  hideMessage: "隐藏消息",
1316
1318
  expandMessage: "展开消息",
1317
1319
  collapseMessage: "收起消息",
@@ -1522,6 +1524,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1522
1524
  }
1523
1525
  class PetOverlay {
1524
1526
  constructor(root, options) {
1527
+ this.reopenButton = null;
1525
1528
  this.overlayElement = null;
1526
1529
  this.petElement = null;
1527
1530
  this.contextMenuElement = null;
@@ -1769,6 +1772,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1769
1772
  this.root = root;
1770
1773
  this.onActivate = options == null ? void 0 : options.onActivate;
1771
1774
  this.onClose = options == null ? void 0 : options.onClose;
1775
+ this.onReopen = options == null ? void 0 : options.onReopen;
1772
1776
  this.onReply = options == null ? void 0 : options.onReply;
1773
1777
  this.onThreadSummaryActivate = options == null ? void 0 : options.onThreadSummaryActivate;
1774
1778
  this.connect();
@@ -1812,6 +1816,44 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1812
1816
  this.resolveCharacter();
1813
1817
  this.render();
1814
1818
  }
1819
+ setReopenVisible(visible, zIndex) {
1820
+ var _a2, _b2, _c2, _d, _e, _f;
1821
+ if (!visible) {
1822
+ (_a2 = this.reopenButton) == null ? void 0 : _a2.remove();
1823
+ this.reopenButton = null;
1824
+ return;
1825
+ }
1826
+ if (!this.reopenButton) {
1827
+ const button2 = document.createElement("button");
1828
+ button2.type = "button";
1829
+ button2.addEventListener("click", () => {
1830
+ var _a3;
1831
+ return (_a3 = this.onReopen) == null ? void 0 : _a3.call(this);
1832
+ });
1833
+ this.root.append(button2);
1834
+ this.reopenButton = button2;
1835
+ }
1836
+ const button = this.reopenButton;
1837
+ const theme = typeof this.theme === "object" ? this.theme : null;
1838
+ const metrics = getSummaryThemeMetrics(this.theme);
1839
+ button.textContent = this.copy.reopenPet;
1840
+ Object.assign(button.style, {
1841
+ position: "fixed",
1842
+ insetInlineEnd: `${PET_SUMMARY_MARGIN}px`,
1843
+ bottom: `${PET_SUMMARY_MARGIN}px`,
1844
+ zIndex: String(zIndex ?? ((_b2 = normalizePetOptions(true)) == null ? void 0 : _b2.position.zIndex)),
1845
+ pointerEvents: "auto",
1846
+ cursor: "pointer",
1847
+ colorScheme: typeof this.theme === "string" ? this.theme : (theme == null ? void 0 : theme.colorScheme) ?? "light",
1848
+ color: ((_d = (_c2 = theme == null ? void 0 : theme.color) == null ? void 0 : _c2.surface) == null ? void 0 : _d.foreground) ?? "ButtonText",
1849
+ background: ((_f = (_e = theme == null ? void 0 : theme.color) == null ? void 0 : _e.surface) == null ? void 0 : _f.background) ?? "ButtonFace",
1850
+ border: "1px solid ButtonBorder",
1851
+ borderRadius: `${metrics.radius}px`,
1852
+ padding: metrics.padding,
1853
+ fontFamily: metrics.fontFamily,
1854
+ fontSize: `${metrics.bodySize}px`
1855
+ });
1856
+ }
1815
1857
  setState(state) {
1816
1858
  var _a2;
1817
1859
  const previous = this.lastAutoState;
@@ -1875,6 +1917,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1875
1917
  return;
1876
1918
  }
1877
1919
  this.connected = false;
1920
+ this.setReopenVisible(false);
1878
1921
  this.clearRestingDelayTimer();
1879
1922
  this.clearTimers();
1880
1923
  this.removeDragListeners();
@@ -2782,9 +2825,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2782
2825
  window.removeEventListener("pointercancel", this.handlePointerUp);
2783
2826
  }
2784
2827
  }
2785
- function getInnerOptions(options) {
2786
- return removeMethods(options);
2787
- }
2788
2828
  function requireCommandCapability(value, context) {
2789
2829
  const command = String(context.name);
2790
2830
  return function(...args) {
@@ -2811,10 +2851,13 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2811
2851
  __privateAdd(this, _chatMinimizedToPet, false);
2812
2852
  __privateAdd(this, _framePetOptionsOverride);
2813
2853
  __privateAdd(this, _petClosedByContextMenu, false);
2854
+ __privateAdd(this, _hostLauncherEnabled, true);
2855
+ __privateAdd(this, _launcherVisible, true);
2814
2856
  __privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
2815
2857
  __privateAdd(this, _petOverlay, new PetOverlay(__privateGet(this, _shadow), {
2816
2858
  onActivate: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetActivate_fn).call(this),
2817
2859
  onClose: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetClose_fn).call(this),
2860
+ onReopen: () => __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, true),
2818
2861
  onReply: (text) => __privateMethod(this, _ChatKitElementBase_instances, handlePetReply_fn).call(this, text),
2819
2862
  onThreadSummaryActivate: (threadId) => void __privateMethod(this, _ChatKitElementBase_instances, handlePetThreadSummaryActivate_fn).call(this, threadId)
2820
2863
  }));
@@ -3007,6 +3050,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3007
3050
  }
3008
3051
  connectedCallback() {
3009
3052
  __privateGet(this, _petOverlay).connect();
3053
+ if (__privateGet(this, _opts)) __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3010
3054
  const style = document.createElement("style");
3011
3055
  style.textContent = `
3012
3056
  :host {
@@ -3285,19 +3329,26 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3285
3329
  __privateGet(this, _petOverlay).destroy();
3286
3330
  }
3287
3331
  applySanitizedOptions(newOptions) {
3288
- var _a2, _b2;
3332
+ var _a2, _b2, _c2, _d;
3333
+ 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);
3334
+ const pet = newOptions.pet;
3335
+ const enabled = typeof pet === "boolean" ? pet : (pet == null ? void 0 : pet.enabled) ?? true;
3336
+ if (sessionChanged || enabled !== __privateGet(this, _hostLauncherEnabled)) {
3337
+ __privateSet(this, _launcherVisible, enabled);
3338
+ }
3339
+ __privateSet(this, _hostLauncherEnabled, enabled);
3340
+ if (sessionChanged) {
3341
+ __privateSet(this, _framePetOptionsOverride, void 0);
3342
+ __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3343
+ }
3289
3344
  __privateSet(this, _opts, newOptions);
3290
- if (!((_a2 = newOptions.header) == null ? void 0 : _a2.windowDrag)) (_b2 = __privateGet(this, _windowDrag)) == null ? void 0 : _b2.clear();
3345
+ if (!((_c2 = newOptions.header) == null ? void 0 : _c2.windowDrag)) (_d = __privateGet(this, _windowDrag)) == null ? void 0 : _d.clear();
3291
3346
  __privateSet(this, _petClosedByContextMenu, false);
3292
3347
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
3293
3348
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3294
3349
  if (__privateGet(this, _initialized)) {
3295
3350
  __privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
3296
- __privateGet(this, _loaded).then(() => {
3297
- __privateGet(this, _messenger).commands.setOptions(
3298
- getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, newOptions))
3299
- );
3300
- });
3351
+ __privateMethod(this, _ChatKitElementBase_instances, updateFrameOptions_fn).call(this);
3301
3352
  } else {
3302
3353
  __privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
3303
3354
  }
@@ -3389,6 +3440,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3389
3440
  _chatMinimizedToPet = new WeakMap();
3390
3441
  _framePetOptionsOverride = new WeakMap();
3391
3442
  _petClosedByContextMenu = new WeakMap();
3443
+ _hostLauncherEnabled = new WeakMap();
3444
+ _launcherVisible = new WeakMap();
3392
3445
  _shadow = new WeakMap();
3393
3446
  _petOverlay = new WeakMap();
3394
3447
  _resolveLoaded = new WeakMap();
@@ -3411,14 +3464,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3411
3464
  getDisplayMode_fn = function(options = __privateGet(this, _opts)) {
3412
3465
  return (options == null ? void 0 : options.displayMode) === "pet" ? "pet" : "chat";
3413
3466
  };
3414
- getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
3415
- if (!options) {
3416
- return null;
3417
- }
3418
- if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) === "pet" && !normalizePetOptions(options.pet ?? null)) {
3419
- return typeof options.pet === "object" ? { ...options.pet, enabled: true } : true;
3420
- }
3421
- return options.pet ?? null;
3467
+ getConfiguredPetOptions_fn = function() {
3468
+ if (!__privateGet(this, _opts)) return null;
3469
+ return __privateMethod(this, _ChatKitElementBase_instances, effectivePet_fn).call(this, __privateGet(this, _opts)) ?? (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" ? true : null);
3422
3470
  };
3423
3471
  mergeConfiguredPetPositionDefaults_fn = function(pet) {
3424
3472
  if (!pet) {
@@ -3446,9 +3494,41 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3446
3494
  }
3447
3495
  };
3448
3496
  };
3497
+ effectivePet_fn = function(options) {
3498
+ const pet = options.pet;
3499
+ if (options.displayMode !== "pet" || __privateGet(this, _launcherVisible) === __privateGet(this, _hostLauncherEnabled)) {
3500
+ return pet;
3501
+ }
3502
+ return typeof pet === "object" ? { ...pet, enabled: __privateGet(this, _launcherVisible) } : __privateGet(this, _launcherVisible);
3503
+ };
3504
+ innerOptions_fn = function(options) {
3505
+ return removeMethods({
3506
+ ...options,
3507
+ pet: __privateMethod(this, _ChatKitElementBase_instances, effectivePet_fn).call(this, options)
3508
+ });
3509
+ };
3510
+ updateFrameOptions_fn = function() {
3511
+ __privateGet(this, _loaded).then(() => {
3512
+ if (__privateGet(this, _opts))
3513
+ __privateGet(this, _messenger).commands.setOptions(__privateMethod(this, _ChatKitElementBase_instances, innerOptions_fn).call(this, __privateGet(this, _opts)));
3514
+ });
3515
+ };
3516
+ isLauncherHidden_fn = function() {
3517
+ return __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !__privateGet(this, _launcherVisible);
3518
+ };
3519
+ requestLauncherVisibility_fn = function(visible) {
3520
+ __privateSet(this, _launcherVisible, visible);
3521
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3522
+ __privateMethod(this, _ChatKitElementBase_instances, updateFrameOptions_fn).call(this);
3523
+ this.dispatchEvent(
3524
+ new CustomEvent("chatkit.pet.launcher.visibility.change", {
3525
+ detail: { visible }
3526
+ })
3527
+ );
3528
+ };
3449
3529
  getOverlayPetOptions_fn = function() {
3450
3530
  var _a2;
3451
- if (__privateGet(this, _petClosedByContextMenu) || ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.pet) === false && __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3531
+ 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") {
3452
3532
  return null;
3453
3533
  }
3454
3534
  let pet;
@@ -3458,7 +3538,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3458
3538
  pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3459
3539
  }
3460
3540
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !normalizePetOptions(pet ?? null)) {
3461
- pet = true;
3541
+ pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3462
3542
  }
3463
3543
  return __privateMethod(this, _ChatKitElementBase_instances, resolveOverlayPetOptions_fn).call(this, pet);
3464
3544
  };
@@ -3493,19 +3573,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3493
3573
  imageRendering: normalized.imageRendering
3494
3574
  };
3495
3575
  };
3496
- getFrameOptions_fn = function(options) {
3497
- const pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this, options);
3498
- if (pet === (options.pet ?? null)) {
3499
- return options;
3500
- }
3501
- const nextOptions = { ...options };
3502
- if (pet === null) {
3503
- delete nextOptions.pet;
3504
- } else {
3505
- nextOptions.pet = pet;
3506
- }
3507
- return nextOptions;
3508
- };
3509
3576
  setLauncherOpen_fn = function(open) {
3510
3577
  __privateSet(this, _launcherOpen, open);
3511
3578
  if (open) {
@@ -3524,9 +3591,14 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3524
3591
  }
3525
3592
  };
3526
3593
  syncPetOverlayOptions_fn = function() {
3527
- var _a2;
3594
+ var _a2, _b2, _c2;
3595
+ if (__privateMethod(this, _ChatKitElementBase_instances, isLauncherHidden_fn).call(this)) __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3528
3596
  const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
3529
3597
  __privateGet(this, _petOverlay).setOptions(overlayPetOptions, (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.theme);
3598
+ __privateGet(this, _petOverlay).setReopenVisible(
3599
+ __privateMethod(this, _ChatKitElementBase_instances, isLauncherHidden_fn).call(this),
3600
+ typeof ((_b2 = __privateGet(this, _opts)) == null ? void 0 : _b2.pet) === "object" ? (_c2 = __privateGet(this, _opts).pet.position) == null ? void 0 : _c2.zIndex : void 0
3601
+ );
3530
3602
  if (!overlayPetOptions) {
3531
3603
  __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3532
3604
  }
@@ -3547,14 +3619,14 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3547
3619
  __privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
3548
3620
  };
3549
3621
  handlePetClose_fn = function() {
3550
- __privateSet(this, _petClosedByContextMenu, true);
3551
- __privateSet(this, _framePetOptionsOverride, null);
3552
- __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3553
3622
  __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3554
- __privateGet(this, _petOverlay).setOptions(null);
3555
3623
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
3624
+ __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, false);
3556
3625
  return;
3557
3626
  }
3627
+ __privateSet(this, _petClosedByContextMenu, true);
3628
+ __privateSet(this, _framePetOptionsOverride, null);
3629
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3558
3630
  __privateGet(this, _loaded).then(() => __privateGet(this, _messenger).commands.setPetEnabled({ enabled: false })).catch(() => void 0);
3559
3631
  };
3560
3632
  handlePetReply_fn = async function(text) {
@@ -3607,7 +3679,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3607
3679
  const frameURL = new URL(__privateMethod(this, _ChatKitElementBase_instances, getFrameUrl_fn).call(this), window.location.origin);
3608
3680
  __privateGet(this, _messenger).setTargetOrigin(frameURL.origin);
3609
3681
  frameURL.hash = encodeBase64({
3610
- options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
3682
+ options: __privateMethod(this, _ChatKitElementBase_instances, innerOptions_fn).call(this, __privateGet(this, _opts)),
3611
3683
  referrer: window.location.origin,
3612
3684
  profile: this.profile,
3613
3685
  ...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}