@gengage/assistant-fe 0.4.13 → 0.4.14
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 +1 -1
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +1 -1
- package/dist/qna.js +1 -1
- package/dist/{runtime-DW9q1zyk.js → runtime-Fs-ZXBnb.js} +63 -63
- package/package.json +1 -1
|
@@ -13,9 +13,9 @@ 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 (!
|
|
18
|
-
const
|
|
16
|
+
const l = await fetch(o, i);
|
|
17
|
+
if (!l.ok) throw new Error(`HTTP ${l.status}: ${l.statusText}`);
|
|
18
|
+
const r = { onEvent: (c) => {
|
|
19
19
|
const s = N(c);
|
|
20
20
|
if (s && (s.type === "ui_spec" && a.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) {
|
|
@@ -24,7 +24,7 @@ async function Y(e, t, n) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
} };
|
|
27
|
-
return n !== void 0 && (
|
|
27
|
+
return n !== void 0 && (r.signal = n), await O(l, r), 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
|
|
58
|
+
let i = 0, l = a[0] ?? "";
|
|
59
|
+
o.placeholder = l;
|
|
60
|
+
let r = null, c = null, s = !1;
|
|
61
61
|
const d = () => {
|
|
62
|
-
|
|
62
|
+
r && clearInterval(r), r = null, c && clearTimeout(c), c = null, o.classList.remove("gengage-qna-input--fade");
|
|
63
63
|
}, y = () => a.length > 1 && !s && o.value.trim().length === 0, m = () => {
|
|
64
|
-
d(), y() && (
|
|
64
|
+
d(), y() && (r = 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, l = a[i] ?? "", o.placeholder = l, o.classList.remove("gengage-qna-input--fade");
|
|
67
67
|
}, 180));
|
|
68
68
|
}, 3e3));
|
|
69
69
|
}, h = document.createElement("div");
|
|
@@ -88,13 +88,13 @@ function Z(e) {
|
|
|
88
88
|
}), g.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), 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 = s ? "" :
|
|
97
|
+
o.placeholder = s ? "" : l, 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,13 +105,13 @@ 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 (!
|
|
110
|
-
const
|
|
111
|
-
title:
|
|
108
|
+
const a = n.title, i = n.payload, l = typeof a == "string" && a.length > 0 ? a : t;
|
|
109
|
+
if (!l) return null;
|
|
110
|
+
const r = {
|
|
111
|
+
title: l,
|
|
112
112
|
type: o
|
|
113
113
|
};
|
|
114
|
-
return i !== void 0 && (
|
|
114
|
+
return i !== void 0 && (r.payload = i), r;
|
|
115
115
|
}
|
|
116
116
|
function C(e) {
|
|
117
117
|
const t = {
|
|
@@ -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
|
|
127
|
-
|
|
125
|
+
if (Array.isArray(o)) for (const l of o) {
|
|
126
|
+
const r = q(l);
|
|
127
|
+
r && n.push(r);
|
|
128
128
|
}
|
|
129
129
|
const a = e.props?.buttons;
|
|
130
|
-
if (Array.isArray(a)) for (const
|
|
131
|
-
if (!
|
|
132
|
-
const
|
|
130
|
+
if (Array.isArray(a)) for (const l of a) {
|
|
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
141
|
const i = /* @__PURE__ */ new Set();
|
|
142
|
-
return n.filter((
|
|
142
|
+
return n.filter((l) => i.has(l.title) ? !1 : (i.add(l.title), !0));
|
|
143
143
|
}
|
|
144
144
|
var I = {
|
|
145
145
|
ButtonRow: ({ element: e, spec: t, context: n }) => {
|
|
@@ -225,13 +225,13 @@ function w(e, t) {
|
|
|
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 (!
|
|
230
|
-
const
|
|
231
|
-
title:
|
|
228
|
+
const i = o.title, l = typeof i == "string" && i.length > 0 ? i : typeof t == "string" && t.length > 0 ? t : "";
|
|
229
|
+
if (!l) return null;
|
|
230
|
+
const r = o.payload, c = {
|
|
231
|
+
title: l,
|
|
232
232
|
type: a
|
|
233
233
|
};
|
|
234
|
-
return
|
|
234
|
+
return r !== void 0 && (c.payload = r), c;
|
|
235
235
|
}
|
|
236
236
|
function et(e, t) {
|
|
237
237
|
const n = e.elements[e.root];
|
|
@@ -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 l = typeof i.label == "string" ? i.label : void 0;
|
|
244
|
+
return l === t ? !0 : w(i, l)?.title === t;
|
|
245
245
|
};
|
|
246
246
|
if (n.type === "ActionButton") return o(n);
|
|
247
247
|
if (n.children) for (const a of n.children) {
|
|
@@ -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 (!
|
|
359
|
-
if (!et(
|
|
360
|
-
const c =
|
|
361
|
-
c?.type === "ActionButtons" ? ot(
|
|
357
|
+
const l = L(t, o), r = it(i);
|
|
358
|
+
if (!r) return [...i, at([l])];
|
|
359
|
+
if (!et(r, l.title)) {
|
|
360
|
+
const c = r.elements[r.root];
|
|
361
|
+
c?.type === "ActionButtons" ? ot(r, l) : c?.type === "ButtonRow" && nt(r, l);
|
|
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 l = {
|
|
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
|
-
},
|
|
456
|
-
|
|
457
|
-
const c = await Y(
|
|
455
|
+
}, r = this.config.pageContext?.pageType;
|
|
456
|
+
r !== void 0 && (l.page_type = r);
|
|
457
|
+
const c = await Y(l, n, this._abortController.signal);
|
|
458
458
|
if (this.track(j(this.analyticsContext(), {
|
|
459
459
|
request_id: o,
|
|
460
460
|
latency_ms: Date.now() - a,
|
|
@@ -492,27 +492,27 @@ var dt = class extends D {
|
|
|
492
492
|
s.appendChild(_);
|
|
493
493
|
}
|
|
494
494
|
u.length > 0 && G("qna"), this._specIncludesType(u, "TextInput") || this._insertStandaloneInputBeforePills(s, p, h);
|
|
495
|
-
} catch (
|
|
496
|
-
if (
|
|
495
|
+
} catch (l) {
|
|
496
|
+
if (l instanceof DOMException && l.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, l)
|
|
501
501
|
}), this.track(W(this.analyticsContext(), {
|
|
502
502
|
request_id: o,
|
|
503
503
|
error_code: "FETCH_ERROR",
|
|
504
|
-
error_message:
|
|
504
|
+
error_message: l instanceof Error ? l.message : String(l),
|
|
505
505
|
widget: "qna"
|
|
506
506
|
})), this._contentEl) {
|
|
507
507
|
this._cleanupTextInputTimers(), this._contentEl.innerHTML = "";
|
|
508
|
-
const
|
|
509
|
-
|
|
508
|
+
const r = document.createElement("div");
|
|
509
|
+
r.className = "gengage-qna-panel", this._contentEl.appendChild(r);
|
|
510
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 && (s.headingTitleOverride = d), this.config.ctaText !== void 0 && (s.ctaText = this.config.ctaText), this._appendStandaloneInput(s, c,
|
|
515
|
+
d !== void 0 && (s.headingTitleOverride = d), this.config.ctaText !== void 0 && (s.ctaText = this.config.ctaText), this._appendStandaloneInput(s, c, r);
|
|
516
516
|
}
|
|
517
517
|
} finally {
|
|
518
518
|
i();
|
|
@@ -536,8 +536,8 @@ 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
|
-
|
|
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() : "", l = typeof t.imagePadding == "string" ? t.imagePadding.trim() : "", r = document.createElement("section");
|
|
540
|
+
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
541
|
const c = document.createElement("div");
|
|
542
542
|
if (c.className = "gengage-qna-chrome-copy", c.dataset.gengagePart = "qna-chrome-copy", n) {
|
|
543
543
|
const s = document.createElement("h2");
|
|
@@ -547,23 +547,23 @@ var dt = class extends D {
|
|
|
547
547
|
const s = document.createElement("p");
|
|
548
548
|
s.className = "gengage-qna-chrome-subtitle", s.dataset.gengagePart = "qna-chrome-subtitle", s.textContent = o, c.appendChild(s);
|
|
549
549
|
}
|
|
550
|
-
if (c.children.length > 0 &&
|
|
550
|
+
if (c.children.length > 0 && r.appendChild(c), i && z(i)) {
|
|
551
551
|
const s = document.createElement("img");
|
|
552
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
553
|
s.style.display = "none";
|
|
554
|
-
}, { once: !0 }),
|
|
554
|
+
}, { once: !0 }), r.appendChild(s);
|
|
555
555
|
}
|
|
556
556
|
if (a) {
|
|
557
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()),
|
|
558
|
+
s.className = "gengage-qna-chrome-start", s.dataset.gengagePart = "qna-chrome-start", s.type = "button", s.textContent = a, s.addEventListener("click", () => this._handleOpenChat()), r.appendChild(s);
|
|
559
559
|
}
|
|
560
|
-
return
|
|
560
|
+
return r.children.length === 0 ? null : r;
|
|
561
561
|
}
|
|
562
562
|
_resolveUISpecRegistry() {
|
|
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 ?? P, a = (
|
|
566
|
+
const n = this._resolveUISpecRegistry(), o = this.config.renderer?.unknownRenderer ?? P, a = (l, r) => X(l, r, 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 (r
|
|
616
|
-
else if (
|
|
617
|
-
const s =
|
|
618
|
-
!c && s ? s.insertAdjacentElement("afterend", i) :
|
|
614
|
+
const l = e.querySelector(".gengage-qna-uispec"), r = e.querySelector(".gengage-qna-uispec > .gengage-qna-buttons"), c = this.config.inputAfterPills === !0;
|
|
615
|
+
if (r) c ? r.insertAdjacentElement("afterend", i) : r.insertAdjacentElement("beforebegin", i);
|
|
616
|
+
else if (l) {
|
|
617
|
+
const s = l.querySelector(":scope > .gengage-qna-heading");
|
|
618
|
+
!c && s ? s.insertAdjacentElement("afterend", i) : l.appendChild(i);
|
|
619
619
|
} else {
|
|
620
620
|
e.appendChild(a);
|
|
621
621
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gengage/assistant-fe",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "Source-available frontend widgets for Gengage AI Assistant — chat, Q&A, and similar-products. Backend is SaaS (gengage.ai).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|