@xpert-ai/chatkit-web-component 0.19.0 → 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());
@@ -269,10 +269,12 @@ class HttpError extends Error {
269
269
  super(message);
270
270
  __publicField(this, "status");
271
271
  __publicField(this, "statusText");
272
+ __publicField(this, "retryAfterMs");
272
273
  __publicField(this, "metadata");
273
274
  this.name = "HttpError";
274
275
  this.statusText = res.statusText;
275
276
  this.status = res.status;
277
+ this.retryAfterMs = res.retryAfterMs;
276
278
  this.metadata = metadata;
277
279
  }
278
280
  static fromPossibleFrameSafeError(error) {
@@ -285,7 +287,8 @@ class HttpError extends Error {
285
287
  safeError.message,
286
288
  {
287
289
  status: safeError.status,
288
- statusText: safeError.statusText
290
+ statusText: safeError.statusText,
291
+ retryAfterMs: safeError.retryAfterMs
289
292
  },
290
293
  safeError.metadata
291
294
  );
@@ -303,11 +306,13 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
303
306
  __publicField(this, "stack");
304
307
  __publicField(this, "status");
305
308
  __publicField(this, "statusText");
309
+ __publicField(this, "retryAfterMs");
306
310
  __publicField(this, "metadata");
307
311
  this.message = message;
308
312
  this.stack = new Error(message).stack;
309
313
  this.status = res.status;
310
314
  this.statusText = res.statusText;
315
+ this.retryAfterMs = res.retryAfterMs;
311
316
  this.metadata = metadata;
312
317
  }
313
318
  static fromHttpError(error) {
@@ -315,7 +320,8 @@ const _FrameSafeHttpError = class _FrameSafeHttpError {
315
320
  error.message,
316
321
  {
317
322
  status: error.status,
318
- statusText: error.statusText
323
+ statusText: error.statusText,
324
+ retryAfterMs: error.retryAfterMs
319
325
  },
320
326
  error.metadata
321
327
  );
@@ -437,19 +443,42 @@ class FrameSafeIntegrationError {
437
443
  }
438
444
  }
439
445
  function serializeFrameError(error) {
446
+ if (error instanceof HttpError || error instanceof FrameSafeHttpError) {
447
+ try {
448
+ return structuredClone(
449
+ error instanceof HttpError ? FrameSafeHttpError.fromHttpError(error) : error
450
+ );
451
+ } catch {
452
+ }
453
+ }
454
+ if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
455
+ const message = "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
456
+ return new FrameSafeHttpError(message, {
457
+ status: error.status,
458
+ statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0,
459
+ retryAfterMs: readRetryAfterMs(error)
460
+ });
461
+ }
440
462
  try {
441
463
  return structuredClone(error);
442
464
  } catch {
443
465
  const message = error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : "ChatKit host request failed";
444
- if (error && typeof error === "object" && "status" in error && typeof error.status === "number") {
445
- return new FrameSafeHttpError(message, {
446
- status: error.status,
447
- statusText: "statusText" in error && typeof error.statusText === "string" ? error.statusText : void 0
448
- });
449
- }
450
466
  return new Error(message);
451
467
  }
452
468
  }
469
+ function readRetryAfterMs(error) {
470
+ if ("retryAfterMs" in error && typeof error.retryAfterMs === "number" && Number.isFinite(error.retryAfterMs)) {
471
+ return Math.max(0, error.retryAfterMs);
472
+ }
473
+ if (!("headers" in error) || !error.headers || typeof error.headers !== "object")
474
+ return;
475
+ const headers = error.headers;
476
+ if (!("get" in headers) || typeof headers.get !== "function") return;
477
+ const value = headers.get("Retry-After");
478
+ if (typeof value !== "string" || !value.trim()) return;
479
+ const duration = /^\d+(\.\d+)?$/.test(value.trim()) ? Number(value) * 1e3 : Date.parse(value) - Date.now();
480
+ return Number.isFinite(duration) ? Math.max(0, duration) : void 0;
481
+ }
453
482
  class BaseMessenger {
454
483
  constructor({
455
484
  handlers,
@@ -1267,6 +1296,7 @@ const PET_SUMMARY_FONT_FAMILY = 'system-ui, -apple-system, BlinkMacSystemFont, "
1267
1296
  const PET_OVERLAY_COPY = {
1268
1297
  "en-US": {
1269
1298
  closePetMenuItem: "Close pet",
1299
+ reopenPet: "Show pet",
1270
1300
  hideMessage: "Hide message",
1271
1301
  expandMessage: "Expand message",
1272
1302
  collapseMessage: "Collapse message",
@@ -1279,6 +1309,7 @@ const PET_OVERLAY_COPY = {
1279
1309
  },
1280
1310
  "zh-CN": {
1281
1311
  closePetMenuItem: "关闭宠物",
1312
+ reopenPet: "显示宠物",
1282
1313
  hideMessage: "隐藏消息",
1283
1314
  expandMessage: "展开消息",
1284
1315
  collapseMessage: "收起消息",
@@ -1489,6 +1520,7 @@ function parseThreadSummaryLogPayload(value) {
1489
1520
  }
1490
1521
  class PetOverlay {
1491
1522
  constructor(root, options) {
1523
+ this.reopenButton = null;
1492
1524
  this.overlayElement = null;
1493
1525
  this.petElement = null;
1494
1526
  this.contextMenuElement = null;
@@ -1736,6 +1768,7 @@ class PetOverlay {
1736
1768
  this.root = root;
1737
1769
  this.onActivate = options == null ? void 0 : options.onActivate;
1738
1770
  this.onClose = options == null ? void 0 : options.onClose;
1771
+ this.onReopen = options == null ? void 0 : options.onReopen;
1739
1772
  this.onReply = options == null ? void 0 : options.onReply;
1740
1773
  this.onThreadSummaryActivate = options == null ? void 0 : options.onThreadSummaryActivate;
1741
1774
  this.connect();
@@ -1779,6 +1812,44 @@ class PetOverlay {
1779
1812
  this.resolveCharacter();
1780
1813
  this.render();
1781
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
+ }
1782
1853
  setState(state) {
1783
1854
  var _a2;
1784
1855
  const previous = this.lastAutoState;
@@ -1842,6 +1913,7 @@ class PetOverlay {
1842
1913
  return;
1843
1914
  }
1844
1915
  this.connected = false;
1916
+ this.setReopenVisible(false);
1845
1917
  this.clearRestingDelayTimer();
1846
1918
  this.clearTimers();
1847
1919
  this.removeDragListeners();
@@ -2749,9 +2821,6 @@ class PetOverlay {
2749
2821
  window.removeEventListener("pointercancel", this.handlePointerUp);
2750
2822
  }
2751
2823
  }
2752
- function getInnerOptions(options) {
2753
- return removeMethods(options);
2754
- }
2755
2824
  function requireCommandCapability(value, context) {
2756
2825
  const command = String(context.name);
2757
2826
  return function(...args) {
@@ -2778,10 +2847,13 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2778
2847
  __privateAdd(this, _chatMinimizedToPet, false);
2779
2848
  __privateAdd(this, _framePetOptionsOverride);
2780
2849
  __privateAdd(this, _petClosedByContextMenu, false);
2850
+ __privateAdd(this, _hostLauncherEnabled, true);
2851
+ __privateAdd(this, _launcherVisible, true);
2781
2852
  __privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
2782
2853
  __privateAdd(this, _petOverlay, new PetOverlay(__privateGet(this, _shadow), {
2783
2854
  onActivate: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetActivate_fn).call(this),
2784
2855
  onClose: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetClose_fn).call(this),
2856
+ onReopen: () => __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, true),
2785
2857
  onReply: (text) => __privateMethod(this, _ChatKitElementBase_instances, handlePetReply_fn).call(this, text),
2786
2858
  onThreadSummaryActivate: (threadId) => void __privateMethod(this, _ChatKitElementBase_instances, handlePetThreadSummaryActivate_fn).call(this, threadId)
2787
2859
  }));
@@ -2974,6 +3046,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2974
3046
  }
2975
3047
  connectedCallback() {
2976
3048
  __privateGet(this, _petOverlay).connect();
3049
+ if (__privateGet(this, _opts)) __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
2977
3050
  const style = document.createElement("style");
2978
3051
  style.textContent = `
2979
3052
  :host {
@@ -3252,19 +3325,26 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
3252
3325
  __privateGet(this, _petOverlay).destroy();
3253
3326
  }
3254
3327
  applySanitizedOptions(newOptions) {
3255
- 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
+ }
3256
3340
  __privateSet(this, _opts, newOptions);
3257
- 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();
3258
3342
  __privateSet(this, _petClosedByContextMenu, false);
3259
3343
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
3260
3344
  __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3261
3345
  if (__privateGet(this, _initialized)) {
3262
3346
  __privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
3263
- __privateGet(this, _loaded).then(() => {
3264
- __privateGet(this, _messenger).commands.setOptions(
3265
- getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, newOptions))
3266
- );
3267
- });
3347
+ __privateMethod(this, _ChatKitElementBase_instances, updateFrameOptions_fn).call(this);
3268
3348
  } else {
3269
3349
  __privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
3270
3350
  }
@@ -3356,6 +3436,8 @@ _launcherOpen = new WeakMap();
3356
3436
  _chatMinimizedToPet = new WeakMap();
3357
3437
  _framePetOptionsOverride = new WeakMap();
3358
3438
  _petClosedByContextMenu = new WeakMap();
3439
+ _hostLauncherEnabled = new WeakMap();
3440
+ _launcherVisible = new WeakMap();
3359
3441
  _shadow = new WeakMap();
3360
3442
  _petOverlay = new WeakMap();
3361
3443
  _resolveLoaded = new WeakMap();
@@ -3378,14 +3460,9 @@ setOptionsDataAttributes_fn = function(options) {
3378
3460
  getDisplayMode_fn = function(options = __privateGet(this, _opts)) {
3379
3461
  return (options == null ? void 0 : options.displayMode) === "pet" ? "pet" : "chat";
3380
3462
  };
3381
- getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
3382
- if (!options) {
3383
- return null;
3384
- }
3385
- if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) === "pet" && !normalizePetOptions(options.pet ?? null)) {
3386
- return typeof options.pet === "object" ? { ...options.pet, enabled: true } : true;
3387
- }
3388
- 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);
3389
3466
  };
3390
3467
  mergeConfiguredPetPositionDefaults_fn = function(pet) {
3391
3468
  if (!pet) {
@@ -3413,9 +3490,41 @@ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3413
3490
  }
3414
3491
  };
3415
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
+ };
3416
3525
  getOverlayPetOptions_fn = function() {
3417
3526
  var _a2;
3418
- 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") {
3419
3528
  return null;
3420
3529
  }
3421
3530
  let pet;
@@ -3425,7 +3534,7 @@ getOverlayPetOptions_fn = function() {
3425
3534
  pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3426
3535
  }
3427
3536
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !normalizePetOptions(pet ?? null)) {
3428
- pet = true;
3537
+ pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3429
3538
  }
3430
3539
  return __privateMethod(this, _ChatKitElementBase_instances, resolveOverlayPetOptions_fn).call(this, pet);
3431
3540
  };
@@ -3460,19 +3569,6 @@ resolveOverlayPetOptions_fn = function(pet) {
3460
3569
  imageRendering: normalized.imageRendering
3461
3570
  };
3462
3571
  };
3463
- getFrameOptions_fn = function(options) {
3464
- const pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this, options);
3465
- if (pet === (options.pet ?? null)) {
3466
- return options;
3467
- }
3468
- const nextOptions = { ...options };
3469
- if (pet === null) {
3470
- delete nextOptions.pet;
3471
- } else {
3472
- nextOptions.pet = pet;
3473
- }
3474
- return nextOptions;
3475
- };
3476
3572
  setLauncherOpen_fn = function(open) {
3477
3573
  __privateSet(this, _launcherOpen, open);
3478
3574
  if (open) {
@@ -3491,9 +3587,14 @@ setChatMinimizedToPet_fn = function(minimized) {
3491
3587
  }
3492
3588
  };
3493
3589
  syncPetOverlayOptions_fn = function() {
3494
- 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);
3495
3592
  const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
3496
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
+ );
3497
3598
  if (!overlayPetOptions) {
3498
3599
  __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3499
3600
  }
@@ -3514,14 +3615,14 @@ handlePetActivate_fn = function() {
3514
3615
  __privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
3515
3616
  };
3516
3617
  handlePetClose_fn = function() {
3517
- __privateSet(this, _petClosedByContextMenu, true);
3518
- __privateSet(this, _framePetOptionsOverride, null);
3519
- __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3520
3618
  __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3521
- __privateGet(this, _petOverlay).setOptions(null);
3522
3619
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
3620
+ __privateMethod(this, _ChatKitElementBase_instances, requestLauncherVisibility_fn).call(this, false);
3523
3621
  return;
3524
3622
  }
3623
+ __privateSet(this, _petClosedByContextMenu, true);
3624
+ __privateSet(this, _framePetOptionsOverride, null);
3625
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
3525
3626
  __privateGet(this, _loaded).then(() => __privateGet(this, _messenger).commands.setPetEnabled({ enabled: false })).catch(() => void 0);
3526
3627
  };
3527
3628
  handlePetReply_fn = async function(text) {
@@ -3574,7 +3675,7 @@ maybeInit_fn = function() {
3574
3675
  const frameURL = new URL(__privateMethod(this, _ChatKitElementBase_instances, getFrameUrl_fn).call(this), window.location.origin);
3575
3676
  __privateGet(this, _messenger).setTargetOrigin(frameURL.origin);
3576
3677
  frameURL.hash = encodeBase64({
3577
- 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)),
3578
3679
  referrer: window.location.origin,
3579
3680
  profile: this.profile,
3580
3681
  ...__privateGet(this, _channelId) ? { channelId: __privateGet(this, _channelId) } : {}