@gengage/assistant-fe 0.6.6 → 0.6.8

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 ie(t = self) {
7
+ function ae(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 ie(t = self) {
34
34
  });
35
35
  };
36
36
  }
37
- function ae({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
37
+ function se({ 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, {
@@ -95,25 +95,25 @@ async function dt(t, e, { tools: n, beacon: r, memory: o }) {
95
95
  function ft() {
96
96
  return (/* @__PURE__ */ new Date()).toISOString();
97
97
  }
98
- function B(t) {
98
+ function R(t) {
99
99
  return Math.max(0, Math.round(performance.now() - t));
100
100
  }
101
- function A(t) {
101
+ function E(t) {
102
102
  return typeof t == "object" && t !== null && !Array.isArray(t);
103
103
  }
104
104
  function pt(t) {
105
- const { accountId: e, locale: n = "en-GB", parentUrl: r = "", threadId: o, incomingContext: i } = t, a = A(i) ? i : {}, s = A(a.thread) ? a.thread : {}, c = A(a.panel) ? a.panel : {}, u = A(a.meta) ? a.meta : {}, l = G(a.messages), d = {
105
+ const { accountId: e, locale: n = "en-GB", parentUrl: r = "", threadId: o, incomingContext: i } = t, a = E(i) ? i : {}, s = E(a.thread) ? a.thread : {}, c = E(a.panel) ? a.panel : {}, u = E(a.meta) ? a.meta : {}, l = G(a.messages), d = {
106
106
  id: String(o || s.id || self.crypto.randomUUID()),
107
107
  started_at: String(s.started_at || ft()),
108
- extensions: A(s.extensions) ? { ...s.extensions } : {}
109
- }, p = String(u.locale || n), m = String(u.parentUrl || r || typeof self < "u" && self.location?.href || "");
108
+ extensions: E(s.extensions) ? { ...s.extensions } : {}
109
+ }, m = String(u.locale || n), p = String(u.parentUrl || r || typeof self < "u" && self.location?.href || "");
110
110
  return {
111
111
  panel: { ...c },
112
112
  messages: l,
113
113
  thread: d,
114
114
  meta: {
115
- locale: p,
116
- parentUrl: m,
115
+ locale: m,
116
+ parentUrl: p,
117
117
  accountId: e
118
118
  }
119
119
  };
@@ -152,10 +152,10 @@ async function ht({ accountId: t, threadId: e, extensions: n, rpc: r }) {
152
152
  function Q(t, e) {
153
153
  return `${yt}${t}:${e}`;
154
154
  }
155
- function g(t) {
155
+ function h(t) {
156
156
  return typeof t == "object" && t !== null && !Array.isArray(t);
157
157
  }
158
- var se = class {
158
+ var ce = class {
159
159
  #t = /* @__PURE__ */ new Map();
160
160
  #e;
161
161
  #r;
@@ -208,11 +208,11 @@ var se = class {
208
208
  }
209
209
  };
210
210
  function kt(t, e) {
211
- return !g(t) && !g(e) ? {} : Y(g(t) ? t : {}, g(e) ? e : {});
211
+ return !h(t) && !h(e) ? {} : Y(h(t) ? t : {}, h(e) ? e : {});
212
212
  }
213
213
  function Y(t, e) {
214
- if (!g(e)) return t;
215
- const n = t, r = e, o = g(n.panel) ? n.panel : {}, i = g(r.panel) ? r.panel : {}, a = g(n.thread) ? n.thread : {}, s = g(r.thread) ? r.thread : {}, c = g(a.extensions) ? a.extensions : {}, u = g(s.extensions) ? s.extensions : {}, l = g(n.meta) ? n.meta : {}, d = g(r.meta) ? r.meta : {};
214
+ if (!h(e)) return t;
215
+ const n = t, r = e, o = h(n.panel) ? n.panel : {}, i = h(r.panel) ? r.panel : {}, a = h(n.thread) ? n.thread : {}, s = h(r.thread) ? r.thread : {}, c = h(a.extensions) ? a.extensions : {}, u = h(s.extensions) ? s.extensions : {}, l = h(n.meta) ? n.meta : {}, d = h(r.meta) ? r.meta : {};
216
216
  return {
217
217
  ...t,
218
218
  ...e,
@@ -389,7 +389,7 @@ function Tt(t, e) {
389
389
  detail: n.detail
390
390
  });
391
391
  }
392
- function ce(t) {
392
+ function ue(t) {
393
393
  return t instanceof Z ? {
394
394
  type: "error",
395
395
  code: t.code,
@@ -403,40 +403,50 @@ function ce(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 ue({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: s, input: c, cacheTtlS: u, signal: l }) {
407
- const d = {
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 }) {
407
+ const m = await (i || bt({
408
+ accountId: e,
409
+ devJwtSecret: n,
410
+ tokenBrokerUrl: r,
411
+ tokenBrokerAudience: o
412
+ }))({
413
+ ...d ? { signal: d } : {},
414
+ ...a ? { parentUrl: a } : {}
415
+ }), { opDomain: p, opName: g } = It(s), f = {
408
416
  method: "POST",
409
417
  headers: {
410
- authorization: `Bearer ${await (i || bt({
411
- accountId: e,
412
- devJwtSecret: n,
413
- tokenBrokerUrl: r,
414
- tokenBrokerAudience: o
415
- }))({
416
- ...l ? { signal: l } : {},
417
- ...a ? { parentUrl: a } : {}
418
- })}`,
418
+ authorization: `Bearer ${m}`,
419
419
  "content-type": "application/json",
420
420
  accept: "application/x-ndjson"
421
421
  },
422
422
  body: JSON.stringify({
423
- op: s,
424
- input: c,
425
- ...u !== void 0 ? { cache_ttl_s: u } : {}
423
+ op_domain: p,
424
+ op_name: g,
425
+ op_payload: c,
426
+ ...u !== void 0 ? { cache_ttl_s: u } : {},
427
+ ...l !== void 0 ? { cache_key: l } : {}
426
428
  }),
427
- ...l ? { signal: l } : {}
428
- }, p = await fetch(`${String(t).replace(/\/+$/u, "")}/v1/invoke`, d);
429
- if (!p.ok) throw Tt(p.status, await It(p));
430
- return Et(p);
429
+ ...d ? { signal: d } : {}
430
+ }, _ = await fetch(`${String(t).replace(/\/+$/u, "")}/v1/execute`, f);
431
+ if (!_.ok) throw Tt(_.status, await Et(_));
432
+ return jt(_);
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}`);
437
+ return {
438
+ opDomain: t.slice(0, e),
439
+ opName: t.slice(e + 1)
440
+ };
431
441
  }
432
- async function It(t) {
442
+ async function Et(t) {
433
443
  try {
434
444
  return await t.json();
435
445
  } catch {
436
446
  return { error: { code: t.statusText || "internal" } };
437
447
  }
438
448
  }
439
- async function Et(t) {
449
+ async function jt(t) {
440
450
  const e = t.body?.getReader();
441
451
  if (!e) throw new Error("BE response body is not readable.");
442
452
  const n = new TextDecoder();
@@ -461,13 +471,13 @@ function q(t, e) {
461
471
  if (t._error) throw tt(t._error);
462
472
  t._end || Object.assign(e, t);
463
473
  }
464
- function le(t = {}) {
474
+ function de(t = {}) {
465
475
  return {
466
476
  type: "metadata",
467
477
  ...t
468
478
  };
469
479
  }
470
- function P(t, e = !1, n = {}) {
480
+ function C(t, e = !1, n = {}) {
471
481
  return {
472
482
  type: "text_chunk",
473
483
  content: t,
@@ -475,19 +485,19 @@ function P(t, e = !1, n = {}) {
475
485
  ...n
476
486
  };
477
487
  }
478
- function jt(t) {
488
+ function Pt(t) {
479
489
  return {
480
490
  type: "ui_spec",
481
491
  ...t
482
492
  };
483
493
  }
484
- function de(t) {
494
+ function fe(t) {
485
495
  return {
486
496
  type: "action",
487
497
  action: t
488
498
  };
489
499
  }
490
- function Pt(t, e) {
500
+ function Ct(t, e) {
491
501
  return {
492
502
  type: "error",
493
503
  code: t,
@@ -497,19 +507,19 @@ function Pt(t, e) {
497
507
  function et() {
498
508
  return { type: "done" };
499
509
  }
500
- function Ct(t, e) {
510
+ function Mt(t, e) {
501
511
  return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
502
512
  }
503
- async function fe({ request: t, accountModule: e, contextStore: n, beClient: r, toolBridge: o, emit: i, rpc: a, signal: s }) {
504
- const c = performance.now(), u = await n.load(t), l = u.thread.id, d = Ft(t);
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);
505
515
  n.appendUserMessage(l, d);
506
- const p = Ct(e.flows, t);
507
- if (!p)
508
- return i(Pt("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(et()), {
516
+ const m = Mt(e.flows, t);
517
+ if (!m)
518
+ return i(Ct("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(et()), {
509
519
  steps: 0,
510
520
  productSkusEmitted: []
511
521
  };
512
- const m = {
522
+ const p = {
513
523
  request: t,
514
524
  context: n.patch(l, {}) || u,
515
525
  bag: {},
@@ -518,7 +528,7 @@ async function fe({ request: t, accountModule: e, contextStore: n, beClient: r,
518
528
  steps: 0,
519
529
  productSkusEmitted: /* @__PURE__ */ new Set(),
520
530
  committed: !1
521
- }, h = {
531
+ }, g = {
522
532
  contextStore: n,
523
533
  beClient: r,
524
534
  toolBridge: o,
@@ -526,37 +536,37 @@ async function fe({ request: t, accountModule: e, contextStore: n, beClient: r,
526
536
  rpc: a,
527
537
  ...s ? { signal: s } : {}
528
538
  };
529
- return await U(p, m, h), m.committed || await $(m, h), await a("beacon.send", {
539
+ return await U(m, p, g), p.committed || await $(p, g), await a("beacon.send", {
530
540
  type: "turnSummary",
531
541
  threadId: l,
532
542
  sessionId: t?.session_id || t?.sessionId || l,
533
- accountId: e.accountId || m.context.meta.accountId,
534
- steps: m.steps,
535
- totalLatencyMs: B(c),
536
- productSkusEmitted: [...m.productSkusEmitted]
543
+ accountId: e.accountId || p.context.meta.accountId,
544
+ steps: p.steps,
545
+ totalLatencyMs: R(c),
546
+ productSkusEmitted: [...p.productSkusEmitted]
537
547
  }), {
538
- steps: m.steps,
539
- productSkusEmitted: [...m.productSkusEmitted]
548
+ steps: p.steps,
549
+ productSkusEmitted: [...p.productSkusEmitted]
540
550
  };
541
551
  }
542
552
  async function U(t, e, n) {
543
553
  for (const r of t) {
544
554
  if (n.signal?.aborted) return;
545
- e.steps += 1, await Mt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
555
+ e.steps += 1, await vt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
546
556
  }
547
557
  }
548
- async function Mt(t, e, n) {
558
+ async function vt(t, e, n) {
549
559
  const r = F(e);
550
560
  if (t.kind === "be_op") {
551
- await vt(t, e, n, r);
561
+ await Nt(t, e, n, r);
552
562
  return;
553
563
  }
554
564
  if (t.kind === "tool") {
555
- await Nt(t, e, n, r);
565
+ await Ot(t, e, n, r);
556
566
  return;
557
567
  }
558
568
  if (t.kind === "emit") {
559
- Ot(t, e, n);
569
+ Bt(t, e, n);
560
570
  return;
561
571
  }
562
572
  if (t.kind === "branch") {
@@ -564,70 +574,71 @@ async function Mt(t, e, n) {
564
574
  return;
565
575
  }
566
576
  if (t.kind === "parallel") {
567
- await Bt(t, e, n);
577
+ await Ut(t, e, n);
568
578
  return;
569
579
  }
570
580
  if (t.kind === "refusal") {
571
- await Ut(t, e, n, r);
581
+ await $t(t, e, n, r);
572
582
  return;
573
583
  }
574
- t.kind === "commit" && await $t(t, e, n);
584
+ t.kind === "commit" && await Ft(t, e, n);
575
585
  }
576
- async function vt(t, e, n, r) {
586
+ async function Nt(t, e, n, r) {
577
587
  const o = performance.now();
578
588
  let i;
579
- const a = E(t.cacheTtlS, r);
589
+ const a = I(t.cacheTtlS, r), s = I(t.cacheKey, r);
580
590
  try {
581
591
  i = await n.beClient.invoke({
582
592
  op: t.op,
583
- input: E(t.input, r),
593
+ input: I(t.input, r),
584
594
  ...a !== void 0 ? { cacheTtlS: a } : {},
595
+ ...s !== void 0 ? { cacheKey: s } : {},
585
596
  ...n.signal ? { signal: n.signal } : {}
586
597
  });
587
- } catch (c) {
588
- const u = c, l = String(u?.sourceCode || u?.code || "unknown"), d = {
598
+ } catch (u) {
599
+ const l = u, d = String(l?.sourceCode || l?.code || "unknown"), m = {
589
600
  type: "agentOp",
590
601
  threadId: e.threadId,
591
602
  sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
592
603
  accountId: e.context.meta.accountId,
593
604
  op: t.op,
594
605
  status: "error",
595
- latencyMs: B(o),
596
- errorCode: l
606
+ latencyMs: R(o),
607
+ errorCode: d
597
608
  };
598
- throw await n.rpc("beacon.send", d), c;
609
+ throw await n.rpc("beacon.send", m), u;
599
610
  }
600
611
  t.out && (e.bag[t.out] = i), nt(t, i, e, n.contextStore);
601
- const s = {
612
+ const c = {
602
613
  type: "agentOp",
603
614
  threadId: e.threadId,
604
615
  sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
605
616
  accountId: e.context.meta.accountId,
606
617
  op: t.op,
607
618
  status: "ok",
608
- latencyMs: B(o)
619
+ latencyMs: R(o)
609
620
  };
610
- await n.rpc("beacon.send", s);
621
+ await n.rpc("beacon.send", c);
611
622
  }
612
- async function Nt(t, e, n, r) {
613
- const o = await n.toolBridge.invoke(t.name, E(t.input, r));
623
+ async function Ot(t, e, n, r) {
624
+ const o = await n.toolBridge.invoke(t.name, I(t.input, r));
614
625
  t.out && (e.bag[t.out] = o), nt(t, o, e, n.contextStore);
615
626
  }
616
- function Ot(t, e, n) {
627
+ function Bt(t, e, n) {
617
628
  const r = t.build(F(e));
618
- Dt(r, e.productSkusEmitted), n.emit(r);
629
+ zt(r, e.productSkusEmitted), n.emit(r);
619
630
  }
620
631
  async function Rt(t, e, n, r) {
621
- const o = String(E(t.on, r) || "default");
632
+ const o = String(I(t.on, r) || "default");
622
633
  await U(t.cases[o] || t.cases.default || [], e, n);
623
634
  }
624
- async function Bt(t, e, n) {
635
+ async function Ut(t, e, n) {
625
636
  await Promise.all(t.steps.map((r) => U(r, e, n)));
626
637
  }
627
- async function Ut(t, e, n, r) {
628
- n.emit(P(E(t.message, r), !0)), await $(e, n);
638
+ async function $t(t, e, n, r) {
639
+ n.emit(C(I(t.message, r), !0)), await $(e, n);
629
640
  }
630
- async function $t(t, e, n) {
641
+ async function Ft(t, e, n) {
631
642
  await $(e, n);
632
643
  }
633
644
  async function $(t, { contextStore: e, emit: n }) {
@@ -646,10 +657,10 @@ function F(t) {
646
657
  accountConfig: t.accountConfig
647
658
  };
648
659
  }
649
- function E(t, e) {
660
+ function I(t, e) {
650
661
  return typeof t == "function" ? t(e) : t;
651
662
  }
652
- function Ft(t) {
663
+ function Dt(t) {
653
664
  const e = t?.payload;
654
665
  if (typeof e == "string") return e;
655
666
  if (e && typeof e == "object" && "text" in e) {
@@ -658,7 +669,7 @@ function Ft(t) {
658
669
  }
659
670
  return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
660
671
  }
661
- function Dt(t, e) {
672
+ function zt(t, e) {
662
673
  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;
663
674
  if (Array.isArray(a)) {
664
675
  for (const s of a) if (s && typeof s == "object") {
@@ -667,7 +678,7 @@ function Dt(t, e) {
667
678
  }
668
679
  }
669
680
  }
670
- function pe(t) {
681
+ function me(t) {
671
682
  return { invoke(e, n) {
672
683
  return t("tool.invoke", {
673
684
  name: e,
@@ -681,30 +692,30 @@ function rt(t) {
681
692
  function D(t) {
682
693
  const e = rt(t);
683
694
  if (!e) return null;
684
- const n = x(e.sku, e.SKU);
695
+ const n = T(e.sku, e.SKU);
685
696
  if (!n) return null;
686
697
  const r = {
687
698
  sku: n,
688
- name: x(e.name, e.title, e.short_name, n) || n,
689
- url: x(e.url) || ""
690
- }, o = Array.isArray(e.images) ? e.images : void 0, i = x(e.imageUrl, e.image_url, e.image, o?.[0]);
699
+ name: T(e.name, e.title, e.short_name, n) || n,
700
+ url: T(e.url) || ""
701
+ }, o = Array.isArray(e.images) ? e.images : void 0, i = T(e.imageUrl, e.image_url, e.image, o?.[0]);
691
702
  i && (r.imageUrl = i), o && o.length > 1 && (r.images = o.filter((f) => !!f).map(String));
692
- const a = I(e.price_discounted), s = I(e.price), c = a || s;
703
+ const a = j(e.price_discounted), s = j(e.price), c = a || s;
693
704
  c > 0 && (r.price = String(c));
694
705
  const u = a > 0 ? s : 0;
695
706
  u > 0 && (r.originalPrice = String(u));
696
- const l = x(e.brand);
707
+ const l = T(e.brand);
697
708
  l && (r.brand = l);
698
- const d = I(e.rating);
709
+ const d = j(e.rating);
699
710
  d > 0 && (r.rating = d);
700
- const p = I(e.review_count) || I(e.reviewCount);
701
- p > 0 && (r.reviewCount = p);
702
- const m = x(e.cart_code, e.cartCode);
703
- m && (r.cartCode = m), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
704
- const h = e.category_names;
705
- return Array.isArray(h) && (r.categoryNames = h.map(String)), r;
706
- }
707
- function zt(t) {
711
+ const m = j(e.review_count) || j(e.reviewCount);
712
+ m > 0 && (r.reviewCount = m);
713
+ const p = T(e.cart_code, e.cartCode);
714
+ p && (r.cartCode = p), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
715
+ const g = e.category_names;
716
+ return Array.isArray(g) && (r.categoryNames = g.map(String)), r;
717
+ }
718
+ function Lt(t) {
708
719
  const e = rt(t);
709
720
  if (!e) return t;
710
721
  const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
@@ -724,20 +735,20 @@ function zt(t) {
724
735
  return a;
725
736
  }
726
737
  function ot(t) {
727
- return Array.isArray(t) ? t.map(zt).filter((e) => !!e) : [];
738
+ return Array.isArray(t) ? t.map(Lt).filter((e) => !!e) : [];
728
739
  }
729
- function x(...t) {
740
+ function T(...t) {
730
741
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
731
742
  return "";
732
743
  }
733
- function I(t) {
744
+ function j(t) {
734
745
  const e = Number(t);
735
746
  return Number.isFinite(e) ? e : 0;
736
747
  }
737
748
  function J(t) {
738
749
  return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
739
750
  }
740
- function Lt(t = []) {
751
+ function qt(t = []) {
741
752
  const e = {}, n = [];
742
753
  return (Array.isArray(t) ? t.map(D).filter((r) => !!r) : []).forEach((r, o) => {
743
754
  const i = `product-${o.toString()}`;
@@ -771,7 +782,7 @@ function Lt(t = []) {
771
782
  }
772
783
  };
773
784
  }
774
- function me(t) {
785
+ function ye(t) {
775
786
  return {
776
787
  widget: "chat",
777
788
  panelHint: "panel",
@@ -784,7 +795,7 @@ function me(t) {
784
795
  }
785
796
  };
786
797
  }
787
- function ye(t = {}) {
798
+ function ge(t = {}) {
788
799
  const e = (t.multiple_product_details || t.products || []).map(D).filter((r) => !!r), n = t.table || {};
789
800
  return {
790
801
  widget: "chat",
@@ -816,7 +827,7 @@ function ye(t = {}) {
816
827
  }
817
828
  };
818
829
  }
819
- function ge(t = []) {
830
+ function he(t = []) {
820
831
  return {
821
832
  widget: "chat",
822
833
  panelHint: "inline",
@@ -849,10 +860,10 @@ function v(t) {
849
860
  const n = t?.action;
850
861
  return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
851
862
  }
852
- function qt(t) {
863
+ function Jt(t) {
853
864
  return Object.freeze([...t]);
854
865
  }
855
- function _(t) {
866
+ function S(t) {
856
867
  return t && typeof t == "object" ? t : {};
857
868
  }
858
869
  function N(t) {
@@ -861,39 +872,39 @@ function N(t) {
861
872
  function K(t) {
862
873
  return t.thread.extensions.beauty_profile;
863
874
  }
864
- var he = qt([{
875
+ var ke = Jt([{
865
876
  kind: "be_op",
866
877
  op: "beauty-consulting-turn",
867
878
  input: ({ request: t, context: e }) => ({
868
879
  utterance: v(t),
869
880
  prior_messages: e.messages.slice(-10),
870
881
  profile: K(e),
871
- candidate_products: Kt(t),
882
+ candidate_products: Ht(t),
872
883
  locale: e.meta.locale
873
884
  }),
874
885
  out: "consultation",
875
886
  patch: H
876
887
  }, {
877
888
  kind: "branch",
878
- on: ({ bag: t }) => _(t.consultation).consultation_state?.stage || "answer",
889
+ on: ({ bag: t }) => S(t.consultation).consultation_state?.stage || "answer",
879
890
  cases: {
880
891
  refuse: [{
881
892
  kind: "refusal",
882
893
  message: ({ bag: t }) => {
883
- const e = _(t.consultation);
894
+ const e = S(t.consultation);
884
895
  return e.refusal?.message || e.plain_text || "I cannot help with that request.";
885
896
  }
886
897
  }],
887
898
  needs_more_info: [{
888
899
  kind: "emit",
889
- build: ({ bag: t }) => P(R(_(t.consultation)), !0)
900
+ build: ({ bag: t }) => C(B(S(t.consultation)), !0)
890
901
  }, { kind: "commit" }],
891
902
  search: [
892
903
  {
893
904
  kind: "tool",
894
905
  name: "search",
895
906
  input: ({ request: t, bag: e, context: n }) => {
896
- const r = _(e.consultation);
907
+ const r = S(e.consultation);
897
908
  return {
898
909
  query: r.search_params?.query || v(t),
899
910
  facets: r.search_params?.facets || {},
@@ -906,14 +917,14 @@ var he = qt([{
906
917
  const n = N(e);
907
918
  return { panel: {
908
919
  ...t.panel,
909
- screen_sku_list: O(n).map((r) => Jt(r)).filter((r) => !!r),
920
+ screen_sku_list: O(n).map((r) => Kt(r)).filter((r) => !!r),
910
921
  last_search: { query: n.query || "" }
911
922
  } };
912
923
  }
913
924
  },
914
925
  {
915
926
  kind: "emit",
916
- build: ({ bag: t }) => jt(Lt(O(N(t.products))))
927
+ build: ({ bag: t }) => Pt(qt(O(N(t.products))))
917
928
  },
918
929
  {
919
930
  kind: "be_op",
@@ -927,7 +938,7 @@ var he = qt([{
927
938
  }),
928
939
  out: "answer",
929
940
  patch: (t, e) => {
930
- const n = H(t, e), r = (_(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
941
+ const n = H(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
931
942
  return {
932
943
  ...n || {},
933
944
  panel: {
@@ -940,8 +951,8 @@ var he = qt([{
940
951
  {
941
952
  kind: "emit",
942
953
  build: ({ bag: t }) => {
943
- const e = _(t.answer);
944
- return P(R(e), !0, { productMentions: e.product_mentions || [] });
954
+ const e = S(t.answer);
955
+ return C(B(e), !0, { productMentions: e.product_mentions || [] });
945
956
  }
946
957
  },
947
958
  { kind: "commit" }
@@ -949,14 +960,14 @@ var he = qt([{
949
960
  default: [{
950
961
  kind: "emit",
951
962
  build: ({ bag: t }) => {
952
- const e = _(t.consultation);
953
- return P(R(e), !0, { productMentions: e.product_mentions || [] });
963
+ const e = S(t.consultation);
964
+ return C(B(e), !0, { productMentions: e.product_mentions || [] });
954
965
  }
955
966
  }, { kind: "commit" }]
956
967
  }
957
968
  }]);
958
969
  function H(t, e) {
959
- const n = _(e).consultation_state?.captured_profile;
970
+ const n = S(e).consultation_state?.captured_profile;
960
971
  if (!n) return null;
961
972
  const r = t.thread.extensions.beauty_profile && typeof t.thread.extensions.beauty_profile == "object" ? t.thread.extensions.beauty_profile : {};
962
973
  return { thread: {
@@ -973,17 +984,17 @@ function H(t, e) {
973
984
  function O(t) {
974
985
  return Array.isArray(t?.products) ? t.products : [];
975
986
  }
976
- function Jt(t) {
987
+ function Kt(t) {
977
988
  if (t && typeof t == "object" && "sku" in t) {
978
989
  const e = t.sku;
979
990
  if (typeof e == "string") return e;
980
991
  }
981
992
  }
982
- function Kt(t) {
993
+ function Ht(t) {
983
994
  const e = t?.payload && typeof t.payload == "object" ? t.payload.products : void 0, n = t?.action?.payload && typeof t.action.payload == "object" ? t.action.payload.products : void 0, r = e || n;
984
995
  return Array.isArray(r) ? ot(r.slice(0, 12)) : void 0;
985
996
  }
986
- function R(t) {
997
+ function B(t) {
987
998
  return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
988
999
  }
989
1000
  var W = /* @__PURE__ */ new Set([
@@ -994,10 +1005,9 @@ var W = /* @__PURE__ */ new Set([
994
1005
  "from",
995
1006
  "gift",
996
1007
  "gifts",
997
- "interflora",
998
1008
  "the",
999
1009
  "with"
1000
- ]), Ht = {
1010
+ ]), Wt = {
1001
1011
  token: 0.26,
1002
1012
  keyword: 0.22,
1003
1013
  category: 0.18,
@@ -1006,7 +1016,7 @@ var W = /* @__PURE__ */ new Set([
1006
1016
  attribute: 0.06,
1007
1017
  price: 0.08,
1008
1018
  retrieval: 0.08
1009
- }, Wt = [
1019
+ }, Vt = [
1010
1020
  "amber",
1011
1021
  "beige",
1012
1022
  "black",
@@ -1030,18 +1040,18 @@ var W = /* @__PURE__ */ new Set([
1030
1040
  "white",
1031
1041
  "yellow"
1032
1042
  ];
1033
- function S(t) {
1043
+ function x(t) {
1034
1044
  return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1035
1045
  }
1036
1046
  function k(t, e = W) {
1037
1047
  const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...W, ...e]), r = /* @__PURE__ */ new Set(), o = [];
1038
- for (const i of S(t).split(/\s+/u))
1048
+ for (const i of x(t).split(/\s+/u))
1039
1049
  i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
1040
1050
  return o;
1041
1051
  }
1042
- function C(t, e = {}) {
1043
- if (Gt(t)) return t;
1044
- const n = e.facetKeys, r = y(t.category_names ?? t.category), o = y(t.category_ids), i = Qt(t.facet_hits), a = Object.entries(i).filter(([f]) => !n || n.some((M) => S(M) === S(f))).map(([, f]) => f), s = w(t.name, t.title), c = w(t.brand), u = e.sourceKeywords ?? [], l = [
1052
+ 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 = [
1045
1055
  s,
1046
1056
  c,
1047
1057
  ...r,
@@ -1049,23 +1059,23 @@ function C(t, e = {}) {
1049
1059
  ...y(t.promotions),
1050
1060
  w(t.description),
1051
1061
  ...u
1052
- ].join(" "), d = k(l, e.stopWords), p = w(e.sourceProductType, Zt(r, s, d), d[0]), m = b([...Xt(l, Wt), ...Object.entries(i).filter(([f]) => /colou?r/iu.test(f)).flatMap(([, f]) => k(f, e.stopWords))]), h = b([...a.flatMap((f) => k(f, e.stopWords)), ...y(t.promotions).flatMap((f) => k(f, e.stopWords))]).slice(0, 24);
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);
1053
1063
  return {
1054
1064
  sku: w(t.sku),
1055
1065
  title: s,
1056
1066
  brand: c,
1057
- productType: p,
1067
+ productType: m,
1058
1068
  categoryNames: r,
1059
1069
  categoryIds: o,
1060
1070
  facets: i,
1061
1071
  keywords: b([...u.flatMap((f) => k(f, e.stopWords)), ...d]).slice(0, 12),
1062
1072
  tokens: d,
1063
- colors: m,
1064
- attributes: h,
1065
- price: Yt(t)
1073
+ colors: p,
1074
+ attributes: g,
1075
+ price: Xt(t)
1066
1076
  };
1067
1077
  }
1068
- function ke(t, e = {}) {
1078
+ function we(t, e = {}) {
1069
1079
  const n = w(t.product_type, t.productType), r = w(t.title, n, y(t.keywords).join(" ")), o = b([
1070
1080
  ...y(t.keywords),
1071
1081
  ...y(t.colors),
@@ -1073,7 +1083,7 @@ function ke(t, e = {}) {
1073
1083
  ...y(t.styles),
1074
1084
  ...y(t.attributes)
1075
1085
  ]);
1076
- return C({
1086
+ return M({
1077
1087
  sku: "__photo__",
1078
1088
  name: r,
1079
1089
  category_names: n ? [n] : [],
@@ -1090,38 +1100,38 @@ function ke(t, e = {}) {
1090
1100
  sourceKeywords: o
1091
1101
  });
1092
1102
  }
1093
- function we(t, e = {}) {
1094
- const n = C(t, e);
1103
+ function be(t, e = {}) {
1104
+ const n = M(t, e);
1095
1105
  return b([
1096
1106
  ...e.sourceQueries ?? [],
1097
- j([
1107
+ P([
1098
1108
  n.productType,
1099
1109
  ...n.colors.slice(0, 1),
1100
1110
  ...n.attributes.slice(0, 2)
1101
1111
  ]),
1102
- j([n.productType, ...n.keywords.slice(0, 3)]),
1103
- j([n.categoryNames[n.categoryNames.length - 1], ...n.keywords.slice(0, 2)]),
1104
- j(n.title.split(/\s+/u).slice(0, 6)),
1112
+ P([n.productType, ...n.keywords.slice(0, 3)]),
1113
+ P([n.categoryNames[n.categoryNames.length - 1], ...n.keywords.slice(0, 2)]),
1114
+ P(n.title.split(/\s+/u).slice(0, 6)),
1105
1115
  n.productType
1106
1116
  ].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1107
1117
  }
1108
- function Vt(t, e, n = {}) {
1118
+ function Gt(t, e, n = {}) {
1109
1119
  const r = {
1110
- ...Ht,
1120
+ ...Wt,
1111
1121
  ...n.weights
1112
- }, o = C(e, n), i = [], a = T(t.tokens, o.tokens), s = T(t.keywords, o.tokens), c = te(t.categoryNames, o.categoryNames) || T(V(t.categoryNames), V(o.categoryNames)), u = T(t.attributes, o.attributes), l = T(t.colors, o.colors), d = T(t.attributes, o.tokens), p = ee(t.price, o.price), m = ne(o.sku, n.hitCounts) > 0 ? 1 : 0, h = re(t, o), f = a * r.token + s * r.keyword + c * r.category + u * r.facet + l * r.color + d * r.attribute + p * r.price + m * r.retrieval, M = oe(h ? f : f * 0.35);
1113
- return h && 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"), p > 0.8 && i.push("similar price"), h || i.push("weaker product-type match"), {
1114
- score: Number(M.toFixed(4)),
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);
1123
+ 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
+ score: Number(_.toFixed(4)),
1115
1125
  reasons: i
1116
1126
  };
1117
1127
  }
1118
- function be(t, e, n = {}) {
1119
- const r = C(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1128
+ function _e(t, e, n = {}) {
1129
+ const r = M(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1120
1130
  return e.filter((i) => {
1121
1131
  const a = w(i.sku);
1122
1132
  return a && !o.has(a);
1123
1133
  }).map((i) => {
1124
- const a = Vt(r, i, n);
1134
+ const a = Gt(r, i, n);
1125
1135
  return {
1126
1136
  ...i,
1127
1137
  similarity_score: a.score,
@@ -1129,7 +1139,7 @@ function be(t, e, n = {}) {
1129
1139
  };
1130
1140
  }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
1131
1141
  }
1132
- function Gt(t) {
1142
+ function Qt(t) {
1133
1143
  return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1134
1144
  }
1135
1145
  function w(...t) {
@@ -1139,10 +1149,10 @@ function w(...t) {
1139
1149
  function y(t) {
1140
1150
  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) : [];
1141
1151
  }
1142
- function Qt(t) {
1152
+ function Yt(t) {
1143
1153
  return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, w(n)]).filter(([, e]) => e));
1144
1154
  }
1145
- function Yt(t) {
1155
+ function Xt(t) {
1146
1156
  const e = Number(t.price_discounted);
1147
1157
  if (Number.isFinite(e) && e > 0) return e;
1148
1158
  const n = Number(t.price);
@@ -1151,89 +1161,89 @@ function Yt(t) {
1151
1161
  function b(t) {
1152
1162
  const e = /* @__PURE__ */ new Set(), n = [];
1153
1163
  for (const r of t) {
1154
- const o = S(r);
1164
+ const o = x(r);
1155
1165
  !o || e.has(o) || (e.add(o), n.push(o));
1156
1166
  }
1157
1167
  return n;
1158
1168
  }
1159
- function Xt(t, e) {
1160
- const n = ` ${S(t)} `;
1161
- return e.filter((r) => n.includes(` ${S(r)} `));
1169
+ function Zt(t, e) {
1170
+ const n = ` ${x(t)} `;
1171
+ return e.filter((r) => n.includes(` ${x(r)} `));
1162
1172
  }
1163
- function Zt(t, e, n) {
1164
- const r = S(t[t.length - 1] ?? t[0] ?? "");
1173
+ function te(t, e, n) {
1174
+ const r = x(t[t.length - 1] ?? t[0] ?? "");
1165
1175
  if (r) {
1166
1176
  const o = k(r), i = new Set(k(e));
1167
1177
  return o.find((a) => i.has(a)) ?? o[0] ?? r;
1168
1178
  }
1169
1179
  return n[0] ?? "";
1170
1180
  }
1171
- function j(t) {
1172
- return t.map((e) => S(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1181
+ function P(t) {
1182
+ return t.map((e) => x(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1173
1183
  }
1174
1184
  function V(t) {
1175
1185
  return t.flatMap((e) => k(e));
1176
1186
  }
1177
- function T(t, e) {
1187
+ function A(t, e) {
1178
1188
  const n = b(t), r = new Set(b(e));
1179
1189
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1180
1190
  }
1181
- function te(t, e) {
1191
+ function ee(t, e) {
1182
1192
  const n = b(t), r = new Set(b(e));
1183
1193
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1184
1194
  }
1185
- function ee(t, e) {
1195
+ function ne(t, e) {
1186
1196
  return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1187
1197
  }
1188
- function ne(t, e) {
1198
+ function re(t, e) {
1189
1199
  return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1190
1200
  }
1191
- function re(t, e) {
1201
+ function oe(t, e) {
1192
1202
  if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1193
1203
  const n = new Set(k(t.productType)), r = /* @__PURE__ */ new Set([...k(e.productType), ...e.tokens]);
1194
1204
  return [...n].some((o) => r.has(o));
1195
1205
  }
1196
- function oe(t) {
1206
+ function ie(t) {
1197
1207
  return Math.max(0, Math.min(1, t));
1198
1208
  }
1199
1209
  export {
1200
- ce as A,
1201
- Pt as C,
1202
- ue as D,
1203
- jt as E,
1204
- B as F,
1210
+ ue as A,
1211
+ Ct as C,
1212
+ le as D,
1213
+ Pt as E,
1214
+ R as F,
1205
1215
  ft as I,
1206
- ie as L,
1216
+ ae as L,
1207
1217
  bt as M,
1208
1218
  wt as N,
1209
1219
  Z as O,
1210
- se as P,
1211
- ae as R,
1220
+ ce as P,
1221
+ se as R,
1212
1222
  et as S,
1213
- P as T,
1223
+ C as T,
1214
1224
  ot as _,
1215
- be as a,
1216
- Ct as b,
1217
- he as c,
1218
- ge as d,
1219
- ye as f,
1220
- zt as g,
1225
+ _e as a,
1226
+ Mt as b,
1227
+ ke as c,
1228
+ he as d,
1229
+ ge as f,
1230
+ Lt as g,
1221
1231
  D as h,
1222
- S as i,
1232
+ x as i,
1223
1233
  Tt as j,
1224
1234
  tt as k,
1225
- qt as l,
1226
- Lt as m,
1227
- C as n,
1228
- Vt as o,
1229
- me as p,
1230
- we as r,
1235
+ Jt as l,
1236
+ qt as m,
1237
+ M as n,
1238
+ Gt as o,
1239
+ ye as p,
1240
+ be as r,
1231
1241
  k as s,
1232
- ke as t,
1242
+ we as t,
1233
1243
  v as u,
1234
- pe as v,
1235
- le as w,
1236
- de as x,
1237
- fe as y,
1244
+ me as v,
1245
+ de as w,
1246
+ fe as x,
1247
+ pe as y,
1238
1248
  dt as z
1239
1249
  };