@active-reach/web-sdk 1.46.1 → 1.46.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.
package/dist/index.js CHANGED
@@ -1804,9 +1804,9 @@ function buildProgressElement(el2, ctx, accent, muted, compact) {
1804
1804
  }
1805
1805
  return wrap;
1806
1806
  }
1807
- function buildCtaAction(el2, card, meta, inline, sanitizeUrl) {
1807
+ function buildCtaAction(el2, card, meta, inline, sanitizeUrl2) {
1808
1808
  const kind = el2.cta_action ?? (inline ? "add_to_cart" : "navigate");
1809
- const safe = (u) => u ? sanitizeUrl(u) || void 0 : void 0;
1809
+ const safe = (u) => u ? sanitizeUrl2(u) || void 0 : void 0;
1810
1810
  const url = safe(el2.cta_url || card.cta_url);
1811
1811
  const productId = meta.product_id;
1812
1812
  const sku = meta.sku;
@@ -1860,7 +1860,7 @@ function findElement(els, type) {
1860
1860
  function renderCardFromTemplate(card, opts) {
1861
1861
  const { ctx, action, layout, layoutAccent } = opts;
1862
1862
  const inline = action === "cart";
1863
- const { campaign, trackEvent, sanitizeUrl, sanitizeColor } = ctx;
1863
+ const { campaign, trackEvent, sanitizeUrl: sanitizeUrl2, sanitizeColor } = ctx;
1864
1864
  const tpl = applyPerCardOverride(opts.template, asLook(card.style));
1865
1865
  const frame = tpl.frame || {};
1866
1866
  const meta = card.metadata || {};
@@ -1870,6 +1870,10 @@ function renderCardFromTemplate(card, opts) {
1870
1870
  const muted = fg === "#ffffff" ? "rgba(255,255,255,0.72)" : "#6b7280";
1871
1871
  const compact = slotVariant(ctx.slotEl) === "compact";
1872
1872
  const frameBg = frame.bg ? sanitizeColor(frame.bg) : "#ffffff";
1873
+ const ink = (role, own) => {
1874
+ const base = own ? sanitizeColor(own) : role === "fg" ? fg : muted;
1875
+ return compact ? `var(--aegis-card-${role}, ${base})` : base;
1876
+ };
1873
1877
  const tile = document.createElement("div");
1874
1878
  markEl(tile, "frame");
1875
1879
  if (compact) tile.setAttribute("data-aegis-variant", "compact");
@@ -1921,7 +1925,7 @@ function renderCardFromTemplate(card, opts) {
1921
1925
  case "image": {
1922
1926
  const wrap = document.createElement("div");
1923
1927
  wrap.style.cssText = `position:relative;width:100%;aspect-ratio:${ASPECT$2[el2.aspect || "1/1"] || "1 / 1"};border-radius:${el2.radius ?? 10}px;overflow:hidden;background:#f7f8fa;`;
1924
- const safeVideo = card.video_url ? sanitizeUrl(card.video_url) : "";
1928
+ const safeVideo = card.video_url ? sanitizeUrl2(card.video_url) : "";
1925
1929
  if (safeVideo) {
1926
1930
  const v = document.createElement("video");
1927
1931
  v.src = safeVideo;
@@ -1933,7 +1937,7 @@ function renderCardFromTemplate(card, opts) {
1933
1937
  v.style.cssText = "width:100%;height:100%;object-fit:cover;display:block;";
1934
1938
  wrap.appendChild(v);
1935
1939
  } else if (card.image_url) {
1936
- const safe = sanitizeUrl(card.image_url);
1940
+ const safe = sanitizeUrl2(card.image_url);
1937
1941
  if (safe) {
1938
1942
  const img = document.createElement("img");
1939
1943
  const size = IMAGE_SIZE[el2.aspect || "1/1"] || IMAGE_SIZE["1/1"];
@@ -1982,7 +1986,7 @@ function renderCardFromTemplate(card, opts) {
1982
1986
  markEl(t, "title");
1983
1987
  t.textContent = card.title;
1984
1988
  const lines = el2.lines && el2.lines > 0 ? el2.lines : 2;
1985
- t.style.cssText = `${displayFont}font-size:12.5px;font-weight:600;line-height:1.3;text-align:${el2.align ?? "left"};color:${el2.color ? sanitizeColor(el2.color) : fg};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1989
+ t.style.cssText = `${displayFont}font-size:12.5px;font-weight:600;line-height:1.3;text-align:${el2.align ?? "left"};color:${ink("fg", el2.color)};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1986
1990
  container.appendChild(t);
1987
1991
  break;
1988
1992
  }
@@ -1992,7 +1996,7 @@ function renderCardFromTemplate(card, opts) {
1992
1996
  markEl(s, "subtitle");
1993
1997
  s.textContent = card.body;
1994
1998
  const lines = el2.lines && el2.lines > 0 ? el2.lines : 2;
1995
- s.style.cssText = `font-size:11px;color:${el2.color ? sanitizeColor(el2.color) : muted};line-height:1.3;text-align:${el2.align ?? "left"};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1999
+ s.style.cssText = `font-size:11px;color:${ink("muted", el2.color)};line-height:1.3;text-align:${el2.align ?? "left"};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1996
2000
  container.appendChild(s);
1997
2001
  break;
1998
2002
  }
@@ -2015,7 +2019,7 @@ function renderCardFromTemplate(card, opts) {
2015
2019
  const px = ICON_PX[el2.size || "md"] || 30;
2016
2020
  const node = document.createElement("div");
2017
2021
  markEl(node, "icon");
2018
- const iconColor = el2.color ? sanitizeColor(el2.color) : fg;
2022
+ const iconColor = compact ? "currentColor" : el2.color ? sanitizeColor(el2.color) : fg;
2019
2023
  if (el2.bubble) {
2020
2024
  const bubbleTint = el2.color ? sanitizeColor(el2.color) : brand;
2021
2025
  node.style.cssText = `flex:0 0 auto;width:${px}px;height:${px}px;border-radius:999px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb, ${bubbleTint} 16%, transparent);`;
@@ -2027,6 +2031,7 @@ function renderCardFromTemplate(card, opts) {
2027
2031
  color: iconColor,
2028
2032
  strokeWidth: 2
2029
2033
  });
2034
+ if (compact) node.style.cssText += `color:${ink("fg", el2.color)};`;
2030
2035
  if (svg) node.appendChild(svg);
2031
2036
  container.appendChild(node);
2032
2037
  break;
@@ -2035,7 +2040,7 @@ function renderCardFromTemplate(card, opts) {
2035
2040
  const t = document.createElement("div");
2036
2041
  markEl(t, "text");
2037
2042
  const fs = TEXT_PX[el2.size || "md"] || 13;
2038
- t.style.cssText = `font-size:${fs}px;font-weight:${WEIGHT[el2.weight ?? "medium"]};text-align:${el2.align ?? "left"};color:${el2.color ? sanitizeColor(el2.color) : fg};line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;`;
2043
+ t.style.cssText = `font-size:${fs}px;font-weight:${WEIGHT[el2.weight ?? "medium"]};text-align:${el2.align ?? "left"};color:${ink("fg", el2.color)};line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;`;
2039
2044
  t.textContent = interpolateTokens(el2.content ?? "", ctx);
2040
2045
  container.appendChild(t);
2041
2046
  break;
@@ -2099,7 +2104,7 @@ function renderCardFromTemplate(card, opts) {
2099
2104
  trackEvent(campaign.id, "clicked", { stepId: el2.id || "add" });
2100
2105
  (_a = ctx.dispatchAction) == null ? void 0 : _a.call(
2101
2106
  ctx,
2102
- buildCtaAction(el2, card, meta, inline, sanitizeUrl)
2107
+ buildCtaAction(el2, card, meta, inline, sanitizeUrl2)
2103
2108
  );
2104
2109
  });
2105
2110
  (overlayOnImage ? imageWrap : container).appendChild(cta);
@@ -2127,7 +2132,7 @@ function renderCardFromTemplate(card, opts) {
2127
2132
  e.stopPropagation();
2128
2133
  trackEvent(campaign.id, "clicked");
2129
2134
  const bm = meta;
2130
- const safe = (u) => u ? sanitizeUrl(u) || void 0 : void 0;
2135
+ const safe = (u) => u ? sanitizeUrl2(u) || void 0 : void 0;
2131
2136
  const act = inline ? {
2132
2137
  type: "open_product",
2133
2138
  productId: bm.product_id,
@@ -2340,7 +2345,7 @@ function renderCarouselCards(ctx) {
2340
2345
  }
2341
2346
  const DISMISS_STORAGE_PREFIX = "aegis_sticky_dismissed:";
2342
2347
  function renderStickyBar(ctx) {
2343
- const { campaign, trackEvent, sanitizeUrl, sanitizeColor, log, addAnimationStyles } = ctx;
2348
+ const { campaign, trackEvent, sanitizeUrl: sanitizeUrl2, sanitizeColor, log, addAnimationStyles } = ctx;
2344
2349
  const ic = campaign.interactive_config || {};
2345
2350
  const position = ic.sticky_position === "top" ? "top" : "bottom";
2346
2351
  const dismissible = ic.sticky_dismissible !== false;
@@ -2390,7 +2395,7 @@ function renderStickyBar(ctx) {
2390
2395
  cta.addEventListener("click", () => {
2391
2396
  trackEvent(campaign.id, "clicked");
2392
2397
  if (campaign.action_url) {
2393
- const safe = sanitizeUrl(campaign.action_url);
2398
+ const safe = sanitizeUrl2(campaign.action_url);
2394
2399
  if (safe) window.location.href = safe;
2395
2400
  }
2396
2401
  });
@@ -2847,6 +2852,91 @@ function renderCoachmarkTour(ctx) {
2847
2852
  showStep(current);
2848
2853
  window.aegisResetTour = (key) => clearResume(key);
2849
2854
  }
2855
+ const RAIL_REASONS_WEAKEST_FIRST = [
2856
+ "popular_here",
2857
+ "same_category",
2858
+ "similar"
2859
+ ];
2860
+ const RESERVED_BOUGHT_TOGETHER_HEADINGS = {
2861
+ item: "Often bought together",
2862
+ cart: "Complete your order"
2863
+ };
2864
+ const DEFAULT_RAIL_TITLES = [
2865
+ "You might also like",
2866
+ "View Similar items",
2867
+ "Recommended for you",
2868
+ "Bestsellers",
2869
+ "Buy again",
2870
+ "Buy it again",
2871
+ "Picked for you",
2872
+ "Frequently bought together",
2873
+ "Loved by reviewers",
2874
+ "While you wait"
2875
+ ];
2876
+ const DEFAULT_KEYS = new Set(DEFAULT_RAIL_TITLES.map((t) => t.toLowerCase()));
2877
+ function isReplaceableRailTitle(title) {
2878
+ const t = (title ?? "").trim();
2879
+ return t === "" || DEFAULT_KEYS.has(t.toLowerCase());
2880
+ }
2881
+ const KNOWN = /* @__PURE__ */ new Set([
2882
+ "similar",
2883
+ "same_category",
2884
+ "popular_here",
2885
+ "top_rated"
2886
+ ]);
2887
+ function baseReason(raw) {
2888
+ if (typeof raw !== "string") return null;
2889
+ const base = raw.split("+")[0].trim();
2890
+ return KNOWN.has(base) ? base : null;
2891
+ }
2892
+ function railCategory(cards, only) {
2893
+ var _a, _b;
2894
+ const counts = /* @__PURE__ */ new Map();
2895
+ for (const c of cards) {
2896
+ if (only && baseReason((_a = c.metadata) == null ? void 0 : _a.reason) !== only) continue;
2897
+ const cat = (_b = c.metadata) == null ? void 0 : _b.category;
2898
+ if (typeof cat !== "string" || !cat.trim()) continue;
2899
+ const key = cat.trim();
2900
+ counts.set(key, (counts.get(key) ?? 0) + 1);
2901
+ }
2902
+ let best = null;
2903
+ let bestN = 0;
2904
+ for (const [cat, n] of counts) {
2905
+ if (n > bestN) {
2906
+ best = cat;
2907
+ bestN = n;
2908
+ }
2909
+ }
2910
+ return best;
2911
+ }
2912
+ function resolveRailHeading(cards, fallback) {
2913
+ var _a;
2914
+ const keep = { show: cards.length > 0, heading: fallback ?? "", reason: null };
2915
+ if (cards.length === 0) return keep;
2916
+ if (!isReplaceableRailTitle(fallback)) return keep;
2917
+ const reasons = /* @__PURE__ */ new Set();
2918
+ for (const c of cards) {
2919
+ const r = baseReason((_a = c.metadata) == null ? void 0 : _a.reason);
2920
+ if (r === null) return keep;
2921
+ reasons.add(r);
2922
+ }
2923
+ if (reasons.has("top_rated")) {
2924
+ return reasons.size === 1 ? { show: true, heading: "Loved by reviewers", reason: "top_rated" } : keep;
2925
+ }
2926
+ const weakest = RAIL_REASONS_WEAKEST_FIRST.find((r) => reasons.has(r));
2927
+ switch (weakest) {
2928
+ case "popular_here":
2929
+ return { show: true, heading: "Popular here", reason: "popular_here" };
2930
+ case "same_category": {
2931
+ const category = railCategory(cards, "same_category") ?? railCategory(cards);
2932
+ return category ? { show: true, heading: `More ${category}`, reason: "same_category" } : keep;
2933
+ }
2934
+ case "similar":
2935
+ return { show: true, heading: "Similar items", reason: "similar" };
2936
+ default:
2937
+ return keep;
2938
+ }
2939
+ }
2850
2940
  const MAX_PRODUCTS = 24;
2851
2941
  function renderProductRecommendation(ctx) {
2852
2942
  const { campaign, trackEvent, sanitizeColor, log, addAnimationStyles } = ctx;
@@ -2857,6 +2947,7 @@ function renderProductRecommendation(ctx) {
2857
2947
  log("product_recommendation rendered with zero products — skipping", "warn");
2858
2948
  return;
2859
2949
  }
2950
+ const rail = resolveRailHeading(cards, campaign.title);
2860
2951
  const layout = ic.rec_layout || "grid";
2861
2952
  const template = resolveGlobalTemplate(ic);
2862
2953
  addAnimationStyles();
@@ -2892,7 +2983,7 @@ function renderProductRecommendation(ctx) {
2892
2983
  header.style.cssText = "display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;";
2893
2984
  const headerText = document.createElement("div");
2894
2985
  const title = document.createElement("div");
2895
- title.textContent = campaign.title;
2986
+ title.textContent = rail.heading;
2896
2987
  title.style.cssText = "font-weight: 700; font-size: 16px; margin-bottom: 2px;";
2897
2988
  const body = document.createElement("div");
2898
2989
  body.textContent = campaign.body;
@@ -2953,6 +3044,7 @@ function renderProductRecommendationInline(ctx, target) {
2953
3044
  log("product_recommendation (inline) rendered with zero products — skipping", "warn");
2954
3045
  return false;
2955
3046
  }
3047
+ const rail = resolveRailHeading(cards, campaign.title);
2956
3048
  const layout = ic.rec_layout || "row";
2957
3049
  const template = resolveGlobalTemplate(ic);
2958
3050
  const fg = "#0f172a";
@@ -2965,9 +3057,9 @@ function renderProductRecommendationInline(ctx, target) {
2965
3057
  ${fontFamilyCss("body")}
2966
3058
  color: ${fg};
2967
3059
  `;
2968
- if (campaign.title) {
3060
+ if (rail.heading) {
2969
3061
  const title = document.createElement("h2");
2970
- title.textContent = campaign.title;
3062
+ title.textContent = rail.heading;
2971
3063
  title.style.cssText = "font-weight: 700; font-size: 16px; margin: 0 0 2px;";
2972
3064
  section.appendChild(title);
2973
3065
  }
@@ -3231,7 +3323,7 @@ function buildGroupBubble(ctx, cfg, g, i, labelColor) {
3231
3323
  return wrap;
3232
3324
  }
3233
3325
  function openViewer(ctx, cfg, startGroupIndex, startFrameIndex = 0) {
3234
- const { campaign, trackEvent, sanitizeUrl, log } = ctx;
3326
+ const { campaign, trackEvent, sanitizeUrl: sanitizeUrl2, log } = ctx;
3235
3327
  const { loop, autoplay, showProgress, defaultDuration, reduceMotion } = cfg;
3236
3328
  const groups = cfg.groups;
3237
3329
  if (groups.length === 0) return;
@@ -3342,8 +3434,8 @@ function openViewer(ctx, cfg, startGroupIndex, startFrameIndex = 0) {
3342
3434
  const f = frames[i];
3343
3435
  frameLayer.replaceChildren();
3344
3436
  currentVideo = null;
3345
- const safeVideo = f.video_url ? sanitizeUrl(f.video_url) : null;
3346
- const safeImage = f.image_url ? sanitizeUrl(f.image_url) : null;
3437
+ const safeVideo = f.video_url ? sanitizeUrl2(f.video_url) : null;
3438
+ const safeImage = f.image_url ? sanitizeUrl2(f.image_url) : null;
3347
3439
  if (safeVideo) {
3348
3440
  const vid = document.createElement("video");
3349
3441
  vid.src = safeVideo;
@@ -3385,7 +3477,7 @@ function openViewer(ctx, cfg, startGroupIndex, startFrameIndex = 0) {
3385
3477
  b.style.cssText = "font-size: 14px; line-height: 1.45; opacity: 0.92; text-shadow: 0 1px 6px rgba(0,0,0,0.4);";
3386
3478
  copy.appendChild(b);
3387
3479
  }
3388
- const ctaUrl = f.cta_url ? sanitizeUrl(f.cta_url) : null;
3480
+ const ctaUrl = f.cta_url ? sanitizeUrl2(f.cta_url) : null;
3389
3481
  const ctaLabel = f.cta_text || (ctaUrl ? "Learn more" : "");
3390
3482
  if (ctaLabel) {
3391
3483
  const cta = document.createElement("button");
@@ -4239,10 +4331,10 @@ function renderGame(ctx, subType) {
4239
4331
  const ASPECT$1 = { "16:9": "16 / 9", "9:16": "9 / 16", "1:1": "1 / 1", "4:5": "4 / 5" };
4240
4332
  function buildVideo(ctx, aspect, autoplay, loop) {
4241
4333
  var _a;
4242
- const { campaign, sanitizeUrl } = ctx;
4334
+ const { campaign, sanitizeUrl: sanitizeUrl2 } = ctx;
4243
4335
  const ic = campaign.interactive_config || {};
4244
- const videoUrl = sanitizeUrl(ic.video_url || campaign.video_url || "");
4245
- const poster = campaign.image_url ? sanitizeUrl(campaign.image_url) : null;
4336
+ const videoUrl = sanitizeUrl2(ic.video_url || campaign.video_url || "");
4337
+ const poster = campaign.image_url ? sanitizeUrl2(campaign.image_url) : null;
4246
4338
  const wrap = document.createElement("div");
4247
4339
  wrap.style.cssText = `position:relative;width:100%;aspect-ratio:${ASPECT$1[aspect] || ASPECT$1["16:9"]};background:#0b1220;border-radius:14px;overflow:hidden;`;
4248
4340
  if (videoUrl) {
@@ -4466,7 +4558,7 @@ function cardUrl(c) {
4466
4558
  return "";
4467
4559
  }
4468
4560
  function renderHeroInline(ctx, target) {
4469
- const { campaign, sanitizeUrl, trackEvent } = ctx;
4561
+ const { campaign, sanitizeUrl: sanitizeUrl2, trackEvent } = ctx;
4470
4562
  const ic = campaign.interactive_config || {};
4471
4563
  const cards = Array.isArray(ic.cards) ? ic.cards : [];
4472
4564
  if (cards.length === 0) return false;
@@ -4481,7 +4573,7 @@ function renderHeroInline(ctx, target) {
4481
4573
  const bar = document.createElement("div");
4482
4574
  bar.style.cssText = `display:flex;align-items:center;justify-content:center;gap:10px;background:${accent};color:#fff;padding:8px 14px;font-weight:600;font-size:13px;line-height:1.3;${fontFamilyCss("body")}text-align:center;`;
4483
4575
  bar.textContent = [cardHeadline(c), cardSub(c)].filter(Boolean).join(" · ");
4484
- const url = sanitizeUrl(cardUrl(c));
4576
+ const url = sanitizeUrl2(cardUrl(c));
4485
4577
  if (url && cardCta(c)) {
4486
4578
  const a = document.createElement("span");
4487
4579
  a.style.cssText = "text-decoration:underline;cursor:pointer;white-space:nowrap;";
@@ -4500,7 +4592,7 @@ function renderHeroInline(ctx, target) {
4500
4592
  _injectHeroResponsiveCss();
4501
4593
  const explicitRatio = chrome.aspect_ratio ? ASPECT[chrome.aspect_ratio] : void 0;
4502
4594
  const hasPhoneImage = cards.some(
4503
- (c) => !c.video_url && c.media_type !== "video" && !!c.image_url_mobile && !!sanitizeUrl(c.image_url_mobile)
4595
+ (c) => !c.video_url && c.media_type !== "video" && !!c.image_url_mobile && !!sanitizeUrl2(c.image_url_mobile)
4504
4596
  );
4505
4597
  const root = document.createElement("div");
4506
4598
  root.className = explicitRatio ? "aegis-hero-root" : `aegis-hero-root aegis-hero-auto${hasPhoneImage ? " aegis-hero-phone-square" : ""}`;
@@ -4517,9 +4609,9 @@ function renderHeroInline(ctx, target) {
4517
4609
  cards.forEach((c, i) => {
4518
4610
  const slide = document.createElement("div");
4519
4611
  slide.style.cssText = "position:relative;flex:0 0 100%;width:100%;height:100%;min-height:inherit;background:#f1f5f9;";
4520
- const videoUrl = c.video_url ? sanitizeUrl(c.video_url) ?? "" : "";
4612
+ const videoUrl = c.video_url ? sanitizeUrl2(c.video_url) ?? "" : "";
4521
4613
  const isVideo = !!videoUrl || c.media_type === "video";
4522
- const mediaUrl = isVideo ? videoUrl || sanitizeUrl(c.media_url ?? "") : sanitizeUrl(c.image_url || c.media_url || "") ?? (c.image_url_mobile ? sanitizeUrl(c.image_url_mobile) : null);
4614
+ const mediaUrl = isVideo ? videoUrl || sanitizeUrl2(c.media_url ?? "") : sanitizeUrl2(c.image_url || c.media_url || "") ?? (c.image_url_mobile ? sanitizeUrl2(c.image_url_mobile) : null);
4523
4615
  if (mediaUrl) {
4524
4616
  if (isVideo) {
4525
4617
  const v = document.createElement("video");
@@ -4532,7 +4624,7 @@ function renderHeroInline(ctx, target) {
4532
4624
  slide.appendChild(v);
4533
4625
  } else {
4534
4626
  const picture = document.createElement("picture");
4535
- const phoneUrl = c.image_url_mobile ? sanitizeUrl(c.image_url_mobile) : null;
4627
+ const phoneUrl = c.image_url_mobile ? sanitizeUrl2(c.image_url_mobile) : null;
4536
4628
  const shell = i === 0 ? adoptableShell(ctx.shellImage, mediaUrl) : null;
4537
4629
  if (phoneUrl) {
4538
4630
  const source = document.createElement("source");
@@ -4593,7 +4685,7 @@ function renderHeroInline(ctx, target) {
4593
4685
  content.appendChild(sub);
4594
4686
  }
4595
4687
  const cta = cardCta(c);
4596
- const url = sanitizeUrl(cardUrl(c));
4688
+ const url = sanitizeUrl2(cardUrl(c));
4597
4689
  if (cta && chrome.cta_style !== "none") {
4598
4690
  const btn = document.createElement("button");
4599
4691
  btn.textContent = cta;
@@ -4645,8 +4737,124 @@ function renderHeroInline(ctx, target) {
4645
4737
  trackEvent(campaign.id, "impression");
4646
4738
  return true;
4647
4739
  }
4740
+ function sanitizeUrl(url) {
4741
+ if (typeof url !== "string" || url.trim() === "") return null;
4742
+ try {
4743
+ const base = typeof window !== "undefined" ? window.location.origin : void 0;
4744
+ const parsed = base ? new URL(url, base) : new URL(url);
4745
+ const protocol = parsed.protocol.toLowerCase();
4746
+ if (protocol === "javascript:" || protocol === "data:" || protocol === "vbscript:") return null;
4747
+ return parsed.href;
4748
+ } catch {
4749
+ return null;
4750
+ }
4751
+ }
4752
+ const TAG = { "*": "strong", _: "em", "~": "s" };
4753
+ const WORD_CHAR = /[\p{L}\p{N}]/u;
4754
+ const SPACE = /\s/u;
4755
+ function isMarker(c) {
4756
+ return c === "*" || c === "_" || c === "~";
4757
+ }
4758
+ function canOpen(text, i) {
4759
+ const next = text[i + 1];
4760
+ if (next === void 0 || SPACE.test(next) || next === text[i]) return false;
4761
+ const prev = text[i - 1];
4762
+ return prev === void 0 || !WORD_CHAR.test(prev);
4763
+ }
4764
+ function canClose(text, j) {
4765
+ const prev = text[j - 1];
4766
+ if (prev === void 0 || SPACE.test(prev)) return false;
4767
+ const next = text[j + 1];
4768
+ return next === void 0 || !WORD_CHAR.test(next);
4769
+ }
4770
+ function findClose(text, i) {
4771
+ const marker = text[i];
4772
+ for (let j = i + 2; j < text.length; j += 1) {
4773
+ const c = text[j];
4774
+ if (c === "\n") return -1;
4775
+ if (c === marker && canClose(text, j)) return j;
4776
+ }
4777
+ return -1;
4778
+ }
4779
+ function parseWaMarkup(text) {
4780
+ const out = [];
4781
+ let buf = "";
4782
+ let i = 0;
4783
+ while (i < text.length) {
4784
+ const c = text[i];
4785
+ if (isMarker(c) && canOpen(text, i)) {
4786
+ const j = findClose(text, i);
4787
+ if (j !== -1) {
4788
+ if (buf) out.push(buf);
4789
+ buf = "";
4790
+ out.push({ marker: c, children: parseWaMarkup(text.slice(i + 1, j)) });
4791
+ i = j + 1;
4792
+ continue;
4793
+ }
4794
+ }
4795
+ buf += c;
4796
+ i += 1;
4797
+ }
4798
+ if (buf) out.push(buf);
4799
+ return out;
4800
+ }
4801
+ function appendNodes(parent, nodes) {
4802
+ const doc = parent.ownerDocument ?? document;
4803
+ for (const n of nodes) {
4804
+ if (typeof n === "string") {
4805
+ parent.appendChild(doc.createTextNode(n));
4806
+ } else {
4807
+ const el2 = doc.createElement(TAG[n.marker]);
4808
+ appendNodes(el2, n.children);
4809
+ parent.appendChild(el2);
4810
+ }
4811
+ }
4812
+ }
4813
+ function appendWaMarkup(parent, text) {
4814
+ appendNodes(parent, parseWaMarkup(text));
4815
+ }
4816
+ const WORKSPACE_MISMATCH_CODE = "chat_workspace_mismatch";
4817
+ const REMINT_WINDOW_MS = 3e4;
4818
+ const AUTH_STOPPED_TEXT = "Sorry, chat is unavailable right now. Please try again in a moment.";
4819
+ async function errorCode(res) {
4820
+ try {
4821
+ const body = await res.clone().json();
4822
+ for (const v of [body, body == null ? void 0 : body.detail, body == null ? void 0 : body.error]) {
4823
+ if (v && typeof v === "object" && typeof v.code === "string") {
4824
+ return v.code;
4825
+ }
4826
+ }
4827
+ } catch {
4828
+ }
4829
+ return void 0;
4830
+ }
4648
4831
  const STYLE_ID$1 = "aegis-chat-styles";
4649
4832
  const POLL_INTERVAL_MS = 5e3;
4833
+ const NEAR_BOTTOM_PX = 48;
4834
+ const MESSAGE_TOP_GAP_PX = 8;
4835
+ function chatScrollTarget(m2) {
4836
+ const bottom = Math.max(0, m2.scrollHeight - m2.viewportHeight);
4837
+ if (m2.sender === "customer") return bottom;
4838
+ if (m2.rowHeight <= m2.viewportHeight - MESSAGE_TOP_GAP_PX) return bottom;
4839
+ return Math.min(bottom, Math.max(0, m2.rowTop - MESSAGE_TOP_GAP_PX));
4840
+ }
4841
+ function ctaTarget(inter) {
4842
+ const buttons = Array.isArray(inter.buttons) ? inter.buttons : [];
4843
+ const first = buttons.find((b) => b && typeof b.url === "string" && b.url) || {};
4844
+ const action = inter.action && typeof inter.action === "object" ? inter.action : {};
4845
+ const params = action.parameters && typeof action.parameters === "object" ? action.parameters : {};
4846
+ const url = first.url ?? params.url ?? inter.url;
4847
+ const label = first.title ?? params.display_text ?? inter.display_text;
4848
+ return { url, title: typeof label === "string" ? label : "" };
4849
+ }
4850
+ function interactiveSig(msg) {
4851
+ if (!msg.interactive || !msg.interactive.length) return "";
4852
+ try {
4853
+ return JSON.stringify(msg.interactive);
4854
+ } catch {
4855
+ return String(msg.interactive.length);
4856
+ }
4857
+ }
4650
4858
  let currentLauncher = null;
4651
4859
  function getCurrentLauncher() {
4652
4860
  return currentLauncher;
@@ -4660,6 +4868,11 @@ function closeChat() {
4660
4868
  const ATTENTION_DELAY_MS = 4500;
4661
4869
  class AegisChat {
4662
4870
  constructor(config) {
4871
+ this.workspaceRejected = false;
4872
+ this.lastRemintAt = 0;
4873
+ this.authStopped = false;
4874
+ this.streamRefused = false;
4875
+ this.renderedRows = /* @__PURE__ */ new Map();
4663
4876
  this.sessionResumed = false;
4664
4877
  this.open = false;
4665
4878
  this.initialized = false;
@@ -4669,6 +4882,8 @@ class AegisChat {
4669
4882
  this.hasInteracted = false;
4670
4883
  this.writeKey = config.writeKey;
4671
4884
  this.organizationId = config.organizationId;
4885
+ const ws = typeof config.workspaceId === "string" ? config.workspaceId.trim() : "";
4886
+ this.workspaceId = ws || void 0;
4672
4887
  this.apiHost = (config.apiHost ?? "").replace(/\/$/, "");
4673
4888
  this.contactId = config.contactId;
4674
4889
  this.channel = config.channel ?? "web";
@@ -4710,6 +4925,7 @@ class AegisChat {
4710
4925
  if (this.open) return;
4711
4926
  this.open = true;
4712
4927
  this.hasInteracted = true;
4928
+ this.streamRefused = false;
4713
4929
  try {
4714
4930
  (_a = this.onSessionStart) == null ? void 0 : _a.call(this);
4715
4931
  } catch {
@@ -4717,6 +4933,8 @@ class AegisChat {
4717
4933
  this.dismissAttention();
4718
4934
  (_b = this.panel) == null ? void 0 : _b.classList.add("aegis-chat-panel--open");
4719
4935
  (_c = this.bubble) == null ? void 0 : _c.classList.add("aegis-chat-bubble--hidden");
4936
+ this.bindViewport();
4937
+ this.revealLatest();
4720
4938
  this.clearUnread();
4721
4939
  if (prefill && this.input) this.input.value = prefill;
4722
4940
  void this.resumeSession();
@@ -4729,6 +4947,7 @@ class AegisChat {
4729
4947
  this.open = false;
4730
4948
  (_a = this.panel) == null ? void 0 : _a.classList.remove("aegis-chat-panel--open");
4731
4949
  (_b = this.bubble) == null ? void 0 : _b.classList.remove("aegis-chat-bubble--hidden");
4950
+ this.unbindViewport();
4732
4951
  this.disconnectSSE();
4733
4952
  this.stopPolling();
4734
4953
  if (wasOpen) {
@@ -4740,6 +4959,7 @@ class AegisChat {
4740
4959
  }
4741
4960
  destroy() {
4742
4961
  var _a;
4962
+ this.unbindViewport();
4743
4963
  this.disconnectSSE();
4744
4964
  this.stopPolling();
4745
4965
  (_a = this.root) == null ? void 0 : _a.remove();
@@ -4767,10 +4987,11 @@ class AegisChat {
4767
4987
  }
4768
4988
  this.showTyping();
4769
4989
  try {
4770
- const res = await fetch(`${this.apiHost}/v1/chat/message`, {
4990
+ const post = () => fetch(`${this.apiHost}/v1/chat/message`, {
4771
4991
  method: "POST",
4772
4992
  headers: { "Content-Type": "application/json", "X-Aegis-Write-Key": this.writeKey },
4773
4993
  body: JSON.stringify({
4994
+ workspace_id: this.sentWorkspaceId(),
4774
4995
  message_text: message,
4775
4996
  channel: this.channel,
4776
4997
  anonymous_id: this.anonymousId,
@@ -4784,6 +5005,8 @@ class AegisChat {
4784
5005
  }),
4785
5006
  keepalive: true
4786
5007
  });
5008
+ let res = await post();
5009
+ if (await this.isWorkspaceMismatch(res)) res = await post();
4787
5010
  if (!res.ok) {
4788
5011
  this.log("send failed", res.status);
4789
5012
  this.appendSystem("Sorry — your message could not be delivered. Please try again.");
@@ -4797,6 +5020,7 @@ class AegisChat {
4797
5020
  this.contactId = data.contact_id;
4798
5021
  this.persistContactId(data.contact_id);
4799
5022
  this.sseTicket = data.sse_ticket;
5023
+ this.authStopped = false;
4800
5024
  this.connectSSE(data.sse_ticket);
4801
5025
  void this.refreshHistory();
4802
5026
  } catch (err) {
@@ -4854,11 +5078,17 @@ class AegisChat {
4854
5078
  if (!this.open) return;
4855
5079
  if (typeof EventSource === "undefined" || !this.contactId) return;
4856
5080
  if (!ticket) return;
5081
+ if (this.streamRefused) {
5082
+ this.startPolling();
5083
+ return;
5084
+ }
4857
5085
  this.disconnectSSE();
4858
5086
  const url = new URL("/v1/stream/realtime", this.apiHost || window.location.origin);
4859
5087
  url.searchParams.set("ticket", ticket);
4860
5088
  url.searchParams.set("mode", "ephemeral");
4861
5089
  if (this.organizationId) url.searchParams.set("org", this.organizationId);
5090
+ const ws = this.sentWorkspaceId();
5091
+ if (ws) url.searchParams.set("workspace_id", ws);
4862
5092
  try {
4863
5093
  this.eventSource = new EventSource(url.toString());
4864
5094
  this.eventSource.onopen = () => {
@@ -4869,6 +5099,17 @@ class AegisChat {
4869
5099
  void this.refreshHistory();
4870
5100
  });
4871
5101
  this.eventSource.onerror = () => {
5102
+ if (this.eventSource && this.eventSource.readyState === 2) {
5103
+ this.disconnectSSE();
5104
+ if (this.lastRemintAt && Date.now() - this.lastRemintAt < REMINT_WINDOW_MS) {
5105
+ this.streamRefused = true;
5106
+ this.log("SSE refused with a fresh ticket; polling");
5107
+ this.startPolling();
5108
+ return;
5109
+ }
5110
+ void this.recoverAuth();
5111
+ return;
5112
+ }
4872
5113
  this.startPolling();
4873
5114
  };
4874
5115
  } catch (err) {
@@ -4884,6 +5125,7 @@ class AegisChat {
4884
5125
  }
4885
5126
  startPolling() {
4886
5127
  if (!this.open) return;
5128
+ if (this.authStopped) return;
4887
5129
  if (this.pollTimer) return;
4888
5130
  this.pollTimer = setInterval(() => {
4889
5131
  void this.refreshHistory();
@@ -4895,7 +5137,7 @@ class AegisChat {
4895
5137
  this.pollTimer = void 0;
4896
5138
  }
4897
5139
  }
4898
- async refreshHistory() {
5140
+ async refreshHistory(retry = true) {
4899
5141
  if (!this.contactId) return;
4900
5142
  if (!this.sseTicket) return;
4901
5143
  try {
@@ -4904,15 +5146,31 @@ class AegisChat {
4904
5146
  url.searchParams.set("ticket", this.sseTicket);
4905
5147
  url.searchParams.set("channel", this.channel);
4906
5148
  url.searchParams.set("limit", "50");
5149
+ const ws = this.sentWorkspaceId();
5150
+ if (ws) url.searchParams.set("workspace_id", ws);
4907
5151
  const res = await fetch(url.toString(), {
4908
5152
  method: "GET",
4909
5153
  headers: { "X-Aegis-Write-Key": this.writeKey }
4910
5154
  });
5155
+ if (res.status === 401 || res.status === 403) {
5156
+ if (!retry) {
5157
+ this.stopAuth();
5158
+ return;
5159
+ }
5160
+ if (await this.isWorkspaceMismatch(res)) {
5161
+ await this.refreshHistory(false);
5162
+ return;
5163
+ }
5164
+ if (await this.recoverAuth({ refresh: false })) await this.refreshHistory(false);
5165
+ return;
5166
+ }
4911
5167
  if (!res.ok) return;
4912
5168
  const data = await res.json();
4913
- let appended = false;
4914
5169
  for (const msg of data.messages || []) {
4915
- if (this.renderedIds.has(msg.id)) continue;
5170
+ if (this.renderedIds.has(msg.id)) {
5171
+ this.redrawIfInteractiveChanged(msg);
5172
+ continue;
5173
+ }
4916
5174
  if (msg.sender === "customer") {
4917
5175
  const idx = this.pendingEcho.indexOf(msg.content || "");
4918
5176
  if (idx !== -1) {
@@ -4923,10 +5181,8 @@ class AegisChat {
4923
5181
  }
4924
5182
  if (msg.sender === "assistant") this.hideTyping();
4925
5183
  this.appendBubble(msg);
4926
- appended = true;
4927
5184
  if (msg.sender === "assistant" && !this.open) this.bumpUnread();
4928
5185
  }
4929
- if (appended) this.scrollToBottom();
4930
5186
  } catch (err) {
4931
5187
  this.log("history fetch error", err);
4932
5188
  }
@@ -5077,6 +5333,37 @@ class AegisChat {
5077
5333
  appendBubble(msg) {
5078
5334
  if (!this.thread) return;
5079
5335
  if (msg.id) this.renderedIds.add(msg.id);
5336
+ const row = this.buildRow(msg);
5337
+ this.thread.appendChild(row);
5338
+ if (msg.id) this.renderedRows.set(msg.id, { row, sig: interactiveSig(msg) });
5339
+ this.reveal(row, msg.sender);
5340
+ }
5341
+ /** The server attaches `interactive` to a bot row a few ms AFTER the insert
5342
+ * that nudged SSE, so the first fetch can draw the text alone. When a later
5343
+ * fetch carries a different interactive, re-draw that row IN PLACE: no
5344
+ * duplicate, scroll position kept, an answered (disabled) group stays so. */
5345
+ redrawIfInteractiveChanged(msg) {
5346
+ var _a;
5347
+ if (!msg.id || !this.thread) return;
5348
+ const drawn = this.renderedRows.get(msg.id);
5349
+ if (!drawn || !drawn.row.isConnected) return;
5350
+ const sig = interactiveSig(msg);
5351
+ if (sig === drawn.sig || !((_a = msg.interactive) == null ? void 0 : _a.length)) return;
5352
+ const answered = !!drawn.row.querySelector(
5353
+ ".aegis-chat-chip:disabled, .aegis-chat-listrow:disabled"
5354
+ );
5355
+ const top = this.thread.scrollTop;
5356
+ const row = this.buildRow(msg);
5357
+ if (answered) {
5358
+ row.querySelectorAll(".aegis-chat-chip, .aegis-chat-listrow").forEach((b) => {
5359
+ b.disabled = true;
5360
+ });
5361
+ }
5362
+ drawn.row.replaceWith(row);
5363
+ this.renderedRows.set(msg.id, { row, sig });
5364
+ this.thread.scrollTop = top;
5365
+ }
5366
+ buildRow(msg) {
5080
5367
  const row = document.createElement("div");
5081
5368
  row.className = `aegis-chat-msg aegis-chat-msg--${msg.sender}`;
5082
5369
  if (msg.media_url) {
@@ -5102,26 +5389,33 @@ class AegisChat {
5102
5389
  if (msg.content) {
5103
5390
  const bubble = document.createElement("div");
5104
5391
  bubble.className = "aegis-chat-bubbletext";
5105
- bubble.textContent = msg.content;
5392
+ if (msg.sender === "customer") bubble.textContent = msg.content;
5393
+ else appendWaMarkup(bubble, msg.content);
5106
5394
  row.appendChild(bubble);
5107
5395
  }
5108
5396
  if (msg.interactive && Array.isArray(msg.interactive)) {
5109
5397
  for (const inter of msg.interactive) {
5110
- const el2 = this.renderInteractive(inter);
5398
+ const el2 = this.renderInteractive(inter, msg.content || "");
5111
5399
  if (el2) row.appendChild(el2);
5112
5400
  }
5113
5401
  }
5114
- this.thread.appendChild(row);
5115
- this.scrollToBottom();
5402
+ return row;
5116
5403
  }
5117
5404
  /** Render one interactive message: the `web`-format product_carousel, or the
5118
- * WhatsApp-shape reply_button / list the store picker stores. */
5119
- renderInteractive(inter) {
5405
+ * WhatsApp-shape reply_button / list / cta_url the agent stores. Any other
5406
+ * shape falls back to its body text, so a message is never silently lost. */
5407
+ renderInteractive(inter, bubbleText = "") {
5120
5408
  const type = inter == null ? void 0 : inter.type;
5121
5409
  const waShape = inter == null ? void 0 : inter.interactive_type;
5122
- if (type === "interactive" && waShape === "reply_button") return this.renderReplyButtons(inter);
5123
- if (type === "interactive" && waShape === "list") return this.renderListRows(inter);
5124
- if (type !== "product_carousel") return null;
5410
+ if (type === "interactive" && waShape === "reply_button") {
5411
+ return this.withBody(inter, bubbleText, this.renderReplyButtons(inter));
5412
+ }
5413
+ if (type === "interactive" && waShape === "list") {
5414
+ return this.withBody(inter, bubbleText, this.renderListRows(inter));
5415
+ }
5416
+ if (waShape === "cta_url" || type === "cta_url") return this.renderCtaUrl(inter, bubbleText);
5417
+ if (waShape === "flow" || type === "flow") return this.renderFlowFallback(inter, bubbleText);
5418
+ if (type !== "product_carousel") return this.renderBodyFallback(inter, bubbleText);
5125
5419
  const products = inter.products || [];
5126
5420
  if (!products.length) return null;
5127
5421
  const carousel = document.createElement("div");
@@ -5164,6 +5458,99 @@ class AegisChat {
5164
5458
  }
5165
5459
  return carousel;
5166
5460
  }
5461
+ /** WhatsApp-shape `cta_url` (link_buttons.link_message / pay offers): the body
5462
+ * (when the bubble does not already say it), an optional header image (the
5463
+ * UPI QR) and ONE link button. The URL goes through sanitizeUrl and opens in
5464
+ * a new tab with rel=noopener; an unsafe or missing URL leaves the body only. */
5465
+ renderCtaUrl(inter, bubbleText) {
5466
+ const { url, title: rawTitle } = ctaTarget(inter);
5467
+ const href = sanitizeUrl(url);
5468
+ const title = rawTitle.trim();
5469
+ if (!href || !title) return this.renderBodyFallback(inter, bubbleText);
5470
+ const group = document.createElement("div");
5471
+ group.className = "aegis-chat-cta";
5472
+ const image = sanitizeUrl(inter.header_image);
5473
+ if (image && /^https?:/i.test(image)) {
5474
+ const img = document.createElement("img");
5475
+ img.className = "aegis-chat-cta-img";
5476
+ img.src = image;
5477
+ img.alt = "";
5478
+ img.loading = "lazy";
5479
+ group.appendChild(img);
5480
+ }
5481
+ const body = this.distinctBody(inter, bubbleText);
5482
+ if (body) {
5483
+ const text = document.createElement("div");
5484
+ text.className = "aegis-chat-bubbletext";
5485
+ appendWaMarkup(text, body);
5486
+ group.appendChild(text);
5487
+ }
5488
+ const link = document.createElement("a");
5489
+ link.className = "aegis-chat-ctabtn";
5490
+ link.href = href;
5491
+ link.target = "_blank";
5492
+ link.rel = "noopener noreferrer";
5493
+ link.textContent = title;
5494
+ group.appendChild(link);
5495
+ return group;
5496
+ }
5497
+ /** A Flow's `native_fallback` is one ordinary message (reply_button / list /
5498
+ * text) or `{text, messages[]}`; it is drawn by the same renderer, never as
5499
+ * another Flow (one level only). */
5500
+ renderFlowFallback(inter, bubbleText) {
5501
+ const fb = inter.native_fallback;
5502
+ if (!fb || typeof fb !== "object") return this.renderBodyFallback(inter, bubbleText);
5503
+ const f = fb;
5504
+ const parts = [];
5505
+ const isFlow = (m2) => m2.interactive_type === "flow" || m2.type === "flow";
5506
+ if (typeof f.type === "string" || typeof f.interactive_type === "string") {
5507
+ const el2 = isFlow(f) ? this.renderBodyFallback(f, bubbleText) : this.renderInteractive(f, bubbleText);
5508
+ if (el2) parts.push(el2);
5509
+ } else {
5510
+ const text = this.renderBodyFallback({ body: f.text }, bubbleText);
5511
+ if (text) parts.push(text);
5512
+ const messages = Array.isArray(f.messages) ? f.messages : [];
5513
+ for (const m2 of messages) {
5514
+ if (!m2 || typeof m2 !== "object") continue;
5515
+ const el2 = isFlow(m2) ? this.renderBodyFallback(m2, bubbleText) : this.renderInteractive(m2, bubbleText);
5516
+ if (el2) parts.push(el2);
5517
+ }
5518
+ }
5519
+ if (!parts.length) return this.renderBodyFallback(inter, bubbleText);
5520
+ if (parts.length === 1) return parts[0];
5521
+ const wrap = document.createElement("div");
5522
+ wrap.className = "aegis-chat-interactive";
5523
+ for (const el2 of parts) wrap.appendChild(el2);
5524
+ return wrap;
5525
+ }
5526
+ /** reply_button / list: the choices, preceded by the message body when the
5527
+ * bubble text does not already carry it (WA markup rendered). */
5528
+ withBody(inter, bubbleText, choices) {
5529
+ const body = this.renderBodyFallback(inter, bubbleText);
5530
+ if (!body) return choices ?? null;
5531
+ if (!choices) return body;
5532
+ const wrap = document.createElement("div");
5533
+ wrap.className = "aegis-chat-interactive";
5534
+ wrap.appendChild(body);
5535
+ wrap.appendChild(choices);
5536
+ return wrap;
5537
+ }
5538
+ /** An interactive shape this launcher does not draw: show its body text (if
5539
+ * the bubble does not already carry it) instead of dropping it silently. */
5540
+ renderBodyFallback(inter, bubbleText) {
5541
+ const body = this.distinctBody(inter, bubbleText);
5542
+ if (!body) return null;
5543
+ const text = document.createElement("div");
5544
+ text.className = "aegis-chat-bubbletext aegis-chat-fallback";
5545
+ appendWaMarkup(text, body);
5546
+ return text;
5547
+ }
5548
+ distinctBody(inter, bubbleText) {
5549
+ const raw = typeof inter.body === "string" ? inter.body : typeof inter.text === "string" ? inter.text : "";
5550
+ const body = raw.trim();
5551
+ if (!body || body === bubbleText.trim() || bubbleText.includes(body)) return "";
5552
+ return body;
5553
+ }
5167
5554
  /** WhatsApp-shape `reply_button` (store picker: Nearest / Other stores / Change
5168
5555
  * store). The body is already the bubble text, so only the buttons render. A
5169
5556
  * tap sends the button title (the same text WhatsApp's inbound hands the bot)
@@ -5244,6 +5631,62 @@ class AegisChat {
5244
5631
  scrollToBottom() {
5245
5632
  if (this.thread) this.thread.scrollTop = this.thread.scrollHeight;
5246
5633
  }
5634
+ isNearBottom() {
5635
+ const t = this.thread;
5636
+ if (!t) return true;
5637
+ return t.scrollHeight - t.scrollTop - t.clientHeight <= NEAR_BOTTOM_PX;
5638
+ }
5639
+ /** Place the view for a just-appended message (rule: chatScrollTarget). */
5640
+ reveal(row, sender) {
5641
+ const t = this.thread;
5642
+ if (!t) return;
5643
+ t.scrollTop = chatScrollTarget({
5644
+ sender,
5645
+ rowTop: row.offsetTop,
5646
+ rowHeight: row.offsetHeight,
5647
+ viewportHeight: t.clientHeight,
5648
+ scrollHeight: t.scrollHeight
5649
+ });
5650
+ }
5651
+ revealLatest() {
5652
+ var _a;
5653
+ const rows = (_a = this.thread) == null ? void 0 : _a.querySelectorAll(".aegis-chat-msg:not(.aegis-chat-typing)");
5654
+ const last = rows && rows.length ? rows[rows.length - 1] : void 0;
5655
+ if (!last) return;
5656
+ const sender = last.classList.contains("aegis-chat-msg--customer") ? "customer" : last.classList.contains("aegis-chat-msg--system") ? "system" : "assistant";
5657
+ this.reveal(last, sender);
5658
+ }
5659
+ /** Phones: size the open panel to the VISUAL viewport. `100dvh` does not
5660
+ * shrink for the soft keyboard, so the browser scrolled the full-height panel
5661
+ * and pushed the header (title + close) off the top. The panel's height and
5662
+ * top follow visualViewport while open; without it the CSS keeps 100dvh. */
5663
+ bindViewport() {
5664
+ const vv = typeof window !== "undefined" ? window.visualViewport : null;
5665
+ const panel = this.panel;
5666
+ if (!vv || !panel || this.viewportCleanup) return;
5667
+ const apply = () => {
5668
+ const stick = this.isNearBottom();
5669
+ panel.style.setProperty("--aegis-chat-vh", `${Math.round(vv.height)}px`);
5670
+ panel.style.setProperty("--aegis-chat-top", `${Math.round(vv.offsetTop)}px`);
5671
+ if (stick) this.scrollToBottom();
5672
+ };
5673
+ panel.classList.add("aegis-chat-panel--vv");
5674
+ apply();
5675
+ vv.addEventListener("resize", apply);
5676
+ vv.addEventListener("scroll", apply);
5677
+ this.viewportCleanup = () => {
5678
+ vv.removeEventListener("resize", apply);
5679
+ vv.removeEventListener("scroll", apply);
5680
+ panel.classList.remove("aegis-chat-panel--vv");
5681
+ panel.style.removeProperty("--aegis-chat-vh");
5682
+ panel.style.removeProperty("--aegis-chat-top");
5683
+ };
5684
+ }
5685
+ unbindViewport() {
5686
+ var _a;
5687
+ (_a = this.viewportCleanup) == null ? void 0 : _a.call(this);
5688
+ this.viewportCleanup = void 0;
5689
+ }
5247
5690
  readAnonId() {
5248
5691
  if (typeof document === "undefined") return void 0;
5249
5692
  try {
@@ -5277,38 +5720,91 @@ class AegisChat {
5277
5720
  }
5278
5721
  if (this.sessionResumed) return;
5279
5722
  this.sessionResumed = true;
5280
- if (!this.contactId && !this.anonymousId) return;
5723
+ await this.mintSession();
5724
+ }
5725
+ /** POST /v1/chat/session: resolve the contact and mint a ticket (no message
5726
+ * sent). Loads history and connects SSE when `refresh`. True when a ticket
5727
+ * was minted. A workspace mismatch retries once without the workspace. */
5728
+ async mintSession({ refresh = true } = {}) {
5729
+ if (!this.contactId && !this.anonymousId) return false;
5281
5730
  try {
5282
- const res = await fetch(`${this.apiHost}/v1/chat/session`, {
5731
+ const post = () => fetch(`${this.apiHost}/v1/chat/session`, {
5283
5732
  method: "POST",
5284
5733
  headers: { "Content-Type": "application/json", "X-Aegis-Write-Key": this.writeKey },
5285
5734
  body: JSON.stringify({
5735
+ workspace_id: this.sentWorkspaceId(),
5286
5736
  anonymous_id: this.anonymousId,
5287
5737
  contact_id: this.contactId,
5288
5738
  channel: this.channel
5289
5739
  })
5290
5740
  });
5291
- if (!res.ok) return;
5741
+ let res = await post();
5742
+ if (await this.isWorkspaceMismatch(res)) res = await post();
5743
+ if (!res.ok) return false;
5292
5744
  const data = await res.json();
5293
- if (!data.contact_id || !data.sse_ticket) return;
5745
+ if (!data.contact_id || !data.sse_ticket) return false;
5294
5746
  this.contactId = data.contact_id;
5295
5747
  this.sseTicket = data.sse_ticket;
5296
5748
  this.persistContactId(data.contact_id);
5297
- await this.refreshHistory();
5749
+ if (refresh) await this.refreshHistory();
5298
5750
  if (this.open) this.connectSSE(data.sse_ticket);
5751
+ return true;
5299
5752
  } catch (err) {
5300
- this.log("resume session failed", err);
5753
+ this.log("session mint failed", err);
5754
+ return false;
5755
+ }
5756
+ }
5757
+ // ── Workspace + auth recovery ─────────────────────────────────────────────
5758
+ /** The workspace_id to send: the configured one until the server refused it. */
5759
+ sentWorkspaceId() {
5760
+ return this.workspaceRejected ? void 0 : this.workspaceId;
5761
+ }
5762
+ /** True (once) when `res` is the server refusing our workspace_id: the
5763
+ * launcher drops it for the rest of the page-load and warns once. */
5764
+ async isWorkspaceMismatch(res) {
5765
+ if (res.status !== 403 || !this.sentWorkspaceId()) return false;
5766
+ if (await errorCode(res) !== WORKSPACE_MISMATCH_CODE) return false;
5767
+ this.workspaceRejected = true;
5768
+ console.warn(
5769
+ `[AegisChat] workspace_id "${this.workspaceId}" does not belong to this write key's property; continuing without it (the server uses the key's property).`
5770
+ );
5771
+ return true;
5772
+ }
5773
+ /** An old/expired ticket (401/403 other than a workspace mismatch): drop it
5774
+ * and mint a new one, at most once per REMINT_WINDOW_MS. A failure inside the
5775
+ * window (or a failed mint) stops the transport and shows the error line. */
5776
+ async recoverAuth({ refresh = true } = {}) {
5777
+ if (this.authStopped) return false;
5778
+ const now = Date.now();
5779
+ if (this.lastRemintAt && now - this.lastRemintAt < REMINT_WINDOW_MS) {
5780
+ this.stopAuth();
5781
+ return false;
5301
5782
  }
5783
+ this.lastRemintAt = now;
5784
+ this.sseTicket = void 0;
5785
+ this.disconnectSSE();
5786
+ const ok = await this.mintSession({ refresh });
5787
+ if (!ok) this.stopAuth();
5788
+ return ok;
5789
+ }
5790
+ stopAuth() {
5791
+ if (this.authStopped) return;
5792
+ this.authStopped = true;
5793
+ this.stopPolling();
5794
+ this.disconnectSSE();
5795
+ this.hideTyping();
5796
+ this.appendSystem(AUTH_STOPPED_TEXT);
5302
5797
  }
5303
5798
  // ── Typing indicator ───────────────────────────────────────────────────────
5304
5799
  showTyping() {
5305
5800
  if (!this.thread || this.typingEl) return;
5801
+ const follow = this.isNearBottom();
5306
5802
  const row = document.createElement("div");
5307
5803
  row.className = "aegis-chat-msg aegis-chat-msg--assistant aegis-chat-typing";
5308
5804
  row.innerHTML = '<div class="aegis-chat-bubbletext aegis-chat-typingdots"><span></span><span></span><span></span></div>';
5309
5805
  this.thread.appendChild(row);
5310
5806
  this.typingEl = row;
5311
- this.scrollToBottom();
5807
+ if (follow) this.scrollToBottom();
5312
5808
  }
5313
5809
  hideTyping() {
5314
5810
  if (this.typingEl) {
@@ -5371,11 +5867,11 @@ const CHAT_CSS = `
5371
5867
  .aegis-chat-panel--open{display:flex}
5372
5868
  /* Header + customer bubbles use the "fill" surface — accent solid by default, or
5373
5869
  a soft tint when surfaceStyle:'tinted' sets --aegis-chat-fill/-fg on the root. */
5374
- .aegis-chat-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;background:var(--aegis-chat-fill,var(--aegis-chat-accent,#4169e1));color:var(--aegis-chat-fill-fg,#fff)}
5870
+ .aegis-chat-header{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;padding:14px 16px;background:var(--aegis-chat-fill,var(--aegis-chat-accent,#4169e1));color:var(--aegis-chat-fill-fg,#fff)}
5375
5871
  .aegis-chat-title{font-weight:600;font-size:15px}
5376
5872
  .aegis-chat-close{background:transparent;border:none;color:var(--aegis-chat-fill-fg,#fff);font-size:16px;cursor:pointer;opacity:.85}
5377
5873
  .aegis-chat-close:hover{opacity:1}
5378
- .aegis-chat-thread{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:10px;background:#f8fafc}
5874
+ .aegis-chat-thread{position:relative;flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px;display:flex;flex-direction:column;gap:10px;background:#f8fafc}
5379
5875
  .aegis-chat-msg{display:flex;flex-direction:column;max-width:85%}
5380
5876
  .aegis-chat-msg--customer{align-self:flex-end;align-items:flex-end}
5381
5877
  .aegis-chat-msg--assistant,.aegis-chat-msg--system{align-self:flex-start;align-items:flex-start}
@@ -5403,13 +5899,20 @@ const CHAT_CSS = `
5403
5899
  .aegis-chat-card-name{font-size:13px;font-weight:500;line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
5404
5900
  .aegis-chat-card-price{font-size:13px;font-weight:600;color:var(--aegis-chat-accent,#4169e1)}
5405
5901
  .aegis-chat-card--more{align-items:center;justify-content:center;font-weight:600;color:var(--aegis-chat-accent,#4169e1)}
5406
- .aegis-chat-composer{display:flex;align-items:flex-end;gap:8px;padding:12px;border-top:1px solid #e2e8f0;background:#fff}
5902
+ .aegis-chat-composer{flex:0 0 auto;display:flex;align-items:flex-end;gap:8px;padding:12px;border-top:1px solid #e2e8f0;background:#fff}
5407
5903
  .aegis-chat-input{flex:1;resize:none;border:1px solid #e2e8f0;border-radius:12px;padding:9px 12px;font-size:14px;font-family:inherit;max-height:96px;outline:none}
5408
5904
  .aegis-chat-input:focus{border-color:var(--aegis-chat-accent,#4169e1)}
5409
5905
  .aegis-chat-send{width:40px;height:40px;border-radius:9999px;border:none;background:var(--aegis-chat-accent,#4169e1);color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;flex:0 0 auto}
5410
5906
  .aegis-chat-attach{width:38px;height:38px;border-radius:9999px;border:none;background:transparent;color:#64748b;display:flex;align-items:center;justify-content:center;cursor:pointer;flex:0 0 auto;transition:background .15s ease,color .15s ease}
5411
5907
  .aegis-chat-attach:hover{background:#f1f5f9;color:var(--aegis-chat-accent,#4169e1)}
5412
5908
  .aegis-chat-fileinput{display:none}
5909
+ .aegis-chat-interactive{display:flex;flex-direction:column;align-items:flex-start;gap:6px}
5910
+ .aegis-chat-cta{display:flex;flex-direction:column;align-items:flex-start;gap:6px;padding:4px 0;max-width:320px}
5911
+ .aegis-chat-cta-img{max-width:200px;border-radius:12px;display:block}
5912
+ .aegis-chat-ctabtn{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:8px 16px;border-radius:9999px;background:var(--aegis-chat-accent,#4169e1);color:#fff;font-size:14px;font-weight:600;text-decoration:none}
5913
+ .aegis-chat-ctabtn:hover{filter:brightness(1.05)}
5914
+ .aegis-chat-ctabtn:focus-visible{outline:2px solid var(--aegis-chat-accent,#4169e1);outline-offset:2px}
5915
+ .aegis-chat-msg--assistant .aegis-chat-fallback,.aegis-chat-cta .aegis-chat-bubbletext{background:#fff;color:#0f172a;border:1px solid #e2e8f0}
5413
5916
  .aegis-chat-media-img{max-width:200px;max-height:200px;border-radius:12px;object-fit:cover;cursor:pointer;display:block}
5414
5917
  .aegis-chat-media-file{display:inline-flex;align-items:center;gap:6px;padding:8px 12px;border-radius:12px;background:#fff;border:1px solid #e2e8f0;font-size:13px;color:#0f172a;text-decoration:none;max-width:220px}
5415
5918
  .aegis-chat-msg--customer .aegis-chat-media-file{background:rgba(255,255,255,.18);border-color:transparent;color:#fff}
@@ -5420,6 +5923,9 @@ const CHAT_CSS = `
5420
5923
  /* Full-page chat on mobile — the open panel covers the whole viewport (incl.
5421
5924
  the bottom nav) like a native chat screen, instead of a floating card. */
5422
5925
  .aegis-chat-panel{position:fixed;inset:0;left:0;right:0;width:100vw;height:100vh;height:100dvh;max-width:none;max-height:none;border-radius:0}
5926
+ /* Keyboard open: follow the visual viewport (bindViewport) so the header and
5927
+ composer stay on screen. Without visualViewport the 100dvh rule stands. */
5928
+ .aegis-chat-panel.aegis-chat-panel--vv{top:var(--aegis-chat-top,0px);bottom:auto;height:var(--aegis-chat-vh,100dvh)}
5423
5929
  .aegis-chat-tip{max-width:200px}
5424
5930
  }
5425
5931
  `;
@@ -6007,6 +6513,8 @@ function renderActiveWebChat(ctx, creds) {
6007
6513
  writeKey: creds.writeKey,
6008
6514
  apiHost: creds.apiHost,
6009
6515
  contactId: creds.contactId,
6516
+ // The brand this runtime is scoped to; chat history is per brand.
6517
+ workspaceId: ctx.workspaceId,
6010
6518
  channel: creds.channel ?? "web",
6011
6519
  title: str(ic.chat_title),
6012
6520
  greeting: str(ic.chat_greeting),
@@ -7318,6 +7826,14 @@ function productIdentitiesFor(campaign) {
7318
7826
  productIdentityCache.set(cards, encoded);
7319
7827
  return encoded || void 0;
7320
7828
  }
7829
+ function setPaneActive(pane, active) {
7830
+ var _a;
7831
+ pane.style.visibility = active ? "visible" : "hidden";
7832
+ pane.setAttribute("data-aegis-rotate-active", active ? "true" : "false");
7833
+ pane.setAttribute("aria-hidden", active ? "false" : "true");
7834
+ if (active) (_a = pane.removeAttribute) == null ? void 0 : _a.call(pane, "inert");
7835
+ else pane.setAttribute("inert", "");
7836
+ }
7321
7837
  const _AegisInAppManager = class _AegisInAppManager {
7322
7838
  constructor(config) {
7323
7839
  this.productUrl = productPath;
@@ -8198,7 +8714,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8198
8714
  this.slotTimers.delete(slot);
8199
8715
  }
8200
8716
  slot.querySelectorAll(
8201
- ":scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
8717
+ ":scope > [data-aegis-rotate-stack], :scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
8202
8718
  ).forEach((n) => n.remove());
8203
8719
  }
8204
8720
  // Re-fill slots that mount after a poll (SPA route changes). Observes the DOM
@@ -8362,14 +8878,26 @@ const _AegisInAppManager = class _AegisInAppManager {
8362
8878
  * while off-screen; only the visibility toggles every `rotateMs`. The impression
8363
8879
  * is deferred at render and fired per campaign on FIRST visibility, so hidden
8364
8880
  * panes never over-count. One rendered pane → no rotation (just shows it).
8881
+ *
8882
+ * Stable height (1.46.2): with >1 pane every pane sits in the SAME grid cell
8883
+ * of an SDK-owned wrapper (`data-aegis-rotate-stack`, panes + dots row), so
8884
+ * the HOST element's own display (`hidden md:block`, flex, …) is never
8885
+ * touched. The inactive ones are `visibility:hidden` + `aria-hidden` + `inert`
8886
+ * (not `display:none`), so the slot is always as tall as its tallest pane. A
8887
+ * one-line value bar rotating with a two-line card no longer grows and shrinks
8888
+ * the slot (and the page around it) on every turn. The visible pane carries
8889
+ * `data-aegis-rotate-active="true"`, the others `"false"`.
8365
8890
  */
8366
8891
  renderRotatingSlot(slot, campaigns, rotateMs, flush = false) {
8367
8892
  const panes = [];
8368
8893
  for (const c of campaigns) {
8369
8894
  const pane = document.createElement("div");
8370
8895
  pane.setAttribute("data-aegis-rotate-pane", c.id);
8371
- pane.style.display = "none";
8896
+ pane.style.gridArea = "1 / 1";
8897
+ pane.style.minWidth = "0";
8898
+ pane.style.alignSelf = "center";
8372
8899
  slot.appendChild(pane);
8900
+ setPaneActive(pane, false);
8373
8901
  this.renderCampaignIntoSlot(c, pane, { deferImpression: true });
8374
8902
  if (pane.childElementCount > 0) {
8375
8903
  if (flush) this._flattenSlotCard(pane);
@@ -8377,6 +8905,17 @@ const _AegisInAppManager = class _AegisInAppManager {
8377
8905
  } else pane.remove();
8378
8906
  }
8379
8907
  if (panes.length === 0) return;
8908
+ let stack = slot;
8909
+ if (panes.length > 1) {
8910
+ stack = document.createElement("div");
8911
+ stack.setAttribute("data-aegis-rotate-stack", "");
8912
+ stack.style.display = "grid";
8913
+ stack.style.gridTemplateColumns = "minmax(0, 1fr)";
8914
+ stack.style.width = "100%";
8915
+ stack.style.minWidth = "0";
8916
+ for (const p of panes) stack.appendChild(p.el);
8917
+ slot.appendChild(stack);
8918
+ }
8380
8919
  const impressed = /* @__PURE__ */ new Set();
8381
8920
  const markVisible = (c) => {
8382
8921
  if (impressed.has(c.id)) return;
@@ -8399,8 +8938,11 @@ const _AegisInAppManager = class _AegisInAppManager {
8399
8938
  return false;
8400
8939
  };
8401
8940
  const darkDots = panes.length > 0 && panes.every((p) => isDarkSurface(p.campaign));
8402
- const dotInactive = darkDots ? "rgba(255,255,255,0.4)" : "rgba(15,23,42,0.2)";
8403
- const dotActive = darkDots ? "#ffffff" : "var(--aegis-brand-accent, #4169e1)";
8941
+ const compactSlot = slotVariant(slot) === "compact";
8942
+ const dotInactiveBase = darkDots ? "rgba(255,255,255,0.4)" : "rgba(15,23,42,0.2)";
8943
+ const dotActiveBase = darkDots ? "#ffffff" : "var(--aegis-brand-accent, #4169e1)";
8944
+ const dotInactive = compactSlot ? `var(--aegis-card-muted, ${dotInactiveBase})` : dotInactiveBase;
8945
+ const dotActive = compactSlot ? `var(--aegis-card-fg, ${dotActiveBase})` : dotActiveBase;
8404
8946
  const dots = [];
8405
8947
  if (panes.length > 1) {
8406
8948
  const bar = document.createElement("div");
@@ -8421,7 +8963,8 @@ const _AegisInAppManager = class _AegisInAppManager {
8421
8963
  dots.push(dot);
8422
8964
  bar.appendChild(dot);
8423
8965
  });
8424
- slot.appendChild(bar);
8966
+ bar.style.gridArea = "2 / 1";
8967
+ stack.appendChild(bar);
8425
8968
  }
8426
8969
  const paintDots = () => {
8427
8970
  dots.forEach((d, i) => {
@@ -8440,9 +8983,9 @@ const _AegisInAppManager = class _AegisInAppManager {
8440
8983
  return t;
8441
8984
  };
8442
8985
  function show(i, fromClick = false) {
8443
- panes[idx].el.style.display = "none";
8986
+ setPaneActive(panes[idx].el, false);
8444
8987
  idx = (i % panes.length + panes.length) % panes.length;
8445
- panes[idx].el.style.display = "";
8988
+ setPaneActive(panes[idx].el, true);
8446
8989
  markVisible(panes[idx].campaign);
8447
8990
  paintDots();
8448
8991
  if (fromClick && timer) {
@@ -8450,7 +8993,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8450
8993
  timer = start();
8451
8994
  }
8452
8995
  }
8453
- panes[0].el.style.display = "";
8996
+ setPaneActive(panes[0].el, true);
8454
8997
  markVisible(panes[0].campaign);
8455
8998
  paintDots();
8456
8999
  if (panes.length === 1) return;
@@ -13154,18 +13697,11 @@ const _AegisInAppManager = class _AegisInAppManager {
13154
13697
  document.head.appendChild(style);
13155
13698
  }
13156
13699
  sanitizeUrl(url) {
13157
- if (typeof url !== "string" || url.trim() === "") return null;
13158
- try {
13159
- const parsedUrl = new URL(url, window.location.origin);
13160
- if (parsedUrl.protocol === "javascript:" || parsedUrl.protocol === "data:") {
13161
- this.log(`Blocked unsafe URL: ${url}`, "error");
13162
- return null;
13163
- }
13164
- return parsedUrl.href;
13165
- } catch (error) {
13166
- this.log(`Invalid URL: ${url}`, "error");
13167
- return null;
13700
+ const safe = sanitizeUrl(url);
13701
+ if (safe === null && typeof url === "string" && url.trim() !== "") {
13702
+ this.log(`Blocked unsafe or invalid URL: ${url}`, "error");
13168
13703
  }
13704
+ return safe;
13169
13705
  }
13170
13706
  sanitizeColor(color) {
13171
13707
  if (/^#[0-9A-Fa-f]{3,6}$/.test(color)) {
@@ -16033,11 +16569,11 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
16033
16569
  // updateContext). The renderer cart reader + the cart_value signal are DERIVED
16034
16570
  // from it; there is no parallel cart/context store on the runtime.
16035
16571
  constructor(config) {
16036
- var _a;
16572
+ var _a, _b, _c;
16037
16573
  this.initialized = false;
16038
16574
  this.armedInAppTriggers = /* @__PURE__ */ new Set();
16039
16575
  {
16040
- const v = "1.46.1";
16576
+ const v = "1.46.3";
16041
16577
  try {
16042
16578
  globalThis.__AEGIS_SDK_VERSION__ = v;
16043
16579
  } catch {
@@ -16135,9 +16671,12 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
16135
16671
  organizationId: config.organizationId,
16136
16672
  contactId: config.contactId,
16137
16673
  debugMode: config.debugMode,
16138
- ...config.chat
16674
+ ...config.chat,
16675
+ // The brand the chat talks for: the host's explicit value, else the
16676
+ // runtime's effective workspace (the same one in-app reads send).
16677
+ workspaceId: ((_a = config.chat) == null ? void 0 : _a.workspaceId) ?? ((_b = config.getWorkspaceId) == null ? void 0 : _b.call(config))
16139
16678
  });
16140
- const proactive = (((_a = config.chat) == null ? void 0 : _a.proactiveTriggers) ?? []).map(triggerFromEngineEvent);
16679
+ const proactive = (((_c = config.chat) == null ? void 0 : _c.proactiveTriggers) ?? []).map(triggerFromEngineEvent);
16141
16680
  armBehaviouralTriggers(
16142
16681
  triggerEngine,
16143
16682
  proactive,
@@ -16512,9 +17051,12 @@ export {
16512
17051
  A as AegisWebPush,
16513
17052
  B as BloomFilter,
16514
17053
  BootstrapError,
17054
+ DEFAULT_RAIL_TITLES,
16515
17055
  E as EcommerceTracker,
16516
17056
  N as NameGovernor,
16517
17057
  PrefetchBundleClient,
17058
+ RAIL_REASONS_WEAKEST_FIRST,
17059
+ RESERVED_BOUGHT_TOGETHER_HEADINGS,
16518
17060
  R as RateLimiter,
16519
17061
  SdkConfigPoller,
16520
17062
  TriggerEngine,
@@ -16527,12 +17069,14 @@ export {
16527
17069
  deriveDeviceFingerprint,
16528
17070
  fallbackUrlForAction,
16529
17071
  getCurrentLauncher,
17072
+ isReplaceableRailTitle,
16530
17073
  mountScratchSurface,
16531
17074
  m as murmurhash3_x86_32,
16532
17075
  openChat,
16533
17076
  parseAction,
16534
17077
  readFirstPartyCookie,
16535
17078
  renderPreview,
17079
+ resolveRailHeading,
16536
17080
  scratchFoilPalette,
16537
17081
  throttle,
16538
17082
  writeFirstPartyCookie