@gengage/assistant-fe 0.6.50 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/chat/api.d.ts +1 -1
  2. package/dist/chat/components/ChatDrawer.d.ts +3 -1
  3. package/dist/chat/features/beauty-consulting/mode-controller.d.ts +1 -1
  4. package/dist/chat/features/beauty-consulting/stream-handler.d.ts +7 -1
  5. package/dist/chat/history-storage.d.ts +36 -4
  6. package/dist/chat/runtime.d.ts +2 -2
  7. package/dist/chat/utils/chat-presentation-debug.d.ts +0 -14
  8. package/dist/chat-runtime.js +1 -1
  9. package/dist/chat.iife.js +56 -56
  10. package/dist/chat.js +1 -1
  11. package/dist/common/connection-warning.d.ts +10 -0
  12. package/dist/common/indexed-db.d.ts +35 -2
  13. package/dist/common/native-webview.d.ts +1 -1
  14. package/dist/common/streaming.d.ts +6 -1
  15. package/dist/common/transport.d.ts +2 -1
  16. package/dist/common/types.d.ts +16 -0
  17. package/dist/{common-DJFI5t11.js → common-CeuGSwJL.js} +61 -65
  18. package/dist/common.js +30 -30
  19. package/dist/{connection-warning-TXqyeFaf.js → connection-warning-C0e2byq5.js} +31 -25
  20. package/dist/{fastIntent-539wPavr.js → fastIntent-BI7l1oDv.js} +2 -2
  21. package/dist/global-error-toast-DvaKvPNA.js +798 -0
  22. package/dist/index.js +29 -29
  23. package/dist/native-webview-CHKpwixw.js +303 -0
  24. package/dist/native.iife.js +27 -27
  25. package/dist/native.js +1 -1
  26. package/dist/{overlay-BPZEIyo_.js → overlay-C3XzoSKd.js} +51 -32
  27. package/dist/overlay.js +6 -6
  28. package/dist/{price-formatter-CHUmYq8I.js → price-formatter-Q3wUKrl1.js} +2 -1
  29. package/dist/qna/runtime.d.ts +1 -0
  30. package/dist/qna-runtime.js +1 -1
  31. package/dist/qna.iife.js +32 -32
  32. package/dist/qna.js +1 -1
  33. package/dist/{request-response-cache-DwADBDeB.js → request-response-cache-BLQy7llq.js} +478 -454
  34. package/dist/{runtime-Do3qShrH.js → runtime-BC8-a6Ql.js} +231 -219
  35. package/dist/{runtime-9f9SB4WE.js → runtime-BSIrZhF2.js} +2783 -2692
  36. package/dist/{runtime-rTw1jMhB.js → runtime-DiONTdBz.js} +230 -212
  37. package/dist/{simbut-DlWvDoPI.js → simbut-BDbb3nMH.js} +5 -5
  38. package/dist/simbut.iife.js +2 -2
  39. package/dist/simbut.js +1 -1
  40. package/dist/simrel/components/GroupTabs.d.ts +6 -0
  41. package/dist/simrel/runtime.d.ts +8 -0
  42. package/dist/{simrel-BFPU2n5p.js → simrel-CdxDIKu3.js} +15 -15
  43. package/dist/simrel-runtime.js +1 -1
  44. package/dist/simrel.iife.js +22 -22
  45. package/dist/simrel.js +2 -2
  46. package/dist/widget-base-Cvxdrqqt.js +141 -0
  47. package/package.json +1 -1
  48. package/dist/context-UTzCGyR9.js +0 -543
  49. package/dist/native-webview-CYX30O3Q.js +0 -273
  50. package/dist/widget-base-BwU6SI2o.js +0 -365
package/dist/simrel.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a, i as r, n as t, r as i, t as m } from "./runtime-Do3qShrH.js";
2
- import { n as R, t as n } from "./simrel-BFPU2n5p.js";
1
+ import { a, i as r, n as t, r as i, t as m } from "./runtime-BC8-a6Ql.js";
2
+ import { n as R, t as n } from "./simrel-CdxDIKu3.js";
3
3
  export {
4
4
  m as GengageSimRel,
5
5
  i as createDefaultSimRelUISpecRegistry,
@@ -0,0 +1,141 @@
1
+ import { i as o, p as g, u as h } from "./global-error-toast-DvaKvPNA.js";
2
+ var a = {
3
+ "--gengage-chat-offset": "20px",
4
+ "--gengage-chat-launcher-width": "56px",
5
+ "--gengage-chat-launcher-height": "56px",
6
+ "--gengage-chat-width": "400px",
7
+ "--gengage-chat-shell-radius": "1rem",
8
+ "--gengage-chat-header-height": "72px",
9
+ "--gengage-chat-conversation-width": "396px",
10
+ "--gengage-chat-panel-min-width": "320px",
11
+ "--gengage-chat-panel-max-width": "1200px",
12
+ "--gengage-chat-input-height": "48px",
13
+ "--gengage-qna-pill-radius": "999px",
14
+ "--gengage-qna-input-radius": "12px",
15
+ "--gengage-simrel-card-radius": "0.75rem",
16
+ "--radius-control": "12px",
17
+ "--radius-card": "16px",
18
+ "--radius-panel": "24px",
19
+ "--radius-pill": "999px",
20
+ "--surface-card-muted": "#f8fafc",
21
+ "--text-secondary": "#4b5563",
22
+ "--text-muted": "#6b7280",
23
+ "--border-default": "rgba(17, 24, 39, 0.10)"
24
+ };
25
+ function d(e) {
26
+ if (!e) return { ...a };
27
+ const t = {
28
+ ...a,
29
+ ...e
30
+ }, i = e["--gengage-chat-launcher-size"];
31
+ return i !== void 0 && (e["--gengage-chat-launcher-width"] === void 0 && (t["--gengage-chat-launcher-width"] = i), e["--gengage-chat-launcher-height"] === void 0 && (t["--gengage-chat-launcher-height"] = i)), t;
32
+ }
33
+ var s = null;
34
+ function l() {
35
+ if (s !== null) return s;
36
+ try {
37
+ s = localStorage.getItem("gengage:debug") === "1";
38
+ } catch {
39
+ s = !1;
40
+ }
41
+ return s;
42
+ }
43
+ function r(e, t, i) {
44
+ if (!l()) return;
45
+ const n = [`[gengage:${e}]`, t];
46
+ i !== void 0 && n.push(i), console.debug(...n);
47
+ }
48
+ var u = ("0.7.0".trim(), "0.7.0".trim()), c = ("package-build".trim(), "package-build".trim());
49
+ function f() {
50
+ typeof window > "u" || (window.gengage || (window.gengage = {}), window.gengage.__internal || (window.gengage.__internal = {}), !window.gengage.__internal.sdkRuntimeInfoLogged && (window.gengage.__internal.sdkRuntimeInfoLogged = !0, console.info(`[gengage] @gengage/assistant-fe v${u} (${c})`)));
51
+ }
52
+ var m = class {
53
+ constructor() {
54
+ this.isVisible = !1, this.isInitialised = !1, this._handlers = /* @__PURE__ */ new Map(), this._cleanups = [], this._ownsRoot = !1, this._destroying = !1;
55
+ }
56
+ async init(e) {
57
+ if (this.isInitialised) {
58
+ console.warn("[gengage] Widget already initialised. Call update() instead.");
59
+ return;
60
+ }
61
+ const t = d(e.theme);
62
+ f(), this.config = {
63
+ ...e,
64
+ theme: t,
65
+ session: h(e.session)
66
+ }, this.root = this._resolveMount(e.mountTarget), this._applyTheme(t), o();
67
+ const i = g("gengage:context:update", (n) => this.update(n));
68
+ this._cleanups.push(i), r("lifecycle", `${this.constructor.name}.init`, {
69
+ accountId: e.accountId,
70
+ sku: e.pageContext?.sku
71
+ });
72
+ try {
73
+ await this.onInit(this.config);
74
+ } catch (n) {
75
+ throw this.destroy(), n;
76
+ }
77
+ this._destroying || (this.isInitialised = !0, r("lifecycle", `${this.constructor.name} ready`), this.emit("ready"));
78
+ }
79
+ update(e) {
80
+ this.isInitialised && (this.config.pageContext ? this.config = {
81
+ ...this.config,
82
+ pageContext: {
83
+ ...this.config.pageContext,
84
+ ...e
85
+ }
86
+ } : e.pageType !== void 0 && (this.config = {
87
+ ...this.config,
88
+ pageContext: e
89
+ }), this.onUpdate(e), this.emit("context-update", this.config.pageContext));
90
+ }
91
+ show() {
92
+ this.isVisible || (this.isVisible = !0, this.root.style.display = "", this.onShow(), this.emit("show"));
93
+ }
94
+ hide() {
95
+ this.isVisible && (this.isVisible = !1, this.root.style.display = "none", this.onHide(), this.emit("hide"));
96
+ }
97
+ destroy() {
98
+ this._destroying || (this._destroying = !0, this.emit("destroy"), this._cleanups.forEach((e) => e()), this._cleanups.length = 0, this._handlers.clear(), this.onDestroy(), this._cleanupRoot(), this.isInitialised = !1);
99
+ }
100
+ _cleanupRoot() {
101
+ this._ownsRoot ? this.root.remove() : this.root.innerHTML = "";
102
+ }
103
+ on(e, t) {
104
+ return this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(t), () => this._handlers.get(e)?.delete(t);
105
+ }
106
+ emit(e, ...t) {
107
+ this._handlers.get(e)?.forEach((i) => i(...t));
108
+ }
109
+ addCleanup(e) {
110
+ this._cleanups.push(e);
111
+ }
112
+ _resolveMount(e) {
113
+ if (e instanceof HTMLElement) return e;
114
+ if (typeof e == "string") {
115
+ const i = document.querySelector(e);
116
+ if (!i) throw new Error(`[gengage] Mount target not found: "${e}"`);
117
+ return i;
118
+ }
119
+ const t = document.createElement("div");
120
+ return t.dataset.gengageWidget = this.constructor.name.toLowerCase(), document.body.insertBefore(t, document.body.firstChild), this._ownsRoot = !0, t;
121
+ }
122
+ _applyTheme(e) {
123
+ if (e) {
124
+ for (const [t, i] of Object.entries(e)) if (i !== void 0) {
125
+ const n = t.startsWith("--") ? t : `--gengage-${p(t)}`;
126
+ this.root.style.setProperty(n, i);
127
+ }
128
+ }
129
+ }
130
+ };
131
+ function p(e) {
132
+ return e.replace(/([A-Z])/g, "-$1").toLowerCase();
133
+ }
134
+ export {
135
+ a,
136
+ r as i,
137
+ c as n,
138
+ d as o,
139
+ u as r,
140
+ m as t
141
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gengage/assistant-fe",
3
- "version": "0.6.50",
3
+ "version": "0.7.0",
4
4
  "description": "Source-available frontend widgets for Gengage AI Assistant — chat, Q&A, and similar-products. Backend is SaaS (gengage.ai).",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -1,543 +0,0 @@
1
- var T = /* @__PURE__ */ new Set([
2
- "p",
3
- "br",
4
- "a",
5
- "strong",
6
- "b",
7
- "em",
8
- "i",
9
- "u",
10
- "ul",
11
- "ol",
12
- "li",
13
- "h1",
14
- "h2",
15
- "h3",
16
- "h4",
17
- "h5",
18
- "h6",
19
- "span",
20
- "div",
21
- "table",
22
- "thead",
23
- "tbody",
24
- "tr",
25
- "th",
26
- "td",
27
- "hr",
28
- "code",
29
- "pre",
30
- "blockquote",
31
- "img",
32
- "sup",
33
- "sub",
34
- "button"
35
- ]), E = /* @__PURE__ */ new Set([
36
- "script",
37
- "iframe",
38
- "object",
39
- "embed",
40
- "form",
41
- "input",
42
- "textarea",
43
- "select",
44
- "style",
45
- "link",
46
- "meta",
47
- "template",
48
- "noscript"
49
- ]), b = {
50
- "*": /* @__PURE__ */ new Set(["class"]),
51
- a: /* @__PURE__ */ new Set([
52
- "href",
53
- "target",
54
- "rel"
55
- ]),
56
- img: /* @__PURE__ */ new Set([
57
- "src",
58
- "alt",
59
- "width",
60
- "height"
61
- ]),
62
- button: /* @__PURE__ */ new Set([
63
- "type",
64
- "disabled",
65
- "aria-label",
66
- "aria-hidden",
67
- "title"
68
- ]),
69
- div: /* @__PURE__ */ new Set(["style"]),
70
- span: /* @__PURE__ */ new Set(["style"]),
71
- p: /* @__PURE__ */ new Set(["style"])
72
- };
73
- function I(e) {
74
- return /^\s*javascript\s*:/i.test(e);
75
- }
76
- var O = /* @__PURE__ */ new Set([
77
- "color",
78
- "background-color",
79
- "font-size",
80
- "font-weight",
81
- "font-style",
82
- "font-family",
83
- "text-align",
84
- "text-decoration",
85
- "line-height",
86
- "letter-spacing",
87
- "margin",
88
- "margin-top",
89
- "margin-right",
90
- "margin-bottom",
91
- "margin-left",
92
- "padding",
93
- "padding-top",
94
- "padding-right",
95
- "padding-bottom",
96
- "padding-left",
97
- "border",
98
- "border-top",
99
- "border-right",
100
- "border-bottom",
101
- "border-left",
102
- "border-radius",
103
- "border-color",
104
- "border-width",
105
- "border-style",
106
- "width",
107
- "max-width",
108
- "min-width",
109
- "height",
110
- "max-height",
111
- "min-height",
112
- "display",
113
- "vertical-align",
114
- "white-space",
115
- "word-break",
116
- "overflow",
117
- "opacity",
118
- "visibility",
119
- "list-style",
120
- "list-style-type",
121
- "text-transform",
122
- "text-indent",
123
- "text-overflow",
124
- "box-sizing",
125
- "flex",
126
- "flex-direction",
127
- "flex-wrap",
128
- "justify-content",
129
- "align-items",
130
- "gap"
131
- ]), P = /url\s*\(|expression\s*\(|javascript\s*:|\bimport\b|-moz-binding|behavior\s*:/i;
132
- function N(e) {
133
- const t = [];
134
- for (const n of e.split(";")) {
135
- const i = n.trim();
136
- if (!i) continue;
137
- const a = i.indexOf(":");
138
- if (a === -1) continue;
139
- const s = i.slice(0, a).trim().toLowerCase(), u = i.slice(a + 1).trim();
140
- O.has(s) && (P.test(u) || t.push(i));
141
- }
142
- return t.join("; ");
143
- }
144
- function w(e, t) {
145
- if (e.nodeType === Node.TEXT_NODE) return;
146
- if (e.nodeType !== Node.ELEMENT_NODE) {
147
- e.parentNode?.removeChild(e);
148
- return;
149
- }
150
- const n = e, i = n.tagName.toLowerCase();
151
- if (E.has(i)) {
152
- n.parentNode?.removeChild(n);
153
- return;
154
- }
155
- if (!T.has(i)) {
156
- const o = Array.from(n.childNodes);
157
- for (const c of o) t.insertBefore(c, n);
158
- t.removeChild(n);
159
- for (const c of o) w(c, t);
160
- return;
161
- }
162
- const a = b["*"] ?? /* @__PURE__ */ new Set(), s = b[i] ?? /* @__PURE__ */ new Set(), u = Array.from(n.attributes);
163
- for (const o of u) {
164
- const c = o.name.toLowerCase();
165
- if (!a.has(c) && !s.has(c)) {
166
- n.removeAttribute(o.name);
167
- continue;
168
- }
169
- if (I(o.value)) {
170
- n.removeAttribute(o.name);
171
- continue;
172
- }
173
- if (c === "style") {
174
- const d = N(o.value);
175
- d ? n.setAttribute("style", d) : n.removeAttribute("style");
176
- continue;
177
- }
178
- }
179
- if (i === "a") {
180
- const o = n.getAttribute("href");
181
- if (o !== null) {
182
- const c = o.trim().toLowerCase();
183
- !c.startsWith("http://") && !c.startsWith("https://") && !c.startsWith("mailto:") && n.removeAttribute("href");
184
- }
185
- n.setAttribute("target", "_blank"), n.setAttribute("rel", "noopener noreferrer");
186
- }
187
- if (i === "img") {
188
- const o = n.getAttribute("src");
189
- o !== null && (o.trim().toLowerCase().startsWith("https://") || n.removeAttribute("src"));
190
- }
191
- if (i === "button") {
192
- const o = n.getAttribute("type")?.trim().toLowerCase();
193
- (!o || o !== "button") && n.setAttribute("type", "button");
194
- }
195
- const p = Array.from(n.childNodes);
196
- for (const o of p) w(o, n);
197
- }
198
- var k = ["http:", "https:"];
199
- function J(e) {
200
- const t = e.trim();
201
- if (!t) return !1;
202
- if (t.startsWith("/") && !t.startsWith("//")) return !0;
203
- try {
204
- return k.includes(new URL(t).protocol);
205
- } catch {
206
- return !1;
207
- }
208
- }
209
- function A(e) {
210
- if (e.startsWith("/") && !e.startsWith("//")) return !0;
211
- try {
212
- const t = new URL(e);
213
- return k.includes(t.protocol);
214
- } catch {
215
- return !1;
216
- }
217
- }
218
- function X(e, t, n) {
219
- (t === "href" || t === "src") && !A(n) || e.setAttribute(t, n);
220
- }
221
- function K(e) {
222
- if (!e) return "";
223
- const t = new DOMParser().parseFromString(e, "text/html").body, n = Array.from(t.childNodes);
224
- for (const i of n) w(i, t);
225
- return t.innerHTML;
226
- }
227
- function W() {
228
- return typeof window < "u" && Array.isArray(window.dataLayer);
229
- }
230
- function r(e, t) {
231
- const n = {
232
- event: e,
233
- ...t
234
- };
235
- W() && window.dataLayer.push(n);
236
- }
237
- function D(e) {
238
- r("gengage-on-init", { gengage_widget: e });
239
- }
240
- function v(e) {
241
- r("gengage-show", { gengage_widget: e });
242
- }
243
- function U(e) {
244
- r("gengage-hide", { gengage_widget: e });
245
- }
246
- function z(e, t) {
247
- r("gengage-suggested-question", {
248
- gengage_question_title: e,
249
- gengage_action_type: t
250
- });
251
- }
252
- function Y(e) {
253
- r("gengage-find-similars", { gengage_sku: e });
254
- }
255
- function Z(e) {
256
- r("gengage-compare-preselection", { gengage_sku: e });
257
- }
258
- function $(e) {
259
- r("gengage-compare-selected", {
260
- gengage_skus: e,
261
- gengage_product_count: e.length
262
- });
263
- }
264
- function ee() {
265
- r("gengage-compare-clear");
266
- }
267
- function te(e) {
268
- r("gengage-compare-received", { gengage_product_count: e });
269
- }
270
- function ne(e) {
271
- r("gengage-like-product", { gengage_sku: e });
272
- }
273
- function ie() {
274
- r("gengage-like-list");
275
- }
276
- function re(e, t) {
277
- r("gengage-search", {
278
- gengage_search_query: e,
279
- gengage_result_count: t
280
- });
281
- }
282
- function oe(e, t) {
283
- r("gengage-product-detail", {
284
- gengage_sku: e,
285
- gengage_product_name: t
286
- });
287
- }
288
- function M(e, t) {
289
- r("gengage-similar-product-click", {
290
- gengage_sku: e,
291
- ...t?.url !== void 0 ? { gengage_product_url: t.url } : {},
292
- ...t?.name !== void 0 ? { gengage_product_name: t.name } : {},
293
- ...t?.session_id !== void 0 ? { gengage_session_id: t.session_id } : {}
294
- });
295
- }
296
- function R(e, t) {
297
- r("gengage-similar-grouping-click", {
298
- gengage_grouping_label: e,
299
- gengage_grouping_index: t
300
- });
301
- }
302
- function j(e) {
303
- r("gengage-similar-products-impression", {
304
- gengage_source_sku: e.source_sku,
305
- gengage_product_count: e.product_count,
306
- gengage_grouped: e.grouped,
307
- ...e.session_id !== void 0 ? { gengage_session_id: e.session_id } : {}
308
- });
309
- }
310
- function ae(e) {
311
- r("gengage-compare-product", {
312
- gengage_skus: e,
313
- gengage_product_count: e.length
314
- });
315
- }
316
- function se() {
317
- r("gengage-chatbot-maximized");
318
- }
319
- function q(e) {
320
- r("gengage-interface-not-ready", {
321
- ...e?.reason !== void 0 ? { gengage_reason: e.reason } : {},
322
- ...e?.attempts !== void 0 ? { gengage_attempts: e.attempts } : {},
323
- ...e?.message !== void 0 ? { gengage_message: e.message } : {}
324
- });
325
- }
326
- function G(e, t) {
327
- r("gengage-cart-add", {
328
- gengage_sku: e,
329
- gengage_quantity: t
330
- });
331
- }
332
- function ge() {
333
- r("gengage-message-sent");
334
- }
335
- function ce() {
336
- r("gengage-message-received");
337
- }
338
- function le() {
339
- r("gengage-conversation-start");
340
- }
341
- function F() {
342
- r("gengage-voice-input");
343
- }
344
- function Q(e, t) {
345
- r("gengage-error", {
346
- gengage_widget: e,
347
- gengage_error: t
348
- });
349
- }
350
- var f = null;
351
- function ue() {
352
- if (typeof window > "u") return () => {
353
- };
354
- if (f) return f;
355
- const e = [];
356
- function t(n, i) {
357
- const a = (s) => i(s.detail);
358
- window.addEventListener(n, a), e.push(() => window.removeEventListener(n, a));
359
- }
360
- return t("gengage:chat:open", () => v("chat")), t("gengage:chat:close", () => U("chat")), t("gengage:chat:ready", () => D("chat")), t("gengage:similar:add-to-cart", ({ sku: n, quantity: i }) => {
361
- G(n, i);
362
- }), t("gengage:similar:product-click", ({ sku: n, url: i, sessionId: a, productName: s }) => {
363
- const u = {
364
- url: i,
365
- session_id: a
366
- };
367
- s !== void 0 && s !== "" && (u.name = s), M(n, u);
368
- }), t("gengage:similar:grouping-click", ({ grouping_label: n, grouping_index: i }) => {
369
- R(n, i);
370
- }), t("gengage:similar:products-impression", ({ source_sku: n, product_count: i, grouped: a, sessionId: s }) => {
371
- j({
372
- source_sku: n,
373
- product_count: i,
374
- grouped: a,
375
- session_id: s
376
- });
377
- }), t("gengage:qna:action", ({ title: n, type: i }) => {
378
- z(n, i);
379
- }), t("gengage:chat:voice", () => F()), t("gengage:qna:open-chat", () => v("chat")), t("gengage:global:error", ({ source: n, message: i }) => {
380
- Q(n, i);
381
- }), f = () => {
382
- for (const n of e) n();
383
- e.length = 0, f = null;
384
- }, f;
385
- }
386
- function de(e, t) {
387
- window.dispatchEvent(new CustomEvent(e, {
388
- detail: t,
389
- bubbles: !1
390
- }));
391
- }
392
- function _(e, t) {
393
- const n = (i) => {
394
- t(i.detail);
395
- };
396
- return window.addEventListener(e, n), () => window.removeEventListener(e, n);
397
- }
398
- function H(e) {
399
- if (e.type !== "user_message" && e.type !== "inputText") return null;
400
- if (typeof e.payload == "string" && e.payload.trim().length > 0) return e.payload.trim();
401
- if (typeof e.payload == "object" && e.payload !== null) {
402
- const t = e.payload;
403
- if (typeof t.text == "string") {
404
- const n = t.text.trim();
405
- if (n.length > 0) return n;
406
- }
407
- }
408
- return typeof e.title == "string" && e.title.trim().length > 0 ? e.title.trim() : null;
409
- }
410
- function V(e) {
411
- if (e.type !== "inputText" && e.type !== "user_message") return e;
412
- const t = typeof e.payload == "string" ? { text: e.payload.trim() } : e.payload != null && typeof e.payload == "object" && !Array.isArray(e.payload) ? { ...e.payload } : {};
413
- if (typeof t.text != "string" || !t.text.trim()) {
414
- const n = e.title?.trim();
415
- n && (t.text = n);
416
- }
417
- return "is_launcher" in t || (t.is_launcher = 1), "is_suggested_text" in t || (t.is_suggested_text = 1), {
418
- ...e,
419
- payload: t
420
- };
421
- }
422
- function fe(e) {
423
- let t = !1;
424
- const n = [];
425
- let i = 0, a = null, s = 0;
426
- const u = 500, p = 10;
427
- function o() {
428
- return window.gengage?.chat ?? null;
429
- }
430
- function c() {
431
- t || (console.warn("[gengage] QNA tried to open chat, but chat widget is not initialized. Ensure GengageChat is initialized before calling wireQNAToChat()."), t = !0), e?.onChatUnavailable?.();
432
- }
433
- function d(g, l) {
434
- if (g.openWithAction) {
435
- const L = l.type === "inputText" || l.type === "user_message" ? V(l) : l;
436
- g.openWithAction(L);
437
- return;
438
- }
439
- const h = H(l);
440
- if (h && g.sendMessage) {
441
- g.open?.(), g.sendMessage(h);
442
- return;
443
- }
444
- }
445
- function m() {
446
- a !== null && (window.clearInterval(a), a = null);
447
- }
448
- function S() {
449
- const g = o();
450
- if (!g) return !1;
451
- if (i > 0 && (g.open?.(), i = 0), n.length > 0) {
452
- const l = n.splice(0, n.length);
453
- for (const h of l) d(g, h);
454
- }
455
- return m(), !0;
456
- }
457
- function y() {
458
- a === null && (s = 0, a = window.setInterval(() => {
459
- S() || (s += 1, s >= p && ((n.length > 0 || i > 0) && q({
460
- reason: "chat_unavailable_after_poll",
461
- attempts: p
462
- }), n.length = 0, i = 0, m()));
463
- }, u));
464
- }
465
- const C = _("gengage:qna:action", (g) => {
466
- const l = o();
467
- if (l) {
468
- d(l, g);
469
- return;
470
- }
471
- c(), n.length >= 20 && n.shift(), n.push(g), y();
472
- }), x = _("gengage:qna:open-chat", () => {
473
- const g = o();
474
- if (g) {
475
- g.open?.();
476
- return;
477
- }
478
- c(), i += 1, y();
479
- });
480
- return () => {
481
- C(), x(), n.length = 0, i = 0, m();
482
- };
483
- }
484
- function pe() {
485
- return _("gengage:similar:product-click", ({ sku: e, url: t, sessionId: n }) => {
486
- n && window.gengage?.chat?.saveSession(n, e), A(t) && (window.location.href = t);
487
- });
488
- }
489
- function B() {
490
- const e = window.__gengageSessionId ?? sessionStorage.getItem("gengage_session_id") ?? null ?? crypto.randomUUID();
491
- return window.__gengageSessionId = e, sessionStorage.setItem("gengage_session_id", e), window.gengage || (window.gengage = {}), window.gengage.sessionId = e, e;
492
- }
493
- function he() {
494
- return window.gengage?.pageContext ?? null;
495
- }
496
- function me(e) {
497
- window.gengage || (window.gengage = {}), window.gengage.pageContext = {
498
- pageType: "other",
499
- ...window.gengage.pageContext,
500
- ...e
501
- }, window.dispatchEvent(new CustomEvent("gengage:context:update", { detail: e }));
502
- }
503
- function we(e) {
504
- return {
505
- sessionId: e?.sessionId ?? B(),
506
- ...e
507
- };
508
- }
509
- export {
510
- J as A,
511
- ge as C,
512
- z as D,
513
- v as E,
514
- X as M,
515
- K as N,
516
- F as O,
517
- ce as S,
518
- re as T,
519
- Y as _,
520
- de as a,
521
- ie as b,
522
- pe as c,
523
- ee as d,
524
- Z as f,
525
- le as g,
526
- $ as h,
527
- me as i,
528
- A as j,
529
- ue as k,
530
- G as l,
531
- te as m,
532
- he as n,
533
- _ as o,
534
- ae as p,
535
- we as r,
536
- fe as s,
537
- B as t,
538
- se as u,
539
- D as v,
540
- oe as w,
541
- ne as x,
542
- q as y
543
- };