@gengage/assistant-fe 0.6.0 → 0.6.2

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.
Files changed (41) hide show
  1. package/README.md +6 -22
  2. package/dist/agentic/adaptor/fetch-bridge.d.ts +3 -2
  3. package/dist/agentic/index.d.ts +1 -0
  4. package/dist/agentic/index.js +358 -306
  5. package/dist/agentic/similarity.d.ts +77 -0
  6. package/dist/agentic/types.d.ts +2 -0
  7. package/dist/agentic/util/be-url.d.ts +1 -1
  8. package/dist/agentic/worker/be-client.d.ts +2 -1
  9. package/dist/agentic/worker.d.ts +1 -0
  10. package/dist/agentic/worker.js +65 -57
  11. package/dist/agentic.iife.js +5 -5
  12. package/dist/{api-paths-DJFF9RuZ.js → api-paths-B1sFG4Tn.js} +1 -1
  13. package/dist/chat/runtime.d.ts +1 -0
  14. package/dist/chat-runtime.js +1 -1
  15. package/dist/chat.iife.js +2 -2
  16. package/dist/chat.js +1 -1
  17. package/dist/common/overlay.d.ts +1 -1
  18. package/dist/common/transport.d.ts +7 -0
  19. package/dist/{common-BydCGBNn.js → common-BML75wCP.js} +1 -1
  20. package/dist/common.js +5 -5
  21. package/dist/{connection-warning-Pbvk3J8k.js → connection-warning-Qy4APv0U.js} +1 -1
  22. package/dist/{fastIntent-CkYN2UOl.js → fastIntent-CXqUDc50.js} +1 -1
  23. package/dist/index.js +10 -10
  24. package/dist/native.iife.js +2 -2
  25. package/dist/qna/types.d.ts +1 -1
  26. package/dist/qna-runtime.js +1 -1
  27. package/dist/qna.iife.js +1 -1
  28. package/dist/qna.js +1 -1
  29. package/dist/{runtime-OpNoB3cu.js → runtime-C5FjeLrv.js} +116 -113
  30. package/dist/{runtime-iCLkUjI3.js → runtime-DmZ325aj.js} +3 -3
  31. package/dist/{runtime-DbZO1qG5.js → runtime-U8DOh3fb.js} +3 -3
  32. package/dist/{simbut-FyXolmZY.js → simbut-BJpWnq1J.js} +1 -1
  33. package/dist/simbut.iife.js +1 -1
  34. package/dist/simbut.js +1 -1
  35. package/dist/{beauty-consulting-turn-BmPXbkQg.js → similarity-DcfZ0CKT.js} +515 -295
  36. package/dist/{simrel-CbLe5OAr.js → simrel-B7RQY06h.js} +1 -1
  37. package/dist/simrel-runtime.js +1 -1
  38. package/dist/simrel.iife.js +1 -1
  39. package/dist/simrel.js +2 -2
  40. package/dist/{widget-base-COP8QwU3.js → widget-base-d-dDGkr7.js} +1 -1
  41. package/package.json +2 -34
@@ -1,32 +1,32 @@
1
- function G(t) {
1
+ function it(t) {
2
2
  return !!t && typeof t == "object" && t.type === "rpc.result";
3
3
  }
4
- function W(t) {
4
+ function at(t) {
5
5
  return !!t && typeof t == "object" && t.type === "rpc.req";
6
6
  }
7
- function Bt(t = self) {
7
+ function ie(t = self) {
8
8
  let e = 1;
9
9
  const n = /* @__PURE__ */ new Map();
10
10
  return t.addEventListener("message", (r) => {
11
11
  const o = r.data;
12
- if (!G(o)) return;
13
- const a = n.get(o.rpcId);
14
- if (a) {
12
+ if (!it(o)) return;
13
+ const i = n.get(o.rpcId);
14
+ if (i) {
15
15
  if (n.delete(o.rpcId), o.ok === !1) {
16
- const i = typeof o.error == "object" ? o.error?.message : o.error;
17
- a.reject(new Error(i || "RPC failed"));
16
+ const a = typeof o.error == "object" ? o.error?.message : o.error;
17
+ i.reject(new Error(a || "RPC failed"));
18
18
  return;
19
19
  }
20
- a.resolve(o.value);
20
+ i.resolve(o.value);
21
21
  }
22
- }), function(o, a, i) {
22
+ }), function(o, i, a) {
23
23
  const s = e++;
24
24
  return t.postMessage({
25
25
  type: "rpc.req",
26
26
  rpcId: s,
27
27
  method: o,
28
- payload: a
29
- }, i || []), new Promise((c, u) => {
28
+ payload: i
29
+ }, a || []), new Promise((c, u) => {
30
30
  n.set(s, {
31
31
  resolve: (l) => c(l),
32
32
  reject: u
@@ -34,19 +34,19 @@ function Bt(t = self) {
34
34
  });
35
35
  };
36
36
  }
37
- function Nt({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
37
+ function ae({ worker: t, tools: e = {}, beacon: n, memory: r = sessionStorage }) {
38
38
  t.addEventListener("message", (o) => {
39
- const a = o.data;
40
- W(a) && Y(t, a, {
39
+ const i = o.data;
40
+ at(i) && st(t, i, {
41
41
  tools: e,
42
42
  beacon: n,
43
43
  memory: r
44
44
  });
45
45
  });
46
46
  }
47
- async function Y(t, e, n) {
47
+ async function st(t, e, n) {
48
48
  try {
49
- const r = await tt(e.method, e.payload, n);
49
+ const r = await dt(e.method, e.payload, n);
50
50
  t.postMessage({
51
51
  type: "rpc.result",
52
52
  rpcId: e.rpcId,
@@ -62,70 +62,70 @@ async function Y(t, e, n) {
62
62
  });
63
63
  }
64
64
  }
65
- function X(t) {
65
+ function ct(t) {
66
66
  if (t && typeof t == "object" && typeof t.name == "string") return t;
67
67
  throw new Error("tool.invoke requires { name, input }");
68
68
  }
69
- function Q(t) {
69
+ function ut(t) {
70
70
  if (t && typeof t == "object" && t.key !== void 0) return t;
71
71
  throw new Error("memory.get requires { key }");
72
72
  }
73
- function Z(t) {
73
+ function lt(t) {
74
74
  if (t && typeof t == "object" && t.key !== void 0) return t;
75
75
  throw new Error("memory.set requires { key }");
76
76
  }
77
- async function tt(t, e, { tools: n, beacon: r, memory: o }) {
77
+ async function dt(t, e, { tools: n, beacon: r, memory: o }) {
78
78
  if (t === "tool.invoke") {
79
- const { name: a, input: i } = X(e), s = n[a];
80
- if (typeof s != "function") throw new Error(`Unknown tool: ${a}`);
81
- return s(i);
79
+ const { name: i, input: a } = ct(e), s = n[i];
80
+ if (typeof s != "function") throw new Error(`Unknown tool: ${i}`);
81
+ return s(a);
82
82
  }
83
83
  if (t === "beacon.send")
84
84
  return r?.(e), { sent: !0 };
85
85
  if (t === "memory.get") {
86
- const { key: a } = Q(e), i = o.getItem(String(a));
87
- return i ? JSON.parse(i) : null;
86
+ const { key: i } = ut(e), a = o.getItem(String(i));
87
+ return a ? JSON.parse(a) : null;
88
88
  }
89
89
  if (t === "memory.set") {
90
- const { key: a, value: i } = Z(e);
91
- return o.setItem(String(a), JSON.stringify(i ?? null)), { ok: !0 };
90
+ const { key: i, value: a } = lt(e);
91
+ return o.setItem(String(i), JSON.stringify(a ?? null)), { ok: !0 };
92
92
  }
93
93
  throw new Error(`Unknown RPC method: ${t}`);
94
94
  }
95
- function et() {
95
+ function ft() {
96
96
  return (/* @__PURE__ */ new Date()).toISOString();
97
97
  }
98
- function E(t) {
98
+ function B(t) {
99
99
  return Math.max(0, Math.round(performance.now() - t));
100
100
  }
101
- function w(t) {
101
+ function A(t) {
102
102
  return typeof t == "object" && t !== null && !Array.isArray(t);
103
103
  }
104
- function nt(t) {
105
- const { accountId: e, locale: n = "en-GB", parentUrl: r = "", threadId: o, incomingContext: a } = t, i = w(a) ? a : {}, s = w(i.thread) ? i.thread : {}, c = w(i.panel) ? i.panel : {}, u = w(i.meta) ? i.meta : {}, l = U(i.messages), d = {
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 = {
106
106
  id: String(o || s.id || self.crypto.randomUUID()),
107
- started_at: String(s.started_at || et()),
108
- extensions: w(s.extensions) ? { ...s.extensions } : {}
109
- }, y = String(u.locale || n), p = String(u.parentUrl || r || typeof self < "u" && self.location?.href || "");
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 || "");
110
110
  return {
111
111
  panel: { ...c },
112
112
  messages: l,
113
113
  thread: d,
114
114
  meta: {
115
- locale: y,
116
- parentUrl: p,
115
+ locale: p,
116
+ parentUrl: m,
117
117
  accountId: e
118
118
  }
119
119
  };
120
120
  }
121
- function rt(t, e) {
122
- const n = U([e])[0];
121
+ function mt(t, e) {
122
+ const n = G([e])[0];
123
123
  return n ? {
124
124
  ...t,
125
125
  messages: [...t.messages, n].slice(-50)
126
126
  } : t;
127
127
  }
128
- function U(t) {
128
+ function G(t) {
129
129
  return Array.isArray(t) ? t.map((e) => {
130
130
  const n = e?.role;
131
131
  return {
@@ -134,28 +134,28 @@ function U(t) {
134
134
  };
135
135
  }).filter((e) => (e.role === "user" || e.role === "assistant") && !!e.content).slice(-50) : [];
136
136
  }
137
- var ot = "gengage:agent:context:";
138
- async function it({ accountId: t, threadId: e, rpc: n }) {
137
+ var yt = "gengage:agent:context:";
138
+ async function gt({ accountId: t, threadId: e, rpc: n }) {
139
139
  const r = await n("memory.get", {
140
140
  tier: "session",
141
- key: $(t, e)
141
+ key: Q(t, e)
142
142
  });
143
143
  return r && typeof r == "object" && !Array.isArray(r) ? r : {};
144
144
  }
145
- async function at({ accountId: t, threadId: e, extensions: n, rpc: r }) {
145
+ async function ht({ accountId: t, threadId: e, extensions: n, rpc: r }) {
146
146
  await r("memory.set", {
147
147
  tier: "session",
148
- key: $(t, e),
148
+ key: Q(t, e),
149
149
  value: { thread: { extensions: n } }
150
150
  });
151
151
  }
152
- function $(t, e) {
153
- return `${ot}${t}:${e}`;
152
+ function Q(t, e) {
153
+ return `${yt}${t}:${e}`;
154
154
  }
155
- function f(t) {
155
+ function g(t) {
156
156
  return typeof t == "object" && t !== null && !Array.isArray(t);
157
157
  }
158
- var Ut = class {
158
+ var se = class {
159
159
  #t = /* @__PURE__ */ new Map();
160
160
  #e;
161
161
  #r;
@@ -167,23 +167,23 @@ var Ut = class {
167
167
  async load(t) {
168
168
  const e = t?.meta?.threadId || t?.session_id || t?.sessionId, n = String(e || "default"), r = this.#t.get(n);
169
169
  if (r) return r;
170
- const o = await it({
170
+ const o = await gt({
171
171
  accountId: this.#e,
172
172
  threadId: n,
173
173
  rpc: this.#n
174
- }), a = nt({
174
+ }), i = pt({
175
175
  accountId: this.#e,
176
176
  locale: t?.locale || this.#r,
177
177
  parentUrl: this.#o,
178
178
  threadId: n,
179
- incomingContext: st(o, t?.context)
179
+ incomingContext: kt(o, t?.context)
180
180
  });
181
- return this.#t.set(n, a), a;
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 = D(r, typeof e == "function" ? e(r) : e);
186
+ const o = Y(r, typeof e == "function" ? e(r) : e);
187
187
  return this.#t.set(n, o), o;
188
188
  }
189
189
  appendUserMessage(t, e) {
@@ -191,7 +191,7 @@ var Ut = class {
191
191
  if (!e) return this.#t.get(n) ?? null;
192
192
  const r = this.#t.get(n);
193
193
  if (!r) return null;
194
- const o = rt(r, {
194
+ const o = mt(r, {
195
195
  role: "user",
196
196
  content: e
197
197
  });
@@ -199,7 +199,7 @@ var Ut = class {
199
199
  }
200
200
  async commit(t) {
201
201
  const e = String(t || "default"), n = this.#t.get(e);
202
- return n ? (await at({
202
+ return n ? (await ht({
203
203
  accountId: this.#e,
204
204
  threadId: e,
205
205
  extensions: n.thread.extensions,
@@ -207,21 +207,21 @@ var Ut = class {
207
207
  }), n) : null;
208
208
  }
209
209
  };
210
- function st(t, e) {
211
- return !f(t) && !f(e) ? {} : D(f(t) ? t : {}, f(e) ? e : {});
210
+ function kt(t, e) {
211
+ return !g(t) && !g(e) ? {} : Y(g(t) ? t : {}, g(e) ? e : {});
212
212
  }
213
- function D(t, e) {
214
- if (!f(e)) return t;
215
- const n = t, r = e, o = f(n.panel) ? n.panel : {}, a = f(r.panel) ? r.panel : {}, i = f(n.thread) ? n.thread : {}, s = f(r.thread) ? r.thread : {}, c = f(i.extensions) ? i.extensions : {}, u = f(s.extensions) ? s.extensions : {}, l = f(n.meta) ? n.meta : {}, d = f(r.meta) ? r.meta : {};
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 : {};
216
216
  return {
217
217
  ...t,
218
218
  ...e,
219
219
  panel: {
220
220
  ...o,
221
- ...a
221
+ ...i
222
222
  },
223
223
  thread: {
224
- ...i,
224
+ ...a,
225
225
  ...s,
226
226
  extensions: {
227
227
  ...c,
@@ -235,51 +235,51 @@ function D(t, e) {
235
235
  messages: Array.isArray(r.messages) ? r.messages.slice(-50) : t.messages ?? []
236
236
  };
237
237
  }
238
- function J(t) {
238
+ function X(t) {
239
239
  const e = String.fromCharCode(...t);
240
240
  return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
241
241
  }
242
- function P(t) {
243
- return J(new TextEncoder().encode(JSON.stringify(t)));
242
+ function z(t) {
243
+ return X(new TextEncoder().encode(JSON.stringify(t)));
244
244
  }
245
- async function ct({ accountId: t, devJwtSecret: e, ttlS: n = 300 }) {
245
+ async function wt({ 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 = `${P({
247
+ const r = Math.floor(Date.now() / 1e3), o = `${z({
248
248
  alg: "HS256",
249
249
  typ: "JWT"
250
- })}.${P({
250
+ })}.${z({
251
251
  sub: t,
252
252
  iat: r,
253
253
  exp: r + n,
254
254
  scope: "invoke",
255
255
  jti: crypto.randomUUID?.() || `${r}-${Math.random()}`
256
- })}`, a = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
256
+ })}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
257
257
  name: "HMAC",
258
258
  hash: "SHA-256"
259
- }, !1, ["sign"]), i = await crypto.subtle.sign("HMAC", a, new TextEncoder().encode(o));
260
- return `${o}.${J(new Uint8Array(i))}`;
259
+ }, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
260
+ return `${o}.${X(new Uint8Array(a))}`;
261
261
  }
262
- function ut({ accountId: t, devJwtSecret: e, tokenBrokerUrl: n, tokenBrokerAudience: r, refreshSkewS: o = 30, fetchImpl: a = fetch }) {
263
- let i = null;
262
+ function bt({ accountId: t, devJwtSecret: e, tokenBrokerUrl: n, tokenBrokerAudience: r, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
263
+ let a = null;
264
264
  return async ({ signal: s, parentUrl: c } = {}) => {
265
- if (e) return ct({
265
+ if (e) return wt({
266
266
  accountId: t,
267
267
  devJwtSecret: e
268
268
  });
269
269
  if (!n) throw new Error("tokenBrokerUrl is required for production agent mode.");
270
270
  const u = Math.floor(Date.now() / 1e3);
271
- return i?.token && i.expiresAtS - o > u || (i = await lt({
271
+ return a?.token && a.expiresAtS - o > u || (a = await _t({
272
272
  accountId: t,
273
273
  tokenBrokerUrl: n,
274
274
  tokenBrokerAudience: r,
275
275
  parentUrl: c,
276
276
  signal: s,
277
- fetchImpl: a
278
- })), i.token;
277
+ fetchImpl: i
278
+ })), a.token;
279
279
  };
280
280
  }
281
- async function lt({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: n, parentUrl: r, signal: o, fetchImpl: a }) {
282
- const i = await a(e, {
281
+ async function _t({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: n, parentUrl: r, signal: o, fetchImpl: i }) {
282
+ const a = await i(e, {
283
283
  method: "POST",
284
284
  credentials: "include",
285
285
  headers: {
@@ -294,15 +294,15 @@ async function lt({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: n, par
294
294
  }),
295
295
  ...o ? { signal: o } : {}
296
296
  });
297
- if (!i.ok) throw new Error(`Token broker request failed (${i.status}).`);
298
- const s = await i.json(), c = s?.token || s?.jwt || s?.access_token;
297
+ if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
298
+ const s = await a.json(), c = s?.token || s?.jwt || s?.access_token;
299
299
  if (!c || typeof c != "string") throw new Error("Token broker response did not include a JWT.");
300
300
  return {
301
301
  token: c,
302
- expiresAtS: dt(s) || pt(c) || Math.floor(Date.now() / 1e3) + 300
302
+ expiresAtS: St(s) || xt(c) || Math.floor(Date.now() / 1e3) + 300
303
303
  };
304
304
  }
305
- function dt(t) {
305
+ function St(t) {
306
306
  const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
307
307
  if (Number.isFinite(e)) return Number(e);
308
308
  const n = t?.expiresIn ?? t?.expires_in;
@@ -314,7 +314,7 @@ function dt(t) {
314
314
  }
315
315
  return null;
316
316
  }
317
- function pt(t) {
317
+ function xt(t) {
318
318
  try {
319
319
  const [, e] = t.split(".");
320
320
  if (!e) return null;
@@ -324,7 +324,7 @@ function pt(t) {
324
324
  return null;
325
325
  }
326
326
  }
327
- var M = {
327
+ var L = {
328
328
  unauthorized: {
329
329
  code: "auth",
330
330
  message: "Assistant authentication failed. Please retry."
@@ -369,28 +369,28 @@ var M = {
369
369
  code: "invalid_request",
370
370
  message: "The assistant request was too large."
371
371
  }
372
- }, q = class extends Error {
372
+ }, Z = 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 F(t) {
378
- const e = String(t?.code || "upstream_llm"), n = M[e] || M.upstream_llm;
379
- return new q(n.code, n.message, {
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, {
380
380
  source: "be",
381
381
  sourceCode: e,
382
382
  detail: t?.detail
383
383
  });
384
384
  }
385
- function ft(t, e) {
385
+ function Tt(t, e) {
386
386
  const n = e?.error && typeof e.error == "object" ? e.error : {};
387
- return F({
388
- code: String(n.code || mt(t)),
387
+ return tt({
388
+ code: String(n.code || At(t)),
389
389
  detail: n.detail
390
390
  });
391
391
  }
392
- function $t(t) {
393
- return t instanceof q ? {
392
+ function ce(t) {
393
+ return t instanceof Z ? {
394
394
  type: "error",
395
395
  code: t.code,
396
396
  message: t.message
@@ -400,73 +400,74 @@ function $t(t) {
400
400
  message: "The assistant could not complete that request."
401
401
  };
402
402
  }
403
- function mt(t) {
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 Dt({ beUrl: t, accountId: e, devJwtSecret: n, tokenBrokerUrl: r, tokenBrokerAudience: o, jwtProvider: a, parentUrl: i, op: s, input: c, signal: u }) {
407
- const l = {
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 = {
408
408
  method: "POST",
409
409
  headers: {
410
- authorization: `Bearer ${await (a || ut({
410
+ authorization: `Bearer ${await (i || bt({
411
411
  accountId: e,
412
412
  devJwtSecret: n,
413
413
  tokenBrokerUrl: r,
414
414
  tokenBrokerAudience: o
415
415
  }))({
416
- ...u ? { signal: u } : {},
417
- ...i ? { parentUrl: i } : {}
416
+ ...l ? { signal: l } : {},
417
+ ...a ? { parentUrl: a } : {}
418
418
  })}`,
419
419
  "content-type": "application/json",
420
420
  accept: "application/x-ndjson"
421
421
  },
422
422
  body: JSON.stringify({
423
423
  op: s,
424
- input: c
424
+ input: c,
425
+ ...u !== void 0 ? { cache_ttl_s: u } : {}
425
426
  }),
426
- ...u ? { signal: u } : {}
427
- }, d = await fetch(`${String(t).replace(/\/+$/u, "")}/v1/invoke`, l);
428
- if (!d.ok) throw ft(d.status, await yt(d));
429
- return gt(d);
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);
430
431
  }
431
- async function yt(t) {
432
+ async function It(t) {
432
433
  try {
433
434
  return await t.json();
434
435
  } catch {
435
436
  return { error: { code: t.statusText || "internal" } };
436
437
  }
437
438
  }
438
- async function gt(t) {
439
+ async function Et(t) {
439
440
  const e = t.body?.getReader();
440
441
  if (!e) throw new Error("BE response body is not readable.");
441
442
  const n = new TextDecoder();
442
443
  let r = "";
443
444
  const o = {};
444
445
  for (; ; ) {
445
- const { value: i, done: s } = await e.read();
446
+ const { value: a, done: s } = await e.read();
446
447
  if (s) break;
447
- r += n.decode(i, { stream: !0 });
448
+ r += n.decode(a, { stream: !0 });
448
449
  let c = r.indexOf(`
449
450
  `);
450
451
  for (; c >= 0; ) {
451
452
  const u = r.slice(0, c).trim();
452
- r = r.slice(c + 1), u && O(JSON.parse(u), o), c = r.indexOf(`
453
+ r = r.slice(c + 1), u && q(JSON.parse(u), o), c = r.indexOf(`
453
454
  `);
454
455
  }
455
456
  }
456
- const a = r.trim();
457
- return a && O(JSON.parse(a), o), o;
457
+ const i = r.trim();
458
+ return i && q(JSON.parse(i), o), o;
458
459
  }
459
- function O(t, e) {
460
- if (t._error) throw F(t._error);
460
+ function q(t, e) {
461
+ if (t._error) throw tt(t._error);
461
462
  t._end || Object.assign(e, t);
462
463
  }
463
- function Jt(t = {}) {
464
+ function le(t = {}) {
464
465
  return {
465
466
  type: "metadata",
466
467
  ...t
467
468
  };
468
469
  }
469
- function _(t, e = !1, n = {}) {
470
+ function P(t, e = !1, n = {}) {
470
471
  return {
471
472
  type: "text_chunk",
472
473
  content: t,
@@ -474,41 +475,41 @@ function _(t, e = !1, n = {}) {
474
475
  ...n
475
476
  };
476
477
  }
477
- function ht(t) {
478
+ function jt(t) {
478
479
  return {
479
480
  type: "ui_spec",
480
481
  ...t
481
482
  };
482
483
  }
483
- function qt(t) {
484
+ function de(t) {
484
485
  return {
485
486
  type: "action",
486
487
  action: t
487
488
  };
488
489
  }
489
- function wt(t, e) {
490
+ function Pt(t, e) {
490
491
  return {
491
492
  type: "error",
492
493
  code: t,
493
494
  message: e
494
495
  };
495
496
  }
496
- function z() {
497
+ function et() {
497
498
  return { type: "done" };
498
499
  }
499
- function kt(t, e) {
500
+ function Ct(t, e) {
500
501
  return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
501
502
  }
502
- async function Ft({ request: t, accountModule: e, contextStore: n, beClient: r, toolBridge: o, emit: a, rpc: i, signal: s }) {
503
- const c = performance.now(), u = await n.load(t), l = u.thread.id, d = Tt(t);
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);
504
505
  n.appendUserMessage(l, d);
505
- const y = kt(e.flows, t);
506
- if (!y)
507
- return a(wt("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), a(z()), {
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()), {
508
509
  steps: 0,
509
510
  productSkusEmitted: []
510
511
  };
511
- const p = {
512
+ const m = {
512
513
  request: t,
513
514
  context: n.patch(l, {}) || u,
514
515
  bag: {},
@@ -521,121 +522,123 @@ async function Ft({ request: t, accountModule: e, contextStore: n, beClient: r,
521
522
  contextStore: n,
522
523
  beClient: r,
523
524
  toolBridge: o,
524
- emit: a,
525
- rpc: i,
525
+ emit: i,
526
+ rpc: a,
526
527
  ...s ? { signal: s } : {}
527
528
  };
528
- return await C(y, p, h), p.committed || await T(p, h), await i("beacon.send", {
529
+ return await U(p, m, h), m.committed || await $(m, h), await a("beacon.send", {
529
530
  type: "turnSummary",
530
531
  threadId: l,
531
532
  sessionId: t?.session_id || t?.sessionId || l,
532
- accountId: e.accountId || p.context.meta.accountId,
533
- steps: p.steps,
534
- totalLatencyMs: E(c),
535
- productSkusEmitted: [...p.productSkusEmitted]
533
+ accountId: e.accountId || m.context.meta.accountId,
534
+ steps: m.steps,
535
+ totalLatencyMs: B(c),
536
+ productSkusEmitted: [...m.productSkusEmitted]
536
537
  }), {
537
- steps: p.steps,
538
- productSkusEmitted: [...p.productSkusEmitted]
538
+ steps: m.steps,
539
+ productSkusEmitted: [...m.productSkusEmitted]
539
540
  };
540
541
  }
541
- async function C(t, e, n) {
542
+ async function U(t, e, n) {
542
543
  for (const r of t) {
543
544
  if (n.signal?.aborted) return;
544
- e.steps += 1, await _t(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
545
+ e.steps += 1, await Mt(r, e, n), e.context = n.contextStore.patch(e.threadId, {}) || e.context;
545
546
  }
546
547
  }
547
- async function _t(t, e, n) {
548
- const r = j(e);
548
+ async function Mt(t, e, n) {
549
+ const r = F(e);
549
550
  if (t.kind === "be_op") {
550
- await bt(t, e, n, r);
551
+ await vt(t, e, n, r);
551
552
  return;
552
553
  }
553
554
  if (t.kind === "tool") {
554
- await St(t, e, n, r);
555
+ await Nt(t, e, n, r);
555
556
  return;
556
557
  }
557
558
  if (t.kind === "emit") {
558
- xt(t, e, n);
559
+ Ot(t, e, n);
559
560
  return;
560
561
  }
561
562
  if (t.kind === "branch") {
562
- await At(t, e, n, r);
563
+ await Rt(t, e, n, r);
563
564
  return;
564
565
  }
565
566
  if (t.kind === "parallel") {
566
- await It(t, e, n);
567
+ await Bt(t, e, n);
567
568
  return;
568
569
  }
569
570
  if (t.kind === "refusal") {
570
- await Et(t, e, n, r);
571
+ await Ut(t, e, n, r);
571
572
  return;
572
573
  }
573
- t.kind === "commit" && await Ct(t, e, n);
574
+ t.kind === "commit" && await $t(t, e, n);
574
575
  }
575
- async function bt(t, e, n, r) {
576
+ async function vt(t, e, n, r) {
576
577
  const o = performance.now();
577
- let a;
578
+ let i;
579
+ const a = E(t.cacheTtlS, r);
578
580
  try {
579
- a = await n.beClient.invoke({
581
+ i = await n.beClient.invoke({
580
582
  op: t.op,
581
- input: b(t.input, r),
583
+ input: E(t.input, r),
584
+ ...a !== void 0 ? { cacheTtlS: a } : {},
582
585
  ...n.signal ? { signal: n.signal } : {}
583
586
  });
584
- } catch (s) {
585
- const c = s, u = String(c?.sourceCode || c?.code || "unknown"), l = {
587
+ } catch (c) {
588
+ const u = c, l = String(u?.sourceCode || u?.code || "unknown"), d = {
586
589
  type: "agentOp",
587
590
  threadId: e.threadId,
588
591
  sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
589
592
  accountId: e.context.meta.accountId,
590
593
  op: t.op,
591
594
  status: "error",
592
- latencyMs: E(o),
593
- errorCode: u
595
+ latencyMs: B(o),
596
+ errorCode: l
594
597
  };
595
- throw await n.rpc("beacon.send", l), s;
598
+ throw await n.rpc("beacon.send", d), c;
596
599
  }
597
- t.out && (e.bag[t.out] = a), H(t, a, e, n.contextStore);
598
- const i = {
600
+ t.out && (e.bag[t.out] = i), nt(t, i, e, n.contextStore);
601
+ const s = {
599
602
  type: "agentOp",
600
603
  threadId: e.threadId,
601
604
  sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
602
605
  accountId: e.context.meta.accountId,
603
606
  op: t.op,
604
607
  status: "ok",
605
- latencyMs: E(o)
608
+ latencyMs: B(o)
606
609
  };
607
- await n.rpc("beacon.send", i);
610
+ await n.rpc("beacon.send", s);
608
611
  }
609
- async function St(t, e, n, r) {
610
- const o = await n.toolBridge.invoke(t.name, b(t.input, r));
611
- t.out && (e.bag[t.out] = o), H(t, o, e, n.contextStore);
612
+ async function Nt(t, e, n, r) {
613
+ const o = await n.toolBridge.invoke(t.name, E(t.input, r));
614
+ t.out && (e.bag[t.out] = o), nt(t, o, e, n.contextStore);
612
615
  }
613
- function xt(t, e, n) {
614
- const r = t.build(j(e));
615
- jt(r, e.productSkusEmitted), n.emit(r);
616
+ function Ot(t, e, n) {
617
+ const r = t.build(F(e));
618
+ Dt(r, e.productSkusEmitted), n.emit(r);
616
619
  }
617
- async function At(t, e, n, r) {
618
- const o = String(b(t.on, r) || "default");
619
- await C(t.cases[o] || t.cases.default || [], e, n);
620
+ async function Rt(t, e, n, r) {
621
+ const o = String(E(t.on, r) || "default");
622
+ await U(t.cases[o] || t.cases.default || [], e, n);
620
623
  }
621
- async function It(t, e, n) {
622
- await Promise.all(t.steps.map((r) => C(r, e, n)));
624
+ async function Bt(t, e, n) {
625
+ await Promise.all(t.steps.map((r) => U(r, e, n)));
623
626
  }
624
- async function Et(t, e, n, r) {
625
- n.emit(_(b(t.message, r), !0)), await T(e, n);
627
+ async function Ut(t, e, n, r) {
628
+ n.emit(P(E(t.message, r), !0)), await $(e, n);
626
629
  }
627
- async function Ct(t, e, n) {
628
- await T(e, n);
630
+ async function $t(t, e, n) {
631
+ await $(e, n);
629
632
  }
630
- async function T(t, { contextStore: e, emit: n }) {
631
- t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, n(z()));
633
+ async function $(t, { contextStore: e, emit: n }) {
634
+ t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, n(et()));
632
635
  }
633
- function H(t, e, n, r) {
636
+ function nt(t, e, n, r) {
634
637
  if (typeof t.patch != "function") return;
635
- const o = t.patch(n.context, e, j(n));
638
+ const o = t.patch(n.context, e, F(n));
636
639
  o && (n.context = r.patch(n.threadId, o) || n.context);
637
640
  }
638
- function j(t) {
641
+ function F(t) {
639
642
  return {
640
643
  request: t.request,
641
644
  context: t.context,
@@ -643,10 +646,10 @@ function j(t) {
643
646
  accountConfig: t.accountConfig
644
647
  };
645
648
  }
646
- function b(t, e) {
649
+ function E(t, e) {
647
650
  return typeof t == "function" ? t(e) : t;
648
651
  }
649
- function Tt(t) {
652
+ function Ft(t) {
650
653
  const e = t?.payload;
651
654
  if (typeof e == "string") return e;
652
655
  if (e && typeof e == "object" && "text" in e) {
@@ -655,16 +658,16 @@ function Tt(t) {
655
658
  }
656
659
  return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
657
660
  }
658
- function jt(t, e) {
659
- const n = t, r = n.spec, o = Array.isArray(r?.items) ? r.items : void 0, a = Array.isArray(n.items) ? n.items : void 0, i = o || a;
660
- if (Array.isArray(i)) {
661
- for (const s of i) if (s && typeof s == "object") {
661
+ function Dt(t, e) {
662
+ 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
+ if (Array.isArray(a)) {
664
+ for (const s of a) if (s && typeof s == "object") {
662
665
  const c = s.sku;
663
666
  typeof c == "string" && e.add(c);
664
667
  }
665
668
  }
666
669
  }
667
- function zt(t) {
670
+ function pe(t) {
668
671
  return { invoke(e, n) {
669
672
  return t("tool.invoke", {
670
673
  name: e,
@@ -672,39 +675,39 @@ function zt(t) {
672
675
  });
673
676
  } };
674
677
  }
675
- function L(t) {
678
+ function rt(t) {
676
679
  return t && typeof t == "object" && !Array.isArray(t) ? t : null;
677
680
  }
678
- function v(t) {
679
- const e = L(t);
681
+ function D(t) {
682
+ const e = rt(t);
680
683
  if (!e) return null;
681
- const n = g(e.sku, e.SKU);
684
+ const n = x(e.sku, e.SKU);
682
685
  if (!n) return null;
683
686
  const r = {
684
687
  sku: n,
685
- name: g(e.name, e.title, e.short_name, n) || n,
686
- url: g(e.url) || ""
687
- }, o = Array.isArray(e.images) ? e.images : void 0, a = g(e.imageUrl, e.image_url, e.image, o?.[0]);
688
- a && (r.imageUrl = a), o && o.length > 1 && (r.images = o.filter((V) => !!V).map(String));
689
- const i = k(e.price_discounted), s = k(e.price), c = i || s;
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]);
691
+ 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;
690
693
  c > 0 && (r.price = String(c));
691
- const u = i > 0 ? s : 0;
694
+ const u = a > 0 ? s : 0;
692
695
  u > 0 && (r.originalPrice = String(u));
693
- const l = g(e.brand);
696
+ const l = x(e.brand);
694
697
  l && (r.brand = l);
695
- const d = k(e.rating);
698
+ const d = I(e.rating);
696
699
  d > 0 && (r.rating = d);
697
- const y = k(e.review_count) || k(e.reviewCount);
698
- y > 0 && (r.reviewCount = y);
699
- const p = g(e.cart_code, e.cartCode);
700
- p && (r.cartCode = p), typeof e.in_stock == "boolean" && (r.inStock = e.in_stock), typeof e.inStock == "boolean" && (r.inStock = e.inStock);
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);
701
704
  const h = e.category_names;
702
705
  return Array.isArray(h) && (r.categoryNames = h.map(String)), r;
703
706
  }
704
- function vt(t) {
705
- const e = L(t);
707
+ function zt(t) {
708
+ const e = rt(t);
706
709
  if (!e) return t;
707
- const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, a = Array.isArray(o) ? o : void 0, i = {
710
+ const n = e.category_names, r = Array.isArray(n) ? n : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
708
711
  sku: e.sku,
709
712
  name: e.name || e.title,
710
713
  url: e.url,
@@ -712,38 +715,38 @@ function vt(t) {
712
715
  currency: e.price_currency || e.currency,
713
716
  category: r?.[r.length - 1] ?? void 0,
714
717
  category_names: r ? r.slice(0, 4) : void 0,
715
- image: a ? a[0] : e.image,
718
+ image: i ? i[0] : e.image,
716
719
  in_stock: e.in_stock,
717
720
  rating: e.rating,
718
721
  review_count: e.review_count
719
722
  };
720
- for (const s of Object.keys(i)) i[s] === void 0 && delete i[s];
721
- return i;
723
+ for (const s of Object.keys(a)) a[s] === void 0 && delete a[s];
724
+ return a;
722
725
  }
723
- function K(t) {
724
- return Array.isArray(t) ? t.map(vt).filter((e) => !!e) : [];
726
+ function ot(t) {
727
+ return Array.isArray(t) ? t.map(zt).filter((e) => !!e) : [];
725
728
  }
726
- function g(...t) {
729
+ function x(...t) {
727
730
  for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
728
731
  return "";
729
732
  }
730
- function k(t) {
733
+ function I(t) {
731
734
  const e = Number(t);
732
735
  return Number.isFinite(e) ? e : 0;
733
736
  }
734
- function R(t) {
737
+ function J(t) {
735
738
  return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
736
739
  }
737
- function Pt(t = []) {
740
+ function Lt(t = []) {
738
741
  const e = {}, n = [];
739
- return (Array.isArray(t) ? t.map(v).filter((r) => !!r) : []).forEach((r, o) => {
740
- const a = `product-${o.toString()}`;
741
- n.push(a);
742
- const i = {
742
+ return (Array.isArray(t) ? t.map(D).filter((r) => !!r) : []).forEach((r, o) => {
743
+ const i = `product-${o.toString()}`;
744
+ n.push(i);
745
+ const a = {
743
746
  sku: r.sku,
744
747
  product: r
745
748
  };
746
- e[a] = {
749
+ e[i] = {
747
750
  type: "ProductCard",
748
751
  props: {
749
752
  product: r,
@@ -751,7 +754,7 @@ function Pt(t = []) {
751
754
  action: {
752
755
  title: r.name,
753
756
  type: "launchSingleProduct",
754
- payload: i
757
+ payload: a
755
758
  }
756
759
  }
757
760
  };
@@ -768,7 +771,7 @@ function Pt(t = []) {
768
771
  }
769
772
  };
770
773
  }
771
- function Ht(t) {
774
+ function me(t) {
772
775
  return {
773
776
  widget: "chat",
774
777
  panelHint: "panel",
@@ -776,13 +779,13 @@ function Ht(t) {
776
779
  root: "root",
777
780
  elements: { root: {
778
781
  type: "ProductDetailsPanel",
779
- props: { product: v(t) || t || {} }
782
+ props: { product: D(t) || t || {} }
780
783
  } }
781
784
  }
782
785
  };
783
786
  }
784
- function Lt(t = {}) {
785
- const e = (t.multiple_product_details || t.products || []).map(v).filter((r) => !!r), n = t.table || {};
787
+ function ye(t = {}) {
788
+ const e = (t.multiple_product_details || t.products || []).map(D).filter((r) => !!r), n = t.table || {};
786
789
  return {
787
790
  widget: "chat",
788
791
  panelHint: "panel",
@@ -797,8 +800,8 @@ function Lt(t = {}) {
797
800
  label: r,
798
801
  values: Array.isArray(o) ? o.map(String) : [String(o ?? "")]
799
802
  })),
800
- highlights: R(t.key_differences),
801
- specialCases: R(t.special_considerations),
803
+ highlights: J(t.key_differences),
804
+ specialCases: J(t.special_considerations),
802
805
  recommendedText: t.recommended_choice,
803
806
  productActions: Object.fromEntries(e.map((r) => [r.sku, {
804
807
  title: r.name,
@@ -813,7 +816,7 @@ function Lt(t = {}) {
813
816
  }
814
817
  };
815
818
  }
816
- function Kt(t = []) {
819
+ function ge(t = []) {
817
820
  return {
818
821
  widget: "chat",
819
822
  panelHint: "inline",
@@ -836,7 +839,7 @@ function Kt(t = []) {
836
839
  }
837
840
  };
838
841
  }
839
- function S(t) {
842
+ function v(t) {
840
843
  const e = t?.payload;
841
844
  if (typeof e == "string") return e;
842
845
  if (e && typeof e == "object" && "text" in e) {
@@ -846,53 +849,53 @@ function S(t) {
846
849
  const n = t?.action;
847
850
  return n && typeof n.payload == "string" ? n.payload : n && typeof n.title == "string" ? n.title : "";
848
851
  }
849
- function Mt(t) {
852
+ function qt(t) {
850
853
  return Object.freeze([...t]);
851
854
  }
852
- function m(t) {
855
+ function _(t) {
853
856
  return t && typeof t == "object" ? t : {};
854
857
  }
855
- function x(t) {
858
+ function N(t) {
856
859
  return t && typeof t == "object" ? t : {};
857
860
  }
858
- function B(t) {
861
+ function K(t) {
859
862
  return t.thread.extensions.beauty_profile;
860
863
  }
861
- var Vt = Mt([{
864
+ var he = qt([{
862
865
  kind: "be_op",
863
866
  op: "beauty-consulting-turn",
864
867
  input: ({ request: t, context: e }) => ({
865
- utterance: S(t),
868
+ utterance: v(t),
866
869
  prior_messages: e.messages.slice(-10),
867
- profile: B(e),
868
- candidate_products: Rt(t),
870
+ profile: K(e),
871
+ candidate_products: Kt(t),
869
872
  locale: e.meta.locale
870
873
  }),
871
874
  out: "consultation",
872
- patch: N
875
+ patch: H
873
876
  }, {
874
877
  kind: "branch",
875
- on: ({ bag: t }) => m(t.consultation).consultation_state?.stage || "answer",
878
+ on: ({ bag: t }) => _(t.consultation).consultation_state?.stage || "answer",
876
879
  cases: {
877
880
  refuse: [{
878
881
  kind: "refusal",
879
882
  message: ({ bag: t }) => {
880
- const e = m(t.consultation);
883
+ const e = _(t.consultation);
881
884
  return e.refusal?.message || e.plain_text || "I cannot help with that request.";
882
885
  }
883
886
  }],
884
887
  needs_more_info: [{
885
888
  kind: "emit",
886
- build: ({ bag: t }) => _(I(m(t.consultation)), !0)
889
+ build: ({ bag: t }) => P(R(_(t.consultation)), !0)
887
890
  }, { kind: "commit" }],
888
891
  search: [
889
892
  {
890
893
  kind: "tool",
891
894
  name: "search",
892
895
  input: ({ request: t, bag: e, context: n }) => {
893
- const r = m(e.consultation);
896
+ const r = _(e.consultation);
894
897
  return {
895
- query: r.search_params?.query || S(t),
898
+ query: r.search_params?.query || v(t),
896
899
  facets: r.search_params?.facets || {},
897
900
  limit: 12,
898
901
  locale: n.meta.locale
@@ -900,31 +903,31 @@ var Vt = Mt([{
900
903
  },
901
904
  out: "products",
902
905
  patch: (t, e) => {
903
- const n = x(e);
906
+ const n = N(e);
904
907
  return { panel: {
905
908
  ...t.panel,
906
- screen_sku_list: A(n).map((r) => Ot(r)).filter((r) => !!r),
909
+ screen_sku_list: O(n).map((r) => Jt(r)).filter((r) => !!r),
907
910
  last_search: { query: n.query || "" }
908
911
  } };
909
912
  }
910
913
  },
911
914
  {
912
915
  kind: "emit",
913
- build: ({ bag: t }) => ht(Pt(A(x(t.products))))
916
+ build: ({ bag: t }) => jt(Lt(O(N(t.products))))
914
917
  },
915
918
  {
916
919
  kind: "be_op",
917
920
  op: "beauty-consulting-turn",
918
921
  input: ({ request: t, context: e, bag: n }) => ({
919
- utterance: S(t),
922
+ utterance: v(t),
920
923
  prior_messages: e.messages.slice(-10),
921
- profile: B(e),
922
- candidate_products: K(A(x(n.products)).slice(0, 12)),
924
+ profile: K(e),
925
+ candidate_products: ot(O(N(n.products)).slice(0, 12)),
923
926
  locale: e.meta.locale
924
927
  }),
925
928
  out: "answer",
926
929
  patch: (t, e) => {
927
- const n = N(t, e), r = (m(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
930
+ const n = H(t, e), r = (_(e).product_mentions || []).map((o) => o.sku).filter((o) => !!o);
928
931
  return {
929
932
  ...n || {},
930
933
  panel: {
@@ -937,8 +940,8 @@ var Vt = Mt([{
937
940
  {
938
941
  kind: "emit",
939
942
  build: ({ bag: t }) => {
940
- const e = m(t.answer);
941
- return _(I(e), !0, { productMentions: e.product_mentions || [] });
943
+ const e = _(t.answer);
944
+ return P(R(e), !0, { productMentions: e.product_mentions || [] });
942
945
  }
943
946
  },
944
947
  { kind: "commit" }
@@ -946,14 +949,14 @@ var Vt = Mt([{
946
949
  default: [{
947
950
  kind: "emit",
948
951
  build: ({ bag: t }) => {
949
- const e = m(t.consultation);
950
- return _(I(e), !0, { productMentions: e.product_mentions || [] });
952
+ const e = _(t.consultation);
953
+ return P(R(e), !0, { productMentions: e.product_mentions || [] });
951
954
  }
952
955
  }, { kind: "commit" }]
953
956
  }
954
957
  }]);
955
- function N(t, e) {
956
- const n = m(e).consultation_state?.captured_profile;
958
+ function H(t, e) {
959
+ const n = _(e).consultation_state?.captured_profile;
957
960
  if (!n) return null;
958
961
  const r = t.thread.extensions.beauty_profile && typeof t.thread.extensions.beauty_profile == "object" ? t.thread.extensions.beauty_profile : {};
959
962
  return { thread: {
@@ -967,53 +970,270 @@ function N(t, e) {
967
970
  }
968
971
  } };
969
972
  }
970
- function A(t) {
973
+ function O(t) {
971
974
  return Array.isArray(t?.products) ? t.products : [];
972
975
  }
973
- function Ot(t) {
976
+ function Jt(t) {
974
977
  if (t && typeof t == "object" && "sku" in t) {
975
978
  const e = t.sku;
976
979
  if (typeof e == "string") return e;
977
980
  }
978
981
  }
979
- function Rt(t) {
982
+ function Kt(t) {
980
983
  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;
981
- return Array.isArray(r) ? K(r.slice(0, 12)) : void 0;
984
+ return Array.isArray(r) ? ot(r.slice(0, 12)) : void 0;
982
985
  }
983
- function I(t) {
986
+ function R(t) {
984
987
  return t?.answer_html || t?.plain_text || t?.refusal?.message || "I can help with beauty shopping.";
985
988
  }
989
+ var W = /* @__PURE__ */ new Set([
990
+ "and",
991
+ "are",
992
+ "box",
993
+ "for",
994
+ "from",
995
+ "gift",
996
+ "gifts",
997
+ "interflora",
998
+ "the",
999
+ "with"
1000
+ ]), Ht = {
1001
+ token: 0.26,
1002
+ keyword: 0.22,
1003
+ category: 0.18,
1004
+ facet: 0.16,
1005
+ color: 0.08,
1006
+ attribute: 0.06,
1007
+ price: 0.08,
1008
+ retrieval: 0.08
1009
+ }, Wt = [
1010
+ "amber",
1011
+ "beige",
1012
+ "black",
1013
+ "blue",
1014
+ "blush",
1015
+ "bronze",
1016
+ "brown",
1017
+ "cream",
1018
+ "gold",
1019
+ "green",
1020
+ "grey",
1021
+ "ivory",
1022
+ "lilac",
1023
+ "mixed",
1024
+ "orange",
1025
+ "pastel",
1026
+ "pink",
1027
+ "purple",
1028
+ "red",
1029
+ "silver",
1030
+ "white",
1031
+ "yellow"
1032
+ ];
1033
+ function S(t) {
1034
+ return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1035
+ }
1036
+ function k(t, e = W) {
1037
+ 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))
1039
+ i.length < 3 || n.has(i) || r.has(i) || (r.add(i), o.push(i));
1040
+ return o;
1041
+ }
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 = [
1045
+ s,
1046
+ c,
1047
+ ...r,
1048
+ ...a,
1049
+ ...y(t.promotions),
1050
+ w(t.description),
1051
+ ...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);
1053
+ return {
1054
+ sku: w(t.sku),
1055
+ title: s,
1056
+ brand: c,
1057
+ productType: p,
1058
+ categoryNames: r,
1059
+ categoryIds: o,
1060
+ facets: i,
1061
+ keywords: b([...u.flatMap((f) => k(f, e.stopWords)), ...d]).slice(0, 12),
1062
+ tokens: d,
1063
+ colors: m,
1064
+ attributes: h,
1065
+ price: Yt(t)
1066
+ };
1067
+ }
1068
+ function ke(t, e = {}) {
1069
+ const n = w(t.product_type, t.productType), r = w(t.title, n, y(t.keywords).join(" ")), o = b([
1070
+ ...y(t.keywords),
1071
+ ...y(t.colors),
1072
+ ...y(t.materials),
1073
+ ...y(t.styles),
1074
+ ...y(t.attributes)
1075
+ ]);
1076
+ return C({
1077
+ sku: "__photo__",
1078
+ name: r,
1079
+ category_names: n ? [n] : [],
1080
+ facet_hits: {
1081
+ colors: y(t.colors).join(", "),
1082
+ materials: y(t.materials).join(", "),
1083
+ styles: y(t.styles).join(", "),
1084
+ attributes: y(t.attributes).join(", ")
1085
+ },
1086
+ promotions: o
1087
+ }, {
1088
+ ...e,
1089
+ sourceProductType: n,
1090
+ sourceKeywords: o
1091
+ });
1092
+ }
1093
+ function we(t, e = {}) {
1094
+ const n = C(t, e);
1095
+ return b([
1096
+ ...e.sourceQueries ?? [],
1097
+ j([
1098
+ n.productType,
1099
+ ...n.colors.slice(0, 1),
1100
+ ...n.attributes.slice(0, 2)
1101
+ ]),
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)),
1105
+ n.productType
1106
+ ].map((r) => r.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1107
+ }
1108
+ function Vt(t, e, n = {}) {
1109
+ const r = {
1110
+ ...Ht,
1111
+ ...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)),
1115
+ reasons: i
1116
+ };
1117
+ }
1118
+ function be(t, e, n = {}) {
1119
+ const r = C(t, n), o = new Set([r.sku, ...n.ignoreSkus ?? []].filter(Boolean));
1120
+ return e.filter((i) => {
1121
+ const a = w(i.sku);
1122
+ return a && !o.has(a);
1123
+ }).map((i) => {
1124
+ const a = Vt(r, i, n);
1125
+ return {
1126
+ ...i,
1127
+ similarity_score: a.score,
1128
+ similarity_reasons: a.reasons
1129
+ };
1130
+ }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(n.limit ?? 12, 100)));
1131
+ }
1132
+ function Gt(t) {
1133
+ return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1134
+ }
1135
+ function w(...t) {
1136
+ for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
1137
+ return "";
1138
+ }
1139
+ function y(t) {
1140
+ 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
+ }
1142
+ function Qt(t) {
1143
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, n]) => [e, w(n)]).filter(([, e]) => e));
1144
+ }
1145
+ function Yt(t) {
1146
+ const e = Number(t.price_discounted);
1147
+ if (Number.isFinite(e) && e > 0) return e;
1148
+ const n = Number(t.price);
1149
+ return Number.isFinite(n) && n > 0 ? n : 0;
1150
+ }
1151
+ function b(t) {
1152
+ const e = /* @__PURE__ */ new Set(), n = [];
1153
+ for (const r of t) {
1154
+ const o = S(r);
1155
+ !o || e.has(o) || (e.add(o), n.push(o));
1156
+ }
1157
+ return n;
1158
+ }
1159
+ function Xt(t, e) {
1160
+ const n = ` ${S(t)} `;
1161
+ return e.filter((r) => n.includes(` ${S(r)} `));
1162
+ }
1163
+ function Zt(t, e, n) {
1164
+ const r = S(t[t.length - 1] ?? t[0] ?? "");
1165
+ if (r) {
1166
+ const o = k(r), i = new Set(k(e));
1167
+ return o.find((a) => i.has(a)) ?? o[0] ?? r;
1168
+ }
1169
+ return n[0] ?? "";
1170
+ }
1171
+ function j(t) {
1172
+ return t.map((e) => S(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1173
+ }
1174
+ function V(t) {
1175
+ return t.flatMap((e) => k(e));
1176
+ }
1177
+ function T(t, e) {
1178
+ const n = b(t), r = new Set(b(e));
1179
+ return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1180
+ }
1181
+ function te(t, e) {
1182
+ const n = b(t), r = new Set(b(e));
1183
+ return n.length === 0 || r.size === 0 ? 0 : n.filter((o) => r.has(o)).length / n.length;
1184
+ }
1185
+ function ee(t, e) {
1186
+ return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1187
+ }
1188
+ function ne(t, e) {
1189
+ return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1190
+ }
1191
+ function re(t, e) {
1192
+ if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1193
+ const n = new Set(k(t.productType)), r = /* @__PURE__ */ new Set([...k(e.productType), ...e.tokens]);
1194
+ return [...n].some((o) => r.has(o));
1195
+ }
1196
+ function oe(t) {
1197
+ return Math.max(0, Math.min(1, t));
1198
+ }
986
1199
  export {
987
- Bt as A,
988
- $t as C,
989
- Ut as D,
990
- ct as E,
991
- tt as M,
992
- E as O,
993
- F as S,
994
- ut as T,
995
- Jt as _,
996
- Lt as a,
997
- Dt as b,
998
- v as c,
999
- zt as d,
1000
- Ft as f,
1001
- wt as g,
1002
- z as h,
1003
- Kt as i,
1004
- Nt as j,
1005
- et as k,
1006
- vt as l,
1007
- qt as m,
1008
- Mt as n,
1009
- Ht as o,
1010
- kt as p,
1011
- S as r,
1012
- Pt as s,
1013
- Vt as t,
1014
- K as u,
1015
- _ as v,
1016
- ft as w,
1017
- q as x,
1018
- ht as y
1200
+ ce as A,
1201
+ Pt as C,
1202
+ ue as D,
1203
+ jt as E,
1204
+ B as F,
1205
+ ft as I,
1206
+ ie as L,
1207
+ bt as M,
1208
+ wt as N,
1209
+ Z as O,
1210
+ se as P,
1211
+ ae as R,
1212
+ et as S,
1213
+ P as T,
1214
+ 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,
1221
+ D as h,
1222
+ S as i,
1223
+ Tt as j,
1224
+ 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,
1231
+ k as s,
1232
+ ke as t,
1233
+ v as u,
1234
+ pe as v,
1235
+ le as w,
1236
+ de as x,
1237
+ fe as y,
1238
+ dt as z
1019
1239
  };