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