@gengage/assistant-fe 0.6.34 → 0.6.36

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