@aikaara/chat-sdk 0.9.3 → 0.9.5

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.
@@ -454,9 +454,7 @@ function Il(c, e, t = 15e3) {
454
454
  if (!i && !s && !o) return null;
455
455
  const l = new Date(e.createdAt).getTime();
456
456
  for (let u = c.length - 1; u >= 0; u--) {
457
- const d = c[u];
458
- if (d.role !== e.role) continue;
459
- const p = d.attachments && d.attachments[0], y = (d.metadata ?? {}).attributes;
457
+ const d = c[u], p = d.attachments && d.attachments[0], y = (d.metadata ?? {}).attributes;
460
458
  if (!(!!p || !!(y && y.fileMessage)) || Math.abs(l - new Date(d.createdAt).getTime()) > t) continue;
461
459
  const g = fo(d);
462
460
  if (i && g && i === g) return d;
@@ -12456,7 +12454,18 @@ function ll(c) {
12456
12454
  ll(t);
12457
12455
  }
12458
12456
  }
12459
- class lh extends HTMLElement {
12457
+ function lh(c) {
12458
+ const e = Date.now() - c.getTime(), t = Math.round(e / 1e3);
12459
+ if (t < 5) return "just now";
12460
+ if (t < 60) return `${t}s ago`;
12461
+ const r = Math.round(t / 60);
12462
+ if (r < 60) return `${r} min ago`;
12463
+ const a = Math.round(r / 60);
12464
+ if (a < 24) return `${a} hr ago`;
12465
+ const n = Math.round(a / 24);
12466
+ return n === 1 ? "Yesterday" : n < 7 ? `${n} d ago` : c.toLocaleDateString(void 0, { month: "short", day: "2-digit" });
12467
+ }
12468
+ class ch extends HTMLElement {
12460
12469
  shadow;
12461
12470
  container;
12462
12471
  welcomeMessage = "";
@@ -12783,12 +12792,22 @@ class lh extends HTMLElement {
12783
12792
  }
12784
12793
  formatTime(e) {
12785
12794
  try {
12786
- const t = new Date(e);
12795
+ const t = new Date(e), r = t.toLocaleDateString(void 0, { month: "short", day: "2-digit" });
12787
12796
  switch (this.timestampFormat) {
12788
12797
  case "datetime":
12789
- return `${t.toLocaleDateString(void 0, { month: "short", day: "2-digit" })}, ${t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" })}`;
12798
+ return `${r}, ${t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" })}`;
12799
+ case "datetime-seconds":
12800
+ return `${r}, ${t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", second: "2-digit" })}`;
12801
+ case "datetime-24":
12802
+ return `${r}, ${t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", hour12: !1 })}`;
12790
12803
  case "date":
12791
- return t.toLocaleDateString(void 0, { month: "short", day: "2-digit" });
12804
+ return r;
12805
+ case "relative":
12806
+ return lh(t);
12807
+ case "time-24":
12808
+ return t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", hour12: !1 });
12809
+ case "time-seconds":
12810
+ return t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", second: "2-digit" });
12792
12811
  case "none":
12793
12812
  return "";
12794
12813
  default:
@@ -12804,7 +12823,7 @@ class lh extends HTMLElement {
12804
12823
  * data, or opens in a new tab depending on the matched handler.
12805
12824
  */
12806
12825
  async handleLinkClick(e, t) {
12807
- const r = this.linkHandlers.find((y) => ch(e, y.match)), a = r?.target ?? "iframe";
12826
+ const r = this.linkHandlers.find((y) => uh(e, y.match)), a = r?.target ?? "iframe";
12808
12827
  if (a === "tab") {
12809
12828
  window.open(e, "_blank", "noopener,noreferrer");
12810
12829
  return;
@@ -12814,7 +12833,7 @@ class lh extends HTMLElement {
12814
12833
  requestAnimationFrame(() => n.show?.(e, i));
12815
12834
  return;
12816
12835
  }
12817
- const s = uh(e), o = cl(r.fetch.url, s), l = {
12836
+ const s = hh(e), o = cl(r.fetch.url, s), l = {
12818
12837
  accept: "application/json",
12819
12838
  ...r.fetch.headers ?? {}
12820
12839
  }, u = r.fetch.authHeader ?? "session";
@@ -12860,11 +12879,11 @@ class lh extends HTMLElement {
12860
12879
  return e || (e = document.createElement("aikaara-link-modal"), document.body.appendChild(e)), e;
12861
12880
  }
12862
12881
  }
12863
- function ch(c, e) {
12882
+ function uh(c, e) {
12864
12883
  const t = e.replace(/[.+^${}()|[\]\\]/g, "\\$&");
12865
12884
  return new RegExp("^" + t.replace(/\*/g, ".*").replace(/\?/g, ".") + "$", "i").test(c);
12866
12885
  }
12867
- function uh(c) {
12886
+ function hh(c) {
12868
12887
  try {
12869
12888
  const e = new URL(c), t = {};
12870
12889
  return e.searchParams.forEach((r, a) => {
@@ -12887,7 +12906,7 @@ function zi(c, e) {
12887
12906
  }
12888
12907
  return c;
12889
12908
  }
12890
- class hh extends HTMLElement {
12909
+ class fh extends HTMLElement {
12891
12910
  shadow;
12892
12911
  templatePayload = null;
12893
12912
  attachments = [];
@@ -13003,7 +13022,7 @@ class hh extends HTMLElement {
13003
13022
  renderAttachments() {
13004
13023
  return this.attachments.length ? `<div class="attachments">${this.attachments.map(
13005
13024
  (t) => `<a class="attachment" href="${xs(t.fileUrl)}" target="_blank" rel="noopener noreferrer">
13006
- 📎 ${fh(t.fileName)}
13025
+ 📎 ${dh(t.fileName)}
13007
13026
  </a>`
13008
13027
  ).join("")}</div>` : "";
13009
13028
  }
@@ -13011,10 +13030,10 @@ class hh extends HTMLElement {
13011
13030
  function xs(c) {
13012
13031
  return String(c).replace(/[&<>"']/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[e]);
13013
13032
  }
13014
- function fh(c) {
13033
+ function dh(c) {
13015
13034
  return String(c).replace(/[&<>]/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[e]);
13016
13035
  }
13017
- class dh extends HTMLElement {
13036
+ class ph extends HTMLElement {
13018
13037
  shadow;
13019
13038
  textarea;
13020
13039
  sendBtn;
@@ -13165,7 +13184,7 @@ class dh extends HTMLElement {
13165
13184
  this.textarea.style.height = "auto", this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
13166
13185
  }
13167
13186
  }
13168
- class ph extends HTMLElement {
13187
+ class gh extends HTMLElement {
13169
13188
  shadow;
13170
13189
  constructor() {
13171
13190
  super(), this.shadow = this.attachShadow({ mode: "open" });
@@ -13214,7 +13233,7 @@ class ph extends HTMLElement {
13214
13233
  this.removeAttribute("visible");
13215
13234
  }
13216
13235
  }
13217
- class gh extends HTMLElement {
13236
+ class mh extends HTMLElement {
13218
13237
  shadow;
13219
13238
  bubble;
13220
13239
  constructor() {
@@ -13279,7 +13298,7 @@ class gh extends HTMLElement {
13279
13298
  this.bubble?.classList.remove("cursor");
13280
13299
  }
13281
13300
  }
13282
- class mh extends HTMLElement {
13301
+ class bh extends HTMLElement {
13283
13302
  shadow;
13284
13303
  container;
13285
13304
  dismissTimer = null;
@@ -13352,7 +13371,7 @@ function ul(c) {
13352
13371
  });
13353
13372
  return qr.set(c, t), t;
13354
13373
  }
13355
- function bh(c, e = 5e3) {
13374
+ function yh(c, e = 5e3) {
13356
13375
  return new Promise((t, r) => {
13357
13376
  const a = setTimeout(() => r(new Error(`Custom element <${c}> not registered within ${e}ms`)), e);
13358
13377
  customElements.whenDefined(c).then(() => {
@@ -13360,11 +13379,11 @@ function bh(c, e = 5e3) {
13360
13379
  });
13361
13380
  });
13362
13381
  }
13363
- function yh(c) {
13382
+ function vh(c) {
13364
13383
  const e = `template:${c}`, t = window.__aikaara_descriptor__?.components?.[e];
13365
13384
  return t && t.kind === "iife-element" ? { render: t.tag, scriptUrl: t.scriptUrl, props: t.props } : window.__aikaara_descriptor__?.templates?.[c];
13366
13385
  }
13367
- class vh extends HTMLElement {
13386
+ class wh extends HTMLElement {
13368
13387
  shadow;
13369
13388
  payloadData = null;
13370
13389
  innerMessage = "";
@@ -13403,8 +13422,8 @@ class vh extends HTMLElement {
13403
13422
  <slot></slot>
13404
13423
  `; this.firstChild; ) this.removeChild(this.firstChild);
13405
13424
  if (!e) return;
13406
- const r = t ? yh(t) : void 0, a = r?.render ?? (t ? `aikaara-template-${t}` : `aikaara-template-${e}`);
13407
- if (r?.scriptUrl && !customElements.get(a) && ul(r.scriptUrl).then(() => bh(a)).then(() => this.render()).catch((n) => console.warn(`[aikaara-template-renderer] failed to lazy-load ${r.scriptUrl}`, n)), customElements.get(a)) {
13425
+ const r = t ? vh(t) : void 0, a = r?.render ?? (t ? `aikaara-template-${t}` : `aikaara-template-${e}`);
13426
+ if (r?.scriptUrl && !customElements.get(a) && ul(r.scriptUrl).then(() => yh(a)).then(() => this.render()).catch((n) => console.warn(`[aikaara-template-renderer] failed to lazy-load ${r.scriptUrl}`, n)), customElements.get(a)) {
13408
13427
  const n = document.createElement(a);
13409
13428
  if (r?.props) {
13410
13429
  for (const [i, s] of Object.entries(r.props))
@@ -13494,7 +13513,7 @@ class vh extends HTMLElement {
13494
13513
  url: e.url ?? "",
13495
13514
  openLinkInNewTab: e.openLinkInNewTab,
13496
13515
  orderId: e.orderId,
13497
- extra: _h(e),
13516
+ extra: kh(e),
13498
13517
  messageId: this.getAttribute("message-id") ?? void 0
13499
13518
  }), this.appendChild(n);
13500
13519
  });
@@ -13504,20 +13523,20 @@ class vh extends HTMLElement {
13504
13523
  t.setPayload(e), this.appendChild(t);
13505
13524
  }
13506
13525
  }
13507
- const wh = /* @__PURE__ */ new Set([
13526
+ const _h = /* @__PURE__ */ new Set([
13508
13527
  "type",
13509
13528
  "url",
13510
13529
  "name",
13511
13530
  "openLinkInNewTab",
13512
13531
  "orderId"
13513
13532
  ]);
13514
- function _h(c) {
13533
+ function kh(c) {
13515
13534
  const e = {};
13516
13535
  for (const [t, r] of Object.entries(c))
13517
- wh.has(t) || (e[t] = r);
13536
+ _h.has(t) || (e[t] = r);
13518
13537
  return e;
13519
13538
  }
13520
- class kh extends HTMLElement {
13539
+ class Sh extends HTMLElement {
13521
13540
  shadow;
13522
13541
  static get observedAttributes() {
13523
13542
  return ["text", "subtext"];
@@ -13566,7 +13585,7 @@ class kh extends HTMLElement {
13566
13585
  function As(c) {
13567
13586
  return String(c).replace(/[&<>]/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[e]);
13568
13587
  }
13569
- class Sh extends HTMLElement {
13588
+ class Eh extends HTMLElement {
13570
13589
  shadow;
13571
13590
  data = null;
13572
13591
  selected = /* @__PURE__ */ new Set();
@@ -13717,7 +13736,7 @@ function rr(c) {
13717
13736
  function Is(c) {
13718
13737
  return String(c).replace(/[&<>"']/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[e]);
13719
13738
  }
13720
- class Eh extends HTMLElement {
13739
+ class xh extends HTMLElement {
13721
13740
  shadow;
13722
13741
  data = null;
13723
13742
  constructor() {
@@ -13777,14 +13796,14 @@ class Eh extends HTMLElement {
13777
13796
  button:hover { background: var(--aikaara-submit-hover-bg, var(--aikaara-primary-hover, #4f46e5)); }
13778
13797
  button:disabled { opacity: var(--aikaara-submit-disabled-opacity, 0.5); cursor: not-allowed; }
13779
13798
  </style>
13780
- <button type="button">${xh(e)}</button>
13799
+ <button type="button">${Ah(e)}</button>
13781
13800
  `, this.shadow.querySelector("button").addEventListener("click", () => this.handleClick());
13782
13801
  }
13783
13802
  }
13784
- function xh(c) {
13803
+ function Ah(c) {
13785
13804
  return String(c).replace(/[&<>]/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[e]);
13786
13805
  }
13787
- class Ah extends HTMLElement {
13806
+ class Ih extends HTMLElement {
13788
13807
  shadow;
13789
13808
  data = null;
13790
13809
  dismissed = !1;
@@ -13876,7 +13895,7 @@ class Ah extends HTMLElement {
13876
13895
  function Hr(c) {
13877
13896
  return String(c).replace(/[&<>]/g, (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[e]);
13878
13897
  }
13879
- class Ih extends HTMLElement {
13898
+ class Th extends HTMLElement {
13880
13899
  static get observedAttributes() {
13881
13900
  return ["slug", "user-id", "user-name", "user-token", "department-id", "config-base", "api-key"];
13882
13901
  }
@@ -13930,7 +13949,7 @@ class Ih extends HTMLElement {
13930
13949
  const o = Object.keys(n).length > 0 ? n : void 0;
13931
13950
  return this.mountInflight = (async () => {
13932
13951
  try {
13933
- this.mounted = await cf({
13952
+ this.mounted = await uf({
13934
13953
  container: this,
13935
13954
  slug: e,
13936
13955
  configBase: this.getAttribute("config-base") ?? void 0,
@@ -13959,7 +13978,7 @@ class Ih extends HTMLElement {
13959
13978
  })(), this.mountInflight;
13960
13979
  }
13961
13980
  }
13962
- class Th extends HTMLElement {
13981
+ class Ch extends HTMLElement {
13963
13982
  shadow;
13964
13983
  root = null;
13965
13984
  iframe = null;
@@ -14076,7 +14095,7 @@ class Th extends HTMLElement {
14076
14095
  });
14077
14096
  }
14078
14097
  }
14079
- const Ch = [
14098
+ const Oh = [
14080
14099
  { label: "Self-filing guidance" },
14081
14100
  { label: "Smart tax suggestions" },
14082
14101
  { label: "Auto-fetch 26AS / AIS" },
@@ -14084,7 +14103,7 @@ const Ch = [
14084
14103
  { label: "Dedicated tax expert" },
14085
14104
  { label: "End-to-end filing" },
14086
14105
  { label: "Document handling" }
14087
- ], Oh = [
14106
+ ], Ph = [
14088
14107
  {
14089
14108
  label: "DIY",
14090
14109
  match: ["DIY", "DIY_SALARY"],
@@ -14107,11 +14126,11 @@ const Ch = [
14107
14126
  features: [!0, !0, !0, !0, !0, !0, !0]
14108
14127
  }
14109
14128
  ];
14110
- class Ph extends HTMLElement {
14129
+ class Mh extends HTMLElement {
14111
14130
  shadow;
14112
14131
  data = null;
14113
- columns = Oh;
14114
- features = Ch;
14132
+ columns = Ph;
14133
+ features = Oh;
14115
14134
  constructor() {
14116
14135
  super(), this.shadow = this.attachShadow({ mode: "open" });
14117
14136
  }
@@ -14244,30 +14263,30 @@ function zr(c) {
14244
14263
  (e) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[e]
14245
14264
  );
14246
14265
  }
14247
- function Mh() {
14266
+ function Rh() {
14248
14267
  const c = [
14249
14268
  ["aikaara-chat-widget", th],
14250
14269
  ["aikaara-chat-bubble", rh],
14251
14270
  ["aikaara-chat-header", nh],
14252
- ["aikaara-message-list", lh],
14253
- ["aikaara-message-bubble", hh],
14254
- ["aikaara-chat-input", dh],
14255
- ["aikaara-typing-indicator", ph],
14256
- ["aikaara-streaming-message", gh],
14257
- ["aikaara-error-banner", mh],
14258
- ["aikaara-template-renderer", vh],
14259
- ["aikaara-system-pill", kh],
14260
- ["aikaara-option-list", Sh],
14261
- ["aikaara-submit-action", Eh],
14262
- ["aikaara-modal-action", Ah],
14263
- ["aikaara-chat", Ih],
14264
- ["aikaara-link-modal", Th],
14265
- ["aikaara-compare-plans", Ph]
14271
+ ["aikaara-message-list", ch],
14272
+ ["aikaara-message-bubble", fh],
14273
+ ["aikaara-chat-input", ph],
14274
+ ["aikaara-typing-indicator", gh],
14275
+ ["aikaara-streaming-message", mh],
14276
+ ["aikaara-error-banner", bh],
14277
+ ["aikaara-template-renderer", wh],
14278
+ ["aikaara-system-pill", Sh],
14279
+ ["aikaara-option-list", Eh],
14280
+ ["aikaara-submit-action", xh],
14281
+ ["aikaara-modal-action", Ih],
14282
+ ["aikaara-chat", Th],
14283
+ ["aikaara-link-modal", Ch],
14284
+ ["aikaara-compare-plans", Mh]
14266
14285
  ];
14267
14286
  for (const [e, t] of c)
14268
14287
  customElements.get(e) || customElements.define(e, t);
14269
14288
  }
14270
- Mh();
14289
+ Rh();
14271
14290
  function Kr(c, e, t = "") {
14272
14291
  if (!e) return t;
14273
14292
  const r = e.split(".");
@@ -14278,7 +14297,7 @@ function Kr(c, e, t = "") {
14278
14297
  else return t;
14279
14298
  return typeof a == "string" ? a : t;
14280
14299
  }
14281
- function Rh(c) {
14300
+ function jh(c) {
14282
14301
  try {
14283
14302
  const e = c.split(".")[1];
14284
14303
  if (!e) return 0;
@@ -14293,7 +14312,7 @@ function Rh(c) {
14293
14312
  async function Pr(c) {
14294
14313
  return typeof c == "function" ? await c() : c;
14295
14314
  }
14296
- class jh {
14315
+ class Lh {
14297
14316
  constructor(e, t) {
14298
14317
  this.descriptor = e, this.sessionToken = t;
14299
14318
  }
@@ -14325,14 +14344,14 @@ class jh {
14325
14344
  if (!d) throw new Error("Session auth response missing token");
14326
14345
  const p = Kr(o, this.descriptor.requestIdPath ?? "data.requestId"), y = this.cache?.requestId || p;
14327
14346
  if (!y) throw new Error("Session auth response missing requestId");
14328
- const f = Kr(o, this.descriptor.fullNamePath ?? "data.fullName"), g = Rh(d) || Date.now() + 3600 * 1e3;
14347
+ const f = Kr(o, this.descriptor.fullNamePath ?? "data.fullName"), g = jh(d) || Date.now() + 3600 * 1e3;
14329
14348
  return this.cache = { token: d, requestId: y, fullName: f, expiresAt: g }, this.cache;
14330
14349
  }
14331
14350
  }
14332
- async function Lh(c) {
14351
+ async function Nh(c) {
14333
14352
  const e = {};
14334
14353
  for (const t of c.spec) {
14335
- const r = await Nh(t, c.providers);
14354
+ const r = await Uh(t, c.providers);
14336
14355
  if (r !== void 0 && r !== "")
14337
14356
  e[t.name] = r;
14338
14357
  else {
@@ -14345,11 +14364,11 @@ async function Lh(c) {
14345
14364
  }
14346
14365
  return e;
14347
14366
  }
14348
- async function Nh(c, e) {
14367
+ async function Uh(c, e) {
14349
14368
  const t = c.key ?? c.name;
14350
14369
  switch (c.source) {
14351
14370
  case "cookie":
14352
- return Uh(t);
14371
+ return Bh(t);
14353
14372
  case "localStorage":
14354
14373
  return nr(() => window.localStorage.getItem(t) ?? void 0);
14355
14374
  case "sessionStorage":
@@ -14357,7 +14376,7 @@ async function Nh(c, e) {
14357
14376
  case "url_param":
14358
14377
  return nr(() => new URL(window.location.href).searchParams.get(t) ?? void 0);
14359
14378
  case "header_meta":
14360
- return nr(() => document.querySelector(`meta[name="${Bh(t)}"]`)?.content ?? void 0);
14379
+ return nr(() => document.querySelector(`meta[name="${Fh(t)}"]`)?.content ?? void 0);
14361
14380
  case "callback": {
14362
14381
  const r = e?.[c.name];
14363
14382
  if (!r) return;
@@ -14368,7 +14387,7 @@ async function Nh(c, e) {
14368
14387
  return;
14369
14388
  }
14370
14389
  }
14371
- function Uh(c) {
14390
+ function Bh(c) {
14372
14391
  if (typeof document > "u") return;
14373
14392
  const e = encodeURIComponent(c), t = document.cookie ? document.cookie.split("; ") : [];
14374
14393
  for (const r of t) {
@@ -14390,11 +14409,11 @@ function nr(c) {
14390
14409
  return;
14391
14410
  }
14392
14411
  }
14393
- function Bh(c) {
14412
+ function Fh(c) {
14394
14413
  return c.replace(/["\\]/g, "\\$&");
14395
14414
  }
14396
- const Fh = 1800;
14397
- class Dh {
14415
+ const Dh = 1800;
14416
+ class $h {
14398
14417
  constructor(e) {
14399
14418
  this.opts = e, this.cache = this.loadCache();
14400
14419
  }
@@ -14423,7 +14442,7 @@ class Dh {
14423
14442
  throw new Error(
14424
14443
  "[aikaara-chat-sdk] SsoExchangeAdapter.exchange() requires descriptor.sso.collect; v2 partner-token flow should be handled by TokenDiscoveryReader instead."
14425
14444
  );
14426
- const e = await Lh({
14445
+ const e = await Nh({
14427
14446
  spec: this.opts.descriptor.collect,
14428
14447
  providers: this.opts.providers
14429
14448
  }), t = JSON.stringify({ credentials: e }), r = {
@@ -14461,7 +14480,7 @@ class Dh {
14461
14480
  return this.cache = u, this.persistCache(u), u;
14462
14481
  }
14463
14482
  computeExpiry() {
14464
- const e = this.opts.descriptor.cacheTtlSec ?? Fh;
14483
+ const e = this.opts.descriptor.cacheTtlSec ?? Dh;
14465
14484
  if (!(!this.opts.descriptor.cacheKey || e <= 0))
14466
14485
  return Date.now() + e * 1e3;
14467
14486
  }
@@ -14494,8 +14513,8 @@ class Dh {
14494
14513
  }
14495
14514
  }
14496
14515
  }
14497
- const $h = 3e4, Wh = 2e3, qh = 100;
14498
- async function Hh(c) {
14516
+ const Wh = 3e4, qh = 2e3, Hh = 100;
14517
+ async function zh(c) {
14499
14518
  const { descriptor: e } = c, t = e.tokenSourceConfig ?? {};
14500
14519
  switch (e.tokenSource) {
14501
14520
  case "init": {
@@ -14504,37 +14523,37 @@ async function Hh(c) {
14504
14523
  return { token: c.initToken, source: "init" };
14505
14524
  }
14506
14525
  case "query": {
14507
- const r = typeof t.key == "string" && t.key ? t.key : "token", a = Kh(r);
14526
+ const r = typeof t.key == "string" && t.key ? t.key : "token", a = Vh(r);
14508
14527
  if (!a) throw new Ke("query", `?${r}= not present`);
14509
14528
  return { token: a, source: "query" };
14510
14529
  }
14511
14530
  case "hash": {
14512
- const r = typeof t.key == "string" && t.key ? t.key : "token", a = Vh(r);
14531
+ const r = typeof t.key == "string" && t.key ? t.key : "token", a = Gh(r);
14513
14532
  if (!a) throw new Ke("hash", `#${r}= not present`);
14514
14533
  return { token: a, source: "hash" };
14515
14534
  }
14516
14535
  case "postmsg": {
14517
- const r = typeof t.type == "string" ? t.type : "", a = typeof t.key == "string" && t.key ? t.key : "token", n = Xh(typeof t.origins == "string" ? t.origins : ""), i = typeof t.timeoutMs == "number" && t.timeoutMs > 0 ? t.timeoutMs : $h;
14518
- return { token: await Jh({ type: r, key: a, origins: n, timeoutMs: i }), source: "postmsg" };
14536
+ const r = typeof t.type == "string" ? t.type : "", a = typeof t.key == "string" && t.key ? t.key : "token", n = Zh(typeof t.origins == "string" ? t.origins : ""), i = typeof t.timeoutMs == "number" && t.timeoutMs > 0 ? t.timeoutMs : Wh;
14537
+ return { token: await Xh({ type: r, key: a, origins: n, timeoutMs: i }), source: "postmsg" };
14519
14538
  }
14520
14539
  case "cookie": {
14521
14540
  const r = typeof t.name == "string" && t.name ? t.name : "";
14522
14541
  if (!r) throw new Ke("cookie", "cookie.name not configured");
14523
- const a = Gh(r);
14542
+ const a = Yh(r);
14524
14543
  if (!a) throw new Ke("cookie", `cookie "${r}" not set`);
14525
14544
  return { token: a, source: "cookie" };
14526
14545
  }
14527
14546
  case "storage": {
14528
14547
  const r = t.store === "session" ? "session" : "local", a = typeof t.key == "string" && t.key ? t.key : "", n = typeof t.path == "string" ? t.path : "";
14529
14548
  if (!a) throw new Ke("storage", "storage.key not configured");
14530
- const i = Yh(r, a, n);
14549
+ const i = Qh(r, a, n);
14531
14550
  if (!i) throw new Ke("storage", `${r}Storage["${a}"] not set`);
14532
14551
  return { token: i, source: "storage" };
14533
14552
  }
14534
14553
  case "global": {
14535
14554
  const r = typeof t.path == "string" ? t.path : "";
14536
14555
  if (!r) throw new Ke("global", "global.path not configured");
14537
- const a = typeof t.timeoutMs == "number" && t.timeoutMs > 0 ? t.timeoutMs : Wh, n = typeof t.intervalMs == "number" && t.intervalMs > 0 ? t.intervalMs : qh, i = await Qh(r, a, n);
14556
+ const a = typeof t.timeoutMs == "number" && t.timeoutMs > 0 ? t.timeoutMs : qh, n = typeof t.intervalMs == "number" && t.intervalMs > 0 ? t.intervalMs : Hh, i = await Jh(r, a, n);
14538
14557
  if (!i) throw new Ke("global", `window.${r} not present`);
14539
14558
  return { token: i, source: "global" };
14540
14559
  }
@@ -14547,7 +14566,7 @@ async function Hh(c) {
14547
14566
  }
14548
14567
  }
14549
14568
  }
14550
- class zh {
14569
+ class Kh {
14551
14570
  constructor(e) {
14552
14571
  this.opts = e;
14553
14572
  }
@@ -14558,7 +14577,7 @@ class zh {
14558
14577
  /** Resolve the token. Returns cache if present. */
14559
14578
  async get() {
14560
14579
  if (this.cached) return this.cached;
14561
- const e = await Hh(this.opts);
14580
+ const e = await zh(this.opts);
14562
14581
  return this.cached = e, e;
14563
14582
  }
14564
14583
  /**
@@ -14575,7 +14594,7 @@ class Ke extends Error {
14575
14594
  super(`[aikaara-chat-sdk] token-discovery (${e}): ${t}`), this.source = e, this.name = "TokenDiscoveryError";
14576
14595
  }
14577
14596
  }
14578
- function Kh(c) {
14597
+ function Vh(c) {
14579
14598
  if (!(typeof window > "u"))
14580
14599
  try {
14581
14600
  return new URL(window.location.href).searchParams.get(c) ?? void 0;
@@ -14583,7 +14602,7 @@ function Kh(c) {
14583
14602
  return;
14584
14603
  }
14585
14604
  }
14586
- function Vh(c) {
14605
+ function Gh(c) {
14587
14606
  if (!(typeof window > "u"))
14588
14607
  try {
14589
14608
  const e = window.location.hash.replace(/^#/, "");
@@ -14592,7 +14611,7 @@ function Vh(c) {
14592
14611
  return;
14593
14612
  }
14594
14613
  }
14595
- function Gh(c) {
14614
+ function Yh(c) {
14596
14615
  if (typeof document > "u") return;
14597
14616
  const e = encodeURIComponent(c), t = document.cookie ? document.cookie.split("; ") : [];
14598
14617
  for (const r of t) {
@@ -14607,7 +14626,7 @@ function Gh(c) {
14607
14626
  }
14608
14627
  }
14609
14628
  }
14610
- function Yh(c, e, t) {
14629
+ function Qh(c, e, t) {
14611
14630
  if (!(typeof window > "u"))
14612
14631
  try {
14613
14632
  const a = (c === "session" ? window.sessionStorage : window.localStorage).getItem(e);
@@ -14625,7 +14644,7 @@ function Yh(c, e, t) {
14625
14644
  return;
14626
14645
  }
14627
14646
  }
14628
- async function Qh(c, e, t) {
14647
+ async function Jh(c, e, t) {
14629
14648
  if (typeof window > "u") return;
14630
14649
  const r = Date.now() + e;
14631
14650
  for (; Date.now() < r; ) {
@@ -14640,7 +14659,7 @@ async function Qh(c, e, t) {
14640
14659
  await new Promise((n) => setTimeout(n, t));
14641
14660
  }
14642
14661
  }
14643
- function Jh(c) {
14662
+ function Xh(c) {
14644
14663
  return new Promise((e, t) => {
14645
14664
  if (typeof window > "u") {
14646
14665
  t(new Ke("postmsg", "no window"));
@@ -14662,7 +14681,7 @@ function Jh(c) {
14662
14681
  window.addEventListener("message", n);
14663
14682
  });
14664
14683
  }
14665
- function Xh(c) {
14684
+ function Zh(c) {
14666
14685
  return c ? c.split(/[,\s]+/).map((e) => e.trim()).filter(Boolean) : [];
14667
14686
  }
14668
14687
  function hl(c, e) {
@@ -14676,7 +14695,7 @@ function hl(c, e) {
14676
14695
  return;
14677
14696
  return r;
14678
14697
  }
14679
- function Zh() {
14698
+ function ef() {
14680
14699
  const c = typeof crypto < "u" ? crypto : null;
14681
14700
  if (c?.randomUUID) return c.randomUUID();
14682
14701
  if (c?.getRandomValues) {
@@ -14690,30 +14709,30 @@ function Zh() {
14690
14709
  return (e === "x" ? t : t & 3 | 8).toString(16);
14691
14710
  });
14692
14711
  }
14693
- const ef = "aikaara_chat:requestId";
14712
+ const tf = "aikaara_chat:requestId";
14694
14713
  function so(c, e) {
14695
- return `${ef}:${c}:${e}`;
14714
+ return `${tf}:${c}:${e}`;
14696
14715
  }
14697
- function tf(c, e) {
14716
+ function rf(c, e) {
14698
14717
  try {
14699
14718
  return localStorage.getItem(so(c, e));
14700
14719
  } catch {
14701
14720
  return null;
14702
14721
  }
14703
14722
  }
14704
- function rf(c, e, t) {
14723
+ function nf(c, e, t) {
14705
14724
  try {
14706
14725
  localStorage.setItem(so(c, e), t);
14707
14726
  } catch {
14708
14727
  }
14709
14728
  }
14710
- function uf(c, e) {
14729
+ function hf(c, e) {
14711
14730
  try {
14712
14731
  localStorage.removeItem(so(c, e));
14713
14732
  } catch {
14714
14733
  }
14715
14734
  }
14716
- async function nf(c, e) {
14735
+ async function of(c, e) {
14717
14736
  console.log("[aikaara-chat-sdk] preflight running", c.length, "steps");
14718
14737
  const t = {
14719
14738
  userId: e.userId,
@@ -14746,7 +14765,7 @@ async function nf(c, e) {
14746
14765
  try {
14747
14766
  const b = await fetch(l, p);
14748
14767
  if (b.ok) break;
14749
- if (y = b.status, f = await b.text().catch(() => ""), g < i.length && of(y, f)) {
14768
+ if (y = b.status, f = await b.text().catch(() => ""), g < i.length && sf(y, f)) {
14750
14769
  const m = i[g++];
14751
14770
  console.warn(
14752
14771
  `[aikaara-chat-sdk] preflight #${s} ${u} ${l} → ${y} (transient). Retry #${g} in ${m}ms.`
@@ -14776,7 +14795,7 @@ async function nf(c, e) {
14776
14795
  }
14777
14796
  }
14778
14797
  }
14779
- function of(c, e) {
14798
+ function sf(c, e) {
14780
14799
  if (c === 503 || c === 504 || c === 502) return !0;
14781
14800
  if (c === 401 || c === 403) return e.trim().length === 0;
14782
14801
  if (c === 500) {
@@ -14801,8 +14820,8 @@ async function fl(c, e) {
14801
14820
  }
14802
14821
  return r;
14803
14822
  }
14804
- function sf(c, e) {
14805
- return c.replace("{projectId}", e).replace("{uuid}", Zh().replace(/-/g, ""));
14823
+ function af(c, e) {
14824
+ return c.replace("{projectId}", e).replace("{uuid}", ef().replace(/-/g, ""));
14806
14825
  }
14807
14826
  function dl(c) {
14808
14827
  const e = c._preload;
@@ -14814,7 +14833,7 @@ function dl(c) {
14814
14833
  );
14815
14834
  t.length !== 0 && Promise.allSettled(t.map((r) => ul(r)));
14816
14835
  }
14817
- async function af(c) {
14836
+ async function lf(c) {
14818
14837
  const e = {
14819
14838
  ...c.config ?? (c.configUrl ? await fl(c.configUrl, c.configHeaders) : {}),
14820
14839
  ...c.overrides ?? {}
@@ -14823,8 +14842,8 @@ async function af(c) {
14823
14842
  const t = e.transport ?? "tiledesk", r = e.tiledesk;
14824
14843
  if ((t === "tiledesk" || t === "dual") && !r)
14825
14844
  throw new Error("mount: descriptor.tiledesk is required for tiledesk/dual transport");
14826
- const a = r?.projectId ?? "", n = c.identity.userId, i = c.forceNewConversation ? null : tf(n, a), s = r?.requestIdTemplate ?? "support-group-{projectId}-{uuid}", o = c.conversationId ?? i ?? sf(s, a);
14827
- (!i || c.forceNewConversation) && a && rf(n, a, o);
14845
+ const a = r?.projectId ?? "", n = c.identity.userId, i = c.forceNewConversation ? null : rf(n, a), s = r?.requestIdTemplate ?? "support-group-{projectId}-{uuid}", o = c.conversationId ?? i ?? af(s, a);
14846
+ (!i || c.forceNewConversation) && a && nf(n, a, o);
14828
14847
  const l = await c.tokenProvider(), u = c.tokenProvider, d = c.historyTokenProvider ?? u, p = r ? {
14829
14848
  mqttEndpoint: r.mqttEndpoint,
14830
14849
  jwtToken: l,
@@ -14911,13 +14930,13 @@ async function af(c) {
14911
14930
  }
14912
14931
  };
14913
14932
  }
14914
- function lf(c) {
14933
+ function cf(c) {
14915
14934
  if (typeof c != "string") return c;
14916
14935
  const e = document.querySelector(c);
14917
14936
  if (!e) throw new Error(`mountFromSlug: container "${c}" not found`);
14918
14937
  return e;
14919
14938
  }
14920
- async function cf(c) {
14939
+ async function uf(c) {
14921
14940
  const e = (c.configBase ?? "https://api.aikaara.com").replace(/\/$/, ""), t = `${e}/api/v1/widget_configs/${encodeURIComponent(c.slug)}`;
14922
14941
  let r = null;
14923
14942
  try {
@@ -14957,7 +14976,7 @@ async function cf(c) {
14957
14976
  );
14958
14977
  let n = null, i = c.user.id, s = c.user.name, o = "", l = c.user.token, u = null;
14959
14978
  if (a.sso?.tokenSource) {
14960
- u = new zh({
14979
+ u = new Kh({
14961
14980
  descriptor: {
14962
14981
  provider: a.sso.provider,
14963
14982
  flow: a.sso.flow,
@@ -14974,20 +14993,20 @@ async function cf(c) {
14974
14993
  l = async () => (await u.get()).token, c.user.identity && !c.user.identity.partnerToken && (c.user.identity.partnerToken = w.token);
14975
14994
  } else if (a.sso && a.sso.collect && a.sso.collect.length > 0) {
14976
14995
  const w = `${e}/api/v1/projects/by-slug/${encodeURIComponent(c.slug)}/sso_exchange`;
14977
- n = await new Dh({
14996
+ n = await new $h({
14978
14997
  descriptor: a.sso,
14979
14998
  providers: c.user.credentialProviders,
14980
14999
  exchangeUrl: w
14981
15000
  }).get(), i = n.extUid || i, s = s ?? n.displayName, o = n.userToken;
14982
15001
  }
14983
- a.preflight && a.preflight.length && await nf(a.preflight, {
15002
+ a.preflight && a.preflight.length && await of(a.preflight, {
14984
15003
  sessionToken: l,
14985
15004
  userId: i,
14986
15005
  projectId: a.tiledesk?.projectId ?? "",
14987
15006
  slug: c.slug,
14988
15007
  identity: c.user.identity
14989
15008
  });
14990
- const d = new jh(a.auth, l), p = await d.get(), y = p.fullName || s || i;
15009
+ const d = new Lh(a.auth, l), p = await d.get(), y = p.fullName || s || i;
14991
15010
  window.__aikaara_runtime__ = {
14992
15011
  getChatJwt: async () => (await d.get()).token,
14993
15012
  identity: c.user.identity,
@@ -15007,8 +15026,8 @@ async function cf(c) {
15007
15026
  fieldName: g.fieldName,
15008
15027
  extraFields: g.extraFields,
15009
15028
  headers: async () => ({ authorization: await b() })
15010
- }) : void 0), m = await af({
15011
- container: lf(c.container),
15029
+ }) : void 0), m = await lf({
15030
+ container: cf(c.container),
15012
15031
  config: a,
15013
15032
  // SSO-issued Aikaara user token, used by the ActionCable transport.
15014
15033
  // Tiledesk-only widgets ignore this; falls back to `userId` inside `mount`.
@@ -15042,45 +15061,45 @@ async function cf(c) {
15042
15061
  }
15043
15062
  export {
15044
15063
  ao as A,
15045
- cf as B,
15064
+ uf as B,
15046
15065
  pl as C,
15047
- af as D,
15066
+ lf as D,
15048
15067
  Ts as E,
15049
15068
  sl as F,
15050
- Ih as G,
15051
- Ph as H,
15052
- Th as I,
15053
- Ah as J,
15054
- Sh as K,
15055
- Eh as L,
15069
+ Th as G,
15070
+ Mh as H,
15071
+ Ch as I,
15072
+ Ih as J,
15073
+ Eh as K,
15074
+ xh as L,
15056
15075
  Al as M,
15057
- kh as N,
15058
- vh as O,
15059
- jh as S,
15076
+ Sh as N,
15077
+ wh as O,
15078
+ Lh as S,
15060
15079
  $u as T,
15061
15080
  rh as a,
15062
15081
  Vu as b,
15063
15082
  nh as c,
15064
- dh as d,
15083
+ ph as d,
15065
15084
  th as e,
15066
- mh as f,
15067
- hh as g,
15068
- lh as h,
15069
- gh as i,
15070
- ph as j,
15085
+ bh as f,
15086
+ fh as g,
15087
+ ch as h,
15088
+ mh as i,
15089
+ gh as j,
15071
15090
  xl as k,
15072
15091
  El as l,
15073
15092
  Tl as m,
15074
- Dh as n,
15093
+ $h as n,
15075
15094
  Ke as o,
15076
- zh as p,
15077
- uf as q,
15078
- Mh as r,
15079
- Lh as s,
15095
+ Kh as p,
15096
+ hf as q,
15097
+ Rh as r,
15098
+ Nh as s,
15080
15099
  al as t,
15081
15100
  Ju as u,
15082
15101
  Zu as v,
15083
- Hh as w,
15102
+ zh as w,
15084
15103
  zu as x,
15085
15104
  Hu as y,
15086
15105
  qu as z