@gengage/assistant-fe 0.6.18 → 0.6.21

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 (49) hide show
  1. package/dist/account-config-D_EMuR0g.js +1479 -0
  2. package/dist/agentic/context/context-store.d.ts +2 -1
  3. package/dist/agentic/index.d.ts +0 -1
  4. package/dist/agentic/index.js +155 -181
  5. package/dist/agentic/types.d.ts +6 -1
  6. package/dist/agentic/worker.d.ts +0 -2
  7. package/dist/agentic/worker.js +117 -415
  8. package/dist/agentic.iife.js +6 -6
  9. package/dist/{api-paths-CEDR4rld.js → api-paths-DcKsQqb6.js} +1 -1
  10. package/dist/chat/components/InlineLauncher.d.ts +1 -1
  11. package/dist/chat/history-storage.d.ts +1 -0
  12. package/dist/chat/runtime.d.ts +1 -1
  13. package/dist/chat/types.d.ts +1 -0
  14. package/dist/chat-runtime.js +1 -1
  15. package/dist/chat.iife.js +10 -10
  16. package/dist/chat.js +1 -1
  17. package/dist/{common-BBgWfT-W.js → common-MpBmMLVk.js} +2 -2
  18. package/dist/common.js +8 -8
  19. package/dist/{connection-warning-B-doodzu.js → connection-warning-ClrMLgmZ.js} +1 -1
  20. package/dist/{context-heG8hv5l.js → context-UTzCGyR9.js} +19 -8
  21. package/dist/{fastIntent-CloHPZQh.js → fastIntent-Bl4xN0qL.js} +2 -2
  22. package/dist/index.js +13 -13
  23. package/dist/{native-webview-NWc9LrJh.js → native-webview-BcwGKkDe.js} +1 -1
  24. package/dist/native.iife.js +6 -6
  25. package/dist/native.js +1 -1
  26. package/dist/{overlay-COzFFq0-.js → overlay-cF2SjxYU.js} +1 -1
  27. package/dist/overlay.js +2 -2
  28. package/dist/qna-runtime.js +1 -1
  29. package/dist/qna.iife.js +1 -1
  30. package/dist/qna.js +1 -1
  31. package/dist/{runtime-BGCNkU1H.js → runtime-BlU1rKqc.js} +4 -4
  32. package/dist/{runtime-Ctqq0V6G.js → runtime-CS4mg3ra.js} +4 -4
  33. package/dist/{runtime-CbWCU424.js → runtime-_koZbJK_.js} +51 -48
  34. package/dist/{simbut-Dh4cJysK.js → simbut-BtL7zYIJ.js} +2 -2
  35. package/dist/simbut.iife.js +1 -1
  36. package/dist/simbut.js +1 -1
  37. package/dist/{simrel-B-sjHbL5.js → simrel-ekf3kUb_.js} +2 -2
  38. package/dist/simrel-runtime.js +1 -1
  39. package/dist/simrel.iife.js +2 -2
  40. package/dist/simrel.js +2 -2
  41. package/dist/{widget-base-CIJT5AiP.js → widget-base-p1EKDuiI.js} +2 -2
  42. package/package.json +4 -2
  43. package/dist/account-config-gj7_mF6Q.js +0 -1731
  44. package/dist/agentic/recipes/catalog-assistant-flow.d.ts +0 -50
  45. package/dist/agentic/recipes/input-text/actions.d.ts +0 -15
  46. package/dist/agentic/recipes/input-text/index.d.ts +0 -4
  47. package/dist/agentic/recipes/input-text/products.d.ts +0 -4
  48. package/dist/agentic/recipes/input-text/ranking.d.ts +0 -14
  49. package/dist/agentic/recipes/input-text/steps.d.ts +0 -31
@@ -0,0 +1,1479 @@
1
+ import { t as lt } from "./request-response-cache-BxRsKGJ0.js";
2
+ function ft(t) {
3
+ return !!t && typeof t == "object" && t.type === "rpc.result";
4
+ }
5
+ function dt(t) {
6
+ return !!t && typeof t == "object" && t.type === "rpc.req";
7
+ }
8
+ function Re(t = self) {
9
+ let e = 1;
10
+ const r = /* @__PURE__ */ new Map();
11
+ return t.addEventListener("message", (n) => {
12
+ const o = n.data;
13
+ if (!ft(o)) return;
14
+ const i = r.get(o.rpcId);
15
+ if (i) {
16
+ if (r.delete(o.rpcId), o.ok === !1) {
17
+ const a = typeof o.error == "object" ? o.error?.message : o.error;
18
+ i.reject(new Error(a || "RPC failed"));
19
+ return;
20
+ }
21
+ i.resolve(o.value);
22
+ }
23
+ }), function(o, i, a) {
24
+ const c = e++;
25
+ return t.postMessage({
26
+ type: "rpc.req",
27
+ rpcId: c,
28
+ method: o,
29
+ payload: i
30
+ }, a || []), new Promise((s, u) => {
31
+ r.set(c, {
32
+ resolve: (l) => s(l),
33
+ reject: u
34
+ });
35
+ });
36
+ };
37
+ }
38
+ function ve({ worker: t, tools: e = {}, beacon: r, memory: n = sessionStorage }) {
39
+ t.addEventListener("message", (o) => {
40
+ const i = o.data;
41
+ dt(i) && pt(t, i, {
42
+ tools: e,
43
+ beacon: r,
44
+ memory: n
45
+ });
46
+ });
47
+ }
48
+ async function pt(t, e, r) {
49
+ try {
50
+ const n = await ht(e.method, e.payload, r);
51
+ t.postMessage({
52
+ type: "rpc.result",
53
+ rpcId: e.rpcId,
54
+ ok: !0,
55
+ value: n
56
+ });
57
+ } catch (n) {
58
+ t.postMessage({
59
+ type: "rpc.result",
60
+ rpcId: e.rpcId,
61
+ ok: !1,
62
+ error: { message: n instanceof Error ? n.message : String(n) }
63
+ });
64
+ }
65
+ }
66
+ function mt(t) {
67
+ if (t && typeof t == "object" && typeof t.name == "string") return t;
68
+ throw new Error("tool.invoke requires { name, input }");
69
+ }
70
+ function yt(t) {
71
+ if (t && typeof t == "object" && t.key !== void 0) return t;
72
+ throw new Error("memory.get requires { key }");
73
+ }
74
+ function gt(t) {
75
+ if (t && typeof t == "object" && t.key !== void 0) return t;
76
+ throw new Error("memory.set requires { key }");
77
+ }
78
+ async function ht(t, e, { tools: r, beacon: n, memory: o }) {
79
+ if (t === "tool.invoke") {
80
+ const { name: i, input: a } = mt(e), c = r[i];
81
+ if (typeof c != "function") throw new Error(`Unknown tool: ${i}`);
82
+ return c(a);
83
+ }
84
+ if (t === "beacon.send")
85
+ return n?.(e), { sent: !0 };
86
+ if (t === "memory.get") {
87
+ const { key: i } = yt(e), a = o.getItem(String(i));
88
+ return a ? JSON.parse(a) : null;
89
+ }
90
+ if (t === "memory.set") {
91
+ const { key: i, value: a } = gt(e);
92
+ return o.setItem(String(i), JSON.stringify(a ?? null)), { ok: !0 };
93
+ }
94
+ throw new Error(`Unknown RPC method: ${t}`);
95
+ }
96
+ function bt() {
97
+ return (/* @__PURE__ */ new Date()).toISOString();
98
+ }
99
+ function O(t) {
100
+ return Math.max(0, Math.round(performance.now() - t));
101
+ }
102
+ function I(t) {
103
+ return typeof t == "object" && t !== null && !Array.isArray(t);
104
+ }
105
+ function wt(t) {
106
+ const { accountId: e, locale: r = "en-GB", parentUrl: n = "", threadId: o, incomingContext: i } = t, a = I(i) ? i : {}, c = I(a.thread) ? a.thread : {}, s = I(a.panel) ? a.panel : {}, u = I(a.meta) ? a.meta : {}, l = Y(a.messages), f = {
107
+ id: String(o || c.id || self.crypto.randomUUID()),
108
+ started_at: String(c.started_at || bt()),
109
+ extensions: I(c.extensions) ? { ...c.extensions } : {}
110
+ }, m = String(u.locale || r), d = String(u.parentUrl || n || typeof self < "u" && self.location?.href || "");
111
+ return {
112
+ panel: { ...s },
113
+ messages: l,
114
+ thread: f,
115
+ meta: {
116
+ locale: m,
117
+ parentUrl: d,
118
+ accountId: e
119
+ }
120
+ };
121
+ }
122
+ function kt(t, e) {
123
+ const r = Y([e])[0];
124
+ return r ? {
125
+ ...t,
126
+ messages: [...t.messages, r].slice(-50)
127
+ } : t;
128
+ }
129
+ function Y(t) {
130
+ return Array.isArray(t) ? t.map((e) => {
131
+ const r = e?.role;
132
+ return {
133
+ role: r === "model" ? "assistant" : typeof r == "string" ? r : "",
134
+ content: String(e?.content || "")
135
+ };
136
+ }).filter((e) => (e.role === "user" || e.role === "assistant") && !!e.content).slice(-50) : [];
137
+ }
138
+ var St = "gengage:agent:context:";
139
+ async function xt({ accountId: t, threadId: e, rpc: r }) {
140
+ const n = await r("memory.get", {
141
+ tier: "session",
142
+ key: X(t, e)
143
+ });
144
+ return n && typeof n == "object" && !Array.isArray(n) ? n : {};
145
+ }
146
+ async function _t({ accountId: t, threadId: e, extensions: r, panel: n, rpc: o }) {
147
+ await o("memory.set", {
148
+ tier: "session",
149
+ key: X(t, e),
150
+ value: {
151
+ thread: { extensions: r },
152
+ ...n && Object.keys(n).length > 0 ? { panel: n } : {}
153
+ }
154
+ });
155
+ }
156
+ function X(t, e) {
157
+ return `${St}${t}:${e}`;
158
+ }
159
+ function g(t) {
160
+ return typeof t == "object" && t !== null && !Array.isArray(t);
161
+ }
162
+ var $e = class {
163
+ #t = /* @__PURE__ */ new Map();
164
+ #e;
165
+ #n;
166
+ #o;
167
+ #r;
168
+ #i;
169
+ #a;
170
+ constructor({ accountId: t, locale: e, parentUrl: r, rpc: n, persistentPanelKeys: o = [], panelKeyLimits: i = {} }) {
171
+ this.#e = t, this.#n = e, this.#o = r, this.#r = n, this.#i = [...new Set(o.filter(Boolean))], this.#a = Tt(i);
172
+ }
173
+ async load(t) {
174
+ const e = t?.meta?.threadId || t?.session_id || t?.sessionId, r = String(e || "default"), n = this.#t.get(r);
175
+ if (n) return n;
176
+ const o = await xt({
177
+ accountId: this.#e,
178
+ threadId: r,
179
+ rpc: this.#r
180
+ }), i = wt({
181
+ accountId: this.#e,
182
+ locale: t?.locale || this.#n,
183
+ parentUrl: this.#o,
184
+ threadId: r,
185
+ incomingContext: It(o, t?.context)
186
+ });
187
+ return this.#t.set(r, i), i;
188
+ }
189
+ patch(t, e) {
190
+ const r = String(t || "default"), n = this.#t.get(r);
191
+ if (!n) return null;
192
+ const o = tt(n, typeof e == "function" ? e(n) : e);
193
+ return this.#t.set(r, o), o;
194
+ }
195
+ appendUserMessage(t, e) {
196
+ const r = String(t || "default");
197
+ if (!e) return this.#t.get(r) ?? null;
198
+ const n = this.#t.get(r);
199
+ if (!n) return null;
200
+ const o = kt(n, {
201
+ role: "user",
202
+ content: e
203
+ });
204
+ return this.#t.set(r, o), o;
205
+ }
206
+ async commit(t) {
207
+ const e = String(t || "default"), r = this.#t.get(e);
208
+ return r ? (await _t({
209
+ accountId: this.#e,
210
+ threadId: e,
211
+ extensions: r.thread.extensions,
212
+ panel: At(r.panel, this.#i, this.#a),
213
+ rpc: this.#r
214
+ }), r) : null;
215
+ }
216
+ };
217
+ function At(t, e, r) {
218
+ if (!e.length || !g(t)) return;
219
+ const n = {};
220
+ for (const o of e) Object.prototype.hasOwnProperty.call(t, o) && (n[o] = jt(t[o], r[o]));
221
+ return n;
222
+ }
223
+ function Tt(t) {
224
+ const e = {};
225
+ for (const [r, n] of Object.entries(t || {})) {
226
+ const o = Math.floor(Number(n));
227
+ r && Number.isFinite(o) && o > 0 && (e[r] = o);
228
+ }
229
+ return e;
230
+ }
231
+ function jt(t, e) {
232
+ return !e || !Array.isArray(t) ? t : t.slice(-e);
233
+ }
234
+ function It(t, e) {
235
+ return !g(t) && !g(e) ? {} : tt(g(t) ? t : {}, g(e) ? e : {});
236
+ }
237
+ function tt(t, e) {
238
+ if (!g(e)) return t;
239
+ const r = t, n = e, o = g(r.panel) ? r.panel : {}, i = g(n.panel) ? n.panel : {}, a = g(r.thread) ? r.thread : {}, c = g(n.thread) ? n.thread : {}, s = g(a.extensions) ? a.extensions : {}, u = g(c.extensions) ? c.extensions : {}, l = g(r.meta) ? r.meta : {}, f = g(n.meta) ? n.meta : {};
240
+ return {
241
+ ...t,
242
+ ...e,
243
+ panel: {
244
+ ...o,
245
+ ...i
246
+ },
247
+ thread: {
248
+ ...a,
249
+ ...c,
250
+ extensions: {
251
+ ...s,
252
+ ...u
253
+ }
254
+ },
255
+ meta: {
256
+ ...l,
257
+ ...f
258
+ },
259
+ messages: Array.isArray(n.messages) ? n.messages.slice(-50) : t.messages ?? []
260
+ };
261
+ }
262
+ function et(t) {
263
+ const e = String.fromCharCode(...t);
264
+ return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
265
+ }
266
+ function K(t) {
267
+ return et(new TextEncoder().encode(JSON.stringify(t)));
268
+ }
269
+ async function Et({ accountId: t, devJwtSecret: e, ttlS: r = 300 }) {
270
+ if (!e) throw new Error("devJwtSecret is required for local agent mode.");
271
+ const n = Math.floor(Date.now() / 1e3), o = `${K({
272
+ alg: "HS256",
273
+ typ: "JWT"
274
+ })}.${K({
275
+ sub: t,
276
+ iat: n,
277
+ exp: n + r,
278
+ scope: "invoke",
279
+ jti: crypto.randomUUID?.() || `${n}-${Math.random()}`
280
+ })}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
281
+ name: "HMAC",
282
+ hash: "SHA-256"
283
+ }, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
284
+ return `${o}.${et(new Uint8Array(a))}`;
285
+ }
286
+ function Ot({ accountId: t, devJwtSecret: e, tokenBrokerUrl: r, tokenBrokerAudience: n, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
287
+ let a = null;
288
+ return async ({ signal: c, parentUrl: s } = {}) => {
289
+ if (e) return Et({
290
+ accountId: t,
291
+ devJwtSecret: e
292
+ });
293
+ if (!r) throw new Error("tokenBrokerUrl is required for production agent mode.");
294
+ const u = Math.floor(Date.now() / 1e3);
295
+ return a?.token && a.expiresAtS - o > u || (a = await Pt({
296
+ accountId: t,
297
+ tokenBrokerUrl: r,
298
+ tokenBrokerAudience: n,
299
+ parentUrl: s,
300
+ signal: c,
301
+ fetchImpl: i
302
+ })), a.token;
303
+ };
304
+ }
305
+ async function Pt({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: r, parentUrl: n, signal: o, fetchImpl: i }) {
306
+ const a = await i(e, {
307
+ method: "POST",
308
+ credentials: "include",
309
+ headers: {
310
+ accept: "application/json",
311
+ "content-type": "application/json"
312
+ },
313
+ body: JSON.stringify({
314
+ accountId: t,
315
+ scope: "invoke",
316
+ audience: r || void 0,
317
+ parentUrl: n || void 0
318
+ }),
319
+ ...o ? { signal: o } : {}
320
+ });
321
+ if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
322
+ const c = await a.json(), s = c?.token || c?.jwt || c?.access_token;
323
+ if (!s || typeof s != "string") throw new Error("Token broker response did not include a JWT.");
324
+ return {
325
+ token: s,
326
+ expiresAtS: Ct(c) || Mt(s) || Math.floor(Date.now() / 1e3) + 300
327
+ };
328
+ }
329
+ function Ct(t) {
330
+ const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
331
+ if (Number.isFinite(e)) return Number(e);
332
+ const r = t?.expiresIn ?? t?.expires_in;
333
+ if (Number.isFinite(r)) return Math.floor(Date.now() / 1e3) + Number(r);
334
+ const n = t?.expiresAt ?? t?.expires_at;
335
+ if (typeof n == "string") {
336
+ const o = Date.parse(n);
337
+ if (Number.isFinite(o)) return Math.floor(o / 1e3);
338
+ }
339
+ return null;
340
+ }
341
+ function Mt(t) {
342
+ try {
343
+ const [, e] = t.split(".");
344
+ if (!e) return null;
345
+ const r = e.replace(/-/gu, "+").replace(/_/gu, "/"), n = atob(r.padEnd(Math.ceil(r.length / 4) * 4, "=")), o = JSON.parse(n);
346
+ return Number.isFinite(o?.exp) ? Number(o.exp) : null;
347
+ } catch {
348
+ return null;
349
+ }
350
+ }
351
+ var q = {
352
+ unauthorized: {
353
+ code: "auth",
354
+ message: "Assistant authentication failed. Please retry."
355
+ },
356
+ forbidden: {
357
+ code: "auth",
358
+ message: "Assistant authentication failed. Please retry."
359
+ },
360
+ unknown_op: {
361
+ code: "op_unavailable",
362
+ message: "This assistant action is not available yet."
363
+ },
364
+ invalid_input: {
365
+ code: "invalid_request",
366
+ message: "The assistant request was not valid."
367
+ },
368
+ account_config: {
369
+ code: "account_config",
370
+ message: "Assistant configuration is unavailable."
371
+ },
372
+ upstream_llm: {
373
+ code: "op_failed",
374
+ message: "The assistant could not complete that request."
375
+ },
376
+ upstream_timeout: {
377
+ code: "op_timeout",
378
+ message: "The assistant took too long to respond."
379
+ },
380
+ schema_mismatch: {
381
+ code: "op_failed",
382
+ message: "The assistant could not complete that request."
383
+ },
384
+ rate_limited: {
385
+ code: "rate_limited",
386
+ message: "The assistant is receiving too many requests. Please retry shortly."
387
+ },
388
+ internal: {
389
+ code: "op_failed",
390
+ message: "The assistant could not complete that request."
391
+ },
392
+ payload_too_large: {
393
+ code: "invalid_request",
394
+ message: "The assistant request was too large."
395
+ }
396
+ }, v = class extends Error {
397
+ constructor(t, e, r = {}) {
398
+ super(e), this.name = "AgentError", this.code = t, this.source = r.source || "agent", r.sourceCode && (this.sourceCode = r.sourceCode), r.detail !== void 0 && (this.detail = r.detail);
399
+ }
400
+ };
401
+ function rt(t) {
402
+ const e = String(t?.code || "upstream_llm"), r = q[e] || q.upstream_llm;
403
+ return new v(r.code, r.message, {
404
+ source: "be",
405
+ sourceCode: e,
406
+ detail: t?.detail
407
+ });
408
+ }
409
+ function Nt(t, e) {
410
+ const r = e?.error && typeof e.error == "object" ? e.error : {};
411
+ return rt({
412
+ code: String(r.code || Bt(t)),
413
+ detail: r.detail
414
+ });
415
+ }
416
+ function Ue(t) {
417
+ return t instanceof v ? {
418
+ type: "error",
419
+ code: t.code,
420
+ message: t.message
421
+ } : {
422
+ type: "error",
423
+ code: "agent_invoke_failed",
424
+ message: "The assistant could not complete that request."
425
+ };
426
+ }
427
+ function Bt(t) {
428
+ return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
429
+ }
430
+ async function Fe({ beUrl: t, accountId: e, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: c, input: s, cacheTtlS: u, cacheKey: l, browserCache: f, signal: m }) {
431
+ const d = await (i || Ot({
432
+ accountId: e,
433
+ devJwtSecret: r,
434
+ tokenBrokerUrl: n,
435
+ tokenBrokerAudience: o
436
+ }))({
437
+ ...m ? { signal: m } : {},
438
+ ...a ? { parentUrl: a } : {}
439
+ }), { opDomain: h, opName: p } = Rt(c, e), A = {
440
+ method: "POST",
441
+ headers: {
442
+ authorization: `Bearer ${d}`,
443
+ "content-type": "application/json",
444
+ accept: "application/x-ndjson"
445
+ },
446
+ body: JSON.stringify({
447
+ op_domain: h,
448
+ op_name: p,
449
+ op_payload: s,
450
+ ...u !== void 0 ? { cache_ttl_s: u } : {},
451
+ ...l !== void 0 ? { cache_key: l } : {}
452
+ }),
453
+ ...m ? { signal: m } : {}
454
+ }, z = `${String(t).replace(/\/+$/u, "")}/v1/execute`, M = f === !1 ? await fetch(z, A) : await lt(z, A, typeof f == "object" ? f : {});
455
+ if (!M.ok) throw Nt(M.status, await $t(M));
456
+ return Ut(M);
457
+ }
458
+ function Rt(t, e) {
459
+ if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
460
+ return {
461
+ opDomain: vt(e),
462
+ opName: t
463
+ };
464
+ }
465
+ function vt(t) {
466
+ return t.replace(/-agentic$/u, "");
467
+ }
468
+ async function $t(t) {
469
+ try {
470
+ return await t.json();
471
+ } catch {
472
+ return { error: { code: t.statusText || "internal" } };
473
+ }
474
+ }
475
+ async function Ut(t) {
476
+ const e = t.body?.getReader();
477
+ if (!e) throw new Error("BE response body is not readable.");
478
+ const r = new TextDecoder();
479
+ let n = "";
480
+ const o = {};
481
+ for (; ; ) {
482
+ const { value: a, done: c } = await e.read();
483
+ if (c) break;
484
+ n += r.decode(a, { stream: !0 });
485
+ let s = n.indexOf(`
486
+ `);
487
+ for (; s >= 0; ) {
488
+ const u = n.slice(0, s).trim();
489
+ n = n.slice(s + 1), u && J(JSON.parse(u), o), s = n.indexOf(`
490
+ `);
491
+ }
492
+ }
493
+ const i = n.trim();
494
+ return i && J(JSON.parse(i), o), o;
495
+ }
496
+ function J(t, e) {
497
+ if (t._error) throw rt(t._error);
498
+ if (!t._end)
499
+ for (const [r, n] of Object.entries(t)) {
500
+ if (Object.prototype.hasOwnProperty.call(e, r)) throw new v("op_failed", `BE streamed duplicate field "${r}".`, {
501
+ source: "be",
502
+ sourceCode: "schema_mismatch"
503
+ });
504
+ e[r] = n;
505
+ }
506
+ }
507
+ function De(t = {}) {
508
+ return {
509
+ type: "metadata",
510
+ ...t
511
+ };
512
+ }
513
+ function Ft(t, e = !1, r = {}) {
514
+ return {
515
+ type: "text_chunk",
516
+ content: t,
517
+ final: e,
518
+ ...r
519
+ };
520
+ }
521
+ function Le(t) {
522
+ return {
523
+ type: "ui_spec",
524
+ ...t
525
+ };
526
+ }
527
+ function ze(t) {
528
+ return {
529
+ type: "action",
530
+ action: t
531
+ };
532
+ }
533
+ function Dt(t, e) {
534
+ return {
535
+ type: "error",
536
+ code: t,
537
+ message: e
538
+ };
539
+ }
540
+ function nt() {
541
+ return { type: "done" };
542
+ }
543
+ function Lt(t, e) {
544
+ return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
545
+ }
546
+ async function Ke({ request: t, accountModule: e, contextStore: r, beClient: n, toolBridge: o, emit: i, rpc: a, signal: c }) {
547
+ const s = performance.now(), u = await r.load(t), l = u.thread.id, f = ee(t);
548
+ r.appendUserMessage(l, f);
549
+ const m = Lt(e.flows, t);
550
+ if (!m)
551
+ return i(Dt("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(nt()), {
552
+ steps: 0,
553
+ productSkusEmitted: []
554
+ };
555
+ const d = {
556
+ request: t,
557
+ context: r.patch(l, {}) || u,
558
+ bag: {},
559
+ accountConfig: e.accountConfig || {},
560
+ threadId: l,
561
+ steps: 0,
562
+ productSkusEmitted: /* @__PURE__ */ new Set(),
563
+ committed: !1
564
+ }, h = {
565
+ contextStore: r,
566
+ beClient: n,
567
+ toolBridge: o,
568
+ emit: i,
569
+ rpc: a,
570
+ adapters: e.adapters || {},
571
+ ...c ? { signal: c } : {}
572
+ };
573
+ return await C(m, d, h), d.committed || await $(d, h), await a("beacon.send", {
574
+ type: "turnSummary",
575
+ threadId: l,
576
+ sessionId: t?.session_id || t?.sessionId || l,
577
+ accountId: e.accountId || d.context.meta.accountId,
578
+ steps: d.steps,
579
+ totalLatencyMs: O(s),
580
+ productSkusEmitted: [...d.productSkusEmitted]
581
+ }), {
582
+ steps: d.steps,
583
+ productSkusEmitted: [...d.productSkusEmitted]
584
+ };
585
+ }
586
+ async function C(t, e, r) {
587
+ for (const n of t) {
588
+ if (r.signal?.aborted || e.committed) return;
589
+ e.steps += 1, await zt(n, e, r), e.context = r.contextStore.patch(e.threadId, {}) || e.context;
590
+ }
591
+ }
592
+ async function zt(t, e, r) {
593
+ const n = U(e);
594
+ if (t.kind === "be_op") {
595
+ await Kt(t, e, r, n);
596
+ return;
597
+ }
598
+ if (t.kind === "tool") {
599
+ await qt(t, e, r, n);
600
+ return;
601
+ }
602
+ if (t.kind === "adapter") {
603
+ await Jt(t, e, r, n);
604
+ return;
605
+ }
606
+ if (t.kind === "emit") {
607
+ Wt(t, e, r);
608
+ return;
609
+ }
610
+ if (t.kind === "patch") {
611
+ Ht(t, e, r);
612
+ return;
613
+ }
614
+ if (t.kind === "branch") {
615
+ await Vt(t, e, r, n);
616
+ return;
617
+ }
618
+ if (t.kind === "parallel") {
619
+ await Gt(t, e, r);
620
+ return;
621
+ }
622
+ if (t.kind === "refusal") {
623
+ await Qt(t, e, r, n);
624
+ return;
625
+ }
626
+ t.kind === "commit" && await Zt(t, e, r);
627
+ }
628
+ async function Kt(t, e, r, n) {
629
+ const o = performance.now();
630
+ let i;
631
+ const a = x(t.cacheTtlS, n), c = x(t.cacheKey, n), s = x(t.browserCache, n);
632
+ try {
633
+ i = await r.beClient.invoke({
634
+ op: t.op,
635
+ input: x(t.input, n),
636
+ ...a !== void 0 ? { cacheTtlS: a } : {},
637
+ ...c !== void 0 ? { cacheKey: c } : {},
638
+ ...s !== void 0 ? { browserCache: s } : {},
639
+ ...r.signal ? { signal: r.signal } : {}
640
+ });
641
+ } catch (l) {
642
+ const f = l, m = String(f?.sourceCode || f?.code || "unknown"), d = {
643
+ type: "agentOp",
644
+ threadId: e.threadId,
645
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
646
+ accountId: e.context.meta.accountId,
647
+ op: t.op,
648
+ status: "error",
649
+ latencyMs: O(o),
650
+ errorCode: m
651
+ };
652
+ if (await r.rpc("beacon.send", d), t.onError) {
653
+ t.errorOut && (e.bag[t.errorOut] = l), await C(t.onError, e, r);
654
+ return;
655
+ }
656
+ throw l;
657
+ }
658
+ t.out && (e.bag[t.out] = i), B(t, i, e, r.contextStore);
659
+ const u = {
660
+ type: "agentOp",
661
+ threadId: e.threadId,
662
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
663
+ accountId: e.context.meta.accountId,
664
+ op: t.op,
665
+ status: "ok",
666
+ latencyMs: O(o)
667
+ };
668
+ await r.rpc("beacon.send", u);
669
+ }
670
+ async function qt(t, e, r, n) {
671
+ const o = performance.now();
672
+ try {
673
+ const i = await r.toolBridge.invoke(t.name, x(t.input, n));
674
+ t.out && (e.bag[t.out] = i), B(t, i, e, r.contextStore), await r.rpc("beacon.send", {
675
+ type: "agentTool",
676
+ threadId: e.threadId,
677
+ sessionId: W(e),
678
+ accountId: e.context.meta.accountId,
679
+ tool: t.name,
680
+ status: "ok",
681
+ latencyMs: O(o)
682
+ });
683
+ } catch (i) {
684
+ const a = i;
685
+ if (await r.rpc("beacon.send", {
686
+ type: "agentTool",
687
+ threadId: e.threadId,
688
+ sessionId: W(e),
689
+ accountId: e.context.meta.accountId,
690
+ tool: t.name,
691
+ status: "error",
692
+ latencyMs: O(o),
693
+ errorCode: String(a?.code || a?.name || "unknown")
694
+ }), t.onError) {
695
+ t.errorOut && (e.bag[t.errorOut] = i), await C(t.onError, e, r);
696
+ return;
697
+ }
698
+ throw i;
699
+ }
700
+ }
701
+ async function Jt(t, e, r, n) {
702
+ const o = r.adapters?.[t.name];
703
+ if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
704
+ const i = await o(x(t.input, n), n);
705
+ t.out && (e.bag[t.out] = i), B(t, i, e, r.contextStore);
706
+ }
707
+ function Wt(t, e, r) {
708
+ const n = t.build(U(e));
709
+ re(n, e.productSkusEmitted), r.emit(n);
710
+ }
711
+ function Ht(t, e, r) {
712
+ B(t, void 0, e, r.contextStore);
713
+ }
714
+ async function Vt(t, e, r, n) {
715
+ const o = String(x(t.on, n) || "default");
716
+ await C(t.cases[o] || t.cases.default || [], e, r);
717
+ }
718
+ async function Gt(t, e, r) {
719
+ const n = t.steps.map((a) => {
720
+ const c = {
721
+ ...e,
722
+ context: Yt(e.context),
723
+ bag: { ...e.bag },
724
+ productSkusEmitted: e.productSkusEmitted,
725
+ committed: !1
726
+ };
727
+ return C(a, c, {
728
+ ...r,
729
+ emit: (s) => {
730
+ s.type !== "done" && r.emit(s);
731
+ },
732
+ contextStore: Xt(c)
733
+ }).then(() => c);
734
+ }), o = await Promise.all(n), i = t.merge || {};
735
+ for (const a of o) {
736
+ for (const c of i.bag || []) Object.prototype.hasOwnProperty.call(a.bag, c) && (e.bag[c] = a.bag[c]);
737
+ if (i.panel?.length) {
738
+ const c = H(a.context.panel, i.panel);
739
+ Object.keys(c).length && (e.context = r.contextStore.patch(e.threadId, { panel: c }) || e.context);
740
+ }
741
+ if (i.threadExtensions?.length) {
742
+ const c = H(a.context.thread.extensions, i.threadExtensions);
743
+ Object.keys(c).length && (e.context = r.contextStore.patch(e.threadId, { thread: {
744
+ ...e.context.thread,
745
+ extensions: c
746
+ } }) || e.context);
747
+ }
748
+ }
749
+ }
750
+ async function Qt(t, e, r, n) {
751
+ r.emit(Ft(x(t.message, n), !0)), await $(e, r);
752
+ }
753
+ async function Zt(t, e, r) {
754
+ await $(e, r);
755
+ }
756
+ async function $(t, { contextStore: e, emit: r }) {
757
+ t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, r(nt()));
758
+ }
759
+ function B(t, e, r, n) {
760
+ if (typeof t.patch != "function") return;
761
+ const o = t.patch(r.context, e, U(r));
762
+ o && (r.context = n.patch(r.threadId, o) || r.context);
763
+ }
764
+ function U(t) {
765
+ return {
766
+ request: t.request,
767
+ context: t.context,
768
+ bag: t.bag,
769
+ accountConfig: t.accountConfig
770
+ };
771
+ }
772
+ function W(t) {
773
+ return t.request?.session_id || t.request?.sessionId || t.threadId;
774
+ }
775
+ function Yt(t) {
776
+ return typeof structuredClone == "function" ? structuredClone(t) : JSON.parse(JSON.stringify(t));
777
+ }
778
+ function H(t, e) {
779
+ const r = {};
780
+ for (const n of e) Object.prototype.hasOwnProperty.call(t, n) && (r[n] = t[n]);
781
+ return r;
782
+ }
783
+ function Xt(t) {
784
+ return {
785
+ async load() {
786
+ return t.context;
787
+ },
788
+ patch(e, r) {
789
+ return t.context = te(t.context, r), t.context;
790
+ },
791
+ appendUserMessage() {
792
+ return t.context;
793
+ },
794
+ async commit() {
795
+ return t.context;
796
+ }
797
+ };
798
+ }
799
+ function te(t, e) {
800
+ return !e || typeof e != "object" ? t : {
801
+ ...t,
802
+ ...e,
803
+ panel: {
804
+ ...t.panel || {},
805
+ ...e.panel || {}
806
+ },
807
+ thread: {
808
+ ...t.thread || {},
809
+ ...e.thread || {},
810
+ extensions: {
811
+ ...t.thread?.extensions || {},
812
+ ...e.thread?.extensions || {}
813
+ }
814
+ },
815
+ meta: {
816
+ ...t.meta || {},
817
+ ...e.meta || {}
818
+ },
819
+ messages: Array.isArray(e.messages) ? e.messages.slice(-50) : t.messages
820
+ };
821
+ }
822
+ function x(t, e) {
823
+ return typeof t == "function" ? t(e) : t;
824
+ }
825
+ function ee(t) {
826
+ const e = t?.payload;
827
+ if (typeof e == "string") return e;
828
+ if (e && typeof e == "object" && "text" in e) {
829
+ const r = e.text;
830
+ if (typeof r == "string") return r;
831
+ }
832
+ return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
833
+ }
834
+ function re(t, e) {
835
+ const r = t, n = r.spec, o = Array.isArray(n?.items) ? n.items : void 0, i = Array.isArray(r.items) ? r.items : void 0, a = o || i;
836
+ if (Array.isArray(a)) {
837
+ for (const c of a) if (c && typeof c == "object") {
838
+ const s = c.sku;
839
+ typeof s == "string" && e.add(s);
840
+ }
841
+ }
842
+ }
843
+ function qe(t) {
844
+ return { invoke(e, r) {
845
+ return t("tool.invoke", {
846
+ name: e,
847
+ input: r
848
+ });
849
+ } };
850
+ }
851
+ function ot(t) {
852
+ return t && typeof t == "object" && !Array.isArray(t) ? t : null;
853
+ }
854
+ function F(t) {
855
+ const e = ot(t);
856
+ if (!e) return null;
857
+ const r = T(e.sku, e.SKU);
858
+ if (!r) return null;
859
+ const n = {
860
+ sku: r,
861
+ name: T(e.name, e.title, e.short_name, r) || r,
862
+ url: T(e.url) || ""
863
+ }, o = Array.isArray(e.images) ? e.images : void 0, i = T(e.imageUrl, e.image_url, e.image, o?.[0]);
864
+ i && (n.imageUrl = i), o && o.length > 1 && (n.images = o.filter((p) => !!p).map(String));
865
+ const a = E(e.price_discounted), c = E(e.price), s = a || c;
866
+ s > 0 && (n.price = String(s));
867
+ const u = a > 0 ? c : 0;
868
+ u > 0 && (n.originalPrice = String(u));
869
+ const l = T(e.brand);
870
+ l && (n.brand = l);
871
+ const f = E(e.rating);
872
+ f > 0 && (n.rating = f);
873
+ const m = E(e.review_count) || E(e.reviewCount);
874
+ m > 0 && (n.reviewCount = m);
875
+ const d = T(e.cart_code, e.cartCode);
876
+ d && (n.cartCode = d), typeof e.in_stock == "boolean" && (n.inStock = e.in_stock), typeof e.inStock == "boolean" && (n.inStock = e.inStock);
877
+ const h = e.category_names;
878
+ return Array.isArray(h) && (n.categoryNames = h.map(String)), n;
879
+ }
880
+ function D(t) {
881
+ const e = ot(t);
882
+ if (!e) return t;
883
+ const r = e.category_names, n = Array.isArray(r) ? r : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
884
+ sku: e.sku,
885
+ name: e.name || e.title,
886
+ url: e.url,
887
+ price: e.price,
888
+ currency: e.price_currency || e.currency,
889
+ category: n?.[n.length - 1] ?? void 0,
890
+ category_names: n ? n.slice(0, 4) : void 0,
891
+ image: i ? i[0] : e.image,
892
+ in_stock: e.in_stock,
893
+ rating: e.rating,
894
+ review_count: e.review_count
895
+ };
896
+ for (const c of Object.keys(a)) a[c] === void 0 && delete a[c];
897
+ return a;
898
+ }
899
+ function Je(t) {
900
+ return Array.isArray(t) ? t.map(D).filter((e) => !!e) : [];
901
+ }
902
+ function T(...t) {
903
+ for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
904
+ return "";
905
+ }
906
+ function E(t) {
907
+ const e = Number(t);
908
+ return Number.isFinite(e) ? e : 0;
909
+ }
910
+ function V(t) {
911
+ return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
912
+ }
913
+ function We(t, e, r = {}) {
914
+ return `${t}:${r.version || "v2"}:${it(e)}`;
915
+ }
916
+ function He(t, e = {}) {
917
+ return at(t).map((r) => ct(typeof r == "string" ? r : r.sku, e.locale)).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n).sort((r, n) => L(r, n, e.locale)).slice(0, e.limit || 16).join(",");
918
+ }
919
+ function Ve(t, e = {}) {
920
+ return it(at(t).map((r) => ne(r, e)).filter((r) => !!r).sort((r, n) => L(String(r.sku || r.name || ""), String(n.sku || n.name || ""), e.locale)).slice(0, e.limit || 16));
921
+ }
922
+ function Ge(t, e) {
923
+ return S(t, e);
924
+ }
925
+ function it(t) {
926
+ let e = 2166136261;
927
+ const r = oe(t);
928
+ for (let n = 0; n < r.length; n += 1)
929
+ e ^= r.charCodeAt(n), e = Math.imul(e, 16777619);
930
+ return (e >>> 0).toString(36);
931
+ }
932
+ function ne(t, e) {
933
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
934
+ const r = t, n = e.mapProduct?.(r);
935
+ if (n) return P(n);
936
+ const o = D(r);
937
+ return o && typeof o == "object" && !Array.isArray(o) ? P(ie(o, e)) : null;
938
+ }
939
+ function at(t) {
940
+ return Array.isArray(t) ? t.filter((e) => typeof e == "string" || !!(e && typeof e == "object" && !Array.isArray(e))) : [];
941
+ }
942
+ function oe(t) {
943
+ return JSON.stringify(P(t));
944
+ }
945
+ function P(t) {
946
+ return Array.isArray(t) ? t.map(P) : !t || typeof t != "object" ? t : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0).sort(([e], [r]) => e.localeCompare(r)).map(([e, r]) => [e, P(r)]));
947
+ }
948
+ function ie(t, e) {
949
+ return {
950
+ sku: ct(t.sku, e.locale),
951
+ name: S(t.name, e.locale),
952
+ url: S(t.url, e.locale),
953
+ price: t.price,
954
+ currency: S(t.currency, e.locale),
955
+ category: S(t.category, e.locale),
956
+ category_names: ae(t.category_names, e.locale, 16),
957
+ image: S(t.image, e.locale),
958
+ in_stock: t.in_stock,
959
+ rating: t.rating,
960
+ review_count: t.review_count
961
+ };
962
+ }
963
+ function ct(t, e) {
964
+ return S(t, e).toUpperCase();
965
+ }
966
+ function S(t, e) {
967
+ return typeof t == "string" ? t.trim().replace(/\s+/gu, " ").toLocaleLowerCase(e || void 0) : "";
968
+ }
969
+ function L(t, e, r) {
970
+ return t.localeCompare(e, r, { numeric: !0 });
971
+ }
972
+ function ae(t, e, r) {
973
+ return Array.isArray(t) ? t.map((n) => S(n, e)).filter(Boolean).sort((n, o) => L(n, o, e)).slice(0, r) : void 0;
974
+ }
975
+ function Qe(t, e = {}) {
976
+ if (!Array.isArray(t)) return [];
977
+ const r = e.maxItems ?? 8, n = e.maxFeatures ?? 8;
978
+ return t.map((o) => ce(o, e.defaultBrand, n)).filter((o) => !!o).slice(0, r);
979
+ }
980
+ function ce(t, e, r) {
981
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
982
+ const n = t, o = D(n);
983
+ return o ? le({
984
+ sku: o.sku,
985
+ name: o.name,
986
+ url: o.url,
987
+ image: o.image,
988
+ price: o.price,
989
+ currency: o.currency,
990
+ category: o.category,
991
+ category_names: o.category_names,
992
+ brand: n.brand || e,
993
+ features: se(n.features, r),
994
+ specs: ue(n.specs, r),
995
+ in_stock: o.in_stock
996
+ }) : null;
997
+ }
998
+ function se(t, e) {
999
+ return Array.isArray(t) ? t.filter(Boolean).slice(0, e) : void 0;
1000
+ }
1001
+ function ue(t, e) {
1002
+ if (!(!t || typeof t != "object" || Array.isArray(t)))
1003
+ return Object.fromEntries(Object.entries(t).filter(([, r]) => r != null).slice(0, e));
1004
+ }
1005
+ function le(t) {
1006
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
1007
+ }
1008
+ function st(t) {
1009
+ if (!t || typeof t != "object" || Array.isArray(t)) return {};
1010
+ const e = t, r = Array.isArray(e.rows) ? e.rows : [];
1011
+ return {
1012
+ ...e,
1013
+ rows: r.map(de).filter(Boolean)
1014
+ };
1015
+ }
1016
+ function fe(t, e) {
1017
+ const r = Array.isArray(t) ? t.filter((c) => !!(c && typeof c == "object" && !Array.isArray(c))) : [], n = st(e), o = Array.isArray(n.columns) ? n.columns.map(String) : [];
1018
+ if (!o.length) return r;
1019
+ const i = new Map(r.map((c) => [String(c.sku || c.id || ""), c])), a = o.map((c) => i.get(c)).filter((c) => !!c);
1020
+ return a.length ? a : r;
1021
+ }
1022
+ function Ze(t, e) {
1023
+ const r = st(t?.table), n = fe(e, r);
1024
+ return {
1025
+ ...t || {},
1026
+ table: r,
1027
+ products: n,
1028
+ multiple_product_details: n
1029
+ };
1030
+ }
1031
+ function de(t) {
1032
+ return !t || typeof t != "object" || Array.isArray(t) ? null : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
1033
+ }
1034
+ function Ye(t = []) {
1035
+ const e = {}, r = [];
1036
+ return (Array.isArray(t) ? t.map(F).filter((n) => !!n) : []).forEach((n, o) => {
1037
+ const i = `product-${o.toString()}`;
1038
+ r.push(i);
1039
+ const a = {
1040
+ sku: n.sku,
1041
+ product: n
1042
+ };
1043
+ e[i] = {
1044
+ type: "ProductCard",
1045
+ props: {
1046
+ product: n,
1047
+ index: o,
1048
+ action: {
1049
+ title: n.name,
1050
+ type: "launchSingleProduct",
1051
+ payload: a
1052
+ }
1053
+ }
1054
+ };
1055
+ }), e.root = {
1056
+ type: "ProductGrid",
1057
+ props: { layout: "grid" },
1058
+ children: r
1059
+ }, {
1060
+ widget: "chat",
1061
+ panelHint: "panel",
1062
+ spec: {
1063
+ root: "root",
1064
+ elements: e
1065
+ }
1066
+ };
1067
+ }
1068
+ function Xe(t) {
1069
+ return {
1070
+ widget: "chat",
1071
+ panelHint: "panel",
1072
+ spec: {
1073
+ root: "root",
1074
+ elements: { root: {
1075
+ type: "ProductDetailsPanel",
1076
+ props: { product: F(t) || t || {} }
1077
+ } }
1078
+ }
1079
+ };
1080
+ }
1081
+ function tr(t = {}) {
1082
+ const e = (t.multiple_product_details || t.products || []).map(F).filter((n) => !!n), r = t.table || {};
1083
+ return {
1084
+ widget: "chat",
1085
+ panelHint: "panel",
1086
+ spec: {
1087
+ root: "root",
1088
+ elements: { root: {
1089
+ type: "ComparisonTable",
1090
+ props: {
1091
+ products: e,
1092
+ recommended: e.find((n) => n.sku === t.recommended_choice_sku) || e[0],
1093
+ attributes: Object.entries(r).map(([n, o]) => ({
1094
+ label: n,
1095
+ values: Array.isArray(o) ? o.map(String) : [String(o ?? "")]
1096
+ })),
1097
+ highlights: V(t.key_differences),
1098
+ specialCases: V(t.special_considerations),
1099
+ recommendedText: t.recommended_choice,
1100
+ productActions: Object.fromEntries(e.map((n) => [n.sku, {
1101
+ title: n.name,
1102
+ type: "launchSingleProduct",
1103
+ payload: {
1104
+ sku: n.sku,
1105
+ product: n
1106
+ }
1107
+ }]))
1108
+ }
1109
+ } }
1110
+ }
1111
+ };
1112
+ }
1113
+ function er(t = []) {
1114
+ return {
1115
+ widget: "chat",
1116
+ panelHint: "inline",
1117
+ spec: {
1118
+ root: "root",
1119
+ elements: { root: {
1120
+ type: "ActionButtons",
1121
+ props: { buttons: (Array.isArray(t) ? t : []).map((e) => {
1122
+ const r = e.label || e.title || e.shortName || "", n = e.action || e.requestDetails || e.request_details;
1123
+ return !r || !n?.type ? null : {
1124
+ label: r,
1125
+ action: {
1126
+ title: r,
1127
+ type: n.type,
1128
+ ...n.payload !== void 0 ? { payload: n.payload } : {}
1129
+ }
1130
+ };
1131
+ }).filter((e) => !!e) }
1132
+ } }
1133
+ }
1134
+ };
1135
+ }
1136
+ function rr(t) {
1137
+ return Object.freeze([...t]);
1138
+ }
1139
+ var G = /* @__PURE__ */ new Set([
1140
+ "and",
1141
+ "are",
1142
+ "for",
1143
+ "from",
1144
+ "the",
1145
+ "with"
1146
+ ]), pe = {
1147
+ token: 0.26,
1148
+ keyword: 0.22,
1149
+ category: 0.18,
1150
+ facet: 0.16,
1151
+ color: 0.08,
1152
+ attribute: 0.06,
1153
+ price: 0.08,
1154
+ retrieval: 0.08
1155
+ }, me = [
1156
+ "amber",
1157
+ "beige",
1158
+ "black",
1159
+ "blue",
1160
+ "blush",
1161
+ "bronze",
1162
+ "brown",
1163
+ "cream",
1164
+ "gold",
1165
+ "green",
1166
+ "grey",
1167
+ "ivory",
1168
+ "lilac",
1169
+ "mixed",
1170
+ "orange",
1171
+ "pastel",
1172
+ "pink",
1173
+ "purple",
1174
+ "red",
1175
+ "silver",
1176
+ "white",
1177
+ "yellow"
1178
+ ];
1179
+ function _(t) {
1180
+ return String(t ?? "").normalize("NFKD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/gu, " ").trim();
1181
+ }
1182
+ function b(t, e = G) {
1183
+ const r = e instanceof Set ? e : /* @__PURE__ */ new Set([...G, ...e]), n = /* @__PURE__ */ new Set(), o = [];
1184
+ for (const i of _(t).split(/\s+/u))
1185
+ i.length < 3 || r.has(i) || n.has(i) || (n.add(i), o.push(i));
1186
+ return o;
1187
+ }
1188
+ function R(t, e = {}) {
1189
+ if (ge(t)) return t;
1190
+ const r = e.facetKeys, n = y(t.category_names ?? t.category), o = y(t.category_ids), i = he(t.facet_hits), a = Object.entries(i).filter(([p]) => !r || r.some((A) => _(A) === _(p))).map(([, p]) => p), c = w(t.name, t.title), s = w(t.brand), u = e.sourceKeywords ?? [], l = [
1191
+ c,
1192
+ s,
1193
+ ...n,
1194
+ ...a,
1195
+ ...y(t.promotions),
1196
+ w(t.description),
1197
+ ...u
1198
+ ].join(" "), f = b(l, e.stopWords), m = w(e.sourceProductType, ke(n, c, f), f[0]), d = k([...we(l, me), ...Object.entries(i).filter(([p]) => /colou?r/iu.test(p)).flatMap(([, p]) => b(p, e.stopWords))]), h = k([...a.flatMap((p) => b(p, e.stopWords)), ...y(t.promotions).flatMap((p) => b(p, e.stopWords))]).slice(0, 24);
1199
+ return {
1200
+ sku: w(t.sku),
1201
+ title: c,
1202
+ brand: s,
1203
+ productType: m,
1204
+ categoryNames: n,
1205
+ categoryIds: o,
1206
+ facets: i,
1207
+ keywords: k([...u.flatMap((p) => b(p, e.stopWords)), ...f]).slice(0, 12),
1208
+ tokens: f,
1209
+ colors: d,
1210
+ attributes: h,
1211
+ price: be(t)
1212
+ };
1213
+ }
1214
+ function nr(t, e = {}) {
1215
+ const r = w(t.product_type, t.productType), n = w(t.title, r, y(t.keywords).join(" ")), o = k([
1216
+ ...y(t.keywords),
1217
+ ...y(t.colors),
1218
+ ...y(t.materials),
1219
+ ...y(t.styles),
1220
+ ...y(t.attributes)
1221
+ ]);
1222
+ return R({
1223
+ sku: "__photo__",
1224
+ name: n,
1225
+ category_names: r ? [r] : [],
1226
+ facet_hits: {
1227
+ colors: y(t.colors).join(", "),
1228
+ materials: y(t.materials).join(", "),
1229
+ styles: y(t.styles).join(", "),
1230
+ attributes: y(t.attributes).join(", ")
1231
+ },
1232
+ promotions: o
1233
+ }, {
1234
+ ...e,
1235
+ sourceProductType: r,
1236
+ sourceKeywords: o
1237
+ });
1238
+ }
1239
+ function or(t, e = {}) {
1240
+ const r = R(t, e);
1241
+ return k([
1242
+ ...e.sourceQueries ?? [],
1243
+ N([
1244
+ r.productType,
1245
+ ...r.colors.slice(0, 1),
1246
+ ...r.attributes.slice(0, 2)
1247
+ ]),
1248
+ N([r.productType, ...r.keywords.slice(0, 3)]),
1249
+ N([r.categoryNames[r.categoryNames.length - 1], ...r.keywords.slice(0, 2)]),
1250
+ N(r.title.split(/\s+/u).slice(0, 6)),
1251
+ r.productType
1252
+ ].map((n) => n.trim()).filter(Boolean)).slice(0, e.queryLimit ?? 6);
1253
+ }
1254
+ function ye(t, e, r = {}) {
1255
+ const n = {
1256
+ ...pe,
1257
+ ...r.weights
1258
+ }, o = R(e, r), i = [], a = j(t.tokens, o.tokens), c = j(t.keywords, o.tokens), s = Se(t.categoryNames, o.categoryNames) || j(Q(t.categoryNames), Q(o.categoryNames)), u = j(t.attributes, o.attributes), l = j(t.colors, o.colors), f = j(t.attributes, o.tokens), m = xe(t.price, o.price), d = _e(o.sku, r.hitCounts) > 0 ? 1 : 0, h = Ae(t, o), p = a * n.token + c * n.keyword + s * n.category + u * n.facet + l * n.color + f * n.attribute + m * n.price + d * n.retrieval, A = Te(h ? p : p * 0.35);
1259
+ return h && t.productType && t.productType === o.productType && i.push("same product type"), s > 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"), h || i.push("weaker product-type match"), {
1260
+ score: Number(A.toFixed(4)),
1261
+ reasons: i
1262
+ };
1263
+ }
1264
+ function ir(t, e, r = {}) {
1265
+ const n = R(t, r), o = new Set([n.sku, ...r.ignoreSkus ?? []].filter(Boolean));
1266
+ return e.filter((i) => {
1267
+ const a = w(i.sku);
1268
+ return a && !o.has(a);
1269
+ }).map((i) => {
1270
+ const a = ye(n, i, r);
1271
+ return {
1272
+ ...i,
1273
+ similarity_score: a.score,
1274
+ similarity_reasons: a.reasons
1275
+ };
1276
+ }).sort((i, a) => a.similarity_score - i.similarity_score).slice(0, Math.max(1, Math.min(r.limit ?? 12, 100)));
1277
+ }
1278
+ function ge(t) {
1279
+ return !!(t && typeof t == "object" && Array.isArray(t.tokens));
1280
+ }
1281
+ function w(...t) {
1282
+ for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
1283
+ return "";
1284
+ }
1285
+ function y(t) {
1286
+ 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) : [];
1287
+ }
1288
+ function he(t) {
1289
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).map(([e, r]) => [e, w(r)]).filter(([, e]) => e));
1290
+ }
1291
+ function be(t) {
1292
+ const e = Number(t.price_discounted);
1293
+ if (Number.isFinite(e) && e > 0) return e;
1294
+ const r = Number(t.price);
1295
+ return Number.isFinite(r) && r > 0 ? r : 0;
1296
+ }
1297
+ function k(t) {
1298
+ const e = /* @__PURE__ */ new Set(), r = [];
1299
+ for (const n of t) {
1300
+ const o = _(n);
1301
+ !o || e.has(o) || (e.add(o), r.push(o));
1302
+ }
1303
+ return r;
1304
+ }
1305
+ function we(t, e) {
1306
+ const r = ` ${_(t)} `;
1307
+ return e.filter((n) => r.includes(` ${_(n)} `));
1308
+ }
1309
+ function ke(t, e, r) {
1310
+ const n = _(t[t.length - 1] ?? t[0] ?? "");
1311
+ if (n) {
1312
+ const o = b(n), i = new Set(b(e));
1313
+ return o.find((a) => i.has(a)) ?? o[0] ?? n;
1314
+ }
1315
+ return r[0] ?? "";
1316
+ }
1317
+ function N(t) {
1318
+ return t.map((e) => _(e)).filter(Boolean).join(" ").replace(/\s+/gu, " ").trim().slice(0, 120);
1319
+ }
1320
+ function Q(t) {
1321
+ return t.flatMap((e) => b(e));
1322
+ }
1323
+ function j(t, e) {
1324
+ const r = k(t), n = new Set(k(e));
1325
+ return r.length === 0 || n.size === 0 ? 0 : r.filter((o) => n.has(o)).length / r.length;
1326
+ }
1327
+ function Se(t, e) {
1328
+ const r = k(t), n = new Set(k(e));
1329
+ return r.length === 0 || n.size === 0 ? 0 : r.filter((o) => n.has(o)).length / r.length;
1330
+ }
1331
+ function xe(t, e) {
1332
+ return t <= 0 || e <= 0 ? 0 : Math.min(t, e) / Math.max(t, e);
1333
+ }
1334
+ function _e(t, e) {
1335
+ return !t || !e ? 0 : typeof e.get == "function" ? e.get(t) ?? 0 : e[t] ?? 0;
1336
+ }
1337
+ function Ae(t, e) {
1338
+ if (!t.productType || !e.productType || t.productType === e.productType) return !0;
1339
+ const r = new Set(b(t.productType)), n = /* @__PURE__ */ new Set([...b(e.productType), ...e.tokens]);
1340
+ return [...r].some((o) => n.has(o));
1341
+ }
1342
+ function Te(t) {
1343
+ return Math.max(0, Math.min(1, t));
1344
+ }
1345
+ function je(t) {
1346
+ const e = t?.payload;
1347
+ if (typeof e == "string") return e;
1348
+ if (e && typeof e == "object" && "text" in e) {
1349
+ const n = e.text;
1350
+ if (typeof n == "string") return n;
1351
+ }
1352
+ const r = t?.action;
1353
+ return r && typeof r.payload == "string" ? r.payload : r && typeof r.title == "string" ? r.title : "";
1354
+ }
1355
+ var Ie = [
1356
+ {
1357
+ pattern: /\bhttps?:\/\/[^\s?#]+(?:\?[^\s#]*)?/giu,
1358
+ replacement: Oe
1359
+ },
1360
+ {
1361
+ pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu,
1362
+ replacement: "[email]"
1363
+ },
1364
+ {
1365
+ pattern: /\b(?:\+?\d[\d\s().-]{7,}\d)\b/gu,
1366
+ replacement: "[phone]"
1367
+ },
1368
+ {
1369
+ pattern: /\b(?:token|secret|csrf|cookie|bearer|session|sid|cart(?:[_-]?id)?)\s*[:=]\s*[^\s,;&]+/giu,
1370
+ replacement: "[secret]"
1371
+ },
1372
+ {
1373
+ pattern: /\b(?:order|cart|session)[_-]?(?:id|no|number)?\s*[:#=]?\s*[A-Z0-9-]{6,}\b/giu,
1374
+ replacement: "[secret]"
1375
+ }
1376
+ ], ut = { patterns: Ie };
1377
+ function Ee(t, e = ut) {
1378
+ let r = typeof t == "string" ? t : t == null ? "" : String(t);
1379
+ for (const n of e.patterns || []) {
1380
+ const o = n.replacement;
1381
+ r = typeof o == "function" ? r.replace(n.pattern, (i) => o(i)) : r.replace(n.pattern, o);
1382
+ }
1383
+ return r;
1384
+ }
1385
+ function ar(t, e = ut) {
1386
+ return Ee(je(t), e);
1387
+ }
1388
+ function Oe(t) {
1389
+ try {
1390
+ const e = new URL(t);
1391
+ return `${e.origin}${e.pathname}${e.search ? "?[query]" : ""}`;
1392
+ } catch {
1393
+ return "[url]";
1394
+ }
1395
+ }
1396
+ var Pe = [
1397
+ "assistantName",
1398
+ "homeDomain",
1399
+ "categories",
1400
+ "policyTopics"
1401
+ ], Ce = { intent: ["searchContract", "competitorBrands"] };
1402
+ function cr(t, e, r, n = {}) {
1403
+ const o = Me(e, r, n);
1404
+ return Object.keys(o).length ? {
1405
+ ...t,
1406
+ account_config: o
1407
+ } : t;
1408
+ }
1409
+ function Me(t, e, r = {}) {
1410
+ if (!t) return {};
1411
+ const n = {}, o = r.baseKeys || Pe;
1412
+ for (const c of o) Z(n, t, c);
1413
+ const i = t[e];
1414
+ i && typeof i == "object" && !Array.isArray(i) && Object.assign(n, Ne(i));
1415
+ const a = r.opAllowlist || Ce;
1416
+ for (const c of a[e] || []) Z(n, t, c);
1417
+ return n;
1418
+ }
1419
+ function Z(t, e, r) {
1420
+ e[r] !== void 0 && (t[r] = e[r]);
1421
+ }
1422
+ function Ne(t) {
1423
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
1424
+ }
1425
+ export {
1426
+ ht as $,
1427
+ D as A,
1428
+ Le as B,
1429
+ Qe as C,
1430
+ it as D,
1431
+ He as E,
1432
+ ze as F,
1433
+ Nt as G,
1434
+ v as H,
1435
+ nt as I,
1436
+ $e as J,
1437
+ Ot as K,
1438
+ Dt as L,
1439
+ qe as M,
1440
+ Ke as N,
1441
+ Ge as O,
1442
+ Lt as P,
1443
+ ve as Q,
1444
+ De as R,
1445
+ st as S,
1446
+ Ve as T,
1447
+ rt as U,
1448
+ Fe as V,
1449
+ Ue as W,
1450
+ bt as X,
1451
+ O as Y,
1452
+ Re as Z,
1453
+ tr as _,
1454
+ Ie as a,
1455
+ fe as b,
1456
+ nr as c,
1457
+ _ as d,
1458
+ ir as f,
1459
+ er as g,
1460
+ rr as h,
1461
+ ut as i,
1462
+ Je as j,
1463
+ F as k,
1464
+ R as l,
1465
+ b as m,
1466
+ cr as n,
1467
+ Ee as o,
1468
+ ye as p,
1469
+ Et as q,
1470
+ ar as r,
1471
+ je as s,
1472
+ Me as t,
1473
+ or as u,
1474
+ Xe as v,
1475
+ We as w,
1476
+ Ze as x,
1477
+ Ye as y,
1478
+ Ft as z
1479
+ };