@gengage/assistant-fe 0.6.26 → 0.6.28

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 (42) hide show
  1. package/dist/agent-ui-steps-Dc4ByfZo.js +3161 -0
  2. package/dist/agentic/context/context-store.d.ts +25 -0
  3. package/dist/agentic/debug/activity-collector.d.ts +1 -0
  4. package/dist/agentic/index.d.ts +15 -1
  5. package/dist/agentic/index.js +415 -380
  6. package/dist/agentic/types.d.ts +34 -3
  7. package/dist/agentic/worker/agent-ui-steps.d.ts +43 -0
  8. package/dist/agentic/worker/agent-ui.d.ts +44 -0
  9. package/dist/agentic/worker/be-client.d.ts +16 -4
  10. package/dist/agentic/worker/coalesce.d.ts +25 -0
  11. package/dist/agentic/worker/compaction.d.ts +12 -0
  12. package/dist/agentic/worker/pdp-hydrate.d.ts +30 -0
  13. package/dist/agentic/worker/tool-schema.d.ts +19 -0
  14. package/dist/agentic/worker.d.ts +15 -1
  15. package/dist/agentic/worker.js +292 -264
  16. package/dist/agentic.iife.js +10 -9
  17. package/dist/{api-paths-CmFRzaMd.js → api-paths-PFiXYIey.js} +1 -1
  18. package/dist/chat-runtime.js +1 -1
  19. package/dist/chat.iife.js +1 -1
  20. package/dist/chat.js +1 -1
  21. package/dist/{common-uHKZ-s5H.js → common-DyAcz33-.js} +1 -1
  22. package/dist/common.js +5 -5
  23. package/dist/{connection-warning-xRmq7uJ3.js → connection-warning-nWEUv5bp.js} +1 -1
  24. package/dist/{fastIntent-B3qZhCis.js → fastIntent-BiHAWBIa.js} +1 -1
  25. package/dist/index.js +10 -10
  26. package/dist/native.iife.js +1 -1
  27. package/dist/qna-runtime.js +1 -1
  28. package/dist/qna.iife.js +1 -1
  29. package/dist/qna.js +1 -1
  30. package/dist/{runtime-Cpi9hXiL.js → runtime-BIA5sGno.js} +3 -3
  31. package/dist/{runtime-C1mVW5y1.js → runtime-BuzZUB0i.js} +3 -3
  32. package/dist/{runtime-DhhnaNUQ.js → runtime-PHarcyNZ.js} +3 -3
  33. package/dist/{simbut-csGdfd9_.js → simbut-CiPq-niE.js} +1 -1
  34. package/dist/simbut.iife.js +1 -1
  35. package/dist/simbut.js +1 -1
  36. package/dist/{simrel-B1VHfhBf.js → simrel-XWtKe-OG.js} +1 -1
  37. package/dist/simrel-runtime.js +1 -1
  38. package/dist/simrel.iife.js +1 -1
  39. package/dist/simrel.js +2 -2
  40. package/dist/{widget-base-DNT8SYtf.js → widget-base-DSl6thOx.js} +1 -1
  41. package/package.json +1 -1
  42. package/dist/route-params-UDemctx_.js +0 -2471
@@ -0,0 +1,3161 @@
1
+ import { t as xe } from "./request-response-cache-BxRsKGJ0.js";
2
+ var ve = 120 * 1e3, Ce = "gengage-agentic-ref";
3
+ function Te({ namespace: t = Ce, ttlMs: e = ve, maxEntries: r = 100 } = {}) {
4
+ const n = /* @__PURE__ */ new Map();
5
+ async function o(u, l = {}) {
6
+ c();
7
+ const f = Pe(), d = l.kind || "pageRef", p = {
8
+ kind: d,
9
+ value: u,
10
+ expiresAt: Date.now() + (l.ttlMs || e)
11
+ };
12
+ for (n.set(f, p); n.size > r; ) n.delete(n.keys().next().value);
13
+ return await Ie(t, f, p), {
14
+ kind: d,
15
+ id: f
16
+ };
17
+ }
18
+ async function i(u) {
19
+ const l = typeof u == "string" ? u : u?.id;
20
+ if (!l) return;
21
+ const f = n.get(l) || await je(t, l);
22
+ if (f) {
23
+ if (f.expiresAt <= Date.now()) {
24
+ n.delete(l), await Nt(t, l);
25
+ return;
26
+ }
27
+ return n.set(l, f), f.value;
28
+ }
29
+ }
30
+ async function a(u) {
31
+ const l = typeof u == "string" ? u : u?.id;
32
+ l && (n.delete(l), await Nt(t, l));
33
+ }
34
+ async function s(u) {
35
+ if (Ee(u)) return i(u);
36
+ if (Array.isArray(u)) return Promise.all(u.map((f) => s(f)));
37
+ if (!u || typeof u != "object") return u;
38
+ const l = await Promise.all(Object.entries(u).map(async ([f, d]) => [f, await s(d)]));
39
+ return Object.fromEntries(l);
40
+ }
41
+ function c() {
42
+ const u = Date.now();
43
+ for (const [l, f] of n.entries()) f.expiresAt <= u && n.delete(l);
44
+ }
45
+ return {
46
+ put: o,
47
+ get: i,
48
+ delete: a,
49
+ materialize: s,
50
+ cleanup: c
51
+ };
52
+ }
53
+ function Ee(t) {
54
+ return !!(t && typeof t == "object" && typeof t.kind == "string" && typeof t.id == "string");
55
+ }
56
+ function Pe() {
57
+ return globalThis.crypto?.randomUUID ? globalThis.crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
58
+ }
59
+ async function Ie(t, e, r) {
60
+ const n = await _t(t);
61
+ n && (await et(n.transaction("refs", "readwrite").objectStore("refs").put(r, e)), n.close());
62
+ }
63
+ async function je(t, e) {
64
+ const r = await _t(t);
65
+ if (!r) return;
66
+ const n = await et(r.transaction("refs", "readonly").objectStore("refs").get(e));
67
+ return r.close(), n;
68
+ }
69
+ async function Nt(t, e) {
70
+ const r = await _t(t);
71
+ r && (await et(r.transaction("refs", "readwrite").objectStore("refs").delete(e)), r.close());
72
+ }
73
+ async function _t(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 et(e);
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+ function et(t) {
85
+ return new Promise((e, r) => {
86
+ t.onsuccess = () => e(t.result), t.onerror = () => r(t.error);
87
+ });
88
+ }
89
+ function Oe(t) {
90
+ return !!t && typeof t == "object" && t.type === "rpc.result";
91
+ }
92
+ function Re(t) {
93
+ return !!t && typeof t == "object" && t.type === "rpc.req";
94
+ }
95
+ function yo(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 (!Oe(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, u) => {
118
+ r.set(s, {
119
+ resolve: (l) => c(l),
120
+ reject: u
121
+ });
122
+ });
123
+ };
124
+ }
125
+ function go({ worker: t, tools: e = {}, beacon: r, confirmation: n, memory: o = Be(), refStore: i }) {
126
+ t.addEventListener("message", (a) => {
127
+ const s = a.data;
128
+ Re(s) && Me(t, s, {
129
+ tools: e,
130
+ beacon: r,
131
+ confirmation: n,
132
+ memory: o,
133
+ refStore: i
134
+ });
135
+ });
136
+ }
137
+ async function Me(t, e, r) {
138
+ try {
139
+ const n = await Je(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 ct = /* @__PURE__ */ new Map(), Ft = null;
156
+ function Be() {
157
+ try {
158
+ if (typeof sessionStorage < "u") return sessionStorage;
159
+ } catch {
160
+ }
161
+ return {
162
+ getItem: (t) => ct.get(t) ?? null,
163
+ setItem: (t, e) => {
164
+ ct.set(t, e);
165
+ },
166
+ removeItem: (t) => {
167
+ ct.delete(t);
168
+ }
169
+ };
170
+ }
171
+ function $e() {
172
+ return Ft ||= Te(), Ft;
173
+ }
174
+ function Le(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 Ne(t) {
179
+ if (t && typeof t == "object" && t.key !== void 0) return t;
180
+ throw new Error("memory.get requires { key }");
181
+ }
182
+ function Fe(t) {
183
+ if (t && typeof t == "object" && t.key !== void 0) return t;
184
+ throw new Error("memory.set requires { key }");
185
+ }
186
+ function qe(t) {
187
+ if (t && typeof t == "object" && t.key !== void 0) return t;
188
+ throw new Error("memory.remove requires { key }");
189
+ }
190
+ function De(t) {
191
+ return !t || typeof t != "object" ? { value: t } : t;
192
+ }
193
+ function Ue(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 ut(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 At(t) {
210
+ return typeof t.getItem == "function" && typeof t.setItem == "function";
211
+ }
212
+ function St(t) {
213
+ return typeof t.get == "function" && typeof t.set == "function";
214
+ }
215
+ function xt(t) {
216
+ return typeof t.accountId == "string" && !!t.session && !!t.indexedDb;
217
+ }
218
+ function ze(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 Ve(t, e, r) {
223
+ if (At(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 St(t) && !xt(t) ? await t.get(e, r) ?? null : await t[e].get(r) ?? null;
233
+ }
234
+ async function Ke(t, e, r, n, o) {
235
+ return At(t) ? (t.setItem(r, JSON.stringify(n ?? null)), !0) : St(t) && !xt(t) ? await t.set(e, r, n ?? null, o) !== !1 : await t[e].set(r, n ?? null, o) !== !1;
236
+ }
237
+ async function He(t, e, r) {
238
+ return At(t) ? (t.removeItem?.(r), !0) : St(t) && !xt(t) ? t.remove ? (await t.remove(e, r), !0) : !1 : (await t[e].remove(r), !0);
239
+ }
240
+ async function Je(t, e, { tools: r, beacon: n, confirmation: o, memory: i, refStore: a }) {
241
+ if (t === "tool.invoke") {
242
+ const { name: s, input: c } = Le(e), u = r[s];
243
+ if (typeof u != "function") throw new Error(`Unknown tool: ${s}`);
244
+ return u(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 } = Ne(e);
255
+ return Ve(i, ut(c), String(s));
256
+ }
257
+ if (t === "memory.set") {
258
+ const s = Fe(e);
259
+ return { ok: await Ke(i, ut(s.tier), String(s.key), s.value, ze(s)) };
260
+ }
261
+ if (t === "memory.remove") {
262
+ const { key: s, tier: c } = qe(e);
263
+ return { ok: await He(i, ut(c), String(s)) };
264
+ }
265
+ if (t === "ref.put") {
266
+ const s = G({
267
+ tools: r,
268
+ beacon: n,
269
+ confirmation: o,
270
+ memory: i,
271
+ refStore: a
272
+ }), c = De(e);
273
+ return s.put(c.value, Ue(c));
274
+ }
275
+ if (t === "ref.get") return G({
276
+ tools: r,
277
+ beacon: n,
278
+ confirmation: o,
279
+ memory: i,
280
+ refStore: a
281
+ }).get(e);
282
+ if (t === "ref.materialize") return G({
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 G({
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 G(t) {
300
+ const e = t.refStore || $e();
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 Ze() {
305
+ return (/* @__PURE__ */ new Date()).toISOString();
306
+ }
307
+ function P(t) {
308
+ return Math.max(0, Math.round(performance.now() - t));
309
+ }
310
+ function z(t) {
311
+ return typeof t == "object" && t !== null && !Array.isArray(t);
312
+ }
313
+ function We(t) {
314
+ const { accountId: e, locale: r = "en-GB", parentUrl: n = "", threadId: o, incomingContext: i, messageLimit: a } = t, s = z(i) ? i : {}, c = z(s.thread) ? s.thread : {}, u = z(s.panel) ? s.panel : {}, l = z(s.meta) ? s.meta : {}, f = Yt(s.messages, a), d = {
315
+ id: String(o || c.id || self.crypto.randomUUID()),
316
+ started_at: String(c.started_at || Ze()),
317
+ extensions: z(c.extensions) ? { ...c.extensions } : {}
318
+ }, p = String(l.locale || r), m = String(l.parentUrl || n || typeof self < "u" && self.location?.href || "");
319
+ return {
320
+ panel: { ...u },
321
+ messages: f,
322
+ thread: d,
323
+ meta: {
324
+ locale: p,
325
+ parentUrl: m,
326
+ accountId: e
327
+ }
328
+ };
329
+ }
330
+ function qt(t, e, r) {
331
+ const n = Yt([e], r)[0];
332
+ return n ? {
333
+ ...t,
334
+ messages: rt([...t.messages, n], r)
335
+ } : t;
336
+ }
337
+ function rt(t, e) {
338
+ const r = Ge(e);
339
+ return r === 1 / 0 ? [...t] : t.slice(-r);
340
+ }
341
+ function Yt(t, e) {
342
+ return Array.isArray(t) ? rt(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.role === "tool_result") && (r.role === "tool_result" || !!r.content)), e) : [];
349
+ }
350
+ function Ge(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 Ye = "gengage:agent:context:";
357
+ async function Qe({ accountId: t, threadId: e, rpc: r }) {
358
+ const n = await r("memory.get", {
359
+ tier: "session",
360
+ key: Qt(t, e)
361
+ });
362
+ return n && typeof n == "object" && !Array.isArray(n) ? n : {};
363
+ }
364
+ async function Xe({ accountId: t, threadId: e, extensions: r, panel: n, rpc: o }) {
365
+ await o("memory.set", {
366
+ tier: "session",
367
+ key: Qt(t, e),
368
+ value: {
369
+ thread: { extensions: r },
370
+ ...n && Object.keys(n).length > 0 ? { panel: n } : {}
371
+ }
372
+ });
373
+ }
374
+ function Qt(t, e) {
375
+ return `${Ye}${t}:${e}`;
376
+ }
377
+ function w(t) {
378
+ return typeof t == "object" && t !== null && !Array.isArray(t);
379
+ }
380
+ var tr = "gengage_agentic_savepoints", Y = "savepoints", Dt = 3600 * 1e3, er = 1, ho = class {
381
+ #t = /* @__PURE__ */ new Map();
382
+ #i = /* @__PURE__ */ new Map();
383
+ #e;
384
+ #u;
385
+ #l;
386
+ #a;
387
+ #f;
388
+ #d;
389
+ #o;
390
+ #s;
391
+ #c;
392
+ #r = /* @__PURE__ */ new Map();
393
+ constructor({ accountId: t, locale: e, parentUrl: r, rpc: n, persistentPanelKeys: o = [], panelKeyLimits: i = {}, messageLimit: a, maxThreads: s, threadTtlMs: c }) {
394
+ this.#e = t, this.#u = e, this.#l = r, this.#a = n, this.#f = [...new Set(o.filter(Boolean))], this.#d = or(i), this.#o = dt(a), this.#s = dt(s), this.#c = dt(c);
395
+ }
396
+ get size() {
397
+ return this.pruneExpired(), this.#t.size;
398
+ }
399
+ get(t = "default") {
400
+ this.pruneExpired();
401
+ const e = String(t || "default"), r = this.#t.get(e);
402
+ return r ? (this.#n(e, r), r) : null;
403
+ }
404
+ getPanel(t = "default") {
405
+ return this.get(t)?.panel ?? null;
406
+ }
407
+ getRecentProducts(t = "default", e = "last_search_products") {
408
+ const r = this.getPanel(t)?.[e];
409
+ return Array.isArray(r) ? r : [];
410
+ }
411
+ async load(t) {
412
+ this.pruneExpired();
413
+ const e = t?.session_id || t?.meta?.threadId || t?.sessionId, r = String(e || "default"), n = this.#t.get(r);
414
+ if (n) {
415
+ const a = sr(n, t?.context, this.#o);
416
+ return this.#n(r, a), a;
417
+ }
418
+ const o = await Qe({
419
+ accountId: this.#e,
420
+ threadId: r,
421
+ rpc: this.#a
422
+ }), i = We({
423
+ accountId: this.#e,
424
+ locale: t?.locale || this.#u,
425
+ parentUrl: this.#l,
426
+ threadId: r,
427
+ incomingContext: ar(o, t?.context),
428
+ messageLimit: this.#o
429
+ });
430
+ return this.#n(r, i), this.#m(), i;
431
+ }
432
+ patch(t, e) {
433
+ this.pruneExpired();
434
+ const r = String(t || "default"), n = this.#t.get(r);
435
+ if (!n) return null;
436
+ const o = vt(n, typeof e == "function" ? e(n) : e, this.#o);
437
+ return this.#n(r, o), o;
438
+ }
439
+ appendUserMessage(t, e) {
440
+ this.pruneExpired();
441
+ const r = String(t || "default");
442
+ if (!e) return this.#t.get(r) ?? null;
443
+ const n = this.#t.get(r);
444
+ if (!n) return null;
445
+ const o = qt(n, {
446
+ role: "user",
447
+ content: e
448
+ }, this.#o);
449
+ return this.#n(r, o), o;
450
+ }
451
+ appendToolResult(t, e) {
452
+ this.pruneExpired();
453
+ const r = String(t || "default"), n = this.#t.get(r);
454
+ if (!n) return null;
455
+ const o = qt(n, {
456
+ role: "tool_result",
457
+ content: String(e?.content || ""),
458
+ ...e?.name ? { name: String(e.name) } : {},
459
+ ...e?.details !== void 0 ? { details: e.details } : {}
460
+ }, this.#o);
461
+ return this.#n(r, o), o;
462
+ }
463
+ async commit(t) {
464
+ this.pruneExpired();
465
+ const e = String(t || "default"), r = this.#t.get(e);
466
+ return r ? (this.#n(e, r), await Xe({
467
+ accountId: this.#e,
468
+ threadId: e,
469
+ extensions: r.thread.extensions,
470
+ panel: nr(r.panel, this.#f, this.#d),
471
+ rpc: this.#a
472
+ }), r) : null;
473
+ }
474
+ delete(t) {
475
+ const e = String(t || "default");
476
+ return this.#i.delete(e), this.#r.delete(e), this.#t.delete(e);
477
+ }
478
+ clear() {
479
+ this.#t.clear(), this.#i.clear(), this.#r.clear();
480
+ }
481
+ enqueueSteer(t, e, r = "all") {
482
+ this.#p(t, "steer", e, r);
483
+ }
484
+ enqueueFollowUp(t, e, r = "all") {
485
+ this.#p(t, "follow_up", e, r);
486
+ }
487
+ drainPending(t, e) {
488
+ const r = String(t || "default"), n = this.#r.get(r);
489
+ if (!n || !n.length) return null;
490
+ const o = n.findIndex((a) => a.kind === e);
491
+ if (o < 0) return null;
492
+ const [i] = n.splice(o, 1);
493
+ return n.length || this.#r.delete(r), i || null;
494
+ }
495
+ peekPending(t = "default") {
496
+ const e = String(t || "default"), r = this.#r.get(e);
497
+ return r ? [...r] : [];
498
+ }
499
+ #p(t, e, r, n) {
500
+ const o = String(r || "").trim();
501
+ if (!o) return;
502
+ const i = String(t || "default"), a = this.#r.get(i) || [];
503
+ if (n === "one-at-a-time")
504
+ for (let s = a.length - 1; s >= 0; s -= 1) a[s].kind === e && a.splice(s, 1);
505
+ a.push({
506
+ kind: e,
507
+ text: o,
508
+ enqueuedAt: Date.now()
509
+ }), this.#r.set(i, a);
510
+ }
511
+ async savepoint(t, e, r) {
512
+ if (!t || typeof e != "number" || !Number.isFinite(e)) return;
513
+ const n = {
514
+ threadId: t,
515
+ turnIndex: e,
516
+ payload: r,
517
+ createdAt: Date.now()
518
+ };
519
+ try {
520
+ await ft(this.#e, "readwrite", (o) => {
521
+ o.put(n, lt(t, e));
522
+ });
523
+ } catch {
524
+ }
525
+ }
526
+ async restoreSavepoint(t, e) {
527
+ if (!t) return null;
528
+ try {
529
+ let r = null;
530
+ return await ft(this.#e, "readonly", (n) => {
531
+ const o = typeof e == "number" ? lt(t, e) : null;
532
+ if (o !== null) {
533
+ const i = n.get(o);
534
+ i.onsuccess = () => {
535
+ const a = i.result;
536
+ a && Date.now() - a.createdAt < Dt && (r = a);
537
+ };
538
+ } else {
539
+ const i = n.openCursor(null, "prev");
540
+ i.onsuccess = () => {
541
+ const a = i.result;
542
+ if (!a || r) return;
543
+ const s = a.value;
544
+ if (s.threadId !== t) {
545
+ a.continue();
546
+ return;
547
+ }
548
+ Date.now() - s.createdAt < Dt && (r = s);
549
+ };
550
+ }
551
+ }), r;
552
+ } catch {
553
+ return null;
554
+ }
555
+ }
556
+ async clearSavepoint(t, e) {
557
+ if (t)
558
+ try {
559
+ await ft(this.#e, "readwrite", (r) => {
560
+ if (typeof e == "number") {
561
+ r.delete(lt(t, e));
562
+ return;
563
+ }
564
+ const n = r.openCursor();
565
+ n.onsuccess = () => {
566
+ const o = n.result;
567
+ o && (o.value.threadId === t && o.delete(), o.continue());
568
+ };
569
+ });
570
+ } catch {
571
+ }
572
+ }
573
+ pruneExpired(t = Date.now()) {
574
+ if (!this.#c) return 0;
575
+ let e = 0;
576
+ for (const [r, n] of this.#i)
577
+ t - n <= this.#c || (this.#i.delete(r), this.#t.delete(r) && (e += 1));
578
+ return e;
579
+ }
580
+ #n(t, e) {
581
+ this.#t.delete(t), this.#t.set(t, e), this.#i.set(t, Date.now());
582
+ }
583
+ #m() {
584
+ if (this.#s)
585
+ for (; this.#t.size > this.#s; ) {
586
+ const t = this.#t.keys().next().value;
587
+ if (!t) return;
588
+ this.delete(t);
589
+ }
590
+ }
591
+ };
592
+ function lt(t, e) {
593
+ return `${t}|${e}`;
594
+ }
595
+ function rr() {
596
+ return (typeof self < "u" ? self : globalThis)?.indexedDB || null;
597
+ }
598
+ async function ft(t, e, r) {
599
+ const n = rr();
600
+ if (!n) return;
601
+ const o = `${tr}_${t}`;
602
+ await new Promise((i, a) => {
603
+ const s = n.open(o, er);
604
+ s.onupgradeneeded = () => {
605
+ const c = s.result;
606
+ c.objectStoreNames.contains(Y) || c.createObjectStore(Y);
607
+ }, s.onerror = () => a(s.error || /* @__PURE__ */ new Error("savepoint:open_failed")), s.onsuccess = () => {
608
+ const c = s.result;
609
+ try {
610
+ const u = c.transaction(Y, e);
611
+ r(u.objectStore(Y)), u.oncomplete = () => {
612
+ c.close(), i();
613
+ }, u.onerror = () => {
614
+ c.close(), a(u.error || /* @__PURE__ */ new Error("savepoint:tx_failed"));
615
+ }, u.onabort = () => {
616
+ c.close(), a(u.error || /* @__PURE__ */ new Error("savepoint:tx_aborted"));
617
+ };
618
+ } catch (u) {
619
+ c.close(), a(u instanceof Error ? u : new Error(String(u)));
620
+ }
621
+ };
622
+ });
623
+ }
624
+ function nr(t, e, r) {
625
+ if (!e.length || !w(t)) return;
626
+ const n = {};
627
+ for (const o of e) Object.prototype.hasOwnProperty.call(t, o) && (n[o] = ir(t[o], r[o]));
628
+ return n;
629
+ }
630
+ function or(t) {
631
+ const e = {};
632
+ for (const [r, n] of Object.entries(t || {})) {
633
+ const o = Math.floor(Number(n));
634
+ r && Number.isFinite(o) && o > 0 && (e[r] = o);
635
+ }
636
+ return e;
637
+ }
638
+ function dt(t) {
639
+ if (t === void 0) return;
640
+ const e = Math.floor(Number(t));
641
+ return Number.isFinite(e) && e > 0 ? e : void 0;
642
+ }
643
+ function ir(t, e) {
644
+ return !e || !Array.isArray(t) ? t : t.slice(-e);
645
+ }
646
+ function ar(t, e) {
647
+ if (!w(t) && !w(e)) return {};
648
+ const r = w(t) ? t : {}, n = vt(r, w(e) ? e : {});
649
+ return w(r.panel) && (n.panel = r.panel), n;
650
+ }
651
+ function sr(t, e, r) {
652
+ if (!w(e)) return t;
653
+ const n = vt(t, e, r);
654
+ return {
655
+ ...n,
656
+ panel: t.panel,
657
+ thread: {
658
+ ...n.thread,
659
+ id: t.thread.id,
660
+ started_at: t.thread.started_at
661
+ },
662
+ meta: {
663
+ ...n.meta,
664
+ accountId: t.meta.accountId
665
+ }
666
+ };
667
+ }
668
+ function vt(t, e, r) {
669
+ if (!w(e)) return t;
670
+ const n = t, o = e, i = w(n.panel) ? n.panel : {}, a = w(o.panel) ? o.panel : {}, s = w(n.thread) ? n.thread : {}, c = w(o.thread) ? o.thread : {}, u = w(s.extensions) ? s.extensions : {}, l = w(c.extensions) ? c.extensions : {}, f = w(n.meta) ? n.meta : {}, d = w(o.meta) ? o.meta : {};
671
+ return {
672
+ ...t,
673
+ ...e,
674
+ panel: {
675
+ ...i,
676
+ ...a
677
+ },
678
+ thread: {
679
+ ...s,
680
+ ...c,
681
+ extensions: {
682
+ ...u,
683
+ ...l
684
+ }
685
+ },
686
+ meta: {
687
+ ...f,
688
+ ...d
689
+ },
690
+ messages: Array.isArray(o.messages) ? rt(o.messages, r) : t.messages ?? []
691
+ };
692
+ }
693
+ function Xt(t) {
694
+ const e = String.fromCharCode(...t);
695
+ return btoa(e).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
696
+ }
697
+ function Ut(t) {
698
+ return Xt(new TextEncoder().encode(JSON.stringify(t)));
699
+ }
700
+ async function cr({ accountId: t, devJwtSecret: e, ttlS: r = 300 }) {
701
+ if (!e) throw new Error("devJwtSecret is required for local agent mode.");
702
+ const n = Math.floor(Date.now() / 1e3), o = `${Ut({
703
+ alg: "HS256",
704
+ typ: "JWT"
705
+ })}.${Ut({
706
+ sub: t,
707
+ iat: n,
708
+ exp: n + r,
709
+ scope: "invoke",
710
+ jti: crypto.randomUUID?.() || `${n}-${Math.random()}`
711
+ })}`, i = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
712
+ name: "HMAC",
713
+ hash: "SHA-256"
714
+ }, !1, ["sign"]), a = await crypto.subtle.sign("HMAC", i, new TextEncoder().encode(o));
715
+ return `${o}.${Xt(new Uint8Array(a))}`;
716
+ }
717
+ function ur({ accountId: t, devJwtSecret: e, tokenBrokerUrl: r, tokenBrokerAudience: n, refreshSkewS: o = 30, fetchImpl: i = fetch }) {
718
+ let a = null;
719
+ return async ({ signal: s, parentUrl: c } = {}) => {
720
+ if (e) return cr({
721
+ accountId: t,
722
+ devJwtSecret: e
723
+ });
724
+ if (!r) throw new Error("tokenBrokerUrl is required for production agent mode.");
725
+ const u = Math.floor(Date.now() / 1e3);
726
+ return a?.token && a.expiresAtS - o > u || (a = await lr({
727
+ accountId: t,
728
+ tokenBrokerUrl: r,
729
+ tokenBrokerAudience: n,
730
+ parentUrl: c,
731
+ signal: s,
732
+ fetchImpl: i
733
+ })), a.token;
734
+ };
735
+ }
736
+ async function lr({ accountId: t, tokenBrokerUrl: e, tokenBrokerAudience: r, parentUrl: n, signal: o, fetchImpl: i }) {
737
+ const a = await i(e, {
738
+ method: "POST",
739
+ credentials: "include",
740
+ headers: {
741
+ accept: "application/json",
742
+ "content-type": "application/json"
743
+ },
744
+ body: JSON.stringify({
745
+ accountId: t,
746
+ scope: "invoke",
747
+ audience: r || void 0,
748
+ parentUrl: n || void 0
749
+ }),
750
+ ...o ? { signal: o } : {}
751
+ });
752
+ if (!a.ok) throw new Error(`Token broker request failed (${a.status}).`);
753
+ const s = await a.json(), c = s?.token || s?.jwt || s?.access_token;
754
+ if (!c || typeof c != "string") throw new Error("Token broker response did not include a JWT.");
755
+ return {
756
+ token: c,
757
+ expiresAtS: fr(s) || dr(c) || Math.floor(Date.now() / 1e3) + 300
758
+ };
759
+ }
760
+ function fr(t) {
761
+ const e = t?.expiresAtS ?? t?.expires_at_s ?? t?.expiresInS ?? t?.expires_in_s;
762
+ if (Number.isFinite(e)) return Number(e);
763
+ const r = t?.expiresIn ?? t?.expires_in;
764
+ if (Number.isFinite(r)) return Math.floor(Date.now() / 1e3) + Number(r);
765
+ const n = t?.expiresAt ?? t?.expires_at;
766
+ if (typeof n == "string") {
767
+ const o = Date.parse(n);
768
+ if (Number.isFinite(o)) return Math.floor(o / 1e3);
769
+ }
770
+ return null;
771
+ }
772
+ function dr(t) {
773
+ try {
774
+ const [, e] = t.split(".");
775
+ if (!e) return null;
776
+ const r = e.replace(/-/gu, "+").replace(/_/gu, "/"), n = atob(r.padEnd(Math.ceil(r.length / 4) * 4, "=")), o = JSON.parse(n);
777
+ return Number.isFinite(o?.exp) ? Number(o.exp) : null;
778
+ } catch {
779
+ return null;
780
+ }
781
+ }
782
+ var zt = {
783
+ unauthorized: {
784
+ code: "auth",
785
+ message: "Assistant authentication failed. Please retry."
786
+ },
787
+ forbidden: {
788
+ code: "auth",
789
+ message: "Assistant authentication failed. Please retry."
790
+ },
791
+ unknown_op: {
792
+ code: "op_unavailable",
793
+ message: "This assistant action is not available yet."
794
+ },
795
+ invalid_input: {
796
+ code: "invalid_request",
797
+ message: "The assistant request was not valid."
798
+ },
799
+ account_config: {
800
+ code: "account_config",
801
+ message: "Assistant configuration is unavailable."
802
+ },
803
+ upstream_llm: {
804
+ code: "op_failed",
805
+ message: "The assistant could not complete that request."
806
+ },
807
+ upstream_timeout: {
808
+ code: "op_timeout",
809
+ message: "The assistant took too long to respond."
810
+ },
811
+ schema_mismatch: {
812
+ code: "op_failed",
813
+ message: "The assistant could not complete that request."
814
+ },
815
+ rate_limited: {
816
+ code: "rate_limited",
817
+ message: "The assistant is receiving too many requests. Please retry shortly."
818
+ },
819
+ internal: {
820
+ code: "op_failed",
821
+ message: "The assistant could not complete that request."
822
+ },
823
+ payload_too_large: {
824
+ code: "invalid_request",
825
+ message: "The assistant request was too large."
826
+ }
827
+ }, x = class extends Error {
828
+ constructor(t, e, r = {}) {
829
+ 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);
830
+ }
831
+ };
832
+ function te(t) {
833
+ const e = String(t?.code || "upstream_llm"), r = zt[e] || zt.upstream_llm;
834
+ return new x(r.code, r.message, {
835
+ source: "be",
836
+ sourceCode: e,
837
+ detail: t?.detail
838
+ });
839
+ }
840
+ function pr(t, e) {
841
+ const r = e?.error && typeof e.error == "object" ? e.error : {};
842
+ return te({
843
+ code: String(r.code || mr(t)),
844
+ detail: r.detail
845
+ });
846
+ }
847
+ function wo(t) {
848
+ return t instanceof x ? {
849
+ type: "error",
850
+ code: t.code,
851
+ message: t.message
852
+ } : {
853
+ type: "error",
854
+ code: "agent_invoke_failed",
855
+ message: "The assistant could not complete that request."
856
+ };
857
+ }
858
+ function mr(t) {
859
+ return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 413 ? "payload_too_large" : t === 429 ? "rate_limited" : "internal";
860
+ }
861
+ async function bo(t) {
862
+ const { beUrl: e, accountId: r, devJwtSecret: n, tokenBrokerUrl: o, tokenBrokerAudience: i, jwtProvider: a, parentUrl: s, op: c, input: u, cacheTtlS: l, cacheKey: f, browserCache: d, signal: p, interceptors: m } = t, h = await (a || ur({
863
+ accountId: r,
864
+ devJwtSecret: n,
865
+ tokenBrokerUrl: o,
866
+ tokenBrokerAudience: i
867
+ }))({
868
+ ...p ? { signal: p } : {},
869
+ ...s ? { parentUrl: s } : {}
870
+ }), { opDomain: C, opName: $ } = yr(c, r);
871
+ let R = {
872
+ method: "POST",
873
+ headers: {
874
+ authorization: `Bearer ${h}`,
875
+ "content-type": "application/json",
876
+ accept: "application/x-ndjson"
877
+ },
878
+ body: JSON.stringify({
879
+ op_domain: C,
880
+ op_name: $,
881
+ op_payload: u,
882
+ ...l !== void 0 ? { cache_ttl_s: l } : {},
883
+ ...f !== void 0 ? { cache_key: f } : {}
884
+ }),
885
+ ...p ? { signal: p } : {}
886
+ };
887
+ const L = `${String(e).replace(/\/+$/u, "")}/v1/execute`;
888
+ if (m?.beforeRequest) {
889
+ const k = await m.beforeRequest(t, {
890
+ url: L,
891
+ init: R
892
+ });
893
+ if (k && "cached" in k && k.cached !== void 0) return k.cached;
894
+ k?.init && (R = k.init);
895
+ }
896
+ const M = d === !1 ? await fetch(L, R) : await xe(L, R, typeof d == "object" ? d : {});
897
+ if (!M.ok) throw pr(M.status, await hr(M));
898
+ let N = await wr(M);
899
+ if (m?.afterResponse) {
900
+ const k = await m.afterResponse(t, N);
901
+ k && "result" in k && k.result !== void 0 && (N = k.result);
902
+ }
903
+ return N;
904
+ }
905
+ function yr(t, e) {
906
+ if (!t || t.startsWith("-") || t.endsWith("-")) throw new Error(`Invalid BE op name: ${t}`);
907
+ return {
908
+ opDomain: gr(e),
909
+ opName: t
910
+ };
911
+ }
912
+ function gr(t) {
913
+ return t.replace(/-agentic$/u, "");
914
+ }
915
+ async function hr(t) {
916
+ try {
917
+ return await t.json();
918
+ } catch {
919
+ return { error: { code: t.statusText || "internal" } };
920
+ }
921
+ }
922
+ async function wr(t) {
923
+ const e = t.body?.getReader();
924
+ if (!e) throw new Error("BE response body is not readable.");
925
+ const r = new TextDecoder();
926
+ let n = "";
927
+ const o = {};
928
+ for (; ; ) {
929
+ const { value: a, done: s } = await e.read();
930
+ if (s) break;
931
+ n += r.decode(a, { stream: !0 });
932
+ let c = n.indexOf(`
933
+ `);
934
+ for (; c >= 0; ) {
935
+ const u = n.slice(0, c).trim();
936
+ n = n.slice(c + 1), u && Vt(JSON.parse(u), o), c = n.indexOf(`
937
+ `);
938
+ }
939
+ }
940
+ const i = n.trim();
941
+ return i && Vt(JSON.parse(i), o), o;
942
+ }
943
+ function Vt(t, e) {
944
+ if (t._error) throw te(t._error);
945
+ if (!t._end)
946
+ for (const [r, n] of Object.entries(t)) {
947
+ if (Object.prototype.hasOwnProperty.call(e, r)) throw new x("op_failed", `BE streamed duplicate field "${r}".`, {
948
+ source: "be",
949
+ sourceCode: "schema_mismatch"
950
+ });
951
+ e[r] = n;
952
+ }
953
+ }
954
+ function ko(t = {}) {
955
+ return {
956
+ type: "metadata",
957
+ ...t
958
+ };
959
+ }
960
+ function br(t, e = !1, r = {}) {
961
+ return {
962
+ type: "text_chunk",
963
+ content: t,
964
+ final: e,
965
+ ...r
966
+ };
967
+ }
968
+ function _o(t) {
969
+ return {
970
+ type: "ui_spec",
971
+ ...t
972
+ };
973
+ }
974
+ function Ao(t) {
975
+ return {
976
+ type: "action",
977
+ action: t
978
+ };
979
+ }
980
+ function kr(t, e) {
981
+ return {
982
+ type: "error",
983
+ code: t,
984
+ message: e
985
+ };
986
+ }
987
+ function ee() {
988
+ return { type: "done" };
989
+ }
990
+ function _r(t, e) {
991
+ return t[e?.type || e?.action?.type || "inputText"] || t.inputText;
992
+ }
993
+ function re(t) {
994
+ return t && typeof t == "object" && !Array.isArray(t) ? t : null;
995
+ }
996
+ function Ct(t, e = {}) {
997
+ const r = re(t);
998
+ if (!r) return null;
999
+ const n = e.catalogMapper?.(r);
1000
+ if (n) return n;
1001
+ const o = F(r.sku, r.SKU);
1002
+ if (!o) return null;
1003
+ const i = {
1004
+ sku: o,
1005
+ name: F(r.name, r.title, r.short_name, o) || o,
1006
+ url: F(r.url) || ""
1007
+ }, a = Array.isArray(r.images) ? r.images : void 0, s = F(r.imageUrl, r.image_url, r.image, a?.[0]);
1008
+ s && (i.imageUrl = s), a && a.length > 1 && (i.images = a.filter(($) => !!$).map(String));
1009
+ const c = V(r.price_discounted), u = V(r.price), l = c || u;
1010
+ l > 0 && (i.price = String(l));
1011
+ const f = c > 0 ? u : 0;
1012
+ f > 0 && (i.originalPrice = String(f));
1013
+ const d = F(r.brand);
1014
+ d && (i.brand = d);
1015
+ const p = V(r.rating);
1016
+ p > 0 && (i.rating = p);
1017
+ const m = V(r.review_count) || V(r.reviewCount);
1018
+ m > 0 && (i.reviewCount = m);
1019
+ const h = F(r.cart_code, r.cartCode);
1020
+ h && (i.cartCode = h), typeof r.in_stock == "boolean" && (i.inStock = r.in_stock), typeof r.inStock == "boolean" && (i.inStock = r.inStock);
1021
+ const C = r.category_names;
1022
+ return Array.isArray(C) && (i.categoryNames = C.map(String)), i;
1023
+ }
1024
+ function Tt(t) {
1025
+ const e = re(t);
1026
+ if (!e) return t;
1027
+ const r = e.category_names, n = Array.isArray(r) ? r : void 0, o = e.images, i = Array.isArray(o) ? o : void 0, a = {
1028
+ sku: e.sku,
1029
+ name: e.name || e.title,
1030
+ url: e.url,
1031
+ price: e.price,
1032
+ currency: e.price_currency || e.currency,
1033
+ category: n?.[n.length - 1] ?? void 0,
1034
+ category_names: n ? n.slice(0, 4) : void 0,
1035
+ image: i ? i[0] : e.image,
1036
+ in_stock: e.in_stock,
1037
+ rating: e.rating,
1038
+ review_count: e.review_count
1039
+ };
1040
+ for (const s of Object.keys(a)) a[s] === void 0 && delete a[s];
1041
+ return a;
1042
+ }
1043
+ function So(t) {
1044
+ return Array.isArray(t) ? t.map(Tt).filter((e) => !!e) : [];
1045
+ }
1046
+ function F(...t) {
1047
+ for (const e of t) if (typeof e == "string" && e.trim()) return e.trim();
1048
+ return "";
1049
+ }
1050
+ function V(t) {
1051
+ const e = Number(t);
1052
+ return Number.isFinite(e) ? e : 0;
1053
+ }
1054
+ function Kt(t) {
1055
+ return Array.isArray(t) ? t.map(String).filter(Boolean) : typeof t == "string" && t ? [t] : [];
1056
+ }
1057
+ function ne(t, e, r = {}) {
1058
+ return `${t}:${r.version || "v2"}:${oe(e)}`;
1059
+ }
1060
+ function xo(t, e = {}) {
1061
+ return ie(t).map((r) => ae(typeof r == "string" ? r : r.sku, e.locale)).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n).sort((r, n) => Et(r, n, e.locale)).slice(0, e.limit || 16).join(",");
1062
+ }
1063
+ function vo(t, e = {}) {
1064
+ return oe(ie(t).map((r) => Ar(r, e)).filter((r) => !!r).sort((r, n) => Et(String(r.sku || r.name || ""), String(n.sku || n.name || ""), e.locale)).slice(0, e.limit || 16));
1065
+ }
1066
+ function Co(t, e) {
1067
+ return j(t, e);
1068
+ }
1069
+ function oe(t) {
1070
+ let e = 2166136261;
1071
+ const r = Sr(t);
1072
+ for (let n = 0; n < r.length; n += 1)
1073
+ e ^= r.charCodeAt(n), e = Math.imul(e, 16777619);
1074
+ return (e >>> 0).toString(36);
1075
+ }
1076
+ function Ar(t, e) {
1077
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
1078
+ const r = t, n = e.mapProduct?.(r);
1079
+ if (n) return J(n);
1080
+ const o = Tt(r);
1081
+ return o && typeof o == "object" && !Array.isArray(o) ? J(xr(o, e)) : null;
1082
+ }
1083
+ function ie(t) {
1084
+ return Array.isArray(t) ? t.filter((e) => typeof e == "string" || !!(e && typeof e == "object" && !Array.isArray(e))) : [];
1085
+ }
1086
+ function Sr(t) {
1087
+ return JSON.stringify(J(t));
1088
+ }
1089
+ function J(t) {
1090
+ return Array.isArray(t) ? t.map(J) : !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, J(r)]));
1091
+ }
1092
+ function xr(t, e) {
1093
+ return {
1094
+ sku: ae(t.sku, e.locale),
1095
+ name: j(t.name, e.locale),
1096
+ url: j(t.url, e.locale),
1097
+ price: t.price,
1098
+ currency: j(t.currency, e.locale),
1099
+ category: j(t.category, e.locale),
1100
+ category_names: vr(t.category_names, e.locale, 16),
1101
+ image: j(t.image, e.locale),
1102
+ in_stock: t.in_stock,
1103
+ rating: t.rating,
1104
+ review_count: t.review_count
1105
+ };
1106
+ }
1107
+ function ae(t, e) {
1108
+ return j(t, e).toUpperCase();
1109
+ }
1110
+ function j(t, e) {
1111
+ return typeof t == "string" ? t.trim().replace(/\s+/gu, " ").toLocaleLowerCase(e || void 0) : "";
1112
+ }
1113
+ function Et(t, e, r) {
1114
+ return t.localeCompare(e, r, { numeric: !0 });
1115
+ }
1116
+ function vr(t, e, r) {
1117
+ return Array.isArray(t) ? t.map((n) => j(n, e)).filter(Boolean).sort((n, o) => Et(n, o, e)).slice(0, r) : void 0;
1118
+ }
1119
+ function Cr(t, e) {
1120
+ if (!t) return { ok: !0 };
1121
+ const r = [];
1122
+ return ht(t, e, "", r), r.length ? {
1123
+ ok: !1,
1124
+ error: r[0] || "invalid"
1125
+ } : { ok: !0 };
1126
+ }
1127
+ function ht(t, e, r, n) {
1128
+ if (t) {
1129
+ if (Array.isArray(t.enum) && !t.enum.includes(e)) {
1130
+ n.push(`${r || "value"} must be one of [${t.enum.join(", ")}]`);
1131
+ return;
1132
+ }
1133
+ switch (t.type) {
1134
+ case "string":
1135
+ if (typeof e != "string") {
1136
+ n.push(`${r || "value"} must be a string`);
1137
+ return;
1138
+ }
1139
+ t.minLength && e.length < t.minLength && n.push(`${r || "value"} must be at least ${t.minLength} chars`);
1140
+ return;
1141
+ case "number":
1142
+ if (typeof e != "number" || !Number.isFinite(e)) {
1143
+ n.push(`${r || "value"} must be a number`);
1144
+ return;
1145
+ }
1146
+ t.minimum != null && e < t.minimum && n.push(`${r || "value"} must be >= ${t.minimum}`), t.maximum != null && e > t.maximum && n.push(`${r || "value"} must be <= ${t.maximum}`);
1147
+ return;
1148
+ case "boolean":
1149
+ typeof e != "boolean" && n.push(`${r || "value"} must be a boolean`);
1150
+ return;
1151
+ case "array":
1152
+ if (!Array.isArray(e)) {
1153
+ n.push(`${r || "value"} must be an array`);
1154
+ return;
1155
+ }
1156
+ if (t.minItems != null && e.length < t.minItems && n.push(`${r || "value"} must have >= ${t.minItems} items`), t.maxItems != null && e.length > t.maxItems && n.push(`${r || "value"} must have <= ${t.maxItems} items`), t.items) {
1157
+ for (let o = 0; o < e.length; o += 1)
1158
+ if (ht(t.items, e[o], `${r}[${o}]`, n), n.length) return;
1159
+ }
1160
+ return;
1161
+ case "object":
1162
+ if (!e || typeof e != "object" || Array.isArray(e)) {
1163
+ n.push(`${r || "value"} must be an object`);
1164
+ return;
1165
+ }
1166
+ if (Array.isArray(t.required)) for (const o of t.required) {
1167
+ const i = e[o];
1168
+ if (i == null || i === "") {
1169
+ n.push(`${r ? `${r}.` : ""}${o} is required`);
1170
+ return;
1171
+ }
1172
+ }
1173
+ if (t.properties) for (const [o, i] of Object.entries(t.properties)) {
1174
+ const a = e[o];
1175
+ if (a !== void 0 && (ht(i, a, r ? `${r}.${o}` : o, n), n.length))
1176
+ return;
1177
+ }
1178
+ return;
1179
+ default:
1180
+ return;
1181
+ }
1182
+ }
1183
+ }
1184
+ async function To({ request: t, accountModule: e, contextStore: r, beClient: n, toolBridge: o, emit: i, rpc: a, signal: s }) {
1185
+ const c = performance.now(), u = await r.load(t), l = u.thread.id, f = Wr(t);
1186
+ qr(u, f) && r.appendUserMessage(l, f);
1187
+ const d = _r(e.flows, t);
1188
+ if (!d)
1189
+ return i(kr("unknown_action", `No agent flow for request type ${t?.type || "inputText"}`)), i(ee()), {
1190
+ steps: 0,
1191
+ productSkusEmitted: []
1192
+ };
1193
+ const p = {
1194
+ request: t,
1195
+ context: r.patch(l, {}) || u,
1196
+ bag: {},
1197
+ accountConfig: e.accountConfig || {},
1198
+ threadId: l,
1199
+ steps: 0,
1200
+ productSkusEmitted: /* @__PURE__ */ new Set(),
1201
+ committed: !1,
1202
+ messageLimit: Zr(e.contextPersistence?.messageLimit),
1203
+ catalogMapper: e.catalogMapper,
1204
+ similarityMapper: e.similarityMapper
1205
+ }, m = {
1206
+ contextStore: r,
1207
+ beClient: n,
1208
+ toolBridge: o,
1209
+ emit: i,
1210
+ rpc: a,
1211
+ adapters: e.adapters || {},
1212
+ ...s ? { signal: s } : {},
1213
+ ...e.trace ? { trace: e.trace } : {},
1214
+ ...e.hooks ? { hooks: e.hooks } : {}
1215
+ };
1216
+ await I(m, H("turn:start", p));
1217
+ try {
1218
+ await D(d, p, m), p.committed || await Pt(p, m);
1219
+ } catch (h) {
1220
+ throw await I(m, {
1221
+ ...H("turn:error", p),
1222
+ latencyMs: P(c),
1223
+ errorCode: jt(h)
1224
+ }), h;
1225
+ }
1226
+ return await a("beacon.send", {
1227
+ type: "turnSummary",
1228
+ threadId: l,
1229
+ sessionId: t?.session_id || t?.sessionId || l,
1230
+ accountId: e.accountId || p.context.meta.accountId,
1231
+ steps: p.steps,
1232
+ totalLatencyMs: P(c),
1233
+ productSkusEmitted: [...p.productSkusEmitted]
1234
+ }), await I(m, {
1235
+ ...H("turn:end", p),
1236
+ latencyMs: P(c)
1237
+ }), {
1238
+ steps: p.steps,
1239
+ productSkusEmitted: [...p.productSkusEmitted]
1240
+ };
1241
+ }
1242
+ async function D(t, e, r) {
1243
+ for (const n of t) {
1244
+ if (r.signal?.aborted || e.committed) return;
1245
+ e.steps += 1;
1246
+ const o = e.steps, i = performance.now();
1247
+ await I(r, pt("step:start", e, n, o));
1248
+ try {
1249
+ await Tr(n, e, r), await I(r, {
1250
+ ...pt("step:end", e, n, o),
1251
+ latencyMs: P(i)
1252
+ });
1253
+ } catch (a) {
1254
+ throw await I(r, {
1255
+ ...pt("step:error", e, n, o),
1256
+ latencyMs: P(i),
1257
+ errorCode: jt(a)
1258
+ }), a;
1259
+ }
1260
+ e.context = r.contextStore.patch(e.threadId, {}) || e.context;
1261
+ }
1262
+ }
1263
+ async function Tr(t, e, r) {
1264
+ if (r.hooks?.transformContext) {
1265
+ const o = await r.hooks.transformContext(e.context);
1266
+ o && (e.context = o);
1267
+ }
1268
+ const n = q(e, r);
1269
+ if (t.kind === "be_op") {
1270
+ await Er(t, e, r, n);
1271
+ return;
1272
+ }
1273
+ if (t.kind === "tool") {
1274
+ await jr(t, e, r, n);
1275
+ return;
1276
+ }
1277
+ if (t.kind === "adapter") {
1278
+ await Or(t, e, r, n);
1279
+ return;
1280
+ }
1281
+ if (t.kind === "emit") {
1282
+ await Rr(t, e, r);
1283
+ return;
1284
+ }
1285
+ if (t.kind === "patch") {
1286
+ await Mr(t, e, r);
1287
+ return;
1288
+ }
1289
+ if (t.kind === "branch") {
1290
+ await Br(t, e, r, n);
1291
+ return;
1292
+ }
1293
+ if (t.kind === "agent_loop") {
1294
+ await $r(t, e, r, n);
1295
+ return;
1296
+ }
1297
+ if (t.kind === "parallel") {
1298
+ await Lr(t, e, r);
1299
+ return;
1300
+ }
1301
+ if (t.kind === "refusal") {
1302
+ await Nr(t, e, r, n);
1303
+ return;
1304
+ }
1305
+ t.kind === "commit" && await Fr(t, e, r);
1306
+ }
1307
+ async function Er(t, e, r, n) {
1308
+ const o = performance.now();
1309
+ let i;
1310
+ try {
1311
+ let s = await _(t.input, n);
1312
+ if (r.hooks?.beforeBeOp) {
1313
+ const c = await r.hooks.beforeBeOp(t.op, s, n);
1314
+ c && "cached" in c && c.cached !== void 0 ? i = c.cached : c && "input" in c && c.input !== void 0 && (s = c.input);
1315
+ }
1316
+ if (i === void 0) {
1317
+ const c = await _(t.cache, n), u = Pr(t, e, s, c), l = await _(t.cacheTtlS, n) ?? u.cacheTtlS, f = await _(t.cacheKey, n) ?? u.cacheKey, d = await _(t.browserCache, n), p = Z(await _(t.timeoutMs, n));
1318
+ await It(t, e, r, n);
1319
+ const m = p ? new AbortController() : null, h = se(r.signal, m?.signal);
1320
+ i = await ot(r.beClient.invoke({
1321
+ op: t.op,
1322
+ input: s,
1323
+ ...l !== void 0 ? { cacheTtlS: l } : {},
1324
+ ...f !== void 0 ? { cacheKey: f } : {},
1325
+ ...d !== void 0 ? { browserCache: d } : {},
1326
+ ...h ? { signal: h } : {}
1327
+ }), p, () => new x("op_timeout", "The assistant took too long to respond.", {
1328
+ source: "be",
1329
+ sourceCode: "timeout"
1330
+ }), () => m?.abort());
1331
+ }
1332
+ if (r.hooks?.afterBeOp) {
1333
+ const c = await r.hooks.afterBeOp(t.op, i, n);
1334
+ c && "result" in c && c.result !== void 0 && (i = c.result);
1335
+ }
1336
+ } catch (s) {
1337
+ const c = s, u = String(c?.sourceCode || c?.code || "unknown"), l = {
1338
+ type: "agentOp",
1339
+ threadId: e.threadId,
1340
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
1341
+ accountId: e.context.meta.accountId,
1342
+ op: t.op,
1343
+ status: "error",
1344
+ latencyMs: P(o),
1345
+ errorCode: u
1346
+ };
1347
+ if (await r.rpc("beacon.send", l), t.onError) {
1348
+ t.errorOut && (e.bag[t.errorOut] = s), await D(t.onError, e, r);
1349
+ return;
1350
+ }
1351
+ throw s;
1352
+ }
1353
+ t.out && (e.bag[t.out] = i), await nt(t, i, e, r.contextStore);
1354
+ const a = {
1355
+ type: "agentOp",
1356
+ threadId: e.threadId,
1357
+ sessionId: e.request?.session_id || e.request?.sessionId || e.threadId,
1358
+ accountId: e.context.meta.accountId,
1359
+ op: t.op,
1360
+ status: "ok",
1361
+ latencyMs: P(o)
1362
+ };
1363
+ await r.rpc("beacon.send", a);
1364
+ }
1365
+ function Pr(t, e, r, n) {
1366
+ if (!n || n.strategy !== "input-hash") return {};
1367
+ const o = Z(n.ttlS);
1368
+ if (!o) return {};
1369
+ const i = e.context.meta.locale, a = n.promptVersion || Ir(r) || "current";
1370
+ return {
1371
+ cacheTtlS: o,
1372
+ cacheKey: ne(t.op, {
1373
+ account: e.context.meta.accountId,
1374
+ locale: i,
1375
+ promptVersion: a,
1376
+ payload: r
1377
+ }, { version: "input-hash" })
1378
+ };
1379
+ }
1380
+ function Ir(t) {
1381
+ if (!t || typeof t != "object" || Array.isArray(t)) return;
1382
+ const e = t, r = e.prompt_version || e.promptVersion;
1383
+ return typeof r == "string" && r.trim() ? r.trim() : void 0;
1384
+ }
1385
+ async function jr(t, e, r, n) {
1386
+ const o = performance.now();
1387
+ try {
1388
+ await It(t, e, r, n);
1389
+ const i = Z(await _(t.timeoutMs, n));
1390
+ let a = await _(t.input, n);
1391
+ if (r.hooks?.beforeToolCall) {
1392
+ const c = await r.hooks.beforeToolCall(t.name, a, n);
1393
+ if (c?.block) throw new x("tool_blocked", c.reason || `Tool '${t.name}' blocked by hook.`, {
1394
+ source: "tool",
1395
+ sourceCode: "blocked"
1396
+ });
1397
+ c && "args" in c && c.args !== void 0 && (a = c.args);
1398
+ }
1399
+ if (t.parameters) {
1400
+ const c = Cr(t.parameters, a);
1401
+ if (!c.ok) throw new x("tool_invalid_args", `Invalid args for tool '${t.name}': ${c.error}`, {
1402
+ source: "tool",
1403
+ sourceCode: "invalid_args"
1404
+ });
1405
+ }
1406
+ let s = await ot(r.toolBridge.invoke(t.name, a), i, () => new x("tool_timeout", "The assistant tool took too long to respond.", {
1407
+ source: "tool",
1408
+ sourceCode: "timeout"
1409
+ }));
1410
+ if (r.hooks?.afterToolCall) {
1411
+ const c = await r.hooks.afterToolCall(t.name, s, n);
1412
+ c && "result" in c && c.result !== void 0 && (s = c.result), c?.terminate && (e.committed = !0);
1413
+ }
1414
+ t.out && (e.bag[t.out] = s), await nt(t, s, e, r.contextStore), await r.rpc("beacon.send", {
1415
+ type: "agentTool",
1416
+ threadId: e.threadId,
1417
+ sessionId: tt(e),
1418
+ accountId: e.context.meta.accountId,
1419
+ tool: t.name,
1420
+ status: "ok",
1421
+ latencyMs: P(o)
1422
+ });
1423
+ } catch (i) {
1424
+ const a = i;
1425
+ if (await r.rpc("beacon.send", {
1426
+ type: "agentTool",
1427
+ threadId: e.threadId,
1428
+ sessionId: tt(e),
1429
+ accountId: e.context.meta.accountId,
1430
+ tool: t.name,
1431
+ status: "error",
1432
+ latencyMs: P(o),
1433
+ errorCode: String(a?.code || a?.name || "unknown")
1434
+ }), t.onError) {
1435
+ t.errorOut && (e.bag[t.errorOut] = i), await D(t.onError, e, r);
1436
+ return;
1437
+ }
1438
+ throw i;
1439
+ }
1440
+ }
1441
+ async function Or(t, e, r, n) {
1442
+ const o = r.adapters?.[t.name];
1443
+ if (typeof o != "function") throw new Error(`Unknown flow adapter: ${t.name}`);
1444
+ await It(t, e, r, n);
1445
+ const i = Z(await _(t.timeoutMs, n)), a = await ot(o(await _(t.input, n), n), i, () => new x("adapter_timeout", "The assistant adapter took too long to respond.", {
1446
+ source: "adapter",
1447
+ sourceCode: "timeout"
1448
+ }));
1449
+ t.out && (e.bag[t.out] = a), await nt(t, a, e, r.contextStore);
1450
+ }
1451
+ async function Rr(t, e, r) {
1452
+ const n = await t.build(q(e, r));
1453
+ Gr(n, e.productSkusEmitted), r.emit(n);
1454
+ }
1455
+ async function Mr(t, e, r) {
1456
+ await nt(t, void 0, e, r.contextStore);
1457
+ }
1458
+ async function Br(t, e, r, n) {
1459
+ const o = String(await _(t.on, n) || "default");
1460
+ await D(t.cases[o] || t.cases.default || [], e, r);
1461
+ }
1462
+ async function $r(t, e, r, n) {
1463
+ if (!await t.shouldContinue(e.bag, n)) return;
1464
+ const o = Math.max(0, Math.floor(Number(t.maxIterations) || 0));
1465
+ let i = 0;
1466
+ for (; !r.signal?.aborted && !e.committed; ) {
1467
+ if (await D(t.body, e, r), r.signal?.aborted || e.committed || !await t.shouldContinue(e.bag, q(e, r)) || i >= o) return;
1468
+ const a = await t.onIterate?.(e.bag, q(e, r));
1469
+ a && typeof a == "object" && Object.assign(e.bag, a), i += 1;
1470
+ }
1471
+ }
1472
+ async function Lr(t, e, r) {
1473
+ const n = Z(await _(t.timeoutMs, q(e, r))), o = n ? new AbortController() : null, i = se(r.signal, o?.signal), a = t.steps.map((u) => {
1474
+ const l = {
1475
+ ...e,
1476
+ context: Dr(e.context),
1477
+ bag: wt(e.bag),
1478
+ productSkusEmitted: new Set(e.productSkusEmitted),
1479
+ committed: !1
1480
+ }, f = [];
1481
+ return D(u, l, {
1482
+ ...r,
1483
+ emit: (d) => {
1484
+ !i?.aborted && d.type !== "done" && f.push(d);
1485
+ },
1486
+ contextStore: Ur(l),
1487
+ ...i ? { signal: i } : {}
1488
+ }).then(() => ({
1489
+ state: l,
1490
+ events: f
1491
+ }));
1492
+ }), s = await ot(Promise.all(a), n, () => new x("parallel_timeout", "The assistant parallel step took too long to respond.", {
1493
+ source: "agent",
1494
+ sourceCode: "timeout"
1495
+ }), () => o?.abort()), c = t.merge || {};
1496
+ for (const { state: u, events: l } of s) {
1497
+ for (const f of l) r.emit(f);
1498
+ for (const f of u.productSkusEmitted) e.productSkusEmitted.add(f);
1499
+ for (const f of c.bag || []) Object.prototype.hasOwnProperty.call(u.bag, f) && (e.bag[f] = u.bag[f]);
1500
+ if (c.panel?.length) {
1501
+ const f = Ht(u.context.panel, c.panel);
1502
+ Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { panel: f }) || e.context);
1503
+ }
1504
+ if (c.threadExtensions?.length) {
1505
+ const f = Ht(u.context.thread.extensions, c.threadExtensions);
1506
+ Object.keys(f).length && (e.context = r.contextStore.patch(e.threadId, { thread: {
1507
+ ...e.context.thread,
1508
+ extensions: f
1509
+ } }) || e.context);
1510
+ }
1511
+ }
1512
+ }
1513
+ async function Nr(t, e, r, n) {
1514
+ r.emit(br(await _(t.message, n), !0)), await Pt(e, r);
1515
+ }
1516
+ async function Fr(t, e, r) {
1517
+ await Pt(e, r);
1518
+ }
1519
+ async function Pt(t, { contextStore: e, emit: r }) {
1520
+ t.committed || (t.context = await e.commit(t.threadId) || t.context, t.committed = !0, r(ee()));
1521
+ }
1522
+ async function nt(t, e, r, n) {
1523
+ if (typeof t.patch != "function") return;
1524
+ const o = await t.patch(r.context, e, q(r));
1525
+ o && (r.context = n.patch(r.threadId, o) || r.context);
1526
+ }
1527
+ function q(t, e) {
1528
+ return {
1529
+ request: t.request,
1530
+ context: t.context,
1531
+ bag: t.bag,
1532
+ accountConfig: t.accountConfig,
1533
+ catalogMapper: t.catalogMapper,
1534
+ similarityMapper: t.similarityMapper,
1535
+ ...e ? {
1536
+ beClient: e.beClient,
1537
+ toolBridge: e.toolBridge
1538
+ } : {},
1539
+ ...e?.signal ? { signal: e.signal } : {}
1540
+ };
1541
+ }
1542
+ function tt(t) {
1543
+ return t.request?.session_id || t.request?.sessionId || t.threadId;
1544
+ }
1545
+ function qr(t, e) {
1546
+ if (!e) return !1;
1547
+ const r = t.messages[t.messages.length - 1];
1548
+ return r?.role !== "user" || r.content !== e;
1549
+ }
1550
+ function Ht(t, e) {
1551
+ const r = {};
1552
+ for (const n of e) Object.prototype.hasOwnProperty.call(t, n) && (r[n] = t[n]);
1553
+ return r;
1554
+ }
1555
+ function Dr(t) {
1556
+ return {
1557
+ ...t,
1558
+ panel: wt(t.panel || {}),
1559
+ thread: {
1560
+ ...t.thread,
1561
+ extensions: wt(t.thread?.extensions || {})
1562
+ },
1563
+ meta: t.meta,
1564
+ messages: t.messages
1565
+ };
1566
+ }
1567
+ function Ur(t) {
1568
+ return {
1569
+ async load() {
1570
+ return t.context;
1571
+ },
1572
+ patch(e, r) {
1573
+ return t.context = zr(t.context, r, t.messageLimit), t.context;
1574
+ },
1575
+ appendUserMessage() {
1576
+ return t.context;
1577
+ },
1578
+ async commit() {
1579
+ return t.context;
1580
+ }
1581
+ };
1582
+ }
1583
+ function zr(t, e, r) {
1584
+ if (!e || typeof e != "object") return t;
1585
+ const n = Jt(t.panel, e.panel), o = Jt(t.thread?.extensions || {}, e.thread?.extensions);
1586
+ return {
1587
+ ...t,
1588
+ ...e,
1589
+ panel: n,
1590
+ thread: {
1591
+ ...t.thread || {},
1592
+ ...e.thread || {},
1593
+ extensions: o
1594
+ },
1595
+ meta: {
1596
+ ...t.meta || {},
1597
+ ...e.meta || {}
1598
+ },
1599
+ messages: Array.isArray(e.messages) ? rt(e.messages, r) : t.messages
1600
+ };
1601
+ }
1602
+ function Jt(t, e) {
1603
+ if (!e || typeof e != "object" || Array.isArray(e)) return t;
1604
+ const r = {};
1605
+ for (const n of Object.keys(t)) r[n] = t[n];
1606
+ for (const [n, o] of Object.entries(e)) r[n] = o;
1607
+ return r;
1608
+ }
1609
+ function wt(t) {
1610
+ return new Proxy({}, {
1611
+ get(e, r, n) {
1612
+ if (typeof r != "string") return Reflect.get(e, r, n);
1613
+ if (Object.prototype.hasOwnProperty.call(e, r)) return e[r];
1614
+ const o = t[r];
1615
+ if (Vr(o)) {
1616
+ const i = Kr(o);
1617
+ return e[r] = i, i;
1618
+ }
1619
+ return o;
1620
+ },
1621
+ has(e, r) {
1622
+ return Reflect.has(e, r) || Reflect.has(t, r);
1623
+ },
1624
+ ownKeys(e) {
1625
+ return Reflect.ownKeys(e);
1626
+ },
1627
+ getOwnPropertyDescriptor(e, r) {
1628
+ return Object.getOwnPropertyDescriptor(e, r);
1629
+ }
1630
+ });
1631
+ }
1632
+ function Vr(t) {
1633
+ return !!(t && typeof t == "object");
1634
+ }
1635
+ function Kr(t) {
1636
+ if (typeof structuredClone == "function") try {
1637
+ return structuredClone(t);
1638
+ } catch {
1639
+ }
1640
+ try {
1641
+ return JSON.parse(JSON.stringify(t));
1642
+ } catch {
1643
+ return t;
1644
+ }
1645
+ }
1646
+ async function _(t, e) {
1647
+ return typeof t == "function" ? await t(e) : t;
1648
+ }
1649
+ function Z(t) {
1650
+ if (t === void 0) return;
1651
+ const e = Math.floor(Number(t));
1652
+ return Number.isFinite(e) && e > 0 ? e : void 0;
1653
+ }
1654
+ async function ot(t, e, r, n) {
1655
+ if (!e) return t;
1656
+ let o, i = !1;
1657
+ return new Promise((a, s) => {
1658
+ o = setTimeout(() => {
1659
+ i || (i = !0, n?.(), s(r()));
1660
+ }, e), Promise.resolve(t).then((c) => {
1661
+ i || (i = !0, o && clearTimeout(o), a(c));
1662
+ }, (c) => {
1663
+ i || (i = !0, o && clearTimeout(o), s(c));
1664
+ });
1665
+ });
1666
+ }
1667
+ function se(t, e) {
1668
+ if (!t) return e;
1669
+ if (!e || t.aborted) return t;
1670
+ if (e.aborted) return e;
1671
+ const r = new AbortController(), n = () => r.abort();
1672
+ return t.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), r.signal;
1673
+ }
1674
+ async function It(t, e, r, n) {
1675
+ if (!t.confirm) return;
1676
+ const o = await _(t.confirm, n);
1677
+ if (!o) return;
1678
+ const i = Hr(o, t, e);
1679
+ await I(r, mt("confirmation:start", e, t));
1680
+ try {
1681
+ const a = await r.rpc("confirmation.request", i), s = typeof a == "boolean" ? a : a?.confirmed === !0;
1682
+ if (await I(r, mt("confirmation:end", e, t)), s) return;
1683
+ throw new x("confirmation_declined", "The requested action was not confirmed.", {
1684
+ source: t.kind === "be_op" ? "be" : t.kind,
1685
+ sourceCode: "confirmation_declined",
1686
+ detail: a
1687
+ });
1688
+ } catch (a) {
1689
+ throw await I(r, {
1690
+ ...mt("confirmation:error", e, t),
1691
+ errorCode: jt(a)
1692
+ }), a;
1693
+ }
1694
+ }
1695
+ function Hr(t, e, r) {
1696
+ return {
1697
+ ...Jr(t),
1698
+ accountId: r.context.meta.accountId,
1699
+ threadId: r.threadId,
1700
+ sessionId: tt(r),
1701
+ stepKind: e.kind,
1702
+ ...e.kind === "be_op" ? { stepName: e.op } : { stepName: e.name }
1703
+ };
1704
+ }
1705
+ function Jr(t) {
1706
+ return typeof t == "string" ? { message: t } : t === !0 ? {} : t && typeof t == "object" ? {
1707
+ ...typeof t.title == "string" ? { title: t.title } : {},
1708
+ ...typeof t.message == "string" ? { message: t.message } : {},
1709
+ ...typeof t.action == "string" ? { action: t.action } : {},
1710
+ ...Object.prototype.hasOwnProperty.call(t, "payload") ? { payload: t.payload } : {}
1711
+ } : {};
1712
+ }
1713
+ async function I(t, e) {
1714
+ try {
1715
+ await t.trace?.(e);
1716
+ } catch {
1717
+ }
1718
+ }
1719
+ function H(t, e) {
1720
+ return {
1721
+ type: t,
1722
+ accountId: e.context.meta.accountId,
1723
+ threadId: e.threadId,
1724
+ sessionId: tt(e)
1725
+ };
1726
+ }
1727
+ function pt(t, e, r, n) {
1728
+ const o = ce(r);
1729
+ return {
1730
+ ...H(t, e),
1731
+ stepIndex: n,
1732
+ stepKind: r.kind,
1733
+ ...o ? { stepName: o } : {}
1734
+ };
1735
+ }
1736
+ function mt(t, e, r) {
1737
+ const n = ce(r);
1738
+ return {
1739
+ ...H(t, e),
1740
+ stepKind: r.kind,
1741
+ ...n ? { stepName: n } : {}
1742
+ };
1743
+ }
1744
+ function ce(t) {
1745
+ if (t.kind === "be_op") return t.op;
1746
+ if (t.kind === "tool" || t.kind === "adapter") return t.name;
1747
+ }
1748
+ function jt(t) {
1749
+ if (t && typeof t == "object") {
1750
+ const e = t;
1751
+ return String(e.sourceCode || e.code || e.name || "unknown");
1752
+ }
1753
+ return "unknown";
1754
+ }
1755
+ function Zr(t) {
1756
+ if (t === void 0) return;
1757
+ const e = Math.floor(Number(t));
1758
+ return Number.isFinite(e) && e > 0 ? e : void 0;
1759
+ }
1760
+ function Wr(t) {
1761
+ const e = t?.payload;
1762
+ if (typeof e == "string") return e;
1763
+ if (e && typeof e == "object" && "text" in e) {
1764
+ const r = e.text;
1765
+ if (typeof r == "string") return r;
1766
+ }
1767
+ return typeof t?.action?.payload == "string" ? t.action.payload : typeof t?.action?.title == "string" ? t.action.title : "";
1768
+ }
1769
+ function Gr(t, e) {
1770
+ 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;
1771
+ if (Array.isArray(a)) {
1772
+ for (const s of a) if (s && typeof s == "object") {
1773
+ const c = s.sku;
1774
+ typeof c == "string" && e.add(c);
1775
+ }
1776
+ }
1777
+ }
1778
+ function Eo(t) {
1779
+ return { invoke(e, r) {
1780
+ return t("tool.invoke", {
1781
+ name: e,
1782
+ input: r
1783
+ });
1784
+ } };
1785
+ }
1786
+ function Po(t, e = {}) {
1787
+ if (!Array.isArray(t)) return [];
1788
+ const r = e.maxItems ?? 8, n = e.maxFeatures ?? 8;
1789
+ return t.map((o) => Yr(o, e.defaultBrand, n)).filter((o) => !!o).slice(0, r);
1790
+ }
1791
+ function Yr(t, e, r) {
1792
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
1793
+ const n = t, o = Tt(n);
1794
+ return o ? tn({
1795
+ sku: o.sku,
1796
+ name: o.name,
1797
+ url: o.url,
1798
+ image: o.image,
1799
+ price: o.price,
1800
+ currency: o.currency,
1801
+ category: o.category,
1802
+ category_names: o.category_names,
1803
+ brand: n.brand || e,
1804
+ features: Qr(n.features, r),
1805
+ specs: Xr(n.specs, r),
1806
+ in_stock: o.in_stock
1807
+ }) : null;
1808
+ }
1809
+ function Qr(t, e) {
1810
+ return Array.isArray(t) ? t.filter(Boolean).slice(0, e) : void 0;
1811
+ }
1812
+ function Xr(t, e) {
1813
+ if (!(!t || typeof t != "object" || Array.isArray(t)))
1814
+ return Object.fromEntries(Object.entries(t).filter(([, r]) => r != null).slice(0, e));
1815
+ }
1816
+ function tn(t) {
1817
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
1818
+ }
1819
+ function ue(t) {
1820
+ if (!t || typeof t != "object" || Array.isArray(t)) return {};
1821
+ const e = t, r = Array.isArray(e.rows) ? e.rows : [];
1822
+ return {
1823
+ ...e,
1824
+ rows: r.map(rn).filter(Boolean)
1825
+ };
1826
+ }
1827
+ function en(t, e) {
1828
+ const r = Array.isArray(t) ? t.filter((s) => !!(s && typeof s == "object" && !Array.isArray(s))) : [], n = ue(e), o = Array.isArray(n.columns) ? n.columns.map(String) : [];
1829
+ if (!o.length) return r;
1830
+ const i = new Map(r.map((s) => [String(s.sku || s.id || ""), s])), a = o.map((s) => i.get(s)).filter((s) => !!s);
1831
+ return a.length ? a : r;
1832
+ }
1833
+ function Io(t, e) {
1834
+ const r = ue(t?.table), n = en(e, r);
1835
+ return {
1836
+ ...t || {},
1837
+ table: r,
1838
+ products: n,
1839
+ multiple_product_details: n
1840
+ };
1841
+ }
1842
+ function rn(t) {
1843
+ return !t || typeof t != "object" || Array.isArray(t) ? null : Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
1844
+ }
1845
+ function jo(t = [], e = {}) {
1846
+ const r = {}, n = [];
1847
+ return (Array.isArray(t) ? t.map((o) => Ct(o, e)).filter((o) => !!o) : []).forEach((o, i) => {
1848
+ const a = `product-${i.toString()}`;
1849
+ n.push(a);
1850
+ const s = {
1851
+ sku: o.sku,
1852
+ product: o
1853
+ };
1854
+ r[a] = {
1855
+ type: "ProductCard",
1856
+ props: {
1857
+ product: o,
1858
+ index: i,
1859
+ action: {
1860
+ title: o.name,
1861
+ type: "launchSingleProduct",
1862
+ payload: s
1863
+ }
1864
+ }
1865
+ };
1866
+ }), r.root = {
1867
+ type: "ProductGrid",
1868
+ props: { layout: "grid" },
1869
+ children: n
1870
+ }, {
1871
+ widget: "chat",
1872
+ panelHint: "panel",
1873
+ spec: {
1874
+ root: "root",
1875
+ elements: r
1876
+ }
1877
+ };
1878
+ }
1879
+ function Oo(t, e = {}) {
1880
+ return {
1881
+ widget: "chat",
1882
+ panelHint: "panel",
1883
+ spec: {
1884
+ root: "root",
1885
+ elements: { root: {
1886
+ type: "ProductDetailsPanel",
1887
+ props: { product: Ct(t, e) || t || {} }
1888
+ } }
1889
+ }
1890
+ };
1891
+ }
1892
+ function Ro(t = {}, e = {}) {
1893
+ const r = (t.multiple_product_details || t.products || []).map((o) => Ct(o, e)).filter((o) => !!o), n = t.table || nn(t.comparison_table);
1894
+ return {
1895
+ widget: "chat",
1896
+ panelHint: "panel",
1897
+ spec: {
1898
+ root: "root",
1899
+ elements: { root: {
1900
+ type: "ComparisonTable",
1901
+ props: {
1902
+ products: r,
1903
+ recommended: r.find((o) => o.sku === t.recommended_choice_sku) || r[0],
1904
+ attributes: Object.entries(n).map(([o, i]) => ({
1905
+ label: o,
1906
+ values: Array.isArray(i) ? i.map(String) : [String(i ?? "")]
1907
+ })),
1908
+ highlights: Kt(t.key_differences),
1909
+ specialCases: Kt(t.special_considerations),
1910
+ recommendedText: t.recommended_choice,
1911
+ productActions: Object.fromEntries(r.map((o) => [o.sku, {
1912
+ title: o.name,
1913
+ type: "launchSingleProduct",
1914
+ payload: {
1915
+ sku: o.sku,
1916
+ product: o
1917
+ }
1918
+ }]))
1919
+ }
1920
+ } }
1921
+ }
1922
+ };
1923
+ }
1924
+ function nn(t) {
1925
+ return Array.isArray(t) ? Object.fromEntries(t.map((e) => {
1926
+ const r = typeof e?.label == "string" ? e.label.trim() : "";
1927
+ return r ? [r, e.values] : null;
1928
+ }).filter((e) => !!e)) : {};
1929
+ }
1930
+ function Mo(t = []) {
1931
+ return {
1932
+ widget: "chat",
1933
+ panelHint: "inline",
1934
+ spec: {
1935
+ root: "root",
1936
+ elements: { root: {
1937
+ type: "ActionButtons",
1938
+ props: { buttons: (Array.isArray(t) ? t : []).map((e) => {
1939
+ const r = e.label || e.title || e.shortName || "", n = e.action || e.requestDetails || e.request_details;
1940
+ return !r || !n?.type ? null : {
1941
+ label: r,
1942
+ action: {
1943
+ title: r,
1944
+ type: n.type,
1945
+ ...n.payload !== void 0 ? { payload: n.payload } : {}
1946
+ }
1947
+ };
1948
+ }).filter((e) => !!e) }
1949
+ } }
1950
+ }
1951
+ };
1952
+ }
1953
+ function Bo(t) {
1954
+ return Object.freeze([...t]);
1955
+ }
1956
+ function on(t) {
1957
+ const e = t?.payload;
1958
+ if (typeof e == "string") return e;
1959
+ if (e && typeof e == "object" && "text" in e) {
1960
+ const n = e.text;
1961
+ if (typeof n == "string") return n;
1962
+ }
1963
+ const r = t?.action;
1964
+ return r && typeof r.payload == "string" ? r.payload : r && typeof r.title == "string" ? r.title : "";
1965
+ }
1966
+ var le = [
1967
+ {
1968
+ pattern: /\bhttps?:\/\/[^\s?#]+(?:\?[^\s#]*)?/giu,
1969
+ replacement: sn
1970
+ },
1971
+ {
1972
+ pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu,
1973
+ replacement: "[email]"
1974
+ },
1975
+ {
1976
+ pattern: /\b(?:\+?\d[\d\s().-]{7,}\d)\b/gu,
1977
+ replacement: "[phone]"
1978
+ },
1979
+ {
1980
+ pattern: /\b(?:token|secret|csrf|cookie|bearer|session|sid|cart(?:[_-]?id)?)\s*[:=]\s*[^\s,;&]+/giu,
1981
+ replacement: "[secret]"
1982
+ },
1983
+ {
1984
+ pattern: /\b(?:order|cart|session)[_-]?(?:id|no|number)?\s*[:#=]?\s*[A-Z0-9-]{6,}\b/giu,
1985
+ replacement: "[secret]"
1986
+ }
1987
+ ], fe = { patterns: le };
1988
+ function de(t, e = fe) {
1989
+ let r = typeof t == "string" ? t : t == null ? "" : String(t);
1990
+ for (const n of e.patterns || []) {
1991
+ const o = n.replacement;
1992
+ r = typeof o == "function" ? r.replace(n.pattern, (i) => o(i)) : r.replace(n.pattern, o);
1993
+ }
1994
+ return r;
1995
+ }
1996
+ function an(t, e = fe) {
1997
+ return de(on(t), e);
1998
+ }
1999
+ function sn(t) {
2000
+ try {
2001
+ const e = new URL(t);
2002
+ return `${e.origin}${e.pathname}${e.search ? "?[query]" : ""}`;
2003
+ } catch {
2004
+ return "[url]";
2005
+ }
2006
+ }
2007
+ var cn = [
2008
+ "assistantName",
2009
+ "homeDomain",
2010
+ "categories",
2011
+ "policyTopics"
2012
+ ], un = { intent: ["searchContract", "competitorBrands"] };
2013
+ function $o(t, e, r, n = {}) {
2014
+ const o = ln(e, r, n);
2015
+ return Object.keys(o).length ? {
2016
+ ...t,
2017
+ account_config: o
2018
+ } : t;
2019
+ }
2020
+ function ln(t, e, r = {}) {
2021
+ if (!t) return {};
2022
+ const n = {}, o = r.baseKeys || cn;
2023
+ for (const s of o) Zt(n, t, s);
2024
+ const i = t[e];
2025
+ i && typeof i == "object" && !Array.isArray(i) && Object.assign(n, fn(i));
2026
+ const a = r.opAllowlist || un;
2027
+ for (const s of a[e] || []) Zt(n, t, s);
2028
+ return n;
2029
+ }
2030
+ function Zt(t, e, r) {
2031
+ e[r] !== void 0 && (t[r] = e[r]);
2032
+ }
2033
+ function fn(t) {
2034
+ return Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
2035
+ }
2036
+ var dn = "input-hash";
2037
+ function pn({ ttlS: t, promptVersion: e = "current" } = {}) {
2038
+ if (!Number.isFinite(t) || t <= 0) throw new Error("inputHashCachePolicy requires a positive ttlS");
2039
+ return {
2040
+ strategy: dn,
2041
+ ttlS: t,
2042
+ promptVersion: e
2043
+ };
2044
+ }
2045
+ function mn({ accountId: t = "", op: e, ttlS: r, promptVersion: n = "current", input: o, keyParts: i, locale: a } = {}) {
2046
+ if (!e) throw new Error("declarativeBeOpCache requires an op");
2047
+ return {
2048
+ cache: pn({
2049
+ ttlS: r,
2050
+ promptVersion: n
2051
+ }),
2052
+ cacheTtlS: r,
2053
+ cacheKey: (s = {}) => ne(e, {
2054
+ account: t,
2055
+ locale: yt(a, s) || s.context?.meta?.locale || s.locale || "",
2056
+ promptVersion: n,
2057
+ payload: bt(yt(o, s)),
2058
+ ...yn(yt(i, s))
2059
+ })
2060
+ };
2061
+ }
2062
+ function Lo(t, e = {}) {
2063
+ return !t || t.kind !== "be_op" ? t : {
2064
+ ...t,
2065
+ ...mn({
2066
+ op: t.op,
2067
+ ttlS: t.cacheTtlS,
2068
+ input: t.input,
2069
+ ...e
2070
+ })
2071
+ };
2072
+ }
2073
+ function yt(t, e) {
2074
+ return typeof t == "function" ? t(e) : t;
2075
+ }
2076
+ function bt(t) {
2077
+ return Array.isArray(t) ? t.map(bt) : !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, bt(r)]));
2078
+ }
2079
+ function yn(t) {
2080
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null));
2081
+ }
2082
+ var No = Object.freeze({
2083
+ FALLBACK_RESULTS: "fallback_results",
2084
+ FALLBACK_NO_RESULTS: "fallback_no_results",
2085
+ FALLBACK_PARTIAL: "fallback_partial",
2086
+ OP_UNAVAILABLE: "op_unavailable"
2087
+ });
2088
+ function Fo(t, e = {}) {
2089
+ return {
2090
+ status: t,
2091
+ ...e
2092
+ };
2093
+ }
2094
+ function qo(t) {
2095
+ return !!(t && typeof t == "object" && typeof t.status == "string");
2096
+ }
2097
+ function Do(t) {
2098
+ return function() {
2099
+ return [{
2100
+ kind: "tool",
2101
+ name: "readPage",
2102
+ input: () => ({}),
2103
+ out: "page",
2104
+ patch: (r, n) => n?.product && typeof t == "function" ? t(r, n.product) : null,
2105
+ onError: []
2106
+ }];
2107
+ };
2108
+ }
2109
+ function Uo(t) {
2110
+ return !t || typeof t != "object" || Array.isArray(t) ? {} : Object.fromEntries(Object.entries(t).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length > 0)));
2111
+ }
2112
+ function zo(t, { screenSummary: e } = {}) {
2113
+ return { panel: {
2114
+ ...t?.panel || {},
2115
+ screen_type: "homepage",
2116
+ screen_sku_list: [],
2117
+ screen_summary: e || null,
2118
+ last_search_products: [],
2119
+ last_search: null,
2120
+ chat_mentioned_skus: [],
2121
+ reviews_summary_skus: [],
2122
+ ai_plist_summary: null,
2123
+ search_suggestions_skus: [],
2124
+ list_source: null,
2125
+ active_product_panel: !1,
2126
+ assistant_mode: "shopping",
2127
+ redirected_agent_state: null,
2128
+ ui_hints: null
2129
+ } };
2130
+ }
2131
+ function gn({ patterns: t, messageFilter: e, messageNormalizer: r = (o) => o, messageLimit: n = 10 } = {}) {
2132
+ const o = { patterns: [...le, ...Array.isArray(t) ? t : []] };
2133
+ function i(c) {
2134
+ return de(c, o);
2135
+ }
2136
+ function a(c) {
2137
+ return an(c, o);
2138
+ }
2139
+ function s(c = []) {
2140
+ const u = (Array.isArray(c) ? c : []).filter((l) => typeof e == "function" ? e(l) : l && typeof l == "object").filter(Boolean);
2141
+ return (Number.isFinite(n) && n > 0 ? u.slice(-n) : u).map((l) => ({
2142
+ role: l.role,
2143
+ content: i(r(l.content)).slice(0, 1e3)
2144
+ }));
2145
+ }
2146
+ return {
2147
+ redactPii: i,
2148
+ anonymousRequestText: a,
2149
+ anonymizeMessages: s
2150
+ };
2151
+ }
2152
+ function Vo(t) {
2153
+ 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();
2154
+ }
2155
+ var A = {
2156
+ features: 18,
2157
+ reviews: 4,
2158
+ qna: 4,
2159
+ sellers: 4,
2160
+ variants: 12,
2161
+ documents: 6,
2162
+ textBlocks: 6,
2163
+ relatedProducts: 8,
2164
+ textChars: 220
2165
+ }, Ot = {
2166
+ description: /\b(?:description|details|product information|urun bilgisi|urun aciklamasi|açıklama|aciklama)\b/iu,
2167
+ seller: /\b(?:seller|merchant|store|satici|satıcı|magaza|mağaza)\b/iu,
2168
+ review: /\b(?:review|reviews|rating|ratings|yorum|degerlendirme|değerlendirme|puan)\b/iu,
2169
+ qna: /\b(?:questions?|answers?|qna|q&a|soru|cevap)\b/iu,
2170
+ payment: /\b(?:installment|instalment|payment|pay in|taksit|odeme|ödeme|vade)\b/iu,
2171
+ delivery: /\b(?:delivery|shipping|cargo|stock|availability|teslimat|kargo|stok|gonderim|gönderim)\b/iu,
2172
+ promotion: /\b(?:campaign|promotion|discount|coupon|deal|kampanya|indirim|kupon|firsat|fırsat)\b/iu,
2173
+ variant: /\b(?:variant|size|colour|color|beden|olcu|ölçü|renk|numara)\b/iu
2174
+ }, hn = /[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, wn = /(?:token|session|sid|auth|code|csrf|secret|key|password|passwd|phone|email|address|postcode|zip|jwt|bearer)/iu, bn = /[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;
2175
+ function Ko({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (i) => i }) {
2176
+ return (i = {}) => kn({
2177
+ accountId: t,
2178
+ getPageType: e,
2179
+ getProduct: r,
2180
+ getProducts: n,
2181
+ normalizeProduct: o,
2182
+ input: i
2183
+ });
2184
+ }
2185
+ function kn({ accountId: t, getPageType: e, getProduct: r, getProducts: n, normalizeProduct: o = (a) => a, input: i = {} }) {
2186
+ const a = Hn(i), s = o(i.product || gt(r)), c = (gt(n) || []).map(o).filter(Boolean), u = b(i.sku || s?.sku || i.product?.sku), l = u ? c.find((st) => b(st?.sku) === u) || s : s || c[0] || null, f = Sn(u || l?.sku), d = Wt({
2187
+ ...f.product,
2188
+ ...l
2189
+ }), p = $t(X(l?.features), X(l?.specs), Bn(l?.facet_hits), X(f.product?.features), vn(), Cn(), Tn()).slice(0, a.features), m = me(it(l?.reviews), f.reviews, En()).slice(0, a.reviews), h = ye(Rt(l?.qna), Pn()).slice(0, a.qna), C = ge(Mt(l?.sellers), In()).slice(0, a.sellers), $ = B([...l?.payment || [], ...Q("payment", a)]), R = B([...l?.delivery || [], ...Q("delivery", a)]), L = B([...l?.promotions || [], ...Q("promotion", a)]), M = he(Bt(l?.variants), jn()).slice(0, a.variants), N = On(a.documents), k = be(l?.description, f.product?.description, Rn("description"), Q("description", {
2190
+ ...a,
2191
+ textBlocks: 2
2192
+ })[0]), Lt = c.filter((st) => !u || b(st?.sku) !== u).map(Wt).filter(Boolean).slice(0, a.relatedProducts);
2193
+ return U({
2194
+ accountId: t,
2195
+ pageType: gt(e) || "other",
2196
+ url: Kn(),
2197
+ product: d,
2198
+ description: k,
2199
+ features: p,
2200
+ sellers: C,
2201
+ reviews: m,
2202
+ qna: h,
2203
+ rating: S(l?.rating ?? f.rating),
2204
+ review_count: S(l?.review_count ?? f.review_count),
2205
+ payment: $,
2206
+ delivery: R,
2207
+ promotions: L,
2208
+ variants: M,
2209
+ documents: N,
2210
+ related_products: Lt,
2211
+ capabilities: Dn({
2212
+ description: k,
2213
+ features: p,
2214
+ sellers: C,
2215
+ reviews: m,
2216
+ qna: h,
2217
+ payment: $,
2218
+ delivery: R,
2219
+ promotions: L,
2220
+ variants: M,
2221
+ documents: N,
2222
+ relatedProducts: Lt
2223
+ }),
2224
+ privacy: {
2225
+ browserLocal: !0,
2226
+ rawHtml: !1,
2227
+ formValues: !1,
2228
+ cookies: !1,
2229
+ storage: !1,
2230
+ redacted: !0
2231
+ }
2232
+ });
2233
+ }
2234
+ function Ho(t, e) {
2235
+ const r = Array.isArray(t) ? t.filter(Boolean) : [];
2236
+ if (!e || typeof e != "object" || !r.length) return r;
2237
+ const n = b(e.product?.sku);
2238
+ return r.map((o, i) => {
2239
+ const a = b(o?.sku);
2240
+ return r.length === 1 || n && a && n === a || i === 0 ? An(o, e) : o;
2241
+ });
2242
+ }
2243
+ function _n(t) {
2244
+ return !t || typeof t != "object" ? null : U({
2245
+ product: t.product,
2246
+ description: g(t.description, 500),
2247
+ features: $n(t.features, 14),
2248
+ sellers: Fn(t.sellers, 4),
2249
+ reviews: Ln(t.reviews, 4),
2250
+ qna: Nn(t.qna, 4),
2251
+ rating: t.rating,
2252
+ review_count: t.review_count,
2253
+ payment: O(t.payment, 5, 160),
2254
+ delivery: O(t.delivery, 5, 160),
2255
+ promotions: O(t.promotions, 5, 160),
2256
+ variants: qn(t.variants, 10),
2257
+ documents: O(t.documents, 5, 220),
2258
+ capabilities: Array.isArray(t.capabilities) ? t.capabilities.slice(0, 12) : void 0
2259
+ });
2260
+ }
2261
+ function Jo(t, e, r = {}) {
2262
+ const n = _n(t);
2263
+ if (!n) return e;
2264
+ 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(", ");
2265
+ 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;
2266
+ }
2267
+ function An(t, e) {
2268
+ return U({
2269
+ ...t,
2270
+ description: be(t.description, e.description),
2271
+ features: $t(X(t.features), e.features).slice(0, 24),
2272
+ specs: t.specs || (e.features?.length ? Object.fromEntries(e.features.map(Un)) : void 0),
2273
+ sellers: ge(Mt(t.sellers), e.sellers),
2274
+ reviews: me(it(t.reviews), e.reviews),
2275
+ qna: ye(Rt(t.qna), e.qna),
2276
+ rating: t.rating ?? e.rating,
2277
+ review_count: t.review_count ?? e.review_count,
2278
+ payment: B([...t.payment || [], ...e.payment || []]),
2279
+ delivery: B([...t.delivery || [], ...e.delivery || []]),
2280
+ promotions: B([...t.promotions || [], ...e.promotions || []]),
2281
+ variants: he(Bt(t.variants), e.variants),
2282
+ documents: B([...t.documents || [], ...e.documents || []])
2283
+ });
2284
+ }
2285
+ function Sn(t) {
2286
+ const e = [];
2287
+ for (const o of v('script[type="application/ld+json"]')) {
2288
+ const i = xn(o.textContent);
2289
+ for (const a of kt(i))
2290
+ String(a?.["@type"] || "").toLowerCase() === "product" && e.push(a);
2291
+ }
2292
+ const r = e.find((o) => b(o.sku || o.productID || o.mpn) === b(t)) || e[0];
2293
+ if (!r) return {};
2294
+ const n = r.aggregateRating || {};
2295
+ return {
2296
+ product: U({
2297
+ sku: b(r.sku || r.productID || r.mpn),
2298
+ name: y(r.name),
2299
+ brand: y(r.brand?.name || r.brand),
2300
+ description: y(r.description),
2301
+ images: O(r.image, 8, 280),
2302
+ url: W(r.url),
2303
+ rating: S(n.ratingValue),
2304
+ review_count: S(n.reviewCount || n.ratingCount)
2305
+ }),
2306
+ reviews: it(r.review),
2307
+ rating: S(n.ratingValue),
2308
+ review_count: S(n.reviewCount || n.ratingCount)
2309
+ };
2310
+ }
2311
+ function kt(t) {
2312
+ return Array.isArray(t) ? t.flatMap(kt) : !t || typeof t != "object" ? [] : [t, ...kt(t["@graph"])];
2313
+ }
2314
+ function xn(t) {
2315
+ try {
2316
+ return JSON.parse(String(t || ""));
2317
+ } catch {
2318
+ return null;
2319
+ }
2320
+ }
2321
+ function vn() {
2322
+ const t = [];
2323
+ for (const e of v("table tr")) {
2324
+ const r = [...e.querySelectorAll?.("th,td") || []].map((n) => y(n.textContent));
2325
+ r.length >= 2 && r[0] && r[1] && t.push({
2326
+ key: r[0],
2327
+ value: r.slice(1).join(" ")
2328
+ });
2329
+ }
2330
+ return t;
2331
+ }
2332
+ function Cn() {
2333
+ const t = [];
2334
+ for (const e of v("dt")) {
2335
+ const r = y(e.textContent), n = y(e.nextElementSibling?.matches?.("dd") ? e.nextElementSibling.textContent : "");
2336
+ r && n && t.push({
2337
+ key: r,
2338
+ value: n
2339
+ });
2340
+ }
2341
+ return t;
2342
+ }
2343
+ function Tn() {
2344
+ return v('[class*="spec" i], [class*="feature" i], [class*="attribute" i], li').map((t) => pe(y(t.textContent))).filter(Boolean).slice(0, A.features);
2345
+ }
2346
+ function En() {
2347
+ return v('[class*="review" i], [data-review], [itemprop="review"]').map((t) => {
2348
+ const e = y(t.textContent);
2349
+ return !e || e.length < 8 || Ot.qna.test(e) ? null : {
2350
+ content: g(e, 260),
2351
+ star: S(t.getAttribute?.("data-rating"))
2352
+ };
2353
+ }).filter(Boolean);
2354
+ }
2355
+ function Pn() {
2356
+ const t = v('[class*="question" i], [class*="answer" i], [data-question], [data-answer]'), e = [];
2357
+ for (const r of t) {
2358
+ const n = y(r.textContent);
2359
+ if (!n || !Ot.qna.test(n)) continue;
2360
+ const o = y(r.getAttribute?.("data-question") || n), i = y(r.getAttribute?.("data-answer") || r.nextElementSibling?.textContent || "");
2361
+ e.push({
2362
+ question: g(o, 220),
2363
+ answer: g(i, 260)
2364
+ });
2365
+ }
2366
+ return e;
2367
+ }
2368
+ function In() {
2369
+ return v('[class*="seller" i], [class*="merchant" i], [data-seller], [data-merchant]').map((t) => y(t.getAttribute?.("data-seller") || t.getAttribute?.("data-merchant") || t.textContent)).filter(Boolean).map((t) => ({ merchant: g(t, 120) }));
2370
+ }
2371
+ function jn() {
2372
+ return v('[class*="variant" i] a,[class*="variant" i] button,[class*="size" i] button,[class*="color" i] button,[data-variant],[data-size],[data-color]').map((t) => U({
2373
+ name: g(ke(t), 120),
2374
+ value: g(t.getAttribute?.("data-value") || t.getAttribute?.("data-size") || t.getAttribute?.("data-color"), 120),
2375
+ sku: b(t.getAttribute?.("data-sku") || t.getAttribute?.("data-product-id")),
2376
+ url: W(t.getAttribute?.("href")),
2377
+ in_stock: t.getAttribute?.("disabled") == null && t.getAttribute?.("aria-disabled") !== "true"
2378
+ })).filter((t) => t.name || t.value || t.sku);
2379
+ }
2380
+ function On(t) {
2381
+ return v("a[href]").filter((e) => /\.pdf(?:$|[?#])/iu.test(e.getAttribute?.("href") || "")).map((e) => {
2382
+ const r = ke(e) || "PDF", n = W(e.getAttribute?.("href"));
2383
+ return n ? `${r}: ${n}` : "";
2384
+ }).filter(Boolean).slice(0, t);
2385
+ }
2386
+ function Q(t, e) {
2387
+ const r = Ot[t];
2388
+ return r ? v("section,article,div,li,p,span,button,a").map((n) => y(n.textContent)).filter((n) => n && r.test(n) && n.length <= 900).map((n) => g(n, e.textChars || A.textChars)).filter(we()).slice(0, e.textBlocks || A.textBlocks) : [];
2389
+ }
2390
+ function Rn(t) {
2391
+ return y(document.querySelector?.(`meta[name="${t}"]`)?.getAttribute?.("content") || document.querySelector?.(`meta[property="og:${t}"]`)?.getAttribute?.("content"));
2392
+ }
2393
+ function v(t) {
2394
+ try {
2395
+ return [...document.querySelectorAll?.(t) || []].filter(Mn);
2396
+ } catch {
2397
+ return [];
2398
+ }
2399
+ }
2400
+ function Mn(t) {
2401
+ if (!t) return !1;
2402
+ if (!t.getBoundingClientRect) return !0;
2403
+ const e = t.getBoundingClientRect();
2404
+ if (e.width <= 0 || e.height <= 0) return !1;
2405
+ const r = window.getComputedStyle?.(t);
2406
+ return !r || r.visibility !== "hidden" && r.display !== "none" && Number(r.opacity || 1) > 0;
2407
+ }
2408
+ function X(t) {
2409
+ return t ? (Array.isArray(t) ? t : Object.entries(t).map(([e, r]) => ({
2410
+ key: e,
2411
+ value: r
2412
+ }))).map((e) => typeof e == "string" ? pe(e) || {
2413
+ key: "",
2414
+ value: y(e)
2415
+ } : {
2416
+ key: y(e.key || e.name || e.label),
2417
+ value: y(e.value || e.text || "")
2418
+ }).filter((e) => e.key || e.value) : [];
2419
+ }
2420
+ function Bn(t) {
2421
+ return !t || typeof t != "object" ? [] : Object.entries(t).map(([e, r]) => ({
2422
+ key: y(e),
2423
+ value: y(r)
2424
+ }));
2425
+ }
2426
+ function pe(t) {
2427
+ const e = /^(.{2,80}?)\s*[::]\s*(.{1,220})$/u.exec(y(t));
2428
+ return e ? {
2429
+ key: e[1],
2430
+ value: e[2]
2431
+ } : null;
2432
+ }
2433
+ function it(t) {
2434
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { content: g(e, 260) } : {
2435
+ content: g(e.content || e.reviewBody || e.description || e.text, 260),
2436
+ star: S(e.star || e.rating || e.reviewRating?.ratingValue)
2437
+ }).filter((e) => e.content || e.star);
2438
+ }
2439
+ function Rt(t) {
2440
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
2441
+ question: g(e.question || e.name || "", 220),
2442
+ answer: g(e.answer || e.acceptedAnswer?.text || e.text || "", 260)
2443
+ })).filter((e) => e.question || e.answer);
2444
+ }
2445
+ function Mt(t) {
2446
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => typeof e == "string" ? { merchant: g(e, 120) } : {
2447
+ merchant: g(e.merchant || e.name || e.seller || "", 120),
2448
+ merchant_id: b(e.merchant_id || e.id || ""),
2449
+ merchant_rating: S(e.merchant_rating || e.rating),
2450
+ price_offer: S(e.price_offer || e.price)
2451
+ }).filter((e) => e.merchant || e.merchant_id);
2452
+ }
2453
+ function Bt(t) {
2454
+ return (Array.isArray(t) ? t : t ? [t] : []).map((e) => ({
2455
+ name: g(e.name || e.label || e.title || "", 120),
2456
+ value: g(e.value || e.size || e.color || "", 120),
2457
+ sku: b(e.sku || e.code || ""),
2458
+ url: W(e.url),
2459
+ in_stock: e.in_stock
2460
+ })).filter((e) => e.name || e.value || e.sku || e.url);
2461
+ }
2462
+ function $t(...t) {
2463
+ const e = /* @__PURE__ */ new Set(), r = [];
2464
+ for (const n of t.flat().filter(Boolean)) {
2465
+ const o = {
2466
+ key: g(n.key || n.name || "", 90),
2467
+ value: g(n.value || n.text || "", 180)
2468
+ }, i = `${o.key}:${o.value}`.toLocaleLowerCase("tr-TR");
2469
+ !o.key && !o.value || e.has(i) || (e.add(i), r.push(o));
2470
+ }
2471
+ return r;
2472
+ }
2473
+ function me(...t) {
2474
+ return at(t.flat().filter(Boolean), (e) => `${e.star || ""}:${e.content || ""}`);
2475
+ }
2476
+ function ye(...t) {
2477
+ return at(t.flat().filter(Boolean), (e) => `${e.question || ""}:${e.answer || ""}`);
2478
+ }
2479
+ function ge(...t) {
2480
+ return at(t.flat().filter(Boolean), (e) => `${e.merchant || ""}:${e.merchant_id || ""}`);
2481
+ }
2482
+ function he(...t) {
2483
+ return at(t.flat().filter(Boolean), (e) => `${e.sku || ""}:${e.name || ""}:${e.value || ""}`);
2484
+ }
2485
+ function at(t, e) {
2486
+ const r = /* @__PURE__ */ new Set();
2487
+ return t.filter((n) => {
2488
+ const o = e(n).toLocaleLowerCase("tr-TR");
2489
+ return !o.trim() || r.has(o) ? !1 : (r.add(o), !0);
2490
+ });
2491
+ }
2492
+ function B(t) {
2493
+ return O(t, 20, A.textChars);
2494
+ }
2495
+ function O(t, e, r) {
2496
+ return (Array.isArray(t) ? t : t ? [t] : []).map((n) => g(n, r)).filter(Boolean).filter(we()).slice(0, e);
2497
+ }
2498
+ function we() {
2499
+ const t = /* @__PURE__ */ new Set();
2500
+ return (e) => {
2501
+ const r = y(e).toLocaleLowerCase("tr-TR");
2502
+ return !r || t.has(r) ? !1 : (t.add(r), !0);
2503
+ };
2504
+ }
2505
+ function $n(t, e) {
2506
+ return $t(t).slice(0, e);
2507
+ }
2508
+ function Ln(t, e) {
2509
+ return it(t).slice(0, e);
2510
+ }
2511
+ function Nn(t, e) {
2512
+ return Rt(t).slice(0, e);
2513
+ }
2514
+ function Fn(t, e) {
2515
+ return Mt(t).slice(0, e);
2516
+ }
2517
+ function qn(t, e) {
2518
+ return Bt(t).slice(0, e);
2519
+ }
2520
+ function Wt(t) {
2521
+ return !t || typeof t != "object" ? null : U({
2522
+ sku: b(t.sku || t.id || ""),
2523
+ group_id: b(t.group_id || t.groupId || ""),
2524
+ name: y(t.name || t.title || ""),
2525
+ brand: y(t.brand || ""),
2526
+ url: W(t.url),
2527
+ images: O(t.images || t.image, 8, 280),
2528
+ price: S(t.price),
2529
+ price_discounted: S(t.price_discounted || t.discountedPrice),
2530
+ price_text: y(t.price_text || t.priceText || ""),
2531
+ price_currency: y(t.price_currency || t.currency || ""),
2532
+ category_ids: zn(t.category_ids || t.categoryIds, 8, 90),
2533
+ category_names: O(t.category_names || t.categoryNames || t.category, 8, 140),
2534
+ in_stock: t.in_stock
2535
+ });
2536
+ }
2537
+ function Dn(t) {
2538
+ return [
2539
+ t.description ? "description" : "",
2540
+ t.features?.length ? "features" : "",
2541
+ t.sellers?.length ? "seller" : "",
2542
+ t.reviews?.length || t.rating || t.review_count ? "reviews_ratings" : "",
2543
+ t.qna?.length ? "qna" : "",
2544
+ t.payment?.length ? "installment_payment" : "",
2545
+ t.delivery?.length ? "shipping_delivery_stock" : "",
2546
+ t.promotions?.length ? "campaigns_promotions" : "",
2547
+ t.variants?.length ? "variants" : "",
2548
+ t.documents?.length ? "documents" : "",
2549
+ t.relatedProducts?.length ? "related_products" : ""
2550
+ ].filter(Boolean);
2551
+ }
2552
+ function Un(t) {
2553
+ return [y(t.key || t.name), y(t.value || t.text)];
2554
+ }
2555
+ function be(...t) {
2556
+ return t.map((e) => g(e, 700)).find(Boolean) || "";
2557
+ }
2558
+ function g(t, e) {
2559
+ return y(t).slice(0, e);
2560
+ }
2561
+ function ke(t) {
2562
+ return y(t.getAttribute?.("aria-label") || t.getAttribute?.("title") || t.getAttribute?.("alt") || t.textContent);
2563
+ }
2564
+ function y(t) {
2565
+ return String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(hn, "[redacted]").replace(/\s+/gu, " ").trim();
2566
+ }
2567
+ function b(t) {
2568
+ const e = String(t ?? "").replace(/<script\b[\s\S]*?<\/script>/giu, " ").replace(/<style\b[\s\S]*?<\/style>/giu, " ").replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
2569
+ 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);
2570
+ }
2571
+ function zn(t, e, r) {
2572
+ return (Array.isArray(t) ? t : t ? [t] : []).map((n) => b(n).slice(0, r)).filter(Boolean).filter(Vn()).slice(0, e);
2573
+ }
2574
+ function Vn() {
2575
+ const t = /* @__PURE__ */ new Set();
2576
+ return (e) => {
2577
+ const r = b(e).toLocaleLowerCase("tr-TR");
2578
+ return !r || t.has(r) ? !1 : (t.add(r), !0);
2579
+ };
2580
+ }
2581
+ function S(t) {
2582
+ const e = Number(String(t ?? "").replace(",", "."));
2583
+ return Number.isFinite(e) && e > 0 ? e : void 0;
2584
+ }
2585
+ function W(t) {
2586
+ if (!t) return "";
2587
+ try {
2588
+ const e = new URL(t, window.location.href);
2589
+ return /^https?:$/u.test(e.protocol) ? (e.hash = "", _e(e), e.href) : "";
2590
+ } catch {
2591
+ return "";
2592
+ }
2593
+ }
2594
+ function Kn() {
2595
+ try {
2596
+ const t = new URL(window.location.href);
2597
+ return t.hash = "", _e(t), `${t.origin}${t.pathname}${t.search}`;
2598
+ } catch {
2599
+ return "";
2600
+ }
2601
+ }
2602
+ function _e(t) {
2603
+ for (const [e, r] of [...t.searchParams.entries()]) {
2604
+ const n = String(r || "");
2605
+ (wn.test(e) || bn.test(n)) && t.searchParams.set(e, "redacted");
2606
+ }
2607
+ return t;
2608
+ }
2609
+ function Hn(t = {}) {
2610
+ return {
2611
+ features: T(t.maxFeatures, A.features, 40),
2612
+ reviews: T(t.maxReviews, A.reviews, 12),
2613
+ qna: T(t.maxQna, A.qna, 12),
2614
+ sellers: T(t.maxSellers, A.sellers, 12),
2615
+ variants: T(t.maxVariants, A.variants, 30),
2616
+ documents: T(t.maxDocuments, A.documents, 12),
2617
+ textBlocks: T(t.maxTextBlocks, A.textBlocks, 16),
2618
+ relatedProducts: T(t.maxRelatedProducts, A.relatedProducts, 20),
2619
+ textChars: T(t.textChars, A.textChars, 420)
2620
+ };
2621
+ }
2622
+ function T(t, e, r) {
2623
+ const n = Number(t);
2624
+ return !Number.isFinite(n) || n <= 0 ? e : Math.min(Math.floor(n), r);
2625
+ }
2626
+ function gt(t) {
2627
+ try {
2628
+ return typeof t == "function" ? t() : null;
2629
+ } catch {
2630
+ return null;
2631
+ }
2632
+ }
2633
+ function U(t) {
2634
+ return Object.fromEntries(Object.entries(t || {}).filter(([, e]) => e != null && e !== "" && (!Array.isArray(e) || e.length)));
2635
+ }
2636
+ var { redactPii: Zo, anonymousRequestText: Wo, anonymizeMessages: Go } = gn({ patterns: [{
2637
+ pattern: /\b\d{5}\b/gu,
2638
+ replacement: "[postcode]"
2639
+ }, {
2640
+ pattern: /\b(?:adresim|adres|mahalle|sokak|cadde)\b[^,.!?\n]{8,160}/giu,
2641
+ replacement: "[address]"
2642
+ }] });
2643
+ function Jn(t) {
2644
+ 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) || {};
2645
+ }
2646
+ function Yo(t) {
2647
+ return Array.isArray(t) ? t.find((e) => String(e || "").trim()) : void 0;
2648
+ }
2649
+ function Qo(t) {
2650
+ const e = Jn(t);
2651
+ return [
2652
+ ...e.sku ? [e.sku] : [],
2653
+ ...Array.isArray(e.sku_list) ? e.sku_list : [],
2654
+ ...Array.isArray(e.skus) ? e.skus : [],
2655
+ ...Array.isArray(e.target_skus) ? e.target_skus : []
2656
+ ].map((r) => String(r || "").trim()).filter(Boolean).filter((r, n, o) => o.indexOf(r) === n);
2657
+ }
2658
+ var Zn = 3e4;
2659
+ function Wn(t, e, r = {}) {
2660
+ const n = r.ttlMs ?? Zn, o = r.clock ?? Date.now, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
2661
+ return async function(c) {
2662
+ const u = String(e(c) ?? "");
2663
+ if (!u) return t(c);
2664
+ const l = o();
2665
+ Gn(a, l, n);
2666
+ const f = i.get(u);
2667
+ if (f) return f;
2668
+ const d = a.get(u);
2669
+ if (d && l - d.at < n) return Yn(d.observation, u);
2670
+ const p = (async () => {
2671
+ try {
2672
+ const m = await t(c);
2673
+ return a.set(u, {
2674
+ at: o(),
2675
+ observation: m
2676
+ }), m;
2677
+ } finally {
2678
+ i.delete(u);
2679
+ }
2680
+ })();
2681
+ return i.set(u, p), p;
2682
+ };
2683
+ }
2684
+ function Gn(t, e, r) {
2685
+ for (const [n, o] of t) e - o.at >= r && t.delete(n);
2686
+ }
2687
+ function Yn(t, e) {
2688
+ return !t || typeof t != "object" ? t : {
2689
+ ...t,
2690
+ deduped: !0,
2691
+ dedupe_key: e
2692
+ };
2693
+ }
2694
+ var Qn = 3e4, Ae = /* @__PURE__ */ new Set();
2695
+ function Xo(t) {
2696
+ const e = () => Wn(async (o) => t(o || {}), (o) => {
2697
+ const i = Xn(o), a = Number(o?.quantity || o?.qty || 1) || 1, s = to(o);
2698
+ return i ? `${i}|${a}|${s}` : "";
2699
+ }, { ttlMs: Qn });
2700
+ let r = e();
2701
+ const n = async function(i = {}) {
2702
+ return r(i);
2703
+ };
2704
+ return n.__resetForTesting = () => {
2705
+ r = e();
2706
+ }, Ae.add(n), n;
2707
+ }
2708
+ function ti() {
2709
+ for (const t of Ae) typeof t.__resetForTesting == "function" && t.__resetForTesting();
2710
+ }
2711
+ function Xn(t) {
2712
+ const e = t?.cartCode ?? t?.sku ?? t?.productCode ?? t?.product?.sku ?? t?.product?.cart_code;
2713
+ return e == null ? "" : String(e).trim();
2714
+ }
2715
+ function to(t) {
2716
+ const e = t?.variantId ?? t?.variantCode ?? t?.product?.variantId ?? "";
2717
+ return e == null ? "" : String(e).trim();
2718
+ }
2719
+ var eo = 32, Se = /* @__PURE__ */ new Set();
2720
+ function ei(t, e) {
2721
+ const { accountId: r, allowedHostnames: n, productFromPage: o, mergeProduct: i = no, needsHydration: a = ro, fetchOptions: s = { credentials: "include" }, maxConcurrency: c = 4 } = e;
2722
+ if (!r) throw new Error("wrapResolveProductsWithPdpHydration: accountId is required");
2723
+ if (typeof o != "function") throw new Error("wrapResolveProductsWithPdpHydration: productFromPage(doc, url) is required");
2724
+ if (!Array.isArray(n) || !n.length) throw new Error("wrapResolveProductsWithPdpHydration: allowedHostnames must be a non-empty array");
2725
+ const u = /* @__PURE__ */ new Map(), l = ao({
2726
+ productFromPage: o,
2727
+ fetchOptions: s,
2728
+ isAllowed: oo(n)
2729
+ }), f = async function(p = {}) {
2730
+ const m = await t(p || {});
2731
+ if (p?.hydrateFromPdp === !1) return m;
2732
+ const h = Array.isArray(m?.products) ? m.products : [];
2733
+ if (!h.length) return m;
2734
+ const C = await so(h, l, u, c, i, a);
2735
+ return {
2736
+ ...m,
2737
+ products: C
2738
+ };
2739
+ };
2740
+ return f.__resetCacheForTesting = () => u.clear(), f.__cacheSizeForTesting = () => u.size, Se.add(f), f;
2741
+ }
2742
+ function ri() {
2743
+ for (const t of Se) typeof t.__resetCacheForTesting == "function" && t.__resetCacheForTesting();
2744
+ }
2745
+ function ro(t) {
2746
+ if (!t || !t.url) return !1;
2747
+ const e = t, r = e.features, n = e.specs, o = e.category_names, i = Array.isArray(r) && r.length > 0, a = !!n && typeof n == "object" && Object.keys(n).length > 0, s = Array.isArray(o) && o.length > 0;
2748
+ return !i && !a && !s;
2749
+ }
2750
+ function no(t, e) {
2751
+ return t ? e ? {
2752
+ ...t,
2753
+ ...e
2754
+ } : t : e;
2755
+ }
2756
+ function oo(t) {
2757
+ const e = t.map((r) => String(r || "").toLowerCase().trim()).filter(Boolean);
2758
+ return (r) => {
2759
+ const n = String(r || "").toLowerCase();
2760
+ if (!n) return !1;
2761
+ for (const o of e)
2762
+ if (n === o || n.endsWith(`.${o}`)) return !0;
2763
+ return !1;
2764
+ };
2765
+ }
2766
+ function io(t, e) {
2767
+ if (!t) return null;
2768
+ try {
2769
+ const r = new URL(String(t));
2770
+ return r.protocol !== "https:" || !e(r.hostname) ? null : r.href;
2771
+ } catch {
2772
+ return null;
2773
+ }
2774
+ }
2775
+ function ao(t) {
2776
+ const { productFromPage: e, fetchOptions: r, isAllowed: n } = t;
2777
+ return async function(i) {
2778
+ const a = io(i?.url, n);
2779
+ if (!a || typeof fetch != "function") return null;
2780
+ let s;
2781
+ try {
2782
+ const u = await fetch(a, r);
2783
+ if (!u?.ok) return null;
2784
+ s = await u.text();
2785
+ } catch {
2786
+ return null;
2787
+ }
2788
+ if (!s || typeof DOMParser > "u") return null;
2789
+ let c;
2790
+ try {
2791
+ c = new DOMParser().parseFromString(s, "text/html");
2792
+ } catch {
2793
+ return null;
2794
+ }
2795
+ if (!c) return null;
2796
+ try {
2797
+ return e(c, a) || null;
2798
+ } catch {
2799
+ return null;
2800
+ }
2801
+ };
2802
+ }
2803
+ async function so(t, e, r, n, o, i) {
2804
+ const a = new Array(t.length);
2805
+ let s = 0;
2806
+ const c = Math.max(1, Math.min(n, t.length)), u = new Array(c).fill(null).map(() => l());
2807
+ return await Promise.all(u), a;
2808
+ async function l() {
2809
+ for (; ; ) {
2810
+ const d = s++;
2811
+ if (d >= t.length) return;
2812
+ a[d] = await f(t[d]);
2813
+ }
2814
+ }
2815
+ async function f(d) {
2816
+ if (!d || !i(d)) return d;
2817
+ const p = d?.sku == null ? "" : String(d.sku).trim();
2818
+ if (p && r.has(p)) {
2819
+ const h = r.get(p);
2820
+ return h ? o(d, h) : d;
2821
+ }
2822
+ const m = await e(d);
2823
+ return p && (r.set(p, m || null), co(r)), m ? o(d, m) : d;
2824
+ }
2825
+ }
2826
+ function co(t) {
2827
+ for (; t.size > eo; ) {
2828
+ const e = t.keys().next().value;
2829
+ if (e === void 0) break;
2830
+ t.delete(e);
2831
+ }
2832
+ }
2833
+ var uo = 20;
2834
+ function lo(t, e = {}) {
2835
+ const { context: r, accountConfig: n } = e, o = Array.isArray(t) ? t.filter(Boolean) : [];
2836
+ if (!o.length) return [];
2837
+ const i = String(r?.meta?.locale || n?.locale || n?.defaultLocale || "tr-TR").toLowerCase().startsWith("en"), a = i ? "Compare the first two" : "İlk ikisini karşılaştır", s = i ? "Open product page" : "Ürün sayfasını aç", c = i ? "Tell me the comfort details" : "Konfor özelliklerini anlat", u = i ? "Show similar" : "Benzerlerini göster", l = [];
2838
+ o.length >= 2 && l.push({
2839
+ label: a,
2840
+ action: {
2841
+ type: "getComparisonTable",
2842
+ payload: {
2843
+ skus: o.slice(0, 2).map((d) => d.sku).filter(Boolean),
2844
+ limit: 2
2845
+ }
2846
+ }
2847
+ });
2848
+ const f = o[0]?.sku;
2849
+ return f && !i && (l.push({
2850
+ label: s,
2851
+ action: {
2852
+ type: "openProductPage",
2853
+ payload: {
2854
+ sku: f,
2855
+ url: o[0]?.url
2856
+ }
2857
+ }
2858
+ }), l.push({
2859
+ label: c,
2860
+ action: {
2861
+ type: "productQuestion",
2862
+ payload: { sku_list: [f] }
2863
+ }
2864
+ })), l.push({
2865
+ label: u,
2866
+ action: {
2867
+ type: "findSimilar",
2868
+ payload: { sku: f }
2869
+ }
2870
+ }), l;
2871
+ }
2872
+ function Gt(t, e = uo) {
2873
+ const r = [];
2874
+ if (!Array.isArray(t)) return [];
2875
+ for (const a of t) {
2876
+ const s = Array.isArray(a?.observation?.products) ? a.observation.products : [];
2877
+ s.length && r.push([...s]);
2878
+ }
2879
+ if (r.length <= 1) return (r[0] || []).slice(0, e);
2880
+ const n = [], o = /* @__PURE__ */ new Set();
2881
+ let i = 0;
2882
+ for (; n.length < e; ) {
2883
+ let a = !1;
2884
+ for (const s of r) {
2885
+ const c = s[i];
2886
+ if (!c) continue;
2887
+ const u = String(c.sku || c.url || c.name || "");
2888
+ if (u && o.has(u)) {
2889
+ a = !0;
2890
+ continue;
2891
+ }
2892
+ if (u && o.add(u), n.push(c), a = !0, n.length >= e) break;
2893
+ }
2894
+ if (!a) break;
2895
+ i += 1;
2896
+ }
2897
+ return n;
2898
+ }
2899
+ function ni(t) {
2900
+ if (!t?.spec?.elements) return t;
2901
+ const e = t.spec.root;
2902
+ if (!e) return t;
2903
+ const r = t.spec.elements[e];
2904
+ return !r || r.type !== "ProductGrid" ? (typeof console < "u" && console.warn && console.warn("[agentic] withSimilarsAppend: products envelope root is not ProductGrid", r?.type), t) : {
2905
+ ...t,
2906
+ spec: {
2907
+ ...t.spec,
2908
+ elements: {
2909
+ ...t.spec.elements,
2910
+ [e]: {
2911
+ ...r,
2912
+ props: {
2913
+ ...r.props || {},
2914
+ similarsAppend: !0
2915
+ }
2916
+ }
2917
+ }
2918
+ }
2919
+ };
2920
+ }
2921
+ function oi(t, e = {}) {
2922
+ const r = e.threshold ?? 0;
2923
+ return !r || r <= 0 || !Array.isArray(t) ? !1 : t.length > r;
2924
+ }
2925
+ function ii(t, e = {}) {
2926
+ const r = Math.max(0, e.retainTail ?? 4);
2927
+ if (!Array.isArray(t) || t.length === 0 || t.length <= r) return null;
2928
+ const n = t.slice(t.length - r), o = t.slice(0, t.length - r);
2929
+ return o.length ? {
2930
+ messagesToSummarize: o,
2931
+ retainedTail: n
2932
+ } : null;
2933
+ }
2934
+ function ai(t, e, r = {}) {
2935
+ const n = String(e || "").trim();
2936
+ if (!n) return t;
2937
+ const o = Math.max(0, r.retainTail ?? 4), i = Array.isArray(t.messages) ? t.messages : [], a = i.slice(Math.max(0, i.length - o));
2938
+ return {
2939
+ ...t,
2940
+ messages: [{
2941
+ role: "assistant",
2942
+ content: n,
2943
+ name: "compaction"
2944
+ }, ...a],
2945
+ panel: {
2946
+ ...t.panel || {},
2947
+ compaction_summary: {
2948
+ summary: n,
2949
+ replacedCount: i.length - a.length,
2950
+ retainedTailCount: a.length,
2951
+ compactedAt: (/* @__PURE__ */ new Date()).toISOString()
2952
+ }
2953
+ }
2954
+ };
2955
+ }
2956
+ function E(t, e) {
2957
+ const r = t?.[e];
2958
+ return Array.isArray(r) ? r : [];
2959
+ }
2960
+ function K(t, e, r = !1) {
2961
+ return [...t].reverse().find((n) => n?.name === e && (!r || n?.observation?.status === "ok"));
2962
+ }
2963
+ function fo(t) {
2964
+ return {
2965
+ kind: "patch",
2966
+ patch: (e, r, n) => {
2967
+ const o = K(E(n.bag, t), "search_catalog"), i = Array.isArray(o?.observation?.products) ? o.observation.products : null;
2968
+ return i?.length ? { panel: {
2969
+ ...e.panel,
2970
+ screen_type: "product_list",
2971
+ list_source: "agent",
2972
+ last_search_products: i,
2973
+ last_search: {
2974
+ query: o.observation.query,
2975
+ source: o.observation.source,
2976
+ count: o.observation.count
2977
+ },
2978
+ screen_sku_list: i.map((a) => a?.sku).filter(Boolean).slice(0, 24)
2979
+ } } : null;
2980
+ }
2981
+ };
2982
+ }
2983
+ function si(t) {
2984
+ const e = t.obsKey || "roundObservations", r = t.gridLimit ?? 20, n = t.similarsFollowupSteps ? t.similarsFollowupSteps() : [];
2985
+ return [
2986
+ fo(e),
2987
+ {
2988
+ kind: "branch",
2989
+ on: ({ bag: o }) => E(o, e).some((i) => Array.isArray(i?.observation?.products) && i.observation.products.length) ? "has_products" : "no_products",
2990
+ cases: {
2991
+ has_products: [{
2992
+ kind: "emit",
2993
+ build: ({ bag: o }) => {
2994
+ const i = Gt(E(o, e), r);
2995
+ return t.uiSpec(t.productsUiSpec(i));
2996
+ }
2997
+ }, {
2998
+ kind: "emit",
2999
+ build: ({ bag: o, context: i, accountConfig: a }) => {
3000
+ const s = Gt(E(o, e), r);
3001
+ return t.uiSpec(t.actionButtonsUiSpec(lo(s, {
3002
+ context: i,
3003
+ accountConfig: a
3004
+ })));
3005
+ }
3006
+ }],
3007
+ no_products: []
3008
+ }
3009
+ },
3010
+ {
3011
+ kind: "branch",
3012
+ on: ({ bag: o }) => K(E(o, e), "compare_products", !0) ? "has_compare" : "no_compare",
3013
+ cases: {
3014
+ has_compare: [{
3015
+ kind: "emit",
3016
+ build: ({ context: o, bag: i }) => {
3017
+ const a = K(E(i, e), "compare_products"), s = a?.observation || {}, c = a?.arguments || {}, u = Array.isArray(c.target_skus) ? c.target_skus.map(String) : [], l = Array.isArray(o?.panel?.last_search_products) ? o.panel.last_search_products : [], f = u.length ? u.map((d) => l.find((p) => String(p?.sku) === d)).filter(Boolean) : l.slice(0, 4);
3018
+ return t.uiSpec(t.comparisonUiSpec({
3019
+ products: f,
3020
+ comparison_table: s.comparison_table,
3021
+ key_differences: s.key_differences,
3022
+ recommended_choice_sku: s.recommendation?.sku,
3023
+ recommended_choice: s.recommendation?.reason
3024
+ }));
3025
+ }
3026
+ }],
3027
+ no_compare: []
3028
+ }
3029
+ },
3030
+ {
3031
+ kind: "branch",
3032
+ on: ({ bag: o }) => K(E(o, e), "get_product_details", !0) ? "has_details" : "no_details",
3033
+ cases: {
3034
+ has_details: [{
3035
+ kind: "emit",
3036
+ build: ({ context: o, bag: i }) => {
3037
+ const a = K(E(i, e), "get_product_details"), s = a?.observation?.surface || {}, c = a?.arguments || {}, u = Array.isArray(o?.panel?.last_search_products) ? o.panel.last_search_products : [], l = c.sku ? u.find((d) => String(d?.sku) === String(c.sku)) : null, f = s.product || l || s || {};
3038
+ return t.uiSpec(t.productDetailsUiSpec(f));
3039
+ }
3040
+ }, ...n],
3041
+ no_details: []
3042
+ }
3043
+ },
3044
+ ...po({
3045
+ ...t,
3046
+ obsKey: e
3047
+ })
3048
+ ];
3049
+ }
3050
+ function po(t) {
3051
+ const e = t.obsKey || "roundObservations", r = t.pdpFollowupProduct;
3052
+ return r ? [{
3053
+ kind: "branch",
3054
+ on: ({ bag: n, context: o }) => n.pdpFollowupRendered || E(n, e).some((i) => {
3055
+ const a = i?.name;
3056
+ return a === "search_catalog" || a === "compare_products" || a === "get_product_details" || Array.isArray(i?.observation?.products) && i.observation.products.length;
3057
+ }) ? "skip" : r(n, o) ? "render" : "skip",
3058
+ cases: {
3059
+ render: [
3060
+ {
3061
+ kind: "emit",
3062
+ build: ({ bag: n, context: o }) => t.uiSpec(t.productDetailsUiSpec(r(n, o)))
3063
+ },
3064
+ {
3065
+ kind: "patch",
3066
+ patch: (n, o, i) => (i.bag.pdpFollowupRendered = !0, null)
3067
+ },
3068
+ ...t.similarsFollowupSteps ? t.similarsFollowupSteps() : []
3069
+ ],
3070
+ skip: []
3071
+ }
3072
+ }] : [];
3073
+ }
3074
+ export {
3075
+ To as $,
3076
+ No as A,
3077
+ Je as At,
3078
+ le as B,
3079
+ Ho as C,
3080
+ ho as Ct,
3081
+ zo as D,
3082
+ yo as Dt,
3083
+ Vo as E,
3084
+ Ze as Et,
3085
+ Lo as F,
3086
+ Ro as G,
3087
+ on as H,
3088
+ ln as I,
3089
+ en as J,
3090
+ Oo as K,
3091
+ $o as L,
3092
+ qo as M,
3093
+ Ee as Mt,
3094
+ mn as N,
3095
+ Uo as O,
3096
+ Be as Ot,
3097
+ pn as P,
3098
+ Eo as Q,
3099
+ an as R,
3100
+ kn as S,
3101
+ cr as St,
3102
+ gn as T,
3103
+ P as Tt,
3104
+ Bo as U,
3105
+ de as V,
3106
+ Mo as W,
3107
+ ue as X,
3108
+ Io as Y,
3109
+ Po as Z,
3110
+ Go as _,
3111
+ x as _t,
3112
+ oi as a,
3113
+ Co as at,
3114
+ _n as b,
3115
+ pr as bt,
3116
+ ni as c,
3117
+ So as ct,
3118
+ ti as d,
3119
+ ee as dt,
3120
+ Cr as et,
3121
+ Xo as f,
3122
+ kr as ft,
3123
+ Qo as g,
3124
+ bo as gt,
3125
+ Jn as h,
3126
+ _o as ht,
3127
+ ii as i,
3128
+ oe as it,
3129
+ Fo as j,
3130
+ Te as jt,
3131
+ Do as k,
3132
+ go as kt,
3133
+ ri as l,
3134
+ _r as lt,
3135
+ Yo as m,
3136
+ br as mt,
3137
+ si as n,
3138
+ vo as nt,
3139
+ Gt as o,
3140
+ Ct as ot,
3141
+ Wn as p,
3142
+ ko as pt,
3143
+ jo as q,
3144
+ ai as r,
3145
+ xo as rt,
3146
+ lo as s,
3147
+ Tt as st,
3148
+ po as t,
3149
+ ne as tt,
3150
+ ei as u,
3151
+ Ao as ut,
3152
+ Wo as v,
3153
+ te as vt,
3154
+ Jo as w,
3155
+ Qt as wt,
3156
+ Ko as x,
3157
+ ur as xt,
3158
+ Zo as y,
3159
+ wo as yt,
3160
+ fe as z
3161
+ };