@gengage/assistant-fe 0.4.13 → 0.4.15

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.
@@ -1,42 +1,42 @@
1
- import { f as R, m as Q, r as N, t as H, u as O } from "./api-paths-BX3Lea3A.js";
2
- import { S as U, b as j, i as M, t as D, w as F, x as W } from "./widget-base-bdJaGJYi.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-C7ehvQxx.js";
6
- async function Y(e, t, n) {
7
- const o = H("launcher_action", t), a = {
1
+ import { f as Q, m as N, r as H, t as O, u as U } from "./api-paths-BX3Lea3A.js";
2
+ import { S as j, b as M, i as D, t as F, w as W, x as z } from "./widget-base-bdJaGJYi.js";
3
+ import { A as $, D as G, E as J, a as E, v as V } from "./context-DGz5F81j.js";
4
+ import { t as T } from "./locale-CfqNifrU.js";
5
+ import { n as Y } from "./connection-warning-C7ehvQxx.js";
6
+ async function Z(e, t, n) {
7
+ const o = O("launcher_action", t), i = {
8
8
  uiSpecs: [],
9
9
  actions: []
10
- }, i = {
10
+ }, a = {
11
11
  method: "POST",
12
12
  headers: { "Content-Type": "application/json" },
13
13
  body: JSON.stringify(e)
14
14
  };
15
- n !== void 0 && (i.signal = n);
16
- const r = await fetch(o, i);
17
- if (!r.ok) throw new Error(`HTTP ${r.status}: ${r.statusText}`);
18
- const l = { onEvent: (c) => {
19
- const s = N(c);
20
- if (s && (s.type === "ui_spec" && a.uiSpecs.push(s.spec), s.type === "ui_spec" && s.spec.elements)) {
15
+ n !== void 0 && (a.signal = n);
16
+ const l = await fetch(o, a);
17
+ if (!l.ok) throw new Error(`HTTP ${l.status}: ${l.statusText}`);
18
+ const r = { onEvent: (c) => {
19
+ const s = H(c);
20
+ if (s && (s.type === "ui_spec" && i.uiSpecs.push(s.spec), s.type === "ui_spec" && s.spec.elements)) {
21
21
  for (const d of Object.values(s.spec.elements)) if (d.type === "ActionButton" && d.props?.action) {
22
- const y = d.props.action;
23
- a.actions.push(y);
22
+ const b = d.props.action;
23
+ i.actions.push(b);
24
24
  }
25
25
  }
26
26
  } };
27
- return n !== void 0 && (l.signal = n), await O(r, l), a;
27
+ return n !== void 0 && (r.signal = n), await U(l, r), i;
28
28
  }
29
- function T(e) {
29
+ function C(e) {
30
30
  const t = document.createElement("div");
31
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
32
  for (const n of e.actions) {
33
33
  const o = document.createElement("button");
34
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 = {
35
+ const i = {
36
36
  title: n.title,
37
37
  type: n.type
38
38
  };
39
- n.payload !== void 0 && (a.payload = n.payload), e.onAction(a);
39
+ n.payload !== void 0 && (i.payload = n.payload), e.onAction(i);
40
40
  }), t.appendChild(o);
41
41
  }
42
42
  if (e.ctaText || e.onOpenChat) {
@@ -47,57 +47,57 @@ function T(e) {
47
47
  }
48
48
  return t;
49
49
  }
50
- function Z(e) {
50
+ function K(e) {
51
51
  const t = document.createElement("div");
52
52
  t.className = "gengage-qna-input-wrapper", t.dataset.gengagePart = "qna-input-wrapper";
53
53
  const n = document.createElement("div");
54
54
  n.className = "gengage-qna-input-combo", n.dataset.gengagePart = "qna-input-combo";
55
55
  const o = document.createElement("input");
56
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, r = a[0] ?? "";
59
- o.placeholder = r;
60
- let l = null, c = null, s = !1;
57
+ const i = Array.isArray(e.placeholders) ? e.placeholders : e.placeholders ? [e.placeholders] : [e.defaultInputPlaceholder ?? "Ask a question..."];
58
+ let a = 0, l = i[0] ?? "";
59
+ o.placeholder = l;
60
+ let r = null, c = null, s = !1;
61
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 && !s && 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, r = a[i] ?? "", o.placeholder = r, o.classList.remove("gengage-qna-input--fade");
62
+ r && clearInterval(r), r = null, c && clearTimeout(c), c = null, o.classList.remove("gengage-qna-input--fade");
63
+ }, b = () => i.length > 1 && !s && o.value.trim().length === 0, f = () => {
64
+ d(), b() && (r = setInterval(() => {
65
+ b() && (o.classList.add("gengage-qna-input--fade"), c = setTimeout(() => {
66
+ a = (a + 1) % i.length, l = i[a] ?? "", o.placeholder = l, o.classList.remove("gengage-qna-input--fade");
67
67
  }, 180));
68
68
  }, 3e3));
69
- }, h = document.createElement("div");
70
- h.className = "gengage-qna-input-actions", h.dataset.gengagePart = "qna-input-actions";
69
+ }, m = document.createElement("div");
70
+ m.className = "gengage-qna-input-actions", m.dataset.gengagePart = "qna-input-actions";
71
71
  const p = document.createElement("button");
72
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;
73
+ const u = document.createElement("button");
74
+ u.className = "gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden", u.type = "button", u.dataset.gengagePart = "qna-send", u.setAttribute("aria-label", e.sendQuestionAriaLabel ?? "Send question"), u.disabled = !0, u.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 y = () => {
76
+ const g = o.value.trim().length > 0;
77
+ p.classList.toggle("gengage-qna-icon-btn--hidden", !g), u.classList.toggle("gengage-qna-icon-btn--hidden", !g), u.classList.toggle("gengage-qna-send--active", g), u.disabled = !g;
78
78
  }, v = () => {
79
- const u = o.value.trim();
80
- u && (e.onSubmit({
81
- title: u,
79
+ const g = o.value.trim();
80
+ g && (e.onSubmit({
81
+ title: g,
82
82
  type: "user_message",
83
- payload: u
84
- }), o.value = "", b(), m());
83
+ payload: g
84
+ }), o.value = "", y(), f());
85
85
  };
86
86
  return p.addEventListener("click", () => {
87
- o.value = "", b(), o.focus({ preventScroll: !0 });
88
- }), g.addEventListener("click", v), o.addEventListener("focus", () => {
87
+ o.value = "", y(), o.focus({ preventScroll: !0 });
88
+ }), u.addEventListener("click", v), o.addEventListener("focus", () => {
89
89
  s = !0, d(), o.placeholder = "";
90
90
  }), o.addEventListener("blur", () => {
91
- s = !1, o.value.trim().length === 0 && (o.placeholder = r), m();
91
+ s = !1, o.value.trim().length === 0 && (o.placeholder = l), f();
92
92
  }), o.addEventListener("input", () => {
93
- if (b(), o.value.trim().length > 0) {
93
+ if (y(), o.value.trim().length > 0) {
94
94
  d();
95
95
  return;
96
96
  }
97
- o.placeholder = s ? "" : r, 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 = () => {
97
+ o.placeholder = s ? "" : l, f();
98
+ }), o.addEventListener("keydown", (g) => {
99
+ g.key === "Enter" && (g.preventDefault(), v()), g.key === "Escape" && o.value.length > 0 && (o.value = "", y(), f());
100
+ }), m.appendChild(p), m.appendChild(u), n.appendChild(o), n.appendChild(m), t.appendChild(n), y(), f(), t._cleanup = () => {
101
101
  d();
102
102
  }, t;
103
103
  }
@@ -105,100 +105,100 @@ function q(e, t) {
105
105
  if (!e || typeof e != "object") return null;
106
106
  const n = e, o = n.type;
107
107
  if (typeof o != "string" || o.length === 0) return null;
108
- const a = n.title, i = n.payload, r = typeof a == "string" && a.length > 0 ? a : t;
109
- if (!r) return null;
110
- const l = {
111
- title: r,
108
+ const i = n.title, a = n.payload, l = typeof i == "string" && i.length > 0 ? i : t;
109
+ if (!l) return null;
110
+ const r = {
111
+ title: l,
112
112
  type: o
113
113
  };
114
- return i !== void 0 && (l.payload = i), l;
114
+ return a !== void 0 && (r.payload = a), r;
115
115
  }
116
- function C(e) {
116
+ function k(e) {
117
117
  const t = {
118
118
  title: e.title,
119
119
  type: e.type
120
120
  };
121
121
  return e.payload !== void 0 && (t.payload = e.payload), t;
122
122
  }
123
- function k(e, t) {
123
+ function I(e, t) {
124
124
  const n = [], o = e.props?.actions;
125
- if (Array.isArray(o)) for (const r of o) {
126
- const l = q(r);
127
- l && n.push(l);
128
- }
129
- const a = e.props?.buttons;
130
- if (Array.isArray(a)) for (const r of a) {
131
- if (!r || typeof r != "object") continue;
132
- const l = r, c = typeof l.label == "string" ? l.label : void 0, s = q(l.action, c);
125
+ if (Array.isArray(o)) for (const l of o) {
126
+ const r = q(l);
127
+ r && n.push(r);
128
+ }
129
+ const i = e.props?.buttons;
130
+ if (Array.isArray(i)) for (const l of i) {
131
+ if (!l || typeof l != "object") continue;
132
+ const r = l, c = typeof r.label == "string" ? r.label : void 0, s = q(r.action, c);
133
133
  s && n.push(s);
134
134
  }
135
- if (e.children) for (const r of e.children) {
136
- const l = t.elements[r];
137
- if (!l || l.type !== "ActionButton") continue;
138
- const c = typeof l.props?.label == "string" ? l.props.label : void 0, s = q(l.props?.action, c);
135
+ if (e.children) for (const l of e.children) {
136
+ const r = t.elements[l];
137
+ if (!r || r.type !== "ActionButton") continue;
138
+ const c = typeof r.props?.label == "string" ? r.props.label : void 0, s = q(r.props?.action, c);
139
139
  s && n.push(s);
140
140
  }
141
- const i = /* @__PURE__ */ new Set();
142
- return n.filter((r) => i.has(r.title) ? !1 : (i.add(r.title), !0));
141
+ const a = /* @__PURE__ */ new Set();
142
+ return n.filter((l) => a.has(l.title) ? !1 : (a.add(l.title), !0));
143
143
  }
144
- var I = {
144
+ var w = {
145
145
  ButtonRow: ({ element: e, spec: t, context: n }) => {
146
- const o = k(e, t).map(C), a = e.props?.orientation, i = {
146
+ const o = I(e, t).map(k), i = e.props?.orientation, a = {
147
147
  actions: o,
148
148
  onAction: n.onAction,
149
149
  defaultCtaText: n.i18n.defaultCtaText,
150
150
  quickQuestionsAriaLabel: n.i18n.quickQuestionsAriaLabel
151
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);
152
+ return n.onOpenChat !== void 0 && (a.onOpenChat = n.onOpenChat), n.ctaText !== void 0 && (a.ctaText = n.ctaText), (i === "horizontal" || i === "vertical") && (a.orientation = i), C(a);
153
153
  },
154
154
  ActionButtons: ({ element: e, spec: t, context: n }) => {
155
155
  const o = {
156
- actions: k(e, t).map(C),
156
+ actions: I(e, t).map(k),
157
157
  onAction: n.onAction,
158
158
  defaultCtaText: n.i18n.defaultCtaText,
159
159
  quickQuestionsAriaLabel: n.i18n.quickQuestionsAriaLabel
160
160
  };
161
- return n.onOpenChat !== void 0 && (o.onOpenChat = n.onOpenChat), n.ctaText !== void 0 && (o.ctaText = n.ctaText), T(o);
161
+ return n.onOpenChat !== void 0 && (o.onOpenChat = n.onOpenChat), n.ctaText !== void 0 && (o.ctaText = n.ctaText), C(o);
162
162
  },
163
163
  ActionButton: ({ element: e, context: t }) => {
164
164
  const n = document.createElement("button");
165
165
  n.className = "gengage-qna-button gds-chip", n.type = "button", n.dataset.gengagePart = "qna-action-button";
166
166
  const o = e.props?.label;
167
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;
168
+ const i = q(e.props?.action, typeof o == "string" ? o : void 0);
169
+ return i && n.addEventListener("click", () => t.onAction(i)), n;
170
170
  },
171
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 = {
172
+ const n = e.props?.placeholder, o = typeof n == "string" || Array.isArray(n) ? n : t.inputPlaceholder, i = typeof e.props?.ctaLabel == "string" ? e.props.ctaLabel : void 0, a = {
173
173
  onSubmit: t.onAction,
174
174
  askQuestionAriaLabel: t.i18n.askQuestionAriaLabel,
175
175
  defaultInputPlaceholder: t.i18n.defaultInputPlaceholder,
176
176
  sendButtonText: t.i18n.sendButton,
177
177
  sendQuestionAriaLabel: t.i18n.sendQuestionAriaLabel
178
178
  };
179
- return o !== void 0 && (i.placeholders = o), a !== void 0 && (i.ctaLabel = a), Z(i);
179
+ return o !== void 0 && (a.placeholders = o), i !== void 0 && (a.ctaLabel = i), K(a);
180
180
  },
181
181
  QuestionHeading: ({ element: e, context: t }) => {
182
182
  const n = document.createElement("h3");
183
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;
184
+ const o = e.props?.text, i = t.headingTitleOverride;
185
+ return n.textContent = typeof i == "string" && i.trim().length > 0 ? i : typeof o == "string" ? o : "", n;
186
186
  },
187
187
  ProductCard: () => null
188
188
  }, P = ({ element: e, renderElement: t }) => {
189
189
  if (!e.children || e.children.length === 0) return null;
190
190
  const n = document.createElement("div");
191
191
  for (const o of e.children) {
192
- const a = t(o);
193
- a && n.appendChild(a);
192
+ const i = t(o);
193
+ i && n.appendChild(i);
194
194
  }
195
195
  return n;
196
196
  };
197
- function K() {
198
- return { ...I };
197
+ function X() {
198
+ return { ...w };
199
199
  }
200
- function X(e, t, n = I, o = P) {
201
- return Q({
200
+ function tt(e, t, n = w, o = P) {
201
+ return N({
202
202
  spec: e,
203
203
  context: t,
204
204
  registry: n,
@@ -206,62 +206,62 @@ function X(e, t, n = I, o = P) {
206
206
  unknownRenderer: o
207
207
  });
208
208
  }
209
- function tt(e) {
209
+ function et(e) {
210
210
  if (!e) return;
211
211
  const t = e.extra;
212
212
  if (t && typeof t == "object" && !Array.isArray(t)) {
213
213
  const o = t.visible_skus ?? t.visibleSkus;
214
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;
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
217
  }
218
218
  }
219
219
  const n = typeof e.sku == "string" && e.sku.trim() ? e.sku.trim() : void 0;
220
220
  return n ? [n] : void 0;
221
221
  }
222
- function w(e, t) {
222
+ function x(e, t) {
223
223
  if (!e) return null;
224
224
  const n = e.action;
225
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, r = typeof i == "string" && i.length > 0 ? i : typeof t == "string" && t.length > 0 ? t : "";
229
- if (!r) return null;
230
- const l = o.payload, c = {
231
- title: r,
232
- type: a
226
+ const o = n, i = o.type;
227
+ if (typeof i != "string" || i.length === 0) return null;
228
+ const a = o.title, l = typeof a == "string" && a.length > 0 ? a : typeof t == "string" && t.length > 0 ? t : "";
229
+ if (!l) return null;
230
+ const r = o.payload, c = {
231
+ title: l,
232
+ type: i
233
233
  };
234
- return l !== void 0 && (c.payload = l), c;
234
+ return r !== void 0 && (c.payload = r), c;
235
235
  }
236
- function et(e, t) {
236
+ function nt(e, t) {
237
237
  const n = e.elements[e.root];
238
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 r = typeof i.label == "string" ? i.label : void 0;
244
- return r === t ? !0 : w(i, r)?.title === t;
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 l = typeof a.label == "string" ? a.label : void 0;
244
+ return l === t ? !0 : x(a, l)?.title === t;
245
245
  };
246
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;
247
+ if (n.children) for (const i of n.children) {
248
+ const a = e.elements[i];
249
+ if (a && o(a)) return !0;
250
250
  }
251
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;
252
+ for (const i of n.props.buttons)
253
+ if (i?.label === t || i?.action?.title === t) return !0;
254
254
  }
255
255
  return !1;
256
256
  }
257
257
  var S = 0;
258
- function x() {
258
+ function B() {
259
259
  return S += 1, `gengage-merge-${S}`;
260
260
  }
261
- function nt(e, t) {
261
+ function ot(e, t) {
262
262
  const n = e.elements[e.root];
263
263
  if (!n || n.type !== "ButtonRow") return;
264
- const o = x();
264
+ const o = B();
265
265
  e.elements[o] = {
266
266
  type: "ActionButton",
267
267
  props: {
@@ -274,10 +274,10 @@ function nt(e, t) {
274
274
  }
275
275
  }, n.children = n.children ? [o, ...n.children] : [o];
276
276
  }
277
- function ot(e, t) {
277
+ function it(e, t) {
278
278
  const n = e.elements[e.root];
279
279
  if (!n || n.type !== "ActionButtons") return;
280
- const o = x();
280
+ const o = B();
281
281
  e.elements[o] = {
282
282
  type: "ActionButton",
283
283
  props: {
@@ -289,7 +289,7 @@ function ot(e, t) {
289
289
  }
290
290
  }
291
291
  }, n.children = n.children ? [o, ...n.children] : [o];
292
- const a = n.props?.buttons ?? [], i = {
292
+ const i = n.props?.buttons ?? [], a = {
293
293
  label: t.title,
294
294
  action: {
295
295
  title: t.title,
@@ -299,21 +299,21 @@ function ot(e, t) {
299
299
  };
300
300
  n.props = {
301
301
  ...n.props,
302
- buttons: [i, ...a]
302
+ buttons: [a, ...i]
303
303
  };
304
304
  }
305
305
  function at(e) {
306
306
  const t = {}, n = [];
307
307
  for (let o = 0; o < e.length; o++) {
308
- const a = e[o], i = `action-${o}`;
309
- n.push(i), t[i] = {
308
+ const i = e[o], a = `action-${o}`;
309
+ n.push(a), t[a] = {
310
310
  type: "ActionButton",
311
311
  props: {
312
- label: a.title,
312
+ label: i.title,
313
313
  action: {
314
- title: a.title,
315
- type: a.type,
316
- ...a.payload !== void 0 ? { payload: a.payload } : {}
314
+ title: i.title,
315
+ type: i.type,
316
+ ...i.payload !== void 0 ? { payload: i.payload } : {}
317
317
  }
318
318
  }
319
319
  };
@@ -326,7 +326,7 @@ function at(e) {
326
326
  elements: t
327
327
  };
328
328
  }
329
- function it(e) {
329
+ function st(e) {
330
330
  return e.find((t) => {
331
331
  const n = t.elements[t.root];
332
332
  return n?.type === "ActionButtons" || n?.type === "ButtonRow";
@@ -340,29 +340,29 @@ function L(e, t) {
340
340
  payload: o
341
341
  };
342
342
  }
343
- function st(e, t, n) {
344
- const o = n?.skuList, a = [], i = [];
343
+ function rt(e, t, n) {
344
+ const o = n?.skuList, i = [], a = [];
345
345
  for (const c of e) {
346
346
  const s = c.elements[c.root];
347
347
  if (s?.type === "ActionButton") {
348
348
  const d = s.props;
349
- if (w(d, typeof d?.label == "string" ? d.label : void 0)?.type === "findSimilar") {
350
- a.push(L(t, o));
349
+ if (x(d, typeof d?.label == "string" ? d.label : void 0)?.type === "findSimilar") {
350
+ i.push(L(t, o));
351
351
  continue;
352
352
  }
353
353
  }
354
- i.push(c);
354
+ a.push(c);
355
355
  }
356
- if (a.length === 0) return e;
357
- const r = L(t, o), l = it(i);
358
- if (!l) return [...i, at([r])];
359
- if (!et(l, r.title)) {
360
- const c = l.elements[l.root];
361
- c?.type === "ActionButtons" ? ot(l, r) : c?.type === "ButtonRow" && nt(l, r);
356
+ if (i.length === 0) return e;
357
+ const l = L(t, o), r = st(a);
358
+ if (!r) return [...a, at([l])];
359
+ if (!nt(r, l.title)) {
360
+ const c = r.elements[r.root];
361
+ c?.type === "ActionButtons" ? it(r, l) : c?.type === "ButtonRow" && ot(r, l);
362
362
  }
363
- return i;
363
+ return a;
364
364
  }
365
- var B = {
365
+ var R = {
366
366
  quickQuestionsAriaLabel: "Hızlı sorular",
367
367
  askQuestionAriaLabel: "Soru sorun",
368
368
  defaultInputPlaceholder: "Bir soru sorun...",
@@ -371,7 +371,7 @@ var B = {
371
371
  defaultCtaText: "Başka bir şey sor",
372
372
  redirectingToChat: "Sohbete yönlendiriliyor...",
373
373
  productContextQuickPillLabel: "Bu ürün hakkında ne bilmeliyim?"
374
- }, rt = {
374
+ }, lt = {
375
375
  quickQuestionsAriaLabel: "Quick questions",
376
376
  askQuestionAriaLabel: "Ask a question",
377
377
  defaultInputPlaceholder: "Ask a question...",
@@ -381,25 +381,25 @@ var B = {
381
381
  redirectingToChat: "Redirecting to chat...",
382
382
  productContextQuickPillLabel: "What should I know about this product?"
383
383
  };
384
- function lt(e) {
384
+ function ct(e) {
385
385
  return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
386
386
  }
387
- function ct(e) {
388
- return lt(e) === "en" ? rt : B;
387
+ function dt(e) {
388
+ return ct(e) === "en" ? lt : R;
389
389
  }
390
- var dt = class extends D {
390
+ var ut = class extends F {
391
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);
392
+ super(...e), this._abortController = null, this._debounceTimer = null, this._contentEl = null, this._i18n = R, this._actionHandler = this._handleAction.bind(this), this._openChatHandler = this._handleOpenChat.bind(this);
393
393
  }
394
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);
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 = T(e.locale);
396
396
  const t = this._createChrome(e);
397
397
  if (t) {
398
398
  const o = document.createElement("div");
399
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
400
  } else this.root.appendChild(this._contentEl);
401
401
  const n = e.pageContext?.sku;
402
- n && (this._lastSku = n, await this._fetchAndRender(n)), J("qna");
402
+ n && (this._lastSku = n, await this._fetchAndRender(n)), V("qna");
403
403
  }
404
404
  onUpdate(e) {
405
405
  const t = e.sku;
@@ -436,86 +436,88 @@ var dt = class extends D {
436
436
  this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
437
437
  const t = this._createLoadingIndicator();
438
438
  this._contentEl.appendChild(t);
439
- const n = { middlewareUrl: this.config.middlewareUrl }, o = crypto.randomUUID(), a = Date.now(), i = V({
439
+ const n = { middlewareUrl: this.config.middlewareUrl }, o = crypto.randomUUID(), i = Date.now(), a = Y({
440
440
  source: "qna",
441
441
  locale: this.config.locale
442
442
  });
443
- this.track(U(this.analyticsContext(), {
443
+ this.track(j(this.analyticsContext(), {
444
444
  endpoint: "launcher_action",
445
445
  request_id: o,
446
446
  widget: "qna"
447
447
  }));
448
448
  try {
449
- const r = {
449
+ const l = this.config.session?.sessionId ?? "", r = {
450
450
  account_id: this.config.accountId,
451
- session_id: this.config.session?.sessionId ?? "",
452
- correlation_id: this.config.session?.sessionId ?? "",
451
+ session_id: l,
452
+ correlation_id: l,
453
453
  sku: e,
454
- locale: E(this.config.locale)
455
- }, l = this.config.pageContext?.pageType;
456
- l !== void 0 && (r.page_type = l);
457
- const c = await Y(r, n, this._abortController.signal);
458
- if (this.track(j(this.analyticsContext(), {
454
+ locale: T(this.config.locale)
455
+ };
456
+ this.config.session?.userId !== void 0 && (r.user_id = this.config.session.userId), this.config.session?.viewId !== void 0 && (r.view_id = this.config.session.viewId);
457
+ const c = this.config.pageContext?.pageType;
458
+ c !== void 0 && (r.page_type = c);
459
+ const s = await Z(r, n, this._abortController.signal);
460
+ if (this.track(M(this.analyticsContext(), {
459
461
  request_id: o,
460
- latency_ms: Date.now() - a,
461
- chunk_count: c.actions.length,
462
+ latency_ms: Date.now() - i,
463
+ chunk_count: s.actions.length,
462
464
  widget: "qna"
463
- })), this.track(F(this.analyticsContext(), {
464
- message_count: c.actions.length,
465
+ })), this.track(W(this.analyticsContext(), {
466
+ message_count: s.actions.length,
465
467
  history_ref: o,
466
468
  redaction_level: "none",
467
469
  widget: "qna"
468
470
  })), !this._contentEl) return;
469
471
  this._contentEl.innerHTML = "";
470
- const s = document.createElement("div");
471
- s.className = "gengage-qna-panel gds-panel", s.dataset.gengagePart = "qna-panel", this._contentEl.appendChild(s);
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, s.appendChild(f);
472
+ const d = document.createElement("div");
473
+ d.className = "gengage-qna-panel gds-panel", d.dataset.gengagePart = "qna-panel", this._contentEl.appendChild(d);
474
+ const b = this._specIncludesType(s.uiSpecs, "QuestionHeading"), f = this._resolvedQnaHeaderTitle() ?? (this.config.showStaticQuestion && this.config.staticQuestionText ? this.config.staticQuestionText : void 0);
475
+ if (!b && f) {
476
+ const h = document.createElement("h3");
477
+ h.className = "gengage-qna-heading", h.textContent = f, d.appendChild(h);
476
478
  }
477
479
  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 = {
480
+ let p;
481
+ if (m !== !0) p = m ?? this._i18n.defaultInputPlaceholder;
482
+ else if (s.actions.length > 0) {
483
+ const h = s.actions.filter((_) => _.type === "user_message" || _.title.includes("?")).map((_) => _.title);
484
+ p = h.length > 0 ? h : this._i18n.defaultInputPlaceholder;
485
+ } else p = this._i18n.defaultInputPlaceholder;
486
+ const u = {
485
487
  onAction: this._actionHandler,
486
488
  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
- s.appendChild(_);
489
+ }, y = this._resolvedQnaHeaderTitle();
490
+ y !== void 0 && (u.headingTitleOverride = y), this.config.hideButtonRowCta || (u.onOpenChat = this._openChatHandler, this.config.ctaText !== void 0 && (u.ctaText = this.config.ctaText)), p !== void 0 && (u.inputPlaceholder = p);
491
+ const v = this._buildFallbackActionsSpec(s.actions), g = et(this.config.pageContext), A = (s.uiSpecs.length > 0 ? rt(s.uiSpecs, this._i18n, { skuList: g }) : [v]).filter((h) => Object.keys(h.elements).length > 0);
492
+ for (const h of A) {
493
+ const _ = this._renderUISpec(h, u);
494
+ d.appendChild(_);
493
495
  }
494
- u.length > 0 && G("qna"), this._specIncludesType(u, "TextInput") || this._insertStandaloneInputBeforePills(s, p, h);
495
- } catch (r) {
496
- if (r instanceof DOMException && r.name === "AbortError") return;
497
- if (A("gengage:global:error", {
496
+ A.length > 0 && J("qna"), this._specIncludesType(A, "TextInput") || this._insertStandaloneInputBeforePills(d, u, p);
497
+ } catch (l) {
498
+ if (l instanceof DOMException && l.name === "AbortError") return;
499
+ if (E("gengage:global:error", {
498
500
  source: "qna",
499
501
  code: "FETCH_ERROR",
500
- message: M(this.config.locale, r)
501
- }), this.track(W(this.analyticsContext(), {
502
+ message: D(this.config.locale, l)
503
+ }), this.track(z(this.analyticsContext(), {
502
504
  request_id: o,
503
505
  error_code: "FETCH_ERROR",
504
- error_message: r instanceof Error ? r.message : String(r),
506
+ error_message: l instanceof Error ? l.message : String(l),
505
507
  widget: "qna"
506
508
  })), this._contentEl) {
507
509
  this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
508
- const l = document.createElement("div");
509
- l.className = "gengage-qna-panel", this._contentEl.appendChild(l);
510
+ const r = document.createElement("div");
511
+ r.className = "gengage-qna-panel", this._contentEl.appendChild(r);
510
512
  const c = this.config.inputPlaceholder === !0 ? this._i18n.defaultInputPlaceholder : this.config.inputPlaceholder ?? this._i18n.defaultInputPlaceholder, s = {
511
513
  onAction: this._actionHandler,
512
514
  i18n: this._i18n,
513
515
  onOpenChat: this._openChatHandler
514
516
  }, d = this._resolvedQnaHeaderTitle();
515
- d !== void 0 && (s.headingTitleOverride = d), this.config.ctaText !== void 0 && (s.ctaText = this.config.ctaText), this._appendStandaloneInput(s, c, l);
517
+ d !== void 0 && (s.headingTitleOverride = d), this.config.ctaText !== void 0 && (s.ctaText = this.config.ctaText), this._appendStandaloneInput(s, c, r);
516
518
  }
517
519
  } finally {
518
- i();
520
+ a();
519
521
  }
520
522
  }
521
523
  _createLoadingIndicator() {
@@ -529,15 +531,15 @@ var dt = class extends D {
529
531
  }
530
532
  _resolveI18n(e) {
531
533
  return {
532
- ...ct(e.locale),
534
+ ...dt(e.locale),
533
535
  ...e.i18n
534
536
  };
535
537
  }
536
538
  _createChrome(e) {
537
539
  const t = e.chrome;
538
540
  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() : "", r = 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"), r && l.style.setProperty("--gengage-qna-chrome-image-padding", r);
541
+ const n = typeof t.title == "string" ? t.title.trim() : "", o = typeof t.subtitle == "string" ? t.subtitle.trim() : "", i = typeof t.startButtonLabel == "string" ? t.startButtonLabel.trim() : "", a = typeof t.imageUrl == "string" ? t.imageUrl.trim() : "", l = typeof t.imagePadding == "string" ? t.imagePadding.trim() : "", r = document.createElement("section");
542
+ r.className = "gengage-qna-chrome", r.dataset.gengagePart = "qna-chrome", t.layout === "side-image" && (r.classList.add("gengage-qna-chrome--side-image"), r.dataset.gengageChromeLayout = "side-image"), l && r.style.setProperty("--gengage-qna-chrome-image-padding", l);
541
543
  const c = document.createElement("div");
542
544
  if (c.className = "gengage-qna-chrome-copy", c.dataset.gengagePart = "qna-chrome-copy", n) {
543
545
  const s = document.createElement("h2");
@@ -547,28 +549,28 @@ var dt = class extends D {
547
549
  const s = document.createElement("p");
548
550
  s.className = "gengage-qna-chrome-subtitle", s.dataset.gengagePart = "qna-chrome-subtitle", s.textContent = o, c.appendChild(s);
549
551
  }
550
- if (c.children.length > 0 && l.appendChild(c), i && z(i)) {
552
+ if (c.children.length > 0 && r.appendChild(c), a && $(a)) {
551
553
  const s = document.createElement("img");
552
- s.className = "gengage-qna-chrome-image", s.dataset.gengagePart = "qna-chrome-image", s.src = i, s.alt = typeof t.imageAlt == "string" ? t.imageAlt : "", s.loading = "lazy", s.addEventListener("error", () => {
554
+ s.className = "gengage-qna-chrome-image", s.dataset.gengagePart = "qna-chrome-image", s.src = a, s.alt = typeof t.imageAlt == "string" ? t.imageAlt : "", s.loading = "lazy", s.addEventListener("error", () => {
553
555
  s.style.display = "none";
554
- }, { once: !0 }), l.appendChild(s);
556
+ }, { once: !0 }), r.appendChild(s);
555
557
  }
556
- if (a) {
558
+ if (i) {
557
559
  const s = document.createElement("button");
558
- s.className = "gengage-qna-chrome-start", s.dataset.gengagePart = "qna-chrome-start", s.type = "button", s.textContent = a, s.addEventListener("click", () => this._handleOpenChat()), l.appendChild(s);
560
+ s.className = "gengage-qna-chrome-start", s.dataset.gengagePart = "qna-chrome-start", s.type = "button", s.textContent = i, s.addEventListener("click", () => this._handleOpenChat()), r.appendChild(s);
559
561
  }
560
- return l.children.length === 0 ? null : l;
562
+ return r.children.length === 0 ? null : r;
561
563
  }
562
564
  _resolveUISpecRegistry() {
563
- return R(K(), this.config.renderer?.registry);
565
+ return Q(X(), this.config.renderer?.registry);
564
566
  }
565
567
  _renderUISpec(e, t) {
566
- const n = this._resolveUISpecRegistry(), o = this.config.renderer?.unknownRenderer ?? P, a = (r, l) => X(r, l, n, o), i = this.config.renderer?.renderUISpec;
567
- return i ? i(e, t, {
568
+ const n = this._resolveUISpecRegistry(), o = this.config.renderer?.unknownRenderer ?? P, i = (l, r) => tt(l, r, n, o), a = this.config.renderer?.renderUISpec;
569
+ return a ? a(e, t, {
568
570
  registry: n,
569
571
  unknownRenderer: o,
570
- defaultRender: a
571
- }) : a(e, t);
572
+ defaultRender: i
573
+ }) : i(e, t);
572
574
  }
573
575
  _specIncludesType(e, t) {
574
576
  for (const n of e) for (const o of Object.values(n.elements)) if (o.type === t) return !0;
@@ -581,15 +583,15 @@ var dt = class extends D {
581
583
  };
582
584
  const t = {}, n = [];
583
585
  for (let o = 0; o < e.length; o++) {
584
- const a = e[o], i = `action-${o}`;
585
- n.push(i), t[i] = {
586
+ const i = e[o], a = `action-${o}`;
587
+ n.push(a), t[a] = {
586
588
  type: "ActionButton",
587
589
  props: {
588
- label: a.title,
590
+ label: i.title,
589
591
  action: {
590
- title: a.title,
591
- type: a.type,
592
- payload: a.payload
592
+ title: i.title,
593
+ type: i.type,
594
+ payload: i.payload
593
595
  }
594
596
  }
595
597
  };
@@ -609,18 +611,18 @@ var dt = class extends D {
609
611
  type: "TextInput",
610
612
  props: { placeholder: n }
611
613
  } }
612
- }, a = this._renderUISpec(o, t), i = a.querySelector(".gengage-qna-input-wrapper");
613
- if (!i) return;
614
- const r = e.querySelector(".gengage-qna-uispec"), l = r?.querySelector(":scope > .gengage-qna-buttons"), c = this.config.inputAfterPills === !0;
615
- if (r && l) c ? l.insertAdjacentElement("afterend", i) : r.insertBefore(i, l);
616
- else if (r) {
617
- const s = r.querySelector(":scope > .gengage-qna-heading");
618
- !c && s ? s.insertAdjacentElement("afterend", i) : r.appendChild(i);
614
+ }, i = this._renderUISpec(o, t), a = i.querySelector(".gengage-qna-input-wrapper");
615
+ if (!a) return;
616
+ const l = e.querySelector(".gengage-qna-uispec"), r = e.querySelector(".gengage-qna-uispec > .gengage-qna-buttons"), c = this.config.inputAfterPills === !0;
617
+ if (r) c ? r.insertAdjacentElement("afterend", a) : r.insertAdjacentElement("beforebegin", a);
618
+ else if (l) {
619
+ const s = l.querySelector(":scope > .gengage-qna-heading");
620
+ !c && s ? s.insertAdjacentElement("afterend", a) : l.appendChild(a);
619
621
  } else {
620
- e.appendChild(a);
622
+ e.appendChild(i);
621
623
  return;
622
624
  }
623
- a.remove();
625
+ i.remove();
624
626
  }
625
627
  _appendStandaloneInput(e, t, n) {
626
628
  if (!this._contentEl) return;
@@ -630,14 +632,14 @@ var dt = class extends D {
630
632
  type: "TextInput",
631
633
  props: { placeholder: t }
632
634
  } }
633
- }, a = this._renderUISpec(o, e);
634
- (n ?? this._contentEl).appendChild(a);
635
+ }, i = this._renderUISpec(o, e);
636
+ (n ?? this._contentEl).appendChild(i);
635
637
  }
636
638
  _handleAction(e) {
637
- this._showTransitionIndicator(), $(e.title, e.type), this.config.onActionSelected?.(e), setTimeout(() => A("gengage:qna:action", e), 350);
639
+ this._showTransitionIndicator(), G(e.title, e.type), this.config.onActionSelected?.(e), setTimeout(() => E("gengage:qna:action", e), 350);
638
640
  }
639
641
  _handleOpenChat() {
640
- this._showTransitionIndicator(), this.config.onOpenChat?.(), setTimeout(() => A("gengage:qna:open-chat", {}), 350);
642
+ this._showTransitionIndicator(), this.config.onOpenChat?.(), setTimeout(() => E("gengage:qna:open-chat", {}), 350);
641
643
  }
642
644
  _showTransitionIndicator() {
643
645
  if (!this._contentEl) return;
@@ -648,13 +650,13 @@ var dt = class extends D {
648
650
  }, 600);
649
651
  }
650
652
  };
651
- function mt() {
652
- return new dt();
653
+ function yt() {
654
+ return new ut();
653
655
  }
654
656
  export {
655
- X as a,
657
+ tt as a,
656
658
  P as i,
657
- mt as n,
658
- K as r,
659
- dt as t
659
+ yt as n,
660
+ X as r,
661
+ ut as t
660
662
  };