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