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