@alan-ai/alan-sdk-web 1.8.126 → 1.8.128
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/alan_lib.js +234 -46
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -374,16 +374,36 @@
|
|
|
374
374
|
function isProjectIdValid(projectId) {
|
|
375
375
|
return projectId.match(/^[A-Z0-9]{64}\/(prod|stage|testing)$/gi);
|
|
376
376
|
}
|
|
377
|
+
|
|
378
|
+
function parseHostWithQueryString(host) {
|
|
379
|
+
var baseURL = config.baseURL;
|
|
380
|
+
var queryString = '';
|
|
381
|
+
|
|
382
|
+
if (host) {
|
|
383
|
+
var qIndex = host.indexOf('?');
|
|
384
|
+
if (qIndex >= 0) {
|
|
385
|
+
queryString = host.substring(qIndex);
|
|
386
|
+
baseURL = "wss://" + host.substring(0, qIndex);
|
|
387
|
+
} else {
|
|
388
|
+
baseURL = "wss://" + host;
|
|
389
|
+
}
|
|
390
|
+
} else if (config.baseURL.indexOf('?') >= 0) {
|
|
391
|
+
var qIndex = config.baseURL.indexOf('?');
|
|
392
|
+
queryString = config.baseURL.substring(qIndex);
|
|
393
|
+
baseURL = config.baseURL.substring(0, qIndex);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return { baseURL: baseURL, queryString: queryString };
|
|
397
|
+
}
|
|
377
398
|
|
|
378
399
|
function connectProject(projectId, auth, host, mode, ext) {
|
|
379
400
|
var connect = new ConnectionWrapper();
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
401
|
+
var parsed = parseHostWithQueryString(host);
|
|
402
|
+
|
|
383
403
|
connect._config.projectId = projectId;
|
|
384
404
|
connect._config.codec = config.codec;
|
|
385
405
|
connect._config.version = config.version;
|
|
386
|
-
connect._config.url =
|
|
406
|
+
connect._config.url = parsed.baseURL + "/ws_project/" + projectId + parsed.queryString;
|
|
387
407
|
|
|
388
408
|
if (!isProjectIdValid(projectId)) {
|
|
389
409
|
throw new Error("Wrong projectId was provided: ", projectId);
|
|
@@ -422,13 +442,12 @@
|
|
|
422
442
|
|
|
423
443
|
function connectProjectTest(projectId, auth, host, mode, ext) {
|
|
424
444
|
var connect = new ConnectionWrapper();
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}
|
|
445
|
+
var parsed = parseHostWithQueryString(host);
|
|
446
|
+
|
|
428
447
|
connect._config.projectId = projectId;
|
|
429
448
|
connect._config.codec = config.codec;
|
|
430
449
|
connect._config.version = config.version;
|
|
431
|
-
connect._config.url =
|
|
450
|
+
connect._config.url = parsed.baseURL + "/ws_project/" + projectId + parsed.queryString;
|
|
432
451
|
|
|
433
452
|
if (!isProjectIdValid(projectId)) {
|
|
434
453
|
throw new Error("Wrong projectId was provided");
|
|
@@ -96973,6 +96992,7 @@
|
|
|
96973
96992
|
docked: false,
|
|
96974
96993
|
options: null,
|
|
96975
96994
|
maxCharactersCount: 2e4,
|
|
96995
|
+
maxQuestionsCount: 5,
|
|
96976
96996
|
loaderTimeoutMs: 18e5,
|
|
96977
96997
|
defaults: {
|
|
96978
96998
|
minChatWidth: 250,
|
|
@@ -97235,7 +97255,6 @@
|
|
|
97235
97255
|
// alan_btn/src/textChat/helpers/getMsgReqId.ts
|
|
97236
97256
|
function getMsgReqId(msg) {
|
|
97237
97257
|
return msg.reqId || msg?.ctx?.reqId;
|
|
97238
|
-
;
|
|
97239
97258
|
}
|
|
97240
97259
|
function getMsgResponseId(msg) {
|
|
97241
97260
|
return msg.responseId || msg?.ctx?.responseId || msg?.ctx?.resId;
|
|
@@ -97244,12 +97263,13 @@
|
|
|
97244
97263
|
// alan_btn/src/textChat/helpers/getMsgLoader.ts
|
|
97245
97264
|
var DEFAULT_INTERIM_MESSAGE = "Thinking...";
|
|
97246
97265
|
var STOP_RESPONSE_ICON_CLASS = "alan-btn__chat-incomming-msg-loader-icon";
|
|
97266
|
+
var INCOMMING_MSG_LOADER_ICON_HOLDER_CLASS = "alan-btn__chat-incomming-msg-loader-icon-holder";
|
|
97247
97267
|
function getMsgLoaderWrapper(content) {
|
|
97248
97268
|
return `<div class="alan-btn__chat-incomming-msg-wrapper">${content}</div>`;
|
|
97249
97269
|
}
|
|
97250
97270
|
function getMsgLoader(textChatOptions, inTop = false) {
|
|
97251
97271
|
const icon = textChatOptions?.bubbles?.waitingResponse?.icon?.svg || chatIcons.msgLoader;
|
|
97252
|
-
return `<span class="
|
|
97272
|
+
return `<span class="${INCOMMING_MSG_LOADER_ICON_HOLDER_CLASS} ${inTop ? "" : "alan-btn__bottom-loader"}">
|
|
97253
97273
|
<span class="${STOP_RESPONSE_ICON_CLASS}">${icon}</span>
|
|
97254
97274
|
</span>`;
|
|
97255
97275
|
}
|
|
@@ -99776,6 +99796,9 @@
|
|
|
99776
99796
|
user-select: text;
|
|
99777
99797
|
overflow: hidden;
|
|
99778
99798
|
}`;
|
|
99799
|
+
keyFrames += getStyleSheetMarker() + `.alan-btn__chat-response.without-content {
|
|
99800
|
+
display: none!important;
|
|
99801
|
+
}`;
|
|
99779
99802
|
keyFrames += getStyleSheetMarker() + `.alan-btn__chat-response.alan-incoming-msg {
|
|
99780
99803
|
max-width: 100%;
|
|
99781
99804
|
${waitingResponseBubbleLayout === "loader-and-label-wo-bubble" ? `padding: ${getPaddingProp(responseBubbleTopPadding, 0, responseBubbleBottomPadding, 0)};
|
|
@@ -100568,6 +100591,7 @@
|
|
|
100568
100591
|
white-space: nowrap;
|
|
100569
100592
|
overflow: hidden;
|
|
100570
100593
|
text-overflow: ellipsis;
|
|
100594
|
+
pointer-events: none;
|
|
100571
100595
|
}`;
|
|
100572
100596
|
keyFrames += styleSheetMarker + `.alan-btn__chat-incomming-msg-loader-label-default {
|
|
100573
100597
|
position: relative;
|
|
@@ -102338,19 +102362,21 @@ code.hljs {
|
|
|
102338
102362
|
}
|
|
102339
102363
|
return pathSegments.join(" > ");
|
|
102340
102364
|
}
|
|
102341
|
-
function collectScrollableElementStates() {
|
|
102342
|
-
if (typeof
|
|
102365
|
+
function collectScrollableElementStates(doc2 = document) {
|
|
102366
|
+
if (typeof doc2 === "undefined") {
|
|
102343
102367
|
return [];
|
|
102344
102368
|
}
|
|
102369
|
+
const win = doc2.defaultView || window;
|
|
102370
|
+
const HTMLElementClass = win.HTMLElement;
|
|
102345
102371
|
const elements = /* @__PURE__ */ new Set();
|
|
102346
|
-
|
|
102347
|
-
if (
|
|
102348
|
-
if (
|
|
102349
|
-
if (
|
|
102372
|
+
doc2.querySelectorAll("*").forEach((el) => elements.add(el));
|
|
102373
|
+
if (doc2.body) elements.add(doc2.body);
|
|
102374
|
+
if (doc2.documentElement) elements.add(doc2.documentElement);
|
|
102375
|
+
if (doc2.scrollingElement) elements.add(doc2.scrollingElement);
|
|
102350
102376
|
const scrollableStates = [];
|
|
102351
102377
|
const overflowRegex = /(auto|scroll|overlay)/i;
|
|
102352
102378
|
elements.forEach((element) => {
|
|
102353
|
-
if (!(element instanceof
|
|
102379
|
+
if (!(element instanceof HTMLElementClass)) {
|
|
102354
102380
|
return;
|
|
102355
102381
|
}
|
|
102356
102382
|
const scrollHeight = element.scrollHeight;
|
|
@@ -102360,10 +102386,10 @@ code.hljs {
|
|
|
102360
102386
|
if (clientHeight === 0 && clientWidth === 0) {
|
|
102361
102387
|
return;
|
|
102362
102388
|
}
|
|
102363
|
-
const computedStyle =
|
|
102389
|
+
const computedStyle = win.getComputedStyle(element);
|
|
102364
102390
|
const overflowY = computedStyle.overflowY;
|
|
102365
102391
|
const overflowX = computedStyle.overflowX;
|
|
102366
|
-
const isRootElement = element ===
|
|
102392
|
+
const isRootElement = element === doc2.body || element === doc2.documentElement || element === doc2.scrollingElement;
|
|
102367
102393
|
const canScrollVertically = scrollHeight - clientHeight > 1;
|
|
102368
102394
|
const canScrollHorizontally = scrollWidth - clientWidth > 1;
|
|
102369
102395
|
const allowsVerticalScroll = isRootElement || overflowRegex.test(overflowY);
|
|
@@ -102379,17 +102405,41 @@ code.hljs {
|
|
|
102379
102405
|
});
|
|
102380
102406
|
return scrollableStates;
|
|
102381
102407
|
}
|
|
102408
|
+
var CROSS_ORIGIN_IFRAME_CLASS = "alan-iframe-cross-origin";
|
|
102382
102409
|
async function collectIframeContent() {
|
|
102383
102410
|
const iframes = Array.from(document.querySelectorAll("iframe"));
|
|
102384
102411
|
if (iframes.length === 0) {
|
|
102385
102412
|
return [];
|
|
102386
102413
|
}
|
|
102414
|
+
iframes.forEach((iframe, index3) => {
|
|
102415
|
+
if (!iframe.id) {
|
|
102416
|
+
iframe.id = `alan-iframe-${index3}`;
|
|
102417
|
+
}
|
|
102418
|
+
});
|
|
102419
|
+
const directResults = [];
|
|
102420
|
+
const crossOriginIframes = [];
|
|
102421
|
+
for (const iframe of iframes) {
|
|
102422
|
+
try {
|
|
102423
|
+
const doc2 = iframe.contentDocument;
|
|
102424
|
+
if (doc2 && doc2.documentElement) {
|
|
102425
|
+
const clone3 = doc2.documentElement.cloneNode(true);
|
|
102426
|
+
clone3.querySelectorAll("script").forEach((s) => s.remove());
|
|
102427
|
+
directResults.push({ id: iframe.id, html: clone3.outerHTML });
|
|
102428
|
+
} else {
|
|
102429
|
+
iframe.classList.add(CROSS_ORIGIN_IFRAME_CLASS);
|
|
102430
|
+
crossOriginIframes.push(iframe);
|
|
102431
|
+
}
|
|
102432
|
+
} catch (e) {
|
|
102433
|
+
iframe.classList.add(CROSS_ORIGIN_IFRAME_CLASS);
|
|
102434
|
+
crossOriginIframes.push(iframe);
|
|
102435
|
+
}
|
|
102436
|
+
}
|
|
102437
|
+
if (crossOriginIframes.length === 0) {
|
|
102438
|
+
return directResults;
|
|
102439
|
+
}
|
|
102387
102440
|
return new Promise((resolve) => {
|
|
102388
102441
|
const responses = /* @__PURE__ */ new Map();
|
|
102389
|
-
const expectedIds =
|
|
102390
|
-
iframes.forEach((iframe, index3) => {
|
|
102391
|
-
expectedIds.add(iframe.id);
|
|
102392
|
-
});
|
|
102442
|
+
const expectedIds = new Set(crossOriginIframes.map((iframe) => iframe.id));
|
|
102393
102443
|
const messageHandler = (event) => {
|
|
102394
102444
|
if (event.data && event.data.source === "alan-chat-iframe" && event.data.type === "alan-iframe-content-response") {
|
|
102395
102445
|
const { iframeId, html: html5 } = event.data;
|
|
@@ -102397,14 +102447,16 @@ code.hljs {
|
|
|
102397
102447
|
responses.set(iframeId, html5);
|
|
102398
102448
|
if (responses.size === expectedIds.size) {
|
|
102399
102449
|
window.removeEventListener("message", messageHandler);
|
|
102400
|
-
|
|
102401
|
-
|
|
102450
|
+
resolve([
|
|
102451
|
+
...directResults,
|
|
102452
|
+
...Array.from(responses.entries()).map(([id, html6]) => ({ id, html: html6, crossOrigin: true }))
|
|
102453
|
+
]);
|
|
102402
102454
|
}
|
|
102403
102455
|
}
|
|
102404
102456
|
}
|
|
102405
102457
|
};
|
|
102406
102458
|
window.addEventListener("message", messageHandler);
|
|
102407
|
-
|
|
102459
|
+
crossOriginIframes.forEach((iframe) => {
|
|
102408
102460
|
try {
|
|
102409
102461
|
if (iframe.contentWindow) {
|
|
102410
102462
|
iframe.contentWindow.postMessage({
|
|
@@ -102419,23 +102471,32 @@ code.hljs {
|
|
|
102419
102471
|
});
|
|
102420
102472
|
setTimeout(() => {
|
|
102421
102473
|
window.removeEventListener("message", messageHandler);
|
|
102422
|
-
|
|
102423
|
-
|
|
102424
|
-
|
|
102425
|
-
|
|
102426
|
-
|
|
102474
|
+
resolve([
|
|
102475
|
+
...directResults,
|
|
102476
|
+
...Array.from(expectedIds).map((id) => ({
|
|
102477
|
+
id,
|
|
102478
|
+
html: responses.get(id) || "",
|
|
102479
|
+
crossOrigin: true
|
|
102480
|
+
}))
|
|
102481
|
+
]);
|
|
102427
102482
|
}, IFRAME_CONTENT_TIMEOUT_MS);
|
|
102428
102483
|
});
|
|
102429
102484
|
}
|
|
102430
102485
|
function replaceIframesWithSrcDoc(page, iframeContents, visibilityMap) {
|
|
102431
|
-
const contentMap = new Map(iframeContents.map((item) => [item.id, item
|
|
102432
|
-
const iframes = page.querySelectorAll("iframe
|
|
102486
|
+
const contentMap = new Map(iframeContents.map((item) => [item.id, item]));
|
|
102487
|
+
const iframes = page.querySelectorAll("iframe");
|
|
102433
102488
|
iframes.forEach((iframe) => {
|
|
102434
102489
|
const iframeId = iframe.id;
|
|
102435
|
-
const
|
|
102436
|
-
if (
|
|
102490
|
+
const entry = contentMap.get(iframeId);
|
|
102491
|
+
if (!entry) {
|
|
102492
|
+
return;
|
|
102493
|
+
}
|
|
102494
|
+
if (entry.crossOrigin) {
|
|
102495
|
+
iframe.classList.add(CROSS_ORIGIN_IFRAME_CLASS);
|
|
102496
|
+
}
|
|
102497
|
+
if (entry.html && visibilityMap.get(iframeId)) {
|
|
102437
102498
|
iframe.removeAttribute("src");
|
|
102438
|
-
iframe.setAttribute("srcdoc",
|
|
102499
|
+
iframe.setAttribute("srcdoc", entry.html);
|
|
102439
102500
|
}
|
|
102440
102501
|
});
|
|
102441
102502
|
}
|
|
@@ -102446,6 +102507,14 @@ code.hljs {
|
|
|
102446
102507
|
if (rect.bottom <= 0 || rect.top >= viewportHeight || rect.right <= 0 || rect.left >= viewportWidth) {
|
|
102447
102508
|
return false;
|
|
102448
102509
|
}
|
|
102510
|
+
let node = element;
|
|
102511
|
+
while (node) {
|
|
102512
|
+
const style = window.getComputedStyle(node);
|
|
102513
|
+
if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0") {
|
|
102514
|
+
return false;
|
|
102515
|
+
}
|
|
102516
|
+
node = node.parentElement;
|
|
102517
|
+
}
|
|
102449
102518
|
let parent3 = element.parentElement;
|
|
102450
102519
|
while (parent3) {
|
|
102451
102520
|
const style = window.getComputedStyle(parent3);
|
|
@@ -102542,6 +102611,7 @@ code.hljs {
|
|
|
102542
102611
|
if (!document.getElementsByTagName("html")[0]) {
|
|
102543
102612
|
throw new Error("HTML document not available");
|
|
102544
102613
|
}
|
|
102614
|
+
const iframeContents = await collectIframeContent();
|
|
102545
102615
|
const page = document.createElement("html");
|
|
102546
102616
|
page.innerHTML = document.getElementsByTagName("html")[0].innerHTML;
|
|
102547
102617
|
const scripts = page.getElementsByTagName("script");
|
|
@@ -102552,7 +102622,6 @@ code.hljs {
|
|
|
102552
102622
|
}
|
|
102553
102623
|
}
|
|
102554
102624
|
const pageContent = page.outerHTML;
|
|
102555
|
-
const iframeContents = await collectIframeContent();
|
|
102556
102625
|
const liveIframes = Array.from(document.querySelectorAll("iframe"));
|
|
102557
102626
|
const visibilityMap = /* @__PURE__ */ new Map();
|
|
102558
102627
|
liveIframes.forEach((iframe) => {
|
|
@@ -102574,6 +102643,10 @@ code.hljs {
|
|
|
102574
102643
|
if (!window.tutorProject) {
|
|
102575
102644
|
return;
|
|
102576
102645
|
}
|
|
102646
|
+
const animatedElements = page.querySelectorAll(".alan-btn__chat-response.animated, .alan-btn__chat-request.animated");
|
|
102647
|
+
animatedElements.forEach((el) => {
|
|
102648
|
+
el.classList.remove("animated");
|
|
102649
|
+
});
|
|
102577
102650
|
const params = {
|
|
102578
102651
|
html: page.outerHTML,
|
|
102579
102652
|
url: window.location.href,
|
|
@@ -102591,11 +102664,29 @@ code.hljs {
|
|
|
102591
102664
|
return;
|
|
102592
102665
|
}
|
|
102593
102666
|
if (uiState10.pageState?.screenshot?.enabled) {
|
|
102667
|
+
const iframeScrollStates = [];
|
|
102668
|
+
for (const iframe of liveIframes) {
|
|
102669
|
+
if (!visibilityMap.get(iframe.id)) continue;
|
|
102670
|
+
try {
|
|
102671
|
+
const iframeDoc = iframe.contentDocument;
|
|
102672
|
+
if (iframeDoc) {
|
|
102673
|
+
const states = collectScrollableElementStates(iframeDoc);
|
|
102674
|
+
states.forEach((s) => iframeScrollStates.push({
|
|
102675
|
+
...s,
|
|
102676
|
+
path: `#${iframe.id} >> ${s.path}`
|
|
102677
|
+
}));
|
|
102678
|
+
}
|
|
102679
|
+
} catch (e) {
|
|
102680
|
+
}
|
|
102681
|
+
}
|
|
102594
102682
|
params.screenshot_data = {
|
|
102595
102683
|
baseHref: document.baseURI,
|
|
102596
102684
|
width: window.innerWidth,
|
|
102597
102685
|
height: window.innerHeight,
|
|
102598
|
-
scrollStates:
|
|
102686
|
+
scrollStates: [
|
|
102687
|
+
...collectScrollableElementStates(),
|
|
102688
|
+
...iframeScrollStates
|
|
102689
|
+
]
|
|
102599
102690
|
};
|
|
102600
102691
|
}
|
|
102601
102692
|
window.tutorProject.call("syncPageState", params);
|
|
@@ -109360,7 +109451,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
109360
109451
|
return match ? match[0] : null;
|
|
109361
109452
|
}
|
|
109362
109453
|
function extractFunction(code2, functionName) {
|
|
109363
|
-
const ast = parse11(code2, { ecmaVersion:
|
|
109454
|
+
const ast = parse11(code2, { ecmaVersion: 2022 });
|
|
109364
109455
|
for (const node of ast.body) {
|
|
109365
109456
|
if (node.type === "FunctionDeclaration" && node.id.name === functionName) {
|
|
109366
109457
|
return generate2(node);
|
|
@@ -109547,6 +109638,54 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
109547
109638
|
}
|
|
109548
109639
|
} catch (error) {
|
|
109549
109640
|
console.error(`Failed to fetch or process iframe from ${srcUrl}:`, error);
|
|
109641
|
+
const errorMessage = error?.message || error?.toString() || "Unknown error";
|
|
109642
|
+
const errorHtml = `
|
|
109643
|
+
<!DOCTYPE html>
|
|
109644
|
+
<html>
|
|
109645
|
+
<head>
|
|
109646
|
+
<meta charset="UTF-8">
|
|
109647
|
+
<style>
|
|
109648
|
+
body {
|
|
109649
|
+
font-family: Arial, sans-serif;
|
|
109650
|
+
padding: 20px;
|
|
109651
|
+
background-color: #fff3cd;
|
|
109652
|
+
color: #856404;
|
|
109653
|
+
margin: 0;
|
|
109654
|
+
}
|
|
109655
|
+
.error-container {
|
|
109656
|
+
border: 1px solid #ffc107;
|
|
109657
|
+
border-radius: 4px;
|
|
109658
|
+
padding: 15px;
|
|
109659
|
+
background-color: #fff;
|
|
109660
|
+
}
|
|
109661
|
+
.error-title {
|
|
109662
|
+
font-weight: bold;
|
|
109663
|
+
margin-bottom: 10px;
|
|
109664
|
+
font-size: 16px;
|
|
109665
|
+
}
|
|
109666
|
+
.error-details {
|
|
109667
|
+
font-size: 14px;
|
|
109668
|
+
word-break: break-word;
|
|
109669
|
+
}
|
|
109670
|
+
.error-url {
|
|
109671
|
+
margin-top: 10px;
|
|
109672
|
+
font-size: 12px;
|
|
109673
|
+
color: #666;
|
|
109674
|
+
}
|
|
109675
|
+
</style>
|
|
109676
|
+
</head>
|
|
109677
|
+
<body>
|
|
109678
|
+
<div class="error-container">
|
|
109679
|
+
<div class="error-title">\u26A0\uFE0F Failed to collect iframe content</div>
|
|
109680
|
+
<div class="error-details">${errorMessage.replace(/</g, "<").replace(/>/g, ">")}</div>
|
|
109681
|
+
<div class="error-url">Source: ${srcUrl}</div>
|
|
109682
|
+
</div>
|
|
109683
|
+
</body>
|
|
109684
|
+
</html>
|
|
109685
|
+
`;
|
|
109686
|
+
iframe.removeAttribute("src");
|
|
109687
|
+
iframe.setAttribute("srcdoc", errorHtml);
|
|
109688
|
+
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
|
|
109550
109689
|
}
|
|
109551
109690
|
}));
|
|
109552
109691
|
const iframeResizerCode = 'const v=()=>typeof window<"u",C=()=>{try{return window.self!==window.top}catch{return!0}},w=e=>e instanceof HTMLIFrameElement,z=e=>{"complete"===window.document.readyState?e():window.addEventListener("load",e,{once:!0})},B=(e,t)=>{t(),e.addEventListener("load",t,{once:!0})},k=(e,t)=>{const n="complete"===e.contentWindow?.document.readyState;return"about:blank"!==e.src&&"about:blank"!==e.contentWindow?.location.href&&n?t():e.addEventListener("load",t,{once:!0})},W=()=>({offsetSize:0,checkOrigin:!0,enableLegacyLibSupport:!1});async function A(e){try{return"about:blank"===e.contentDocument?.URL?new Promise((t=>{e.addEventListener("load",(()=>t(null!==e.contentDocument)),{once:!0})})):null!==e.contentDocument}catch{return!1}}const P=e=>{try{const t=new URL(e.src).origin;if("about:blank"!==t)return t}catch{}return null},H=e=>(Object.keys(e).forEach((t=>{void 0===e[t]&&delete e[t]})),e),I=e=>{const{height:t,width:n}=e.getBoundingClientRect();return{height:Math.ceil(t),width:Math.ceil(n)}},l=(e,t)=>e?t?e.querySelector(t):e.documentElement:null,O=(e,t)=>{e&&(t.bodyPadding&&(e.body.style.padding=t.bodyPadding),t.bodyMargin&&(e.body.style.margin=t.bodyMargin))},b=e=>e<=100?100:e<=120?1e3:1e4,x=()=>"[iFrameSizer]ID:0:false:false:32:true:true::auto:::0:false:child:auto:true:::true:::false";function F(e){if("string"!=typeof e.data||!e.data.startsWith("[iFrameSizer]")||!e.data.endsWith("mutationObserver")&&!e.data.endsWith("resizeObserver"))return null;const[t,n]=e.data.split(":"),i=+n;return i>0?i:null}const p=V();let m=[];const Z=async(e,t)=>{if(!v())return[];const n={...W(),...H(e??{})},i=N(t),r=U(n,i);return Promise.all(i.map((async e=>{const t={iframe:e,settings:n,interactionState:{isHovered:!1},initContext:{isInitialized:!1,retryAttempts:0}},{unsubscribe:i,resize:o}=await $(t,r);return m.push(t),{unsubscribe:()=>{i(),m=m.filter((t=>t.iframe!==e))},resize:o}})))};function N(e){return"string"==typeof e?Array.from(document.querySelectorAll(e)).filter(w):e?w(e)?[e]:[]:Array.from(document.getElementsByTagName("iframe"))}function U(e,t){if(Array.isArray(e.checkOrigin))return e.checkOrigin;if(!e.checkOrigin)return[];const n=[];for(const e of t){const t=P(e);t&&n.push(t)}return n}async function $(e,t){const n=await A(e.iframe),{unsubscribe:i,resize:r}=n?_(e):q(e,t),o=G(e);return{unsubscribe:()=>{i(),o()},resize:r}}function q(e,t){const{iframe:n,initContext:i,settings:{checkOrigin:r,enableLegacyLibSupport:o,targetElementSelector:s,bodyPadding:a,bodyMargin:c}}=e,d=i=>{const s="null"===i.origin,a=!r||s||t.includes(i.origin);if(n.contentWindow===i.source&&a){if("iframe-resized"===i.data?.type){const{height:t}=i.data;return void(t&&g({newHeight:t,registeredElement:e}))}if(o){const t=F(i);return void(null!==t&&g({newHeight:t,registeredElement:e}))}}};window.addEventListener("message",d);const u=o?x():{type:"iframe-child-init",targetElementSelector:s,bodyPadding:a,bodyMargin:c},l=()=>{B(n,(()=>n.contentWindow?.postMessage(u,"*"))),i.retryAttempts++,i.retryTimeoutId=window.setTimeout(l,b(i.retryAttempts))};return l(),{unsubscribe:()=>window.removeEventListener("message",d),resize:()=>{n.contentWindow?.postMessage({type:"iframe-get-child-dimensions"},"*")}}}function _(e){const{iframe:t,settings:n}=e,{targetElementSelector:i}=n;let r=0;const o=()=>{const e=l(t.contentDocument,i);if(!t.contentDocument||!e)return r++,setTimeout(o,b(r));O(t.contentDocument,n),p().observe(e)};return k(t,o),{unsubscribe:()=>{const e=l(t.contentDocument,i);e&&p().unobserve(e)},resize:()=>L(e)}}function G({iframe:e,interactionState:t,settings:n}){if(!n.onBeforeIframeResize&&!n.onIframeResize)return()=>{};const i=()=>{t.isHovered=!0},r=()=>{t.isHovered=!1};return e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",r),()=>{e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",r)}}function V(){let e=null;return()=>{if(!e){const t=({target:e})=>{const t=m.find((({iframe:t})=>t.contentDocument===e.ownerDocument));t&&L(t)};e=new ResizeObserver((e=>e.forEach(t)))}return e}}function L(e){const{iframe:t,settings:n}=e,i=l(t.contentDocument,n.targetElementSelector);if(!i)return;const{height:r}=I(i);r&&g({newHeight:r,registeredElement:e})}function g({registeredElement:e,newHeight:t}){const{iframe:n,settings:i,interactionState:r,initContext:o}=e;if(o.isInitialized||(o.isInitialized=!0,clearTimeout(o.retryTimeoutId)),!1===i.onBeforeIframeResize?.({iframe:n,interactionState:{...r},settings:{...i},observedHeight:t}))return;const s=n.getBoundingClientRect(),a=t+i.offsetSize;if(n.style.height=`${a}px`,!i.onIframeResize)return;const c={iframe:n,settings:{...i},interactionState:{...r},previousRenderState:{rect:s},nextRenderState:{rect:n.getBoundingClientRect()}};i.onIframeResize(c)}const J=X();let R,h=!1;function K(){!v()||!C()||window.addEventListener("message",(e=>"iframe-child-init"===e.data?.type?z((()=>S(e))):"iframe-get-child-dimensions"===e.data?.type?z((()=>Q(e))):void 0))}function S(e,t=0){const{targetElementSelector:n,bodyPadding:i,bodyMargin:r}=e.data,o=l(document,n);if(h||window.parent!==e.source)return;if(!o)return setTimeout((()=>S(e,t+1)),b(t));O(document,{bodyMargin:r,bodyPadding:i}),R=n;const s=J();s.disconnect(),s.observe(o),h=!0}function Q(e){const t=l(document,R);!h||window.parent!==e.source||!t||E(t)}function X(){let e=null;return()=>(e||(e=new ResizeObserver((e=>{e[0].target&&E(e[0].target)}))),e)}K();const E=e=>{const{width:t,height:n}=I(e),i={type:"iframe-resized",width:t,height:n};window.parent.postMessage(i,"*")},j=({previousRenderState:e,nextRenderState:t,iframe:n})=>{document.activeElement===n&&window.scrollBy(0,t.rect.bottom-e.rect.bottom)}; window.iframeResizer={initialize :Z ,initializeChildListener:K,updateParentScrollOnResize:j};';
|
|
@@ -110827,7 +110966,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
110827
110966
|
// alan_btn/alan_btn.ts
|
|
110828
110967
|
(function(ns) {
|
|
110829
110968
|
const uiState10 = getUIState();
|
|
110830
|
-
const version2 = "alan-version.1.8.
|
|
110969
|
+
const version2 = "alan-version.1.8.128".replace("alan-version.", "");
|
|
110831
110970
|
uiState10.lib.version = version2;
|
|
110832
110971
|
window.alanLib = { version: version2 };
|
|
110833
110972
|
if (window.alanBtn) {
|
|
@@ -110870,6 +111009,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
110870
111009
|
var textChatMessages = [];
|
|
110871
111010
|
var canceledRequests = [];
|
|
110872
111011
|
var textChatScrollPosition = null;
|
|
111012
|
+
var questionInProgress = false;
|
|
110873
111013
|
var sentMessageInd = null;
|
|
110874
111014
|
var sentMessages = [];
|
|
110875
111015
|
const LOCAL_STORAGE_KEYS = {
|
|
@@ -111912,7 +112052,6 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
111912
112052
|
userAgent: navigator.userAgent,
|
|
111913
112053
|
appName: window.location.hostname
|
|
111914
112054
|
});
|
|
111915
|
-
console.time("Alan: receiving options time");
|
|
111916
112055
|
window.tutorProject.on("connectStatus", onConnectStatusChange);
|
|
111917
112056
|
window.tutorProject.on("options", onOptionsReceived);
|
|
111918
112057
|
window.tutorProject.on("scripts", onScriptsCb);
|
|
@@ -112609,7 +112748,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
112609
112748
|
}
|
|
112610
112749
|
}
|
|
112611
112750
|
function updateMsgLoaderIcons(textChatOptions) {
|
|
112612
|
-
document.querySelectorAll(
|
|
112751
|
+
document.querySelectorAll(`.${INCOMMING_MSG_LOADER_ICON_HOLDER_CLASS}`).forEach((el) => {
|
|
112613
112752
|
el.outerHTML = getMsgLoader(textChatOptions);
|
|
112614
112753
|
});
|
|
112615
112754
|
}
|
|
@@ -112621,7 +112760,6 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
112621
112760
|
}
|
|
112622
112761
|
function onOptionsReceived(data4) {
|
|
112623
112762
|
console.log("Alan: options received");
|
|
112624
|
-
console.timeEnd("Alan: receiving options time");
|
|
112625
112763
|
saveOptions(data4);
|
|
112626
112764
|
uiState10.textChat.notifications.enabled = data4?.web?.chatOptions?.textChat?.notifications?.enabled;
|
|
112627
112765
|
uiState10.textChat.chatExport.includeGraphInfo.enabled = data4?.web?.chatOptions?.textChat?.popup?.saveChatState?.includeGraphInfo?.enabled;
|
|
@@ -112630,6 +112768,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
112630
112768
|
uiState10.pageState.autoSync = data4?.web?.pageState?.autoSync;
|
|
112631
112769
|
uiState10.textChat.autocomplete.enabled = data4?.web?.chatOptions?.textChat?.textarea?.autocomplete?.enabled;
|
|
112632
112770
|
uiState10.textChat.maxCharactersCount = data4?.web?.chatOptions?.textChat?.textarea?.maxCharactersCount ? +data4?.web?.chatOptions?.textChat?.textarea?.maxCharactersCount : 2e4;
|
|
112771
|
+
uiState10.textChat.maxQuestionsCount = data4?.web?.chatOptions?.textChat?.textarea?.maxQuestionsCount ? +data4?.web?.chatOptions?.textChat?.textarea?.maxQuestionsCount : 5;
|
|
112633
112772
|
changeOptions(getOptionsByTheme(data4?.web, uiState10.currentTheme || options.theme));
|
|
112634
112773
|
saveResourcesUrl(data4);
|
|
112635
112774
|
insertResources(data4);
|
|
@@ -112687,6 +112826,9 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
|
|
|
112687
112826
|
console.info(`Alan: connected to ${dialogId !== getSavedDialogId() ? "new" : ""} dialog:
|
|
112688
112827
|
${dialogId}
|
|
112689
112828
|
${getSavedDialogId() || "-"} (prev. dialog)`);
|
|
112829
|
+
if (dialogId !== getSavedDialogId()) {
|
|
112830
|
+
questionInProgress = false;
|
|
112831
|
+
}
|
|
112690
112832
|
curDialogId = dialogId;
|
|
112691
112833
|
sentMessages = restoreSentMessages();
|
|
112692
112834
|
const prevUserId = getPrevUserId();
|
|
@@ -113502,7 +113644,7 @@ ${curDialogId}`);
|
|
|
113502
113644
|
if (msg?.suggestions?.length > 0) {
|
|
113503
113645
|
suggestionsHtml += renderSuggestions(msg.suggestions);
|
|
113504
113646
|
}
|
|
113505
|
-
msgHtml = `<div class="alan-btn__chat-inner-msg ${msg.type === "request" ? "alan-btn__chat-request" : "alan-btn__chat-response"} ${msg.images?.length > 0 ? "with-images" : ""} ${isMsgContainsTable(innerMsgPart) ? "with-table" : ""} ${isMsgContainsIFrame(innerMsgPart) ? "with-iframe" : ""}">${innerMsgPart}</div>${suggestionsHtml}`;
|
|
113647
|
+
msgHtml = `<div class="alan-btn__chat-inner-msg ${msg.text || msg.images?.length > 0 || msg?.links?.length > 0 ? "" : "without-content"} ${msg.type === "request" ? "alan-btn__chat-request" : "alan-btn__chat-response"} ${msg.images?.length > 0 ? "with-images" : ""} ${isMsgContainsTable(innerMsgPart) ? "with-table" : ""} ${isMsgContainsIFrame(innerMsgPart) ? "with-iframe" : ""}">${innerMsgPart}</div>${suggestionsHtml}`;
|
|
113506
113648
|
}
|
|
113507
113649
|
if (msg.name === "loading") {
|
|
113508
113650
|
const loaderId = `loading-msg-${guid()}`;
|
|
@@ -113577,6 +113719,9 @@ ${curDialogId}`);
|
|
|
113577
113719
|
if (innerEl.classList.contains("alan-hidden-loader")) {
|
|
113578
113720
|
innerEl.classList.remove("alan-hidden-loader");
|
|
113579
113721
|
}
|
|
113722
|
+
if (msg.text || msg.images?.length > 0 || msg.links?.length > 0) {
|
|
113723
|
+
innerEl.classList.remove("without-content");
|
|
113724
|
+
}
|
|
113580
113725
|
const updatedMsg = textChatMessages[msgInd];
|
|
113581
113726
|
innerEl.innerHTML = innerMsgPart;
|
|
113582
113727
|
if (withDetailedStatuses) {
|
|
@@ -113612,6 +113757,9 @@ ${curDialogId}`);
|
|
|
113612
113757
|
if (innerEl.classList.contains("alan-hidden-loader")) {
|
|
113613
113758
|
innerEl.classList.remove("alan-hidden-loader");
|
|
113614
113759
|
}
|
|
113760
|
+
if (msg.text || msg.images?.length > 0 || msg.links?.length > 0) {
|
|
113761
|
+
innerEl.classList.remove("without-content");
|
|
113762
|
+
}
|
|
113615
113763
|
const updatedMsg = textChatMessages[msgInd];
|
|
113616
113764
|
const imagesWrapper = innerEl.querySelector(".alan-btn__chat-response-imgs-wrapper");
|
|
113617
113765
|
if (updatedMsg.images?.length > 0 && imagesWrapper) {
|
|
@@ -113714,6 +113862,11 @@ ${curDialogId}`);
|
|
|
113714
113862
|
enableTextareaInTheChat();
|
|
113715
113863
|
}
|
|
113716
113864
|
}
|
|
113865
|
+
if (msg.ctx?.final === true && msg.type === "response") {
|
|
113866
|
+
if (msg.type === "response") {
|
|
113867
|
+
enableTextareaInTheChat();
|
|
113868
|
+
}
|
|
113869
|
+
}
|
|
113717
113870
|
manageSaveChatHistoryBtn();
|
|
113718
113871
|
}
|
|
113719
113872
|
function updateTextParts(textWrapperEl, updatedMsg) {
|
|
@@ -113819,6 +113972,7 @@ ${curDialogId}`);
|
|
|
113819
113972
|
if (options.onEvent) {
|
|
113820
113973
|
options.onEvent({ name: "textChatCleared" });
|
|
113821
113974
|
}
|
|
113975
|
+
questionInProgress = false;
|
|
113822
113976
|
window.alanIframes = {};
|
|
113823
113977
|
clearChatHistoryStorage();
|
|
113824
113978
|
clearDOMChat();
|
|
@@ -113916,22 +114070,37 @@ ${curDialogId}`);
|
|
|
113916
114070
|
}
|
|
113917
114071
|
}
|
|
113918
114072
|
}
|
|
114073
|
+
function getActiveQuestionsCount() {
|
|
114074
|
+
return document.querySelectorAll(
|
|
114075
|
+
`.alan-btn__chat-msg-holder:not(.alan-hide-msg-immidiatelly) .${INCOMMING_MSG_LOADER_ICON_HOLDER_CLASS}`
|
|
114076
|
+
).length + (questionInProgress ? 1 : 0);
|
|
114077
|
+
}
|
|
113919
114078
|
async function _sendText(text5) {
|
|
113920
114079
|
manageAutocompeteInChat();
|
|
113921
114080
|
var maxChars = uiState10.textChat.maxCharactersCount || 2e4;
|
|
114081
|
+
var maxQuestions = uiState10.textChat.maxQuestionsCount || 5;
|
|
113922
114082
|
if (text5?.length > maxChars) {
|
|
113923
114083
|
console.warn("Alan: message cannot be sent: maximum message limit exceeded.");
|
|
113924
114084
|
return;
|
|
113925
114085
|
}
|
|
114086
|
+
if (getActiveQuestionsCount() >= maxQuestions) {
|
|
114087
|
+
console.warn("Alan: message cannot be sent: maximum concurrent questions limit exceeded.");
|
|
114088
|
+
return;
|
|
114089
|
+
}
|
|
113926
114090
|
if (!canMsgBeSent()) {
|
|
113927
114091
|
console.warn("Alan: message cannot be sent. Model is not ready or connection is not established.");
|
|
113928
114092
|
return;
|
|
113929
114093
|
}
|
|
114094
|
+
if (getActiveQuestionsCount() >= maxQuestions) {
|
|
114095
|
+
disableTextareaInTheChat();
|
|
114096
|
+
}
|
|
113930
114097
|
var msg = { text: text5, type: "request", name: "text", tsInit: Date.now() };
|
|
113931
114098
|
sentMessageInd = null;
|
|
113932
114099
|
clearMessageProgressStatusInterval();
|
|
114100
|
+
questionInProgress = true;
|
|
113933
114101
|
var res = await sendText(text5);
|
|
113934
114102
|
msg = { ...msg, reqId: res.reqId };
|
|
114103
|
+
questionInProgress = false;
|
|
113935
114104
|
renderMessageInTextChat(msg);
|
|
113936
114105
|
renderMessageInTextChat({
|
|
113937
114106
|
type: "response",
|
|
@@ -113959,10 +114128,19 @@ ${curDialogId}`);
|
|
|
113959
114128
|
}
|
|
113960
114129
|
function enableTextareaInTheChat() {
|
|
113961
114130
|
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
113962
|
-
|
|
114131
|
+
var maxQuestions = uiState10.textChat.maxQuestionsCount || 5;
|
|
114132
|
+
if (getActiveQuestionsCount() < maxQuestions) {
|
|
114133
|
+
textareaHolderEl.classList.remove("alan-btn__inactive");
|
|
114134
|
+
}
|
|
113963
114135
|
clearTimeout(lastSendMsgTs);
|
|
113964
114136
|
lastSendMsgTs = null;
|
|
113965
114137
|
}
|
|
114138
|
+
function disableTextareaInTheChat() {
|
|
114139
|
+
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
114140
|
+
if (textareaHolderEl) {
|
|
114141
|
+
textareaHolderEl.classList.add("alan-btn__inactive");
|
|
114142
|
+
}
|
|
114143
|
+
}
|
|
113966
114144
|
function canMsgBeSent() {
|
|
113967
114145
|
if (!isModelReady || state === DISCONNECTED || state === OFFLINE) {
|
|
113968
114146
|
return false;
|
|
@@ -113974,6 +114152,7 @@ ${curDialogId}`);
|
|
|
113974
114152
|
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
113975
114153
|
var text5 = textareaEl.value;
|
|
113976
114154
|
var maxChars = uiState10.textChat.maxCharactersCount || 2e4;
|
|
114155
|
+
var maxQuestions = uiState10.textChat.maxQuestionsCount || 5;
|
|
113977
114156
|
if (lastSendMsgTs) {
|
|
113978
114157
|
console.warn("Alan: message cannot be sent: you are sending messages too fast. Please wait a moment before sending another message.");
|
|
113979
114158
|
return;
|
|
@@ -113982,6 +114161,10 @@ ${curDialogId}`);
|
|
|
113982
114161
|
console.warn("Alan: message cannot be sent: maximum message limit exceeded.");
|
|
113983
114162
|
return;
|
|
113984
114163
|
}
|
|
114164
|
+
if (getActiveQuestionsCount() >= maxQuestions) {
|
|
114165
|
+
console.warn("Alan: message cannot be sent: maximum concurrent questions limit exceeded.");
|
|
114166
|
+
return;
|
|
114167
|
+
}
|
|
113985
114168
|
if (!canMsgBeSent()) {
|
|
113986
114169
|
return;
|
|
113987
114170
|
}
|
|
@@ -113993,7 +114176,7 @@ ${curDialogId}`);
|
|
|
113993
114176
|
textareaEl.value = "";
|
|
113994
114177
|
previousTextValue = "";
|
|
113995
114178
|
_sendText(text5);
|
|
113996
|
-
|
|
114179
|
+
disableTextareaInTheChat();
|
|
113997
114180
|
textChatScrollPosition = null;
|
|
113998
114181
|
}, 1e3);
|
|
113999
114182
|
function getMsgElForMathJax(msgInd) {
|
|
@@ -114145,6 +114328,11 @@ ${curDialogId}`);
|
|
|
114145
114328
|
} else {
|
|
114146
114329
|
errEl.style.display = "block";
|
|
114147
114330
|
}
|
|
114331
|
+
if (getActiveQuestionsCount() >= uiState10.textChat.maxQuestionsCount) {
|
|
114332
|
+
disableTextareaInTheChat();
|
|
114333
|
+
} else {
|
|
114334
|
+
enableTextareaInTheChat();
|
|
114335
|
+
}
|
|
114148
114336
|
}
|
|
114149
114337
|
}
|
|
114150
114338
|
const resizeTextAreaDebounced = throttle(function() {
|