@gengage/assistant-fe 0.6.10 → 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 ae(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 ae(t = self) {
34
34
  });
35
35
  };
36
36
  }
37
- function se({ 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 ce = class {
158
+ var le = class {
159
159
  #t = /* @__PURE__ */ new Map();
160
160
  #e;
161
161
  #r;
@@ -176,14 +176,14 @@ var ce = 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 ce = 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 ue(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 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 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,
@@ -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();
@@ -460,18 +462,18 @@ async function jt(t) {
460
462
  `);
461
463
  for (; c >= 0; ) {
462
464
  const u = r.slice(0, c).trim();
463
- 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(`
464
466
  `);
465
467
  }
466
468
  }
467
469
  const i = r.trim();
468
- return i && q(JSON.parse(i), o), o;
470
+ return i && J(JSON.parse(i), o), o;
469
471
  }
470
- function q(t, e) {
471
- if (t._error) throw tt(t._error);
472
+ function J(t, e) {
473
+ if (t._error) throw et(t._error);
472
474
  t._end || Object.assign(e, t);
473
475
  }
474
- function de(t = {}) {
476
+ function pe(t = {}) {
475
477
  return {
476
478
  type: "metadata",
477
479
  ...t
@@ -485,37 +487,37 @@ 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 me(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,
504
506
  message: e
505
507
  };
506
508
  }
507
- function et() {
509
+ function nt() {
508
510
  return { type: "done" };
509
511
  }
510
- function Mt(t, e) {
512
+ function Nt(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 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);
515
517
  n.appendUserMessage(l, d);
516
- const m = Mt(e.flows, t);
518
+ const m = Nt(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(nt()), {
519
521
  steps: 0,
520
522
  productSkusEmitted: []
521
523
  };
@@ -534,6 +536,7 @@ async function pe({ request: t, accountModule: e, contextStore: n, beClient: r,
534
536
  toolBridge: o,
535
537
  emit: i,
536
538
  rpc: a,
539
+ adapters: e.adapters || {},
537
540
  ...s ? { signal: s } : {}
538
541
  };
539
542
  return await U(m, p, g), p.committed || await $(p, g), await a("beacon.send", {
@@ -558,39 +561,43 @@ async function U(t, e, n) {
558
561
  async function vt(t, e, n) {
559
562
  const r = F(e);
560
563
  if (t.kind === "be_op") {
561
- await Nt(t, e, n, r);
564
+ await Ot(t, e, n, r);
562
565
  return;
563
566
  }
564
567
  if (t.kind === "tool") {
565
- await Ot(t, e, n, r);
568
+ await Bt(t, e, n, r);
569
+ return;
570
+ }
571
+ if (t.kind === "adapter") {
572
+ await Rt(t, e, n, r);
566
573
  return;
567
574
  }
568
575
  if (t.kind === "emit") {
569
- Bt(t, e, n);
576
+ Ut(t, e, n);
570
577
  return;
571
578
  }
572
579
  if (t.kind === "branch") {
573
- await Rt(t, e, n, r);
580
+ await $t(t, e, n, r);
574
581
  return;
575
582
  }
576
583
  if (t.kind === "parallel") {
577
- await Ut(t, e, n);
584
+ await Dt(t, e, n);
578
585
  return;
579
586
  }
580
587
  if (t.kind === "refusal") {
581
- await $t(t, e, n, r);
588
+ await Ft(t, e, n, r);
582
589
  return;
583
590
  }
584
- t.kind === "commit" && await Ft(t, e, n);
591
+ t.kind === "commit" && await zt(t, e, n);
585
592
  }
586
- async function Nt(t, e, n, r) {
593
+ async function Ot(t, e, n, r) {
587
594
  const o = performance.now();
588
595
  let i;
589
- const a = I(t.cacheTtlS, r), s = I(t.cacheKey, r);
596
+ const a = T(t.cacheTtlS, r), s = T(t.cacheKey, r);
590
597
  try {
591
598
  i = await n.beClient.invoke({
592
599
  op: t.op,
593
- input: I(t.input, r),
600
+ input: T(t.input, r),
594
601
  ...a !== void 0 ? { cacheTtlS: a } : {},
595
602
  ...s !== void 0 ? { cacheKey: s } : {},
596
603
  ...n.signal ? { signal: n.signal } : {}
@@ -608,7 +615,7 @@ async function Nt(t, e, n, r) {
608
615
  };
609
616
  throw await n.rpc("beacon.send", m), u;
610
617
  }
611
- 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);
612
619
  const c = {
613
620
  type: "agentOp",
614
621
  threadId: e.threadId,
@@ -620,31 +627,37 @@ async function Nt(t, e, n, r) {
620
627
  };
621
628
  await n.rpc("beacon.send", c);
622
629
  }
623
- async function Ot(t, e, n, r) {
624
- const o = await n.toolBridge.invoke(t.name, I(t.input, r));
625
- t.out && (e.bag[t.out] = o), nt(t, o, e, n.contextStore);
630
+ async function Bt(t, e, n, r) {
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);
626
639
  }
627
- function Bt(t, e, n) {
640
+ function Ut(t, e, n) {
628
641
  const r = t.build(F(e));
629
- zt(r, e.productSkusEmitted), n.emit(r);
642
+ qt(r, e.productSkusEmitted), n.emit(r);
630
643
  }
631
- async function Rt(t, e, n, r) {
632
- 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");
633
646
  await U(t.cases[o] || t.cases.default || [], e, n);
634
647
  }
635
- async function Ut(t, e, n) {
648
+ async function Dt(t, e, n) {
636
649
  await Promise.all(t.steps.map((r) => U(r, e, n)));
637
650
  }
638
- async function $t(t, e, n, r) {
639
- 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);
640
653
  }
641
- async function Ft(t, e, n) {
654
+ async function zt(t, e, n) {
642
655
  await $(e, n);
643
656
  }
644
657
  async function $(t, { contextStore: e, emit: n }) {
645
- 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()));
646
659
  }
647
- function nt(t, e, n, r) {
660
+ function D(t, e, n, r) {
648
661
  if (typeof t.patch != "function") return;
649
662
  const o = t.patch(n.context, e, F(n));
650
663
  o && (n.context = r.patch(n.threadId, o) || n.context);
@@ -657,10 +670,10 @@ function F(t) {
657
670
  accountConfig: t.accountConfig
658
671
  };
659
672
  }
660
- function I(t, e) {
673
+ function T(t, e) {
661
674
  return typeof t == "function" ? t(e) : t;
662
675
  }
663
- function Dt(t) {
676
+ function Lt(t) {
664
677
  const e = t?.payload;
665
678
  if (typeof e == "string") return e;
666
679
  if (e && typeof e == "object" && "text" in e) {
@@ -669,7 +682,7 @@ function Dt(t) {
669
682
  }
670
683
  return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
671
684
  }
672
- function zt(t, e) {
685
+ function qt(t, e) {
673
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;
674
687
  if (Array.isArray(a)) {
675
688
  for (const s of a) if (s && typeof s == "object") {
@@ -678,7 +691,7 @@ function zt(t, e) {
678
691
  }
679
692
  }
680
693
  }
681
- function me(t) {
694
+ function ge(t) {
682
695
  return { invoke(e, n) {
683
696
  return t("tool.invoke", {
684
697
  name: e,
@@ -689,33 +702,33 @@ function me(t) {
689
702
  function rt(t) {
690
703
  return t && typeof t == "object" && !Array.isArray(t) ? t : null;
691
704
  }
692
- function D(t) {
705
+ function z(t) {
693
706
  const e = rt(t);
694
707
  if (!e) return null;
695
- const n = T(e.sku, e.SKU);
708
+ const n = A(e.sku, e.SKU);
696
709
  if (!n) return null;
697
710
  const r = {
698
711
  sku: n,
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]);
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]);
702
715
  i && (r.imageUrl = i), o && o.length > 1 && (r.images = o.filter((f) => !!f).map(String));
703
716
  const a = j(e.price_discounted), s = j(e.price), c = a || s;
704
717
  c > 0 && (r.price = String(c));
705
718
  const u = a > 0 ? s : 0;
706
719
  u > 0 && (r.originalPrice = String(u));
707
- const l = T(e.brand);
720
+ const l = A(e.brand);
708
721
  l && (r.brand = l);
709
722
  const d = j(e.rating);
710
723
  d > 0 && (r.rating = d);
711
724
  const m = j(e.review_count) || j(e.reviewCount);
712
725
  m > 0 && (r.reviewCount = m);
713
- const p = T(e.cart_code, e.cartCode);
726
+ const p = A(e.cart_code, e.cartCode);
714
727
  p && (r.cartCode = p), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
715
728
  const g = e.category_names;
716
729
  return Array.isArray(g) && (r.categoryNames = g.map(String)), r;
717
730
  }
718
- function Lt(t) {
731
+ function Jt(t) {
719
732
  const e = rt(t);
720
733
  if (!e) return t;
721
734
  const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
@@ -735,9 +748,9 @@ function Lt(t) {
735
748
  return a;
736
749
  }
737
750
  function ot(t) {
738
- return Array.isArray(t) ? t.map(Lt).filter((e) => !!e) : [];
751
+ return Array.isArray(t) ? t.map(Jt).filter((e) => !!e) : [];
739
752
  }
740
- function T(...t) {
753
+ function A(...t) {
741
754
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
742
755
  return "";
743
756
  }
@@ -745,12 +758,12 @@ function j(t) {
745
758
  const e = Number(t);
746
759
  return Number.isFinite(e) ? e : 0;
747
760
  }
748
- function J(t) {
761
+ function K(t) {
749
762
  return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
750
763
  }
751
- function qt(t = []) {
764
+ function Kt(t = []) {
752
765
  const e = {}, n = [];
753
- return (Array.isArray(t) ? t.map(D).filter((r) => !!r) : []).forEach((r, o) => {
766
+ return (Array.isArray(t) ? t.map(z).filter((r) => !!r) : []).forEach((r, o) => {
754
767
  const i = `product-${o.toString()}`;
755
768
  n.push(i);
756
769
  const a = {
@@ -782,7 +795,7 @@ function qt(t = []) {
782
795
  }
783
796
  };
784
797
  }
785
- function ye(t) {
798
+ function he(t) {
786
799
  return {
787
800
  widget: "chat",
788
801
  panelHint: "panel",
@@ -790,13 +803,13 @@ function ye(t) {
790
803
  root: "root",
791
804
  elements: { root: {
792
805
  type: "ProductDetailsPanel",
793
- props: { product: D(t) || t || {} }
806
+ props: { product: z(t) || t || {} }
794
807
  } }
795
808
  }
796
809
  };
797
810
  }
798
- function ge(t = {}) {
799
- const e = (t.multiple_product_details || t.products || []).map(D).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 || {};
800
813
  return {
801
814
  widget: "chat",
802
815
  panelHint: "panel",
@@ -811,8 +824,8 @@ function ge(t = {}) {
811
824
  label: r,
812
825
  values: Array.isArray(o) ? o.map(String) : [String(o ?? "")]
813
826
  })),
814
- highlights: J(t.key_differences),
815
- specialCases: J(t.special_considerations),
827
+ highlights: K(t.key_differences),
828
+ specialCases: K(t.special_considerations),
816
829
  recommendedText: t.recommended_choice,
817
830
  productActions: Object.fromEntries(e.map((r) => [r.sku, {
818
831
  title: r.name,
@@ -827,7 +840,7 @@ function ge(t = {}) {
827
840
  }
828
841
  };
829
842
  }
830
- function he(t = []) {
843
+ function ke(t = []) {
831
844
  return {
832
845
  widget: "chat",
833
846
  panelHint: "inline",
@@ -850,7 +863,7 @@ function he(t = []) {
850
863
  }
851
864
  };
852
865
  }
853
- function v(t) {
866
+ function N(t) {
854
867
  const e = t?.payload;
855
868
  if (typeof e == "string") return e;
856
869
  if (e && typeof e == "object" && "text" in e) {
@@ -860,26 +873,26 @@ function v(t) {
860
873
  const n = t?.action;
861
874
  return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
862
875
  }
863
- function Jt(t) {
876
+ function Wt(t) {
864
877
  return Object.freeze([...t]);
865
878
  }
866
879
  function S(t) {
867
880
  return t && typeof t == "object" ? t : {};
868
881
  }
869
- function N(t) {
882
+ function v(t) {
870
883
  return t && typeof t == "object" ? t : {};
871
884
  }
872
- function K(t) {
885
+ function W(t) {
873
886
  return t.thread.extensions.beauty_profile;
874
887
  }
875
- var ke = Jt([{
888
+ var be = Wt([{
876
889
  kind: "be_op",
877
890
  op: "beauty-consulting-turn",
878
891
  input: ({ request: t, context: e }) => ({
879
- utterance: v(t),
892
+ utterance: N(t),
880
893
  prior_messages: e.messages.slice(-10),
881
- profile: K(e),
882
- candidate_products: Ht(t),
894
+ profile: W(e),
895
+ candidate_products: Vt(t),
883
896
  locale: e.meta.locale
884
897
  }),
885
898
  out: "consultation",
@@ -906,7 +919,7 @@ var ke = Jt([{
906
919
  input: ({ request: t, bag: e, context: n }) => {
907
920
  const r = S(e.consultation);
908
921
  return {
909
- query: r.search_params?.query || v(t),
922
+ query: r.search_params?.query || N(t),
910
923
  facets: r.search_params?.facets || {},
911
924
  limit: 12,
912
925
  locale: n.meta.locale
@@ -914,26 +927,26 @@ var ke = Jt([{
914
927
  },
915
928
  out: "products",
916
929
  patch: (t, e) => {
917
- const n = N(e);
930
+ const n = v(e);
918
931
  return { panel: {
919
932
  ...t.panel,
920
- screen_sku_list: O(n).map((r) => Kt(r)).filter((r) => !!r),
933
+ screen_sku_list: O(n).map((r) => Ht(r)).filter((r) => !!r),
921
934
  last_search: { query: n.query || "" }
922
935
  } };
923
936
  }
924
937
  },
925
938
  {
926
939
  kind: "emit",
927
- build: ({ bag: t }) => Pt(qt(O(N(t.products))))
940
+ build: ({ bag: t }) => Ct(Kt(O(v(t.products))))
928
941
  },
929
942
  {
930
943
  kind: "be_op",
931
944
  op: "beauty-consulting-turn",
932
945
  input: ({ request: t, context: e, bag: n }) => ({
933
- utterance: v(t),
946
+ utterance: N(t),
934
947
  prior_messages: e.messages.slice(-10),
935
- profile: K(e),
936
- 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)),
937
950
  locale: e.meta.locale
938
951
  }),
939
952
  out: "answer",
@@ -984,20 +997,20 @@ function H(t, e) {
984
997
  function O(t) {
985
998
  return Array.isArray(t?.products) ? t.products : [];
986
999
  }
987
- function Kt(t) {
1000
+ function Ht(t) {
988
1001
  if (t && typeof t == "object" && "sku" in t) {
989
1002
  const e = t.sku;
990
1003
  if (typeof e == "string") return e;
991
1004
  }
992
1005
  }
993
- function Ht(t) {
1006
+ function Vt(t) {
994
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;
995
1008
  return Array.isArray(r) ? ot(r.slice(0, 12)) : void 0;
996
1009
  }
997
1010
  function B(t) {
998
1011
  return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
999
1012
  }
1000
- var W = /* @__PURE__ */ new Set([
1013
+ var V = /* @__PURE__ */ new Set([
1001
1014
  "and",
1002
1015
  "are",
1003
1016
  "box",
@@ -1007,7 +1020,7 @@ var W = /* @__PURE__ */ new Set([
1007
1020
  "gifts",
1008
1021
  "the",
1009
1022
  "with"
1010
- ]), Wt = {
1023
+ ]), Gt = {
1011
1024
  token: 0.26,
1012
1025
  keyword: 0.22,
1013
1026
  category: 0.18,
@@ -1016,7 +1029,7 @@ var W = /* @__PURE__ */ new Set([
1016
1029
  attribute: 0.06,
1017
1030
  price: 0.08,
1018
1031
  retrieval: 0.08
1019
- }, Vt = [
1032
+ }, Qt = [
1020
1033
  "amber",
1021
1034
  "beige",
1022
1035
  "black",
@@ -1043,40 +1056,40 @@ var W = /* @__PURE__ */ new Set([
1043
1056
  function x(t) {
1044
1057
  return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1045
1058
  }
1046
- function k(t, e = W) {
1047
- const n = e instanceof Set ? e : /* @__PURE__ */ new Set([...W, ...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 = [];
1048
1061
  for (const i of x(t).split(/\s+/u))
1049
1062
  i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
1050
1063
  return o;
1051
1064
  }
1052
1065
  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 = [
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 = [
1055
1068
  s,
1056
1069
  c,
1057
1070
  ...r,
1058
1071
  ...a,
1059
1072
  ...y(t.promotions),
1060
- w(t.description),
1073
+ k(t.description),
1061
1074
  ...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);
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);
1063
1076
  return {
1064
- sku: w(t.sku),
1077
+ sku: k(t.sku),
1065
1078
  title: s,
1066
1079
  brand: c,
1067
1080
  productType: m,
1068
1081
  categoryNames: r,
1069
1082
  categoryIds: o,
1070
1083
  facets: i,
1071
- 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),
1072
1085
  tokens: d,
1073
1086
  colors: p,
1074
1087
  attributes: g,
1075
- price: Xt(t)
1088
+ price: te(t)
1076
1089
  };
1077
1090
  }
1078
- function we(t, e = {}) {
1079
- 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([
1080
1093
  ...y(t.keywords),
1081
1094
  ...y(t.colors),
1082
1095
  ...y(t.materials),
@@ -1100,7 +1113,7 @@ function we(t, e = {}) {
1100
1113
  sourceKeywords: o
1101
1114
  });
1102
1115
  }
1103
- function be(t, e = {}) {
1116
+ function Se(t, e = {}) {
1104
1117
  const n = M(t, e);
1105
1118
  return b([
1106
1119
  ...e.sourceQueries ?? [],
@@ -1115,23 +1128,23 @@ function be(t, e = {}) {
1115
1128
  n.productType
1116
1129
  ].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1117
1130
  }
1118
- function Gt(t, e, n = {}) {
1131
+ function Yt(t, e, n = {}) {
1119
1132
  const r = {
1120
- ...Wt,
1133
+ ...Gt,
1121
1134
  ...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);
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);
1123
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"), {
1124
1137
  score: Number(_.toFixed(4)),
1125
1138
  reasons: i
1126
1139
  };
1127
1140
  }
1128
- function _e(t, e, n = {}) {
1141
+ function xe(t, e, n = {}) {
1129
1142
  const r = M(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1130
1143
  return e.filter((i) => {
1131
- const a = w(i.sku);
1144
+ const a = k(i.sku);
1132
1145
  return a && !o.has(a);
1133
1146
  }).map((i) => {
1134
- const a = Gt(r, i, n);
1147
+ const a = Yt(r, i, n);
1135
1148
  return {
1136
1149
  ...i,
1137
1150
  similarity_score: a.score,
@@ -1139,20 +1152,20 @@ function _e(t, e, n = {}) {
1139
1152
  };
1140
1153
  }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
1141
1154
  }
1142
- function Qt(t) {
1155
+ function Xt(t) {
1143
1156
  return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1144
1157
  }
1145
- function w(...t) {
1158
+ function k(...t) {
1146
1159
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
1147
1160
  return "";
1148
1161
  }
1149
1162
  function y(t) {
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) : [];
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) : [];
1151
1164
  }
1152
- function Yt(t) {
1153
- return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, w(n)]).filter(([, e]) => e));
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));
1154
1167
  }
1155
- function Xt(t) {
1168
+ function te(t) {
1156
1169
  const e = Number(t.price_discounted);
1157
1170
  if (Number.isFinite(e) && e > 0) return e;
1158
1171
  const n = Number(t.price);
@@ -1166,14 +1179,14 @@ function b(t) {
1166
1179
  }
1167
1180
  return n;
1168
1181
  }
1169
- function Zt(t, e) {
1182
+ function ee(t, e) {
1170
1183
  const n = ` ${x(t)} `;
1171
1184
  return e.filter((r) => n.includes(` ${x(r)} `));
1172
1185
  }
1173
- function te(t, e, n) {
1186
+ function ne(t, e, n) {
1174
1187
  const r = x(t[t.length - 1] ?? t[0] ?? "");
1175
1188
  if (r) {
1176
- const o = k(r), i = new Set(k(e));
1189
+ const o = w(r), i = new Set(w(e));
1177
1190
  return o.find((a) => i.has(a)) ?? o[0] ?? r;
1178
1191
  }
1179
1192
  return n[0] ?? "";
@@ -1181,69 +1194,69 @@ function te(t, e, n) {
1181
1194
  function P(t) {
1182
1195
  return t.map((e) => x(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1183
1196
  }
1184
- function V(t) {
1185
- return t.flatMap((e) => k(e));
1197
+ function G(t) {
1198
+ return t.flatMap((e) => w(e));
1186
1199
  }
1187
- function A(t, e) {
1200
+ function I(t, e) {
1188
1201
  const n = b(t), r = new Set(b(e));
1189
1202
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1190
1203
  }
1191
- function ee(t, e) {
1204
+ function re(t, e) {
1192
1205
  const n = b(t), r = new Set(b(e));
1193
1206
  return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1194
1207
  }
1195
- function ne(t, e) {
1208
+ function oe(t, e) {
1196
1209
  return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1197
1210
  }
1198
- function re(t, e) {
1211
+ function ie(t, e) {
1199
1212
  return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1200
1213
  }
1201
- function oe(t, e) {
1214
+ function ae(t, e) {
1202
1215
  if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1203
- 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]);
1204
1217
  return [...n].some((o) => r.has(o));
1205
1218
  }
1206
- function ie(t) {
1219
+ function se(t) {
1207
1220
  return Math.max(0, Math.min(1, t));
1208
1221
  }
1209
1222
  export {
1210
- ue as A,
1211
- Ct as C,
1212
- le as D,
1213
- Pt as E,
1223
+ de as A,
1224
+ Mt as C,
1225
+ fe as D,
1226
+ Ct as E,
1214
1227
  R as F,
1215
1228
  ft as I,
1216
- ae as L,
1229
+ ce as L,
1217
1230
  bt as M,
1218
- wt as N,
1219
- Z as O,
1220
- ce as P,
1221
- se as R,
1222
- et as S,
1231
+ kt as N,
1232
+ tt as O,
1233
+ le as P,
1234
+ ue as R,
1235
+ nt as S,
1223
1236
  C as T,
1224
1237
  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,
1238
+ xe as a,
1239
+ Nt as b,
1240
+ be as c,
1241
+ ke as d,
1242
+ we as f,
1243
+ Jt as g,
1244
+ z as h,
1232
1245
  x as i,
1233
1246
  Tt as j,
1234
- tt as k,
1235
- Jt as l,
1236
- qt as m,
1247
+ et as k,
1248
+ Wt as l,
1249
+ Kt as m,
1237
1250
  M as n,
1238
- Gt as o,
1239
- ye as p,
1240
- be as r,
1241
- k as s,
1242
- we as t,
1243
- v as u,
1244
- me as v,
1245
- de as w,
1246
- fe as x,
1247
- pe 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,
1248
1261
  dt as z
1249
1262
  };