@gengage/assistant-fe 0.5.3 → 0.5.5

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.
@@ -1,17 +1,17 @@
1
- import { i as U } from "./widget-base-CJIr0DLe.js";
2
- var H = ({ element: e, renderElement: t }) => {
1
+ import { i as U } from "./widget-base-BMAeQQ2X.js";
2
+ var z = ({ element: e, renderElement: t }) => {
3
3
  if (!e.children || e.children.length === 0) return null;
4
- const o = document.createElement("div");
4
+ const r = document.createElement("div");
5
5
  for (const n of e.children) {
6
- const r = t(n);
7
- r && o.appendChild(r);
6
+ const o = t(n);
7
+ o && r.appendChild(o);
8
8
  }
9
- return o;
9
+ return r;
10
10
  };
11
11
  function He(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 o = e.unknownRenderer ?? H, n = (i) => {
14
+ const r = e.unknownRenderer ?? z, n = (i) => {
15
15
  const s = e.spec.elements[i];
16
16
  if (!s) return null;
17
17
  const a = e.registry[s.type];
@@ -21,60 +21,60 @@ function He(e) {
21
21
  spec: e.spec,
22
22
  context: e.context,
23
23
  renderElement: n
24
- }) : o({
24
+ }) : r({
25
25
  elementId: i,
26
26
  element: s,
27
27
  spec: e.spec,
28
28
  context: e.context,
29
29
  renderElement: n
30
30
  });
31
- }, r = n(e.spec.root);
32
- return r && t.appendChild(r), t;
31
+ }, o = n(e.spec.root);
32
+ return o && t.appendChild(o), t;
33
33
  }
34
- function ze(e, t) {
34
+ function Ue(e, t) {
35
35
  if (!t) return e;
36
- const o = { ...e };
37
- for (const [n, r] of Object.entries(t))
38
- r && (o[n] = r);
39
- return o;
36
+ const r = { ...e };
37
+ for (const [n, o] of Object.entries(t))
38
+ o && (r[n] = o);
39
+ return r;
40
40
  }
41
41
  function v(e) {
42
42
  return typeof e == "object" && e !== null && typeof e.type == "string";
43
43
  }
44
- function z(e) {
44
+ function G(e) {
45
45
  const t = [];
46
- let o = 0, n = !1, r = !1, i = 0;
46
+ let r = 0, n = !1, o = !1, i = 0;
47
47
  for (let s = 0; s < e.length; s++) {
48
48
  const a = e[s];
49
- if (r) {
50
- r = !1;
49
+ if (o) {
50
+ o = !1;
51
51
  continue;
52
52
  }
53
53
  if (a === "\\" && n) {
54
- r = !0;
54
+ o = !0;
55
55
  continue;
56
56
  }
57
57
  if (a === '"') {
58
58
  n = !n;
59
59
  continue;
60
60
  }
61
- n || (a === "{" && o++, a === "}" && (o--, o === 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 N(e, t) {
66
- const o = e.trim();
67
- if (!o || o.startsWith(":")) return !1;
68
- const n = o.startsWith("data: ") ? o.slice(6) : o;
65
+ function I(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
69
  if (n === "[DONE]")
70
70
  return t.onDone?.(), !0;
71
71
  try {
72
- const r = JSON.parse(n);
73
- return v(r) ? (U("stream", `event: ${r.type}`, r), t.onEvent(r), r.type === "done" ? (t.onDone?.(), !0) : !1) : !1;
72
+ const o = JSON.parse(n);
73
+ return v(o) ? (U("stream", `event: ${o.type}`, o), t.onEvent(o), o.type === "done" ? (t.onDone?.(), !0) : !1) : !1;
74
74
  } catch {
75
- const r = z(n);
76
- if (r.length > 1) {
77
- for (const i of r) try {
75
+ const o = G(n);
76
+ if (o.length > 1) {
77
+ for (const i of o) try {
78
78
  const s = JSON.parse(i);
79
79
  if (!v(s)) continue;
80
80
  if (t.onEvent(s), s.type === "done")
@@ -86,7 +86,7 @@ function N(e, t) {
86
86
  return !1;
87
87
  }
88
88
  }
89
- async function G(e, t) {
89
+ async function j(e, t) {
90
90
  if (!e.ok) {
91
91
  t.onError?.(/* @__PURE__ */ new Error(`HTTP ${e.status}: ${e.statusText}`));
92
92
  return;
@@ -95,107 +95,106 @@ async function G(e, t) {
95
95
  t.onError?.(/* @__PURE__ */ new Error("Response body is null — streaming not supported"));
96
96
  return;
97
97
  }
98
- const o = e.body.getReader(), n = new TextDecoder("utf-8");
99
- let r = "";
98
+ const r = e.body.getReader(), n = new TextDecoder("utf-8");
99
+ let o = "";
100
100
  const i = t.idleTimeoutMs ?? 6e4, s = /* @__PURE__ */ Symbol("idle-timeout");
101
101
  let a = !1;
102
102
  try {
103
103
  for (; ; ) {
104
- const c = o.read();
104
+ const c = r.read();
105
105
  let m;
106
- const g = await (i > 0 ? Promise.race([c.then((f) => (clearTimeout(m), f)), new Promise((f) => {
107
- m = setTimeout(() => f(s), i);
106
+ const _ = await (i > 0 ? Promise.race([c.then((g) => (clearTimeout(m), g)), new Promise((g) => {
107
+ m = setTimeout(() => g(s), i);
108
108
  })]) : c);
109
- if (g === s) {
110
- a = !0, await o.cancel();
109
+ if (_ === s) {
110
+ a = !0, await r.cancel();
111
111
  break;
112
112
  }
113
- const { done: l, value: p } = g;
114
- if (l) break;
115
- r += n.decode(p, { stream: !0 });
116
- const u = r.split(`
113
+ const { done: d, value: p } = _;
114
+ if (d) break;
115
+ o += n.decode(p, { stream: !0 });
116
+ const l = o.split(`
117
117
  `);
118
- r = u.pop() ?? "";
119
- for (const f of u) if (N(f, t)) return;
118
+ o = l.pop() ?? "";
119
+ for (const g of l) if (I(g, t)) return;
120
120
  }
121
- if (r.trim() && N(r, t))
121
+ if (o.trim() && I(o, t))
122
122
  return;
123
123
  } catch (c) {
124
124
  if (c instanceof DOMException && c.name === "AbortError") return;
125
125
  t.onError?.(c instanceof Error ? c : new Error(String(c)));
126
126
  } finally {
127
- a || o.releaseLock();
127
+ a || r.releaseLock();
128
128
  }
129
129
  t.onDone?.();
130
130
  }
131
- function Ge(e, t, o) {
132
- const n = new AbortController(), r = o.signal ? j([o.signal, n.signal]) : n.signal;
131
+ function ze(e, t, r) {
132
+ const n = new AbortController(), o = r.signal ? M([r.signal, n.signal]) : n.signal;
133
133
  return fetch(e, {
134
134
  method: "POST",
135
135
  headers: {
136
136
  "Content-Type": "application/json",
137
- ...o.headers
137
+ ...r.headers
138
138
  },
139
139
  body: JSON.stringify(t),
140
- signal: r
141
- }).then((i) => G(i, {
142
- ...o,
143
- signal: r
140
+ signal: o
141
+ }).then((i) => j(i, {
142
+ ...r,
143
+ signal: o
144
144
  })).catch((i) => {
145
- i instanceof DOMException && i.name === "AbortError" || o.onError?.(i instanceof Error ? i : new Error(String(i)));
145
+ i instanceof DOMException && i.name === "AbortError" || r.onError?.(i instanceof Error ? i : new Error(String(i)));
146
146
  }), n;
147
147
  }
148
- function j(e) {
149
- const t = new AbortController(), o = [];
148
+ function M(e) {
149
+ const t = new AbortController(), r = [];
150
150
  for (const n of e) {
151
151
  if (n.aborted)
152
152
  return t.abort(n.reason), t.signal;
153
- const r = () => t.abort(n.reason);
154
- n.addEventListener("abort", r, { once: !0 }), o.push(() => n.removeEventListener("abort", r));
153
+ const o = () => t.abort(n.reason);
154
+ n.addEventListener("abort", o, { once: !0 }), r.push(() => n.removeEventListener("abort", o));
155
155
  }
156
156
  return t.signal.addEventListener("abort", () => {
157
- for (const n of o) n();
157
+ for (const n of r) n();
158
158
  }, { once: !0 }), t.signal;
159
159
  }
160
- var I = 3, M = (e, t) => {
161
- const o = e.replace(/\s+/g, " ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g, "");
162
- if (!o) return "";
163
- const n = t?.stripLeadingStopWords ? o.replace(/^(?:daha|için)\s+/i, "").trim() : o;
160
+ var N = 3, $ = (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
164
  return n ? n.split(/\s+/).slice(0, 3).join(" ").trim() : "";
165
- }, x = (e, t) => e ? e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map((o) => M(o, t)).filter(Boolean) : [];
166
- function $(e) {
167
- const t = (e.display_keywords ?? []).flatMap((r) => x(r, { stripLeadingStopWords: !0 })), o = t.filter((r, i) => t.indexOf(r) === i);
168
- if (o.length > 0) return o.slice(0, I);
165
+ }, x = (e, t) => e ? e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map((r) => $(r, t)).filter(Boolean) : [];
166
+ function B(e) {
167
+ const t = (e.display_keywords ?? []).flatMap((o) => x(o, { stripLeadingStopWords: !0 })), r = t.filter((o, i) => t.indexOf(o) === i);
168
+ if (r.length > 0) return r.slice(0, N);
169
169
  const n = [...x(e.chosen_attribute, { stripLeadingStopWords: !0 }), ...x(e.short_name)];
170
- return n.filter((r, i) => n.indexOf(r) === i).slice(0, I);
170
+ return n.filter((o, i) => n.indexOf(o) === i).slice(0, N);
171
171
  }
172
- function B(e) {
173
- return $(e).join(" • ");
172
+ function K(e) {
173
+ return B(e).join(" • ");
174
174
  }
175
- var K = ["beauty_consulting", "watch_expert"];
176
175
  function V(e) {
177
- return typeof e == "string" && K.includes(e);
176
+ return e === "beauty_consulting" || e === "account_expert";
178
177
  }
179
178
  function P(...e) {
180
179
  for (const t of e) {
181
180
  if (typeof t != "string") continue;
182
- const o = t.trim();
183
- if (o.length > 0) return o;
181
+ const r = t.trim();
182
+ if (r.length > 0) return r;
184
183
  }
185
184
  }
186
185
  function C(e) {
187
186
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0).map((t) => t.trim()) : [];
188
187
  }
189
188
  function R(e) {
190
- const t = { ...e }, o = P(t.sku), n = C(t.group_skus);
191
- if (o ? t.sku = o : delete t.sku, n.length > 0 ? t.group_skus = n : delete t.group_skus, o || n.length > 0) delete t.image_url;
189
+ const t = { ...e }, r = P(t.sku), n = C(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;
192
191
  else {
193
- const r = P(t.image_url);
194
- r ? t.image_url = r : delete t.image_url;
192
+ const o = P(t.image_url);
193
+ o ? t.image_url = o : delete t.image_url;
195
194
  }
196
195
  return t;
197
196
  }
198
- function je(e) {
197
+ function Ge(e) {
199
198
  if (typeof e.type != "string") return null;
200
199
  if (W(e)) return e;
201
200
  const t = e;
@@ -213,7 +212,7 @@ function je(e) {
213
212
  case "comparisonTable":
214
213
  return Z(t);
215
214
  case "context":
216
- return oe(t);
215
+ return re(t);
217
216
  case "chatStreamEnd":
218
217
  return ne();
219
218
  case "loading":
@@ -268,7 +267,7 @@ function je(e) {
268
267
  case "handoff":
269
268
  return Pe(t);
270
269
  case "uiSpec":
271
- return De(t);
270
+ return Le(t);
272
271
  default:
273
272
  return null;
274
273
  }
@@ -282,14 +281,14 @@ function W(e) {
282
281
  case "text_chunk":
283
282
  return typeof e.content == "string";
284
283
  case "ui_spec": {
285
- const o = e.widget;
286
- if (o !== "chat" && o !== "qna" && o !== "simrel") return !1;
287
- const n = h(e.spec);
288
- return n ? typeof n.root == "string" && h(n.elements) !== null : !1;
284
+ const r = e.widget;
285
+ if (r !== "chat" && r !== "qna" && r !== "simrel") return !1;
286
+ const n = k(e.spec);
287
+ return n ? typeof n.root == "string" && k(n.elements) !== null : !1;
289
288
  }
290
289
  case "action": {
291
- const o = h(e.action);
292
- return o !== null && typeof o.kind == "string";
290
+ const r = k(e.action);
291
+ return r !== null && typeof r.kind == "string";
293
292
  }
294
293
  case "error":
295
294
  return typeof e.code == "string" && typeof e.message == "string";
@@ -300,18 +299,18 @@ function W(e) {
300
299
  }
301
300
  }
302
301
  function F(e) {
303
- const t = d(e.payload.text, e.payload.plain_text) ?? "", o = d(e.payload.plain_text, e.payload.text) ?? t;
302
+ const t = u(e.payload.text, e.payload.plain_text) ?? "", r = u(e.payload.plain_text, e.payload.text) ?? t;
304
303
  if (e.payload.is_error) return {
305
304
  type: "error",
306
305
  code: "BACKEND_ERROR",
307
- message: o || "Backend returned an error"
306
+ message: r || "Backend returned an error"
308
307
  };
309
308
  const n = {
310
309
  type: "text_chunk",
311
310
  content: t,
312
311
  final: !0
313
- }, r = e.payload.product_mentions;
314
- Array.isArray(r) && r.length > 0 && (n.productMentions = r.filter((c) => typeof c == "object" && c !== null && typeof c.sku == "string" && typeof c.short_name == "string"));
312
+ }, o = e.payload.product_mentions;
313
+ Array.isArray(o) && o.length > 0 && (n.productMentions = o.filter((c) => typeof c == "object" && c !== null && typeof c.sku == "string" && typeof c.short_name == "string"));
315
314
  const i = e.payload.sku_to_product_item;
316
315
  i && typeof i == "object" && !Array.isArray(i) && (n.skuToProductItem = i);
317
316
  const s = e.payload.conversation_mode;
@@ -321,36 +320,36 @@ function F(e) {
321
320
  }
322
321
  function Q(e) {
323
322
  return q((e.payload.actions ?? []).map((t) => {
324
- const o = d(t.title) ?? "", n = b(t.requestDetails, o), r = n ? {
325
- label: o,
323
+ const r = u(t.title) ?? "", n = b(t.requestDetails, r), o = n ? {
324
+ label: r,
326
325
  action: n
327
326
  } : null;
328
- return r ? (typeof t.icon == "string" && (r.icon = t.icon), typeof t.image == "string" && (r.image = t.image), r) : null;
327
+ return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
329
328
  }).filter(A), "chat");
330
329
  }
331
330
  function J(e) {
332
331
  const t = (Array.isArray(e.payload.style_variations) ? e.payload.style_variations : []).map((s) => {
333
- const a = d(s.style_label);
332
+ const a = u(s.style_label);
334
333
  if (!a) return null;
335
- const c = d(s.style_mood), m = d(s.image_url ?? void 0), g = (Array.isArray(s.product_list) ? s.product_list : []).map((p) => {
336
- const u = h(p);
337
- return u ? E(h(u.product_detail) ?? h(u.product) ?? u) : null;
338
- }).filter(A), l = Array.isArray(s.recommendation_groups) ? s.recommendation_groups.map((p) => ({
339
- label: d(p.label) ?? "",
340
- reason: d(p.reason) ?? "",
341
- skus: Array.isArray(p.skus) ? p.skus.filter((u) => typeof u == "string" && u.trim().length > 0) : []
334
+ const c = u(s.style_mood), m = u(s.image_url ?? void 0), _ = (Array.isArray(s.product_list) ? s.product_list : []).map((p) => {
335
+ const l = k(p);
336
+ return l ? E(k(l.product_detail) ?? k(l.product) ?? l) : null;
337
+ }).filter(A), d = Array.isArray(s.recommendation_groups) ? s.recommendation_groups.map((p) => ({
338
+ label: u(p.label) ?? "",
339
+ reason: u(p.reason) ?? "",
340
+ skus: Array.isArray(p.skus) ? p.skus.filter((l) => typeof l == "string" && l.trim().length > 0) : []
342
341
  })) : [];
343
342
  return {
344
343
  style_label: a,
345
344
  style_mood: c ?? "",
346
345
  ...m ? { image_url: m } : {},
347
346
  ...typeof s.status == "string" ? { status: s.status } : {},
348
- product_list: g,
349
- recommendation_groups: l
347
+ product_list: _,
348
+ recommendation_groups: d
350
349
  };
351
- }).filter(A), o = e.payload.product_list ?? [], n = V(e.payload.source) && t.length > 0 ? t[0].product_list : null, r = n ? Te(n, "chat") : O(o, "chat");
352
- r.panelHint = "panel";
353
- const i = r.spec.elements[r.spec.root];
350
+ }).filter(A), r = e.payload.product_list ?? [], n = V(e.payload.source) && t.length > 0 ? t[0].product_list : null, o = n ? Te(n, "chat") : O(r, "chat");
351
+ o.panelHint = "panel";
352
+ const i = o.spec.elements[o.spec.root];
354
353
  if (i) {
355
354
  const s = {};
356
355
  typeof e.payload.offset == "number" && (s.offset = e.payload.offset), typeof e.payload.end_of_list == "boolean" && (s.endOfList = e.payload.end_of_list), typeof e.payload.title == "string" && (s.panelTitle = e.payload.title), typeof e.payload.source == "string" && (s.source = e.payload.source), t.length > 0 && (s.styleVariations = t), e.payload.replace_panel === !0 && (s.replacePanel = !0), (e.payload.ranking_state === "pending" || e.payload.ranking_state === "final") && (s.rankingState = e.payload.ranking_state);
@@ -360,12 +359,12 @@ function J(e) {
360
359
  ...s
361
360
  });
362
361
  }
363
- return r;
362
+ return o;
364
363
  }
365
364
  function Y(e) {
366
365
  const t = e.payload.productDetails;
367
366
  if (!t) return ve("chat");
368
- const o = w(t);
367
+ const r = w(t);
369
368
  return {
370
369
  type: "ui_spec",
371
370
  widget: "chat",
@@ -375,7 +374,7 @@ function Y(e) {
375
374
  type: "ProductDetailsPanel",
376
375
  props: { product: {
377
376
  ...t,
378
- ...o
377
+ ...r
379
378
  } }
380
379
  } }
381
380
  },
@@ -383,9 +382,9 @@ function Y(e) {
383
382
  };
384
383
  }
385
384
  function X(e) {
386
- const t = O(e.payload.similarProducts ?? [], "chat"), o = t.spec.elements[t.spec.root];
387
- return o && (o.props = {
388
- ...o.props,
385
+ const t = O(e.payload.similarProducts ?? [], "chat"), r = t.spec.elements[t.spec.root];
386
+ return r && (r.props = {
387
+ ...r.props,
389
388
  similarsAppend: !0
390
389
  }), {
391
390
  ...t,
@@ -393,103 +392,103 @@ function X(e) {
393
392
  };
394
393
  }
395
394
  function Z(e) {
396
- const t = e.payload.multiple_product_details ?? [], o = e.payload, n = {
397
- key_differences: o.key_differences,
398
- recommended_choice: o.recommended_choice,
399
- recommended_choice_sku: o.recommended_choice_sku,
400
- special_considerations: o.special_considerations,
401
- criteria_view: o.criteria_view,
402
- criteria_view_short: o.criteria_view_short,
403
- compared_field_names: o.compared_field_names,
404
- winner_product: o.winner_product,
405
- winner_hits: o.winner_hits,
395
+ const t = e.payload.multiple_product_details ?? [], r = e.payload, n = {
396
+ key_differences: r.key_differences,
397
+ recommended_choice: r.recommended_choice,
398
+ recommended_choice_sku: r.recommended_choice_sku,
399
+ special_considerations: r.special_considerations,
400
+ criteria_view: r.criteria_view,
401
+ criteria_view_short: r.criteria_view_short,
402
+ compared_field_names: r.compared_field_names,
403
+ winner_product: r.winner_product,
404
+ winner_hits: r.winner_hits,
406
405
  ...e.payload.product_comparison_framework ?? {}
407
- }, r = e.payload.table, i = e.payload.features_list, s = [];
408
- for (const _ of t) {
409
- const k = w(_);
410
- s.push(k);
406
+ }, o = e.payload.table, i = e.payload.features_list, s = [];
407
+ for (const y of t) {
408
+ const h = w(y);
409
+ s.push(h);
411
410
  }
412
- const a = ee(r, s, n, i);
411
+ const a = ee(o, s, n, i);
413
412
  let c;
414
413
  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);
415
- const m = c ? s.find((_) => _.sku === c) ?? s[0] : s[0], g = [];
414
+ const m = c ? s.find((y) => y.sku === c) ?? s[0] : s[0], _ = [];
416
415
  if (Array.isArray(n?.key_differences))
417
- for (const _ of n.key_differences) typeof _ == "string" && g.push(_);
418
- const l = Re(n?.special_considerations), p = n?.recommended_choice, u = n?.winner_hits, f = {};
419
- for (const _ of s) {
420
- const k = _.sku;
421
- k && (f[k] = {
422
- title: _.name ?? k,
416
+ for (const y of n.key_differences) typeof y == "string" && _.push(y);
417
+ const d = H(n?.special_considerations), p = n?.recommended_choice, l = n?.winner_hits, g = {};
418
+ for (const y of s) {
419
+ const h = y.sku;
420
+ h && (g[h] = {
421
+ title: y.name ?? h,
423
422
  type: "launchSingleProduct",
424
- payload: { sku: k }
423
+ payload: { sku: h }
425
424
  });
426
425
  }
427
- const y = {
426
+ const f = {
428
427
  products: s,
429
428
  attributes: a,
430
- highlights: g,
431
- productActions: f
429
+ highlights: _,
430
+ productActions: g
432
431
  };
433
- return m && (y.recommended = m), l.length > 0 && (y.specialCases = l), p && (y.recommendedText = p), u && (y.winnerHits = u), typeof n?.key_differences == "string" && (y.keyDifferencesHtml = n.key_differences), n?.special_considerations && (y.specialConsiderations = n.special_considerations), {
432
+ return m && (f.recommended = m), d.length > 0 && (f.specialCases = d), p && (f.recommendedText = p), l && (f.winnerHits = l), typeof n?.key_differences == "string" && (f.keyDifferencesHtml = n.key_differences), n?.special_considerations && (f.specialConsiderations = n.special_considerations), {
434
433
  type: "ui_spec",
435
434
  widget: "chat",
436
435
  spec: {
437
436
  root: "root",
438
437
  elements: { root: {
439
438
  type: "ComparisonTable",
440
- props: y
439
+ props: f
441
440
  } }
442
441
  },
443
442
  panelHint: "panel"
444
443
  };
445
444
  }
446
- function ee(e, t, o, n) {
445
+ function ee(e, t, r, n) {
447
446
  if (!e) return [];
448
- const r = Object.entries(e);
449
- if (r.length === 0) return [];
450
- const i = r[0]?.[1];
447
+ const o = Object.entries(e);
448
+ if (o.length === 0) return [];
449
+ const i = o[0]?.[1];
451
450
  if (Array.isArray(i)) {
452
- const l = o.criteria_view ?? o.criteria_view_short ?? {}, p = o.compared_field_names ?? Object.keys(e), u = [];
453
- for (const f of p) {
454
- const y = e[f];
455
- if (!y || !Array.isArray(y)) continue;
456
- const _ = l[f] ?? f;
457
- u.push({
458
- label: _,
459
- values: y.map((k) => typeof k == "string" ? k : String(k ?? ""))
451
+ const d = r.criteria_view ?? r.criteria_view_short ?? {}, p = r.compared_field_names ?? Object.keys(e), l = [];
452
+ for (const g of p) {
453
+ const f = e[g];
454
+ if (!f || !Array.isArray(f)) continue;
455
+ const y = d[g] ?? g;
456
+ l.push({
457
+ label: y,
458
+ values: f.map((h) => typeof h == "string" ? h : String(h ?? ""))
460
459
  });
461
460
  }
462
- return u;
461
+ return l;
463
462
  }
464
- const s = e, a = t.map((l) => String(l.sku ?? "")).filter((l) => l.length > 0), c = o.criteria_view ?? o.criteria_view_short ?? {}, m = (n && n.length > 0 ? n : o.compared_field_names && o.compared_field_names.length > 0 ? o.compared_field_names : te(s)).filter((l) => l !== "name" && l !== "name_short" && !l.endsWith("_short")), g = [];
465
- for (const l of m) {
466
- const p = a.map((f) => {
467
- const y = s[f];
468
- if (!y || typeof y != "object") return "";
469
- const _ = y[`${l}_short`], k = y[l];
470
- return re(_ ?? k);
463
+ const s = e, a = t.map((d) => String(d.sku ?? "")).filter((d) => d.length > 0), c = r.criteria_view ?? r.criteria_view_short ?? {}, m = (n && n.length > 0 ? n : r.compared_field_names && r.compared_field_names.length > 0 ? r.compared_field_names : te(s)).filter((d) => d !== "name" && d !== "name_short" && !d.endsWith("_short")), _ = [];
464
+ for (const d of m) {
465
+ const p = a.map((g) => {
466
+ const f = s[g];
467
+ if (!f || typeof f != "object") return "";
468
+ const y = f[`${d}_short`], h = f[d];
469
+ return oe(y ?? h);
471
470
  });
472
- if (p.every((f) => f.length === 0)) continue;
473
- const u = c[l] ?? l;
474
- g.push({
475
- label: u,
471
+ if (p.every((g) => g.length === 0)) continue;
472
+ const l = c[d] ?? d;
473
+ _.push({
474
+ label: l,
476
475
  values: p
477
476
  });
478
477
  }
479
- return g;
478
+ return _;
480
479
  }
481
480
  function te(e) {
482
- const t = [], o = /* @__PURE__ */ new Set();
481
+ const t = [], r = /* @__PURE__ */ new Set();
483
482
  for (const n of Object.values(e))
484
483
  if (!(!n || typeof n != "object"))
485
- for (const r of Object.keys(n))
486
- o.has(r) || (o.add(r), t.push(r));
484
+ for (const o of Object.keys(n))
485
+ r.has(o) || (r.add(o), t.push(o));
487
486
  return t;
488
487
  }
489
- function re(e) {
488
+ function oe(e) {
490
489
  return typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "";
491
490
  }
492
- function oe(e) {
491
+ function re(e) {
493
492
  return {
494
493
  type: "metadata",
495
494
  sessionId: "",
@@ -544,7 +543,7 @@ function ae(e) {
544
543
  };
545
544
  }
546
545
  function ce(e) {
547
- const t = d(e.payload.url);
546
+ const t = u(e.payload.url);
548
547
  return t ? {
549
548
  type: "action",
550
549
  action: {
@@ -558,7 +557,7 @@ function ce(e) {
558
557
  model: "",
559
558
  meta: {
560
559
  redirect: e.payload,
561
- redirectTarget: d(e.payload.to)
560
+ redirectTarget: u(e.payload.to)
562
561
  }
563
562
  };
564
563
  }
@@ -566,7 +565,7 @@ function ue(e) {
566
565
  return {
567
566
  type: "error",
568
567
  code: "BACKEND_ERROR",
569
- message: d(e.payload?.text, e.payload?.message, e.payload?.error) ?? "Backend returned an error"
568
+ message: u(e.payload?.text, e.payload?.message, e.payload?.error) ?? "Backend returned an error"
570
569
  };
571
570
  }
572
571
  function de(e) {
@@ -580,26 +579,26 @@ function de(e) {
580
579
  function le(e) {
581
580
  const t = e.payload ?? {};
582
581
  if (Array.isArray(t.action_list)) {
583
- const r = { action_list: t.action_list }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0;
584
- return i !== void 0 && (r.type = i), s !== void 0 && (r.theme = s), D({
582
+ 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;
583
+ return i !== void 0 && (o.type = i), s !== void 0 && (o.theme = s), D({
585
584
  type: "quick_qna",
586
- payload: r
585
+ payload: o
587
586
  });
588
587
  }
589
- const o = h(t.action);
590
- if (o) {
591
- const r = { action: o }, 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;
592
- return i !== void 0 && (r.text = i), s !== void 0 && (r.image_url = s), a !== void 0 && (r.theme = a), L({
588
+ const r = k(t.action);
589
+ if (r) {
590
+ 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;
591
+ return i !== void 0 && (o.text = i), s !== void 0 && (o.image_url = s), a !== void 0 && (o.theme = a), L({
593
592
  type: "text_image",
594
- payload: r
593
+ payload: o
595
594
  });
596
595
  }
597
596
  const n = typeof t.text == "string" ? t.text : "";
598
597
  if (n) {
599
- const r = { text: n }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0, a = h(t.payload) ?? void 0;
600
- return i !== void 0 && (r.type = i), a !== void 0 && (r.payload = a), s !== void 0 && (r.theme = s), T({
598
+ const o = { text: n }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0, a = k(t.payload) ?? void 0;
599
+ return i !== void 0 && (o.type = i), a !== void 0 && (o.payload = a), s !== void 0 && (o.theme = s), T({
601
600
  type: "text",
602
- payload: r
601
+ payload: o
603
602
  });
604
603
  }
605
604
  return {
@@ -610,7 +609,7 @@ function le(e) {
610
609
  };
611
610
  }
612
611
  function T(e) {
613
- const t = { text: d(e.payload.text) ?? "" };
612
+ const t = { text: u(e.payload.text) ?? "" };
614
613
  return typeof e.payload.theme == "string" && (t.theme = e.payload.theme), e.payload.payload !== void 0 && (t.payload = e.payload.payload), {
615
614
  type: "ui_spec",
616
615
  widget: "qna",
@@ -627,20 +626,20 @@ function pe(e) {
627
626
  return Ee(e.payload, "qna");
628
627
  }
629
628
  function L(e) {
630
- const t = d(e.payload.text) ?? "", o = b(e.payload.action, t);
631
- if (o) {
632
- const r = {
633
- label: t || o.title,
634
- action: o
629
+ const t = u(e.payload.text) ?? "", r = b(e.payload.action, t);
630
+ if (r) {
631
+ const o = {
632
+ label: t || r.title,
633
+ action: r
635
634
  };
636
- return typeof e.payload.image_url == "string" && (r.image = e.payload.image_url), typeof e.payload.theme == "string" && (r.theme = e.payload.theme), {
635
+ return typeof e.payload.image_url == "string" && (o.image = e.payload.image_url), typeof e.payload.theme == "string" && (o.theme = e.payload.theme), {
637
636
  type: "ui_spec",
638
637
  widget: "qna",
639
638
  spec: {
640
639
  root: "root",
641
640
  elements: { root: {
642
641
  type: "ActionButton",
643
- props: r
642
+ props: o
644
643
  } }
645
644
  }
646
645
  };
@@ -653,17 +652,17 @@ function L(e) {
653
652
  }
654
653
  function D(e) {
655
654
  return q((e.payload.action_list ?? []).map((t) => {
656
- const o = d(t.title) ?? "", n = b(t.requestDetails, o), r = n ? {
657
- label: o,
655
+ const r = u(t.title) ?? "", n = b(t.requestDetails, r), o = n ? {
656
+ label: r,
658
657
  action: n
659
658
  } : null;
660
- return r ? (typeof t.icon == "string" && (r.icon = t.icon), typeof t.image == "string" && (r.image = t.image), r) : null;
659
+ return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
661
660
  }).filter(A), "qna");
662
661
  }
663
662
  function fe(e) {
664
- const t = { reviews: (e.payload.reviews ?? []).map((o) => {
663
+ const t = { reviews: (e.payload.reviews ?? []).map((r) => {
665
664
  const n = {};
666
- return typeof o.review_class == "string" && (n.review_class = o.review_class), typeof o.review_text == "string" && (n.review_text = o.review_text), (typeof o.review_rating == "string" || typeof o.review_rating == "number") && (n.review_rating = o.review_rating), typeof o.review_tag == "string" && (n.review_tag = o.review_tag), n;
665
+ 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;
667
666
  }) };
668
667
  return typeof e.payload.sku == "string" && (t.sku = e.payload.sku), {
669
668
  type: "ui_spec",
@@ -700,16 +699,16 @@ function ge(e) {
700
699
  };
701
700
  }
702
701
  function me(e) {
703
- const t = e.payload.product_suggestions ?? [], o = [];
702
+ const t = e.payload.product_suggestions ?? [], r = [];
704
703
  for (let n = 0; n < t.length; n++) {
705
- const r = t[n];
706
- if (!r) continue;
707
- const i = Ne(r);
704
+ const o = t[n];
705
+ if (!o) continue;
706
+ const i = Ie(o);
708
707
  if (!i) continue;
709
- const s = { product: i }, a = b(r.requestDetails, i.name);
710
- a && (s.action = a), typeof r.role == "string" && (s.role = r.role), typeof r.reason == "string" && (s.reason = r.reason), typeof r.review_highlight == "string" && (s.reviewHighlight = r.review_highlight), Array.isArray(r.labels) && (s.labels = r.labels), typeof r.expert_quality_score == "number" && (s.expertQualityScore = r.expert_quality_score), o.push(s);
708
+ const s = { product: i }, a = b(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);
711
710
  }
712
- return o.length === 0 ? {
711
+ return r.length === 0 ? {
713
712
  type: "metadata",
714
713
  sessionId: "",
715
714
  model: "",
@@ -721,46 +720,42 @@ function me(e) {
721
720
  root: "root",
722
721
  elements: { root: {
723
722
  type: "AITopPicks",
724
- props: { suggestions: o }
723
+ props: { suggestions: r }
725
724
  } }
726
725
  }
727
726
  };
728
727
  }
729
728
  function _e(e) {
730
- const t = e.payload.product_groupings ?? [], o = [], n = [];
731
- for (let r = 0; r < t.length; r++) {
732
- const i = t[r];
729
+ const t = e.payload.product_groupings ?? [], r = [], n = [];
730
+ for (let o = 0; o < t.length; o++) {
731
+ const i = t[o];
733
732
  if (!i) continue;
734
- const s = d(i.name) ?? "", a = d(i.sku, i.repr_sku), c = d(i.image, i.repr_image), m = he(i, s, a), g = (Array.isArray(i.group_products) ? i.group_products : []).map((u) => {
735
- const f = h(u);
736
- return f ? E(f) : null;
737
- }).filter(A), l = c ?? d(...g.map((u) => u.imageUrl));
738
- if (s && g.length > 0) {
739
- const u = {
733
+ const s = u(i.name) ?? "", a = u(i.description), c = u(i.highlight), m = Array.isArray(i.labels) ? H(i.labels) : [], _ = u(i.sku, i.repr_sku), d = u(i.image, i.repr_image), p = he(i, s, _), l = (Array.isArray(i.group_products) ? i.group_products : []).map((y) => {
734
+ const h = k(y);
735
+ return h ? E(h) : null;
736
+ }).filter(A), g = d ?? u(...l.map((y) => y.imageUrl));
737
+ if (s && l.length > 0) {
738
+ const y = {
740
739
  groupName: s,
741
- products: g
740
+ products: l
742
741
  };
743
- l && (u.image = l), o.push(u);
742
+ g && (y.image = g), a && (y.description = a), c && (y.highlight = c), m.length > 0 && (y.labels = m), r.push(y);
744
743
  }
745
- if (!m) continue;
746
- const p = {
744
+ if (!p) continue;
745
+ const f = {
747
746
  name: s,
748
- action: m
747
+ action: p
749
748
  };
750
- if (Array.isArray(i.labels)) {
751
- const u = i.labels.filter((f) => typeof f == "string");
752
- u.length > 0 && (p.labels = u);
753
- }
754
- c !== void 0 && (p.image = c), n.push(p);
749
+ m.length > 0 && (f.labels = m), d !== void 0 && (f.image = d), n.push(f);
755
750
  }
756
- return o.length > 0 ? {
751
+ return r.length > 0 ? {
757
752
  type: "ui_spec",
758
753
  widget: "chat",
759
754
  spec: {
760
755
  root: "root",
761
756
  elements: { root: {
762
757
  type: "CategoriesContainer",
763
- props: { groups: o }
758
+ props: { groups: r }
764
759
  } }
765
760
  },
766
761
  panelHint: "panel"
@@ -781,51 +776,51 @@ function _e(e) {
781
776
  }
782
777
  };
783
778
  }
784
- function he(e, t, o) {
785
- const n = h(e.requestDetails);
779
+ function he(e, t, r) {
780
+ const n = k(e.requestDetails);
786
781
  if (n) {
787
782
  if (n.type !== "findSimilar") return b(n, t);
788
- const s = { ...h(n.payload) ?? {} };
789
- o && !P(s.sku) && (s.sku = o);
783
+ const s = { ...k(n.payload) ?? {} };
784
+ r && !P(s.sku) && (s.sku = r);
790
785
  const a = C(e.group_skus);
791
786
  return a.length > 0 && (s.group_skus = a), b({
792
787
  ...n,
793
788
  payload: R(s)
794
789
  }, t);
795
790
  }
796
- const r = {};
797
- o && (r.sku = o);
791
+ const o = {};
792
+ r && (o.sku = r);
798
793
  const i = C(e.group_skus);
799
- return i.length > 0 && (r.group_skus = i), Object.keys(r).length === 0 ? null : b({
794
+ return i.length > 0 && (o.group_skus = i), Object.keys(o).length === 0 ? null : b({
800
795
  type: "findSimilar",
801
- payload: R(r)
796
+ payload: R(o)
802
797
  }, t);
803
798
  }
804
799
  function ke(e) {
805
- const t = e.payload.suggested_searches ?? [], o = [];
800
+ const t = e.payload.suggested_searches ?? [], r = [];
806
801
  for (let n = 0; n < t.length; n++) {
807
- const r = t[n];
808
- if (!r) continue;
809
- const i = d(r.short_name, r.chosen_attribute, r.detailed_user_message) ?? `Search ${n + 1}`, s = {}, a = d(r.detailed_user_message);
802
+ const o = t[n];
803
+ if (!o) continue;
804
+ const i = u(o.short_name, o.chosen_attribute, o.detailed_user_message) ?? `Search ${n + 1}`, s = {}, a = u(o.detailed_user_message);
810
805
  a && (s.text = a);
811
- const c = h(h(r.requestDetails)?.payload), m = c?.group_skus;
812
- r.group_skus && Array.isArray(r.group_skus) ? s.group_skus = r.group_skus : Array.isArray(m) && (s.group_skus = m.filter((k) => typeof k == "string"));
813
- const g = d(r.sku, r.representative_product_sku, c?.sku);
814
- g && (s.sku = g), s.is_suggested_text = 1;
815
- const l = {
806
+ const c = k(k(o.requestDetails)?.payload), m = c?.group_skus;
807
+ o.group_skus && Array.isArray(o.group_skus) ? s.group_skus = o.group_skus : Array.isArray(m) && (s.group_skus = m.filter((h) => typeof h == "string"));
808
+ const _ = u(o.sku, o.representative_product_sku, c?.sku);
809
+ _ && (s.sku = _), s.is_suggested_text = 1;
810
+ const d = {
816
811
  type: "inputText",
817
812
  payload: s
818
- }, p = b(r.requestDetails, i), u = p?.type === "findSimilar" && typeof s.text == "string" ? b(l, i) : p ?? b(l, i);
819
- if (!u) continue;
820
- const f = {
813
+ }, p = b(o.requestDetails, i), l = p?.type === "findSimilar" && typeof s.text == "string" ? b(d, i) : p ?? b(d, i);
814
+ if (!l) continue;
815
+ const g = {
821
816
  shortName: i,
822
- action: u
823
- }, y = d(r.detailed_user_message);
824
- y && y !== i && (f.detailedMessage = y);
825
- const _ = B(r);
826
- _ && _ !== i && _ !== (y ?? "") && (f.whyDifferent = _), typeof r.image == "string" && (f.image = r.image), o.push(f);
817
+ action: l
818
+ }, f = u(o.detailed_user_message);
819
+ f && f !== i && (g.detailedMessage = f);
820
+ const y = K(o);
821
+ y && y !== i && y !== (f ?? "") && (g.whyDifferent = y), typeof o.image == "string" && (g.image = o.image), r.push(g);
827
822
  }
828
- return o.length === 0 ? {
823
+ return r.length === 0 ? {
829
824
  type: "metadata",
830
825
  sessionId: "",
831
826
  model: "",
@@ -837,20 +832,20 @@ function ke(e) {
837
832
  root: "root",
838
833
  elements: { root: {
839
834
  type: "AISuggestedSearchCards",
840
- props: { entries: o }
835
+ props: { entries: r }
841
836
  } }
842
837
  }
843
838
  };
844
839
  }
845
840
  function be(e) {
846
- const t = e.payload, o = b(t.requestDetails ?? t.request_details, d(t.review_count, t.reviewCount, t.text, t.title) ?? "Show product reviews");
847
- if (!o) return {
841
+ const t = e.payload, r = b(t.requestDetails ?? t.request_details, u(t.review_count, t.reviewCount, t.text, t.title) ?? "Show product reviews");
842
+ if (!r) return {
848
843
  type: "metadata",
849
844
  sessionId: "",
850
845
  model: "",
851
846
  meta: { groundingReview: t }
852
847
  };
853
- const n = { action: o };
848
+ const n = { action: r };
854
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), {
855
850
  type: "ui_spec",
856
851
  widget: "chat",
@@ -880,19 +875,19 @@ function Se(e) {
880
875
  };
881
876
  }
882
877
  function Ae(e) {
883
- const t = e.payload.group_list ?? [], o = [];
884
- for (const r of t) {
885
- const i = r.group_name ?? "", s = (r.product_list ?? []).map(w);
886
- o.push({
878
+ const t = e.payload.group_list ?? [], r = [];
879
+ for (const o of t) {
880
+ const i = o.group_name ?? "", s = (o.product_list ?? []).map(w);
881
+ r.push({
887
882
  groupName: i,
888
883
  products: s
889
884
  });
890
885
  }
891
886
  const n = [];
892
- for (const r of e.payload.filter_tags ?? []) {
893
- const i = r.title ?? "";
887
+ for (const o of e.payload.filter_tags ?? []) {
888
+ const i = o.title ?? "";
894
889
  if (!i) continue;
895
- const s = b(r.requestDetails, i), a = { title: i };
890
+ const s = b(o.requestDetails, i), a = { title: i };
896
891
  s && (a.action = s), n.push(a);
897
892
  }
898
893
  return {
@@ -903,7 +898,7 @@ function Ae(e) {
903
898
  elements: { root: {
904
899
  type: "CategoriesContainer",
905
900
  props: {
906
- groups: o,
901
+ groups: r,
907
902
  filterTags: n
908
903
  }
909
904
  } }
@@ -945,29 +940,29 @@ function Ce(e) {
945
940
  };
946
941
  }
947
942
  function q(e, t) {
948
- const o = {}, n = [];
949
- for (let r = 0; r < e.length; r++) {
950
- const i = e[r];
943
+ const r = {}, n = [];
944
+ for (let o = 0; o < e.length; o++) {
945
+ const i = e[o];
951
946
  if (!i) continue;
952
- const s = `action-${r}`;
947
+ const s = `action-${o}`;
953
948
  n.push(s);
954
949
  const a = {
955
950
  label: i.label,
956
951
  action: i.action
957
952
  };
958
- i.icon !== void 0 && (a.icon = i.icon), i.image !== void 0 && (a.image = i.image), i.description !== void 0 && (a.description = i.description), o[s] = {
953
+ 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] = {
959
954
  type: "ActionButton",
960
955
  props: a
961
956
  };
962
957
  }
963
- return o.root = {
958
+ return r.root = {
964
959
  type: "ActionButtons",
965
- props: { buttons: e.map((r) => {
960
+ props: { buttons: e.map((o) => {
966
961
  const i = {
967
- label: r.label,
968
- action: r.action
962
+ label: o.label,
963
+ action: o.action
969
964
  };
970
- return r.image !== void 0 && (i.image = r.image), r.description !== void 0 && (i.description = r.description), r.icon !== void 0 && (i.icon = r.icon), i;
965
+ 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;
971
966
  }) },
972
967
  children: n
973
968
  }, {
@@ -975,31 +970,31 @@ function q(e, t) {
975
970
  widget: t,
976
971
  spec: {
977
972
  root: "root",
978
- elements: o
973
+ elements: r
979
974
  }
980
975
  };
981
976
  }
982
977
  function O(e, t) {
983
- const o = {}, n = [];
984
- for (let r = 0; r < e.length; r++) {
985
- const i = e[r];
978
+ const r = {}, n = [];
979
+ for (let o = 0; o < e.length; o++) {
980
+ const i = e[o];
986
981
  if (!i) continue;
987
- const s = w(i), a = `product-${r}`;
982
+ const s = w(i), a = `product-${o}`;
988
983
  n.push(a);
989
984
  const c = {
990
985
  product: s,
991
- index: r
986
+ index: o
992
987
  };
993
988
  s.sku && (c.action = {
994
989
  title: s.name,
995
990
  type: "launchSingleProduct",
996
991
  payload: { sku: s.sku }
997
- }), o[a] = {
992
+ }), r[a] = {
998
993
  type: "ProductCard",
999
994
  props: c
1000
995
  };
1001
996
  }
1002
- return o.root = {
997
+ return r.root = {
1003
998
  type: "ProductGrid",
1004
999
  props: { layout: "grid" },
1005
1000
  children: n
@@ -1008,31 +1003,31 @@ function O(e, t) {
1008
1003
  widget: t,
1009
1004
  spec: {
1010
1005
  root: "root",
1011
- elements: o
1006
+ elements: r
1012
1007
  }
1013
1008
  };
1014
1009
  }
1015
1010
  function Te(e, t) {
1016
- const o = {}, n = [];
1017
- for (let r = 0; r < e.length; r++) {
1018
- const i = e[r];
1011
+ const r = {}, n = [];
1012
+ for (let o = 0; o < e.length; o++) {
1013
+ const i = e[o];
1019
1014
  if (!i) continue;
1020
- const s = `product-${r}`;
1015
+ const s = `product-${o}`;
1021
1016
  n.push(s);
1022
1017
  const a = {
1023
1018
  product: i,
1024
- index: r
1019
+ index: o
1025
1020
  }, c = i.sku;
1026
1021
  c && (a.action = {
1027
1022
  title: i.name ?? "",
1028
1023
  type: "launchSingleProduct",
1029
1024
  payload: { sku: c }
1030
- }), o[s] = {
1025
+ }), r[s] = {
1031
1026
  type: "ProductCard",
1032
1027
  props: a
1033
1028
  };
1034
1029
  }
1035
- return o.root = {
1030
+ return r.root = {
1036
1031
  type: "ProductGrid",
1037
1032
  props: { layout: "grid" },
1038
1033
  children: n
@@ -1041,7 +1036,7 @@ function Te(e, t) {
1041
1036
  widget: t,
1042
1037
  spec: {
1043
1038
  root: "root",
1044
- elements: o
1039
+ elements: r
1045
1040
  }
1046
1041
  };
1047
1042
  }
@@ -1075,63 +1070,63 @@ function ve(e) {
1075
1070
  }
1076
1071
  };
1077
1072
  }
1078
- function Ne(e) {
1079
- const t = d(e.sku), o = d(e.short_name), n = { ...h(e.product_item) ?? e }, r = d(e.discount_reason, e.discountReason);
1080
- return r && !d(n.discount_reason, n.discountReason) && (n.discount_reason = r), E(n, t, o);
1073
+ function Ie(e) {
1074
+ const t = u(e.sku), r = u(e.short_name), n = { ...k(e.product_item) ?? e }, o = u(e.discount_reason, e.discountReason);
1075
+ return o && !u(n.discount_reason, n.discountReason) && (n.discount_reason = o), E(n, t, r);
1081
1076
  }
1082
- function E(e, t, o) {
1083
- const n = d(e.sku, t), r = d(e.name, o);
1084
- if (!n || !r) return null;
1077
+ function E(e, t, r) {
1078
+ const n = u(e.sku, t), o = u(e.name, r);
1079
+ if (!n || !o) return null;
1085
1080
  const i = {
1086
1081
  sku: n,
1087
- name: r
1088
- }, s = d(e.brand);
1082
+ name: o
1083
+ }, s = u(e.brand);
1089
1084
  s && (i.brand = s);
1090
- const a = d(e.url);
1085
+ const a = u(e.url);
1091
1086
  a && (i.url = a);
1092
- const c = Ie(e.images);
1087
+ const c = Ne(e.images);
1093
1088
  if (c.length > 0) i.images = c;
1094
1089
  else {
1095
- const y = d(e.image, e.image_url, e.imageUrl);
1096
- y && (i.images = [y]);
1090
+ const f = u(e.image, e.image_url, e.imageUrl);
1091
+ f && (i.images = [f]);
1097
1092
  }
1098
1093
  const m = S(e.price_discounted);
1099
1094
  m !== void 0 && (i.price_discounted = m);
1100
- const g = S(e.price);
1101
- g !== void 0 && (i.price = g);
1102
- const l = S(e.rating);
1103
- l !== void 0 && (i.rating = l);
1095
+ const _ = S(e.price);
1096
+ _ !== void 0 && (i.price = _);
1097
+ const d = S(e.rating);
1098
+ d !== void 0 && (i.rating = d);
1104
1099
  const p = S(e.review_count) ?? S(e.reviewCount);
1105
1100
  p !== void 0 && (i.review_count = p);
1106
- const u = d(e.cart_code, e.cartCode);
1107
- u && (i.cart_code = u), typeof e.in_stock == "boolean" && (i.in_stock = e.in_stock), typeof e.inStock == "boolean" && (i.in_stock = e.inStock);
1108
- const f = d(e.discount_reason, e.discountReason);
1109
- return f && (i.discount_reason = f), w(i);
1101
+ const l = u(e.cart_code, e.cartCode);
1102
+ l && (i.cart_code = l), typeof e.in_stock == "boolean" && (i.in_stock = e.in_stock), typeof e.inStock == "boolean" && (i.in_stock = e.inStock);
1103
+ const g = u(e.discount_reason, e.discountReason);
1104
+ return g && (i.discount_reason = g), w(i);
1110
1105
  }
1111
1106
  function b(e, t) {
1112
- const o = h(e);
1113
- if (!o) return null;
1114
- const n = o.type;
1107
+ const r = k(e);
1108
+ if (!r) return null;
1109
+ const n = r.type;
1115
1110
  if (typeof n != "string" || n.length === 0) return null;
1116
- const r = {
1111
+ const o = {
1117
1112
  title: t || n,
1118
1113
  type: n
1119
1114
  };
1120
- return o.payload !== void 0 && (r.payload = o.payload), r;
1115
+ return r.payload !== void 0 && (o.payload = r.payload), o;
1121
1116
  }
1122
- function h(e) {
1117
+ function k(e) {
1123
1118
  return !e || typeof e != "object" || Array.isArray(e) ? null : e;
1124
1119
  }
1125
- function d(...e) {
1120
+ function u(...e) {
1126
1121
  for (const t of e) if (typeof t == "string") {
1127
- const o = t.trim();
1128
- if (o.length > 0) return o;
1122
+ const r = t.trim();
1123
+ if (r.length > 0) return r;
1129
1124
  }
1130
1125
  }
1131
- function Ie(e) {
1126
+ function Ne(e) {
1132
1127
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.length > 0) : [];
1133
1128
  }
1134
- function Re(e) {
1129
+ function H(e) {
1135
1130
  if (typeof e == "string") {
1136
1131
  const t = e.trim();
1137
1132
  return t ? [t] : [];
@@ -1143,14 +1138,14 @@ function S(e) {
1143
1138
  if (typeof e == "string") {
1144
1139
  let t;
1145
1140
  e.includes(".") && e.includes(",") ? t = e.replace(/\./g, "").replace(",", ".") : t = e.replace(",", ".");
1146
- const o = Number(t);
1147
- if (Number.isFinite(o)) return o;
1141
+ const r = Number(t);
1142
+ if (Number.isFinite(r)) return r;
1148
1143
  }
1149
1144
  }
1150
1145
  function A(e) {
1151
1146
  return e != null;
1152
1147
  }
1153
- var Le = /* @__PURE__ */ new Set([
1148
+ var Re = /* @__PURE__ */ new Set([
1154
1149
  "sku",
1155
1150
  "name",
1156
1151
  "brand",
@@ -1177,34 +1172,34 @@ var Le = /* @__PURE__ */ new Set([
1177
1172
  "promotions"
1178
1173
  ]);
1179
1174
  function w(e) {
1180
- const t = e.price_discounted != null && e.price_discounted > 0, o = t ? e.price_discounted : e.price, n = t && e.price != null ? e.price : void 0;
1181
- let r;
1182
- n != null && o != null && n > 0 ? r = Math.round((n - o) / n * 100) : e.price_discount_rate != null && e.price_discount_rate > 0 && (r = e.price_discount_rate);
1183
- const i = d(e.brand), s = d(e.name) ?? e.sku, a = i && !s.toLowerCase().startsWith(i.toLowerCase()) ? `${i} ${s}` : s, c = {
1175
+ 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;
1176
+ let o;
1177
+ 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);
1178
+ const i = u(e.brand), s = u(e.name) ?? e.sku, a = i && !s.toLowerCase().startsWith(i.toLowerCase()) ? `${i} ${s}` : s, c = {
1184
1179
  sku: e.sku,
1185
1180
  name: a,
1186
- url: d(e.url) ?? ""
1181
+ url: u(e.url) ?? ""
1187
1182
  }, m = e.images?.[0];
1188
- m && (c.imageUrl = m), e.images && e.images.length > 1 && (c.images = e.images), o != null && o > 0 && (c.price = String(o)), n != null && n > 0 && (c.originalPrice = String(n)), r !== void 0 && (c.discountPercent = r), 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);
1189
- const g = e, l = {};
1183
+ m && (c.imageUrl = m), e.images && e.images.length > 1 && (c.images = e.images), r != null && r > 0 && (c.price = String(r)), n != null && n > 0 && (c.originalPrice = String(n)), o !== void 0 && (c.discountPercent = o), 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);
1184
+ const _ = e, d = {};
1190
1185
  let p = !1;
1191
- for (const u of Object.keys(g)) Le.has(u) || (l[u] = g[u], p = !0);
1192
- return p && (c.extras = l), c;
1186
+ for (const l of Object.keys(_)) Re.has(l) || (d[l] = _[l], p = !0);
1187
+ return p && (c.extras = d), c;
1193
1188
  }
1194
- function Me(e) {
1189
+ function je(e) {
1195
1190
  return e.results.map(w);
1196
1191
  }
1197
- function $e(e) {
1192
+ function Me(e) {
1198
1193
  return e.product_groupings.map((t) => {
1199
- const o = {
1194
+ const r = {
1200
1195
  name: t.name,
1201
1196
  products: (t.group_products ?? []).map(w)
1202
1197
  };
1203
- return t.highlight !== void 0 && (o.highlight = t.highlight), o;
1198
+ return t.highlight !== void 0 && (r.highlight = t.highlight), r;
1204
1199
  });
1205
1200
  }
1206
- function De(e) {
1207
- const t = e.payload.type, { type: o, ...n } = e.payload;
1201
+ function Le(e) {
1202
+ const t = e.payload.type, { type: r, ...n } = e.payload;
1208
1203
  return {
1209
1204
  type: "ui_spec",
1210
1205
  widget: "chat",
@@ -1217,34 +1212,34 @@ function De(e) {
1217
1212
  }
1218
1213
  };
1219
1214
  }
1220
- var qe = {
1215
+ var De = {
1221
1216
  process_action: "/process_action",
1222
1217
  launcher_action: "/launcher_action",
1223
1218
  similar_products: "/similar_products",
1224
1219
  product_groupings: "/product_groupings"
1225
1220
  };
1226
- function Oe(e) {
1221
+ function qe(e) {
1227
1222
  if (e === void 0) throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");
1228
1223
  const t = e.trim();
1229
1224
  return t === "" ? "" : t.replace(/\/+$/, "");
1230
1225
  }
1231
- function Be(e, t) {
1232
- return `${Oe(t?.middlewareUrl)}/chat${qe[e]}`;
1226
+ function $e(e, t) {
1227
+ return `${qe(t?.middlewareUrl)}/chat${De[e]}`;
1233
1228
  }
1234
1229
  export {
1235
- Me as a,
1230
+ je as a,
1236
1231
  V as c,
1237
- G as d,
1238
- Ge as f,
1232
+ j as d,
1233
+ ze as f,
1239
1234
  He as h,
1240
- $e as i,
1241
- $ as l,
1242
- H as m,
1243
- Oe as n,
1235
+ Me as i,
1236
+ B as l,
1237
+ z as m,
1238
+ qe as n,
1244
1239
  w as o,
1245
- ze as p,
1246
- je as r,
1240
+ Ue as p,
1241
+ Ge as r,
1247
1242
  R as s,
1248
- Be as t,
1249
- B as u
1243
+ $e as t,
1244
+ K as u
1250
1245
  };