@gengage/assistant-fe 0.4.5 → 0.4.7

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