@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.
- package/dist/index.js +1 -1
- package/dist/native.iife.js +6 -6
- package/dist/qna/api.d.ts +2 -0
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +32 -32
- package/dist/qna.js +1 -1
- package/dist/{runtime-DW9q1zyk.js → runtime-B0hDHRlN.js} +232 -230
- package/package.json +2 -2
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { f as
|
|
2
|
-
import { S as
|
|
3
|
-
import { A as
|
|
4
|
-
import { t as
|
|
5
|
-
import { n as
|
|
6
|
-
async function
|
|
7
|
-
const o =
|
|
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
|
-
},
|
|
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 && (
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
const s =
|
|
20
|
-
if (s && (s.type === "ui_spec" &&
|
|
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
|
|
23
|
-
|
|
22
|
+
const b = d.props.action;
|
|
23
|
+
i.actions.push(b);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
} };
|
|
27
|
-
return n !== void 0 && (
|
|
27
|
+
return n !== void 0 && (r.signal = n), await U(l, r), i;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
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
|
|
35
|
+
const i = {
|
|
36
36
|
title: n.title,
|
|
37
37
|
type: n.type
|
|
38
38
|
};
|
|
39
|
-
n.payload !== void 0 && (
|
|
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
|
|
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
|
|
58
|
-
let
|
|
59
|
-
o.placeholder =
|
|
60
|
-
let
|
|
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
|
-
|
|
63
|
-
},
|
|
64
|
-
d(),
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
},
|
|
70
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
p.classList.toggle("gengage-qna-icon-btn--hidden", !
|
|
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
|
|
80
|
-
|
|
81
|
-
title:
|
|
79
|
+
const g = o.value.trim();
|
|
80
|
+
g && (e.onSubmit({
|
|
81
|
+
title: g,
|
|
82
82
|
type: "user_message",
|
|
83
|
-
payload:
|
|
84
|
-
}), o.value = "",
|
|
83
|
+
payload: g
|
|
84
|
+
}), o.value = "", y(), f());
|
|
85
85
|
};
|
|
86
86
|
return p.addEventListener("click", () => {
|
|
87
|
-
o.value = "",
|
|
88
|
-
}),
|
|
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 =
|
|
91
|
+
s = !1, o.value.trim().length === 0 && (o.placeholder = l), f();
|
|
92
92
|
}), o.addEventListener("input", () => {
|
|
93
|
-
if (
|
|
93
|
+
if (y(), o.value.trim().length > 0) {
|
|
94
94
|
d();
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
o.placeholder = s ? "" :
|
|
98
|
-
}), o.addEventListener("keydown", (
|
|
99
|
-
|
|
100
|
-
}),
|
|
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
|
|
109
|
-
if (!
|
|
110
|
-
const
|
|
111
|
-
title:
|
|
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
|
|
114
|
+
return a !== void 0 && (r.payload = a), r;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
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
|
|
123
|
+
function I(e, t) {
|
|
124
124
|
const n = [], o = e.props?.actions;
|
|
125
|
-
if (Array.isArray(o)) for (const
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
const
|
|
130
|
-
if (Array.isArray(
|
|
131
|
-
if (!
|
|
132
|
-
const
|
|
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
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
138
|
-
const c = typeof
|
|
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
|
|
142
|
-
return n.filter((
|
|
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
|
|
144
|
+
var w = {
|
|
145
145
|
ButtonRow: ({ element: e, spec: t, context: n }) => {
|
|
146
|
-
const o =
|
|
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 && (
|
|
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:
|
|
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),
|
|
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
|
|
169
|
-
return
|
|
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,
|
|
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 && (
|
|
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,
|
|
185
|
-
return n.textContent = typeof
|
|
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
|
|
193
|
-
|
|
192
|
+
const i = t(o);
|
|
193
|
+
i && n.appendChild(i);
|
|
194
194
|
}
|
|
195
195
|
return n;
|
|
196
196
|
};
|
|
197
|
-
function
|
|
198
|
-
return { ...
|
|
197
|
+
function X() {
|
|
198
|
+
return { ...w };
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
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
|
|
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
|
|
216
|
-
if (
|
|
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
|
|
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,
|
|
227
|
-
if (typeof
|
|
228
|
-
const
|
|
229
|
-
if (!
|
|
230
|
-
const
|
|
231
|
-
title:
|
|
232
|
-
type:
|
|
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
|
|
234
|
+
return r !== void 0 && (c.payload = r), c;
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function nt(e, t) {
|
|
237
237
|
const n = e.elements[e.root];
|
|
238
238
|
if (!n) return !1;
|
|
239
|
-
const o = (
|
|
240
|
-
if (
|
|
241
|
-
const
|
|
242
|
-
if (!
|
|
243
|
-
const
|
|
244
|
-
return
|
|
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
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
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
|
|
253
|
-
if (
|
|
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
|
|
258
|
+
function B() {
|
|
259
259
|
return S += 1, `gengage-merge-${S}`;
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function ot(e, t) {
|
|
262
262
|
const n = e.elements[e.root];
|
|
263
263
|
if (!n || n.type !== "ButtonRow") return;
|
|
264
|
-
const o =
|
|
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
|
|
277
|
+
function it(e, t) {
|
|
278
278
|
const n = e.elements[e.root];
|
|
279
279
|
if (!n || n.type !== "ActionButtons") return;
|
|
280
|
-
const o =
|
|
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
|
|
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: [
|
|
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
|
|
309
|
-
n.push(
|
|
308
|
+
const i = e[o], a = `action-${o}`;
|
|
309
|
+
n.push(a), t[a] = {
|
|
310
310
|
type: "ActionButton",
|
|
311
311
|
props: {
|
|
312
|
-
label:
|
|
312
|
+
label: i.title,
|
|
313
313
|
action: {
|
|
314
|
-
title:
|
|
315
|
-
type:
|
|
316
|
-
...
|
|
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
|
|
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
|
|
344
|
-
const o = n?.skuList,
|
|
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 (
|
|
350
|
-
|
|
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
|
-
|
|
354
|
+
a.push(c);
|
|
355
355
|
}
|
|
356
|
-
if (
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
359
|
-
if (!
|
|
360
|
-
const c =
|
|
361
|
-
c?.type === "ActionButtons" ?
|
|
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
|
|
363
|
+
return a;
|
|
364
364
|
}
|
|
365
|
-
var
|
|
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
|
-
},
|
|
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
|
|
384
|
+
function ct(e) {
|
|
385
385
|
return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
|
|
386
386
|
}
|
|
387
|
-
function
|
|
388
|
-
return
|
|
387
|
+
function dt(e) {
|
|
388
|
+
return ct(e) === "en" ? lt : R;
|
|
389
389
|
}
|
|
390
|
-
var
|
|
390
|
+
var ut = class extends F {
|
|
391
391
|
constructor(...e) {
|
|
392
|
-
super(...e), this._abortController = null, this._debounceTimer = null, this._contentEl = null, this._i18n =
|
|
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 =
|
|
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)),
|
|
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(),
|
|
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(
|
|
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:
|
|
452
|
-
correlation_id:
|
|
451
|
+
session_id: l,
|
|
452
|
+
correlation_id: l,
|
|
453
453
|
sku: e,
|
|
454
|
-
locale:
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const c =
|
|
458
|
-
|
|
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() -
|
|
461
|
-
chunk_count:
|
|
462
|
+
latency_ms: Date.now() - i,
|
|
463
|
+
chunk_count: s.actions.length,
|
|
462
464
|
widget: "qna"
|
|
463
|
-
})), this.track(
|
|
464
|
-
message_count:
|
|
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
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
if (!
|
|
474
|
-
const
|
|
475
|
-
|
|
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
|
|
479
|
-
if (m !== !0)
|
|
480
|
-
else if (
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
} else
|
|
484
|
-
const
|
|
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
|
-
},
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
for (const
|
|
491
|
-
const _ = this._renderUISpec(
|
|
492
|
-
|
|
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
|
-
|
|
495
|
-
} catch (
|
|
496
|
-
if (
|
|
497
|
-
if (
|
|
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:
|
|
501
|
-
}), this.track(
|
|
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:
|
|
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
|
|
509
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
...
|
|
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() : "",
|
|
540
|
-
|
|
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 &&
|
|
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 =
|
|
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 }),
|
|
556
|
+
}, { once: !0 }), r.appendChild(s);
|
|
555
557
|
}
|
|
556
|
-
if (
|
|
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 =
|
|
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
|
|
562
|
+
return r.children.length === 0 ? null : r;
|
|
561
563
|
}
|
|
562
564
|
_resolveUISpecRegistry() {
|
|
563
|
-
return
|
|
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,
|
|
567
|
-
return
|
|
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:
|
|
571
|
-
}) :
|
|
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
|
|
585
|
-
n.push(
|
|
586
|
+
const i = e[o], a = `action-${o}`;
|
|
587
|
+
n.push(a), t[a] = {
|
|
586
588
|
type: "ActionButton",
|
|
587
589
|
props: {
|
|
588
|
-
label:
|
|
590
|
+
label: i.title,
|
|
589
591
|
action: {
|
|
590
|
-
title:
|
|
591
|
-
type:
|
|
592
|
-
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
|
-
},
|
|
613
|
-
if (!
|
|
614
|
-
const
|
|
615
|
-
if (r
|
|
616
|
-
else if (
|
|
617
|
-
const s =
|
|
618
|
-
!c && s ? s.insertAdjacentElement("afterend",
|
|
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(
|
|
622
|
+
e.appendChild(i);
|
|
621
623
|
return;
|
|
622
624
|
}
|
|
623
|
-
|
|
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
|
-
},
|
|
634
|
-
(n ?? this._contentEl).appendChild(
|
|
635
|
+
}, i = this._renderUISpec(o, e);
|
|
636
|
+
(n ?? this._contentEl).appendChild(i);
|
|
635
637
|
}
|
|
636
638
|
_handleAction(e) {
|
|
637
|
-
this._showTransitionIndicator(),
|
|
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(() =>
|
|
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
|
|
652
|
-
return new
|
|
653
|
+
function yt() {
|
|
654
|
+
return new ut();
|
|
653
655
|
}
|
|
654
656
|
export {
|
|
655
|
-
|
|
657
|
+
tt as a,
|
|
656
658
|
P as i,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
659
|
+
yt as n,
|
|
660
|
+
X as r,
|
|
661
|
+
ut as t
|
|
660
662
|
};
|