ai12z 3.13.3 → 3.14.2
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/cjs/ai12z-bot.cjs.entry.js +107 -19
- package/dist/cjs/ai12z-chat-message.cjs.entry.js +17 -46
- package/dist/cjs/ai12z-knowledge-box.cjs.entry.js +14 -60
- package/dist/cjs/index.cjs.js +1 -0
- package/dist/cjs/styleSheetRegistry-7aecMygn.js +175 -0
- package/dist/collection/components/ai12z-bot/ai12z-bot.js +32 -13
- package/dist/collection/components/ai12z-knowledge-box/ai12z-knowledge-box.js +15 -61
- package/dist/collection/components/ai12z-knowledge-box/components/ai12z-chat-message.js +16 -46
- package/dist/collection/utils/liveagents/providers/salesforce.js +75 -6
- package/dist/collection/utils/styleSheetRegistry.js +169 -0
- package/dist/components/ai12z-bot.js +1 -1
- package/dist/components/ai12z-chat-message.js +1 -1
- package/dist/components/ai12z-chat.js +1 -1
- package/dist/components/ai12z-container.js +1 -1
- package/dist/components/ai12z-cta.js +1 -1
- package/dist/components/ai12z-form.js +1 -1
- package/dist/components/ai12z-inline-search.js +1 -1
- package/dist/components/ai12z-input-form.js +1 -1
- package/dist/components/ai12z-knowledge-box.js +1 -1
- package/dist/components/ai12z-search-panel.js +1 -1
- package/dist/components/audio-recorder.js +1 -1
- package/dist/components/dynamic-form.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/interaction-buttons.js +1 -1
- package/dist/components/item-list.js +1 -1
- package/dist/components/{p-DKxaam7U.js → p-3j2aDKYq.js} +1 -1
- package/dist/components/{p-BP8ig03d.js → p-AQ1MS6Ps.js} +1 -1
- package/dist/components/p-B9IJbo4G.js +1 -0
- package/dist/components/{p-DsZWeAcM.js → p-BWMhH2R1.js} +1 -1
- package/dist/components/{p-5UYwpNzl.js → p-BaXs0IIw.js} +1 -1
- package/dist/components/{p-Gr6Q2s96.js → p-Bnj1LjUJ.js} +1 -1
- package/dist/components/p-BwpiW24r.js +1 -0
- package/dist/components/{p-Bo3Ig8oX.js → p-BwqXbNCx.js} +1 -1
- package/dist/components/{p-D2nUK4Pa.js → p-COqFEHJ7.js} +1 -1
- package/dist/components/{p-DA32xa7d.js → p-Ci85xHWQ.js} +1 -1
- package/dist/components/{p-DUaZgAhA.js → p-CrfXJRIo.js} +1 -1
- package/dist/components/{p-DJ68HDol.js → p-DkRAkHLI.js} +2 -2
- package/dist/components/{p-ha1wIlZ-.js → p-Dubjoiw6.js} +1 -1
- package/dist/components/{p-C2wKkcYa.js → p-DvtUY5FW.js} +1 -1
- package/dist/components/{p-J--erGbY.js → p-dQEvevXk.js} +1 -1
- package/dist/{library/p-DAGa-uHD.js → components/p-g36mIk7k.js} +1 -1
- package/dist/components/p-m0Ed3g6I.js +1 -0
- package/dist/components/p-mBjDeFh_.js +1 -0
- package/dist/components/{p-q7YWDP9B.js → p-pOVc-eI8.js} +1 -1
- package/dist/components/{p-BCJzelr9.js → p-qwKoi5kn.js} +1 -1
- package/dist/components/{p-CKAp10SJ.js → p-xTOLReQF.js} +1 -1
- package/dist/components/privacy-modal.js +1 -1
- package/dist/components/search-results-page.js +1 -1
- package/dist/esm/ai12z-bot.entry.js +115 -27
- package/dist/esm/ai12z-category_2.entry.js +3 -3
- package/dist/esm/ai12z-chat-message.entry.js +17 -46
- package/dist/esm/ai12z-chat_2.entry.js +8 -8
- package/dist/esm/ai12z-container.entry.js +3 -3
- package/dist/esm/ai12z-cta.entry.js +4 -4
- package/dist/esm/ai12z-form.entry.js +2 -2
- package/dist/esm/ai12z-inline-search.entry.js +2 -2
- package/dist/esm/ai12z-knowledge-box.entry.js +18 -64
- package/dist/esm/ai12z-search-panel.entry.js +1 -1
- package/dist/esm/chat-avatar_6.entry.js +1 -1
- package/dist/esm/{ctaHelpers-BhM8KbEY.js → ctaHelpers-DrH6S5iU.js} +1 -1
- package/dist/esm/dynamic-form.entry.js +1 -1
- package/dist/esm/{index-BQKLwW-C.js → index-VWr-8RG8.js} +1 -1
- package/dist/esm/index.js +10 -9
- package/dist/esm/item-list.entry.js +2 -2
- package/dist/esm/{keyboard-shortcuts-Bd3LDe9j.js → keyboard-shortcuts-BhKv64FZ.js} +2 -2
- package/dist/esm/{parseHelper-9rP0JS7J.js → parseHelper-kOGOndOe.js} +1 -1
- package/dist/esm/{processCarouselData-Bf2pDFsV.js → processCarouselData-DX152a4X.js} +1 -1
- package/dist/esm/{reCaptchaHelpers-CUcgfdqX.js → reCaptchaHelpers-DUpCzUFb.js} +1 -1
- package/dist/esm/search-results-page.entry.js +4 -4
- package/dist/esm/{socket-service-B1OMbkCM.js → socket-service-D_h5x8Gr.js} +1 -1
- package/dist/esm/styleSheetRegistry-Bfi9VkqK.js +172 -0
- package/dist/esm/{surveyHelpers-CvrZlir1.js → surveyHelpers-D-00eWjv.js} +1 -1
- package/dist/esm/{utils-BTLjNTwP.js → utils-DK_Yhmpx.js} +1 -1
- package/dist/library/index.esm.js +1 -1
- package/dist/library/library.esm.js +1 -1
- package/dist/library/{p-cd764f70.entry.js → p-11c1f91d.entry.js} +1 -1
- package/dist/library/{p-806bfb3d.entry.js → p-1d382046.entry.js} +1 -1
- package/dist/library/{p-0641ba91.entry.js → p-252bb713.entry.js} +2 -2
- package/dist/library/p-25a678ca.entry.js +1 -0
- package/dist/library/p-53edf210.entry.js +1 -0
- package/dist/library/p-646a7eae.entry.js +1 -0
- package/dist/library/p-675d0243.entry.js +1 -0
- package/dist/library/{p-60d5d99f.entry.js → p-6ea05db1.entry.js} +1 -1
- package/dist/library/{p-7f0e306c.entry.js → p-7154a204.entry.js} +1 -1
- package/dist/library/{p-07f11cb8.entry.js → p-72a5eaf2.entry.js} +1 -1
- package/dist/library/{p-2d262192.entry.js → p-8f238b3f.entry.js} +1 -1
- package/dist/library/p-9cffb6fa.entry.js +1 -0
- package/dist/library/{p-y3Go1NSi.js → p-BCkDiHIY.js} +1 -1
- package/dist/{components/p-BhV62IFF.js → library/p-By1gJKXA.js} +1 -1
- package/dist/library/{p-Bbow4UZX.js → p-C0wNDqKO.js} +1 -1
- package/dist/library/p-C3yxqbFh.js +1 -0
- package/dist/library/p-CwZwG6gL.js +1 -0
- package/dist/library/{p-D5m1leH0.js → p-D1IPrgJe.js} +3 -3
- package/dist/library/{p-NAKC5NP9.js → p-KSKiM1sy.js} +1 -1
- package/dist/library/{p-C1eU4fpM.js → p-TJuczvVq.js} +1 -1
- package/dist/library/{p-CnadO0kA.js → p-ZyOWOLs5.js} +1 -1
- package/dist/library/{p-94bf0c7f.entry.js → p-cbfc9f73.entry.js} +1 -1
- package/dist/library/{p-014d5664.entry.js → p-d8506e43.entry.js} +1 -1
- package/dist/library/{p-BZ_koFpE.js → p-n8ydBHE4.js} +1 -1
- package/dist/types/components/ai12z-bot/ai12z-bot.d.ts +1 -0
- package/dist/types/components/ai12z-knowledge-box/ai12z-knowledge-box.d.ts +0 -3
- package/dist/types/components/ai12z-knowledge-box/components/ai12z-chat-message.d.ts +0 -2
- package/dist/types/utils/liveagents/providers/salesforce.d.ts +2 -0
- package/dist/types/utils/styleSheetRegistry.d.ts +40 -0
- package/package.json +2 -2
- package/dist/components/p-B3lv_O-6.js +0 -1
- package/dist/components/p-CLdlCTTp.js +0 -1
- package/dist/components/p-DT0Uarfg.js +0 -1
- package/dist/components/p-zVXADzTq.js +0 -1
- package/dist/library/p-29cd4edc.entry.js +0 -1
- package/dist/library/p-6f3727d3.entry.js +0 -1
- package/dist/library/p-83a71da9.entry.js +0 -1
- package/dist/library/p-DoBD_KPG.js +0 -1
- package/dist/library/p-d3a2acee.entry.js +0 -1
- package/dist/library/p-dc131a5c.entry.js +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils-BAJarpnb.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* styleSheetRegistry — single source of truth for custom CSS/JS injection.
|
|
7
|
+
*
|
|
8
|
+
* APPROACH
|
|
9
|
+
* --------
|
|
10
|
+
* CSS — One CSSStyleSheet object is constructed per URL (Constructable
|
|
11
|
+
* Stylesheets API). Any shadow root that needs the styles calls
|
|
12
|
+
* adoptStyleSheet(url, shadowRoot); the same object is pushed onto
|
|
13
|
+
* adoptedStyleSheets so the browser parses the rules exactly once,
|
|
14
|
+
* regardless of how many roots adopt it. The parent knowledge-box
|
|
15
|
+
* triggers the first fetch; child chat-message calls re-use the
|
|
16
|
+
* already-resolved Promise and adopt the cached sheet at zero cost.
|
|
17
|
+
*
|
|
18
|
+
* JS — Scripts are injected into the caller's shadow root (or element)
|
|
19
|
+
* exactly once per root per URL via a two-level cache: a WeakMap
|
|
20
|
+
* tracks which URLs have been appended to each root, and a url →
|
|
21
|
+
* Promise map shares the single load event across all roots so the
|
|
22
|
+
* network request fires only once. Concurrent callers await the same
|
|
23
|
+
* load event; subsequent callers for the same URL in the same root
|
|
24
|
+
* return immediately.
|
|
25
|
+
*
|
|
26
|
+
* SINGLE CODE PATH
|
|
27
|
+
* ----------------
|
|
28
|
+
* Both ai12z-knowledge-box and ai12z-chat-message import from this module.
|
|
29
|
+
* The parent box makes the first call (triggering the fetch / DOM append).
|
|
30
|
+
* Child calls get the cached result with no side-effects.
|
|
31
|
+
* There is no third injection point; do not add one here.
|
|
32
|
+
*/
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// CSS – Constructable Stylesheets
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* True when the browser supports the Constructable Stylesheets API:
|
|
38
|
+
* - CSSStyleSheet.replace() (required to build sheets from text)
|
|
39
|
+
* - Document.adoptedStyleSheets (required to attach them)
|
|
40
|
+
* Safari 15 and Safari 16.0 fail both checks; they get the <link> fallback.
|
|
41
|
+
*/
|
|
42
|
+
const supportsConstructable = typeof CSSStyleSheet !== 'undefined' &&
|
|
43
|
+
'replace' in CSSStyleSheet.prototype &&
|
|
44
|
+
'adoptedStyleSheets' in Document.prototype;
|
|
45
|
+
const _cssCache = new Map();
|
|
46
|
+
/** Per-shadow-root set of URLs already injected via the <link> fallback path. */
|
|
47
|
+
const _linkFallbackCache = new WeakMap();
|
|
48
|
+
/**
|
|
49
|
+
* Fetch `url` exactly once, build a CSSStyleSheet from its text, and adopt
|
|
50
|
+
* it in `shadowRoot`. Safe to call from multiple components / shadow roots —
|
|
51
|
+
* repeated calls for the same URL share the cached sheet.
|
|
52
|
+
*/
|
|
53
|
+
function adoptStyleSheet(url, shadowRoot) {
|
|
54
|
+
if (!url || !shadowRoot || !utils.isValidHttpsUrl(url))
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
// ── Legacy fallback for Safari 15 / Safari 16.0 ──────────────────────────
|
|
57
|
+
// Constructable Stylesheets are not supported; append a <link> element to
|
|
58
|
+
// the shadow root instead. The WeakMap cache ensures one <link> per URL
|
|
59
|
+
// per shadow root, mirroring the once-per-URL guarantee of the main path.
|
|
60
|
+
if (!supportsConstructable) {
|
|
61
|
+
let adopted = _linkFallbackCache.get(shadowRoot);
|
|
62
|
+
if (!adopted) {
|
|
63
|
+
adopted = new Set();
|
|
64
|
+
_linkFallbackCache.set(shadowRoot, adopted);
|
|
65
|
+
}
|
|
66
|
+
if (!adopted.has(url)) {
|
|
67
|
+
adopted.add(url);
|
|
68
|
+
const linkEl = document.createElement('link');
|
|
69
|
+
linkEl.rel = 'stylesheet';
|
|
70
|
+
linkEl.href = url;
|
|
71
|
+
shadowRoot.appendChild(linkEl);
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
// ── Constructable Stylesheets path (Chrome, Firefox, Safari 16.4+) ────────
|
|
76
|
+
if (!_cssCache.has(url)) {
|
|
77
|
+
const sheetPromise = fetch(url)
|
|
78
|
+
.then(r => {
|
|
79
|
+
if (!r.ok)
|
|
80
|
+
throw new Error(`[ai12z] adoptStyleSheet: HTTP ${r.status} for ${url}`);
|
|
81
|
+
return r.text();
|
|
82
|
+
})
|
|
83
|
+
.then(css => {
|
|
84
|
+
const sheet = new CSSStyleSheet();
|
|
85
|
+
return sheet.replace(css).then(() => sheet);
|
|
86
|
+
})
|
|
87
|
+
.catch(err => {
|
|
88
|
+
_cssCache.delete(url); // allow a retry on next call
|
|
89
|
+
return Promise.reject(err);
|
|
90
|
+
});
|
|
91
|
+
_cssCache.set(url, sheetPromise);
|
|
92
|
+
}
|
|
93
|
+
return _cssCache.get(url)
|
|
94
|
+
.then(sheet => {
|
|
95
|
+
if (!shadowRoot.adoptedStyleSheets.includes(sheet)) {
|
|
96
|
+
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, sheet];
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.catch(err => {
|
|
100
|
+
console.error('[ai12z] adoptStyleSheet failed for', url, err);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// JS – shadow-root-level, exactly-once injection per root
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
/**
|
|
107
|
+
* Global load-event cache: url → Promise. The network request fires only
|
|
108
|
+
* once regardless of how many roots call loadScriptOnce for the same URL.
|
|
109
|
+
*/
|
|
110
|
+
const _scriptLoadCache = new Map();
|
|
111
|
+
/**
|
|
112
|
+
* Per-root injection tracker: mirrors _linkFallbackCache for CSS.
|
|
113
|
+
* Ensures each shadow root / element gets the <script> appended exactly once.
|
|
114
|
+
*/
|
|
115
|
+
const _scriptRootCache = new WeakMap();
|
|
116
|
+
/**
|
|
117
|
+
* Append `url` as a <script> into `el` (shadow root or element) exactly once
|
|
118
|
+
* per root per URL. The underlying network request is shared across all roots
|
|
119
|
+
* via a url → Promise cache, so the script is only fetched once.
|
|
120
|
+
*/
|
|
121
|
+
function loadScriptOnce(url, el) {
|
|
122
|
+
if (!url || !utils.isValidHttpsUrl(url)) {
|
|
123
|
+
if (url)
|
|
124
|
+
console.warn('[ai12z] Blocked script injection — URL must use HTTPS.', url);
|
|
125
|
+
return Promise.resolve();
|
|
126
|
+
}
|
|
127
|
+
// ── Per-root deduplication ──────────────────────────────────────────────
|
|
128
|
+
let rootSet = _scriptRootCache.get(el);
|
|
129
|
+
if (!rootSet) {
|
|
130
|
+
rootSet = new Set();
|
|
131
|
+
_scriptRootCache.set(el, rootSet);
|
|
132
|
+
}
|
|
133
|
+
if (rootSet.has(url)) {
|
|
134
|
+
// Already injected into this root. Return the shared load Promise.
|
|
135
|
+
// If the load cache no longer has an entry (stale rootSet marker after a
|
|
136
|
+
// previous error), remove it and fall through to re-inject rather than
|
|
137
|
+
// resolving early and letting callers assume the script is ready.
|
|
138
|
+
const cached = _scriptLoadCache.get(url);
|
|
139
|
+
if (cached)
|
|
140
|
+
return cached;
|
|
141
|
+
rootSet.delete(url);
|
|
142
|
+
}
|
|
143
|
+
rootSet.add(url);
|
|
144
|
+
// ── Append script element into this root ────────────────────────────────
|
|
145
|
+
if (!_scriptLoadCache.has(url)) {
|
|
146
|
+
// First root to request this URL — track the load event.
|
|
147
|
+
const p = new Promise((resolve, reject) => {
|
|
148
|
+
const script = document.createElement('script');
|
|
149
|
+
script.src = url;
|
|
150
|
+
script.async = false;
|
|
151
|
+
script.onload = () => resolve();
|
|
152
|
+
script.onerror = () => reject(new Error(`[ai12z] Failed to load script: ${url}`));
|
|
153
|
+
el.appendChild(script);
|
|
154
|
+
});
|
|
155
|
+
_scriptLoadCache.set(url, p.catch(err => {
|
|
156
|
+
_scriptLoadCache.delete(url);
|
|
157
|
+
rootSet.delete(url);
|
|
158
|
+
return Promise.reject(err);
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// Already loading/loaded globally; inject into this root without a new
|
|
163
|
+
// load listener (the shared Promise already tracks completion).
|
|
164
|
+
const script = document.createElement('script');
|
|
165
|
+
script.src = url;
|
|
166
|
+
script.async = false;
|
|
167
|
+
el.appendChild(script);
|
|
168
|
+
}
|
|
169
|
+
return _scriptLoadCache.get(url).catch(err => {
|
|
170
|
+
console.warn('[ai12z] loadScriptOnce:', err);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.adoptStyleSheet = adoptStyleSheet;
|
|
175
|
+
exports.loadScriptOnce = loadScriptOnce;
|
|
@@ -375,6 +375,7 @@ export class Ai12zBot {
|
|
|
375
375
|
if (currentDomElement) {
|
|
376
376
|
// Append the agent event messages to the current message bubble
|
|
377
377
|
currentDomElement.parentNode.appendChild(agentEventMessages);
|
|
378
|
+
this.currentDomId = "";
|
|
378
379
|
return agentEventMessages;
|
|
379
380
|
}
|
|
380
381
|
}
|
|
@@ -424,9 +425,6 @@ export class Ai12zBot {
|
|
|
424
425
|
this.agentEventHandler = event => {
|
|
425
426
|
this.isTypingIndicatorVisible = false;
|
|
426
427
|
if ((event === null || event === void 0 ? void 0 : event.length) > 0) {
|
|
427
|
-
if (this.isLiveAgentEnabled && this.currentDomId === "") {
|
|
428
|
-
this.currentDomId = this.messages[this.messages.length - 1].id;
|
|
429
|
-
}
|
|
430
428
|
// Persist each system event into this.messages so they survive page reload
|
|
431
429
|
const systemMessages = event.map((evt) => ({
|
|
432
430
|
id: evt.id || `system-${generateUUID()}`,
|
|
@@ -468,6 +466,16 @@ export class Ai12zBot {
|
|
|
468
466
|
this.isLiveAgent = true;
|
|
469
467
|
this.updateBotState();
|
|
470
468
|
};
|
|
469
|
+
this.handleAgentUnavailable = () => {
|
|
470
|
+
this.addEventMessage("Live Agent is currently unavailable. Please try again later.");
|
|
471
|
+
this.isTypingIndicatorVisible = false;
|
|
472
|
+
this.isLiveAgent = false;
|
|
473
|
+
this.liveAgentSessionId = "";
|
|
474
|
+
this.liveAgentConversationId = "";
|
|
475
|
+
this.updateBotState();
|
|
476
|
+
this.announce("Live agent is currently unavailable");
|
|
477
|
+
this.clearEvents();
|
|
478
|
+
};
|
|
471
479
|
this.toggleBot = _e => {
|
|
472
480
|
// e.stopPropagation()
|
|
473
481
|
this.isToggled = !this.isToggled;
|
|
@@ -1140,6 +1148,9 @@ export class Ai12zBot {
|
|
|
1140
1148
|
this.socket.on(endEvent, async (rawData) => {
|
|
1141
1149
|
// For v2, adapt the response format to match legacy expectations
|
|
1142
1150
|
const data = protocol === "v2" ? adaptCompleteToLegacy(rawData) : rawData;
|
|
1151
|
+
if (data.showInput !== undefined && typeof data.showInput === "boolean") {
|
|
1152
|
+
this.botSettings.showInput = data.showInput;
|
|
1153
|
+
}
|
|
1143
1154
|
this.unreadCount++;
|
|
1144
1155
|
const { id, idChanged, orphaned } = ensureMessageId(this.currentDomId, this.messages, "chatbot");
|
|
1145
1156
|
this.currentDomId = id;
|
|
@@ -1623,7 +1634,9 @@ export class Ai12zBot {
|
|
|
1623
1634
|
this.liveAgentSessionId = "";
|
|
1624
1635
|
this.liveAgentConversationId = "";
|
|
1625
1636
|
this.liveAgentButtonText = "Talk to a Live Agent";
|
|
1626
|
-
this.sendMessage(((_a = this.botSettings) === null || _a === void 0 ? void 0 : _a.llmMessageOnDisconnect) !== ""
|
|
1637
|
+
this.sendMessage(((_a = this.botSettings) === null || _a === void 0 ? void 0 : _a.llmMessageOnDisconnect) !== ""
|
|
1638
|
+
? (_b = this.botSettings) === null || _b === void 0 ? void 0 : _b.llmMessageOnDisconnect
|
|
1639
|
+
: "The live agent has been disconnected. Please do not initiate the live agent directive again.", ((_c = this.botSettings) === null || _c === void 0 ? void 0 : _c.userMessageOnDisconnect) !== "" ? (_d = this.botSettings) === null || _d === void 0 ? void 0 : _d.userMessageOnDisconnect : "The live agent has ended the conversation.", { isLiveChatEnded: true });
|
|
1627
1640
|
this.announce("Live agent chat ended");
|
|
1628
1641
|
this.clearEvents();
|
|
1629
1642
|
}
|
|
@@ -1644,6 +1657,7 @@ export class Ai12zBot {
|
|
|
1644
1657
|
this.liveAgentListenersRegistered = true;
|
|
1645
1658
|
ChatEventBus.on("FINDING_AGENT", this.findingAgent);
|
|
1646
1659
|
ChatEventBus.on("AGENT_EVENT", this.agentEventHandler);
|
|
1660
|
+
ChatEventBus.on("AGENT_UNAVAILABLE", this.handleAgentUnavailable);
|
|
1647
1661
|
ChatEventBus.on("TYPING_STARTED", this.handleTypingStarted);
|
|
1648
1662
|
ChatEventBus.on("TYPING_STOPPED", this.handleTypingStopped);
|
|
1649
1663
|
ChatEventBus.on("AGENT_MESSAGE", this.agentMessageCreated);
|
|
@@ -1655,6 +1669,7 @@ export class Ai12zBot {
|
|
|
1655
1669
|
this.liveAgentListenersRegistered = false;
|
|
1656
1670
|
ChatEventBus.off("FINDING_AGENT", this.findingAgent);
|
|
1657
1671
|
ChatEventBus.off("AGENT_EVENT", this.agentEventHandler);
|
|
1672
|
+
ChatEventBus.off("AGENT_UNAVAILABLE", this.handleAgentUnavailable);
|
|
1658
1673
|
ChatEventBus.off("AGENT_MESSAGE", this.agentMessageCreated);
|
|
1659
1674
|
ChatEventBus.off("AGENT_ERROR", this.handleAgentError);
|
|
1660
1675
|
ChatEventBus.off("CONVERSATION_CLOSED", this.handleAgentConversationEnded);
|
|
@@ -1866,7 +1881,7 @@ export class Ai12zBot {
|
|
|
1866
1881
|
}
|
|
1867
1882
|
}
|
|
1868
1883
|
render() {
|
|
1869
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x, _y;
|
|
1884
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _w, _x, _y, _z;
|
|
1870
1885
|
if (!this.canRender) {
|
|
1871
1886
|
return (h(Host, null, h("span", { style: { display: "none" } }, "Failed to load ai12z bot control due to insufficient fund")));
|
|
1872
1887
|
}
|
|
@@ -1949,7 +1964,11 @@ export class Ai12zBot {
|
|
|
1949
1964
|
"opacity-90": !this.isProse,
|
|
1950
1965
|
"max-w-full break-words @md:text-body2 box-border @md:pr-4 flex-1 rounded-lg text-gray-30 pr-2 text-body3": true,
|
|
1951
1966
|
}, innerHTML: message.text, id: message.id }, message.isLoading && (h("div", { class: "w-full rounded-md", id: "spinner" }, h("div", { class: "flex animate-pulse space-x-4" }, h("div", { class: "flex-1 space-y-3 py-1" }, h("div", { class: "h-4 rounded bg-gray-200" }), h("div", { class: "space-y-3" }, h("div", { class: "grid grid-cols-3 gap-4" }, h("div", { class: "col-span-2 h-4 rounded bg-gray-200" }), h("div", { class: "col-span-1 h-4 rounded bg-gray-200" })), h("div", { class: "h-4 rounded bg-gray-200" }))))))), message.text !== "" && message.showIcon && ((_c = this.botSettings.showMessageIcons) !== null && _c !== void 0 ? _c : true) && (h("interaction-buttons", { message: message, chatArray: this.messages, currentIndex: idx, dataKey: this.dataKey, dataMode: this.dataMode, voice: this.voice, voiceType: this.voiceType, source: "bot", conversationId: this.conversationId, projectId: ((_d = this.botSettings) === null || _d === void 0 ? void 0 : _d.pId) || "" })), h("div", { class: "text-gray-30 pt-2 text-body4" }, this.botSettings.botName, " \u2022 ", message.timestamp)))));
|
|
1952
|
-
}), this.showHistory && (h("chatbot-history", { chatList: this.conversationHistory, botName: (_s = this.botSettings) === null || _s === void 0 ? void 0 : _s.botName, styles: this.customStyle, scripts: this.customJS })), h("div", { class: "h-px pt-2px", style: { overflowAnchor: "auto" } })), h("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", class: "sr-only" }, this.announceMessage)))), h("form", { "data-testid": "user-input", class: `relative pointer-events-auto ${this.isOpened ? "p-2.5" : ""} searchform user-input`, "aria-label": "Message Area", "aria-hidden": "false", style: {
|
|
1967
|
+
}), this.showHistory && (h("chatbot-history", { chatList: this.conversationHistory, botName: (_s = this.botSettings) === null || _s === void 0 ? void 0 : _s.botName, styles: this.customStyle, scripts: this.customJS })), h("div", { class: "h-px pt-2px", style: { overflowAnchor: "auto" } })), h("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", class: "sr-only" }, this.announceMessage)))), ((_t = this.botSettings) === null || _t === void 0 ? void 0 : _t.showInput) !== false && (h("form", { "data-testid": "user-input", class: `relative pointer-events-auto ${this.isOpened ? "p-2.5" : ""} searchform user-input`, "aria-label": "Message Area", "aria-hidden": "false", style: {
|
|
1968
|
+
opacity: !this.isMinimized ? "1" : "0",
|
|
1969
|
+
transform: "translateX(0)",
|
|
1970
|
+
pointerEvents: !this.isMinimized ? "auto" : "none",
|
|
1971
|
+
} }, !this.isOpened && (h("div", { class: `absolute right-4 md:right-0 border-2 border-white border-solid rounded-full ${this.isContent ? "" : "top-0"} minimize-input` }, h("button", { class: "rounded-full flex items-center justify-center disabled:cursor-not-allowed bg-gray-500 bg-opacity-60 hover:bg-opacity-80 h-5 w-5 bot-btn-primary", "aria-label": "Minimize Bot", tabindex: "0", onClick: e => {
|
|
1953
1972
|
e.preventDefault();
|
|
1954
1973
|
this.isMinimized = !this.isMinimized;
|
|
1955
1974
|
this.isOpened = !this.isMinimized;
|
|
@@ -1981,12 +2000,12 @@ export class Ai12zBot {
|
|
|
1981
2000
|
.filter(Boolean)
|
|
1982
2001
|
.join(" "), "aria-placeholder": this.isLiveAgent
|
|
1983
2002
|
? "Type a message to the agent..."
|
|
1984
|
-
: ((
|
|
1985
|
-
? (
|
|
2003
|
+
: ((_u = this.botSettings) === null || _u === void 0 ? void 0 : _u.botPlaceholderText) !== ""
|
|
2004
|
+
? (_w = this.botSettings) === null || _w === void 0 ? void 0 : _w.botPlaceholderText
|
|
1986
2005
|
: "Ask me anything", "aria-label": "Type your message here", class: `resize-none overflow-hidden text-ellipsis focus:outline-none w-full custom-input ${this.hideAllButtons ? "hidden" : ""}`, "data-testid": "user-input-textarea", rows: this.rowCount, name: "userMessage", placeholder: this.isLiveAgent
|
|
1987
2006
|
? "Type a message to the agent..."
|
|
1988
|
-
: ((
|
|
1989
|
-
? (
|
|
2007
|
+
: ((_x = this.botSettings) === null || _x === void 0 ? void 0 : _x.botPlaceholderText) !== ""
|
|
2008
|
+
? (_y = this.botSettings) === null || _y === void 0 ? void 0 : _y.botPlaceholderText
|
|
1990
2009
|
: "Ask me anything", ref: el => (this.inputEl = el), onKeyUp: _e => {
|
|
1991
2010
|
this.adjustHeight();
|
|
1992
2011
|
}, onKeyDown: e => {
|
|
@@ -2038,7 +2057,7 @@ export class Ai12zBot {
|
|
|
2038
2057
|
this.isOpened = true;
|
|
2039
2058
|
this.isContent = false;
|
|
2040
2059
|
this.handleSend(button.label);
|
|
2041
|
-
} }, button.label)))))))), h("div", {
|
|
2060
|
+
} }, button.label))))))))), h("div", {
|
|
2042
2061
|
// slot="bot"
|
|
2043
2062
|
class: "pointer-events-auto fixed right-7 whitespace-nowrap transition-transform duration-300 ease-in-out fab", style: {
|
|
2044
2063
|
opacity: this.isMinimized ? "1" : "0",
|
|
@@ -2048,8 +2067,8 @@ export class Ai12zBot {
|
|
|
2048
2067
|
}, onClick: () => {
|
|
2049
2068
|
this.openChat();
|
|
2050
2069
|
}
|
|
2051
|
-
}, this.isBot && h("slot", { name: "bot" }), !this.isBot && (h("button", { class: "rounded-full flex cursor-pointer items-center pr-[14px] md:gap-x-3 focus:outline focus:outline-2 focus:outline-offset-2 focus:outline-blue-focused bot-btn-primary", tabindex: "0", "aria-label": "open Bot" }, h("div", { class: "w-10 h-10 flex items-center justify-center bg-white rounded-full border relative" }, this.botSettings.botLaunchIcon && h("img", { src: this.botSettings.botLaunchIcon, alt: "bot icon", class: "w-8 h-8 rounded-lg" }), !this.botSettings.botLaunchIcon && (h("svg", { viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", stroke: "#2095ae", "aria-hidden": "true" }, h("g", { "stroke-width": "0" }), h("g", { "stroke-linecap": "round", "stroke-linejoin": "round" }), h("g", null, " ", h("path", { d: "M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z", stroke: "#2095ae", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }), " ")))), h("span", { class: "bot-name" }, " ", (
|
|
2052
|
-
|
|
2070
|
+
}, this.isBot && h("slot", { name: "bot" }), !this.isBot && (h("button", { class: "rounded-full flex cursor-pointer items-center pr-[14px] md:gap-x-3 focus:outline focus:outline-2 focus:outline-offset-2 focus:outline-blue-focused bot-btn-primary", tabindex: "0", "aria-label": "open Bot" }, h("div", { class: "w-10 h-10 flex items-center justify-center bg-white rounded-full border relative" }, this.botSettings.botLaunchIcon && h("img", { src: this.botSettings.botLaunchIcon, alt: "bot icon", class: "w-8 h-8 rounded-lg" }), !this.botSettings.botLaunchIcon && (h("svg", { viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", stroke: "#2095ae", "aria-hidden": "true" }, h("g", { "stroke-width": "0" }), h("g", { "stroke-linecap": "round", "stroke-linejoin": "round" }), h("g", null, " ", h("path", { d: "M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z", stroke: "#2095ae", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }), " ")))), h("span", { class: "bot-name" }, " ", (_z = this.botSettings) === null || _z === void 0 ? void 0 :
|
|
2071
|
+
_z.botName, " ")))))), h("keyboard-shortcuts-dialog", { show: this.showShortcutsDialog, shortcuts: this.shortcuts, onCloseDialog: () => {
|
|
2053
2072
|
this.showShortcutsDialog = false;
|
|
2054
2073
|
} }), h("delete-confirmation-modal", { show: this.showLiveAgentEndDialog, dialogTitle: "End live agent chat?", message: "You are about to end the current live agent conversation. You can continue chatting with the bot after ending it.", confirmButtonText: "End", onConfirmDelete: () => {
|
|
2055
2074
|
this.confirmEndLiveAgent();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h, Env } from "@stencil/core";
|
|
2
|
-
import { sendFeedback, getConfig, submitForm
|
|
2
|
+
import { sendFeedback, getConfig, submitForm } from "../../utils/utils";
|
|
3
|
+
import { adoptStyleSheet, loadScriptOnce } from "../../utils/styleSheetRegistry";
|
|
3
4
|
import { io } from "socket.io-client";
|
|
4
5
|
import showdown from "showdown";
|
|
5
6
|
import { getEndpoint, getBackendProtocol, generateUUID, updateButtonEvents, splitContentMultiple, getMetaInfo } from "../../utils/utils";
|
|
@@ -31,7 +32,6 @@ export class Ai12zKnowledgeBox {
|
|
|
31
32
|
this.welcomeReady = true;
|
|
32
33
|
this.cdnPath = "https://cdn.ai12z.net/assets/kb";
|
|
33
34
|
this.initializeScript = id => {
|
|
34
|
-
console.log("Initializing script for ID:", id);
|
|
35
35
|
setTimeout(() => {
|
|
36
36
|
this.initializeScripts.emit({ id });
|
|
37
37
|
}, 1000);
|
|
@@ -234,7 +234,7 @@ export class Ai12zKnowledgeBox {
|
|
|
234
234
|
};
|
|
235
235
|
getConfig(payload, this.dataMode)
|
|
236
236
|
.then(async (data) => {
|
|
237
|
-
var _a, _b, _c, _d, _e
|
|
237
|
+
var _a, _b, _c, _d, _e;
|
|
238
238
|
if (data) {
|
|
239
239
|
this.kbSettings = data;
|
|
240
240
|
switch ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.questionType) {
|
|
@@ -254,10 +254,10 @@ export class Ai12zKnowledgeBox {
|
|
|
254
254
|
this.addEventListeners(`.ai12z-kb-wrapper`);
|
|
255
255
|
const welcomeLoads = [];
|
|
256
256
|
if ((_d = this.kbSettings.welcome) === null || _d === void 0 ? void 0 : _d.scripts) {
|
|
257
|
-
welcomeLoads.push(
|
|
257
|
+
welcomeLoads.push(loadScriptOnce(this.kbSettings.welcome.scripts, this.el.shadowRoot));
|
|
258
258
|
}
|
|
259
259
|
if ((_e = this.kbSettings.welcome) === null || _e === void 0 ? void 0 : _e.styles) {
|
|
260
|
-
welcomeLoads.push(
|
|
260
|
+
welcomeLoads.push(adoptStyleSheet(this.kbSettings.welcome.styles, this.el.shadowRoot));
|
|
261
261
|
}
|
|
262
262
|
if (welcomeLoads.length > 0) {
|
|
263
263
|
await Promise.all(welcomeLoads);
|
|
@@ -279,18 +279,10 @@ export class Ai12zKnowledgeBox {
|
|
|
279
279
|
document.head.appendChild(linkEl);
|
|
280
280
|
}
|
|
281
281
|
if (this.kbSettings.customCSS) {
|
|
282
|
-
|
|
282
|
+
adoptStyleSheet(this.kbSettings.customCSS, this.el.shadowRoot);
|
|
283
283
|
}
|
|
284
284
|
if (this.kbSettings.customJS) {
|
|
285
|
-
|
|
286
|
-
console.warn("[ai12z] Blocked customJS injection: URL must use HTTPS.", this.kbSettings.customJS);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
const scriptEl = document.createElement("script");
|
|
290
|
-
scriptEl.setAttribute("type", "text/javascript");
|
|
291
|
-
scriptEl.setAttribute("src", this.kbSettings.customJS);
|
|
292
|
-
(_f = this.el.shadowRoot) === null || _f === void 0 ? void 0 : _f.appendChild(scriptEl);
|
|
293
|
-
}
|
|
285
|
+
loadScriptOnce(this.kbSettings.customJS, this.el.shadowRoot);
|
|
294
286
|
}
|
|
295
287
|
}
|
|
296
288
|
})
|
|
@@ -300,49 +292,6 @@ export class Ai12zKnowledgeBox {
|
|
|
300
292
|
this.errored.emit(error);
|
|
301
293
|
});
|
|
302
294
|
}
|
|
303
|
-
insertStyles(linkURL) {
|
|
304
|
-
const linkEl = document.createElement("link");
|
|
305
|
-
linkEl.setAttribute("rel", "stylesheet");
|
|
306
|
-
linkEl.setAttribute("href", linkURL);
|
|
307
|
-
const shadowRoot = this.el.shadowRoot;
|
|
308
|
-
if (shadowRoot) {
|
|
309
|
-
shadowRoot.appendChild(linkEl);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
insertStylesAsync(linkURL) {
|
|
313
|
-
return new Promise(resolve => {
|
|
314
|
-
const shadowRoot = this.el.shadowRoot;
|
|
315
|
-
if (!shadowRoot) {
|
|
316
|
-
resolve();
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
const linkEl = document.createElement("link");
|
|
320
|
-
linkEl.setAttribute("rel", "stylesheet");
|
|
321
|
-
linkEl.setAttribute("href", linkURL);
|
|
322
|
-
linkEl.addEventListener("load", () => resolve());
|
|
323
|
-
linkEl.addEventListener("error", () => resolve());
|
|
324
|
-
shadowRoot.appendChild(linkEl);
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
insertScriptAsync(scriptURL) {
|
|
328
|
-
if (!isValidHttpsUrl(scriptURL)) {
|
|
329
|
-
console.warn("[ai12z] Blocked script injection: URL must use HTTPS.", scriptURL);
|
|
330
|
-
return Promise.resolve();
|
|
331
|
-
}
|
|
332
|
-
return new Promise(resolve => {
|
|
333
|
-
const shadowRoot = this.el.shadowRoot;
|
|
334
|
-
if (!shadowRoot) {
|
|
335
|
-
resolve();
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const scriptEl = document.createElement("script");
|
|
339
|
-
scriptEl.setAttribute("type", "text/javascript");
|
|
340
|
-
scriptEl.setAttribute("src", scriptURL);
|
|
341
|
-
scriptEl.addEventListener("load", () => resolve());
|
|
342
|
-
scriptEl.addEventListener("error", () => resolve());
|
|
343
|
-
shadowRoot.appendChild(scriptEl);
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
295
|
getResults(type) {
|
|
347
296
|
var _a, _b;
|
|
348
297
|
// console.log("Getting results for question:", this.question)
|
|
@@ -456,9 +405,14 @@ export class Ai12zKnowledgeBox {
|
|
|
456
405
|
}
|
|
457
406
|
}
|
|
458
407
|
componentWillLoad() {
|
|
459
|
-
|
|
408
|
+
adoptStyleSheet(`https://cdn.ai12z.net/assets/bot/v2/tailwind.min.css`, this.el.shadowRoot);
|
|
460
409
|
this.socketConnection();
|
|
461
410
|
this.getConfig();
|
|
411
|
+
const w = window;
|
|
412
|
+
if (!w.ai12z)
|
|
413
|
+
w.ai12z = {};
|
|
414
|
+
if (!w.ai12zChat)
|
|
415
|
+
w.ai12zChat = w.ai12z;
|
|
462
416
|
}
|
|
463
417
|
disconnectedCallback() {
|
|
464
418
|
if (this.socket) {
|
|
@@ -647,7 +601,7 @@ export class Ai12zKnowledgeBox {
|
|
|
647
601
|
}
|
|
648
602
|
render() {
|
|
649
603
|
var _a, _b;
|
|
650
|
-
return (h("div", { key: '
|
|
604
|
+
return (h("div", { key: 'f26a34215a56acd7d3f393a4f0d23727c74ba40a', class: "ai12z-kb-wrapper" }, this.error ? h("p", { class: "ai12z-suggest-error-msg" }, "Error please try again!") : null, this.items.map(item => {
|
|
651
605
|
var _a, _b, _c, _d;
|
|
652
606
|
return (h("div", { class: "prose max-w-none ai12z-suggest-container" }, h("div", null, h("div", null, h("div", { class: "flex flex-row gap-1" }, h("div", { class: "flex items-center gap-2 mb-3", style: { width: "90%" } }, ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.showTitle) && (h("svg", { width: "28", height: "28", viewBox: "0 0 48 48", fill: "currentColor", xmlns: "http://www.w3.org/2000/svg", class: "diamond-icon" + (this.isLoading && !this.finalResponse ? " loading" : "") }, h("path", { d: "M24 2c-3 8-8 13-16 16 8 3 13 8 16 16 3-8 8-13 16-16-8-3-13-8-16-16z" }))), ((_b = this.kbSettings) === null || _b === void 0 ? void 0 : _b.showTitle) && (h("h5", { class: "text-lg font-semibold text-gray-800 m-0" }, !this.finalResponse ? "Generating..." : (_c = this.kbSettings.title) !== null && _c !== void 0 ? _c : "AI Overview"))), item.thumbsUpDown && !this.isLoading && (h("div", null, h("button", { id: `thumbsUp_${item.insightId}`, onClick: () => {
|
|
653
607
|
var _a;
|
|
@@ -668,7 +622,7 @@ export class Ai12zKnowledgeBox {
|
|
|
668
622
|
questionText: this.question,
|
|
669
623
|
});
|
|
670
624
|
}, class: "chat-thumbs-down", "aria-label": "Thumbs Down" }, h("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", class: "w-6 h-6" }, h("path", { "stroke-linecap": "round", "stroke-linejoin": "round", d: "M7.498 15.25H4.372c-1.026 0-1.945-.694-2.054-1.715a12.137 12.137 0 0 1-.068-1.285c0-2.848.992-5.464 2.649-7.521C5.287 4.247 5.886 4 6.504 4h4.016a4.5 4.5 0 0 1 1.423.23l3.114 1.04a4.5 4.5 0 0 0 1.423.23h1.294M7.498 15.25c.618 0 .991.724.725 1.282A7.471 7.471 0 0 0 7.5 19.75 2.25 2.25 0 0 0 9.75 22a.75.75 0 0 0 .75-.75v-.633c0-.573.11-1.14.322-1.672.304-.76.93-1.33 1.653-1.715a9.04 9.04 0 0 0 2.86-2.4c.498-.634 1.226-1.08 2.032-1.08h.384m-10.253 1.5H9.7m8.075-9.75c.01.05.027.1.05.148.593 1.2.925 2.55.925 3.977 0 1.487-.36 2.89-.999 4.125m.023-8.25c-.076-.365.183-.75.575-.75h.908c.889 0 1.713.518 1.972 1.368.339 1.11.521 2.287.521 3.507 0 1.553-.295 3.036-.831 4.398-.306.774-1.086 1.227-1.918 1.227h-1.053c-.472 0-.745-.556-.5-.96a8.95 8.95 0 0 0 .303-.54" }))))))), !this.isLoading && (h("div", null, ((_d = this.searchResults) === null || _d === void 0 ? void 0 : _d.controlType) !== "form" && (h("ai12z-chat-message", { id: item.id, text: this.currentStreamingText, kbSettings: this.kbSettings, "show-button": this.showButton, streaming: this.isStreaming && item.id === this.domId })), h("div", { class: { "ai12z-suggest-relevance": true, "ai12z-suggest-hide": !item["isRelevance"] } }, h("a", { href: "" }, item["relevanceScore"])), h("div", { class: "custom-privacy" }, h("slot", { name: "custom-privacy" })))), this.isLoading && (h("div", { class: "w-full rounded-md", id: "spinner" }, h("div", { class: "flex animate-pulse space-x-4" }, h("div", { class: "flex-1 space-y-3 py-1" }, h("div", { class: "h-4 rounded bg-gray-200" }), h("div", { class: "space-y-3" }, h("div", { class: "grid grid-cols-3 gap-4" }, h("div", { class: "col-span-2 h-4 rounded bg-gray-200" }), h("div", { class: "col-span-1 h-4 rounded bg-gray-200" })), h("div", { class: "h-4 rounded bg-gray-200" })))))))));
|
|
671
|
-
}), ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.questionType) === "staticHtml" && this.items.length === 0 && this.welcomeReady && (h("div", { key: '
|
|
625
|
+
}), ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.questionType) === "staticHtml" && this.items.length === 0 && this.welcomeReady && (h("div", { key: '340c562562715563715e5a103019dd19458c994f', class: "ai12z-suggest-answer", innerHTML: (_b = this.kbSettings.welcome) === null || _b === void 0 ? void 0 : _b.message }))));
|
|
672
626
|
}
|
|
673
627
|
static get is() { return "ai12z-knowledge-box"; }
|
|
674
628
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
2
|
import { initializeScript as initializeScriptHelper } from "../../../utils/botHelpers/botHelpers";
|
|
3
|
-
import {
|
|
3
|
+
import { adoptStyleSheet, loadScriptOnce } from "../../../utils/styleSheetRegistry";
|
|
4
4
|
export class Ai12zChatMessage {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.text = ""; // incoming markdown/html
|
|
@@ -49,69 +49,39 @@ export class Ai12zChatMessage {
|
|
|
49
49
|
}
|
|
50
50
|
componentWillLoad() {
|
|
51
51
|
var _a, _b;
|
|
52
|
+
this.loadScriptsSequentially();
|
|
53
|
+
// Adopt customCSS in this shadow root using the shared CSSStyleSheet
|
|
54
|
+
// already constructed by the parent knowledge-box (zero extra fetches).
|
|
52
55
|
if ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.customCSS) {
|
|
53
|
-
|
|
56
|
+
adoptStyleSheet(this.kbSettings.customCSS, this.el.shadowRoot);
|
|
54
57
|
}
|
|
55
58
|
if ((_b = this.kbSettings) === null || _b === void 0 ? void 0 : _b.customJS) {
|
|
56
|
-
|
|
59
|
+
loadScriptOnce(this.kbSettings.customJS, this.el.shadowRoot);
|
|
57
60
|
}
|
|
58
|
-
this.loadScriptsSequentially();
|
|
59
61
|
}
|
|
60
62
|
componentDidLoad() {
|
|
61
|
-
//
|
|
63
|
+
// Initialise the ai12z global exactly once; never overwrite an existing value.
|
|
62
64
|
if (!window["ai12z"]) {
|
|
63
65
|
window["ai12z"] = {};
|
|
64
66
|
}
|
|
65
67
|
const ai12zHeading = document.createElement("script");
|
|
66
|
-
ai12zHeading.text = `
|
|
67
|
-
var ai12zChat = window["ai12z"] = {}
|
|
68
|
-
`;
|
|
69
|
-
document.head.appendChild(ai12zHeading);
|
|
68
|
+
ai12zHeading.text = `var ai12zChat = window["ai12z"] = {}`;
|
|
70
69
|
this.el.shadowRoot.appendChild(ai12zHeading);
|
|
71
70
|
this.checkOverflow();
|
|
72
|
-
this.injectCustomAssets();
|
|
73
|
-
}
|
|
74
|
-
injectCustomAssets() {
|
|
75
|
-
var _a, _b;
|
|
76
|
-
if ((_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.customCSS) {
|
|
77
|
-
insertStyles(this.kbSettings.customCSS, this.el);
|
|
78
|
-
}
|
|
79
|
-
if ((_b = this.kbSettings) === null || _b === void 0 ? void 0 : _b.customJS) {
|
|
80
|
-
this.loadScript(this.kbSettings.customJS).catch(err => console.warn('customJS load failed:', err));
|
|
81
|
-
}
|
|
82
71
|
}
|
|
83
72
|
async loadScriptsSequentially() {
|
|
84
73
|
try {
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await
|
|
89
|
-
|
|
90
|
-
await
|
|
91
|
-
// 6. Load Survey UI
|
|
92
|
-
await this.loadScript(`${this.surveyCDNPath}/survey-js-ui@2.3.4/survey-js-ui.min.js`);
|
|
93
|
-
// console.log("All Survey.js scripts loaded successfully")
|
|
74
|
+
// Survey.js scripts are loaded into shadowRoot exactly once
|
|
75
|
+
// (loadScriptOnce deduplicates across all component instances).
|
|
76
|
+
await loadScriptOnce(`${this.surveyCDNPath}/survey-core@2.3.4/survey.core.min.js`, this.el.shadowRoot);
|
|
77
|
+
await loadScriptOnce(`${this.surveyCDNPath}/survey-core@2.3.4/survey.i18n.min.js`, this.el.shadowRoot);
|
|
78
|
+
await loadScriptOnce(`${this.surveyCDNPath}/survey-core@2.3.4/themes/index.min.js`, this.el.shadowRoot);
|
|
79
|
+
await loadScriptOnce(`${this.surveyCDNPath}/survey-js-ui@2.3.4/survey-js-ui.min.js`, this.el.shadowRoot);
|
|
94
80
|
}
|
|
95
81
|
catch (error) {
|
|
96
82
|
console.error("Failed to load Survey.js scripts:", error);
|
|
97
83
|
}
|
|
98
84
|
}
|
|
99
|
-
loadScript(src) {
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
if (document.querySelector(`script[src="${src}"]`)) {
|
|
102
|
-
resolve();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const script = document.createElement("script");
|
|
106
|
-
script.src = src;
|
|
107
|
-
script.async = false;
|
|
108
|
-
script.onload = () => resolve();
|
|
109
|
-
script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
|
|
110
|
-
// Load in document head for global access
|
|
111
|
-
// document.head.appendChild(script)
|
|
112
|
-
this.el.shadowRoot.appendChild(script);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
85
|
onTextChange() {
|
|
116
86
|
// if (!this.isExpanded && !this.streaming) {
|
|
117
87
|
// this.updateCollapsedHeight();
|
|
@@ -179,9 +149,9 @@ export class Ai12zChatMessage {
|
|
|
179
149
|
render() {
|
|
180
150
|
var _a, _b, _c, _d;
|
|
181
151
|
const lineClamp = (_b = (_a = this.kbSettings) === null || _a === void 0 ? void 0 : _a.numberOfLines) !== null && _b !== void 0 ? _b : 10;
|
|
182
|
-
return (h("div", { key: '
|
|
152
|
+
return (h("div", { key: '54f51ffb7c06bbb20fc1088c0fb63a8669d7ba45', class: "chat-message" }, h("div", { key: '281bc75361bcfadb4611eefeb9697d525b9e2d27', ref: (el) => this.messageRef = el, class: { 'message-text': true, "custom-line-clamp": !this.isExpanded && !this.isCollapsing && this.showButton }, style: {
|
|
183
153
|
"--line-clamp": `${lineClamp}`,
|
|
184
|
-
}, innerHTML: this.text, onClick: this.showButton ? this.toggleExpand : undefined }), !this.isExpanded && this.showButton && this.canExpand && h("div", { key: '
|
|
154
|
+
}, innerHTML: this.text, onClick: this.showButton ? this.toggleExpand : undefined }), !this.isExpanded && this.showButton && this.canExpand && h("div", { key: 'd6e262dbca0934b97fafb3dd7723b3b9333d8e10', class: "fade-overlay" }), this.showButton && this.canExpand && h("button", { key: 'e1e711b71656763ecdeb1cb6f73166528f023914', class: "show-more-btn", onClick: this.toggleExpand }, this.isExpanded ? (((_c = this.kbSettings) === null || _c === void 0 ? void 0 : _c.showLessButtonLabel) || "Show less") : (((_d = this.kbSettings) === null || _d === void 0 ? void 0 : _d.showMoreButtonLabel) || "Show more"), this.isExpanded ? h("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, h("polyline", { points: "6 9 12 15 18 9" })) : h("svg", { width: "1em", height: "1em", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, h("polyline", { points: "18 15 12 9 6 15" })))));
|
|
185
155
|
}
|
|
186
156
|
static get is() { return "ai12z-chat-message"; }
|
|
187
157
|
static get encapsulation() { return "shadow"; }
|