@gengage/assistant-fe 0.4.6 → 0.4.8

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 (49) hide show
  1. package/README.md +21 -1
  2. package/dist/{api-paths-C4GDpeTf.js → api-paths-DR5bPNhi.js} +2 -3
  3. package/dist/assistant-fe.css +1 -1
  4. package/dist/chat/runtime.d.ts +2 -0
  5. package/dist/chat-runtime.js +1 -1
  6. package/dist/chat.iife.js +12 -12
  7. package/dist/chat.js +1 -1
  8. package/dist/common/overlay.d.ts +4 -0
  9. package/dist/common/protocol-adapter.d.ts +1 -1
  10. package/dist/common/safe-html.d.ts +1 -1
  11. package/dist/{common-CEN5OW7E.js → common-c-awF96O.js} +3 -3
  12. package/dist/common.js +8 -8
  13. package/dist/{connection-warning-B6oIU-9s.js → connection-warning-ecZqpczd.js} +1 -1
  14. package/dist/{context-VIG4SVcS.js → context-DGz5F81j.js} +82 -79
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.js +44 -42
  17. package/dist/{native-webview-DudQ7nHe.js → native-webview-C_PmKnzm.js} +1 -1
  18. package/dist/native.iife.js +7 -7
  19. package/dist/native.js +1 -1
  20. package/dist/{overlay-1EO41ZC7.js → overlay-DJ1ZRMfI.js} +75 -75
  21. package/dist/overlay.js +2 -2
  22. package/dist/{pill-launcher-57nrdLRr.js → pill-launcher-DSEeJT9h.js} +2 -2
  23. package/dist/qna/runtime.d.ts +2 -1
  24. package/dist/qna/types.d.ts +14 -0
  25. package/dist/qna-runtime.js +1 -1
  26. package/dist/qna.css +1 -1
  27. package/dist/qna.iife.js +21 -21
  28. package/dist/qna.js +1 -1
  29. package/dist/{runtime-C0qZk0y7.js → runtime-BlYMjp2f.js} +1548 -1524
  30. package/dist/{runtime-BdwZZIrO.js → runtime-BsZZ8zTg.js} +5 -4
  31. package/dist/runtime-SKDvc0Xc.js +660 -0
  32. package/dist/simbut/index.d.ts +3 -1
  33. package/dist/simbut/types.d.ts +11 -0
  34. package/dist/simbut-Bw3vBFtW.js +109 -0
  35. package/dist/simbut.css +1 -1
  36. package/dist/simbut.iife.js +10 -10
  37. package/dist/simbut.js +1 -1
  38. package/dist/simrel/index.d.ts +2 -0
  39. package/dist/simrel/renderers/default.d.ts +40 -0
  40. package/dist/simrel-DJZ983BF.js +513 -0
  41. package/dist/simrel-runtime.js +1 -1
  42. package/dist/simrel.css +3 -0
  43. package/dist/simrel.iife.js +38 -38
  44. package/dist/simrel.js +4 -3
  45. package/dist/{widget-base-TgwiA8cD.js → widget-base-2-B1Ch5I.js} +1 -1
  46. package/package.json +6 -1
  47. package/dist/runtime-DDu8Wk0z.js +0 -629
  48. package/dist/simbut-BMWC6x_t.js +0 -81
  49. package/dist/simrel-ohfkluhp.js +0 -55
@@ -1,9 +1,9 @@
1
- import { a as D, f as j, i as F, m as H, r as N, t as R, u as U } from "./api-paths-C4GDpeTf.js";
2
- import { S as z, b as T, f as $, i as W, t as J, w, x as Q } from "./widget-base-TgwiA8cD.js";
3
- import { A as Y, E as A, N as V, a as S, l as K, v as X } from "./context-VIG4SVcS.js";
1
+ import { a as D, f as j, i as F, m as H, r as N, t as R, u as U } from "./api-paths-DR5bPNhi.js";
2
+ import { S as z, b as T, f as $, i as W, t as J, w, x as Q } from "./widget-base-2-B1Ch5I.js";
3
+ import { A as Y, E as A, N as V, a as S, l as K, v as X } from "./context-DGz5F81j.js";
4
4
  import { t as Z } from "./locale-CfqNifrU.js";
5
5
  import { a as ee, n as te, r as re, t as P } from "./price-formatter-xI3g9Cd4.js";
6
- import { n as ne } from "./connection-warning-B6oIU-9s.js";
6
+ import { n as ne } from "./connection-warning-ecZqpczd.js";
7
7
  function M(e) {
8
8
  const t = [];
9
9
  for (const r of Object.values(e)) if (r.type === "ProductCard" && r.props) {
@@ -682,6 +682,7 @@ export {
682
682
  ue as a,
683
683
  B as i,
684
684
  Te as n,
685
+ de as o,
685
686
  ge as r,
686
687
  Ce as t
687
688
  };
@@ -0,0 +1,660 @@
1
+ import { f as R, m as Q, r as N, t as H, u as O } from "./api-paths-DR5bPNhi.js";
2
+ import { S as U, b as j, i as M, t as D, w as F, x as W } from "./widget-base-2-B1Ch5I.js";
3
+ import { A as z, D as $, E as G, a as A, v as J } from "./context-DGz5F81j.js";
4
+ import { t as E } from "./locale-CfqNifrU.js";
5
+ import { n as V } from "./connection-warning-ecZqpczd.js";
6
+ async function Y(e, t, n) {
7
+ const o = H("launcher_action", t), a = {
8
+ uiSpecs: [],
9
+ actions: []
10
+ }, i = {
11
+ method: "POST",
12
+ headers: { "Content-Type": "application/json" },
13
+ body: JSON.stringify(e)
14
+ };
15
+ n !== void 0 && (i.signal = n);
16
+ const s = await fetch(o, i);
17
+ if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
18
+ const l = { onEvent: (c) => {
19
+ const r = N(c);
20
+ if (r && (r.type === "ui_spec" && a.uiSpecs.push(r.spec), r.type === "ui_spec" && r.spec.elements)) {
21
+ for (const d of Object.values(r.spec.elements)) if (d.type === "ActionButton" && d.props?.action) {
22
+ const y = d.props.action;
23
+ a.actions.push(y);
24
+ }
25
+ }
26
+ } };
27
+ return n !== void 0 && (l.signal = n), await O(s, l), a;
28
+ }
29
+ function T(e) {
30
+ const t = document.createElement("div");
31
+ t.className = "gengage-qna-buttons gds-toolbar", t.dataset.gengagePart = "qna-button-row", t.setAttribute("role", "group"), t.setAttribute("aria-label", e.quickQuestionsAriaLabel ?? "Quick questions"), e.orientation === "vertical" && (t.style.flexDirection = "column");
32
+ for (const n of e.actions) {
33
+ const o = document.createElement("button");
34
+ o.className = "gengage-qna-button gds-chip", o.dataset.gengagePart = "qna-quick-question", o.textContent = n.title, o.type = "button", o.addEventListener("click", () => {
35
+ const a = {
36
+ title: n.title,
37
+ type: n.type
38
+ };
39
+ n.payload !== void 0 && (a.payload = n.payload), e.onAction(a);
40
+ }), t.appendChild(o);
41
+ }
42
+ if (e.ctaText || e.onOpenChat) {
43
+ const n = document.createElement("button");
44
+ n.className = "gengage-qna-cta gds-btn gds-btn-secondary", n.dataset.gengagePart = "qna-cta", n.textContent = e.ctaText ?? e.defaultCtaText ?? "Ask something else", n.type = "button", n.addEventListener("click", () => {
45
+ e.onOpenChat?.();
46
+ }), t.appendChild(n);
47
+ }
48
+ return t;
49
+ }
50
+ function Z(e) {
51
+ const t = document.createElement("div");
52
+ t.className = "gengage-qna-input-wrapper", t.dataset.gengagePart = "qna-input-wrapper";
53
+ const n = document.createElement("div");
54
+ n.className = "gengage-qna-input-combo", n.dataset.gengagePart = "qna-input-combo";
55
+ const o = document.createElement("input");
56
+ o.type = "text", o.className = "gengage-qna-input", o.dataset.gengagePart = "qna-input", o.setAttribute("aria-label", e.askQuestionAriaLabel ?? "Ask a question");
57
+ const a = Array.isArray(e.placeholders) ? e.placeholders : e.placeholders ? [e.placeholders] : [e.defaultInputPlaceholder ?? "Ask a question..."];
58
+ let i = 0, s = a[0] ?? "";
59
+ o.placeholder = s;
60
+ let l = null, c = null, r = !1;
61
+ const d = () => {
62
+ l && clearInterval(l), l = null, c && clearTimeout(c), c = null, o.classList.remove("gengage-qna-input--fade");
63
+ }, y = () => a.length > 1 && !r && o.value.trim().length === 0, m = () => {
64
+ d(), y() && (l = setInterval(() => {
65
+ y() && (o.classList.add("gengage-qna-input--fade"), c = setTimeout(() => {
66
+ i = (i + 1) % a.length, s = a[i] ?? "", o.placeholder = s, o.classList.remove("gengage-qna-input--fade");
67
+ }, 180));
68
+ }, 3e3));
69
+ }, h = document.createElement("div");
70
+ h.className = "gengage-qna-input-actions", h.dataset.gengagePart = "qna-input-actions";
71
+ const p = document.createElement("button");
72
+ p.className = "gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden", p.type = "button", p.dataset.gengagePart = "qna-clear", p.setAttribute("aria-label", "Clear question"), p.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';
73
+ const g = document.createElement("button");
74
+ g.className = "gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden", g.type = "button", g.dataset.gengagePart = "qna-send", g.setAttribute("aria-label", e.sendQuestionAriaLabel ?? "Send question"), g.disabled = !0, g.innerHTML = `<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${e.ctaLabel ?? e.sendButtonText ?? "Ask"}</span>`;
75
+ const b = () => {
76
+ const u = o.value.trim().length > 0;
77
+ p.classList.toggle("gengage-qna-icon-btn--hidden", !u), g.classList.toggle("gengage-qna-icon-btn--hidden", !u), g.classList.toggle("gengage-qna-send--active", u), g.disabled = !u;
78
+ }, v = () => {
79
+ const u = o.value.trim();
80
+ u && (e.onSubmit({
81
+ title: u,
82
+ type: "user_message",
83
+ payload: u
84
+ }), o.value = "", b(), m());
85
+ };
86
+ return p.addEventListener("click", () => {
87
+ o.value = "", b(), o.focus({ preventScroll: !0 });
88
+ }), g.addEventListener("click", v), o.addEventListener("focus", () => {
89
+ r = !0, d(), o.placeholder = "";
90
+ }), o.addEventListener("blur", () => {
91
+ r = !1, o.value.trim().length === 0 && (o.placeholder = s), m();
92
+ }), o.addEventListener("input", () => {
93
+ if (b(), o.value.trim().length > 0) {
94
+ d();
95
+ return;
96
+ }
97
+ o.placeholder = r ? "" : s, m();
98
+ }), o.addEventListener("keydown", (u) => {
99
+ u.key === "Enter" && (u.preventDefault(), v()), u.key === "Escape" && o.value.length > 0 && (o.value = "", b(), m());
100
+ }), h.appendChild(p), h.appendChild(g), n.appendChild(o), n.appendChild(h), t.appendChild(n), b(), m(), t._cleanup = () => {
101
+ d();
102
+ }, t;
103
+ }
104
+ function q(e, t) {
105
+ if (!e || typeof e != "object") return null;
106
+ const n = e, o = n.type;
107
+ if (typeof o != "string" || o.length === 0) return null;
108
+ const a = n.title, i = n.payload, s = typeof a == "string" && a.length > 0 ? a : t;
109
+ if (!s) return null;
110
+ const l = {
111
+ title: s,
112
+ type: o
113
+ };
114
+ return i !== void 0 && (l.payload = i), l;
115
+ }
116
+ function C(e) {
117
+ const t = {
118
+ title: e.title,
119
+ type: e.type
120
+ };
121
+ return e.payload !== void 0 && (t.payload = e.payload), t;
122
+ }
123
+ function k(e, t) {
124
+ const n = [], o = e.props?.actions;
125
+ if (Array.isArray(o)) for (const s of o) {
126
+ const l = q(s);
127
+ l && n.push(l);
128
+ }
129
+ const a = e.props?.buttons;
130
+ if (Array.isArray(a)) for (const s of a) {
131
+ if (!s || typeof s != "object") continue;
132
+ const l = s, c = typeof l.label == "string" ? l.label : void 0, r = q(l.action, c);
133
+ r && n.push(r);
134
+ }
135
+ if (e.children) for (const s of e.children) {
136
+ const l = t.elements[s];
137
+ if (!l || l.type !== "ActionButton") continue;
138
+ const c = typeof l.props?.label == "string" ? l.props.label : void 0, r = q(l.props?.action, c);
139
+ r && n.push(r);
140
+ }
141
+ const i = /* @__PURE__ */ new Set();
142
+ return n.filter((s) => i.has(s.title) ? !1 : (i.add(s.title), !0));
143
+ }
144
+ var I = {
145
+ ButtonRow: ({ element: e, spec: t, context: n }) => {
146
+ const o = k(e, t).map(C), a = e.props?.orientation, i = {
147
+ actions: o,
148
+ onAction: n.onAction,
149
+ defaultCtaText: n.i18n.defaultCtaText,
150
+ quickQuestionsAriaLabel: n.i18n.quickQuestionsAriaLabel
151
+ };
152
+ return n.onOpenChat !== void 0 && (i.onOpenChat = n.onOpenChat), n.ctaText !== void 0 && (i.ctaText = n.ctaText), (a === "horizontal" || a === "vertical") && (i.orientation = a), T(i);
153
+ },
154
+ ActionButtons: ({ element: e, spec: t, context: n }) => {
155
+ const o = {
156
+ actions: k(e, t).map(C),
157
+ onAction: n.onAction,
158
+ defaultCtaText: n.i18n.defaultCtaText,
159
+ quickQuestionsAriaLabel: n.i18n.quickQuestionsAriaLabel
160
+ };
161
+ return n.onOpenChat !== void 0 && (o.onOpenChat = n.onOpenChat), n.ctaText !== void 0 && (o.ctaText = n.ctaText), T(o);
162
+ },
163
+ ActionButton: ({ element: e, context: t }) => {
164
+ const n = document.createElement("button");
165
+ n.className = "gengage-qna-button gds-chip", n.type = "button", n.dataset.gengagePart = "qna-action-button";
166
+ const o = e.props?.label;
167
+ typeof o == "string" ? n.textContent = o : n.textContent = t.i18n.defaultCtaText;
168
+ const a = q(e.props?.action, typeof o == "string" ? o : void 0);
169
+ return a && n.addEventListener("click", () => t.onAction(a)), n;
170
+ },
171
+ TextInput: ({ element: e, context: t }) => {
172
+ const n = e.props?.placeholder, o = typeof n == "string" || Array.isArray(n) ? n : t.inputPlaceholder, a = typeof e.props?.ctaLabel == "string" ? e.props.ctaLabel : void 0, i = {
173
+ onSubmit: t.onAction,
174
+ askQuestionAriaLabel: t.i18n.askQuestionAriaLabel,
175
+ defaultInputPlaceholder: t.i18n.defaultInputPlaceholder,
176
+ sendButtonText: t.i18n.sendButton,
177
+ sendQuestionAriaLabel: t.i18n.sendQuestionAriaLabel
178
+ };
179
+ return o !== void 0 && (i.placeholders = o), a !== void 0 && (i.ctaLabel = a), Z(i);
180
+ },
181
+ QuestionHeading: ({ element: e, context: t }) => {
182
+ const n = document.createElement("h3");
183
+ n.className = "gengage-qna-heading", n.dataset.gengagePart = "qna-heading";
184
+ const o = e.props?.text, a = t.headingTitleOverride;
185
+ return n.textContent = typeof a == "string" && a.trim().length > 0 ? a : typeof o == "string" ? o : "", n;
186
+ },
187
+ ProductCard: () => null
188
+ }, w = ({ element: e, renderElement: t }) => {
189
+ if (!e.children || e.children.length === 0) return null;
190
+ const n = document.createElement("div");
191
+ for (const o of e.children) {
192
+ const a = t(o);
193
+ a && n.appendChild(a);
194
+ }
195
+ return n;
196
+ };
197
+ function K() {
198
+ return { ...I };
199
+ }
200
+ function X(e, t, n = I, o = w) {
201
+ return Q({
202
+ spec: e,
203
+ context: t,
204
+ registry: n,
205
+ containerClassName: "gengage-qna-uispec",
206
+ unknownRenderer: o
207
+ });
208
+ }
209
+ function tt(e) {
210
+ if (!e) return;
211
+ const t = e.extra;
212
+ if (t && typeof t == "object" && !Array.isArray(t)) {
213
+ const o = t.visible_skus ?? t.visibleSkus;
214
+ if (Array.isArray(o)) {
215
+ const a = o.filter((i) => typeof i == "string" && i.trim().length > 0).map((i) => i.trim()).slice(0, 200);
216
+ if (a.length > 0) return a;
217
+ }
218
+ }
219
+ const n = typeof e.sku == "string" && e.sku.trim() ? e.sku.trim() : void 0;
220
+ return n ? [n] : void 0;
221
+ }
222
+ function P(e, t) {
223
+ if (!e) return null;
224
+ const n = e.action;
225
+ if (!n || typeof n != "object") return null;
226
+ const o = n, a = o.type;
227
+ if (typeof a != "string" || a.length === 0) return null;
228
+ const i = o.title, s = typeof i == "string" && i.length > 0 ? i : typeof t == "string" && t.length > 0 ? t : "";
229
+ if (!s) return null;
230
+ const l = o.payload, c = {
231
+ title: s,
232
+ type: a
233
+ };
234
+ return l !== void 0 && (c.payload = l), c;
235
+ }
236
+ function et(e, t) {
237
+ const n = e.elements[e.root];
238
+ if (!n) return !1;
239
+ const o = (a) => {
240
+ if (a.type !== "ActionButton") return !1;
241
+ const i = a.props;
242
+ if (!i || typeof i != "object") return !1;
243
+ const s = typeof i.label == "string" ? i.label : void 0;
244
+ return s === t ? !0 : P(i, s)?.title === t;
245
+ };
246
+ if (n.type === "ActionButton") return o(n);
247
+ if (n.children) for (const a of n.children) {
248
+ const i = e.elements[a];
249
+ if (i && o(i)) return !0;
250
+ }
251
+ if (n.type === "ActionButtons" && Array.isArray(n.props?.buttons)) {
252
+ for (const a of n.props.buttons)
253
+ if (a?.label === t || a?.action?.title === t) return !0;
254
+ }
255
+ return !1;
256
+ }
257
+ var S = 0;
258
+ function x() {
259
+ return S += 1, `gengage-merge-${S}`;
260
+ }
261
+ function nt(e, t) {
262
+ const n = e.elements[e.root];
263
+ if (!n || n.type !== "ButtonRow") return;
264
+ const o = x();
265
+ e.elements[o] = {
266
+ type: "ActionButton",
267
+ props: {
268
+ label: t.title,
269
+ action: {
270
+ title: t.title,
271
+ type: t.type,
272
+ ...t.payload !== void 0 ? { payload: t.payload } : {}
273
+ }
274
+ }
275
+ }, n.children = n.children ? [o, ...n.children] : [o];
276
+ }
277
+ function ot(e, t) {
278
+ const n = e.elements[e.root];
279
+ if (!n || n.type !== "ActionButtons") return;
280
+ const o = x();
281
+ e.elements[o] = {
282
+ type: "ActionButton",
283
+ props: {
284
+ label: t.title,
285
+ action: {
286
+ title: t.title,
287
+ type: t.type,
288
+ ...t.payload !== void 0 ? { payload: t.payload } : {}
289
+ }
290
+ }
291
+ }, n.children = n.children ? [o, ...n.children] : [o];
292
+ const a = n.props?.buttons ?? [], i = {
293
+ label: t.title,
294
+ action: {
295
+ title: t.title,
296
+ type: t.type,
297
+ ...t.payload !== void 0 ? { payload: t.payload } : {}
298
+ }
299
+ };
300
+ n.props = {
301
+ ...n.props,
302
+ buttons: [i, ...a]
303
+ };
304
+ }
305
+ function at(e) {
306
+ const t = {}, n = [];
307
+ for (let o = 0; o < e.length; o++) {
308
+ const a = e[o], i = `action-${o}`;
309
+ n.push(i), t[i] = {
310
+ type: "ActionButton",
311
+ props: {
312
+ label: a.title,
313
+ action: {
314
+ title: a.title,
315
+ type: a.type,
316
+ ...a.payload !== void 0 ? { payload: a.payload } : {}
317
+ }
318
+ }
319
+ };
320
+ }
321
+ return t.root = {
322
+ type: "ButtonRow",
323
+ children: n
324
+ }, {
325
+ root: "root",
326
+ elements: t
327
+ };
328
+ }
329
+ function it(e) {
330
+ return e.find((t) => {
331
+ const n = t.elements[t.root];
332
+ return n?.type === "ActionButtons" || n?.type === "ButtonRow";
333
+ });
334
+ }
335
+ function L(e, t) {
336
+ const n = e.productContextQuickPillLabel, o = { text: n };
337
+ return t && t.length > 0 && (o.sku_list = t), {
338
+ title: n,
339
+ type: "user_message",
340
+ payload: o
341
+ };
342
+ }
343
+ function st(e, t, n) {
344
+ const o = n?.skuList, a = [], i = [];
345
+ for (const c of e) {
346
+ const r = c.elements[c.root];
347
+ if (r?.type === "ActionButton") {
348
+ const d = r.props;
349
+ if (P(d, typeof d?.label == "string" ? d.label : void 0)?.type === "findSimilar") {
350
+ a.push(L(t, o));
351
+ continue;
352
+ }
353
+ }
354
+ i.push(c);
355
+ }
356
+ if (a.length === 0) return e;
357
+ const s = L(t, o), l = it(i);
358
+ if (!l) return [...i, at([s])];
359
+ if (!et(l, s.title)) {
360
+ const c = l.elements[l.root];
361
+ c?.type === "ActionButtons" ? ot(l, s) : c?.type === "ButtonRow" && nt(l, s);
362
+ }
363
+ return i;
364
+ }
365
+ var B = {
366
+ quickQuestionsAriaLabel: "Hızlı sorular",
367
+ askQuestionAriaLabel: "Soru sorun",
368
+ defaultInputPlaceholder: "Bir soru sorun...",
369
+ sendButton: "Sor",
370
+ sendQuestionAriaLabel: "Soruyu gönder",
371
+ defaultCtaText: "Başka bir şey sor",
372
+ redirectingToChat: "Sohbete yönlendiriliyor...",
373
+ productContextQuickPillLabel: "Bu ürün hakkında ne bilmeliyim?"
374
+ }, rt = {
375
+ quickQuestionsAriaLabel: "Quick questions",
376
+ askQuestionAriaLabel: "Ask a question",
377
+ defaultInputPlaceholder: "Ask a question...",
378
+ sendButton: "Ask",
379
+ sendQuestionAriaLabel: "Send question",
380
+ defaultCtaText: "Ask something else",
381
+ redirectingToChat: "Redirecting to chat...",
382
+ productContextQuickPillLabel: "What should I know about this product?"
383
+ };
384
+ function lt(e) {
385
+ return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
386
+ }
387
+ function ct(e) {
388
+ return lt(e) === "en" ? rt : B;
389
+ }
390
+ var dt = class extends D {
391
+ constructor(...e) {
392
+ super(...e), this._abortController = null, this._debounceTimer = null, this._contentEl = null, this._i18n = B, this._actionHandler = this._handleAction.bind(this), this._openChatHandler = this._handleOpenChat.bind(this);
393
+ }
394
+ async onInit(e) {
395
+ this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-qna-container", this._contentEl.dataset.gengagePart = "qna-container", this._contentEl.lang = E(e.locale);
396
+ const t = this._createChrome(e);
397
+ if (t) {
398
+ const o = document.createElement("div");
399
+ o.className = "gengage-qna-chrome-widget", o.dataset.gengagePart = "qna-chrome-widget", o.appendChild(this._contentEl), t.appendChild(o), this.root.appendChild(t);
400
+ } else this.root.appendChild(this._contentEl);
401
+ const n = e.pageContext?.sku;
402
+ n && (this._lastSku = n, await this._fetchAndRender(n)), J("qna");
403
+ }
404
+ onUpdate(e) {
405
+ const t = e.sku;
406
+ !t || t === this._lastSku || (this._debounceTimer && clearTimeout(this._debounceTimer), this._debounceTimer = setTimeout(() => {
407
+ this._debounceTimer = null, this._lastSku = t, this._fetchAndRender(t);
408
+ }, 50));
409
+ }
410
+ onShow() {
411
+ this._contentEl && (this._contentEl.style.opacity = "0", this._contentEl.style.transition = "opacity 0.2s ease-in", requestAnimationFrame(() => {
412
+ this._contentEl && (this._contentEl.style.opacity = "1");
413
+ }));
414
+ }
415
+ onHide() {
416
+ }
417
+ onDestroy() {
418
+ this._abort(), this._debounceTimer && (clearTimeout(this._debounceTimer), this._debounceTimer = null), this._contentEl && (this._cleanupTextInputTimers(), this._contentEl.remove(), this._contentEl = null);
419
+ }
420
+ _abort() {
421
+ this._abortController?.abort(), this._abortController = null;
422
+ }
423
+ _resolvedQnaHeaderTitle() {
424
+ const e = this.config.headerTitle ?? this.config.headingTitle;
425
+ if (typeof e != "string") return;
426
+ const t = e.trim();
427
+ return t.length > 0 ? t : void 0;
428
+ }
429
+ _cleanupTextInputTimers() {
430
+ if (!this._contentEl) return;
431
+ const e = this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");
432
+ for (const t of e) t._cleanup?.();
433
+ }
434
+ async _fetchAndRender(e) {
435
+ if (this._abort(), this._abortController = new AbortController(), !this._contentEl) return;
436
+ this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
437
+ const t = this._createLoadingIndicator();
438
+ this._contentEl.appendChild(t);
439
+ const n = { middlewareUrl: this.config.middlewareUrl }, o = crypto.randomUUID(), a = Date.now(), i = V({
440
+ source: "qna",
441
+ locale: this.config.locale
442
+ });
443
+ this.track(U(this.analyticsContext(), {
444
+ endpoint: "launcher_action",
445
+ request_id: o,
446
+ widget: "qna"
447
+ }));
448
+ try {
449
+ const s = {
450
+ account_id: this.config.accountId,
451
+ session_id: this.config.session?.sessionId ?? "",
452
+ correlation_id: this.config.session?.sessionId ?? "",
453
+ sku: e,
454
+ locale: E(this.config.locale)
455
+ }, l = this.config.pageContext?.pageType;
456
+ l !== void 0 && (s.page_type = l);
457
+ const c = await Y(s, n, this._abortController.signal);
458
+ if (this.track(j(this.analyticsContext(), {
459
+ request_id: o,
460
+ latency_ms: Date.now() - a,
461
+ chunk_count: c.actions.length,
462
+ widget: "qna"
463
+ })), this.track(F(this.analyticsContext(), {
464
+ message_count: c.actions.length,
465
+ history_ref: o,
466
+ redaction_level: "none",
467
+ widget: "qna"
468
+ })), !this._contentEl) return;
469
+ this._contentEl.innerHTML = "";
470
+ const r = document.createElement("div");
471
+ r.className = "gengage-qna-panel gds-panel", r.dataset.gengagePart = "qna-panel", this._contentEl.appendChild(r);
472
+ const d = this._specIncludesType(c.uiSpecs, "QuestionHeading"), y = this._resolvedQnaHeaderTitle() ?? (this.config.showStaticQuestion && this.config.staticQuestionText ? this.config.staticQuestionText : void 0);
473
+ if (!d && y) {
474
+ const f = document.createElement("h3");
475
+ f.className = "gengage-qna-heading", f.textContent = y, r.appendChild(f);
476
+ }
477
+ const m = this.config.inputPlaceholder;
478
+ let h;
479
+ if (m !== !0) h = m ?? this._i18n.defaultInputPlaceholder;
480
+ else if (c.actions.length > 0) {
481
+ const f = c.actions.filter((_) => _.type === "user_message" || _.title.includes("?")).map((_) => _.title);
482
+ h = f.length > 0 ? f : this._i18n.defaultInputPlaceholder;
483
+ } else h = this._i18n.defaultInputPlaceholder;
484
+ const p = {
485
+ onAction: this._actionHandler,
486
+ i18n: this._i18n
487
+ }, g = this._resolvedQnaHeaderTitle();
488
+ g !== void 0 && (p.headingTitleOverride = g), this.config.hideButtonRowCta || (p.onOpenChat = this._openChatHandler, this.config.ctaText !== void 0 && (p.ctaText = this.config.ctaText)), h !== void 0 && (p.inputPlaceholder = h);
489
+ const b = this._buildFallbackActionsSpec(c.actions), v = tt(this.config.pageContext), u = (c.uiSpecs.length > 0 ? st(c.uiSpecs, this._i18n, { skuList: v }) : [b]).filter((f) => Object.keys(f.elements).length > 0);
490
+ for (const f of u) {
491
+ const _ = this._renderUISpec(f, p);
492
+ r.appendChild(_);
493
+ }
494
+ u.length > 0 && G("qna"), this._specIncludesType(u, "TextInput") || this._insertStandaloneInputBeforePills(r, p, h);
495
+ } catch (s) {
496
+ if (s instanceof DOMException && s.name === "AbortError") return;
497
+ if (A("gengage:global:error", {
498
+ source: "qna",
499
+ code: "FETCH_ERROR",
500
+ message: M(this.config.locale, s)
501
+ }), this.track(W(this.analyticsContext(), {
502
+ request_id: o,
503
+ error_code: "FETCH_ERROR",
504
+ error_message: s instanceof Error ? s.message : String(s),
505
+ widget: "qna"
506
+ })), this._contentEl) {
507
+ this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
508
+ const l = document.createElement("div");
509
+ l.className = "gengage-qna-panel", this._contentEl.appendChild(l);
510
+ const c = this.config.inputPlaceholder === !0 ? this._i18n.defaultInputPlaceholder : this.config.inputPlaceholder ?? this._i18n.defaultInputPlaceholder, r = {
511
+ onAction: this._actionHandler,
512
+ i18n: this._i18n,
513
+ onOpenChat: this._openChatHandler
514
+ }, d = this._resolvedQnaHeaderTitle();
515
+ d !== void 0 && (r.headingTitleOverride = d), this.config.ctaText !== void 0 && (r.ctaText = this.config.ctaText), this._appendStandaloneInput(r, c, l);
516
+ }
517
+ } finally {
518
+ i();
519
+ }
520
+ }
521
+ _createLoadingIndicator() {
522
+ const e = document.createElement("div");
523
+ e.className = "gengage-qna-loading";
524
+ for (let t = 0; t < 3; t++) {
525
+ const n = document.createElement("div");
526
+ n.className = "gengage-qna-loading-dot", e.appendChild(n);
527
+ }
528
+ return e;
529
+ }
530
+ _resolveI18n(e) {
531
+ return {
532
+ ...ct(e.locale),
533
+ ...e.i18n
534
+ };
535
+ }
536
+ _createChrome(e) {
537
+ const t = e.chrome;
538
+ if (!t) return null;
539
+ const n = typeof t.title == "string" ? t.title.trim() : "", o = typeof t.subtitle == "string" ? t.subtitle.trim() : "", a = typeof t.startButtonLabel == "string" ? t.startButtonLabel.trim() : "", i = typeof t.imageUrl == "string" ? t.imageUrl.trim() : "", s = typeof t.imagePadding == "string" ? t.imagePadding.trim() : "", l = document.createElement("section");
540
+ l.className = "gengage-qna-chrome", l.dataset.gengagePart = "qna-chrome", t.layout === "side-image" && (l.classList.add("gengage-qna-chrome--side-image"), l.dataset.gengageChromeLayout = "side-image"), s && l.style.setProperty("--gengage-qna-chrome-image-padding", s);
541
+ const c = document.createElement("div");
542
+ if (c.className = "gengage-qna-chrome-copy", c.dataset.gengagePart = "qna-chrome-copy", n) {
543
+ const r = document.createElement("h2");
544
+ r.className = "gengage-qna-chrome-title", r.dataset.gengagePart = "qna-chrome-title", r.textContent = n, c.appendChild(r);
545
+ }
546
+ if (o) {
547
+ const r = document.createElement("p");
548
+ r.className = "gengage-qna-chrome-subtitle", r.dataset.gengagePart = "qna-chrome-subtitle", r.textContent = o, c.appendChild(r);
549
+ }
550
+ if (c.children.length > 0 && l.appendChild(c), i && z(i)) {
551
+ const r = document.createElement("img");
552
+ r.className = "gengage-qna-chrome-image", r.dataset.gengagePart = "qna-chrome-image", r.src = i, r.alt = typeof t.imageAlt == "string" ? t.imageAlt : "", r.loading = "lazy", r.addEventListener("error", () => {
553
+ r.style.display = "none";
554
+ }, { once: !0 }), l.appendChild(r);
555
+ }
556
+ if (a) {
557
+ const r = document.createElement("button");
558
+ r.className = "gengage-qna-chrome-start", r.dataset.gengagePart = "qna-chrome-start", r.type = "button", r.textContent = a, r.addEventListener("click", () => this._handleOpenChat()), l.appendChild(r);
559
+ }
560
+ return l.children.length === 0 ? null : l;
561
+ }
562
+ _resolveUISpecRegistry() {
563
+ return R(K(), this.config.renderer?.registry);
564
+ }
565
+ _renderUISpec(e, t) {
566
+ const n = this._resolveUISpecRegistry(), o = this.config.renderer?.unknownRenderer ?? w, a = (s, l) => X(s, l, n, o), i = this.config.renderer?.renderUISpec;
567
+ return i ? i(e, t, {
568
+ registry: n,
569
+ unknownRenderer: o,
570
+ defaultRender: a
571
+ }) : a(e, t);
572
+ }
573
+ _specIncludesType(e, t) {
574
+ for (const n of e) for (const o of Object.values(n.elements)) if (o.type === t) return !0;
575
+ return !1;
576
+ }
577
+ _buildFallbackActionsSpec(e) {
578
+ if (e.length === 0) return {
579
+ root: "root",
580
+ elements: {}
581
+ };
582
+ const t = {}, n = [];
583
+ for (let o = 0; o < e.length; o++) {
584
+ const a = e[o], i = `action-${o}`;
585
+ n.push(i), t[i] = {
586
+ type: "ActionButton",
587
+ props: {
588
+ label: a.title,
589
+ action: {
590
+ title: a.title,
591
+ type: a.type,
592
+ payload: a.payload
593
+ }
594
+ }
595
+ };
596
+ }
597
+ return t.root = {
598
+ type: "ButtonRow",
599
+ children: n
600
+ }, {
601
+ root: "root",
602
+ elements: t
603
+ };
604
+ }
605
+ _insertStandaloneInputBeforePills(e, t, n) {
606
+ const o = {
607
+ root: "root",
608
+ elements: { root: {
609
+ type: "TextInput",
610
+ props: { placeholder: n }
611
+ } }
612
+ }, a = this._renderUISpec(o, t), i = a.querySelector(".gengage-qna-input-wrapper");
613
+ if (!i) return;
614
+ const s = e.querySelector(".gengage-qna-uispec"), l = s?.querySelector(":scope > .gengage-qna-buttons");
615
+ if (s && l) s.insertBefore(i, l);
616
+ else if (s) {
617
+ const c = s.querySelector(":scope > .gengage-qna-heading");
618
+ c ? c.insertAdjacentElement("afterend", i) : s.prepend(i);
619
+ } else {
620
+ e.appendChild(a);
621
+ return;
622
+ }
623
+ a.remove();
624
+ }
625
+ _appendStandaloneInput(e, t, n) {
626
+ if (!this._contentEl) return;
627
+ const o = {
628
+ root: "root",
629
+ elements: { root: {
630
+ type: "TextInput",
631
+ props: { placeholder: t }
632
+ } }
633
+ }, a = this._renderUISpec(o, e);
634
+ (n ?? this._contentEl).appendChild(a);
635
+ }
636
+ _handleAction(e) {
637
+ this._showTransitionIndicator(), $(e.title, e.type), this.config.onActionSelected?.(e), setTimeout(() => A("gengage:qna:action", e), 350);
638
+ }
639
+ _handleOpenChat() {
640
+ this._showTransitionIndicator(), this.config.onOpenChat?.(), setTimeout(() => A("gengage:qna:open-chat", {}), 350);
641
+ }
642
+ _showTransitionIndicator() {
643
+ if (!this._contentEl) return;
644
+ this._contentEl.querySelector(".gengage-qna-transition-indicator")?.remove(), this._contentEl.classList.add("gengage-qna--transitioning");
645
+ const e = this._i18n.redirectingToChat ?? "Redirecting to chat...", t = document.createElement("div");
646
+ t.className = "gengage-qna-transition-indicator", t.textContent = e, (this._contentEl.querySelector(".gengage-qna-panel") ?? this._contentEl).appendChild(t), setTimeout(() => {
647
+ this._contentEl?.classList.remove("gengage-qna--transitioning"), t.remove();
648
+ }, 600);
649
+ }
650
+ };
651
+ function mt() {
652
+ return new dt();
653
+ }
654
+ export {
655
+ X as a,
656
+ w as i,
657
+ mt as n,
658
+ K as r,
659
+ dt as t
660
+ };