@gengage/assistant-fe 0.6.11 → 0.6.12

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 se(t = self) {
7
+ function ce(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 se(t = self) {
34
34
  });
35
35
  };
36
36
  }
37
- function ce({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
37
+ function ue({ 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, {
@@ -102,7 +102,7 @@ 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 = 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 = {
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 = Q(a.messages), d = {
106
106
  id: String(o || s.id || self.crypto.randomUUID()),
107
107
  started_at: String(s.started_at || ft()),
108
108
  extensions: E(s.extensions) ? { ...s.extensions } : {}
@@ -119,13 +119,13 @@ function pt(t) {
119
119
  };
120
120
  }
121
121
  function mt(t, e) {
122
- const n = G([e])[0];
122
+ const n = Q([e])[0];
123
123
  return n ? {
124
124
  ...t,
125
125
  messages: [...t.messages, n].slice(-50)
126
126
  } : t;
127
127
  }
128
- function G(t) {
128
+ function Q(t) {
129
129
  return Array.isArray(t) ? t.map((e) => {
130
130
  const n = e?.role;
131
131
  return {
@@ -138,24 +138,24 @@ var yt = "gengage:agent:context:";
138
138
  async function gt({ accountId: t, threadId: e, rpc: n }) {
139
139
  const r = await n("memory.get", {
140
140
  tier: "session",
141
- key: Q(t, e)
141
+ key: Y(t, e)
142
142
  });
143
143
  return r && typeof r == "object" && !Array.isArray(r) ? r : {};
144
144
  }
145
145
  async function ht({ accountId: t, threadId: e, extensions: n, rpc: r }) {
146
146
  await r("memory.set", {
147
147
  tier: "session",
148
- key: Q(t, e),
148
+ key: Y(t, e),
149
149
  value: { thread: { extensions: n } }
150
150
  });
151
151
  }
152
- function Q(t, e) {
152
+ function Y(t, e) {
153
153
  return `${yt}${t}:${e}`;
154
154
  }
155
155
  function h(t) {
156
156
  return typeof t == "object" && t !== null && !Array.isArray(t);
157
157
  }
158
- var ue = class {
158
+ var le = class {
159
159
  #t = /* @__PURE__ */ new Map();
160
160
  #e;
161
161
  #r;
@@ -176,14 +176,14 @@ var ue = class {
176
176
  locale: t?.locale || this.#r,
177
177
  parentUrl: this.#o,
178
178
  threadId: n,
179
- incomingContext: kt(o, t?.context)
179
+ incomingContext: wt(o, t?.context)
180
180
  });
181
181
  return this.#t.set(n, i), i;
182
182
  }
183
183
  patch(t, e) {
184
184
  const n = String(t || "default"), r = this.#t.get(n);
185
185
  if (!r) return null;
186
- const o = Y(r, typeof e == "function" ? e(r) : e);
186
+ const o = X(r, typeof e == "function" ? e(r) : e);
187
187
  return this.#t.set(n, o), o;
188
188
  }
189
189
  appendUserMessage(t, e) {
@@ -207,10 +207,10 @@ var ue = class {
207
207
  }), n) : null;
208
208
  }
209
209
  };
210
- function kt(t, e) {
211
- return !h(t) && !h(e) ? {} : Y(h(t) ? t : {}, h(e) ? e : {});
210
+ function wt(t, e) {
211
+ return !h(t) && !h(e) ? {} : X(h(t) ? t : {}, h(e) ? e : {});
212
212
  }
213
- function Y(t, e) {
213
+ function X(t, e) {
214
214
  if (!h(e)) return t;
215
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 {
@@ -235,19 +235,19 @@ function Y(t, e) {
235
235
  messages: Array.isArray(r.messages) ? r.messages.slice(-50) : t.messages ?? []
236
236
  };
237
237
  }
238
- function X(t) {
238
+ function Z(t) {
239
239
  const e = String.fromCharCode(...t);
240
240
  return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
241
241
  }
242
- function z(t) {
243
- return X(new TextEncoder().encode(JSON.stringify(t)));
242
+ function L(t) {
243
+ return Z(new TextEncoder().encode(JSON.stringify(t)));
244
244
  }
245
- async function wt({ accountId: t, devJwtSecret: e, ttlS: n = 300 }) {
245
+ async function kt({ accountId: t, devJwtSecret: e, ttlS: n = 300 }) {
246
246
  if (!e) throw new Error("devJwtSecret is required for local agent mode.");
247
- const r = Math.floor(Date.now() / 1e3), o = `${z({
247
+ const r = Math.floor(Date.now() / 1e3), o = `${L({
248
248
  alg: "HS256",
249
249
  typ: "JWT"
250
- })}.${z({
250
+ })}.${L({
251
251
  sub: t,
252
252
  iat: r,
253
253
  exp: r + n,
@@ -257,12 +257,12 @@ async function wt({ accountId: t, devJwtSecret: e, ttlS: n = 300 }) {
257
257
  name: "HMAC",
258
258
  hash: "SHA-256"
259
259
  }, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
260
- return `${o}.${X(new Uint8Array(a))}`;
260
+ return `${o}.${Z(new Uint8Array(a))}`;
261
261
  }
262
262
  function bt({ accountId: t, devJwtSecret: e, tokenBrokerUrl: n, tokenBrokerAudience: r, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
263
263
  let a = null;
264
264
  return async ({ signal: s, parentUrl: c } = {}) => {
265
- if (e) return wt({
265
+ if (e) return kt({
266
266
  accountId: t,
267
267
  devJwtSecret: e
268
268
  });
@@ -324,7 +324,7 @@ function xt(t) {
324
324
  return null;
325
325
  }
326
326
  }
327
- var L = {
327
+ var q = {
328
328
  unauthorized: {
329
329
  code: "auth",
330
330
  message: "Assistant authentication failed. Please retry."
@@ -369,14 +369,14 @@ var L = {
369
369
  code: "invalid_request",
370
370
  message: "The assistant request was too large."
371
371
  }
372
- }, Z = class extends Error {
372
+ }, tt = class extends Error {
373
373
  constructor(t, e, n = {}) {
374
374
  super(e), this.name = "AgentError", this.code = t, this.source = n.source || "agent", n.sourceCode && (this.sourceCode = n.sourceCode), n.detail !== void 0 && (this.detail = n.detail);
375
375
  }
376
376
  };
377
- function tt(t) {
378
- const e = String(t?.code || "upstream_llm"), n = L[e] || L.upstream_llm;
379
- return new Z(n.code, n.message, {
377
+ function et(t) {
378
+ const e = String(t?.code || "upstream_llm"), n = q[e] || q.upstream_llm;
379
+ return new tt(n.code, n.message, {
380
380
  source: "be",
381
381
  sourceCode: e,
382
382
  detail: t?.detail
@@ -384,13 +384,13 @@ function tt(t) {
384
384
  }
385
385
  function Tt(t, e) {
386
386
  const n = e?.error && typeof e.error == "object" ? e.error : {};
387
- return tt({
387
+ return et({
388
388
  code: String(n.code || At(t)),
389
389
  detail: n.detail
390
390
  });
391
391
  }
392
- function le(t) {
393
- return t instanceof Z ? {
392
+ function de(t) {
393
+ return t instanceof tt ? {
394
394
  type: "error",
395
395
  code: t.code,
396
396
  message: t.message
@@ -403,7 +403,7 @@ function le(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 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 }) {
406
+ async function fe({ 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,
@@ -462,18 +462,18 @@ async function Pt(t) {
462
462
  `);
463
463
  for (; c >= 0; ) {
464
464
  const u = r.slice(0, c).trim();
465
- r = r.slice(c + 1), u && q(JSON.parse(u), o), c = r.indexOf(`
465
+ r = r.slice(c + 1), u && J(JSON.parse(u), o), c = r.indexOf(`
466
466
  `);
467
467
  }
468
468
  }
469
469
  const i = r.trim();
470
- return i && q(JSON.parse(i), o), o;
470
+ return i && J(JSON.parse(i), o), o;
471
471
  }
472
- function q(t, e) {
473
- if (t._error) throw tt(t._error);
472
+ function J(t, e) {
473
+ if (t._error) throw et(t._error);
474
474
  t._end || Object.assign(e, t);
475
475
  }
476
- function fe(t = {}) {
476
+ function pe(t = {}) {
477
477
  return {
478
478
  type: "metadata",
479
479
  ...t
@@ -493,7 +493,7 @@ function Ct(t) {
493
493
  ...t
494
494
  };
495
495
  }
496
- function pe(t) {
496
+ function me(t) {
497
497
  return {
498
498
  type: "action",
499
499
  action: t
@@ -506,18 +506,18 @@ function Mt(t, e) {
506
506
  message: e
507
507
  };
508
508
  }
509
- function et() {
509
+ function nt() {
510
510
  return { type: "done" };
511
511
  }
512
- function vt(t, e) {
512
+ function Nt(t, e) {
513
513
  return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
514
514
  }
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
+ async function ye({ 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 = Lt(t);
517
517
  n.appendUserMessage(l, d);
518
- const m = vt(e.flows, t);
518
+ const m = Nt(e.flows, t);
519
519
  if (!m)
520
- return i(Mt("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(nt()), {
521
521
  steps: 0,
522
522
  productSkusEmitted: []
523
523
  };
@@ -536,6 +536,7 @@ async function me({ request: t, accountModule: e, contextStore: n, beClient: r,
536
536
  toolBridge: o,
537
537
  emit: i,
538
538
  rpc: a,
539
+ adapters: e.adapters || {},
539
540
  ...s ? { signal: s } : {}
540
541
  };
541
542
  return await U(m, p, g), p.committed || await $(p, g), await a("beacon.send", {
@@ -554,11 +555,11 @@ async function me({ request: t, accountModule: e, contextStore: n, beClient: r,
554
555
  async function U(t, e, n) {
555
556
  for (const r of t) {
556
557
  if (n.signal?.aborted) return;
557
- e.steps += 1, await Nt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
558
+ e.steps += 1, await vt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
558
559
  }
559
560
  }
560
- async function Nt(t, e, n) {
561
- const r = D(e);
561
+ async function vt(t, e, n) {
562
+ const r = F(e);
562
563
  if (t.kind === "be_op") {
563
564
  await Ot(t, e, n, r);
564
565
  return;
@@ -567,32 +568,36 @@ async function Nt(t, e, n) {
567
568
  await Bt(t, e, n, r);
568
569
  return;
569
570
  }
571
+ if (t.kind === "adapter") {
572
+ await Rt(t, e, n, r);
573
+ return;
574
+ }
570
575
  if (t.kind === "emit") {
571
- Rt(t, e, n);
576
+ Ut(t, e, n);
572
577
  return;
573
578
  }
574
579
  if (t.kind === "branch") {
575
- await Ut(t, e, n, r);
580
+ await $t(t, e, n, r);
576
581
  return;
577
582
  }
578
583
  if (t.kind === "parallel") {
579
- await $t(t, e, n);
584
+ await Dt(t, e, n);
580
585
  return;
581
586
  }
582
587
  if (t.kind === "refusal") {
583
- await Dt(t, e, n, r);
588
+ await Ft(t, e, n, r);
584
589
  return;
585
590
  }
586
- t.kind === "commit" && await Ft(t, e, n);
591
+ t.kind === "commit" && await zt(t, e, n);
587
592
  }
588
593
  async function Ot(t, e, n, r) {
589
594
  const o = performance.now();
590
595
  let i;
591
- const a = I(t.cacheTtlS, r), s = I(t.cacheKey, r);
596
+ const a = T(t.cacheTtlS, r), s = T(t.cacheKey, r);
592
597
  try {
593
598
  i = await n.beClient.invoke({
594
599
  op: t.op,
595
- input: I(t.input, r),
600
+ input: T(t.input, r),
596
601
  ...a !== void 0 ? { cacheTtlS: a } : {},
597
602
  ...s !== void 0 ? { cacheKey: s } : {},
598
603
  ...n.signal ? { signal: n.signal } : {}
@@ -610,7 +615,7 @@ async function Ot(t, e, n, r) {
610
615
  };
611
616
  throw await n.rpc("beacon.send", m), u;
612
617
  }
613
- t.out && (e.bag[t.out] = i), nt(t, i, e, n.contextStore);
618
+ t.out && (e.bag[t.out] = i), D(t, i, e, n.contextStore);
614
619
  const c = {
615
620
  type: "agentOp",
616
621
  threadId: e.threadId,
@@ -623,35 +628,41 @@ async function Ot(t, e, n, r) {
623
628
  await n.rpc("beacon.send", c);
624
629
  }
625
630
  async function Bt(t, e, n, r) {
626
- const o = await n.toolBridge.invoke(t.name, I(t.input, r));
627
- t.out && (e.bag[t.out] = o), nt(t, o, e, n.contextStore);
631
+ const o = await n.toolBridge.invoke(t.name, T(t.input, r));
632
+ t.out && (e.bag[t.out] = o), D(t, o, e, n.contextStore);
633
+ }
634
+ async function Rt(t, e, n, r) {
635
+ const o = n.adapters?.[t.name];
636
+ if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
637
+ const i = await o(T(t.input, r), r);
638
+ t.out && (e.bag[t.out] = i), D(t, i, e, n.contextStore);
628
639
  }
629
- function Rt(t, e, n) {
630
- const r = t.build(D(e));
631
- Lt(r, e.productSkusEmitted), n.emit(r);
640
+ function Ut(t, e, n) {
641
+ const r = t.build(F(e));
642
+ qt(r, e.productSkusEmitted), n.emit(r);
632
643
  }
633
- async function Ut(t, e, n, r) {
634
- const o = String(I(t.on, r) || "default");
644
+ async function $t(t, e, n, r) {
645
+ const o = String(T(t.on, r) || "default");
635
646
  await U(t.cases[o] || t.cases.default || [], e, n);
636
647
  }
637
- async function $t(t, e, n) {
648
+ async function Dt(t, e, n) {
638
649
  await Promise.all(t.steps.map((r) => U(r, e, n)));
639
650
  }
640
- async function Dt(t, e, n, r) {
641
- n.emit(C(I(t.message, r), !0)), await $(e, n);
651
+ async function Ft(t, e, n, r) {
652
+ n.emit(C(T(t.message, r), !0)), await $(e, n);
642
653
  }
643
- async function Ft(t, e, n) {
654
+ async function zt(t, e, n) {
644
655
  await $(e, n);
645
656
  }
646
657
  async function $(t, { contextStore: e, emit: n }) {
647
- t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, n(et()));
658
+ t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, n(nt()));
648
659
  }
649
- function nt(t, e, n, r) {
660
+ function D(t, e, n, r) {
650
661
  if (typeof t.patch != "function") return;
651
- const o = t.patch(n.context, e, D(n));
662
+ const o = t.patch(n.context, e, F(n));
652
663
  o && (n.context = r.patch(n.threadId, o) || n.context);
653
664
  }
654
- function D(t) {
665
+ function F(t) {
655
666
  return {
656
667
  request: t.request,
657
668
  context: t.context,
@@ -659,10 +670,10 @@ function D(t) {
659
670
  accountConfig: t.accountConfig
660
671
  };
661
672
  }
662
- function I(t, e) {
673
+ function T(t, e) {
663
674
  return typeof t == "function" ? t(e) : t;
664
675
  }
665
- function zt(t) {
676
+ function Lt(t) {
666
677
  const e = t?.payload;
667
678
  if (typeof e == "string") return e;
668
679
  if (e && typeof e == "object" && "text" in e) {
@@ -671,7 +682,7 @@ function zt(t) {
671
682
  }
672
683
  return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
673
684
  }
674
- function Lt(t, e) {
685
+ function qt(t, e) {
675
686
  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;
676
687
  if (Array.isArray(a)) {
677
688
  for (const s of a) if (s && typeof s == "object") {
@@ -680,7 +691,7 @@ function Lt(t, e) {
680
691
  }
681
692
  }
682
693
  }
683
- function ye(t) {
694
+ function ge(t) {
684
695
  return { invoke(e, n) {
685
696
  return t("tool.invoke", {
686
697
  name: e,
@@ -691,33 +702,33 @@ function ye(t) {
691
702
  function rt(t) {
692
703
  return t && typeof t == "object" && !Array.isArray(t) ? t : null;
693
704
  }
694
- function F(t) {
705
+ function z(t) {
695
706
  const e = rt(t);
696
707
  if (!e) return null;
697
- const n = T(e.sku, e.SKU);
708
+ const n = A(e.sku, e.SKU);
698
709
  if (!n) return null;
699
710
  const r = {
700
711
  sku: n,
701
- name: T(e.name, e.title, e.short_name, n) || n,
702
- url: T(e.url) || ""
703
- }, o = Array.isArray(e.images) ? e.images : void 0, i = T(e.imageUrl, e.image_url, e.image, o?.[0]);
712
+ name: A(e.name, e.title, e.short_name, n) || n,
713
+ url: A(e.url) || ""
714
+ }, o = Array.isArray(e.images) ? e.images : void 0, i = A(e.imageUrl, e.image_url, e.image, o?.[0]);
704
715
  i && (r.imageUrl = i), o && o.length > 1 && (r.images = o.filter((f) => !!f).map(String));
705
716
  const a = j(e.price_discounted), s = j(e.price), c = a || s;
706
717
  c > 0 && (r.price = String(c));
707
718
  const u = a > 0 ? s : 0;
708
719
  u > 0 && (r.originalPrice = String(u));
709
- const l = T(e.brand);
720
+ const l = A(e.brand);
710
721
  l && (r.brand = l);
711
722
  const d = j(e.rating);
712
723
  d > 0 && (r.rating = d);
713
724
  const m = j(e.review_count) || j(e.reviewCount);
714
725
  m > 0 && (r.reviewCount = m);
715
- const p = T(e.cart_code, e.cartCode);
726
+ const p = A(e.cart_code, e.cartCode);
716
727
  p && (r.cartCode = p), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
717
728
  const g = e.category_names;
718
729
  return Array.isArray(g) && (r.categoryNames = g.map(String)), r;
719
730
  }
720
- function qt(t) {
731
+ function Jt(t) {
721
732
  const e = rt(t);
722
733
  if (!e) return t;
723
734
  const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
@@ -737,9 +748,9 @@ function qt(t) {
737
748
  return a;
738
749
  }
739
750
  function ot(t) {
740
- return Array.isArray(t) ? t.map(qt).filter((e) => !!e) : [];
751
+ return Array.isArray(t) ? t.map(Jt).filter((e) => !!e) : [];
741
752
  }
742
- function T(...t) {
753
+ function A(...t) {
743
754
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
744
755
  return "";
745
756
  }
@@ -747,12 +758,12 @@ function j(t) {
747
758
  const e = Number(t);
748
759
  return Number.isFinite(e) ? e : 0;
749
760
  }
750
- function J(t) {
761
+ function K(t) {
751
762
  return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
752
763
  }
753
- function Jt(t = []) {
764
+ function Kt(t = []) {
754
765
  const e = {}, n = [];
755
- return (Array.isArray(t) ? t.map(F).filter((r) => !!r) : []).forEach((r, o) => {
766
+ return (Array.isArray(t) ? t.map(z).filter((r) => !!r) : []).forEach((r, o) => {
756
767
  const i = `product-${o.toString()}`;
757
768
  n.push(i);
758
769
  const a = {
@@ -784,7 +795,7 @@ function Jt(t = []) {
784
795
  }
785
796
  };
786
797
  }
787
- function ge(t) {
798
+ function he(t) {
788
799
  return {
789
800
  widget: "chat",
790
801
  panelHint: "panel",
@@ -792,13 +803,13 @@ function ge(t) {
792
803
  root: "root",
793
804
  elements: { root: {
794
805
  type: "ProductDetailsPanel",
795
- props: { product: F(t) || t || {} }
806
+ props: { product: z(t) || t || {} }
796
807
  } }
797
808
  }
798
809
  };
799
810
  }
800
- function he(t = {}) {
801
- const e = (t.multiple_product_details || t.products || []).map(F).filter((r) => !!r), n = t.table || {};
811
+ function we(t = {}) {
812
+ const e = (t.multiple_product_details || t.products || []).map(z).filter((r) => !!r), n = t.table || {};
802
813
  return {
803
814
  widget: "chat",
804
815
  panelHint: "panel",
@@ -813,8 +824,8 @@ function he(t = {}) {
813
824
  label: r,
814
825
  values: Array.isArray(o) ? o.map(String) : [String(o ?? "")]
815
826
  })),
816
- highlights: J(t.key_differences),
817
- specialCases: J(t.special_considerations),
827
+ highlights: K(t.key_differences),
828
+ specialCases: K(t.special_considerations),
818
829
  recommendedText: t.recommended_choice,
819
830
  productActions: Object.fromEntries(e.map((r) => [r.sku, {
820
831
  title: r.name,
@@ -852,7 +863,7 @@ function ke(t = []) {
852
863
  }
853
864
  };
854
865
  }
855
- function v(t) {
866
+ function N(t) {
856
867
  const e = t?.payload;
857
868
  if (typeof e == "string") return e;
858
869
  if (e && typeof e == "object" && "text" in e) {
@@ -862,30 +873,30 @@ function v(t) {
862
873
  const n = t?.action;
863
874
  return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
864
875
  }
865
- function Kt(t) {
876
+ function Wt(t) {
866
877
  return Object.freeze([...t]);
867
878
  }
868
879
  function S(t) {
869
880
  return t && typeof t == "object" ? t : {};
870
881
  }
871
- function N(t) {
882
+ function v(t) {
872
883
  return t && typeof t == "object" ? t : {};
873
884
  }
874
- function K(t) {
885
+ function W(t) {
875
886
  return t.thread.extensions.beauty_profile;
876
887
  }
877
- var we = Kt([{
888
+ var be = Wt([{
878
889
  kind: "be_op",
879
890
  op: "beauty-consulting-turn",
880
891
  input: ({ request: t, context: e }) => ({
881
- utterance: v(t),
892
+ utterance: N(t),
882
893
  prior_messages: e.messages.slice(-10),
883
- profile: K(e),
884
- candidate_products: Ht(t),
894
+ profile: W(e),
895
+ candidate_products: Vt(t),
885
896
  locale: e.meta.locale
886
897
  }),
887
898
  out: "consultation",
888
- patch: W
899
+ patch: H
889
900
  }, {
890
901
  kind: "branch",
891
902
  on: ({ bag: t }) => S(t.consultation).consultation_state?.stage || "answer",
@@ -908,7 +919,7 @@ var we = Kt([{
908
919
  input: ({ request: t, bag: e, context: n }) => {
909
920
  const r = S(e.consultation);
910
921
  return {
911
- query: r.search_params?.query || v(t),
922
+ query: r.search_params?.query || N(t),
912
923
  facets: r.search_params?.facets || {},
913
924
  limit: 12,
914
925
  locale: n.meta.locale
@@ -916,31 +927,31 @@ var we = Kt([{
916
927
  },
917
928
  out: "products",
918
929
  patch: (t, e) => {
919
- const n = N(e);
930
+ const n = v(e);
920
931
  return { panel: {
921
932
  ...t.panel,
922
- screen_sku_list: O(n).map((r) => Wt(r)).filter((r) => !!r),
933
+ screen_sku_list: O(n).map((r) => Ht(r)).filter((r) => !!r),
923
934
  last_search: { query: n.query || "" }
924
935
  } };
925
936
  }
926
937
  },
927
938
  {
928
939
  kind: "emit",
929
- build: ({ bag: t }) => Ct(Jt(O(N(t.products))))
940
+ build: ({ bag: t }) => Ct(Kt(O(v(t.products))))
930
941
  },
931
942
  {
932
943
  kind: "be_op",
933
944
  op: "beauty-consulting-turn",
934
945
  input: ({ request: t, context: e, bag: n }) => ({
935
- utterance: v(t),
946
+ utterance: N(t),
936
947
  prior_messages: e.messages.slice(-10),
937
- profile: K(e),
938
- candidate_products: ot(O(N(n.products)).slice(0, 12)),
948
+ profile: W(e),
949
+ candidate_products: ot(O(v(n.products)).slice(0, 12)),
939
950
  locale: e.meta.locale
940
951
  }),
941
952
  out: "answer",
942
953
  patch: (t, e) => {
943
- const n = W(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
954
+ const n = H(t, e), r = (S(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
944
955
  return {
945
956
  ...n || {},
946
957
  panel: {
@@ -968,7 +979,7 @@ var we = Kt([{
968
979
  }, { kind: "commit" }]
969
980
  }
970
981
  }]);
971
- function W(t, e) {
982
+ function H(t, e) {
972
983
  const n = S(e).consultation_state?.captured_profile;
973
984
  if (!n) return null;
974
985
  const r = t.thread.extensions.beauty_profile && typeof t.thread.extensions.beauty_profile == "object" ? t.thread.extensions.beauty_profile : {};
@@ -986,20 +997,20 @@ function W(t, e) {
986
997
  function O(t) {
987
998
  return Array.isArray(t?.products) ? t.products : [];
988
999
  }
989
- function Wt(t) {
1000
+ function Ht(t) {
990
1001
  if (t && typeof t == "object" && "sku" in t) {
991
1002
  const e = t.sku;
992
1003
  if (typeof e == "string") return e;
993
1004
  }
994
1005
  }
995
- function Ht(t) {
1006
+ function Vt(t) {
996
1007
  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;
997
1008
  return Array.isArray(r) ? ot(r.slice(0, 12)) : void 0;
998
1009
  }
999
1010
  function B(t) {
1000
1011
  return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
1001
1012
  }
1002
- var H = /* @__PURE__ */ new Set([
1013
+ var V = /* @__PURE__ */ new Set([
1003
1014
  "and",
1004
1015
  "are",
1005
1016
  "box",
@@ -1009,7 +1020,7 @@ var H = /* @__PURE__ */ new Set([
1009
1020
  "gifts",
1010
1021
  "the",
1011
1022
  "with"
1012
- ]), Vt = {
1023
+ ]), Gt = {
1013
1024
  token: 0.26,
1014
1025
  keyword: 0.22,
1015
1026
  category: 0.18,
@@ -1018,7 +1029,7 @@ var H = /* @__PURE__ */ new Set([
1018
1029
  attribute: 0.06,
1019
1030
  price: 0.08,
1020
1031
  retrieval: 0.08
1021
- }, Gt = [
1032
+ }, Qt = [
1022
1033
  "amber",
1023
1034
  "beige",
1024
1035
  "black",
@@ -1045,40 +1056,40 @@ var H = /* @__PURE__ */ new Set([
1045
1056
  function x(t) {
1046
1057
  return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1047
1058
  }
1048
- function k(t, e = H) {
1049
- const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...H, ...e]), r = /* @__PURE__ */ new Set(), o = [];
1059
+ function w(t, e = V) {
1060
+ const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...V, ...e]), r = /* @__PURE__ */ new Set(), o = [];
1050
1061
  for (const i of x(t).split(/\s+/u))
1051
1062
  i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
1052
1063
  return o;
1053
1064
  }
1054
1065
  function M(t, e = {}) {
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 = [
1066
+ if (Xt(t)) return t;
1067
+ const n = e.facetKeys, r = y(t.category_names ?? t.category), o = y(t.category_ids), i = Zt(t.facet_hits), a = Object.entries(i).filter(([f]) => !n || n.some((_) => x(_) === x(f))).map(([, f]) => f), s = k(t.name, t.title), c = k(t.brand), u = e.sourceKeywords ?? [], l = [
1057
1068
  s,
1058
1069
  c,
1059
1070
  ...r,
1060
1071
  ...a,
1061
1072
  ...y(t.promotions),
1062
- w(t.description),
1073
+ k(t.description),
1063
1074
  ...u
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);
1075
+ ].join(" "), d = w(l, e.stopWords), m = k(e.sourceProductType, ne(r, s, d), d[0]), p = b([...ee(l, Qt), ...Object.entries(i).filter(([f]) => /colou?r/iu.test(f)).flatMap(([, f]) => w(f, e.stopWords))]), g = b([...a.flatMap((f) => w(f, e.stopWords)), ...y(t.promotions).flatMap((f) => w(f, e.stopWords))]).slice(0, 24);
1065
1076
  return {
1066
- sku: w(t.sku),
1077
+ sku: k(t.sku),
1067
1078
  title: s,
1068
1079
  brand: c,
1069
1080
  productType: m,
1070
1081
  categoryNames: r,
1071
1082
  categoryIds: o,
1072
1083
  facets: i,
1073
- keywords: b([...u.flatMap((f) => k(f, e.stopWords)), ...d]).slice(0, 12),
1084
+ keywords: b([...u.flatMap((f) => w(f, e.stopWords)), ...d]).slice(0, 12),
1074
1085
  tokens: d,
1075
1086
  colors: p,
1076
1087
  attributes: g,
1077
- price: Zt(t)
1088
+ price: te(t)
1078
1089
  };
1079
1090
  }
1080
- function be(t, e = {}) {
1081
- const n = w(t.product_type, t.productType), r = w(t.title, n, y(t.keywords).join(" ")), o = b([
1091
+ function _e(t, e = {}) {
1092
+ const n = k(t.product_type, t.productType), r = k(t.title, n, y(t.keywords).join(" ")), o = b([
1082
1093
  ...y(t.keywords),
1083
1094
  ...y(t.colors),
1084
1095
  ...y(t.materials),
@@ -1102,7 +1113,7 @@ function be(t, e = {}) {
1102
1113
  sourceKeywords: o
1103
1114
  });
1104
1115
  }
1105
- function _e(t, e = {}) {
1116
+ function Se(t, e = {}) {
1106
1117
  const n = M(t, e);
1107
1118
  return b([
1108
1119
  ...e.sourceQueries ?? [],
@@ -1117,23 +1128,23 @@ function _e(t, e = {}) {
1117
1128
  n.productType
1118
1129
  ].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1119
1130
  }
1120
- function Qt(t, e, n = {}) {
1131
+ function Yt(t, e, n = {}) {
1121
1132
  const r = {
1122
- ...Vt,
1133
+ ...Gt,
1123
1134
  ...n.weights
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);
1135
+ }, o = M(e, n), i = [], a = I(t.tokens, o.tokens), s = I(t.keywords, o.tokens), c = re(t.categoryNames, o.categoryNames) || I(G(t.categoryNames), G(o.categoryNames)), u = I(t.attributes, o.attributes), l = I(t.colors, o.colors), d = I(t.attributes, o.tokens), m = oe(t.price, o.price), p = ie(o.sku, n.hitCounts) > 0 ? 1 : 0, g = ae(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, _ = se(g ? f : f * 0.35);
1125
1136
  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"), {
1126
1137
  score: Number(_.toFixed(4)),
1127
1138
  reasons: i
1128
1139
  };
1129
1140
  }
1130
- function Se(t, e, n = {}) {
1141
+ function xe(t, e, n = {}) {
1131
1142
  const r = M(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1132
1143
  return e.filter((i) => {
1133
- const a = w(i.sku);
1144
+ const a = k(i.sku);
1134
1145
  return a && !o.has(a);
1135
1146
  }).map((i) => {
1136
- const a = Qt(r, i, n);
1147
+ const a = Yt(r, i, n);
1137
1148
  return {
1138
1149
  ...i,
1139
1150
  similarity_score: a.score,
@@ -1141,20 +1152,20 @@ function Se(t, e, n = {}) {
1141
1152
  };
1142
1153
  }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
1143
1154
  }
1144
- function Yt(t) {
1155
+ function Xt(t) {
1145
1156
  return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1146
1157
  }
1147
- function w(...t) {
1158
+ function k(...t) {
1148
1159
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
1149
1160
  return "";
1150
1161
  }
1151
1162
  function y(t) {
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) : [];
1153
- }
1154
- function Xt(t) {
1155
- return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, w(n)]).filter(([, e]) => e));
1163
+ return Array.isArray(t) ? t.map((e) => k(e)).filter(Boolean) : typeof t == "string" && t.trim() ? t.split(/[,;/|]+/u).map((e) => e.trim()).filter(Boolean) : [];
1156
1164
  }
1157
1165
  function Zt(t) {
1166
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, k(n)]).filter(([, e]) => e));
1167
+ }
1168
+ function te(t) {
1158
1169
  const e = Number(t.price_discounted);
1159
1170
  if (Number.isFinite(e) && e > 0) return e;
1160
1171
  const n = Number(t.price);
@@ -1168,14 +1179,14 @@ function b(t) {
1168
1179
  }
1169
1180
  return n;
1170
1181
  }
1171
- function te(t, e) {
1182
+ function ee(t, e) {
1172
1183
  const n = ` ${x(t)} `;
1173
1184
  return e.filter((r) => n.includes(` ${x(r)} `));
1174
1185
  }
1175
- function ee(t, e, n) {
1186
+ function ne(t, e, n) {
1176
1187
  const r = x(t[t.length - 1] ?? t[0] ?? "");
1177
1188
  if (r) {
1178
- const o = k(r), i = new Set(k(e));
1189
+ const o = w(r), i = new Set(w(e));
1179
1190
  return o.find((a) => i.has(a)) ?? o[0] ?? r;
1180
1191
  }
1181
1192
  return n[0] ?? "";
@@ -1183,69 +1194,69 @@ function ee(t, e, n) {
1183
1194
  function P(t) {
1184
1195
  return t.map((e) => x(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1185
1196
  }
1186
- function V(t) {
1187
- return t.flatMap((e) => k(e));
1197
+ function G(t) {
1198
+ return t.flatMap((e) => w(e));
1188
1199
  }
1189
- function A(t, e) {
1200
+ function I(t, e) {
1190
1201
  const n = b(t), r = new Set(b(e));
1191
1202
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1192
1203
  }
1193
- function ne(t, e) {
1204
+ function re(t, e) {
1194
1205
  const n = b(t), r = new Set(b(e));
1195
1206
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1196
1207
  }
1197
- function re(t, e) {
1208
+ function oe(t, e) {
1198
1209
  return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1199
1210
  }
1200
- function oe(t, e) {
1211
+ function ie(t, e) {
1201
1212
  return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1202
1213
  }
1203
- function ie(t, e) {
1214
+ function ae(t, e) {
1204
1215
  if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1205
- const n = new Set(k(t.productType)), r = /* @__PURE__ */ new Set([...k(e.productType), ...e.tokens]);
1216
+ const n = new Set(w(t.productType)), r = /* @__PURE__ */ new Set([...w(e.productType), ...e.tokens]);
1206
1217
  return [...n].some((o) => r.has(o));
1207
1218
  }
1208
- function ae(t) {
1219
+ function se(t) {
1209
1220
  return Math.max(0, Math.min(1, t));
1210
1221
  }
1211
1222
  export {
1212
- le as A,
1223
+ de as A,
1213
1224
  Mt as C,
1214
- de as D,
1225
+ fe as D,
1215
1226
  Ct as E,
1216
1227
  R as F,
1217
1228
  ft as I,
1218
- se as L,
1229
+ ce as L,
1219
1230
  bt as M,
1220
- wt as N,
1221
- Z as O,
1222
- ue as P,
1223
- ce as R,
1224
- et as S,
1231
+ kt as N,
1232
+ tt as O,
1233
+ le as P,
1234
+ ue as R,
1235
+ nt as S,
1225
1236
  C as T,
1226
1237
  ot as _,
1227
- Se as a,
1228
- vt as b,
1229
- we as c,
1238
+ xe as a,
1239
+ Nt as b,
1240
+ be as c,
1230
1241
  ke as d,
1231
- he as f,
1232
- qt as g,
1233
- F as h,
1242
+ we as f,
1243
+ Jt as g,
1244
+ z as h,
1234
1245
  x as i,
1235
1246
  Tt as j,
1236
- tt as k,
1237
- Kt as l,
1238
- Jt as m,
1247
+ et as k,
1248
+ Wt as l,
1249
+ Kt as m,
1239
1250
  M as n,
1240
- Qt as o,
1241
- ge as p,
1242
- _e as r,
1243
- k as s,
1244
- be as t,
1245
- v as u,
1246
- ye as v,
1247
- fe as w,
1248
- pe as x,
1249
- me as y,
1251
+ Yt as o,
1252
+ he as p,
1253
+ Se as r,
1254
+ w as s,
1255
+ _e as t,
1256
+ N as u,
1257
+ ge as v,
1258
+ pe as w,
1259
+ me as x,
1260
+ ye as y,
1250
1261
  dt as z
1251
1262
  };