@gengage/assistant-fe 0.6.9 → 0.6.11

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.
@@ -4,7 +4,7 @@ function it(t) {
4
4
  function at(t) {
5
5
  return !!t && typeof t == "object" && t.type === "rpc.req";
6
6
  }
7
- function ae(t = self) {
7
+ function se(t = self) {
8
8
  let e = 1;
9
9
  const n = /* @__PURE__ */ new Map();
10
10
  return t.addEventListener("message", (r) => {
@@ -34,7 +34,7 @@ function ae(t = self) {
34
34
  });
35
35
  };
36
36
  }
37
- function se({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
37
+ function ce({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
38
38
  t.addEventListener("message", (o) => {
39
39
  const i = o.data;
40
40
  at(i) && st(t, i, {
@@ -155,7 +155,7 @@ function Q(t, e) {
155
155
  function h(t) {
156
156
  return typeof t == "object" && t !== null && !Array.isArray(t);
157
157
  }
158
- var ce = class {
158
+ var ue = class {
159
159
  #t = /* @__PURE__ */ new Map();
160
160
  #e;
161
161
  #r;
@@ -389,7 +389,7 @@ function Tt(t, e) {
389
389
  detail: n.detail
390
390
  });
391
391
  }
392
- function ue(t) {
392
+ function le(t) {
393
393
  return t instanceof Z ? {
394
394
  type: "error",
395
395
  code: t.code,
@@ -403,7 +403,7 @@ function ue(t) {
403
403
  function At(t) {
404
404
  return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
405
405
  }
406
- async function le({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: s, input: c, cacheTtlS: u, cacheKey: l, signal: d }) {
406
+ async function de({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: s, input: c, cacheTtlS: u, cacheKey: l, signal: d }) {
407
407
  const m = await (i || bt({
408
408
  accountId: e,
409
409
  devJwtSecret: n,
@@ -412,7 +412,7 @@ async function le({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r,
412
412
  }))({
413
413
  ...d ? { signal: d } : {},
414
414
  ...a ? { parentUrl: a } : {}
415
- }), { opDomain: p, opName: g } = It(s), f = {
415
+ }), { opDomain: p, opName: g } = It(s, e), f = {
416
416
  method: "POST",
417
417
  headers: {
418
418
  authorization: `Bearer ${m}`,
@@ -428,25 +428,27 @@ async function le({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r,
428
428
  }),
429
429
  ...d ? { signal: d } : {}
430
430
  }, _ = await fetch(`${String(t).replace(/\/+$/u, "")}/v1/execute`, f);
431
- if (!_.ok) throw Tt(_.status, await Et(_));
432
- return jt(_);
431
+ if (!_.ok) throw Tt(_.status, await jt(_));
432
+ return Pt(_);
433
433
  }
434
- function It(t) {
435
- const e = t.indexOf("-");
436
- if (e <= 0 || e === t.length - 1) throw new Error(`Invalid BE op name: ${t}`);
434
+ function It(t, e) {
435
+ if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
437
436
  return {
438
- opDomain: t.slice(0, e),
439
- opName: t.slice(e + 1)
437
+ opDomain: Et(e),
438
+ opName: t
440
439
  };
441
440
  }
442
- async function Et(t) {
441
+ function Et(t) {
442
+ return t.replace(/-agentic$/u, "");
443
+ }
444
+ async function jt(t) {
443
445
  try {
444
446
  return await t.json();
445
447
  } catch {
446
448
  return { error: { code: t.statusText || "internal" } };
447
449
  }
448
450
  }
449
- async function jt(t) {
451
+ async function Pt(t) {
450
452
  const e = t.body?.getReader();
451
453
  if (!e) throw new Error("BE response body is not readable.");
452
454
  const n = new TextDecoder();
@@ -471,7 +473,7 @@ function q(t, e) {
471
473
  if (t._error) throw tt(t._error);
472
474
  t._end || Object.assign(e, t);
473
475
  }
474
- function de(t = {}) {
476
+ function fe(t = {}) {
475
477
  return {
476
478
  type: "metadata",
477
479
  ...t
@@ -485,19 +487,19 @@ function C(t, e = !1, n = {}) {
485
487
  ...n
486
488
  };
487
489
  }
488
- function Pt(t) {
490
+ function Ct(t) {
489
491
  return {
490
492
  type: "ui_spec",
491
493
  ...t
492
494
  };
493
495
  }
494
- function fe(t) {
496
+ function pe(t) {
495
497
  return {
496
498
  type: "action",
497
499
  action: t
498
500
  };
499
501
  }
500
- function Ct(t, e) {
502
+ function Mt(t, e) {
501
503
  return {
502
504
  type: "error",
503
505
  code: t,
@@ -507,15 +509,15 @@ function Ct(t, e) {
507
509
  function et() {
508
510
  return { type: "done" };
509
511
  }
510
- function Mt(t, e) {
512
+ function vt(t, e) {
511
513
  return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
512
514
  }
513
- async function pe({ request: t, accountModule: e, contextStore: n, beClient: r, toolBridge: o, emit: i, rpc: a, signal: s }) {
514
- const c = performance.now(), u = await n.load(t), l = u.thread.id, d = Dt(t);
515
+ async function me({ request: t, accountModule: e, contextStore: n, beClient: r, toolBridge: o, emit: i, rpc: a, signal: s }) {
516
+ const c = performance.now(), u = await n.load(t), l = u.thread.id, d = zt(t);
515
517
  n.appendUserMessage(l, d);
516
- const m = Mt(e.flows, t);
518
+ const m = vt(e.flows, t);
517
519
  if (!m)
518
- return i(Ct("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(et()), {
520
+ return i(Mt("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(et()), {
519
521
  steps: 0,
520
522
  productSkusEmitted: []
521
523
  };
@@ -552,38 +554,38 @@ async function pe({ request: t, accountModule: e, contextStore: n, beClient: r,
552
554
  async function U(t, e, n) {
553
555
  for (const r of t) {
554
556
  if (n.signal?.aborted) return;
555
- e.steps += 1, await vt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
557
+ e.steps += 1, await Nt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
556
558
  }
557
559
  }
558
- async function vt(t, e, n) {
559
- const r = F(e);
560
+ async function Nt(t, e, n) {
561
+ const r = D(e);
560
562
  if (t.kind === "be_op") {
561
- await Nt(t, e, n, r);
563
+ await Ot(t, e, n, r);
562
564
  return;
563
565
  }
564
566
  if (t.kind === "tool") {
565
- await Ot(t, e, n, r);
567
+ await Bt(t, e, n, r);
566
568
  return;
567
569
  }
568
570
  if (t.kind === "emit") {
569
- Bt(t, e, n);
571
+ Rt(t, e, n);
570
572
  return;
571
573
  }
572
574
  if (t.kind === "branch") {
573
- await Rt(t, e, n, r);
575
+ await Ut(t, e, n, r);
574
576
  return;
575
577
  }
576
578
  if (t.kind === "parallel") {
577
- await Ut(t, e, n);
579
+ await $t(t, e, n);
578
580
  return;
579
581
  }
580
582
  if (t.kind === "refusal") {
581
- await $t(t, e, n, r);
583
+ await Dt(t, e, n, r);
582
584
  return;
583
585
  }
584
586
  t.kind === "commit" && await Ft(t, e, n);
585
587
  }
586
- async function Nt(t, e, n, r) {
588
+ async function Ot(t, e, n, r) {
587
589
  const o = performance.now();
588
590
  let i;
589
591
  const a = I(t.cacheTtlS, r), s = I(t.cacheKey, r);
@@ -620,22 +622,22 @@ async function Nt(t, e, n, r) {
620
622
  };
621
623
  await n.rpc("beacon.send", c);
622
624
  }
623
- async function Ot(t, e, n, r) {
625
+ async function Bt(t, e, n, r) {
624
626
  const o = await n.toolBridge.invoke(t.name, I(t.input, r));
625
627
  t.out && (e.bag[t.out] = o), nt(t, o, e, n.contextStore);
626
628
  }
627
- function Bt(t, e, n) {
628
- const r = t.build(F(e));
629
- zt(r, e.productSkusEmitted), n.emit(r);
629
+ function Rt(t, e, n) {
630
+ const r = t.build(D(e));
631
+ Lt(r, e.productSkusEmitted), n.emit(r);
630
632
  }
631
- async function Rt(t, e, n, r) {
633
+ async function Ut(t, e, n, r) {
632
634
  const o = String(I(t.on, r) || "default");
633
635
  await U(t.cases[o] || t.cases.default || [], e, n);
634
636
  }
635
- async function Ut(t, e, n) {
637
+ async function $t(t, e, n) {
636
638
  await Promise.all(t.steps.map((r) => U(r, e, n)));
637
639
  }
638
- async function $t(t, e, n, r) {
640
+ async function Dt(t, e, n, r) {
639
641
  n.emit(C(I(t.message, r), !0)), await $(e, n);
640
642
  }
641
643
  async function Ft(t, e, n) {
@@ -646,10 +648,10 @@ async function $(t, { contextStore: e, emit: n }) {
646
648
  }
647
649
  function nt(t, e, n, r) {
648
650
  if (typeof t.patch != "function") return;
649
- const o = t.patch(n.context, e, F(n));
651
+ const o = t.patch(n.context, e, D(n));
650
652
  o && (n.context = r.patch(n.threadId, o) || n.context);
651
653
  }
652
- function F(t) {
654
+ function D(t) {
653
655
  return {
654
656
  request: t.request,
655
657
  context: t.context,
@@ -660,7 +662,7 @@ function F(t) {
660
662
  function I(t, e) {
661
663
  return typeof t == "function" ? t(e) : t;
662
664
  }
663
- function Dt(t) {
665
+ function zt(t) {
664
666
  const e = t?.payload;
665
667
  if (typeof e == "string") return e;
666
668
  if (e && typeof e == "object" && "text" in e) {
@@ -669,7 +671,7 @@ function Dt(t) {
669
671
  }
670
672
  return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
671
673
  }
672
- function zt(t, e) {
674
+ function Lt(t, e) {
673
675
  const n = t, r = n.spec, o = Array.isArray(r?.items) ? r.items : void 0, i = Array.isArray(n.items) ? n.items : void 0, a = o || i;
674
676
  if (Array.isArray(a)) {
675
677
  for (const s of a) if (s && typeof s == "object") {
@@ -678,7 +680,7 @@ function zt(t, e) {
678
680
  }
679
681
  }
680
682
  }
681
- function me(t) {
683
+ function ye(t) {
682
684
  return { invoke(e, n) {
683
685
  return t("tool.invoke", {
684
686
  name: e,
@@ -689,7 +691,7 @@ function me(t) {
689
691
  function rt(t) {
690
692
  return t && typeof t == "object" && !Array.isArray(t) ? t : null;
691
693
  }
692
- function D(t) {
694
+ function F(t) {
693
695
  const e = rt(t);
694
696
  if (!e) return null;
695
697
  const n = T(e.sku, e.SKU);
@@ -715,7 +717,7 @@ function D(t) {
715
717
  const g = e.category_names;
716
718
  return Array.isArray(g) && (r.categoryNames = g.map(String)), r;
717
719
  }
718
- function Lt(t) {
720
+ function qt(t) {
719
721
  const e = rt(t);
720
722
  if (!e) return t;
721
723
  const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
@@ -735,7 +737,7 @@ function Lt(t) {
735
737
  return a;
736
738
  }
737
739
  function ot(t) {
738
- return Array.isArray(t) ? t.map(Lt).filter((e) => !!e) : [];
740
+ return Array.isArray(t) ? t.map(qt).filter((e) => !!e) : [];
739
741
  }
740
742
  function T(...t) {
741
743
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
@@ -748,9 +750,9 @@ function j(t) {
748
750
  function J(t) {
749
751
  return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
750
752
  }
751
- function qt(t = []) {
753
+ function Jt(t = []) {
752
754
  const e = {}, n = [];
753
- return (Array.isArray(t) ? t.map(D).filter((r) => !!r) : []).forEach((r, o) => {
755
+ return (Array.isArray(t) ? t.map(F).filter((r) => !!r) : []).forEach((r, o) => {
754
756
  const i = `product-${o.toString()}`;
755
757
  n.push(i);
756
758
  const a = {
@@ -782,7 +784,7 @@ function qt(t = []) {
782
784
  }
783
785
  };
784
786
  }
785
- function ye(t) {
787
+ function ge(t) {
786
788
  return {
787
789
  widget: "chat",
788
790
  panelHint: "panel",
@@ -790,13 +792,13 @@ function ye(t) {
790
792
  root: "root",
791
793
  elements: { root: {
792
794
  type: "ProductDetailsPanel",
793
- props: { product: D(t) || t || {} }
795
+ props: { product: F(t) || t || {} }
794
796
  } }
795
797
  }
796
798
  };
797
799
  }
798
- function ge(t = {}) {
799
- const e = (t.multiple_product_details || t.products || []).map(D).filter((r) => !!r), n = t.table || {};
800
+ function he(t = {}) {
801
+ const e = (t.multiple_product_details || t.products || []).map(F).filter((r) => !!r), n = t.table || {};
800
802
  return {
801
803
  widget: "chat",
802
804
  panelHint: "panel",
@@ -827,7 +829,7 @@ function ge(t = {}) {
827
829
  }
828
830
  };
829
831
  }
830
- function he(t = []) {
832
+ function ke(t = []) {
831
833
  return {
832
834
  widget: "chat",
833
835
  panelHint: "inline",
@@ -860,7 +862,7 @@ function v(t) {
860
862
  const n = t?.action;
861
863
  return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
862
864
  }
863
- function Jt(t) {
865
+ function Kt(t) {
864
866
  return Object.freeze([...t]);
865
867
  }
866
868
  function S(t) {
@@ -872,7 +874,7 @@ function N(t) {
872
874
  function K(t) {
873
875
  return t.thread.extensions.beauty_profile;
874
876
  }
875
- var ke = Jt([{
877
+ var we = Kt([{
876
878
  kind: "be_op",
877
879
  op: "beauty-consulting-turn",
878
880
  input: ({ request: t, context: e }) => ({
@@ -883,7 +885,7 @@ var ke = Jt([{
883
885
  locale: e.meta.locale
884
886
  }),
885
887
  out: "consultation",
886
- patch: H
888
+ patch: W
887
889
  }, {
888
890
  kind: "branch",
889
891
  on: ({ bag: t }) => S(t.consultation).consultation_state?.stage || "answer",
@@ -917,14 +919,14 @@ var ke = Jt([{
917
919
  const n = N(e);
918
920
  return { panel: {
919
921
  ...t.panel,
920
- screen_sku_list: O(n).map((r) => Kt(r)).filter((r) => !!r),
922
+ screen_sku_list: O(n).map((r) => Wt(r)).filter((r) => !!r),
921
923
  last_search: { query: n.query || "" }
922
924
  } };
923
925
  }
924
926
  },
925
927
  {
926
928
  kind: "emit",
927
- build: ({ bag: t }) => Pt(qt(O(N(t.products))))
929
+ build: ({ bag: t }) => Ct(Jt(O(N(t.products))))
928
930
  },
929
931
  {
930
932
  kind: "be_op",
@@ -938,7 +940,7 @@ var ke = Jt([{
938
940
  }),
939
941
  out: "answer",
940
942
  patch: (t, e) => {
941
- const n = H(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
943
+ const n = W(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
942
944
  return {
943
945
  ...n || {},
944
946
  panel: {
@@ -966,7 +968,7 @@ var ke = Jt([{
966
968
  }, { kind: "commit" }]
967
969
  }
968
970
  }]);
969
- function H(t, e) {
971
+ function W(t, e) {
970
972
  const n = S(e).consultation_state?.captured_profile;
971
973
  if (!n) return null;
972
974
  const r = t.thread.extensions.beauty_profile && typeof t.thread.extensions.beauty_profile == "object" ? t.thread.extensions.beauty_profile : {};
@@ -984,7 +986,7 @@ function H(t, e) {
984
986
  function O(t) {
985
987
  return Array.isArray(t?.products) ? t.products : [];
986
988
  }
987
- function Kt(t) {
989
+ function Wt(t) {
988
990
  if (t && typeof t == "object" && "sku" in t) {
989
991
  const e = t.sku;
990
992
  if (typeof e == "string") return e;
@@ -997,7 +999,7 @@ function Ht(t) {
997
999
  function B(t) {
998
1000
  return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
999
1001
  }
1000
- var W = /* @__PURE__ */ new Set([
1002
+ var H = /* @__PURE__ */ new Set([
1001
1003
  "and",
1002
1004
  "are",
1003
1005
  "box",
@@ -1007,7 +1009,7 @@ var W = /* @__PURE__ */ new Set([
1007
1009
  "gifts",
1008
1010
  "the",
1009
1011
  "with"
1010
- ]), Wt = {
1012
+ ]), Vt = {
1011
1013
  token: 0.26,
1012
1014
  keyword: 0.22,
1013
1015
  category: 0.18,
@@ -1016,7 +1018,7 @@ var W = /* @__PURE__ */ new Set([
1016
1018
  attribute: 0.06,
1017
1019
  price: 0.08,
1018
1020
  retrieval: 0.08
1019
- }, Vt = [
1021
+ }, Gt = [
1020
1022
  "amber",
1021
1023
  "beige",
1022
1024
  "black",
@@ -1043,15 +1045,15 @@ var W = /* @__PURE__ */ new Set([
1043
1045
  function x(t) {
1044
1046
  return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1045
1047
  }
1046
- function k(t, e = W) {
1047
- const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...W, ...e]), r = /* @__PURE__ */ new Set(), o = [];
1048
+ function k(t, e = H) {
1049
+ const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...H, ...e]), r = /* @__PURE__ */ new Set(), o = [];
1048
1050
  for (const i of x(t).split(/\s+/u))
1049
1051
  i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
1050
1052
  return o;
1051
1053
  }
1052
1054
  function M(t, e = {}) {
1053
- if (Qt(t)) return t;
1054
- const n = e.facetKeys, r = y(t.category_names ?? t.category), o = y(t.category_ids), i = Yt(t.facet_hits), a = Object.entries(i).filter(([f]) => !n || n.some((_) => x(_) === x(f))).map(([, f]) => f), s = w(t.name, t.title), c = w(t.brand), u = e.sourceKeywords ?? [], l = [
1055
+ if (Yt(t)) return t;
1056
+ const n = e.facetKeys, r = y(t.category_names ?? t.category), o = y(t.category_ids), i = Xt(t.facet_hits), a = Object.entries(i).filter(([f]) => !n || n.some((_) => x(_) === x(f))).map(([, f]) => f), s = w(t.name, t.title), c = w(t.brand), u = e.sourceKeywords ?? [], l = [
1055
1057
  s,
1056
1058
  c,
1057
1059
  ...r,
@@ -1059,7 +1061,7 @@ function M(t, e = {}) {
1059
1061
  ...y(t.promotions),
1060
1062
  w(t.description),
1061
1063
  ...u
1062
- ].join(" "), d = k(l, e.stopWords), m = w(e.sourceProductType, te(r, s, d), d[0]), p = b([...Zt(l, Vt), ...Object.entries(i).filter(([f]) => /colou?r/iu.test(f)).flatMap(([, f]) => k(f, e.stopWords))]), g = b([...a.flatMap((f) => k(f, e.stopWords)), ...y(t.promotions).flatMap((f) => k(f, e.stopWords))]).slice(0, 24);
1064
+ ].join(" "), d = k(l, e.stopWords), m = w(e.sourceProductType, ee(r, s, d), d[0]), p = b([...te(l, Gt), ...Object.entries(i).filter(([f]) => /colou?r/iu.test(f)).flatMap(([, f]) => k(f, e.stopWords))]), g = b([...a.flatMap((f) => k(f, e.stopWords)), ...y(t.promotions).flatMap((f) => k(f, e.stopWords))]).slice(0, 24);
1063
1065
  return {
1064
1066
  sku: w(t.sku),
1065
1067
  title: s,
@@ -1072,10 +1074,10 @@ function M(t, e = {}) {
1072
1074
  tokens: d,
1073
1075
  colors: p,
1074
1076
  attributes: g,
1075
- price: Xt(t)
1077
+ price: Zt(t)
1076
1078
  };
1077
1079
  }
1078
- function we(t, e = {}) {
1080
+ function be(t, e = {}) {
1079
1081
  const n = w(t.product_type, t.productType), r = w(t.title, n, y(t.keywords).join(" ")), o = b([
1080
1082
  ...y(t.keywords),
1081
1083
  ...y(t.colors),
@@ -1100,7 +1102,7 @@ function we(t, e = {}) {
1100
1102
  sourceKeywords: o
1101
1103
  });
1102
1104
  }
1103
- function be(t, e = {}) {
1105
+ function _e(t, e = {}) {
1104
1106
  const n = M(t, e);
1105
1107
  return b([
1106
1108
  ...e.sourceQueries ?? [],
@@ -1115,23 +1117,23 @@ function be(t, e = {}) {
1115
1117
  n.productType
1116
1118
  ].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1117
1119
  }
1118
- function Gt(t, e, n = {}) {
1120
+ function Qt(t, e, n = {}) {
1119
1121
  const r = {
1120
- ...Wt,
1122
+ ...Vt,
1121
1123
  ...n.weights
1122
- }, o = M(e, n), i = [], a = A(t.tokens, o.tokens), s = A(t.keywords, o.tokens), c = ee(t.categoryNames, o.categoryNames) || A(V(t.categoryNames), V(o.categoryNames)), u = A(t.attributes, o.attributes), l = A(t.colors, o.colors), d = A(t.attributes, o.tokens), m = ne(t.price, o.price), p = re(o.sku, n.hitCounts) > 0 ? 1 : 0, g = oe(t, o), f = a * r.token + s * r.keyword + c * r.category + u * r.facet + l * r.color + d * r.attribute + m * r.price + p * r.retrieval, _ = ie(g ? f : f * 0.35);
1124
+ }, o = M(e, n), i = [], a = A(t.tokens, o.tokens), s = A(t.keywords, o.tokens), c = ne(t.categoryNames, o.categoryNames) || A(V(t.categoryNames), V(o.categoryNames)), u = A(t.attributes, o.attributes), l = A(t.colors, o.colors), d = A(t.attributes, o.tokens), m = re(t.price, o.price), p = oe(o.sku, n.hitCounts) > 0 ? 1 : 0, g = ie(t, o), f = a * r.token + s * r.keyword + c * r.category + u * r.facet + l * r.color + d * r.attribute + m * r.price + p * r.retrieval, _ = ae(g ? f : f * 0.35);
1123
1125
  return g && t.productType && t.productType === o.productType && i.push("same product type"), c > 0.4 && i.push("similar category"), u > 0.2 && i.push("matching product attributes"), l > 0 && i.push("matching colour"), m > 0.8 && i.push("similar price"), g || i.push("weaker product-type match"), {
1124
1126
  score: Number(_.toFixed(4)),
1125
1127
  reasons: i
1126
1128
  };
1127
1129
  }
1128
- function _e(t, e, n = {}) {
1130
+ function Se(t, e, n = {}) {
1129
1131
  const r = M(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1130
1132
  return e.filter((i) => {
1131
1133
  const a = w(i.sku);
1132
1134
  return a && !o.has(a);
1133
1135
  }).map((i) => {
1134
- const a = Gt(r, i, n);
1136
+ const a = Qt(r, i, n);
1135
1137
  return {
1136
1138
  ...i,
1137
1139
  similarity_score: a.score,
@@ -1139,7 +1141,7 @@ function _e(t, e, n = {}) {
1139
1141
  };
1140
1142
  }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
1141
1143
  }
1142
- function Qt(t) {
1144
+ function Yt(t) {
1143
1145
  return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1144
1146
  }
1145
1147
  function w(...t) {
@@ -1149,10 +1151,10 @@ function w(...t) {
1149
1151
  function y(t) {
1150
1152
  return Array.isArray(t) ? t.map((e) => w(e)).filter(Boolean) : typeof t == "string" && t.trim() ? t.split(/[,;/|]+/u).map((e) => e.trim()).filter(Boolean) : [];
1151
1153
  }
1152
- function Yt(t) {
1154
+ function Xt(t) {
1153
1155
  return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, w(n)]).filter(([, e]) => e));
1154
1156
  }
1155
- function Xt(t) {
1157
+ function Zt(t) {
1156
1158
  const e = Number(t.price_discounted);
1157
1159
  if (Number.isFinite(e) && e > 0) return e;
1158
1160
  const n = Number(t.price);
@@ -1166,11 +1168,11 @@ function b(t) {
1166
1168
  }
1167
1169
  return n;
1168
1170
  }
1169
- function Zt(t, e) {
1171
+ function te(t, e) {
1170
1172
  const n = ` ${x(t)} `;
1171
1173
  return e.filter((r) => n.includes(` ${x(r)} `));
1172
1174
  }
1173
- function te(t, e, n) {
1175
+ function ee(t, e, n) {
1174
1176
  const r = x(t[t.length - 1] ?? t[0] ?? "");
1175
1177
  if (r) {
1176
1178
  const o = k(r), i = new Set(k(e));
@@ -1188,62 +1190,62 @@ function A(t, e) {
1188
1190
  const n = b(t), r = new Set(b(e));
1189
1191
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1190
1192
  }
1191
- function ee(t, e) {
1193
+ function ne(t, e) {
1192
1194
  const n = b(t), r = new Set(b(e));
1193
1195
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1194
1196
  }
1195
- function ne(t, e) {
1197
+ function re(t, e) {
1196
1198
  return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1197
1199
  }
1198
- function re(t, e) {
1200
+ function oe(t, e) {
1199
1201
  return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1200
1202
  }
1201
- function oe(t, e) {
1203
+ function ie(t, e) {
1202
1204
  if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1203
1205
  const n = new Set(k(t.productType)), r = /* @__PURE__ */ new Set([...k(e.productType), ...e.tokens]);
1204
1206
  return [...n].some((o) => r.has(o));
1205
1207
  }
1206
- function ie(t) {
1208
+ function ae(t) {
1207
1209
  return Math.max(0, Math.min(1, t));
1208
1210
  }
1209
1211
  export {
1210
- ue as A,
1211
- Ct as C,
1212
- le as D,
1213
- Pt as E,
1212
+ le as A,
1213
+ Mt as C,
1214
+ de as D,
1215
+ Ct as E,
1214
1216
  R as F,
1215
1217
  ft as I,
1216
- ae as L,
1218
+ se as L,
1217
1219
  bt as M,
1218
1220
  wt as N,
1219
1221
  Z as O,
1220
- ce as P,
1221
- se as R,
1222
+ ue as P,
1223
+ ce as R,
1222
1224
  et as S,
1223
1225
  C as T,
1224
1226
  ot as _,
1225
- _e as a,
1226
- Mt as b,
1227
- ke as c,
1228
- he as d,
1229
- ge as f,
1230
- Lt as g,
1231
- D as h,
1227
+ Se as a,
1228
+ vt as b,
1229
+ we as c,
1230
+ ke as d,
1231
+ he as f,
1232
+ qt as g,
1233
+ F as h,
1232
1234
  x as i,
1233
1235
  Tt as j,
1234
1236
  tt as k,
1235
- Jt as l,
1236
- qt as m,
1237
+ Kt as l,
1238
+ Jt as m,
1237
1239
  M as n,
1238
- Gt as o,
1239
- ye as p,
1240
- be as r,
1240
+ Qt as o,
1241
+ ge as p,
1242
+ _e as r,
1241
1243
  k as s,
1242
- we as t,
1244
+ be as t,
1243
1245
  v as u,
1244
- me as v,
1245
- de as w,
1246
- fe as x,
1247
- pe as y,
1246
+ ye as v,
1247
+ fe as w,
1248
+ pe as x,
1249
+ me as y,
1248
1250
  dt as z
1249
1251
  };
@@ -1,7 +1,7 @@
1
1
  import { A, j as S } from "./context-BBuSsXZ9.js";
2
2
  import { n as $, t as L } from "./price-formatter-xI3g9Cd4.js";
3
3
  import { a as C, c as f, n as q, o as h, t as k, u as H } from "./schemas-CLo8wCjs.js";
4
- import { o as j } from "./runtime-BgdgBiYF.js";
4
+ import { o as j } from "./runtime-Brx9ReJA.js";
5
5
  var V = {
6
6
  images: [
7
7
  "images",
@@ -1,4 +1,4 @@
1
- import { a, i as r, n as i, r as t, t as S } from "./runtime-BgdgBiYF.js";
1
+ import { a, i as r, n as i, r as t, t as S } from "./runtime-Brx9ReJA.js";
2
2
  export {
3
3
  S as GengageSimRel,
4
4
  t as createDefaultSimRelUISpecRegistry,