@gengage/assistant-fe 0.6.50 → 0.7.0

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