@gengage/assistant-fe 0.6.47 → 0.6.49

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.
@@ -0,0 +1,1379 @@
1
+ import { i as X } from "./widget-base-AuwRxs2X.js";
2
+ var Z = ({ element: e, renderElement: t }) => {
3
+ if (!e.children || e.children.length === 0) return null;
4
+ const r = document.createElement("div");
5
+ for (const n of e.children) {
6
+ const o = t(n);
7
+ o && r.appendChild(o);
8
+ }
9
+ return r;
10
+ };
11
+ function dt(e) {
12
+ const t = document.createElement("div");
13
+ if (t.className = e.containerClassName, !e.spec.elements[e.spec.root]) return t;
14
+ const r = e.unknownRenderer ?? Z, n = (i) => {
15
+ const s = e.spec.elements[i];
16
+ if (!s) return null;
17
+ const c = e.registry[s.type];
18
+ return c ? c({
19
+ elementId: i,
20
+ element: s,
21
+ spec: e.spec,
22
+ context: e.context,
23
+ renderElement: n
24
+ }) : r({
25
+ elementId: i,
26
+ element: s,
27
+ spec: e.spec,
28
+ context: e.context,
29
+ renderElement: n
30
+ });
31
+ }, o = n(e.spec.root);
32
+ return o && t.appendChild(o), t;
33
+ }
34
+ function lt(e, t) {
35
+ if (!t) return e;
36
+ const r = { ...e };
37
+ for (const [n, o] of Object.entries(t))
38
+ o && (r[n] = o);
39
+ return r;
40
+ }
41
+ function B(e) {
42
+ return typeof e == "object" && e !== null && typeof e.type == "string";
43
+ }
44
+ function ee(e) {
45
+ const t = [];
46
+ let r = 0, n = !1, o = !1, i = 0;
47
+ for (let s = 0; s < e.length; s++) {
48
+ const c = e[s];
49
+ if (o) {
50
+ o = !1;
51
+ continue;
52
+ }
53
+ if (c === "\\" && n) {
54
+ o = !0;
55
+ continue;
56
+ }
57
+ if (c === '"') {
58
+ n = !n;
59
+ continue;
60
+ }
61
+ n || (c === "{" && r++, c === "}" && (r--, r === 0 && (t.push(e.slice(i, s + 1)), i = s + 1)));
62
+ }
63
+ return t.length > 0 ? t : [e];
64
+ }
65
+ function M(e, t) {
66
+ const r = e.trim();
67
+ if (!r || r.startsWith(":")) return !1;
68
+ const n = r.startsWith("data: ") ? r.slice(6) : r;
69
+ if (n === "[DONE]")
70
+ return t.onDone?.(), !0;
71
+ try {
72
+ const o = JSON.parse(n);
73
+ return B(o) ? (X("stream", `event: ${o.type}`, o), t.onEvent(o), o.type === "done" ? (t.onDone?.(), !0) : !1) : !1;
74
+ } catch {
75
+ const o = ee(n);
76
+ if (o.length > 1) {
77
+ for (const i of o) try {
78
+ const s = JSON.parse(i);
79
+ if (!B(s)) continue;
80
+ if (t.onEvent(s), s.type === "done")
81
+ return t.onDone?.(), !0;
82
+ } catch {
83
+ }
84
+ return !1;
85
+ }
86
+ return !1;
87
+ }
88
+ }
89
+ async function te(e, t) {
90
+ if (!e.ok) {
91
+ t.onError?.(/* @__PURE__ */ new Error(`HTTP ${e.status}: ${e.statusText}`));
92
+ return;
93
+ }
94
+ if (!e.body) {
95
+ t.onError?.(/* @__PURE__ */ new Error("Response body is null — streaming not supported"));
96
+ return;
97
+ }
98
+ const r = e.body.getReader(), n = new TextDecoder("utf-8");
99
+ let o = "";
100
+ const i = t.idleTimeoutMs ?? 6e4, s = /* @__PURE__ */ Symbol("idle-timeout");
101
+ let c = !1;
102
+ try {
103
+ for (; ; ) {
104
+ const a = r.read();
105
+ let d;
106
+ const g = await (i > 0 ? Promise.race([a.then((p) => (clearTimeout(d), p)), new Promise((p) => {
107
+ d = setTimeout(() => p(s), i);
108
+ })]) : a);
109
+ if (g === s) {
110
+ c = !0, await r.cancel();
111
+ break;
112
+ }
113
+ const { done: u, value: m } = g;
114
+ if (u) break;
115
+ o += n.decode(m, { stream: !0 });
116
+ const f = o.split(`
117
+ `);
118
+ o = f.pop() ?? "";
119
+ for (const p of f) if (M(p, t)) return;
120
+ }
121
+ if (o.trim() && M(o, t))
122
+ return;
123
+ } catch (a) {
124
+ if (a instanceof DOMException && a.name === "AbortError") return;
125
+ t.onError?.(a instanceof Error ? a : new Error(String(a)));
126
+ } finally {
127
+ c || r.releaseLock();
128
+ }
129
+ t.onDone?.();
130
+ }
131
+ function pt(e, t, r) {
132
+ const n = new AbortController(), o = r.signal ? re([r.signal, n.signal]) : n.signal;
133
+ return fetch(e, {
134
+ method: "POST",
135
+ headers: {
136
+ "Content-Type": "application/json",
137
+ ...r.headers
138
+ },
139
+ body: JSON.stringify(t),
140
+ signal: o
141
+ }).then((i) => te(i, {
142
+ ...r,
143
+ signal: o
144
+ })).catch((i) => {
145
+ i instanceof DOMException && i.name === "AbortError" || r.onError?.(i instanceof Error ? i : new Error(String(i)));
146
+ }), n;
147
+ }
148
+ function re(e) {
149
+ const t = new AbortController(), r = [];
150
+ for (const n of e) {
151
+ if (n.aborted)
152
+ return t.abort(n.reason), t.signal;
153
+ const o = () => t.abort(n.reason);
154
+ n.addEventListener("abort", o, { once: !0 }), r.push(() => n.removeEventListener("abort", o));
155
+ }
156
+ return t.signal.addEventListener("abort", () => {
157
+ for (const n of r) n();
158
+ }, { once: !0 }), t.signal;
159
+ }
160
+ var U = 3, ne = (e, t) => {
161
+ const r = e.replace(/\s+/g, " ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g, "");
162
+ if (!r) return "";
163
+ const n = t?.stripLeadingStopWords ? r.replace(/^(?:daha|için)\s+/i, "").trim() : r;
164
+ return n ? n.split(/\s+/).slice(0, 3).join(" ").trim() : "";
165
+ }, D = (e, t) => e ? e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map((r) => ne(r, t)).filter(Boolean) : [];
166
+ function oe(e) {
167
+ const t = (e.display_keywords ?? []).flatMap((o) => D(o, { stripLeadingStopWords: !0 })), r = t.filter((o, i) => t.indexOf(o) === i);
168
+ if (r.length > 0) return r.slice(0, U);
169
+ const n = [...D(e.chosen_attribute, { stripLeadingStopWords: !0 }), ...D(e.short_name)];
170
+ return n.filter((o, i) => n.indexOf(o) === i).slice(0, U);
171
+ }
172
+ function ie(e) {
173
+ return oe(e).join(" • ");
174
+ }
175
+ function se(e) {
176
+ return e === "beauty_consulting" || e === "account_expert";
177
+ }
178
+ function E(...e) {
179
+ for (const t of e) {
180
+ if (typeof t != "string") continue;
181
+ const r = t.trim();
182
+ if (r.length > 0) return r;
183
+ }
184
+ }
185
+ function T(e) {
186
+ return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0).map((t) => t.trim()) : [];
187
+ }
188
+ function I(e) {
189
+ const t = { ...e }, r = E(t.sku), n = T(t.group_skus);
190
+ if (r ? t.sku = r : delete t.sku, n.length > 0 ? t.group_skus = n : delete t.group_skus, r || n.length > 0) delete t.image_url;
191
+ else {
192
+ const o = E(t.image_url);
193
+ o ? t.image_url = o : delete t.image_url;
194
+ }
195
+ return t;
196
+ }
197
+ function ft(e) {
198
+ if (typeof e.type != "string") return null;
199
+ if (ae(e)) return e;
200
+ const t = e;
201
+ switch (t.type) {
202
+ case "outputText":
203
+ return ce(t);
204
+ case "suggestedActions":
205
+ return ue(t);
206
+ case "productList":
207
+ return de(t);
208
+ case "productDetails":
209
+ return le(t);
210
+ case "productDetailsSimilars":
211
+ return pe(t);
212
+ case "comparisonTable":
213
+ return fe(t);
214
+ case "context":
215
+ return _e(t);
216
+ case "chatStreamEnd":
217
+ return he();
218
+ case "loading":
219
+ return be(t);
220
+ case "panelLoading":
221
+ return ke(t);
222
+ case "similarLoading":
223
+ return Se(t);
224
+ case "redirect":
225
+ return we(t);
226
+ case "error":
227
+ return xe(t);
228
+ case "dummy":
229
+ return Ae(t);
230
+ case "launcherAction":
231
+ return Pe(t);
232
+ case "text":
233
+ return O(t);
234
+ case "productItem":
235
+ return Ee(t);
236
+ case "text_image":
237
+ return K(t);
238
+ case "quick_qna":
239
+ return F(t);
240
+ case "reviewHighlights":
241
+ return Te(t);
242
+ case "aiProductSuggestions":
243
+ return Ce(t);
244
+ case "aiProductGroupings":
245
+ return Ie(t);
246
+ case "aiSuggestedSearches":
247
+ return Re(t);
248
+ case "getGroundingReview":
249
+ return ve(t);
250
+ case "voice":
251
+ return Le(t);
252
+ case "uiSpec":
253
+ return He(t);
254
+ default:
255
+ return null;
256
+ }
257
+ }
258
+ function ae(e) {
259
+ const t = e.type;
260
+ if (typeof t != "string") return !1;
261
+ switch (t) {
262
+ case "metadata":
263
+ return typeof e.sessionId == "string" && typeof e.model == "string";
264
+ case "text_chunk":
265
+ return typeof e.content == "string";
266
+ case "ui_spec": {
267
+ const r = e.widget;
268
+ if (r !== "chat" && r !== "qna" && r !== "simrel") return !1;
269
+ const n = b(e.spec);
270
+ return n ? typeof n.root == "string" && b(n.elements) !== null : !1;
271
+ }
272
+ case "action": {
273
+ const r = b(e.action);
274
+ return r !== null && typeof r.kind == "string";
275
+ }
276
+ case "error":
277
+ return typeof e.code == "string" && typeof e.message == "string";
278
+ case "done":
279
+ return !0;
280
+ default:
281
+ return !1;
282
+ }
283
+ }
284
+ function ce(e) {
285
+ const t = l(e.payload.text, e.payload.plain_text) ?? "", r = l(e.payload.plain_text, e.payload.text) ?? t;
286
+ if (e.payload.is_error) return {
287
+ type: "error",
288
+ code: "BACKEND_ERROR",
289
+ message: r || "Backend returned an error"
290
+ };
291
+ const n = {
292
+ type: "text_chunk",
293
+ content: t,
294
+ final: !0
295
+ }, o = e.payload.sku_to_product_item;
296
+ o && typeof o == "object" && !Array.isArray(o) && (n.skuToProductItem = o);
297
+ const i = e.payload.product_mentions;
298
+ Array.isArray(i) && i.length > 0 && (n.productMentions = i.map((a) => {
299
+ if (typeof a != "object" || a === null || typeof a.sku != "string") return null;
300
+ const d = typeof a.short_name == "string" ? a.short_name : "";
301
+ if (!d) return null;
302
+ const g = (typeof a.url == "string" && a.url.trim() ? a.url.trim() : void 0) ?? (() => {
303
+ const u = n.skuToProductItem?.[a.sku];
304
+ return typeof u?.url == "string" && u.url.trim() ? u.url.trim() : void 0;
305
+ })();
306
+ return g ? {
307
+ sku: a.sku,
308
+ short_name: d,
309
+ url: g
310
+ } : {
311
+ sku: a.sku,
312
+ short_name: d
313
+ };
314
+ }).filter((a) => a !== null));
315
+ const s = e.payload.conversation_mode;
316
+ typeof s == "string" && s && (n.conversationMode = s);
317
+ const c = e.payload.render_hint;
318
+ return typeof c == "string" && c && (n.renderHint = c), e.payload.kvkk === !0 && (n.kvkk = !0), n;
319
+ }
320
+ function ue(e) {
321
+ return V((e.payload.actions ?? []).map((t) => {
322
+ const r = l(t.title) ?? "", n = k(t.requestDetails, r), o = n ? {
323
+ label: r,
324
+ action: n
325
+ } : null;
326
+ return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
327
+ }).filter(C), "chat");
328
+ }
329
+ function de(e) {
330
+ const t = Array.isArray(e.payload.grouped_assignment) ? e.payload.grouped_assignment : [], r = (Array.isArray(e.payload.style_variations) ? e.payload.style_variations : []).map((c) => {
331
+ const a = l(c.style_label);
332
+ if (!a) return null;
333
+ const d = l(c.style_mood), g = l(c.image_url ?? void 0), u = (Array.isArray(c.product_list) ? c.product_list : []).map((f) => {
334
+ const p = b(f);
335
+ return p ? j(b(p.product_detail) ?? b(p.product) ?? p) : null;
336
+ }).filter(C), m = Array.isArray(c.recommendation_groups) ? c.recommendation_groups.map((f) => ({
337
+ label: l(f.label) ?? "",
338
+ reason: l(f.reason) ?? "",
339
+ skus: Array.isArray(f.skus) ? f.skus.filter((p) => typeof p == "string" && p.trim().length > 0) : []
340
+ })) : [];
341
+ return {
342
+ style_label: a,
343
+ style_mood: d ?? "",
344
+ ...g ? { image_url: g } : {},
345
+ ...typeof c.status == "string" ? { status: c.status } : {},
346
+ product_list: u,
347
+ recommendation_groups: m
348
+ };
349
+ }).filter(C), n = e.payload.product_list ?? [], o = se(e.payload.source) && r.length > 0 ? r[0].product_list : null, i = o ? qe(o, "chat") : t.length > 0 ? Oe(t, n, "chat") ?? R(n, "chat") : R(n, "chat");
350
+ i.panelHint = "panel";
351
+ const s = i.spec.elements[i.spec.root];
352
+ if (s) {
353
+ const c = {};
354
+ typeof e.payload.offset == "number" && (c.offset = e.payload.offset), typeof e.payload.end_of_list == "boolean" && (c.endOfList = e.payload.end_of_list), typeof e.payload.title == "string" && (c.panelTitle = e.payload.title), typeof e.payload.source == "string" && (c.source = e.payload.source), r.length > 0 && (c.styleVariations = r), e.payload.replace_panel === !0 && (c.replacePanel = !0), (e.payload.ranking_state === "pending" || e.payload.ranking_state === "final") && (c.rankingState = e.payload.ranking_state);
355
+ const a = e.payload.sequence_id ?? e.payload.search_id;
356
+ typeof a == "string" && a.length > 0 && (c.sequenceId = a), Object.keys(c).length > 0 && (s.props = {
357
+ ...s.props,
358
+ ...c
359
+ });
360
+ }
361
+ return i;
362
+ }
363
+ function le(e) {
364
+ const t = e.payload.productDetails;
365
+ if (!t) return Be("chat");
366
+ const r = x(t);
367
+ return {
368
+ type: "ui_spec",
369
+ widget: "chat",
370
+ spec: {
371
+ root: "root",
372
+ elements: { root: {
373
+ type: "ProductDetailsPanel",
374
+ props: { product: {
375
+ ...t,
376
+ ...r
377
+ } }
378
+ } }
379
+ },
380
+ panelHint: "panel"
381
+ };
382
+ }
383
+ function pe(e) {
384
+ const t = R(e.payload.similarProducts ?? [], "chat"), r = t.spec.elements[t.spec.root];
385
+ return r && (r.props = {
386
+ ...r.props,
387
+ similarsAppend: !0
388
+ }), {
389
+ ...t,
390
+ panelHint: "panel"
391
+ };
392
+ }
393
+ function fe(e) {
394
+ const t = e.payload.multiple_product_details ?? [], r = e.payload, n = {
395
+ key_differences: r.key_differences,
396
+ recommended_choice: r.recommended_choice,
397
+ recommended_choice_sku: r.recommended_choice_sku,
398
+ special_considerations: r.special_considerations,
399
+ criteria_view: r.criteria_view,
400
+ criteria_view_short: r.criteria_view_short,
401
+ compared_field_names: r.compared_field_names,
402
+ winner_product: r.winner_product,
403
+ winner_hits: r.winner_hits,
404
+ ...e.payload.product_comparison_framework ?? {}
405
+ }, o = e.payload.table, i = e.payload.features_list, s = [];
406
+ for (const _ of t) {
407
+ const h = x(_);
408
+ s.push(h);
409
+ }
410
+ const c = ge(o, s, n, i);
411
+ let a;
412
+ n?.recommended_choice_sku ? a = n.recommended_choice_sku : n?.winner_product && n.winner_product.length > 0 && (a = n.winner_product[0]?.product_detail?.sku ?? n.winner_product[0]?.sku);
413
+ const d = a ? s.find((_) => _.sku === a) ?? s[0] : s[0], g = [];
414
+ if (Array.isArray(n?.key_differences))
415
+ for (const _ of n.key_differences) typeof _ == "string" && g.push(_);
416
+ const u = W(n?.special_considerations), m = n?.recommended_choice, f = n?.winner_hits, p = {};
417
+ for (const _ of s) {
418
+ const h = _.sku;
419
+ h && (p[h] = {
420
+ title: _.name ?? h,
421
+ type: "launchSingleProduct",
422
+ payload: { sku: h }
423
+ });
424
+ }
425
+ const y = {
426
+ products: s,
427
+ attributes: c,
428
+ highlights: g,
429
+ productActions: p
430
+ };
431
+ return d && (y.recommended = d), u.length > 0 && (y.specialCases = u), m && (y.recommendedText = m), f && (y.winnerHits = f), typeof n?.key_differences == "string" && (y.keyDifferencesHtml = n.key_differences), n?.special_considerations && (y.specialConsiderations = n.special_considerations), {
432
+ type: "ui_spec",
433
+ widget: "chat",
434
+ spec: {
435
+ root: "root",
436
+ elements: { root: {
437
+ type: "ComparisonTable",
438
+ props: y
439
+ } }
440
+ },
441
+ panelHint: "panel"
442
+ };
443
+ }
444
+ function ge(e, t, r, n) {
445
+ if (!e) return [];
446
+ const o = Object.entries(e);
447
+ if (o.length === 0) return [];
448
+ const i = o[0]?.[1];
449
+ if (Array.isArray(i)) {
450
+ const u = r.criteria_view ?? r.criteria_view_short ?? {}, m = r.compared_field_names ?? Object.keys(e), f = [];
451
+ for (const p of m) {
452
+ const y = e[p];
453
+ if (!y || !Array.isArray(y)) continue;
454
+ const _ = u[p] ?? p;
455
+ f.push({
456
+ label: _,
457
+ values: y.map((h) => typeof h == "string" ? h : String(h ?? ""))
458
+ });
459
+ }
460
+ return f;
461
+ }
462
+ const s = e, c = t.map((u) => String(u.sku ?? "")).filter((u) => u.length > 0), a = r.criteria_view ?? r.criteria_view_short ?? {}, d = (n && n.length > 0 ? n : r.compared_field_names && r.compared_field_names.length > 0 ? r.compared_field_names : ye(s)).filter((u) => u !== "name" && u !== "name_short" && !u.endsWith("_short")), g = [];
463
+ for (const u of d) {
464
+ const m = c.map((p) => {
465
+ const y = s[p];
466
+ if (!y || typeof y != "object") return "";
467
+ const _ = y[`${u}_short`], h = y[u];
468
+ return me(_ ?? h);
469
+ });
470
+ if (m.every((p) => p.length === 0)) continue;
471
+ const f = a[u] ?? u;
472
+ g.push({
473
+ label: f,
474
+ values: m
475
+ });
476
+ }
477
+ return g;
478
+ }
479
+ function ye(e) {
480
+ const t = [], r = /* @__PURE__ */ new Set();
481
+ for (const n of Object.values(e))
482
+ if (!(!n || typeof n != "object"))
483
+ for (const o of Object.keys(n))
484
+ r.has(o) || (r.add(o), t.push(o));
485
+ return t;
486
+ }
487
+ function me(e) {
488
+ return typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "";
489
+ }
490
+ function _e(e) {
491
+ return {
492
+ type: "metadata",
493
+ sessionId: "",
494
+ model: "",
495
+ meta: {
496
+ panel: e.payload.panel,
497
+ messages: e.payload.messages,
498
+ message_id: e.payload.message_id
499
+ }
500
+ };
501
+ }
502
+ function he() {
503
+ return { type: "done" };
504
+ }
505
+ function be(e) {
506
+ return {
507
+ type: "metadata",
508
+ sessionId: "",
509
+ model: "",
510
+ meta: {
511
+ loading: !0,
512
+ loadingText: e.payload.text,
513
+ thinkingMessages: e.payload.thinking_messages,
514
+ dynamicLoading: e.payload.is_dynamic === !0
515
+ }
516
+ };
517
+ }
518
+ function ke(e) {
519
+ return {
520
+ type: "metadata",
521
+ sessionId: "",
522
+ model: "",
523
+ meta: {
524
+ loading: !0,
525
+ panelLoading: !0,
526
+ panelPendingType: e.payload?.pending_type,
527
+ loadingText: e.payload?.text
528
+ }
529
+ };
530
+ }
531
+ function Se(e) {
532
+ return {
533
+ type: "metadata",
534
+ sessionId: "",
535
+ model: "",
536
+ meta: {
537
+ loading: !0,
538
+ similarPanelLoading: !0,
539
+ panelPendingType: e.payload?.pending_type,
540
+ loadingText: e.payload?.text
541
+ }
542
+ };
543
+ }
544
+ function we(e) {
545
+ const t = l(e.payload.url);
546
+ return t ? {
547
+ type: "action",
548
+ action: {
549
+ kind: "navigate",
550
+ url: t,
551
+ newTab: e.payload.new_tab === !0
552
+ }
553
+ } : {
554
+ type: "metadata",
555
+ sessionId: "",
556
+ model: "",
557
+ meta: {
558
+ redirect: e.payload,
559
+ redirectTarget: l(e.payload.to)
560
+ }
561
+ };
562
+ }
563
+ function xe(e) {
564
+ return {
565
+ type: "error",
566
+ code: "BACKEND_ERROR",
567
+ message: l(e.payload?.text, e.payload?.message, e.payload?.error) ?? "Backend returned an error"
568
+ };
569
+ }
570
+ function Ae(e) {
571
+ return {
572
+ type: "metadata",
573
+ sessionId: "",
574
+ model: "",
575
+ meta: { noop: !0 }
576
+ };
577
+ }
578
+ function Pe(e) {
579
+ const t = e.payload ?? {};
580
+ if (Array.isArray(t.action_list)) {
581
+ const o = { action_list: t.action_list }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0;
582
+ return i !== void 0 && (o.type = i), s !== void 0 && (o.theme = s), F({
583
+ type: "quick_qna",
584
+ payload: o
585
+ });
586
+ }
587
+ const r = b(t.action);
588
+ if (r) {
589
+ const o = { action: r }, i = typeof t.text == "string" ? t.text : void 0, s = typeof t.image_url == "string" ? t.image_url : void 0, c = typeof t.theme == "string" ? t.theme : void 0;
590
+ return i !== void 0 && (o.text = i), s !== void 0 && (o.image_url = s), c !== void 0 && (o.theme = c), K({
591
+ type: "text_image",
592
+ payload: o
593
+ });
594
+ }
595
+ const n = typeof t.text == "string" ? t.text : "";
596
+ if (n) {
597
+ const o = { text: n }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0, c = b(t.payload) ?? void 0;
598
+ return i !== void 0 && (o.type = i), c !== void 0 && (o.payload = c), s !== void 0 && (o.theme = s), O({
599
+ type: "text",
600
+ payload: o
601
+ });
602
+ }
603
+ return {
604
+ type: "metadata",
605
+ sessionId: "",
606
+ model: "",
607
+ meta: { launcherAction: t }
608
+ };
609
+ }
610
+ function O(e) {
611
+ const t = { text: l(e.payload.text) ?? "" };
612
+ return typeof e.payload.theme == "string" && (t.theme = e.payload.theme), e.payload.payload !== void 0 && (t.payload = e.payload.payload), {
613
+ type: "ui_spec",
614
+ widget: "qna",
615
+ spec: {
616
+ root: "root",
617
+ elements: { root: {
618
+ type: "QuestionHeading",
619
+ props: t
620
+ } }
621
+ }
622
+ };
623
+ }
624
+ function Ee(e) {
625
+ return je(e.payload, "qna");
626
+ }
627
+ function K(e) {
628
+ const t = l(e.payload.text) ?? "", r = k(e.payload.action, t);
629
+ if (r) {
630
+ const o = {
631
+ label: t || r.title,
632
+ action: r
633
+ };
634
+ return typeof e.payload.image_url == "string" && (o.image = e.payload.image_url), typeof e.payload.theme == "string" && (o.theme = e.payload.theme), {
635
+ type: "ui_spec",
636
+ widget: "qna",
637
+ spec: {
638
+ root: "root",
639
+ elements: { root: {
640
+ type: "ActionButton",
641
+ props: o
642
+ } }
643
+ }
644
+ };
645
+ }
646
+ const n = { text: t };
647
+ return typeof e.payload.theme == "string" && (n.theme = e.payload.theme), O({
648
+ type: "text",
649
+ payload: n
650
+ });
651
+ }
652
+ function F(e) {
653
+ return V((e.payload.action_list ?? []).map((t) => {
654
+ const r = l(t.title) ?? "", n = k(t.requestDetails, r), o = n ? {
655
+ label: r,
656
+ action: n
657
+ } : null;
658
+ return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
659
+ }).filter(C), "qna");
660
+ }
661
+ function Te(e) {
662
+ const t = { reviews: (e.payload.reviews ?? []).map((r) => {
663
+ const n = {};
664
+ return typeof r.review_class == "string" && (n.review_class = r.review_class), typeof r.review_text == "string" && (n.review_text = r.review_text), (typeof r.review_rating == "string" || typeof r.review_rating == "number") && (n.review_rating = r.review_rating), typeof r.review_tag == "string" && (n.review_tag = r.review_tag), n;
665
+ }) };
666
+ return typeof e.payload.sku == "string" && (t.sku = e.payload.sku), {
667
+ type: "ui_spec",
668
+ widget: "chat",
669
+ spec: {
670
+ root: "root",
671
+ elements: { root: {
672
+ type: "ReviewHighlights",
673
+ props: t
674
+ } }
675
+ }
676
+ };
677
+ }
678
+ function Ce(e) {
679
+ const t = e.payload.product_suggestions ?? [], r = [];
680
+ for (let n = 0; n < t.length; n++) {
681
+ const o = t[n];
682
+ if (!o) continue;
683
+ const i = Me(o);
684
+ if (!i) continue;
685
+ const s = { product: i }, c = k(o.requestDetails, i.name);
686
+ c && (s.action = c), typeof o.role == "string" && (s.role = o.role), typeof o.reason == "string" && (s.reason = o.reason), typeof o.review_highlight == "string" && (s.reviewHighlight = o.review_highlight), Array.isArray(o.labels) && (s.labels = o.labels), typeof o.expert_quality_score == "number" && (s.expertQualityScore = o.expert_quality_score), r.push(s);
687
+ }
688
+ return r.length === 0 ? {
689
+ type: "metadata",
690
+ sessionId: "",
691
+ model: "",
692
+ meta: { aiProductSuggestions: e.payload.product_suggestions ?? [] }
693
+ } : {
694
+ type: "ui_spec",
695
+ widget: "chat",
696
+ spec: {
697
+ root: "root",
698
+ elements: { root: {
699
+ type: "AITopPicks",
700
+ props: { suggestions: r }
701
+ } }
702
+ }
703
+ };
704
+ }
705
+ function Ie(e) {
706
+ const t = e.payload.product_groupings ?? [], r = [], n = [];
707
+ for (let o = 0; o < t.length; o++) {
708
+ const i = t[o];
709
+ if (!i) continue;
710
+ const s = l(i.name) ?? "", c = l(i.description), a = l(i.highlight), d = Array.isArray(i.labels) ? W(i.labels) : [], g = l(i.sku, i.repr_sku), u = l(i.image, i.repr_image), m = Ne(i, s, g), f = (Array.isArray(i.group_products) ? i.group_products : []).map((_) => {
711
+ const h = b(_);
712
+ return h ? j(h) : null;
713
+ }).filter(C), p = u ?? l(...f.map((_) => _.imageUrl));
714
+ if (s && f.length > 0) {
715
+ const _ = {
716
+ groupName: s,
717
+ products: f
718
+ };
719
+ p && (_.image = p), c && (_.description = c), a && (_.highlight = a), d.length > 0 && (_.labels = d), r.push(_);
720
+ }
721
+ if (!m) continue;
722
+ const y = {
723
+ name: s,
724
+ action: m
725
+ };
726
+ d.length > 0 && (y.labels = d), u !== void 0 && (y.image = u), n.push(y);
727
+ }
728
+ return r.length > 0 ? {
729
+ type: "ui_spec",
730
+ widget: "chat",
731
+ spec: {
732
+ root: "root",
733
+ elements: { root: {
734
+ type: "CategoriesContainer",
735
+ props: { groups: r }
736
+ } }
737
+ },
738
+ panelHint: "panel"
739
+ } : n.length === 0 ? {
740
+ type: "metadata",
741
+ sessionId: "",
742
+ model: "",
743
+ meta: { aiProductGroupings: e.payload.product_groupings ?? [] }
744
+ } : {
745
+ type: "ui_spec",
746
+ widget: "chat",
747
+ spec: {
748
+ root: "root",
749
+ elements: { root: {
750
+ type: "AIGroupingCards",
751
+ props: { entries: n }
752
+ } }
753
+ }
754
+ };
755
+ }
756
+ function Ne(e, t, r) {
757
+ const n = b(e.requestDetails);
758
+ if (n) {
759
+ if (n.type !== "findSimilar") return k(n, t);
760
+ const s = { ...b(n.payload) ?? {} };
761
+ r && !E(s.sku) && (s.sku = r);
762
+ const c = T(e.group_skus);
763
+ return c.length > 0 && (s.group_skus = c), k({
764
+ ...n,
765
+ payload: I(s)
766
+ }, t);
767
+ }
768
+ const o = {};
769
+ r && (o.sku = r);
770
+ const i = T(e.group_skus);
771
+ return i.length > 0 && (o.group_skus = i), Object.keys(o).length === 0 ? null : k({
772
+ type: "findSimilar",
773
+ payload: I(o)
774
+ }, t);
775
+ }
776
+ function De(e, t) {
777
+ const r = b(e.requestDetails), n = b(r?.payload), o = l(e.detailed_user_message), i = e.group_skus && Array.isArray(e.group_skus) ? T(e.group_skus) : T(n?.group_skus), s = l(e.sku, e.representative_product_sku, n?.sku);
778
+ if (r?.type === "findSimilar") {
779
+ const a = { ...n ?? {} };
780
+ return s && (a.sku = s), i.length > 0 && (a.group_skus = i), o && (a.input = o, E(a.text) || (a.text = o)), a.is_search_suggestion = 1, k({
781
+ ...r,
782
+ payload: I(a)
783
+ }, t);
784
+ }
785
+ if (s) {
786
+ const a = {
787
+ sku: s,
788
+ is_search_suggestion: 1
789
+ };
790
+ return i.length > 0 && (a.group_skus = i), o && (a.input = o, a.text = o), k({
791
+ type: "findSimilar",
792
+ payload: I(a)
793
+ }, t);
794
+ }
795
+ const c = {
796
+ ...n ?? {},
797
+ is_suggested_text: 1,
798
+ is_search_suggestion: 1
799
+ };
800
+ return o && !E(c.text) && (c.text = o), i.length > 0 && (c.group_skus = i), k(r?.type === "inputText" ? {
801
+ ...r,
802
+ payload: c
803
+ } : {
804
+ type: "inputText",
805
+ payload: c
806
+ }, t);
807
+ }
808
+ function Re(e) {
809
+ const t = e.payload.suggested_searches ?? [], r = [];
810
+ for (let n = 0; n < t.length; n++) {
811
+ const o = t[n];
812
+ if (!o) continue;
813
+ const i = l(o.short_name, o.chosen_attribute, o.detailed_user_message) ?? `Search ${n + 1}`, s = De(o, i);
814
+ if (!s) continue;
815
+ const c = {
816
+ shortName: i,
817
+ action: s
818
+ }, a = l(o.detailed_user_message);
819
+ a && a !== i && (c.detailedMessage = a);
820
+ const d = ie(o);
821
+ d && d !== i && d !== (a ?? "") && (c.whyDifferent = d), typeof o.image == "string" && (c.image = o.image), r.push(c);
822
+ }
823
+ return r.length === 0 ? {
824
+ type: "metadata",
825
+ sessionId: "",
826
+ model: "",
827
+ meta: { aiSuggestedSearches: e.payload.suggested_searches ?? [] }
828
+ } : {
829
+ type: "ui_spec",
830
+ widget: "chat",
831
+ spec: {
832
+ root: "root",
833
+ elements: { root: {
834
+ type: "AISuggestedSearchCards",
835
+ props: { entries: r }
836
+ } }
837
+ }
838
+ };
839
+ }
840
+ function ve(e) {
841
+ const t = e.payload, r = k(t.requestDetails ?? t.request_details, l(t.review_count, t.reviewCount, t.text, t.title) ?? "Show product reviews");
842
+ if (!r) return {
843
+ type: "metadata",
844
+ sessionId: "",
845
+ model: "",
846
+ meta: { groundingReview: t }
847
+ };
848
+ const n = { action: r };
849
+ return t.title && (n.title = t.title), t.text && (n.text = t.text), t.review_count ? n.reviewCount = t.review_count : typeof t.reviewCount == "string" && t.reviewCount.trim() && (n.reviewCount = t.reviewCount), {
850
+ type: "ui_spec",
851
+ widget: "chat",
852
+ spec: {
853
+ root: "root",
854
+ elements: { root: {
855
+ type: "GroundingReviewCard",
856
+ props: n
857
+ } }
858
+ }
859
+ };
860
+ }
861
+ function Le(e) {
862
+ return {
863
+ type: "metadata",
864
+ sessionId: "",
865
+ model: "",
866
+ meta: { voice: e.payload }
867
+ };
868
+ }
869
+ function q(e, t) {
870
+ const r = {
871
+ product: e,
872
+ index: t
873
+ }, n = e, o = typeof n.sku == "string" ? n.sku : void 0;
874
+ return o && (r.action = {
875
+ title: typeof n.name == "string" ? n.name : "",
876
+ type: "launchSingleProduct",
877
+ payload: { sku: o }
878
+ }), {
879
+ type: "ProductCard",
880
+ props: r
881
+ };
882
+ }
883
+ function V(e, t) {
884
+ const r = {}, n = [];
885
+ for (let o = 0; o < e.length; o++) {
886
+ const i = e[o];
887
+ if (!i) continue;
888
+ const s = `action-${o}`;
889
+ n.push(s);
890
+ const c = {
891
+ label: i.label,
892
+ action: i.action
893
+ };
894
+ i.icon !== void 0 && (c.icon = i.icon), i.image !== void 0 && (c.image = i.image), i.description !== void 0 && (c.description = i.description), r[s] = {
895
+ type: "ActionButton",
896
+ props: c
897
+ };
898
+ }
899
+ return r.root = {
900
+ type: "ActionButtons",
901
+ props: { buttons: e.map((o) => {
902
+ const i = {
903
+ label: o.label,
904
+ action: o.action
905
+ };
906
+ return o.image !== void 0 && (i.image = o.image), o.description !== void 0 && (i.description = o.description), o.icon !== void 0 && (i.icon = o.icon), i;
907
+ }) },
908
+ children: n
909
+ }, {
910
+ type: "ui_spec",
911
+ widget: t,
912
+ spec: {
913
+ root: "root",
914
+ elements: r
915
+ }
916
+ };
917
+ }
918
+ function R(e, t) {
919
+ const r = {}, n = [];
920
+ for (let o = 0; o < e.length; o++) {
921
+ const i = e[o];
922
+ if (!i) continue;
923
+ const s = x(i), c = `product-${o}`;
924
+ n.push(c), r[c] = q(s, o);
925
+ }
926
+ return r.root = {
927
+ type: "ProductGrid",
928
+ props: { layout: "grid" },
929
+ children: n
930
+ }, {
931
+ type: "ui_spec",
932
+ widget: t,
933
+ spec: {
934
+ root: "root",
935
+ elements: r
936
+ }
937
+ };
938
+ }
939
+ function Oe(e, t, r) {
940
+ const n = /* @__PURE__ */ new Map();
941
+ for (const d of t)
942
+ d?.sku && n.set(d.sku, d);
943
+ if (n.size === 0) return null;
944
+ const o = /* @__PURE__ */ new Set(), i = {}, s = [], c = [];
945
+ let a = 0;
946
+ for (let d = 0; d < e.length; d++) {
947
+ const g = e[d], u = l(g?.title) ?? "", m = Array.isArray(g?.skus) ? g.skus : [], f = [];
948
+ for (let p = 0; p < m.length; p++) {
949
+ const y = typeof m[p] == "string" ? m[p].trim() : "";
950
+ if (!y || o.has(y)) continue;
951
+ const _ = n.get(y);
952
+ if (!_) continue;
953
+ o.add(y);
954
+ const h = `product-${d}-${p}`, Y = x(_);
955
+ s.push(h), f.push(h), i[h] = q(Y, a), a += 1;
956
+ }
957
+ f.length > 0 && c.push({
958
+ title: u,
959
+ children: f
960
+ });
961
+ }
962
+ return c.length === 0 || o.size < n.size ? null : (i.root = {
963
+ type: "ProductGrid",
964
+ props: {
965
+ layout: "grouped",
966
+ productSections: c
967
+ },
968
+ children: s
969
+ }, {
970
+ type: "ui_spec",
971
+ widget: r,
972
+ spec: {
973
+ root: "root",
974
+ elements: i
975
+ }
976
+ });
977
+ }
978
+ function qe(e, t) {
979
+ const r = {}, n = [];
980
+ for (let o = 0; o < e.length; o++) {
981
+ const i = e[o];
982
+ if (!i) continue;
983
+ const s = `product-${o}`;
984
+ n.push(s), r[s] = q(i, o);
985
+ }
986
+ return r.root = {
987
+ type: "ProductGrid",
988
+ props: { layout: "grid" },
989
+ children: n
990
+ }, {
991
+ type: "ui_spec",
992
+ widget: t,
993
+ spec: {
994
+ root: "root",
995
+ elements: r
996
+ }
997
+ };
998
+ }
999
+ function je(e, t) {
1000
+ return {
1001
+ type: "ui_spec",
1002
+ widget: t,
1003
+ spec: {
1004
+ root: "root",
1005
+ elements: { root: {
1006
+ type: "ProductCard",
1007
+ props: {
1008
+ product: x(e),
1009
+ index: 0
1010
+ }
1011
+ } }
1012
+ }
1013
+ };
1014
+ }
1015
+ function Be(e) {
1016
+ return {
1017
+ type: "ui_spec",
1018
+ widget: e,
1019
+ spec: {
1020
+ root: "root",
1021
+ elements: { root: {
1022
+ type: "ActionButtons",
1023
+ props: { buttons: [] },
1024
+ children: []
1025
+ } }
1026
+ }
1027
+ };
1028
+ }
1029
+ function Me(e) {
1030
+ const t = l(e.sku), r = l(e.short_name), n = { ...b(e.product_item) ?? e }, o = l(e.discount_reason, e.discountReason);
1031
+ return o && !l(n.discount_reason, n.discountReason) && (n.discount_reason = o), j(n, t, r);
1032
+ }
1033
+ function j(e, t, r) {
1034
+ const n = l(e.sku, t), o = l(e.name, r);
1035
+ if (!n || !o) return null;
1036
+ const i = {
1037
+ sku: n,
1038
+ name: o
1039
+ }, s = l(e.brand);
1040
+ s && (i.brand = s);
1041
+ const c = l(e.url);
1042
+ c && (i.url = c);
1043
+ const a = Ue(e.images);
1044
+ if (a.length > 0) i.images = a;
1045
+ else {
1046
+ const y = l(e.image, e.image_url, e.imageUrl);
1047
+ y && (i.images = [y]);
1048
+ }
1049
+ const d = A(e.price_discounted);
1050
+ d !== void 0 && (i.price_discounted = d);
1051
+ const g = A(e.price);
1052
+ g !== void 0 && (i.price = g);
1053
+ const u = A(e.rating);
1054
+ u !== void 0 && (i.rating = u);
1055
+ const m = A(e.review_count) ?? A(e.reviewCount);
1056
+ m !== void 0 && (i.review_count = m);
1057
+ const f = l(e.cart_code, e.cartCode);
1058
+ f && (i.cart_code = f), typeof e.in_stock == "boolean" && (i.in_stock = e.in_stock), typeof e.inStock == "boolean" && (i.in_stock = e.inStock);
1059
+ const p = l(e.discount_reason, e.discountReason);
1060
+ return p && (i.discount_reason = p), x(i);
1061
+ }
1062
+ function k(e, t) {
1063
+ const r = b(e);
1064
+ if (!r) return null;
1065
+ const n = r.type;
1066
+ if (typeof n != "string" || n.length === 0) return null;
1067
+ const o = {
1068
+ title: t || n,
1069
+ type: n
1070
+ };
1071
+ return r.payload !== void 0 && (o.payload = r.payload), o;
1072
+ }
1073
+ function b(e) {
1074
+ return !e || typeof e != "object" || Array.isArray(e) ? null : e;
1075
+ }
1076
+ function l(...e) {
1077
+ for (const t of e) if (typeof t == "string") {
1078
+ const r = t.trim();
1079
+ if (r.length > 0) return r;
1080
+ }
1081
+ }
1082
+ function Ue(e) {
1083
+ return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.length > 0) : [];
1084
+ }
1085
+ function W(e) {
1086
+ if (typeof e == "string") {
1087
+ const t = e.trim();
1088
+ return t ? [t] : [];
1089
+ }
1090
+ return Array.isArray(e) ? e.filter((t) => typeof t == "string").map((t) => t.trim()).filter((t) => t.length > 0) : [];
1091
+ }
1092
+ function A(e) {
1093
+ if (typeof e == "number" && Number.isFinite(e)) return e;
1094
+ if (typeof e == "string") {
1095
+ let t;
1096
+ e.includes(".") && e.includes(",") ? t = e.replace(/\./g, "").replace(",", ".") : t = e.replace(",", ".");
1097
+ const r = Number(t);
1098
+ if (Number.isFinite(r)) return r;
1099
+ }
1100
+ }
1101
+ function C(e) {
1102
+ return e != null;
1103
+ }
1104
+ var ze = /* @__PURE__ */ new Set([
1105
+ "sku",
1106
+ "name",
1107
+ "brand",
1108
+ "images",
1109
+ "price",
1110
+ "price_discounted",
1111
+ "price_discount_rate",
1112
+ "price_currency",
1113
+ "discount_reason",
1114
+ "url",
1115
+ "rating",
1116
+ "review_count",
1117
+ "cart_code",
1118
+ "in_stock",
1119
+ "description",
1120
+ "description_html",
1121
+ "features",
1122
+ "specifications",
1123
+ "short_name",
1124
+ "category_ids",
1125
+ "category_names",
1126
+ "variants",
1127
+ "facet_hits",
1128
+ "promotions"
1129
+ ]);
1130
+ function x(e) {
1131
+ const t = e.price_discounted != null && e.price_discounted > 0, r = t ? e.price_discounted : e.price, n = t && e.price != null ? e.price : void 0;
1132
+ let o;
1133
+ n != null && r != null && n > 0 ? o = Math.round((n - r) / n * 100) : e.price_discount_rate != null && e.price_discount_rate > 0 && (o = e.price_discount_rate);
1134
+ const i = l(e.brand), s = l(e.name) ?? e.sku, c = i && !s.toLowerCase().startsWith(i.toLowerCase()) ? `${i} ${s}` : s, a = {
1135
+ sku: e.sku,
1136
+ name: c,
1137
+ url: l(e.url) ?? ""
1138
+ }, d = e.images?.[0];
1139
+ d && (a.imageUrl = d), e.images && e.images.length > 1 && (a.images = e.images), r != null && r > 0 && (a.price = String(r)), n != null && n > 0 && (a.originalPrice = String(n)), o !== void 0 && (a.discountPercent = o), i !== void 0 && (a.brand = i), e.rating !== void 0 && (a.rating = e.rating), e.review_count !== void 0 && (a.reviewCount = e.review_count), e.cart_code !== void 0 && (a.cartCode = e.cart_code), e.in_stock !== void 0 && (a.inStock = e.in_stock), e.variants && e.variants.length > 0 && (a.variants = e.variants), e.discount_reason !== void 0 && (a.discountReason = e.discount_reason), e.promotions && e.promotions.length > 0 && (a.promotions = e.promotions), e.description !== void 0 && (a.description = e.description), e.description_html !== void 0 && (a.descriptionHtml = e.description_html), e.features && e.features.length > 0 && (a.features = e.features), e.specifications !== void 0 && (a.specifications = e.specifications), e.facet_hits && (a.facetHits = e.facet_hits), e.category_names && e.category_names.length > 0 && (a.categoryNames = e.category_names), e.short_name !== void 0 && (a.shortName = e.short_name);
1140
+ const g = e, u = {};
1141
+ let m = !1;
1142
+ for (const f of Object.keys(g)) ze.has(f) || (u[f] = g[f], m = !0);
1143
+ return m && (a.extras = u), a;
1144
+ }
1145
+ function gt(e) {
1146
+ return e.results.map(x);
1147
+ }
1148
+ function yt(e) {
1149
+ return e.product_groupings.map((t) => {
1150
+ const r = {
1151
+ name: t.name,
1152
+ products: (t.group_products ?? []).map(x)
1153
+ };
1154
+ return t.highlight !== void 0 && (r.highlight = t.highlight), r;
1155
+ });
1156
+ }
1157
+ function He(e) {
1158
+ const t = e.payload.type, { type: r, ...n } = e.payload;
1159
+ return {
1160
+ type: "ui_spec",
1161
+ widget: "chat",
1162
+ spec: {
1163
+ root: "root",
1164
+ elements: { root: {
1165
+ type: t,
1166
+ props: n
1167
+ } }
1168
+ }
1169
+ };
1170
+ }
1171
+ var Ge = {
1172
+ process_action: "/process_action",
1173
+ launcher_action: "/launcher_action",
1174
+ similar_products: "/similar_products",
1175
+ product_groupings: "/product_groupings"
1176
+ };
1177
+ function $e(e) {
1178
+ if (e === void 0) throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");
1179
+ const t = e.trim();
1180
+ return t === "" ? "" : t.replace(/\/+$/, "");
1181
+ }
1182
+ function mt(e, t) {
1183
+ return `${$e(t?.middlewareUrl)}/chat${Ge[e]}`;
1184
+ }
1185
+ var Ke = 7200 * 1e3, J = 200, Fe = 5 * 1024 * 1024, Ve = "gengage_request_response_cache", We = 1, w = "responses", Je = /* @__PURE__ */ new Set(["addToCart", "like"]), S = /* @__PURE__ */ new Map(), z = null;
1186
+ async function _t(e, t = {}, r = {}) {
1187
+ const n = Qe(e, t);
1188
+ if (!n) return fetch(e, t);
1189
+ const o = Date.now(), i = await et(n, o);
1190
+ if (i) return nt(i);
1191
+ const s = await fetch(e, t);
1192
+ return s.ok && tt(n, s.clone(), o, {
1193
+ ttlMs: r.ttlMs ?? Ke,
1194
+ maxEntries: r.maxEntries ?? J,
1195
+ maxBodyBytes: r.maxBodyBytes ?? Fe
1196
+ }), s;
1197
+ }
1198
+ function Qe(e, t = {}) {
1199
+ if (typeof Request < "u" && e instanceof Request) return null;
1200
+ const r = String(t.method || "GET").toUpperCase();
1201
+ if (r !== "POST" || typeof t.body != "string") return null;
1202
+ const n = Ye(t.body);
1203
+ if (Xe(n)) return null;
1204
+ const o = Ze(n);
1205
+ if (o) {
1206
+ const i = P(n?.action);
1207
+ return `rr:${$(G({
1208
+ url: String(e),
1209
+ method: r,
1210
+ headers: H(t.headers),
1211
+ type: n?.type ?? i?.type ?? "",
1212
+ account_id: n?.account_id ?? n?.accountId ?? "",
1213
+ locale: n?.locale ?? "",
1214
+ outputLanguage: P(n?.meta)?.outputLanguage ?? "",
1215
+ cache_key: o
1216
+ }))}`;
1217
+ }
1218
+ return `rr:${$(G({
1219
+ url: String(e),
1220
+ method: r,
1221
+ headers: H(t.headers),
1222
+ body: t.body
1223
+ }))}`;
1224
+ }
1225
+ function Ye(e) {
1226
+ try {
1227
+ const t = JSON.parse(e);
1228
+ return !t || typeof t != "object" || Array.isArray(t) ? null : t;
1229
+ } catch {
1230
+ return null;
1231
+ }
1232
+ }
1233
+ function Xe(e) {
1234
+ const t = e?.type;
1235
+ return typeof t == "string" && Je.has(t);
1236
+ }
1237
+ function Ze(e) {
1238
+ const t = (P(e?.payload) ?? P(P(e?.action)?.payload))?.cache_key;
1239
+ return typeof t == "string" && t.trim().length > 0 ? t.trim() : null;
1240
+ }
1241
+ async function et(e, t) {
1242
+ const r = S.get(e);
1243
+ if (r) if (r.expiresAt <= t) S.delete(e);
1244
+ else
1245
+ return r.lastAccessedAt = t, S.delete(e), S.set(e, r), v(r), r;
1246
+ const n = await it(e);
1247
+ return n ? n.expiresAt <= t ? (S.delete(e), st(e), null) : (n.lastAccessedAt = t, S.set(e, n), v(n), Q(J), n) : null;
1248
+ }
1249
+ async function tt(e, t, r, n) {
1250
+ try {
1251
+ const o = await t.text();
1252
+ if (ct(o) > n.maxBodyBytes || rt(o)) return;
1253
+ const i = {
1254
+ key: e,
1255
+ status: t.status,
1256
+ statusText: t.statusText,
1257
+ headers: ot(t.headers),
1258
+ body: o,
1259
+ createdAt: r,
1260
+ expiresAt: r + n.ttlMs,
1261
+ lastAccessedAt: r
1262
+ };
1263
+ S.set(e, i), Q(n.maxEntries), await v(i), await at(n.maxEntries, r);
1264
+ } catch {
1265
+ }
1266
+ }
1267
+ function rt(e) {
1268
+ return /"_error"\s*:/u.test(e) || /"type"\s*:\s*"error"/u.test(e);
1269
+ }
1270
+ function nt(e) {
1271
+ return new Response(e.body, {
1272
+ status: e.status,
1273
+ statusText: e.statusText,
1274
+ headers: new Headers(e.headers)
1275
+ });
1276
+ }
1277
+ function H(e) {
1278
+ const t = new Headers(e), r = [];
1279
+ return t.forEach((n, o) => {
1280
+ const i = o.toLowerCase();
1281
+ i !== "authorization" && i !== "cookie" && r.push([i, n]);
1282
+ }), r.sort(([n], [o]) => n.localeCompare(o));
1283
+ }
1284
+ function ot(e) {
1285
+ const t = [];
1286
+ return e.forEach((r, n) => {
1287
+ const o = n.toLowerCase();
1288
+ o !== "set-cookie" && t.push([o, r]);
1289
+ }), t.sort(([r], [n]) => r.localeCompare(n));
1290
+ }
1291
+ function Q(e) {
1292
+ for (; S.size > e; ) {
1293
+ const t = [...S.values()].sort((r, n) => r.lastAccessedAt - n.lastAccessedAt)[0];
1294
+ if (!t) break;
1295
+ S.delete(t.key);
1296
+ }
1297
+ }
1298
+ async function N() {
1299
+ return typeof indexedDB > "u" ? null : (z ??= new Promise((e) => {
1300
+ const t = indexedDB.open(Ve, We);
1301
+ t.onupgradeneeded = () => {
1302
+ const r = t.result;
1303
+ r.objectStoreNames.contains(w) || r.createObjectStore(w, { keyPath: "key" }).createIndex("lastAccessedAt", "lastAccessedAt", { unique: !1 });
1304
+ }, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
1305
+ }), z);
1306
+ }
1307
+ async function it(e) {
1308
+ const t = await N();
1309
+ return t ? new Promise((r) => {
1310
+ const n = t.transaction(w, "readonly"), o = n.objectStore(w).get(e);
1311
+ o.onsuccess = () => r(o.result ?? null), o.onerror = () => r(null), n.onerror = () => r(null);
1312
+ }) : null;
1313
+ }
1314
+ async function v(e) {
1315
+ const t = await N();
1316
+ t && await new Promise((r) => {
1317
+ const n = t.transaction(w, "readwrite");
1318
+ n.objectStore(w).put(e), n.oncomplete = () => r(), n.onerror = () => r(), n.onabort = () => r();
1319
+ });
1320
+ }
1321
+ async function st(e) {
1322
+ const t = await N();
1323
+ t && await new Promise((r) => {
1324
+ const n = t.transaction(w, "readwrite");
1325
+ n.objectStore(w).delete(e), n.oncomplete = () => r(), n.onerror = () => r(), n.onabort = () => r();
1326
+ });
1327
+ }
1328
+ async function at(e, t) {
1329
+ const r = await N();
1330
+ r && await new Promise((n) => {
1331
+ const o = r.transaction(w, "readwrite"), i = o.objectStore(w), s = [], c = i.openCursor();
1332
+ c.onsuccess = () => {
1333
+ const a = c.result;
1334
+ if (!a) {
1335
+ const d = s.filter((u) => u.expiresAt <= t), g = s.filter((u) => u.expiresAt > t).sort((u, m) => u.lastAccessedAt - m.lastAccessedAt).slice(0, Math.max(0, s.length - d.length - e));
1336
+ for (const u of [...d, ...g]) i.delete(u.key);
1337
+ return;
1338
+ }
1339
+ s.push(a.value), a.continue();
1340
+ }, c.onerror = () => n(), o.oncomplete = () => n(), o.onerror = () => n(), o.onabort = () => n();
1341
+ });
1342
+ }
1343
+ function G(e) {
1344
+ return JSON.stringify(L(e));
1345
+ }
1346
+ function P(e) {
1347
+ return e && typeof e == "object" && !Array.isArray(e) ? e : null;
1348
+ }
1349
+ function L(e) {
1350
+ return Array.isArray(e) ? e.map(L) : !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).sort(([t], [r]) => t.localeCompare(r)).map(([t, r]) => [t, L(r)]));
1351
+ }
1352
+ function $(e) {
1353
+ let t = 14695981039346656037n;
1354
+ const r = 1099511628211n;
1355
+ for (let n = 0; n < e.length; n += 1)
1356
+ t ^= BigInt(e.charCodeAt(n)), t = BigInt.asUintN(64, t * r);
1357
+ return t.toString(16).padStart(16, "0");
1358
+ }
1359
+ function ct(e) {
1360
+ return typeof TextEncoder < "u" ? new TextEncoder().encode(e).byteLength : e.length;
1361
+ }
1362
+ export {
1363
+ yt as a,
1364
+ I as c,
1365
+ ie as d,
1366
+ te as f,
1367
+ dt as g,
1368
+ Z as h,
1369
+ ft as i,
1370
+ se as l,
1371
+ lt as m,
1372
+ mt as n,
1373
+ gt as o,
1374
+ pt as p,
1375
+ $e as r,
1376
+ x as s,
1377
+ _t as t,
1378
+ oe as u
1379
+ };