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