@gengage/assistant-fe 0.6.21 → 0.6.23

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 (71) hide show
  1. package/README.md +4 -2
  2. package/dist/agentic/adaptor/create-adaptor.d.ts +6 -3
  3. package/dist/agentic/adaptor/mount.d.ts +8 -2
  4. package/dist/agentic/{similarity.d.ts → algos/similarity.d.ts} +11 -2
  5. package/dist/agentic/algos/similarity.js +261 -0
  6. package/dist/agentic/context/chat-context.d.ts +4 -2
  7. package/dist/agentic/context/context-store.d.ts +11 -1
  8. package/dist/agentic/context/persistence.d.ts +1 -0
  9. package/dist/agentic/contracts/agentic-contracts.d.ts +133 -0
  10. package/dist/agentic/debug/activity-collector.d.ts +14 -0
  11. package/dist/agentic/debug/activity-instrumentation.d.ts +22 -0
  12. package/dist/agentic/debug/activity-overlay.d.ts +3 -0
  13. package/dist/agentic/debug/activity-state.d.ts +37 -0
  14. package/dist/agentic/debug/local-dev.d.ts +18 -0
  15. package/dist/agentic/events/product-normalize.d.ts +4 -1
  16. package/dist/agentic/events/ui-specs.d.ts +8 -4
  17. package/dist/agentic/index.d.ts +25 -2
  18. package/dist/agentic/index.js +2792 -441
  19. package/dist/agentic/types.d.ts +77 -4
  20. package/dist/agentic/util/common/declarative-cache.d.ts +21 -0
  21. package/dist/agentic/util/common/fallback-status.d.ts +10 -0
  22. package/dist/agentic/util/common/flow-steps.d.ts +8 -0
  23. package/dist/agentic/util/common/gss-tool-aliases.d.ts +66 -0
  24. package/dist/agentic/util/common/iframe-scraper.d.ts +22 -0
  25. package/dist/agentic/util/common/llm-routing.d.ts +50 -0
  26. package/dist/agentic/util/common/object.d.ts +1 -0
  27. package/dist/agentic/util/common/open-product-page.d.ts +30 -0
  28. package/dist/agentic/util/common/panel-context.d.ts +3 -0
  29. package/dist/agentic/util/common/privacy.d.ts +14 -0
  30. package/dist/agentic/util/common/product-resolver.d.ts +20 -0
  31. package/dist/agentic/util/common/product-surface.d.ts +24 -0
  32. package/dist/agentic/util/common/ref-store.d.ts +15 -0
  33. package/dist/agentic/util/common/retail-privacy.d.ts +4 -0
  34. package/dist/agentic/util/common/route-params.d.ts +3 -0
  35. package/dist/agentic/util/common/similarity-ranking.d.ts +2 -0
  36. package/dist/agentic/util/common/site-awareness.d.ts +130 -0
  37. package/dist/agentic/util/lazy-runtime-loader.d.ts +2 -1
  38. package/dist/agentic/worker/rpc.d.ts +26 -6
  39. package/dist/agentic/worker.d.ts +15 -2
  40. package/dist/agentic/worker.js +316 -119
  41. package/dist/agentic.iife.js +352 -6
  42. package/dist/{api-paths-DcKsQqb6.js → api-paths-BmN07ddR.js} +144 -154
  43. package/dist/chat/catalog.d.ts +8 -0
  44. package/dist/chat/types.d.ts +2 -1
  45. package/dist/{chat-rvSffJXw.js → chat-CIfQyuBl.js} +26 -21
  46. package/dist/chat-runtime.js +1 -1
  47. package/dist/chat.iife.js +44 -44
  48. package/dist/chat.js +2 -2
  49. package/dist/{common-MpBmMLVk.js → common-sx2gD-IP.js} +1 -1
  50. package/dist/common.js +5 -5
  51. package/dist/{connection-warning-ClrMLgmZ.js → connection-warning-D5T4gHSM.js} +1 -1
  52. package/dist/{fastIntent-Bl4xN0qL.js → fastIntent-BFAGybCb.js} +1 -1
  53. package/dist/index.js +10 -10
  54. package/dist/native.iife.js +17 -17
  55. package/dist/qna-runtime.js +1 -1
  56. package/dist/qna.iife.js +7 -7
  57. package/dist/qna.js +1 -1
  58. package/dist/route-params-5KSvTyeb.js +2454 -0
  59. package/dist/{runtime-CS4mg3ra.js → runtime-BD2fW-ed.js} +3 -3
  60. package/dist/{runtime-_koZbJK_.js → runtime-DM7DHhH9.js} +1816 -1778
  61. package/dist/{runtime-BlU1rKqc.js → runtime-DQ3ULuNF.js} +3 -3
  62. package/dist/{simbut-BtL7zYIJ.js → simbut-hkt_4H97.js} +1 -1
  63. package/dist/simbut.iife.js +1 -1
  64. package/dist/simbut.js +1 -1
  65. package/dist/{simrel-ekf3kUb_.js → simrel-BbkK5Bwt.js} +1 -1
  66. package/dist/simrel-runtime.js +1 -1
  67. package/dist/simrel.iife.js +6 -6
  68. package/dist/simrel.js +2 -2
  69. package/dist/{widget-base-p1EKDuiI.js → widget-base-BPKfPh0N.js} +1 -1
  70. package/package.json +5 -1
  71. package/dist/account-config-D_EMuR0g.js +0 -1479
@@ -0,0 +1,2454 @@
1
+ import { t as pe } from "./request-response-cache-BxRsKGJ0.js";
2
+ var me = 120 * 1e3, ye = "gengage-agentic-ref";
3
+ function ge({ namespace: t = ye, ttlMs: e = me, maxEntries: r = 100 } = {}) {
4
+ const n = /* @__PURE__ */ new Map();
5
+ async function o(l, u = {}) {
6
+ c();
7
+ const f = we(), p = u.kind || "pageRef", m = {
8
+ kind: p,
9
+ value: l,
10
+ expiresAt: Date.now() + (u.ttlMs || e)
11
+ };
12
+ for (n.set(f, m); n.size > r; ) n.delete(n.keys().next().value);
13
+ return await be(t, f, m), {
14
+ kind: p,
15
+ id: f
16
+ };
17
+ }
18
+ async function i(l) {
19
+ const u = typeof l == "string" ? l : l?.id;
20
+ if (!u) return;
21
+ const f = n.get(u) || await ke(t, u);
22
+ if (f) {
23
+ if (f.expiresAt <= Date.now()) {
24
+ n.delete(u), await Ot(t, u);
25
+ return;
26
+ }
27
+ return n.set(u, f), f.value;
28
+ }
29
+ }
30
+ async function a(l) {
31
+ const u = typeof l == "string" ? l : l?.id;
32
+ u && (n.delete(u), await Ot(t, u));
33
+ }
34
+ async function s(l) {
35
+ if (he(l)) return i(l);
36
+ if (Array.isArray(l)) return Promise.all(l.map((f) => s(f)));
37
+ if (!l || typeof l != "object") return l;
38
+ const u = await Promise.all(Object.entries(l).map(async ([f, p]) => [f, await s(p)]));
39
+ return Object.fromEntries(u);
40
+ }
41
+ function c() {
42
+ const l = Date.now();
43
+ for (const [u, f] of n.entries()) f.expiresAt <= l && n.delete(u);
44
+ }
45
+ return {
46
+ put: o,
47
+ get: i,
48
+ delete: a,
49
+ materialize: s,
50
+ cleanup: c
51
+ };
52
+ }
53
+ function he(t) {
54
+ return !!(t && typeof t == "object" && typeof t.kind == "string" && typeof t.id == "string");
55
+ }
56
+ function we() {
57
+ return globalThis.crypto?.randomUUID ? globalThis.crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
58
+ }
59
+ async function be(t, e, r) {
60
+ const n = await ft(t);
61
+ n && (await Z(n.transaction("refs", "readwrite").objectStore("refs").put(r, e)), n.close());
62
+ }
63
+ async function ke(t, e) {
64
+ const r = await ft(t);
65
+ if (!r) return;
66
+ const n = await Z(r.transaction("refs", "readonly").objectStore("refs").get(e));
67
+ return r.close(), n;
68
+ }
69
+ async function Ot(t, e) {
70
+ const r = await ft(t);
71
+ r && (await Z(r.transaction("refs", "readwrite").objectStore("refs").delete(e)), r.close());
72
+ }
73
+ async function ft(t) {
74
+ if (!globalThis.indexedDB) return null;
75
+ try {
76
+ const e = globalThis.indexedDB.open(t, 1);
77
+ return e.onupgradeneeded = () => {
78
+ e.result.createObjectStore("refs");
79
+ }, await Z(e);
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+ function Z(t) {
85
+ return new Promise((e, r) => {
86
+ t.onsuccess = () => e(t.result), t.onerror = () => r(t.error);
87
+ });
88
+ }
89
+ function Ae(t) {
90
+ return !!t && typeof t == "object" && t.type === "rpc.result";
91
+ }
92
+ function _e(t) {
93
+ return !!t && typeof t == "object" && t.type === "rpc.req";
94
+ }
95
+ function Mn(t = self) {
96
+ let e = 1;
97
+ const r = /* @__PURE__ */ new Map();
98
+ return t.addEventListener("message", (n) => {
99
+ const o = n.data;
100
+ if (!Ae(o)) return;
101
+ const i = r.get(o.rpcId);
102
+ if (i) {
103
+ if (r.delete(o.rpcId), o.ok === !1) {
104
+ const a = typeof o.error == "object" ? o.error?.message : o.error;
105
+ i.reject(new Error(a || "RPC failed"));
106
+ return;
107
+ }
108
+ i.resolve(o.value);
109
+ }
110
+ }), function(o, i, a) {
111
+ const s = e++;
112
+ return t.postMessage({
113
+ type: "rpc.req",
114
+ rpcId: s,
115
+ method: o,
116
+ payload: i
117
+ }, a || []), new Promise((c, l) => {
118
+ r.set(s, {
119
+ resolve: (u) => c(u),
120
+ reject: l
121
+ });
122
+ });
123
+ };
124
+ }
125
+ function Rn({ worker: t, tools: e = {}, beacon: r, confirmation: n, memory: o = Se(), refStore: i }) {
126
+ t.addEventListener("message", (a) => {
127
+ const s = a.data;
128
+ _e(s) && xe(t, s, {
129
+ tools: e,
130
+ beacon: r,
131
+ confirmation: n,
132
+ memory: o,
133
+ refStore: i
134
+ });
135
+ });
136
+ }
137
+ async function xe(t, e, r) {
138
+ try {
139
+ const n = await $e(e.method, e.payload, r);
140
+ t.postMessage({
141
+ type: "rpc.result",
142
+ rpcId: e.rpcId,
143
+ ok: !0,
144
+ value: n
145
+ });
146
+ } catch (n) {
147
+ t.postMessage({
148
+ type: "rpc.result",
149
+ rpcId: e.rpcId,
150
+ ok: !1,
151
+ error: { message: n instanceof Error ? n.message : String(n) }
152
+ });
153
+ }
154
+ }
155
+ var et = /* @__PURE__ */ new Map(), Bt = null;
156
+ function Se() {
157
+ try {
158
+ if (typeof sessionStorage < "u") return sessionStorage;
159
+ } catch {
160
+ }
161
+ return {
162
+ getItem: (t) => et.get(t) ?? null,
163
+ setItem: (t, e) => {
164
+ et.set(t, e);
165
+ },
166
+ removeItem: (t) => {
167
+ et.delete(t);
168
+ }
169
+ };
170
+ }
171
+ function ve() {
172
+ return Bt ||= ge(), Bt;
173
+ }
174
+ function je(t) {
175
+ if (t && typeof t == "object" && typeof t.name == "string") return t;
176
+ throw new Error("tool.invoke requires { name, input }");
177
+ }
178
+ function Ee(t) {
179
+ if (t && typeof t == "object" && t.key !== void 0) return t;
180
+ throw new Error("memory.get requires { key }");
181
+ }
182
+ function Ce(t) {
183
+ if (t && typeof t == "object" && t.key !== void 0) return t;
184
+ throw new Error("memory.set requires { key }");
185
+ }
186
+ function Ie(t) {
187
+ if (t && typeof t == "object" && t.key !== void 0) return t;
188
+ throw new Error("memory.remove requires { key }");
189
+ }
190
+ function Te(t) {
191
+ return !t || typeof t != "object" ? { value: t } : t;
192
+ }
193
+ function Pe(t) {
194
+ const e = typeof t.kind == "string" && t.kind.trim() ? t.kind.trim() : void 0, r = typeof t.ttlMs == "number" && Number.isFinite(t.ttlMs) && t.ttlMs > 0 ? t.ttlMs : void 0;
195
+ return e || r ? {
196
+ ...e ? { kind: e } : {},
197
+ ...r ? { ttlMs: r } : {}
198
+ } : void 0;
199
+ }
200
+ function rt(t) {
201
+ if (t == null) return "session";
202
+ if (t === "volatile" || t === "session" || t === "local" || t === "indexedDb") return t;
203
+ if (typeof t == "string") {
204
+ const e = t.toLowerCase();
205
+ if (e === "indexeddb" || e === "idb") return "indexedDb";
206
+ }
207
+ throw new Error(`Unsupported memory tier: ${String(t)}`);
208
+ }
209
+ function dt(t) {
210
+ return typeof t.getItem == "function" && typeof t.setItem == "function";
211
+ }
212
+ function pt(t) {
213
+ return typeof t.get == "function" && typeof t.set == "function";
214
+ }
215
+ function mt(t) {
216
+ return typeof t.accountId == "string" && !!t.session && !!t.indexedDb;
217
+ }
218
+ function Oe(t) {
219
+ const e = t.options?.ttlMs ?? t.ttlMs;
220
+ return typeof e == "number" && Number.isFinite(e) && e > 0 ? { ttlMs: e } : void 0;
221
+ }
222
+ async function Be(t, e, r) {
223
+ if (dt(t)) {
224
+ const n = t.getItem(r);
225
+ if (!n) return null;
226
+ try {
227
+ return JSON.parse(n);
228
+ } catch {
229
+ return t.removeItem?.(r), null;
230
+ }
231
+ }
232
+ return pt(t) && !mt(t) ? await t.get(e, r) ?? null : await t[e].get(r) ?? null;
233
+ }
234
+ async function Me(t, e, r, n, o) {
235
+ return dt(t) ? (t.setItem(r, JSON.stringify(n ?? null)), !0) : pt(t) && !mt(t) ? await t.set(e, r, n ?? null, o) !== !1 : await t[e].set(r, n ?? null, o) !== !1;
236
+ }
237
+ async function Re(t, e, r) {
238
+ return dt(t) ? (t.removeItem?.(r), !0) : pt(t) && !mt(t) ? t.remove ? (await t.remove(e, r), !0) : !1 : (await t[e].remove(r), !0);
239
+ }
240
+ async function $e(t, e, { tools: r, beacon: n, confirmation: o, memory: i, refStore: a }) {
241
+ if (t === "tool.invoke") {
242
+ const { name: s, input: c } = je(e), l = r[s];
243
+ if (typeof l != "function") throw new Error(`Unknown tool: ${s}`);
244
+ return l(c);
245
+ }
246
+ if (t === "beacon.send")
247
+ return n?.(e), { sent: !0 };
248
+ if (t === "confirmation.request") {
249
+ if (typeof o != "function") throw new Error("No confirmation handler is configured.");
250
+ const s = await o(e);
251
+ return typeof s == "boolean" ? { confirmed: s } : s;
252
+ }
253
+ if (t === "memory.get") {
254
+ const { key: s, tier: c } = Ee(e);
255
+ return Be(i, rt(c), String(s));
256
+ }
257
+ if (t === "memory.set") {
258
+ const s = Ce(e);
259
+ return { ok: await Me(i, rt(s.tier), String(s.key), s.value, Oe(s)) };
260
+ }
261
+ if (t === "memory.remove") {
262
+ const { key: s, tier: c } = Ie(e);
263
+ return { ok: await Re(i, rt(c), String(s)) };
264
+ }
265
+ if (t === "ref.put") {
266
+ const s = D({
267
+ tools: r,
268
+ beacon: n,
269
+ confirmation: o,
270
+ memory: i,
271
+ refStore: a
272
+ }), c = Te(e);
273
+ return s.put(c.value, Pe(c));
274
+ }
275
+ if (t === "ref.get") return D({
276
+ tools: r,
277
+ beacon: n,
278
+ confirmation: o,
279
+ memory: i,
280
+ refStore: a
281
+ }).get(e);
282
+ if (t === "ref.materialize") return D({
283
+ tools: r,
284
+ beacon: n,
285
+ confirmation: o,
286
+ memory: i,
287
+ refStore: a
288
+ }).materialize(e);
289
+ if (t === "ref.remove")
290
+ return await D({
291
+ tools: r,
292
+ beacon: n,
293
+ confirmation: o,
294
+ memory: i,
295
+ refStore: a
296
+ }).delete(e), { ok: !0 };
297
+ throw new Error(`Unknown RPC method: ${t}`);
298
+ }
299
+ function D(t) {
300
+ const e = t.refStore || ve();
301
+ if (!e || typeof e.put != "function" || typeof e.get != "function") throw new Error("No ref store is configured.");
302
+ return e;
303
+ }
304
+ function Le() {
305
+ return (/* @__PURE__ */ new Date()).toISOString();
306
+ }
307
+ function v(t) {
308
+ return Math.max(0, Math.round(performance.now() - t));
309
+ }
310
+ function $(t) {
311
+ return typeof t == "object" && t !== null && !Array.isArray(t);
312
+ }
313
+ function Ne(t) {
314
+ const { accountId: e, locale: r = "en-GB", parentUrl: n = "", threadId: o, incomingContext: i, messageLimit: a } = t, s = $(i) ? i : {}, c = $(s.thread) ? s.thread : {}, l = $(s.panel) ? s.panel : {}, u = $(s.meta) ? s.meta : {}, f = zt(s.messages, a), p = {
315
+ id: String(o || c.id || self.crypto.randomUUID()),
316
+ started_at: String(c.started_at || Le()),
317
+ extensions: $(c.extensions) ? { ...c.extensions } : {}
318
+ }, m = String(u.locale || r), g = String(u.parentUrl || n || typeof self < "u" && self.location?.href || "");
319
+ return {
320
+ panel: { ...l },
321
+ messages: f,
322
+ thread: p,
323
+ meta: {
324
+ locale: m,
325
+ parentUrl: g,
326
+ accountId: e
327
+ }
328
+ };
329
+ }
330
+ function qe(t, e, r) {
331
+ const n = zt([e], r)[0];
332
+ return n ? {
333
+ ...t,
334
+ messages: H([...t.messages, n], r)
335
+ } : t;
336
+ }
337
+ function H(t, e) {
338
+ const r = Fe(e);
339
+ return r === 1 / 0 ? [...t] : t.slice(-r);
340
+ }
341
+ function zt(t, e) {
342
+ return Array.isArray(t) ? H(t.map((r) => {
343
+ const n = r?.role;
344
+ return {
345
+ role: n === "model" ? "assistant" : typeof n == "string" ? n : "",
346
+ content: String(r?.content || "")
347
+ };
348
+ }).filter((r) => (r.role === "user" || r.role === "assistant") && !!r.content), e) : [];
349
+ }
350
+ function Fe(t) {
351
+ if (t === void 0) return 50;
352
+ if (!Number.isFinite(t)) return 1 / 0;
353
+ const e = Math.floor(t);
354
+ return e > 0 ? e : 50;
355
+ }
356
+ var Ue = "gengage:agent:context:";
357
+ async function ze({ accountId: t, threadId: e, rpc: r }) {
358
+ const n = await r("memory.get", {
359
+ tier: "session",
360
+ key: Dt(t, e)
361
+ });
362
+ return n && typeof n == "object" && !Array.isArray(n) ? n : {};
363
+ }
364
+ async function De({ accountId: t, threadId: e, extensions: r, panel: n, rpc: o }) {
365
+ await o("memory.set", {
366
+ tier: "session",
367
+ key: Dt(t, e),
368
+ value: {
369
+ thread: { extensions: r },
370
+ ...n && Object.keys(n).length > 0 ? { panel: n } : {}
371
+ }
372
+ });
373
+ }
374
+ function Dt(t, e) {
375
+ return `${Ue}${t}:${e}`;
376
+ }
377
+ function h(t) {
378
+ return typeof t == "object" && t !== null && !Array.isArray(t);
379
+ }
380
+ var $n = class {
381
+ #t = /* @__PURE__ */ new Map();
382
+ #r = /* @__PURE__ */ new Map();
383
+ #o;
384
+ #c;
385
+ #u;
386
+ #i;
387
+ #l;
388
+ #f;
389
+ #n;
390
+ #a;
391
+ #s;
392
+ constructor({ accountId: t, locale: e, parentUrl: r, rpc: n, persistentPanelKeys: o = [], panelKeyLimits: i = {}, messageLimit: a, maxThreads: s, threadTtlMs: c }) {
393
+ this.#o = t, this.#c = e, this.#u = r, this.#i = n, this.#l = [...new Set(o.filter(Boolean))], this.#f = Ke(i), this.#n = nt(a), this.#a = nt(s), this.#s = nt(c);
394
+ }
395
+ get size() {
396
+ return this.pruneExpired(), this.#t.size;
397
+ }
398
+ get(t = "default") {
399
+ this.pruneExpired();
400
+ const e = String(t || "default"), r = this.#t.get(e);
401
+ return r ? (this.#e(e, r), r) : null;
402
+ }
403
+ getPanel(t = "default") {
404
+ return this.get(t)?.panel ?? null;
405
+ }
406
+ getRecentProducts(t = "default", e = "last_search_products") {
407
+ const r = this.getPanel(t)?.[e];
408
+ return Array.isArray(r) ? r : [];
409
+ }
410
+ async load(t) {
411
+ this.pruneExpired();
412
+ const e = t?.meta?.threadId || t?.session_id || t?.sessionId, r = String(e || "default"), n = this.#t.get(r);
413
+ if (n) {
414
+ const a = He(n, t?.context, this.#n);
415
+ return this.#e(r, a), a;
416
+ }
417
+ const o = await ze({
418
+ accountId: this.#o,
419
+ threadId: r,
420
+ rpc: this.#i
421
+ }), i = Ne({
422
+ accountId: this.#o,
423
+ locale: t?.locale || this.#c,
424
+ parentUrl: this.#u,
425
+ threadId: r,
426
+ incomingContext: Ze(o, t?.context),
427
+ messageLimit: this.#n
428
+ });
429
+ return this.#e(r, i), this.#d(), i;
430
+ }
431
+ patch(t, e) {
432
+ this.pruneExpired();
433
+ const r = String(t || "default"), n = this.#t.get(r);
434
+ if (!n) return null;
435
+ const o = yt(n, typeof e == "function" ? e(n) : e, this.#n);
436
+ return this.#e(r, o), o;
437
+ }
438
+ appendUserMessage(t, e) {
439
+ this.pruneExpired();
440
+ const r = String(t || "default");
441
+ if (!e) return this.#t.get(r) ?? null;
442
+ const n = this.#t.get(r);
443
+ if (!n) return null;
444
+ const o = qe(n, {
445
+ role: "user",
446
+ content: e
447
+ }, this.#n);
448
+ return this.#e(r, o), o;
449
+ }
450
+ async commit(t) {
451
+ this.pruneExpired();
452
+ const e = String(t || "default"), r = this.#t.get(e);
453
+ return r ? (this.#e(e, r), await De({
454
+ accountId: this.#o,
455
+ threadId: e,
456
+ extensions: r.thread.extensions,
457
+ panel: Ve(r.panel, this.#l, this.#f),
458
+ rpc: this.#i
459
+ }), r) : null;
460
+ }
461
+ delete(t) {
462
+ const e = String(t || "default");
463
+ return this.#r.delete(e), this.#t.delete(e);
464
+ }
465
+ clear() {
466
+ this.#t.clear(), this.#r.clear();
467
+ }
468
+ pruneExpired(t = Date.now()) {
469
+ if (!this.#s) return 0;
470
+ let e = 0;
471
+ for (const [r, n] of this.#r)
472
+ t - n <= this.#s || (this.#r.delete(r), this.#t.delete(r) && (e += 1));
473
+ return e;
474
+ }
475
+ #e(t, e) {
476
+ this.#t.delete(t), this.#t.set(t, e), this.#r.set(t, Date.now());
477
+ }
478
+ #d() {
479
+ if (this.#a)
480
+ for (; this.#t.size > this.#a; ) {
481
+ const t = this.#t.keys().next().value;
482
+ if (!t) return;
483
+ this.delete(t);
484
+ }
485
+ }
486
+ };
487
+ function Ve(t, e, r) {
488
+ if (!e.length || !h(t)) return;
489
+ const n = {};
490
+ for (const o of e) Object.prototype.hasOwnProperty.call(t, o) && (n[o] = Je(t[o], r[o]));
491
+ return n;
492
+ }
493
+ function Ke(t) {
494
+ const e = {};
495
+ for (const [r, n] of Object.entries(t || {})) {
496
+ const o = Math.floor(Number(n));
497
+ r && Number.isFinite(o) && o > 0 && (e[r] = o);
498
+ }
499
+ return e;
500
+ }
501
+ function nt(t) {
502
+ if (t === void 0) return;
503
+ const e = Math.floor(Number(t));
504
+ return Number.isFinite(e) && e > 0 ? e : void 0;
505
+ }
506
+ function Je(t, e) {
507
+ return !e || !Array.isArray(t) ? t : t.slice(-e);
508
+ }
509
+ function Ze(t, e) {
510
+ return !h(t) && !h(e) ? {} : yt(h(t) ? t : {}, h(e) ? e : {});
511
+ }
512
+ function He(t, e, r) {
513
+ if (!h(e)) return t;
514
+ const n = yt(t, e, r);
515
+ return {
516
+ ...n,
517
+ thread: {
518
+ ...n.thread,
519
+ id: t.thread.id,
520
+ started_at: t.thread.started_at
521
+ },
522
+ meta: {
523
+ ...n.meta,
524
+ accountId: t.meta.accountId
525
+ }
526
+ };
527
+ }
528
+ function yt(t, e, r) {
529
+ if (!h(e)) return t;
530
+ const n = t, o = e, i = h(n.panel) ? n.panel : {}, a = h(o.panel) ? o.panel : {}, s = h(n.thread) ? n.thread : {}, c = h(o.thread) ? o.thread : {}, l = h(s.extensions) ? s.extensions : {}, u = h(c.extensions) ? c.extensions : {}, f = h(n.meta) ? n.meta : {}, p = h(o.meta) ? o.meta : {};
531
+ return {
532
+ ...t,
533
+ ...e,
534
+ panel: {
535
+ ...i,
536
+ ...a
537
+ },
538
+ thread: {
539
+ ...s,
540
+ ...c,
541
+ extensions: {
542
+ ...l,
543
+ ...u
544
+ }
545
+ },
546
+ meta: {
547
+ ...f,
548
+ ...p
549
+ },
550
+ messages: Array.isArray(o.messages) ? H(o.messages, r) : t.messages ?? []
551
+ };
552
+ }
553
+ function Vt(t) {
554
+ const e = String.fromCharCode(...t);
555
+ return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
556
+ }
557
+ function Mt(t) {
558
+ return Vt(new TextEncoder().encode(JSON.stringify(t)));
559
+ }
560
+ async function Ge({ accountId: t, devJwtSecret: e, ttlS: r = 300 }) {
561
+ if (!e) throw new Error("devJwtSecret is required for local agent mode.");
562
+ const n = Math.floor(Date.now() / 1e3), o = `${Mt({
563
+ alg: "HS256",
564
+ typ: "JWT"
565
+ })}.${Mt({
566
+ sub: t,
567
+ iat: n,
568
+ exp: n + r,
569
+ scope: "invoke",
570
+ jti: crypto.randomUUID?.() || `${n}-${Math.random()}`
571
+ })}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
572
+ name: "HMAC",
573
+ hash: "SHA-256"
574
+ }, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
575
+ return `${o}.${Vt(new Uint8Array(a))}`;
576
+ }
577
+ function Qe({ accountId: t, devJwtSecret: e, tokenBrokerUrl: r, tokenBrokerAudience: n, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
578
+ let a = null;
579
+ return async ({ signal: s, parentUrl: c } = {}) => {
580
+ if (e) return Ge({
581
+ accountId: t,
582
+ devJwtSecret: e
583
+ });
584
+ if (!r) throw new Error("tokenBrokerUrl is required for production agent mode.");
585
+ const l = Math.floor(Date.now() / 1e3);
586
+ return a?.token && a.expiresAtS - o > l || (a = await Ye({
587
+ accountId: t,
588
+ tokenBrokerUrl: r,
589
+ tokenBrokerAudience: n,
590
+ parentUrl: c,
591
+ signal: s,
592
+ fetchImpl: i
593
+ })), a.token;
594
+ };
595
+ }
596
+ async function Ye({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: r, parentUrl: n, signal: o, fetchImpl: i }) {
597
+ const a = await i(e, {
598
+ method: "POST",
599
+ credentials: "include",
600
+ headers: {
601
+ accept: "application/json",
602
+ "content-type": "application/json"
603
+ },
604
+ body: JSON.stringify({
605
+ accountId: t,
606
+ scope: "invoke",
607
+ audience: r || void 0,
608
+ parentUrl: n || void 0
609
+ }),
610
+ ...o ? { signal: o } : {}
611
+ });
612
+ if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
613
+ const s = await a.json(), c = s?.token || s?.jwt || s?.access_token;
614
+ if (!c || typeof c != "string") throw new Error("Token broker response did not include a JWT.");
615
+ return {
616
+ token: c,
617
+ expiresAtS: We(s) || Xe(c) || Math.floor(Date.now() / 1e3) + 300
618
+ };
619
+ }
620
+ function We(t) {
621
+ const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
622
+ if (Number.isFinite(e)) return Number(e);
623
+ const r = t?.expiresIn ?? t?.expires_in;
624
+ if (Number.isFinite(r)) return Math.floor(Date.now() / 1e3) + Number(r);
625
+ const n = t?.expiresAt ?? t?.expires_at;
626
+ if (typeof n == "string") {
627
+ const o = Date.parse(n);
628
+ if (Number.isFinite(o)) return Math.floor(o / 1e3);
629
+ }
630
+ return null;
631
+ }
632
+ function Xe(t) {
633
+ try {
634
+ const [, e] = t.split(".");
635
+ if (!e) return null;
636
+ const r = e.replace(/-/gu, "+").replace(/_/gu, "/"), n = atob(r.padEnd(Math.ceil(r.length / 4) * 4, "=")), o = JSON.parse(n);
637
+ return Number.isFinite(o?.exp) ? Number(o.exp) : null;
638
+ } catch {
639
+ return null;
640
+ }
641
+ }
642
+ var Rt = {
643
+ unauthorized: {
644
+ code: "auth",
645
+ message: "Assistant authentication failed. Please retry."
646
+ },
647
+ forbidden: {
648
+ code: "auth",
649
+ message: "Assistant authentication failed. Please retry."
650
+ },
651
+ unknown_op: {
652
+ code: "op_unavailable",
653
+ message: "This assistant action is not available yet."
654
+ },
655
+ invalid_input: {
656
+ code: "invalid_request",
657
+ message: "The assistant request was not valid."
658
+ },
659
+ account_config: {
660
+ code: "account_config",
661
+ message: "Assistant configuration is unavailable."
662
+ },
663
+ upstream_llm: {
664
+ code: "op_failed",
665
+ message: "The assistant could not complete that request."
666
+ },
667
+ upstream_timeout: {
668
+ code: "op_timeout",
669
+ message: "The assistant took too long to respond."
670
+ },
671
+ schema_mismatch: {
672
+ code: "op_failed",
673
+ message: "The assistant could not complete that request."
674
+ },
675
+ rate_limited: {
676
+ code: "rate_limited",
677
+ message: "The assistant is receiving too many requests. Please retry shortly."
678
+ },
679
+ internal: {
680
+ code: "op_failed",
681
+ message: "The assistant could not complete that request."
682
+ },
683
+ payload_too_large: {
684
+ code: "invalid_request",
685
+ message: "The assistant request was too large."
686
+ }
687
+ }, T = class extends Error {
688
+ constructor(t, e, r = {}) {
689
+ 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);
690
+ }
691
+ };
692
+ function Kt(t) {
693
+ const e = String(t?.code || "upstream_llm"), r = Rt[e] || Rt.upstream_llm;
694
+ return new T(r.code, r.message, {
695
+ source: "be",
696
+ sourceCode: e,
697
+ detail: t?.detail
698
+ });
699
+ }
700
+ function tr(t, e) {
701
+ const r = e?.error && typeof e.error == "object" ? e.error : {};
702
+ return Kt({
703
+ code: String(r.code || er(t)),
704
+ detail: r.detail
705
+ });
706
+ }
707
+ function Ln(t) {
708
+ return t instanceof T ? {
709
+ type: "error",
710
+ code: t.code,
711
+ message: t.message
712
+ } : {
713
+ type: "error",
714
+ code: "agent_invoke_failed",
715
+ message: "The assistant could not complete that request."
716
+ };
717
+ }
718
+ function er(t) {
719
+ return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
720
+ }
721
+ async function Nn({ beUrl: t, accountId: e, devJwtSecret: r, tokenBrokerUrl: n, tokenBrokerAudience: o, jwtProvider: i, parentUrl: a, op: s, input: c, cacheTtlS: l, cacheKey: u, browserCache: f, signal: p }) {
722
+ const m = await (i || Qe({
723
+ accountId: e,
724
+ devJwtSecret: r,
725
+ tokenBrokerUrl: n,
726
+ tokenBrokerAudience: o
727
+ }))({
728
+ ...p ? { signal: p } : {},
729
+ ...a ? { parentUrl: a } : {}
730
+ }), { opDomain: g, opName: _ } = rr(s, e), E = {
731
+ method: "POST",
732
+ headers: {
733
+ authorization: `Bearer ${m}`,
734
+ "content-type": "application/json",
735
+ accept: "application/x-ndjson"
736
+ },
737
+ body: JSON.stringify({
738
+ op_domain: g,
739
+ op_name: _,
740
+ op_payload: c,
741
+ ...l !== void 0 ? { cache_ttl_s: l } : {},
742
+ ...u !== void 0 ? { cache_key: u } : {}
743
+ }),
744
+ ...p ? { signal: p } : {}
745
+ }, P = `${String(t).replace(/\/+$/u, "")}/v1/execute`, O = f === !1 ? await fetch(P, E) : await pe(P, E, typeof f == "object" ? f : {});
746
+ if (!O.ok) throw tr(O.status, await or(O));
747
+ return ir(O);
748
+ }
749
+ function rr(t, e) {
750
+ if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
751
+ return {
752
+ opDomain: nr(e),
753
+ opName: t
754
+ };
755
+ }
756
+ function nr(t) {
757
+ return t.replace(/-agentic$/u, "");
758
+ }
759
+ async function or(t) {
760
+ try {
761
+ return await t.json();
762
+ } catch {
763
+ return { error: { code: t.statusText || "internal" } };
764
+ }
765
+ }
766
+ async function ir(t) {
767
+ const e = t.body?.getReader();
768
+ if (!e) throw new Error("BE response body is not readable.");
769
+ const r = new TextDecoder();
770
+ let n = "";
771
+ const o = {};
772
+ for (; ; ) {
773
+ const { value: a, done: s } = await e.read();
774
+ if (s) break;
775
+ n += r.decode(a, { stream: !0 });
776
+ let c = n.indexOf(`
777
+ `);
778
+ for (; c >= 0; ) {
779
+ const l = n.slice(0, c).trim();
780
+ n = n.slice(c + 1), l && $t(JSON.parse(l), o), c = n.indexOf(`
781
+ `);
782
+ }
783
+ }
784
+ const i = n.trim();
785
+ return i && $t(JSON.parse(i), o), o;
786
+ }
787
+ function $t(t, e) {
788
+ if (t._error) throw Kt(t._error);
789
+ if (!t._end)
790
+ for (const [r, n] of Object.entries(t)) {
791
+ if (Object.prototype.hasOwnProperty.call(e, r)) throw new T("op_failed", `BE streamed duplicate field "${r}".`, {
792
+ source: "be",
793
+ sourceCode: "schema_mismatch"
794
+ });
795
+ e[r] = n;
796
+ }
797
+ }
798
+ function qn(t = {}) {
799
+ return {
800
+ type: "metadata",
801
+ ...t
802
+ };
803
+ }
804
+ function ar(t, e = !1, r = {}) {
805
+ return {
806
+ type: "text_chunk",
807
+ content: t,
808
+ final: e,
809
+ ...r
810
+ };
811
+ }
812
+ function Fn(t) {
813
+ return {
814
+ type: "ui_spec",
815
+ ...t
816
+ };
817
+ }
818
+ function Un(t) {
819
+ return {
820
+ type: "action",
821
+ action: t
822
+ };
823
+ }
824
+ function sr(t, e) {
825
+ return {
826
+ type: "error",
827
+ code: t,
828
+ message: e
829
+ };
830
+ }
831
+ function Jt() {
832
+ return { type: "done" };
833
+ }
834
+ function cr(t, e) {
835
+ return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
836
+ }
837
+ function Zt(t) {
838
+ return t && typeof t == "object" && !Array.isArray(t) ? t : null;
839
+ }
840
+ function gt(t, e = {}) {
841
+ const r = Zt(t);
842
+ if (!r) return null;
843
+ const n = e.catalogMapper?.(r);
844
+ if (n) return n;
845
+ const o = M(r.sku, r.SKU);
846
+ if (!o) return null;
847
+ const i = {
848
+ sku: o,
849
+ name: M(r.name, r.title, r.short_name, o) || o,
850
+ url: M(r.url) || ""
851
+ }, a = Array.isArray(r.images) ? r.images : void 0, s = M(r.imageUrl, r.image_url, r.image, a?.[0]);
852
+ s && (i.imageUrl = s), a && a.length > 1 && (i.images = a.filter((P) => !!P).map(String));
853
+ const c = L(r.price_discounted), l = L(r.price), u = c || l;
854
+ u > 0 && (i.price = String(u));
855
+ const f = c > 0 ? l : 0;
856
+ f > 0 && (i.originalPrice = String(f));
857
+ const p = M(r.brand);
858
+ p && (i.brand = p);
859
+ const m = L(r.rating);
860
+ m > 0 && (i.rating = m);
861
+ const g = L(r.review_count) || L(r.reviewCount);
862
+ g > 0 && (i.reviewCount = g);
863
+ const _ = M(r.cart_code, r.cartCode);
864
+ _ && (i.cartCode = _), typeof r.in_stock == "boolean" && (i.inStock = r.in_stock), typeof r.inStock == "boolean" && (i.inStock = r.inStock);
865
+ const E = r.category_names;
866
+ return Array.isArray(E) && (i.categoryNames = E.map(String)), i;
867
+ }
868
+ function ht(t) {
869
+ const e = Zt(t);
870
+ if (!e) return t;
871
+ const r = e.category_names, n = Array.isArray(r) ? r : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
872
+ sku: e.sku,
873
+ name: e.name || e.title,
874
+ url: e.url,
875
+ price: e.price,
876
+ currency: e.price_currency || e.currency,
877
+ category: n?.[n.length - 1] ?? void 0,
878
+ category_names: n ? n.slice(0, 4) : void 0,
879
+ image: i ? i[0] : e.image,
880
+ in_stock: e.in_stock,
881
+ rating: e.rating,
882
+ review_count: e.review_count
883
+ };
884
+ for (const s of Object.keys(a)) a[s] === void 0 && delete a[s];
885
+ return a;
886
+ }
887
+ function zn(t) {
888
+ return Array.isArray(t) ? t.map(ht).filter((e) => !!e) : [];
889
+ }
890
+ function M(...t) {
891
+ for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
892
+ return "";
893
+ }
894
+ function L(t) {
895
+ const e = Number(t);
896
+ return Number.isFinite(e) ? e : 0;
897
+ }
898
+ function Lt(t) {
899
+ return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
900
+ }
901
+ function Ht(t, e, r = {}) {
902
+ return `${t}:${r.version || "v2"}:${Gt(e)}`;
903
+ }
904
+ function Dn(t, e = {}) {
905
+ return Qt(t).map((r) => Yt(typeof r == "string" ? r : r.sku, e.locale)).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n).sort((r, n) => wt(r, n, e.locale)).slice(0, e.limit || 16).join(",");
906
+ }
907
+ function Vn(t, e = {}) {
908
+ return Gt(Qt(t).map((r) => ur(r, e)).filter((r) => !!r).sort((r, n) => wt(String(r.sku || r.name || ""), String(n.sku || n.name || ""), e.locale)).slice(0, e.limit || 16));
909
+ }
910
+ function Kn(t, e) {
911
+ return C(t, e);
912
+ }
913
+ function Gt(t) {
914
+ let e = 2166136261;
915
+ const r = lr(t);
916
+ for (let n = 0; n < r.length; n += 1)
917
+ e ^= r.charCodeAt(n), e = Math.imul(e, 16777619);
918
+ return (e >>> 0).toString(36);
919
+ }
920
+ function ur(t, e) {
921
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
922
+ const r = t, n = e.mapProduct?.(r);
923
+ if (n) return q(n);
924
+ const o = ht(r);
925
+ return o && typeof o == "object" && !Array.isArray(o) ? q(fr(o, e)) : null;
926
+ }
927
+ function Qt(t) {
928
+ return Array.isArray(t) ? t.filter((e) => typeof e == "string" || !!(e && typeof e == "object" && !Array.isArray(e))) : [];
929
+ }
930
+ function lr(t) {
931
+ return JSON.stringify(q(t));
932
+ }
933
+ function q(t) {
934
+ return Array.isArray(t) ? t.map(q) : !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, q(r)]));
935
+ }
936
+ function fr(t, e) {
937
+ return {
938
+ sku: Yt(t.sku, e.locale),
939
+ name: C(t.name, e.locale),
940
+ url: C(t.url, e.locale),
941
+ price: t.price,
942
+ currency: C(t.currency, e.locale),
943
+ category: C(t.category, e.locale),
944
+ category_names: dr(t.category_names, e.locale, 16),
945
+ image: C(t.image, e.locale),
946
+ in_stock: t.in_stock,
947
+ rating: t.rating,
948
+ review_count: t.review_count
949
+ };
950
+ }
951
+ function Yt(t, e) {
952
+ return C(t, e).toUpperCase();
953
+ }
954
+ function C(t, e) {
955
+ return typeof t == "string" ? t.trim().replace(/\s+/gu, " ").toLocaleLowerCase(e || void 0) : "";
956
+ }
957
+ function wt(t, e, r) {
958
+ return t.localeCompare(e, r, { numeric: !0 });
959
+ }
960
+ function dr(t, e, r) {
961
+ return Array.isArray(t) ? t.map((n) => C(n, e)).filter(Boolean).sort((n, o) => wt(n, o, e)).slice(0, r) : void 0;
962
+ }
963
+ async function Jn({ request: t, accountModule: e, contextStore: r, beClient: n, toolBridge: o, emit: i, rpc: a, signal: s }) {
964
+ const c = performance.now(), l = await r.load(t), u = l.thread.id, f = Mr(t);
965
+ vr(l, f) && r.appendUserMessage(u, f);
966
+ const p = cr(e.flows, t);
967
+ if (!p)
968
+ return i(sr("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(Jt()), {
969
+ steps: 0,
970
+ productSkusEmitted: []
971
+ };
972
+ const m = {
973
+ request: t,
974
+ context: r.patch(u, {}) || l,
975
+ bag: {},
976
+ accountConfig: e.accountConfig || {},
977
+ threadId: u,
978
+ steps: 0,
979
+ productSkusEmitted: /* @__PURE__ */ new Set(),
980
+ committed: !1,
981
+ messageLimit: Br(e.contextPersistence?.messageLimit),
982
+ catalogMapper: e.catalogMapper,
983
+ similarityMapper: e.similarityMapper
984
+ }, g = {
985
+ contextStore: r,
986
+ beClient: n,
987
+ toolBridge: o,
988
+ emit: i,
989
+ rpc: a,
990
+ adapters: e.adapters || {},
991
+ ...s ? { signal: s } : {},
992
+ ...e.trace ? { trace: e.trace } : {}
993
+ };
994
+ await j(g, N("turn:start", m));
995
+ try {
996
+ await F(p, m, g), m.committed || await bt(m, g);
997
+ } catch (_) {
998
+ throw await j(g, {
999
+ ...N("turn:error", m),
1000
+ latencyMs: v(c),
1001
+ errorCode: At(_)
1002
+ }), _;
1003
+ }
1004
+ return await a("beacon.send", {
1005
+ type: "turnSummary",
1006
+ threadId: u,
1007
+ sessionId: t?.session_id || t?.sessionId || u,
1008
+ accountId: e.accountId || m.context.meta.accountId,
1009
+ steps: m.steps,
1010
+ totalLatencyMs: v(c),
1011
+ productSkusEmitted: [...m.productSkusEmitted]
1012
+ }), await j(g, {
1013
+ ...N("turn:end", m),
1014
+ latencyMs: v(c)
1015
+ }), {
1016
+ steps: m.steps,
1017
+ productSkusEmitted: [...m.productSkusEmitted]
1018
+ };
1019
+ }
1020
+ async function F(t, e, r) {
1021
+ for (const n of t) {
1022
+ if (r.signal?.aborted || e.committed) return;
1023
+ e.steps += 1;
1024
+ const o = e.steps, i = performance.now();
1025
+ await j(r, ot("step:start", e, n, o));
1026
+ try {
1027
+ await pr(n, e, r), await j(r, {
1028
+ ...ot("step:end", e, n, o),
1029
+ latencyMs: v(i)
1030
+ });
1031
+ } catch (a) {
1032
+ throw await j(r, {
1033
+ ...ot("step:error", e, n, o),
1034
+ latencyMs: v(i),
1035
+ errorCode: At(a)
1036
+ }), a;
1037
+ }
1038
+ e.context = r.contextStore.patch(e.threadId, {}) || e.context;
1039
+ }
1040
+ }
1041
+ async function pr(t, e, r) {
1042
+ const n = Q(e);
1043
+ if (t.kind === "be_op") {
1044
+ await mr(t, e, r, n);
1045
+ return;
1046
+ }
1047
+ if (t.kind === "tool") {
1048
+ await hr(t, e, r, n);
1049
+ return;
1050
+ }
1051
+ if (t.kind === "adapter") {
1052
+ await wr(t, e, r, n);
1053
+ return;
1054
+ }
1055
+ if (t.kind === "emit") {
1056
+ await br(t, e, r);
1057
+ return;
1058
+ }
1059
+ if (t.kind === "patch") {
1060
+ await kr(t, e, r);
1061
+ return;
1062
+ }
1063
+ if (t.kind === "branch") {
1064
+ await Ar(t, e, r, n);
1065
+ return;
1066
+ }
1067
+ if (t.kind === "parallel") {
1068
+ await _r(t, e, r);
1069
+ return;
1070
+ }
1071
+ if (t.kind === "refusal") {
1072
+ await xr(t, e, r, n);
1073
+ return;
1074
+ }
1075
+ t.kind === "commit" && await Sr(t, e, r);
1076
+ }
1077
+ async function mr(t, e, r, n) {
1078
+ const o = performance.now();
1079
+ let i;
1080
+ try {
1081
+ const s = await b(t.input, n), c = yr(t, e, s, await b(t.cache, n)), l = await b(t.cacheTtlS, n) ?? c.cacheTtlS, u = await b(t.cacheKey, n) ?? c.cacheKey, f = await b(t.browserCache, n), p = U(await b(t.timeoutMs, n));
1082
+ await kt(t, e, r, n);
1083
+ const m = p ? new AbortController() : null, g = Wt(r.signal, m?.signal);
1084
+ i = await Y(r.beClient.invoke({
1085
+ op: t.op,
1086
+ input: s,
1087
+ ...l !== void 0 ? { cacheTtlS: l } : {},
1088
+ ...u !== void 0 ? { cacheKey: u } : {},
1089
+ ...f !== void 0 ? { browserCache: f } : {},
1090
+ ...g ? { signal: g } : {}
1091
+ }), p, () => new T("op_timeout", "The assistant took too long to respond.", {
1092
+ source: "be",
1093
+ sourceCode: "timeout"
1094
+ }), () => m?.abort());
1095
+ } catch (s) {
1096
+ const c = s, l = String(c?.sourceCode || c?.code || "unknown"), u = {
1097
+ type: "agentOp",
1098
+ threadId: e.threadId,
1099
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
1100
+ accountId: e.context.meta.accountId,
1101
+ op: t.op,
1102
+ status: "error",
1103
+ latencyMs: v(o),
1104
+ errorCode: l
1105
+ };
1106
+ if (await r.rpc("beacon.send", u), t.onError) {
1107
+ t.errorOut && (e.bag[t.errorOut] = s), await F(t.onError, e, r);
1108
+ return;
1109
+ }
1110
+ throw s;
1111
+ }
1112
+ t.out && (e.bag[t.out] = i), await G(t, i, e, r.contextStore);
1113
+ const a = {
1114
+ type: "agentOp",
1115
+ threadId: e.threadId,
1116
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
1117
+ accountId: e.context.meta.accountId,
1118
+ op: t.op,
1119
+ status: "ok",
1120
+ latencyMs: v(o)
1121
+ };
1122
+ await r.rpc("beacon.send", a);
1123
+ }
1124
+ function yr(t, e, r, n) {
1125
+ if (!n || n.strategy !== "input-hash") return {};
1126
+ const o = U(n.ttlS);
1127
+ if (!o) return {};
1128
+ const i = e.context.meta.locale, a = n.promptVersion || gr(r) || "current";
1129
+ return {
1130
+ cacheTtlS: o,
1131
+ cacheKey: Ht(t.op, {
1132
+ account: e.context.meta.accountId,
1133
+ locale: i,
1134
+ promptVersion: a,
1135
+ payload: r
1136
+ }, { version: "input-hash" })
1137
+ };
1138
+ }
1139
+ function gr(t) {
1140
+ if (!t || typeof t != "object" || Array.isArray(t)) return;
1141
+ const e = t, r = e.prompt_version || e.promptVersion;
1142
+ return typeof r == "string" && r.trim() ? r.trim() : void 0;
1143
+ }
1144
+ async function hr(t, e, r, n) {
1145
+ const o = performance.now();
1146
+ try {
1147
+ await kt(t, e, r, n);
1148
+ const i = U(await b(t.timeoutMs, n)), a = await Y(r.toolBridge.invoke(t.name, await b(t.input, n)), i, () => new T("tool_timeout", "The assistant tool took too long to respond.", {
1149
+ source: "tool",
1150
+ sourceCode: "timeout"
1151
+ }));
1152
+ t.out && (e.bag[t.out] = a), await G(t, a, e, r.contextStore), await r.rpc("beacon.send", {
1153
+ type: "agentTool",
1154
+ threadId: e.threadId,
1155
+ sessionId: J(e),
1156
+ accountId: e.context.meta.accountId,
1157
+ tool: t.name,
1158
+ status: "ok",
1159
+ latencyMs: v(o)
1160
+ });
1161
+ } catch (i) {
1162
+ const a = i;
1163
+ if (await r.rpc("beacon.send", {
1164
+ type: "agentTool",
1165
+ threadId: e.threadId,
1166
+ sessionId: J(e),
1167
+ accountId: e.context.meta.accountId,
1168
+ tool: t.name,
1169
+ status: "error",
1170
+ latencyMs: v(o),
1171
+ errorCode: String(a?.code || a?.name || "unknown")
1172
+ }), t.onError) {
1173
+ t.errorOut && (e.bag[t.errorOut] = i), await F(t.onError, e, r);
1174
+ return;
1175
+ }
1176
+ throw i;
1177
+ }
1178
+ }
1179
+ async function wr(t, e, r, n) {
1180
+ const o = r.adapters?.[t.name];
1181
+ if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
1182
+ await kt(t, e, r, n);
1183
+ const i = U(await b(t.timeoutMs, n)), a = await Y(o(await b(t.input, n), n), i, () => new T("adapter_timeout", "The assistant adapter took too long to respond.", {
1184
+ source: "adapter",
1185
+ sourceCode: "timeout"
1186
+ }));
1187
+ t.out && (e.bag[t.out] = a), await G(t, a, e, r.contextStore);
1188
+ }
1189
+ async function br(t, e, r) {
1190
+ const n = await t.build(Q(e));
1191
+ Rr(n, e.productSkusEmitted), r.emit(n);
1192
+ }
1193
+ async function kr(t, e, r) {
1194
+ await G(t, void 0, e, r.contextStore);
1195
+ }
1196
+ async function Ar(t, e, r, n) {
1197
+ const o = String(await b(t.on, n) || "default");
1198
+ await F(t.cases[o] || t.cases.default || [], e, r);
1199
+ }
1200
+ async function _r(t, e, r) {
1201
+ const n = U(await b(t.timeoutMs, Q(e))), o = n ? new AbortController() : null, i = Wt(r.signal, o?.signal), a = t.steps.map((l) => {
1202
+ const u = {
1203
+ ...e,
1204
+ context: jr(e.context),
1205
+ bag: ct(e.bag),
1206
+ productSkusEmitted: new Set(e.productSkusEmitted),
1207
+ committed: !1
1208
+ }, f = [];
1209
+ return F(l, u, {
1210
+ ...r,
1211
+ emit: (p) => {
1212
+ !i?.aborted && p.type !== "done" && f.push(p);
1213
+ },
1214
+ contextStore: Er(u),
1215
+ ...i ? { signal: i } : {}
1216
+ }).then(() => ({
1217
+ state: u,
1218
+ events: f
1219
+ }));
1220
+ }), s = await Y(Promise.all(a), n, () => new T("parallel_timeout", "The assistant parallel step took too long to respond.", {
1221
+ source: "agent",
1222
+ sourceCode: "timeout"
1223
+ }), () => o?.abort()), c = t.merge || {};
1224
+ for (const { state: l, events: u } of s) {
1225
+ for (const f of u) r.emit(f);
1226
+ for (const f of l.productSkusEmitted) e.productSkusEmitted.add(f);
1227
+ for (const f of c.bag || []) Object.prototype.hasOwnProperty.call(l.bag, f) && (e.bag[f] = l.bag[f]);
1228
+ if (c.panel?.length) {
1229
+ const f = Nt(l.context.panel, c.panel);
1230
+ Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { panel: f }) || e.context);
1231
+ }
1232
+ if (c.threadExtensions?.length) {
1233
+ const f = Nt(l.context.thread.extensions, c.threadExtensions);
1234
+ Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { thread: {
1235
+ ...e.context.thread,
1236
+ extensions: f
1237
+ } }) || e.context);
1238
+ }
1239
+ }
1240
+ }
1241
+ async function xr(t, e, r, n) {
1242
+ r.emit(ar(await b(t.message, n), !0)), await bt(e, r);
1243
+ }
1244
+ async function Sr(t, e, r) {
1245
+ await bt(e, r);
1246
+ }
1247
+ async function bt(t, { contextStore: e, emit: r }) {
1248
+ t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, r(Jt()));
1249
+ }
1250
+ async function G(t, e, r, n) {
1251
+ if (typeof t.patch != "function") return;
1252
+ const o = await t.patch(r.context, e, Q(r));
1253
+ o && (r.context = n.patch(r.threadId, o) || r.context);
1254
+ }
1255
+ function Q(t) {
1256
+ return {
1257
+ request: t.request,
1258
+ context: t.context,
1259
+ bag: t.bag,
1260
+ accountConfig: t.accountConfig,
1261
+ catalogMapper: t.catalogMapper,
1262
+ similarityMapper: t.similarityMapper
1263
+ };
1264
+ }
1265
+ function J(t) {
1266
+ return t.request?.session_id || t.request?.sessionId || t.threadId;
1267
+ }
1268
+ function vr(t, e) {
1269
+ if (!e) return !1;
1270
+ const r = t.messages[t.messages.length - 1];
1271
+ return r?.role !== "user" || r.content !== e;
1272
+ }
1273
+ function Nt(t, e) {
1274
+ const r = {};
1275
+ for (const n of e) Object.prototype.hasOwnProperty.call(t, n) && (r[n] = t[n]);
1276
+ return r;
1277
+ }
1278
+ function jr(t) {
1279
+ return {
1280
+ ...t,
1281
+ panel: ct(t.panel || {}),
1282
+ thread: {
1283
+ ...t.thread,
1284
+ extensions: ct(t.thread?.extensions || {})
1285
+ },
1286
+ meta: t.meta,
1287
+ messages: t.messages
1288
+ };
1289
+ }
1290
+ function Er(t) {
1291
+ return {
1292
+ async load() {
1293
+ return t.context;
1294
+ },
1295
+ patch(e, r) {
1296
+ return t.context = Cr(t.context, r, t.messageLimit), t.context;
1297
+ },
1298
+ appendUserMessage() {
1299
+ return t.context;
1300
+ },
1301
+ async commit() {
1302
+ return t.context;
1303
+ }
1304
+ };
1305
+ }
1306
+ function Cr(t, e, r) {
1307
+ if (!e || typeof e != "object") return t;
1308
+ const n = qt(t.panel, e.panel), o = qt(t.thread?.extensions || {}, e.thread?.extensions);
1309
+ return {
1310
+ ...t,
1311
+ ...e,
1312
+ panel: n,
1313
+ thread: {
1314
+ ...t.thread || {},
1315
+ ...e.thread || {},
1316
+ extensions: o
1317
+ },
1318
+ meta: {
1319
+ ...t.meta || {},
1320
+ ...e.meta || {}
1321
+ },
1322
+ messages: Array.isArray(e.messages) ? H(e.messages, r) : t.messages
1323
+ };
1324
+ }
1325
+ function qt(t, e) {
1326
+ if (!e || typeof e != "object" || Array.isArray(e)) return t;
1327
+ const r = {};
1328
+ for (const n of Object.keys(t)) r[n] = t[n];
1329
+ for (const [n, o] of Object.entries(e)) r[n] = o;
1330
+ return r;
1331
+ }
1332
+ function ct(t) {
1333
+ return new Proxy({}, {
1334
+ get(e, r, n) {
1335
+ if (typeof r != "string") return Reflect.get(e, r, n);
1336
+ if (Object.prototype.hasOwnProperty.call(e, r)) return e[r];
1337
+ const o = t[r];
1338
+ if (Ir(o)) {
1339
+ const i = Tr(o);
1340
+ return e[r] = i, i;
1341
+ }
1342
+ return o;
1343
+ },
1344
+ has(e, r) {
1345
+ return Reflect.has(e, r) || Reflect.has(t, r);
1346
+ },
1347
+ ownKeys(e) {
1348
+ return Reflect.ownKeys(e);
1349
+ },
1350
+ getOwnPropertyDescriptor(e, r) {
1351
+ return Object.getOwnPropertyDescriptor(e, r);
1352
+ }
1353
+ });
1354
+ }
1355
+ function Ir(t) {
1356
+ return !!(t && typeof t == "object");
1357
+ }
1358
+ function Tr(t) {
1359
+ if (typeof structuredClone == "function") try {
1360
+ return structuredClone(t);
1361
+ } catch {
1362
+ }
1363
+ try {
1364
+ return JSON.parse(JSON.stringify(t));
1365
+ } catch {
1366
+ return t;
1367
+ }
1368
+ }
1369
+ async function b(t, e) {
1370
+ return typeof t == "function" ? await t(e) : t;
1371
+ }
1372
+ function U(t) {
1373
+ if (t === void 0) return;
1374
+ const e = Math.floor(Number(t));
1375
+ return Number.isFinite(e) && e > 0 ? e : void 0;
1376
+ }
1377
+ async function Y(t, e, r, n) {
1378
+ if (!e) return t;
1379
+ let o, i = !1;
1380
+ return new Promise((a, s) => {
1381
+ o = setTimeout(() => {
1382
+ i || (i = !0, n?.(), s(r()));
1383
+ }, e), Promise.resolve(t).then((c) => {
1384
+ i || (i = !0, o && clearTimeout(o), a(c));
1385
+ }, (c) => {
1386
+ i || (i = !0, o && clearTimeout(o), s(c));
1387
+ });
1388
+ });
1389
+ }
1390
+ function Wt(t, e) {
1391
+ if (!t) return e;
1392
+ if (!e || t.aborted) return t;
1393
+ if (e.aborted) return e;
1394
+ const r = new AbortController(), n = () => r.abort();
1395
+ return t.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), r.signal;
1396
+ }
1397
+ async function kt(t, e, r, n) {
1398
+ if (!t.confirm) return;
1399
+ const o = await b(t.confirm, n);
1400
+ if (!o) return;
1401
+ const i = Pr(o, t, e);
1402
+ await j(r, it("confirmation:start", e, t));
1403
+ try {
1404
+ const a = await r.rpc("confirmation.request", i), s = typeof a == "boolean" ? a : a?.confirmed === !0;
1405
+ if (await j(r, it("confirmation:end", e, t)), s) return;
1406
+ throw new T("confirmation_declined", "The requested action was not confirmed.", {
1407
+ source: t.kind === "be_op" ? "be" : t.kind,
1408
+ sourceCode: "confirmation_declined",
1409
+ detail: a
1410
+ });
1411
+ } catch (a) {
1412
+ throw await j(r, {
1413
+ ...it("confirmation:error", e, t),
1414
+ errorCode: At(a)
1415
+ }), a;
1416
+ }
1417
+ }
1418
+ function Pr(t, e, r) {
1419
+ return {
1420
+ ...Or(t),
1421
+ accountId: r.context.meta.accountId,
1422
+ threadId: r.threadId,
1423
+ sessionId: J(r),
1424
+ stepKind: e.kind,
1425
+ ...e.kind === "be_op" ? { stepName: e.op } : { stepName: e.name }
1426
+ };
1427
+ }
1428
+ function Or(t) {
1429
+ return typeof t == "string" ? { message: t } : t === !0 ? {} : t && typeof t == "object" ? {
1430
+ ...typeof t.title == "string" ? { title: t.title } : {},
1431
+ ...typeof t.message == "string" ? { message: t.message } : {},
1432
+ ...typeof t.action == "string" ? { action: t.action } : {},
1433
+ ...Object.prototype.hasOwnProperty.call(t, "payload") ? { payload: t.payload } : {}
1434
+ } : {};
1435
+ }
1436
+ async function j(t, e) {
1437
+ try {
1438
+ await t.trace?.(e);
1439
+ } catch {
1440
+ }
1441
+ }
1442
+ function N(t, e) {
1443
+ return {
1444
+ type: t,
1445
+ accountId: e.context.meta.accountId,
1446
+ threadId: e.threadId,
1447
+ sessionId: J(e)
1448
+ };
1449
+ }
1450
+ function ot(t, e, r, n) {
1451
+ const o = Xt(r);
1452
+ return {
1453
+ ...N(t, e),
1454
+ stepIndex: n,
1455
+ stepKind: r.kind,
1456
+ ...o ? { stepName: o } : {}
1457
+ };
1458
+ }
1459
+ function it(t, e, r) {
1460
+ const n = Xt(r);
1461
+ return {
1462
+ ...N(t, e),
1463
+ stepKind: r.kind,
1464
+ ...n ? { stepName: n } : {}
1465
+ };
1466
+ }
1467
+ function Xt(t) {
1468
+ if (t.kind === "be_op") return t.op;
1469
+ if (t.kind === "tool" || t.kind === "adapter") return t.name;
1470
+ }
1471
+ function At(t) {
1472
+ if (t && typeof t == "object") {
1473
+ const e = t;
1474
+ return String(e.sourceCode || e.code || e.name || "unknown");
1475
+ }
1476
+ return "unknown";
1477
+ }
1478
+ function Br(t) {
1479
+ if (t === void 0) return;
1480
+ const e = Math.floor(Number(t));
1481
+ return Number.isFinite(e) && e > 0 ? e : void 0;
1482
+ }
1483
+ function Mr(t) {
1484
+ const e = t?.payload;
1485
+ if (typeof e == "string") return e;
1486
+ if (e && typeof e == "object" && "text" in e) {
1487
+ const r = e.text;
1488
+ if (typeof r == "string") return r;
1489
+ }
1490
+ return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
1491
+ }
1492
+ function Rr(t, e) {
1493
+ 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;
1494
+ if (Array.isArray(a)) {
1495
+ for (const s of a) if (s && typeof s == "object") {
1496
+ const c = s.sku;
1497
+ typeof c == "string" && e.add(c);
1498
+ }
1499
+ }
1500
+ }
1501
+ function Zn(t) {
1502
+ return { invoke(e, r) {
1503
+ return t("tool.invoke", {
1504
+ name: e,
1505
+ input: r
1506
+ });
1507
+ } };
1508
+ }
1509
+ function Hn(t, e = {}) {
1510
+ if (!Array.isArray(t)) return [];
1511
+ const r = e.maxItems ?? 8, n = e.maxFeatures ?? 8;
1512
+ return t.map((o) => $r(o, e.defaultBrand, n)).filter((o) => !!o).slice(0, r);
1513
+ }
1514
+ function $r(t, e, r) {
1515
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
1516
+ const n = t, o = ht(n);
1517
+ return o ? qr({
1518
+ sku: o.sku,
1519
+ name: o.name,
1520
+ url: o.url,
1521
+ image: o.image,
1522
+ price: o.price,
1523
+ currency: o.currency,
1524
+ category: o.category,
1525
+ category_names: o.category_names,
1526
+ brand: n.brand || e,
1527
+ features: Lr(n.features, r),
1528
+ specs: Nr(n.specs, r),
1529
+ in_stock: o.in_stock
1530
+ }) : null;
1531
+ }
1532
+ function Lr(t, e) {
1533
+ return Array.isArray(t) ? t.filter(Boolean).slice(0, e) : void 0;
1534
+ }
1535
+ function Nr(t, e) {
1536
+ if (!(!t || typeof t != "object" || Array.isArray(t)))
1537
+ return Object.fromEntries(Object.entries(t).filter(([, r]) => r != null).slice(0, e));
1538
+ }
1539
+ function qr(t) {
1540
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
1541
+ }
1542
+ function te(t) {
1543
+ if (!t || typeof t != "object" || Array.isArray(t)) return {};
1544
+ const e = t, r = Array.isArray(e.rows) ? e.rows : [];
1545
+ return {
1546
+ ...e,
1547
+ rows: r.map(Ur).filter(Boolean)
1548
+ };
1549
+ }
1550
+ function Fr(t, e) {
1551
+ const r = Array.isArray(t) ? t.filter((s) => !!(s && typeof s == "object" && !Array.isArray(s))) : [], n = te(e), o = Array.isArray(n.columns) ? n.columns.map(String) : [];
1552
+ if (!o.length) return r;
1553
+ const i = new Map(r.map((s) => [String(s.sku || s.id || ""), s])), a = o.map((s) => i.get(s)).filter((s) => !!s);
1554
+ return a.length ? a : r;
1555
+ }
1556
+ function Gn(t, e) {
1557
+ const r = te(t?.table), n = Fr(e, r);
1558
+ return {
1559
+ ...t || {},
1560
+ table: r,
1561
+ products: n,
1562
+ multiple_product_details: n
1563
+ };
1564
+ }
1565
+ function Ur(t) {
1566
+ return !t || typeof t != "object" || Array.isArray(t) ? null : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
1567
+ }
1568
+ function Qn(t = [], e = {}) {
1569
+ const r = {}, n = [];
1570
+ return (Array.isArray(t) ? t.map((o) => gt(o, e)).filter((o) => !!o) : []).forEach((o, i) => {
1571
+ const a = `product-${i.toString()}`;
1572
+ n.push(a);
1573
+ const s = {
1574
+ sku: o.sku,
1575
+ product: o
1576
+ };
1577
+ r[a] = {
1578
+ type: "ProductCard",
1579
+ props: {
1580
+ product: o,
1581
+ index: i,
1582
+ action: {
1583
+ title: o.name,
1584
+ type: "launchSingleProduct",
1585
+ payload: s
1586
+ }
1587
+ }
1588
+ };
1589
+ }), r.root = {
1590
+ type: "ProductGrid",
1591
+ props: { layout: "grid" },
1592
+ children: n
1593
+ }, {
1594
+ widget: "chat",
1595
+ panelHint: "panel",
1596
+ spec: {
1597
+ root: "root",
1598
+ elements: r
1599
+ }
1600
+ };
1601
+ }
1602
+ function Yn(t, e = {}) {
1603
+ return {
1604
+ widget: "chat",
1605
+ panelHint: "panel",
1606
+ spec: {
1607
+ root: "root",
1608
+ elements: { root: {
1609
+ type: "ProductDetailsPanel",
1610
+ props: { product: gt(t, e) || t || {} }
1611
+ } }
1612
+ }
1613
+ };
1614
+ }
1615
+ function Wn(t = {}, e = {}) {
1616
+ const r = (t.multiple_product_details || t.products || []).map((o) => gt(o, e)).filter((o) => !!o), n = t.table || zr(t.comparison_table);
1617
+ return {
1618
+ widget: "chat",
1619
+ panelHint: "panel",
1620
+ spec: {
1621
+ root: "root",
1622
+ elements: { root: {
1623
+ type: "ComparisonTable",
1624
+ props: {
1625
+ products: r,
1626
+ recommended: r.find((o) => o.sku === t.recommended_choice_sku) || r[0],
1627
+ attributes: Object.entries(n).map(([o, i]) => ({
1628
+ label: o,
1629
+ values: Array.isArray(i) ? i.map(String) : [String(i ?? "")]
1630
+ })),
1631
+ highlights: Lt(t.key_differences),
1632
+ specialCases: Lt(t.special_considerations),
1633
+ recommendedText: t.recommended_choice,
1634
+ productActions: Object.fromEntries(r.map((o) => [o.sku, {
1635
+ title: o.name,
1636
+ type: "launchSingleProduct",
1637
+ payload: {
1638
+ sku: o.sku,
1639
+ product: o
1640
+ }
1641
+ }]))
1642
+ }
1643
+ } }
1644
+ }
1645
+ };
1646
+ }
1647
+ function zr(t) {
1648
+ return Array.isArray(t) ? Object.fromEntries(t.map((e) => {
1649
+ const r = typeof e?.label == "string" ? e.label.trim() : "";
1650
+ return r ? [r, e.values] : null;
1651
+ }).filter((e) => !!e)) : {};
1652
+ }
1653
+ function Xn(t = []) {
1654
+ return {
1655
+ widget: "chat",
1656
+ panelHint: "inline",
1657
+ spec: {
1658
+ root: "root",
1659
+ elements: { root: {
1660
+ type: "ActionButtons",
1661
+ props: { buttons: (Array.isArray(t) ? t : []).map((e) => {
1662
+ const r = e.label || e.title || e.shortName || "", n = e.action || e.requestDetails || e.request_details;
1663
+ return !r || !n?.type ? null : {
1664
+ label: r,
1665
+ action: {
1666
+ title: r,
1667
+ type: n.type,
1668
+ ...n.payload !== void 0 ? { payload: n.payload } : {}
1669
+ }
1670
+ };
1671
+ }).filter((e) => !!e) }
1672
+ } }
1673
+ }
1674
+ };
1675
+ }
1676
+ function to(t) {
1677
+ return Object.freeze([...t]);
1678
+ }
1679
+ function Dr(t) {
1680
+ const e = t?.payload;
1681
+ if (typeof e == "string") return e;
1682
+ if (e && typeof e == "object" && "text" in e) {
1683
+ const n = e.text;
1684
+ if (typeof n == "string") return n;
1685
+ }
1686
+ const r = t?.action;
1687
+ return r && typeof r.payload == "string" ? r.payload : r && typeof r.title == "string" ? r.title : "";
1688
+ }
1689
+ var ee = [
1690
+ {
1691
+ pattern: /\bhttps?:\/\/[^\s?#]+(?:\?[^\s#]*)?/giu,
1692
+ replacement: Kr
1693
+ },
1694
+ {
1695
+ pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu,
1696
+ replacement: "[email]"
1697
+ },
1698
+ {
1699
+ pattern: /\b(?:\+?\d[\d\s().-]{7,}\d)\b/gu,
1700
+ replacement: "[phone]"
1701
+ },
1702
+ {
1703
+ pattern: /\b(?:token|secret|csrf|cookie|bearer|session|sid|cart(?:[_-]?id)?)\s*[:=]\s*[^\s,;&]+/giu,
1704
+ replacement: "[secret]"
1705
+ },
1706
+ {
1707
+ pattern: /\b(?:order|cart|session)[_-]?(?:id|no|number)?\s*[:#=]?\s*[A-Z0-9-]{6,}\b/giu,
1708
+ replacement: "[secret]"
1709
+ }
1710
+ ], re = { patterns: ee };
1711
+ function ne(t, e = re) {
1712
+ let r = typeof t == "string" ? t : t == null ? "" : String(t);
1713
+ for (const n of e.patterns || []) {
1714
+ const o = n.replacement;
1715
+ r = typeof o == "function" ? r.replace(n.pattern, (i) => o(i)) : r.replace(n.pattern, o);
1716
+ }
1717
+ return r;
1718
+ }
1719
+ function Vr(t, e = re) {
1720
+ return ne(Dr(t), e);
1721
+ }
1722
+ function Kr(t) {
1723
+ try {
1724
+ const e = new URL(t);
1725
+ return `${e.origin}${e.pathname}${e.search ? "?[query]" : ""}`;
1726
+ } catch {
1727
+ return "[url]";
1728
+ }
1729
+ }
1730
+ var Jr = [
1731
+ "assistantName",
1732
+ "homeDomain",
1733
+ "categories",
1734
+ "policyTopics"
1735
+ ], Zr = { intent: ["searchContract", "competitorBrands"] };
1736
+ function eo(t, e, r, n = {}) {
1737
+ const o = Hr(e, r, n);
1738
+ return Object.keys(o).length ? {
1739
+ ...t,
1740
+ account_config: o
1741
+ } : t;
1742
+ }
1743
+ function Hr(t, e, r = {}) {
1744
+ if (!t) return {};
1745
+ const n = {}, o = r.baseKeys || Jr;
1746
+ for (const s of o) Ft(n, t, s);
1747
+ const i = t[e];
1748
+ i && typeof i == "object" && !Array.isArray(i) && Object.assign(n, Gr(i));
1749
+ const a = r.opAllowlist || Zr;
1750
+ for (const s of a[e] || []) Ft(n, t, s);
1751
+ return n;
1752
+ }
1753
+ function Ft(t, e, r) {
1754
+ e[r] !== void 0 && (t[r] = e[r]);
1755
+ }
1756
+ function Gr(t) {
1757
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
1758
+ }
1759
+ var Qr = "input-hash";
1760
+ function Yr({ ttlS: t, promptVersion: e = "current" } = {}) {
1761
+ if (!Number.isFinite(t) || t <= 0) throw new Error("inputHashCachePolicy requires a positive ttlS");
1762
+ return {
1763
+ strategy: Qr,
1764
+ ttlS: t,
1765
+ promptVersion: e
1766
+ };
1767
+ }
1768
+ function Wr({ accountId: t = "", op: e, ttlS: r, promptVersion: n = "current", input: o, keyParts: i, locale: a } = {}) {
1769
+ if (!e) throw new Error("declarativeBeOpCache requires an op");
1770
+ return {
1771
+ cache: Yr({
1772
+ ttlS: r,
1773
+ promptVersion: n
1774
+ }),
1775
+ cacheTtlS: r,
1776
+ cacheKey: (s = {}) => Ht(e, {
1777
+ account: t,
1778
+ locale: at(a, s) || s.context?.meta?.locale || s.locale || "",
1779
+ promptVersion: n,
1780
+ payload: ut(at(o, s)),
1781
+ ...Xr(at(i, s))
1782
+ })
1783
+ };
1784
+ }
1785
+ function ro(t, e = {}) {
1786
+ return !t || t.kind !== "be_op" ? t : {
1787
+ ...t,
1788
+ ...Wr({
1789
+ op: t.op,
1790
+ ttlS: t.cacheTtlS,
1791
+ input: t.input,
1792
+ ...e
1793
+ })
1794
+ };
1795
+ }
1796
+ function at(t, e) {
1797
+ return typeof t == "function" ? t(e) : t;
1798
+ }
1799
+ function ut(t) {
1800
+ return Array.isArray(t) ? t.map(ut) : !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, ut(r)]));
1801
+ }
1802
+ function Xr(t) {
1803
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
1804
+ }
1805
+ var no = Object.freeze({
1806
+ FALLBACK_RESULTS: "fallback_results",
1807
+ FALLBACK_NO_RESULTS: "fallback_no_results",
1808
+ FALLBACK_PARTIAL: "fallback_partial",
1809
+ OP_UNAVAILABLE: "op_unavailable"
1810
+ });
1811
+ function oo(t, e = {}) {
1812
+ return {
1813
+ status: t,
1814
+ ...e
1815
+ };
1816
+ }
1817
+ function io(t) {
1818
+ return !!(t && typeof t == "object" && typeof t.status == "string");
1819
+ }
1820
+ function ao(t) {
1821
+ return function() {
1822
+ return [{
1823
+ kind: "tool",
1824
+ name: "readPage",
1825
+ input: () => ({}),
1826
+ out: "page",
1827
+ patch: (r, n) => n?.product && typeof t == "function" ? t(r, n.product) : null,
1828
+ onError: []
1829
+ }];
1830
+ };
1831
+ }
1832
+ function so(t) {
1833
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length > 0)));
1834
+ }
1835
+ function co(t, { screenSummary: e } = {}) {
1836
+ return { panel: {
1837
+ ...t?.panel || {},
1838
+ screen_type: "homepage",
1839
+ screen_sku_list: [],
1840
+ screen_summary: e || null,
1841
+ last_search_products: [],
1842
+ last_search: null,
1843
+ chat_mentioned_skus: [],
1844
+ reviews_summary_skus: [],
1845
+ ai_plist_summary: null,
1846
+ search_suggestions_skus: [],
1847
+ list_source: null,
1848
+ active_product_panel: !1,
1849
+ assistant_mode: "shopping",
1850
+ redirected_agent_state: null,
1851
+ ui_hints: null
1852
+ } };
1853
+ }
1854
+ function tn({ patterns: t, messageFilter: e, messageNormalizer: r = (o) => o, messageLimit: n = 10 } = {}) {
1855
+ const o = { patterns: [...ee, ...Array.isArray(t) ? t : []] };
1856
+ function i(c) {
1857
+ return ne(c, o);
1858
+ }
1859
+ function a(c) {
1860
+ return Vr(c, o);
1861
+ }
1862
+ function s(c = []) {
1863
+ const l = (Array.isArray(c) ? c : []).filter((u) => typeof e == "function" ? e(u) : u && typeof u == "object").filter(Boolean);
1864
+ return (Number.isFinite(n) && n > 0 ? l.slice(-n) : l).map((u) => ({
1865
+ role: u.role,
1866
+ content: i(r(u.content)).slice(0, 1e3)
1867
+ }));
1868
+ }
1869
+ return {
1870
+ redactPii: i,
1871
+ anonymousRequestText: a,
1872
+ anonymizeMessages: s
1873
+ };
1874
+ }
1875
+ function uo(t) {
1876
+ return String(t || "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(/&nbsp;/giu, " ").replace(/&amp;/giu, "&").replace(/&lt;|&gt;/giu, " ").replace(/\s+/gu, " ").trim();
1877
+ }
1878
+ var k = {
1879
+ features: 18,
1880
+ reviews: 4,
1881
+ qna: 4,
1882
+ sellers: 4,
1883
+ variants: 12,
1884
+ documents: 6,
1885
+ textBlocks: 6,
1886
+ relatedProducts: 8,
1887
+ textChars: 220
1888
+ }, _t = {
1889
+ description: /\b(?:description|details|product information|urun bilgisi|urun aciklamasi|açıklama|aciklama)\b/iu,
1890
+ seller: /\b(?:seller|merchant|store|satici|satıcı|magaza|mağaza)\b/iu,
1891
+ review: /\b(?:review|reviews|rating|ratings|yorum|degerlendirme|değerlendirme|puan)\b/iu,
1892
+ qna: /\b(?:questions?|answers?|qna|q&a|soru|cevap)\b/iu,
1893
+ payment: /\b(?:installment|instalment|payment|pay in|taksit|odeme|ödeme|vade)\b/iu,
1894
+ delivery: /\b(?:delivery|shipping|cargo|stock|availability|teslimat|kargo|stok|gonderim|gönderim)\b/iu,
1895
+ promotion: /\b(?:campaign|promotion|discount|coupon|deal|kampanya|indirim|kupon|firsat|fırsat)\b/iu,
1896
+ variant: /\b(?:variant|size|colour|color|beden|olcu|ölçü|renk|numara)\b/iu
1897
+ }, en = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|\+?\d[\d\s().-]{8,}\d|\b[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}\b|\b(?:token|session|csrf|secret)\s*[:=]\s*[\w.-]+/giu, rn = /(?:token|session|sid|auth|code|csrf|secret|key|password|passwd|phone|email|address|postcode|zip|jwt|bearer)/iu, nn = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}|\+?\d[\d\s().-]{8,}\d|[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}|[A-Za-z0-9_-]{24,}/iu;
1898
+ function lo({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (i) => i }) {
1899
+ return (i = {}) => on({
1900
+ accountId: t,
1901
+ getPageType: e,
1902
+ getProduct: r,
1903
+ getProducts: n,
1904
+ normalizeProduct: o,
1905
+ input: i
1906
+ });
1907
+ }
1908
+ function on({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (a) => a, input: i = {} }) {
1909
+ const a = Pn(i), s = o(i.product || st(r)), c = (st(n) || []).map(o).filter(Boolean), l = w(i.sku || s?.sku || i.product?.sku), u = l ? c.find((tt) => w(tt?.sku) === l) || s : s || c[0] || null, f = cn(l || u?.sku), p = Ut({
1910
+ ...f.product,
1911
+ ...u
1912
+ }), m = jt(K(u?.features), K(u?.specs), kn(u?.facet_hits), K(f.product?.features), ln(), fn(), dn()).slice(0, a.features), g = ie(W(u?.reviews), f.reviews, pn()).slice(0, a.reviews), _ = ae(xt(u?.qna), mn()).slice(0, a.qna), E = se(St(u?.sellers), yn()).slice(0, a.sellers), P = B([...u?.payment || [], ...V("payment", a)]), O = B([...u?.delivery || [], ...V("delivery", a)]), Et = B([...u?.promotions || [], ...V("promotion", a)]), Ct = ce(vt(u?.variants), gn()).slice(0, a.variants), It = hn(a.documents), Tt = le(u?.description, f.product?.description, wn("description"), V("description", {
1913
+ ...a,
1914
+ textBlocks: 2
1915
+ })[0]), Pt = c.filter((tt) => !l || w(tt?.sku) !== l).map(Ut).filter(Boolean).slice(0, a.relatedProducts);
1916
+ return R({
1917
+ accountId: t,
1918
+ pageType: st(e) || "other",
1919
+ url: Tn(),
1920
+ product: p,
1921
+ description: Tt,
1922
+ features: m,
1923
+ sellers: E,
1924
+ reviews: g,
1925
+ qna: _,
1926
+ rating: A(u?.rating ?? f.rating),
1927
+ review_count: A(u?.review_count ?? f.review_count),
1928
+ payment: P,
1929
+ delivery: O,
1930
+ promotions: Et,
1931
+ variants: Ct,
1932
+ documents: It,
1933
+ related_products: Pt,
1934
+ capabilities: jn({
1935
+ description: Tt,
1936
+ features: m,
1937
+ sellers: E,
1938
+ reviews: g,
1939
+ qna: _,
1940
+ payment: P,
1941
+ delivery: O,
1942
+ promotions: Et,
1943
+ variants: Ct,
1944
+ documents: It,
1945
+ relatedProducts: Pt
1946
+ }),
1947
+ privacy: {
1948
+ browserLocal: !0,
1949
+ rawHtml: !1,
1950
+ formValues: !1,
1951
+ cookies: !1,
1952
+ storage: !1,
1953
+ redacted: !0
1954
+ }
1955
+ });
1956
+ }
1957
+ function fo(t, e) {
1958
+ const r = Array.isArray(t) ? t.filter(Boolean) : [];
1959
+ if (!e || typeof e != "object" || !r.length) return r;
1960
+ const n = w(e.product?.sku);
1961
+ return r.map((o, i) => {
1962
+ const a = w(o?.sku);
1963
+ return r.length === 1 || n && a && n === a || i === 0 ? sn(o, e) : o;
1964
+ });
1965
+ }
1966
+ function an(t) {
1967
+ return !t || typeof t != "object" ? null : R({
1968
+ product: t.product,
1969
+ description: y(t.description, 500),
1970
+ features: An(t.features, 14),
1971
+ sellers: Sn(t.sellers, 4),
1972
+ reviews: _n(t.reviews, 4),
1973
+ qna: xn(t.qna, 4),
1974
+ rating: t.rating,
1975
+ review_count: t.review_count,
1976
+ payment: I(t.payment, 5, 160),
1977
+ delivery: I(t.delivery, 5, 160),
1978
+ promotions: I(t.promotions, 5, 160),
1979
+ variants: vn(t.variants, 10),
1980
+ documents: I(t.documents, 5, 220),
1981
+ capabilities: Array.isArray(t.capabilities) ? t.capabilities.slice(0, 12) : void 0
1982
+ });
1983
+ }
1984
+ function po(t, e, r = {}) {
1985
+ const n = an(t);
1986
+ if (!n) return e;
1987
+ const o = String(r.locale || "").toLowerCase().startsWith("en"), i = [], a = [n.rating ? `${n.rating}/5` : "", n.review_count ? `${n.review_count} ${o ? "reviews" : "yorum"}` : ""].filter(Boolean).join(", ");
1988
+ return a && i.push(o ? `Visible rating: ${a}.` : `Görünür puan bilgisi: ${a}.`), n.reviews?.length && i.push(`${o ? "Visible review highlights" : "Görünür yorumlardan öne çıkanlar"}: ${n.reviews.map((s) => [s.star ? `${s.star}/5` : "", s.content].filter(Boolean).join(" ")).filter(Boolean).slice(0, 3).join(" | ")}.`), i.length ? (i.push(o ? "This summary only uses product review and rating fields visible in the browser." : "Bu özet yalnızca tarayıcıda görünen ürün yorumu ve puan alanlarından hazırlandı."), i.join(" ")) : e;
1989
+ }
1990
+ function sn(t, e) {
1991
+ return R({
1992
+ ...t,
1993
+ description: le(t.description, e.description),
1994
+ features: jt(K(t.features), e.features).slice(0, 24),
1995
+ specs: t.specs || (e.features?.length ? Object.fromEntries(e.features.map(En)) : void 0),
1996
+ sellers: se(St(t.sellers), e.sellers),
1997
+ reviews: ie(W(t.reviews), e.reviews),
1998
+ qna: ae(xt(t.qna), e.qna),
1999
+ rating: t.rating ?? e.rating,
2000
+ review_count: t.review_count ?? e.review_count,
2001
+ payment: B([...t.payment || [], ...e.payment || []]),
2002
+ delivery: B([...t.delivery || [], ...e.delivery || []]),
2003
+ promotions: B([...t.promotions || [], ...e.promotions || []]),
2004
+ variants: ce(vt(t.variants), e.variants),
2005
+ documents: B([...t.documents || [], ...e.documents || []])
2006
+ });
2007
+ }
2008
+ function cn(t) {
2009
+ const e = [];
2010
+ for (const o of x('script[type="application/ld+json"]')) {
2011
+ const i = un(o.textContent);
2012
+ for (const a of lt(i))
2013
+ String(a?.["@type"] || "").toLowerCase() === "product" && e.push(a);
2014
+ }
2015
+ const r = e.find((o) => w(o.sku || o.productID || o.mpn) === w(t)) || e[0];
2016
+ if (!r) return {};
2017
+ const n = r.aggregateRating || {};
2018
+ return {
2019
+ product: R({
2020
+ sku: w(r.sku || r.productID || r.mpn),
2021
+ name: d(r.name),
2022
+ brand: d(r.brand?.name || r.brand),
2023
+ description: d(r.description),
2024
+ images: I(r.image, 8, 280),
2025
+ url: z(r.url),
2026
+ rating: A(n.ratingValue),
2027
+ review_count: A(n.reviewCount || n.ratingCount)
2028
+ }),
2029
+ reviews: W(r.review),
2030
+ rating: A(n.ratingValue),
2031
+ review_count: A(n.reviewCount || n.ratingCount)
2032
+ };
2033
+ }
2034
+ function lt(t) {
2035
+ return Array.isArray(t) ? t.flatMap(lt) : !t || typeof t != "object" ? [] : [t, ...lt(t["@graph"])];
2036
+ }
2037
+ function un(t) {
2038
+ try {
2039
+ return JSON.parse(String(t || ""));
2040
+ } catch {
2041
+ return null;
2042
+ }
2043
+ }
2044
+ function ln() {
2045
+ const t = [];
2046
+ for (const e of x("table tr")) {
2047
+ const r = [...e.querySelectorAll?.("th,td") || []].map((n) => d(n.textContent));
2048
+ r.length >= 2 && r[0] && r[1] && t.push({
2049
+ key: r[0],
2050
+ value: r.slice(1).join(" ")
2051
+ });
2052
+ }
2053
+ return t;
2054
+ }
2055
+ function fn() {
2056
+ const t = [];
2057
+ for (const e of x("dt")) {
2058
+ const r = d(e.textContent), n = d(e.nextElementSibling?.matches?.("dd") ? e.nextElementSibling.textContent : "");
2059
+ r && n && t.push({
2060
+ key: r,
2061
+ value: n
2062
+ });
2063
+ }
2064
+ return t;
2065
+ }
2066
+ function dn() {
2067
+ return x('[class*="spec" i], [class*="feature" i], [class*="attribute" i], li').map((t) => oe(d(t.textContent))).filter(Boolean).slice(0, k.features);
2068
+ }
2069
+ function pn() {
2070
+ return x('[class*="review" i], [data-review], [itemprop="review"]').map((t) => {
2071
+ const e = d(t.textContent);
2072
+ return !e || e.length < 8 || _t.qna.test(e) ? null : {
2073
+ content: y(e, 260),
2074
+ star: A(t.getAttribute?.("data-rating"))
2075
+ };
2076
+ }).filter(Boolean);
2077
+ }
2078
+ function mn() {
2079
+ const t = x('[class*="question" i], [class*="answer" i], [data-question], [data-answer]'), e = [];
2080
+ for (const r of t) {
2081
+ const n = d(r.textContent);
2082
+ if (!n || !_t.qna.test(n)) continue;
2083
+ const o = d(r.getAttribute?.("data-question") || n), i = d(r.getAttribute?.("data-answer") || r.nextElementSibling?.textContent || "");
2084
+ e.push({
2085
+ question: y(o, 220),
2086
+ answer: y(i, 260)
2087
+ });
2088
+ }
2089
+ return e;
2090
+ }
2091
+ function yn() {
2092
+ return x('[class*="seller" i], [class*="merchant" i], [data-seller], [data-merchant]').map((t) => d(t.getAttribute?.("data-seller") || t.getAttribute?.("data-merchant") || t.textContent)).filter(Boolean).map((t) => ({ merchant: y(t, 120) }));
2093
+ }
2094
+ function gn() {
2095
+ return x('[class*="variant" i] a,[class*="variant" i] button,[class*="size" i] button,[class*="color" i] button,[data-variant],[data-size],[data-color]').map((t) => R({
2096
+ name: y(fe(t), 120),
2097
+ value: y(t.getAttribute?.("data-value") || t.getAttribute?.("data-size") || t.getAttribute?.("data-color"), 120),
2098
+ sku: w(t.getAttribute?.("data-sku") || t.getAttribute?.("data-product-id")),
2099
+ url: z(t.getAttribute?.("href")),
2100
+ in_stock: t.getAttribute?.("disabled") == null && t.getAttribute?.("aria-disabled") !== "true"
2101
+ })).filter((t) => t.name || t.value || t.sku);
2102
+ }
2103
+ function hn(t) {
2104
+ return x("a[href]").filter((e) => /\.pdf(?:$|[?#])/iu.test(e.getAttribute?.("href") || "")).map((e) => {
2105
+ const r = fe(e) || "PDF", n = z(e.getAttribute?.("href"));
2106
+ return n ? `${r}: ${n}` : "";
2107
+ }).filter(Boolean).slice(0, t);
2108
+ }
2109
+ function V(t, e) {
2110
+ const r = _t[t];
2111
+ return r ? x("section,article,div,li,p,span,button,a").map((n) => d(n.textContent)).filter((n) => n && r.test(n) && n.length <= 900).map((n) => y(n, e.textChars || k.textChars)).filter(ue()).slice(0, e.textBlocks || k.textBlocks) : [];
2112
+ }
2113
+ function wn(t) {
2114
+ return d(document.querySelector?.(`meta[name="${t}"]`)?.getAttribute?.("content") || document.querySelector?.(`meta[property="og:${t}"]`)?.getAttribute?.("content"));
2115
+ }
2116
+ function x(t) {
2117
+ try {
2118
+ return [...document.querySelectorAll?.(t) || []].filter(bn);
2119
+ } catch {
2120
+ return [];
2121
+ }
2122
+ }
2123
+ function bn(t) {
2124
+ if (!t) return !1;
2125
+ if (!t.getBoundingClientRect) return !0;
2126
+ const e = t.getBoundingClientRect();
2127
+ if (e.width <= 0 || e.height <= 0) return !1;
2128
+ const r = window.getComputedStyle?.(t);
2129
+ return !r || r.visibility !== "hidden" && r.display !== "none" && Number(r.opacity || 1) > 0;
2130
+ }
2131
+ function K(t) {
2132
+ return t ? (Array.isArray(t) ? t : Object.entries(t).map(([e, r]) => ({
2133
+ key: e,
2134
+ value: r
2135
+ }))).map((e) => typeof e == "string" ? oe(e) || {
2136
+ key: "",
2137
+ value: d(e)
2138
+ } : {
2139
+ key: d(e.key || e.name || e.label),
2140
+ value: d(e.value || e.text || "")
2141
+ }).filter((e) => e.key || e.value) : [];
2142
+ }
2143
+ function kn(t) {
2144
+ return !t || typeof t != "object" ? [] : Object.entries(t).map(([e, r]) => ({
2145
+ key: d(e),
2146
+ value: d(r)
2147
+ }));
2148
+ }
2149
+ function oe(t) {
2150
+ const e = /^(.{2,80}?)\s*[::]\s*(.{1,220})$/u.exec(d(t));
2151
+ return e ? {
2152
+ key: e[1],
2153
+ value: e[2]
2154
+ } : null;
2155
+ }
2156
+ function W(t) {
2157
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { content: y(e, 260) } : {
2158
+ content: y(e.content || e.reviewBody || e.description || e.text, 260),
2159
+ star: A(e.star || e.rating || e.reviewRating?.ratingValue)
2160
+ }).filter((e) => e.content || e.star);
2161
+ }
2162
+ function xt(t) {
2163
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
2164
+ question: y(e.question || e.name || "", 220),
2165
+ answer: y(e.answer || e.acceptedAnswer?.text || e.text || "", 260)
2166
+ })).filter((e) => e.question || e.answer);
2167
+ }
2168
+ function St(t) {
2169
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { merchant: y(e, 120) } : {
2170
+ merchant: y(e.merchant || e.name || e.seller || "", 120),
2171
+ merchant_id: w(e.merchant_id || e.id || ""),
2172
+ merchant_rating: A(e.merchant_rating || e.rating),
2173
+ price_offer: A(e.price_offer || e.price)
2174
+ }).filter((e) => e.merchant || e.merchant_id);
2175
+ }
2176
+ function vt(t) {
2177
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
2178
+ name: y(e.name || e.label || e.title || "", 120),
2179
+ value: y(e.value || e.size || e.color || "", 120),
2180
+ sku: w(e.sku || e.code || ""),
2181
+ url: z(e.url),
2182
+ in_stock: e.in_stock
2183
+ })).filter((e) => e.name || e.value || e.sku || e.url);
2184
+ }
2185
+ function jt(...t) {
2186
+ const e = /* @__PURE__ */ new Set(), r = [];
2187
+ for (const n of t.flat().filter(Boolean)) {
2188
+ const o = {
2189
+ key: y(n.key || n.name || "", 90),
2190
+ value: y(n.value || n.text || "", 180)
2191
+ }, i = `${o.key}:${o.value}`.toLocaleLowerCase("tr-TR");
2192
+ !o.key && !o.value || e.has(i) || (e.add(i), r.push(o));
2193
+ }
2194
+ return r;
2195
+ }
2196
+ function ie(...t) {
2197
+ return X(t.flat().filter(Boolean), (e) => `${e.star || ""}:${e.content || ""}`);
2198
+ }
2199
+ function ae(...t) {
2200
+ return X(t.flat().filter(Boolean), (e) => `${e.question || ""}:${e.answer || ""}`);
2201
+ }
2202
+ function se(...t) {
2203
+ return X(t.flat().filter(Boolean), (e) => `${e.merchant || ""}:${e.merchant_id || ""}`);
2204
+ }
2205
+ function ce(...t) {
2206
+ return X(t.flat().filter(Boolean), (e) => `${e.sku || ""}:${e.name || ""}:${e.value || ""}`);
2207
+ }
2208
+ function X(t, e) {
2209
+ const r = /* @__PURE__ */ new Set();
2210
+ return t.filter((n) => {
2211
+ const o = e(n).toLocaleLowerCase("tr-TR");
2212
+ return !o.trim() || r.has(o) ? !1 : (r.add(o), !0);
2213
+ });
2214
+ }
2215
+ function B(t) {
2216
+ return I(t, 20, k.textChars);
2217
+ }
2218
+ function I(t, e, r) {
2219
+ return (Array.isArray(t) ? t : t ? [t] : []).map((n) => y(n, r)).filter(Boolean).filter(ue()).slice(0, e);
2220
+ }
2221
+ function ue() {
2222
+ const t = /* @__PURE__ */ new Set();
2223
+ return (e) => {
2224
+ const r = d(e).toLocaleLowerCase("tr-TR");
2225
+ return !r || t.has(r) ? !1 : (t.add(r), !0);
2226
+ };
2227
+ }
2228
+ function An(t, e) {
2229
+ return jt(t).slice(0, e);
2230
+ }
2231
+ function _n(t, e) {
2232
+ return W(t).slice(0, e);
2233
+ }
2234
+ function xn(t, e) {
2235
+ return xt(t).slice(0, e);
2236
+ }
2237
+ function Sn(t, e) {
2238
+ return St(t).slice(0, e);
2239
+ }
2240
+ function vn(t, e) {
2241
+ return vt(t).slice(0, e);
2242
+ }
2243
+ function Ut(t) {
2244
+ return !t || typeof t != "object" ? null : R({
2245
+ sku: w(t.sku || t.id || ""),
2246
+ group_id: w(t.group_id || t.groupId || ""),
2247
+ name: d(t.name || t.title || ""),
2248
+ brand: d(t.brand || ""),
2249
+ url: z(t.url),
2250
+ images: I(t.images || t.image, 8, 280),
2251
+ price: A(t.price),
2252
+ price_discounted: A(t.price_discounted || t.discountedPrice),
2253
+ price_text: d(t.price_text || t.priceText || ""),
2254
+ price_currency: d(t.price_currency || t.currency || ""),
2255
+ category_ids: Cn(t.category_ids || t.categoryIds, 8, 90),
2256
+ category_names: I(t.category_names || t.categoryNames || t.category, 8, 140),
2257
+ in_stock: t.in_stock
2258
+ });
2259
+ }
2260
+ function jn(t) {
2261
+ return [
2262
+ t.description ? "description" : "",
2263
+ t.features?.length ? "features" : "",
2264
+ t.sellers?.length ? "seller" : "",
2265
+ t.reviews?.length || t.rating || t.review_count ? "reviews_ratings" : "",
2266
+ t.qna?.length ? "qna" : "",
2267
+ t.payment?.length ? "installment_payment" : "",
2268
+ t.delivery?.length ? "shipping_delivery_stock" : "",
2269
+ t.promotions?.length ? "campaigns_promotions" : "",
2270
+ t.variants?.length ? "variants" : "",
2271
+ t.documents?.length ? "documents" : "",
2272
+ t.relatedProducts?.length ? "related_products" : ""
2273
+ ].filter(Boolean);
2274
+ }
2275
+ function En(t) {
2276
+ return [d(t.key || t.name), d(t.value || t.text)];
2277
+ }
2278
+ function le(...t) {
2279
+ return t.map((e) => y(e, 700)).find(Boolean) || "";
2280
+ }
2281
+ function y(t, e) {
2282
+ return d(t).slice(0, e);
2283
+ }
2284
+ function fe(t) {
2285
+ return d(t.getAttribute?.("aria-label") || t.getAttribute?.("title") || t.getAttribute?.("alt") || t.textContent);
2286
+ }
2287
+ function d(t) {
2288
+ return String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(en, "[redacted]").replace(/\s+/gu, " ").trim();
2289
+ }
2290
+ function w(t) {
2291
+ const e = String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
2292
+ return !e || /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/iu.test(e) || /\b(?:token|session|csrf|secret|password|passwd|jwt|bearer)\s*[:=]\s*[\w.-]+/iu.test(e) ? "" : e.slice(0, 120);
2293
+ }
2294
+ function Cn(t, e, r) {
2295
+ return (Array.isArray(t) ? t : t ? [t] : []).map((n) => w(n).slice(0, r)).filter(Boolean).filter(In()).slice(0, e);
2296
+ }
2297
+ function In() {
2298
+ const t = /* @__PURE__ */ new Set();
2299
+ return (e) => {
2300
+ const r = w(e).toLocaleLowerCase("tr-TR");
2301
+ return !r || t.has(r) ? !1 : (t.add(r), !0);
2302
+ };
2303
+ }
2304
+ function A(t) {
2305
+ const e = Number(String(t ?? "").replace(",", "."));
2306
+ return Number.isFinite(e) && e > 0 ? e : void 0;
2307
+ }
2308
+ function z(t) {
2309
+ if (!t) return "";
2310
+ try {
2311
+ const e = new URL(t, window.location.href);
2312
+ return /^https?:$/u.test(e.protocol) ? (e.hash = "", de(e), e.href) : "";
2313
+ } catch {
2314
+ return "";
2315
+ }
2316
+ }
2317
+ function Tn() {
2318
+ try {
2319
+ const t = new URL(window.location.href);
2320
+ return t.hash = "", de(t), `${t.origin}${t.pathname}${t.search}`;
2321
+ } catch {
2322
+ return "";
2323
+ }
2324
+ }
2325
+ function de(t) {
2326
+ for (const [e, r] of [...t.searchParams.entries()]) {
2327
+ const n = String(r || "");
2328
+ (rn.test(e) || nn.test(n)) && t.searchParams.set(e, "redacted");
2329
+ }
2330
+ return t;
2331
+ }
2332
+ function Pn(t = {}) {
2333
+ return {
2334
+ features: S(t.maxFeatures, k.features, 40),
2335
+ reviews: S(t.maxReviews, k.reviews, 12),
2336
+ qna: S(t.maxQna, k.qna, 12),
2337
+ sellers: S(t.maxSellers, k.sellers, 12),
2338
+ variants: S(t.maxVariants, k.variants, 30),
2339
+ documents: S(t.maxDocuments, k.documents, 12),
2340
+ textBlocks: S(t.maxTextBlocks, k.textBlocks, 16),
2341
+ relatedProducts: S(t.maxRelatedProducts, k.relatedProducts, 20),
2342
+ textChars: S(t.textChars, k.textChars, 420)
2343
+ };
2344
+ }
2345
+ function S(t, e, r) {
2346
+ const n = Number(t);
2347
+ return !Number.isFinite(n) || n <= 0 ? e : Math.min(Math.floor(n), r);
2348
+ }
2349
+ function st(t) {
2350
+ try {
2351
+ return typeof t == "function" ? t() : null;
2352
+ } catch {
2353
+ return null;
2354
+ }
2355
+ }
2356
+ function R(t) {
2357
+ return Object.fromEntries(Object.entries(t || {}).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length)));
2358
+ }
2359
+ var { redactPii: mo, anonymousRequestText: yo, anonymizeMessages: go } = tn({ patterns: [{
2360
+ pattern: /\b\d{5}\b/gu,
2361
+ replacement: "[postcode]"
2362
+ }, {
2363
+ pattern: /\b(?:adresim|adres|mahalle|sokak|cadde)\b[^,.!?\n]{8,160}/giu,
2364
+ replacement: "[address]"
2365
+ }] });
2366
+ function On(t) {
2367
+ return (t?.route?.flow_params && typeof t.route.flow_params == "object" ? t.route.flow_params : null) || (t?.route?.flowParams && typeof t.route.flowParams == "object" ? t.route.flowParams : null) || {};
2368
+ }
2369
+ function ho(t) {
2370
+ return Array.isArray(t) ? t.find((e) => String(e || "").trim()) : void 0;
2371
+ }
2372
+ function wo(t) {
2373
+ const e = On(t);
2374
+ return [
2375
+ ...e.sku ? [e.sku] : [],
2376
+ ...Array.isArray(e.sku_list) ? e.sku_list : [],
2377
+ ...Array.isArray(e.skus) ? e.skus : [],
2378
+ ...Array.isArray(e.target_skus) ? e.target_skus : []
2379
+ ].map((r) => String(r || "").trim()).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n);
2380
+ }
2381
+ export {
2382
+ qn as $,
2383
+ to as A,
2384
+ Jn as B,
2385
+ Hr as C,
2386
+ ee as D,
2387
+ re as E,
2388
+ Fr as F,
2389
+ Kn as G,
2390
+ Vn as H,
2391
+ Gn as I,
2392
+ zn as J,
2393
+ gt as K,
2394
+ te as L,
2395
+ Wn as M,
2396
+ Yn as N,
2397
+ ne as O,
2398
+ Qn as P,
2399
+ sr as Q,
2400
+ Hn as R,
2401
+ ro as S,
2402
+ Vr as T,
2403
+ Dn as U,
2404
+ Ht as V,
2405
+ Gt as W,
2406
+ Un as X,
2407
+ cr as Y,
2408
+ Jt as Z,
2409
+ no as _,
2410
+ ge as _t,
2411
+ yo as a,
2412
+ Ln as at,
2413
+ Wr as b,
2414
+ lo as c,
2415
+ Ge as ct,
2416
+ po as d,
2417
+ v as dt,
2418
+ ar as et,
2419
+ tn as f,
2420
+ Le as ft,
2421
+ ao as g,
2422
+ $e as gt,
2423
+ so as h,
2424
+ Rn as ht,
2425
+ go as i,
2426
+ Kt as it,
2427
+ Xn as j,
2428
+ Dr as k,
2429
+ on as l,
2430
+ $n as lt,
2431
+ co as m,
2432
+ Se as mt,
2433
+ On as n,
2434
+ Nn as nt,
2435
+ mo as o,
2436
+ tr as ot,
2437
+ uo as p,
2438
+ Mn as pt,
2439
+ ht as q,
2440
+ wo as r,
2441
+ T as rt,
2442
+ an as s,
2443
+ Qe as st,
2444
+ ho as t,
2445
+ Fn as tt,
2446
+ fo as u,
2447
+ Dt as ut,
2448
+ oo as v,
2449
+ he as vt,
2450
+ eo as w,
2451
+ Yr as x,
2452
+ io as y,
2453
+ Zn as z
2454
+ };