@gengage/assistant-fe 0.4.12 → 0.4.13
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/chat/components/Launcher.d.ts +2 -0
- package/dist/chat/runtime.d.ts +1 -0
- package/dist/chat/types.d.ts +5 -0
- package/dist/chat-runtime.js +1 -1
- package/dist/chat.iife.js +22 -22
- package/dist/chat.js +1 -1
- package/dist/common/overlay.d.ts +2 -0
- package/dist/{common-CP5HKBAf.js → common-Bxy1FrAk.js} +1 -1
- package/dist/common.js +3 -3
- package/dist/index.js +5 -5
- package/dist/{native-webview-BGpkM3T9.js → native-webview-BsRcv49q.js} +1 -1
- package/dist/native.iife.js +3 -3
- package/dist/native.js +1 -1
- package/dist/{overlay-DXdWi-GM.js → overlay-CfnBuj7M.js} +43 -43
- package/dist/overlay.js +1 -1
- package/dist/qna/runtime.d.ts +2 -2
- package/dist/qna/types.d.ts +2 -0
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +1 -1
- package/dist/qna.js +1 -1
- package/dist/{runtime-CN3nY1qp.js → runtime-DW9q1zyk.js} +77 -77
- package/dist/{runtime-CYN4ZmHO.js → runtime-EUhElpCX.js} +307 -297
- package/package.json +1 -1
|
@@ -13,18 +13,18 @@ async function Y(e, t, n) {
|
|
|
13
13
|
body: JSON.stringify(e)
|
|
14
14
|
};
|
|
15
15
|
n !== void 0 && (i.signal = n);
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
16
|
+
const r = await fetch(o, i);
|
|
17
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}: ${r.statusText}`);
|
|
18
18
|
const l = { onEvent: (c) => {
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
for (const d of Object.values(
|
|
19
|
+
const s = N(c);
|
|
20
|
+
if (s && (s.type === "ui_spec" && a.uiSpecs.push(s.spec), s.type === "ui_spec" && s.spec.elements)) {
|
|
21
|
+
for (const d of Object.values(s.spec.elements)) if (d.type === "ActionButton" && d.props?.action) {
|
|
22
22
|
const y = d.props.action;
|
|
23
23
|
a.actions.push(y);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
} };
|
|
27
|
-
return n !== void 0 && (l.signal = n), await O(
|
|
27
|
+
return n !== void 0 && (l.signal = n), await O(r, l), a;
|
|
28
28
|
}
|
|
29
29
|
function T(e) {
|
|
30
30
|
const t = document.createElement("div");
|
|
@@ -55,15 +55,15 @@ function Z(e) {
|
|
|
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
57
|
const a = Array.isArray(e.placeholders) ? e.placeholders : e.placeholders ? [e.placeholders] : [e.defaultInputPlaceholder ?? "Ask a question..."];
|
|
58
|
-
let i = 0,
|
|
59
|
-
o.placeholder =
|
|
60
|
-
let l = null, c = null,
|
|
58
|
+
let i = 0, r = a[0] ?? "";
|
|
59
|
+
o.placeholder = r;
|
|
60
|
+
let l = null, c = null, s = !1;
|
|
61
61
|
const d = () => {
|
|
62
62
|
l && clearInterval(l), l = null, c && clearTimeout(c), c = null, o.classList.remove("gengage-qna-input--fade");
|
|
63
|
-
}, y = () => a.length > 1 && !
|
|
63
|
+
}, y = () => a.length > 1 && !s && o.value.trim().length === 0, m = () => {
|
|
64
64
|
d(), y() && (l = setInterval(() => {
|
|
65
65
|
y() && (o.classList.add("gengage-qna-input--fade"), c = setTimeout(() => {
|
|
66
|
-
i = (i + 1) % a.length,
|
|
66
|
+
i = (i + 1) % a.length, r = a[i] ?? "", o.placeholder = r, o.classList.remove("gengage-qna-input--fade");
|
|
67
67
|
}, 180));
|
|
68
68
|
}, 3e3));
|
|
69
69
|
}, h = document.createElement("div");
|
|
@@ -86,15 +86,15 @@ function Z(e) {
|
|
|
86
86
|
return p.addEventListener("click", () => {
|
|
87
87
|
o.value = "", b(), o.focus({ preventScroll: !0 });
|
|
88
88
|
}), g.addEventListener("click", v), o.addEventListener("focus", () => {
|
|
89
|
-
|
|
89
|
+
s = !0, d(), o.placeholder = "";
|
|
90
90
|
}), o.addEventListener("blur", () => {
|
|
91
|
-
|
|
91
|
+
s = !1, o.value.trim().length === 0 && (o.placeholder = r), m();
|
|
92
92
|
}), o.addEventListener("input", () => {
|
|
93
93
|
if (b(), o.value.trim().length > 0) {
|
|
94
94
|
d();
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
o.placeholder =
|
|
97
|
+
o.placeholder = s ? "" : r, m();
|
|
98
98
|
}), o.addEventListener("keydown", (u) => {
|
|
99
99
|
u.key === "Enter" && (u.preventDefault(), v()), u.key === "Escape" && o.value.length > 0 && (o.value = "", b(), m());
|
|
100
100
|
}), h.appendChild(p), h.appendChild(g), n.appendChild(o), n.appendChild(h), t.appendChild(n), b(), m(), t._cleanup = () => {
|
|
@@ -105,10 +105,10 @@ 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,
|
|
109
|
-
if (!
|
|
108
|
+
const a = n.title, i = n.payload, r = typeof a == "string" && a.length > 0 ? a : t;
|
|
109
|
+
if (!r) return null;
|
|
110
110
|
const l = {
|
|
111
|
-
title:
|
|
111
|
+
title: r,
|
|
112
112
|
type: o
|
|
113
113
|
};
|
|
114
114
|
return i !== void 0 && (l.payload = i), l;
|
|
@@ -122,24 +122,24 @@ function C(e) {
|
|
|
122
122
|
}
|
|
123
123
|
function k(e, t) {
|
|
124
124
|
const n = [], o = e.props?.actions;
|
|
125
|
-
if (Array.isArray(o)) for (const
|
|
126
|
-
const l = q(
|
|
125
|
+
if (Array.isArray(o)) for (const r of o) {
|
|
126
|
+
const l = q(r);
|
|
127
127
|
l && n.push(l);
|
|
128
128
|
}
|
|
129
129
|
const a = e.props?.buttons;
|
|
130
|
-
if (Array.isArray(a)) for (const
|
|
131
|
-
if (!
|
|
132
|
-
const l =
|
|
133
|
-
|
|
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);
|
|
133
|
+
s && n.push(s);
|
|
134
134
|
}
|
|
135
|
-
if (e.children) for (const
|
|
136
|
-
const l = t.elements[
|
|
135
|
+
if (e.children) for (const r of e.children) {
|
|
136
|
+
const l = t.elements[r];
|
|
137
137
|
if (!l || l.type !== "ActionButton") continue;
|
|
138
|
-
const c = typeof l.props?.label == "string" ? l.props.label : void 0,
|
|
139
|
-
|
|
138
|
+
const c = typeof l.props?.label == "string" ? l.props.label : void 0, s = q(l.props?.action, c);
|
|
139
|
+
s && n.push(s);
|
|
140
140
|
}
|
|
141
141
|
const i = /* @__PURE__ */ new Set();
|
|
142
|
-
return n.filter((
|
|
142
|
+
return n.filter((r) => i.has(r.title) ? !1 : (i.add(r.title), !0));
|
|
143
143
|
}
|
|
144
144
|
var I = {
|
|
145
145
|
ButtonRow: ({ element: e, spec: t, context: n }) => {
|
|
@@ -185,7 +185,7 @@ var I = {
|
|
|
185
185
|
return n.textContent = typeof a == "string" && a.trim().length > 0 ? a : 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) {
|
|
@@ -197,7 +197,7 @@ var I = {
|
|
|
197
197
|
function K() {
|
|
198
198
|
return { ...I };
|
|
199
199
|
}
|
|
200
|
-
function X(e, t, n = I, o =
|
|
200
|
+
function X(e, t, n = I, o = P) {
|
|
201
201
|
return Q({
|
|
202
202
|
spec: e,
|
|
203
203
|
context: t,
|
|
@@ -219,16 +219,16 @@ function tt(e) {
|
|
|
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 w(e, t) {
|
|
223
223
|
if (!e) return null;
|
|
224
224
|
const n = e.action;
|
|
225
225
|
if (!n || typeof n != "object") return null;
|
|
226
226
|
const o = n, a = o.type;
|
|
227
227
|
if (typeof a != "string" || a.length === 0) return null;
|
|
228
|
-
const i = o.title,
|
|
229
|
-
if (!
|
|
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
230
|
const l = o.payload, c = {
|
|
231
|
-
title:
|
|
231
|
+
title: r,
|
|
232
232
|
type: a
|
|
233
233
|
};
|
|
234
234
|
return l !== void 0 && (c.payload = l), c;
|
|
@@ -240,8 +240,8 @@ function et(e, t) {
|
|
|
240
240
|
if (a.type !== "ActionButton") return !1;
|
|
241
241
|
const i = a.props;
|
|
242
242
|
if (!i || typeof i != "object") return !1;
|
|
243
|
-
const
|
|
244
|
-
return
|
|
243
|
+
const r = typeof i.label == "string" ? i.label : void 0;
|
|
244
|
+
return r === t ? !0 : w(i, r)?.title === t;
|
|
245
245
|
};
|
|
246
246
|
if (n.type === "ActionButton") return o(n);
|
|
247
247
|
if (n.children) for (const a of n.children) {
|
|
@@ -343,10 +343,10 @@ function L(e, t) {
|
|
|
343
343
|
function st(e, t, n) {
|
|
344
344
|
const o = n?.skuList, a = [], i = [];
|
|
345
345
|
for (const c of e) {
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
const d =
|
|
349
|
-
if (
|
|
346
|
+
const s = c.elements[c.root];
|
|
347
|
+
if (s?.type === "ActionButton") {
|
|
348
|
+
const d = s.props;
|
|
349
|
+
if (w(d, typeof d?.label == "string" ? d.label : void 0)?.type === "findSimilar") {
|
|
350
350
|
a.push(L(t, o));
|
|
351
351
|
continue;
|
|
352
352
|
}
|
|
@@ -354,11 +354,11 @@ function st(e, t, n) {
|
|
|
354
354
|
i.push(c);
|
|
355
355
|
}
|
|
356
356
|
if (a.length === 0) return e;
|
|
357
|
-
const
|
|
358
|
-
if (!l) return [...i, at([
|
|
359
|
-
if (!et(l,
|
|
357
|
+
const r = L(t, o), l = it(i);
|
|
358
|
+
if (!l) return [...i, at([r])];
|
|
359
|
+
if (!et(l, r.title)) {
|
|
360
360
|
const c = l.elements[l.root];
|
|
361
|
-
c?.type === "ActionButtons" ? ot(l,
|
|
361
|
+
c?.type === "ActionButtons" ? ot(l, r) : c?.type === "ButtonRow" && nt(l, r);
|
|
362
362
|
}
|
|
363
363
|
return i;
|
|
364
364
|
}
|
|
@@ -446,15 +446,15 @@ var dt = class extends D {
|
|
|
446
446
|
widget: "qna"
|
|
447
447
|
}));
|
|
448
448
|
try {
|
|
449
|
-
const
|
|
449
|
+
const r = {
|
|
450
450
|
account_id: this.config.accountId,
|
|
451
451
|
session_id: this.config.session?.sessionId ?? "",
|
|
452
452
|
correlation_id: this.config.session?.sessionId ?? "",
|
|
453
453
|
sku: e,
|
|
454
454
|
locale: E(this.config.locale)
|
|
455
455
|
}, l = this.config.pageContext?.pageType;
|
|
456
|
-
l !== void 0 && (
|
|
457
|
-
const c = await Y(
|
|
456
|
+
l !== void 0 && (r.page_type = l);
|
|
457
|
+
const c = await Y(r, n, this._abortController.signal);
|
|
458
458
|
if (this.track(j(this.analyticsContext(), {
|
|
459
459
|
request_id: o,
|
|
460
460
|
latency_ms: Date.now() - a,
|
|
@@ -467,12 +467,12 @@ var dt = class extends D {
|
|
|
467
467
|
widget: "qna"
|
|
468
468
|
})), !this._contentEl) return;
|
|
469
469
|
this._contentEl.innerHTML = "";
|
|
470
|
-
const
|
|
471
|
-
|
|
470
|
+
const s = document.createElement("div");
|
|
471
|
+
s.className = "gengage-qna-panel gds-panel", s.dataset.gengagePart = "qna-panel", this._contentEl.appendChild(s);
|
|
472
472
|
const d = this._specIncludesType(c.uiSpecs, "QuestionHeading"), y = this._resolvedQnaHeaderTitle() ?? (this.config.showStaticQuestion && this.config.staticQuestionText ? this.config.staticQuestionText : void 0);
|
|
473
473
|
if (!d && y) {
|
|
474
474
|
const f = document.createElement("h3");
|
|
475
|
-
f.className = "gengage-qna-heading", f.textContent = y,
|
|
475
|
+
f.className = "gengage-qna-heading", f.textContent = y, s.appendChild(f);
|
|
476
476
|
}
|
|
477
477
|
const m = this.config.inputPlaceholder;
|
|
478
478
|
let h;
|
|
@@ -489,30 +489,30 @@ var dt = class extends D {
|
|
|
489
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
490
|
for (const f of u) {
|
|
491
491
|
const _ = this._renderUISpec(f, p);
|
|
492
|
-
|
|
492
|
+
s.appendChild(_);
|
|
493
493
|
}
|
|
494
|
-
u.length > 0 && G("qna"), this._specIncludesType(u, "TextInput") || this._insertStandaloneInputBeforePills(
|
|
495
|
-
} catch (
|
|
496
|
-
if (
|
|
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
497
|
if (A("gengage:global:error", {
|
|
498
498
|
source: "qna",
|
|
499
499
|
code: "FETCH_ERROR",
|
|
500
|
-
message: M(this.config.locale,
|
|
500
|
+
message: M(this.config.locale, r)
|
|
501
501
|
}), this.track(W(this.analyticsContext(), {
|
|
502
502
|
request_id: o,
|
|
503
503
|
error_code: "FETCH_ERROR",
|
|
504
|
-
error_message:
|
|
504
|
+
error_message: r instanceof Error ? r.message : String(r),
|
|
505
505
|
widget: "qna"
|
|
506
506
|
})), this._contentEl) {
|
|
507
507
|
this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
|
|
508
508
|
const l = document.createElement("div");
|
|
509
509
|
l.className = "gengage-qna-panel", this._contentEl.appendChild(l);
|
|
510
|
-
const c = this.config.inputPlaceholder === !0 ? this._i18n.defaultInputPlaceholder : this.config.inputPlaceholder ?? this._i18n.defaultInputPlaceholder,
|
|
510
|
+
const c = this.config.inputPlaceholder === !0 ? this._i18n.defaultInputPlaceholder : this.config.inputPlaceholder ?? this._i18n.defaultInputPlaceholder, s = {
|
|
511
511
|
onAction: this._actionHandler,
|
|
512
512
|
i18n: this._i18n,
|
|
513
513
|
onOpenChat: this._openChatHandler
|
|
514
514
|
}, d = this._resolvedQnaHeaderTitle();
|
|
515
|
-
d !== void 0 && (
|
|
515
|
+
d !== void 0 && (s.headingTitleOverride = d), this.config.ctaText !== void 0 && (s.ctaText = this.config.ctaText), this._appendStandaloneInput(s, c, l);
|
|
516
516
|
}
|
|
517
517
|
} finally {
|
|
518
518
|
i();
|
|
@@ -536,26 +536,26 @@ var dt = class extends D {
|
|
|
536
536
|
_createChrome(e) {
|
|
537
537
|
const t = e.chrome;
|
|
538
538
|
if (!t) return null;
|
|
539
|
-
const n = typeof t.title == "string" ? t.title.trim() : "", o = typeof t.subtitle == "string" ? t.subtitle.trim() : "", a = typeof t.startButtonLabel == "string" ? t.startButtonLabel.trim() : "", i = typeof t.imageUrl == "string" ? t.imageUrl.trim() : "",
|
|
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"),
|
|
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
541
|
const c = document.createElement("div");
|
|
542
542
|
if (c.className = "gengage-qna-chrome-copy", c.dataset.gengagePart = "qna-chrome-copy", n) {
|
|
543
|
-
const
|
|
544
|
-
|
|
543
|
+
const s = document.createElement("h2");
|
|
544
|
+
s.className = "gengage-qna-chrome-title", s.dataset.gengagePart = "qna-chrome-title", s.textContent = n, c.appendChild(s);
|
|
545
545
|
}
|
|
546
546
|
if (o) {
|
|
547
|
-
const
|
|
548
|
-
|
|
547
|
+
const s = document.createElement("p");
|
|
548
|
+
s.className = "gengage-qna-chrome-subtitle", s.dataset.gengagePart = "qna-chrome-subtitle", s.textContent = o, c.appendChild(s);
|
|
549
549
|
}
|
|
550
550
|
if (c.children.length > 0 && l.appendChild(c), i && z(i)) {
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}, { once: !0 }), l.appendChild(
|
|
551
|
+
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", () => {
|
|
553
|
+
s.style.display = "none";
|
|
554
|
+
}, { once: !0 }), l.appendChild(s);
|
|
555
555
|
}
|
|
556
556
|
if (a) {
|
|
557
|
-
const
|
|
558
|
-
|
|
557
|
+
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);
|
|
559
559
|
}
|
|
560
560
|
return l.children.length === 0 ? null : l;
|
|
561
561
|
}
|
|
@@ -563,7 +563,7 @@ var dt = class extends D {
|
|
|
563
563
|
return R(K(), this.config.renderer?.registry);
|
|
564
564
|
}
|
|
565
565
|
_renderUISpec(e, t) {
|
|
566
|
-
const n = this._resolveUISpecRegistry(), o = this.config.renderer?.unknownRenderer ??
|
|
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
567
|
return i ? i(e, t, {
|
|
568
568
|
registry: n,
|
|
569
569
|
unknownRenderer: o,
|
|
@@ -611,11 +611,11 @@ var dt = class extends D {
|
|
|
611
611
|
} }
|
|
612
612
|
}, a = this._renderUISpec(o, t), i = a.querySelector(".gengage-qna-input-wrapper");
|
|
613
613
|
if (!i) return;
|
|
614
|
-
const
|
|
615
|
-
if (
|
|
616
|
-
else if (
|
|
617
|
-
const
|
|
618
|
-
c ?
|
|
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);
|
|
619
619
|
} else {
|
|
620
620
|
e.appendChild(a);
|
|
621
621
|
return;
|
|
@@ -653,7 +653,7 @@ function mt() {
|
|
|
653
653
|
}
|
|
654
654
|
export {
|
|
655
655
|
X as a,
|
|
656
|
-
|
|
656
|
+
P as i,
|
|
657
657
|
mt as n,
|
|
658
658
|
K as r,
|
|
659
659
|
dt as t
|