@alan-ai/alan-sdk-web 1.8.97 → 1.8.98
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 +123 -44
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -93426,6 +93426,76 @@ code.hljs {
|
|
|
93426
93426
|
viewportWidth: 0,
|
|
93427
93427
|
viewportHeight: 0
|
|
93428
93428
|
};
|
|
93429
|
+
function getDomPath(element) {
|
|
93430
|
+
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
93431
|
+
return "";
|
|
93432
|
+
}
|
|
93433
|
+
const pathSegments = [];
|
|
93434
|
+
let current2 = element;
|
|
93435
|
+
while (current2 && current2.nodeType === Node.ELEMENT_NODE) {
|
|
93436
|
+
let selector = current2.nodeName.toLowerCase();
|
|
93437
|
+
if (current2.id) {
|
|
93438
|
+
selector += `#${current2.id}`;
|
|
93439
|
+
pathSegments.unshift(selector);
|
|
93440
|
+
break;
|
|
93441
|
+
}
|
|
93442
|
+
let siblingIndex = 1;
|
|
93443
|
+
let sibling2 = current2.previousElementSibling;
|
|
93444
|
+
while (sibling2) {
|
|
93445
|
+
if (sibling2.nodeName === current2.nodeName) {
|
|
93446
|
+
siblingIndex++;
|
|
93447
|
+
}
|
|
93448
|
+
sibling2 = sibling2.previousElementSibling;
|
|
93449
|
+
}
|
|
93450
|
+
if (siblingIndex > 1) {
|
|
93451
|
+
selector += `:nth-of-type(${siblingIndex})`;
|
|
93452
|
+
}
|
|
93453
|
+
pathSegments.unshift(selector);
|
|
93454
|
+
current2 = current2.parentElement;
|
|
93455
|
+
}
|
|
93456
|
+
return pathSegments.join(" > ");
|
|
93457
|
+
}
|
|
93458
|
+
function collectScrollableElementStates() {
|
|
93459
|
+
if (typeof document === "undefined") {
|
|
93460
|
+
return [];
|
|
93461
|
+
}
|
|
93462
|
+
const elements = /* @__PURE__ */ new Set();
|
|
93463
|
+
document.querySelectorAll("*").forEach((el) => elements.add(el));
|
|
93464
|
+
if (document.body) elements.add(document.body);
|
|
93465
|
+
if (document.documentElement) elements.add(document.documentElement);
|
|
93466
|
+
if (document.scrollingElement) elements.add(document.scrollingElement);
|
|
93467
|
+
const scrollableStates = [];
|
|
93468
|
+
const overflowRegex = /(auto|scroll|overlay)/i;
|
|
93469
|
+
elements.forEach((element) => {
|
|
93470
|
+
if (!(element instanceof HTMLElement)) {
|
|
93471
|
+
return;
|
|
93472
|
+
}
|
|
93473
|
+
const scrollHeight = element.scrollHeight;
|
|
93474
|
+
const clientHeight = element.clientHeight;
|
|
93475
|
+
const scrollWidth = element.scrollWidth;
|
|
93476
|
+
const clientWidth = element.clientWidth;
|
|
93477
|
+
if (clientHeight === 0 && clientWidth === 0) {
|
|
93478
|
+
return;
|
|
93479
|
+
}
|
|
93480
|
+
const computedStyle = window.getComputedStyle(element);
|
|
93481
|
+
const overflowY = computedStyle.overflowY;
|
|
93482
|
+
const overflowX = computedStyle.overflowX;
|
|
93483
|
+
const isRootElement = element === document.body || element === document.documentElement || element === document.scrollingElement;
|
|
93484
|
+
const canScrollVertically = scrollHeight - clientHeight > 1;
|
|
93485
|
+
const canScrollHorizontally = scrollWidth - clientWidth > 1;
|
|
93486
|
+
const allowsVerticalScroll = isRootElement || overflowRegex.test(overflowY);
|
|
93487
|
+
const allowsHorizontalScroll = isRootElement || overflowRegex.test(overflowX);
|
|
93488
|
+
if (!(canScrollVertically && allowsVerticalScroll || canScrollHorizontally && allowsHorizontalScroll)) {
|
|
93489
|
+
return;
|
|
93490
|
+
}
|
|
93491
|
+
scrollableStates.push({
|
|
93492
|
+
path: getDomPath(element),
|
|
93493
|
+
scrollTop: element.scrollTop,
|
|
93494
|
+
scrollLeft: element.scrollLeft
|
|
93495
|
+
});
|
|
93496
|
+
});
|
|
93497
|
+
return scrollableStates;
|
|
93498
|
+
}
|
|
93429
93499
|
function generateContentHash(content) {
|
|
93430
93500
|
let hash = 0;
|
|
93431
93501
|
for (let i = 0; i < content.length; i++) {
|
|
@@ -93465,7 +93535,7 @@ code.hljs {
|
|
|
93465
93535
|
window.removeEventListener(ALAN_BTN_PAGE_SYNC_EVENT, listenForPageChanges);
|
|
93466
93536
|
}
|
|
93467
93537
|
}
|
|
93468
|
-
async function attemptPageStateSync(onSendCb, forceUpdate = false) {
|
|
93538
|
+
async function attemptPageStateSync(onSendCb, forceUpdate = false, reason) {
|
|
93469
93539
|
const currentTime = performance.now();
|
|
93470
93540
|
const timeSinceLastCall = currentTime - lastSendPageStateTime;
|
|
93471
93541
|
if (timeSinceLastCall < SEND_PAGE_STATE_THROTTLE_MS && !forceUpdate) {
|
|
@@ -93477,7 +93547,7 @@ code.hljs {
|
|
|
93477
93547
|
pendingSyncTimeout = setTimeout(() => {
|
|
93478
93548
|
pendingSync = false;
|
|
93479
93549
|
pendingSyncTimeout = null;
|
|
93480
|
-
sendPageState(onSendCb, true);
|
|
93550
|
+
sendPageState(onSendCb, true, reason);
|
|
93481
93551
|
}, delayMs);
|
|
93482
93552
|
return;
|
|
93483
93553
|
}
|
|
@@ -93486,48 +93556,55 @@ code.hljs {
|
|
|
93486
93556
|
pendingSyncTimeout = null;
|
|
93487
93557
|
pendingSync = false;
|
|
93488
93558
|
}
|
|
93489
|
-
await sendPageState(onSendCb, forceUpdate);
|
|
93559
|
+
await sendPageState(onSendCb, forceUpdate, reason);
|
|
93490
93560
|
}
|
|
93491
|
-
function syncPageState(onSendCb, forceUpdate) {
|
|
93492
|
-
attemptPageStateSync(onSendCb, forceUpdate);
|
|
93561
|
+
function syncPageState(onSendCb, forceUpdate, reason) {
|
|
93562
|
+
attemptPageStateSync(onSendCb, forceUpdate, reason);
|
|
93493
93563
|
}
|
|
93494
93564
|
function listenForPageChanges() {
|
|
93495
93565
|
sendPageState();
|
|
93496
93566
|
}
|
|
93497
|
-
async function captureScreenshot(requestId) {
|
|
93567
|
+
async function captureScreenshot(requestId, reason) {
|
|
93498
93568
|
if (!document.body) {
|
|
93499
93569
|
throw new Error("Document body not available");
|
|
93500
93570
|
}
|
|
93501
|
-
const bodyRect = document.body.getBoundingClientRect();
|
|
93502
|
-
const maxWidth = 1280;
|
|
93503
|
-
const maxHeight = 1024;
|
|
93504
|
-
const scale = Math.min(maxWidth / bodyRect.width, maxHeight / bodyRect.height, 1);
|
|
93505
93571
|
try {
|
|
93506
|
-
const
|
|
93507
|
-
|
|
93508
|
-
|
|
93509
|
-
|
|
93510
|
-
|
|
93511
|
-
|
|
93512
|
-
|
|
93513
|
-
|
|
93514
|
-
|
|
93515
|
-
|
|
93516
|
-
|
|
93517
|
-
|
|
93518
|
-
|
|
93519
|
-
|
|
93520
|
-
|
|
93521
|
-
|
|
93522
|
-
|
|
93523
|
-
|
|
93524
|
-
|
|
93525
|
-
|
|
93526
|
-
|
|
93527
|
-
|
|
93572
|
+
const html3 = document.documentElement.outerHTML;
|
|
93573
|
+
const maxWidth = 1280;
|
|
93574
|
+
const maxHeight = 1024;
|
|
93575
|
+
const scrollStates = collectScrollableElementStates();
|
|
93576
|
+
let res;
|
|
93577
|
+
try {
|
|
93578
|
+
res = await new Promise((resolve, reject) => {
|
|
93579
|
+
window.tutorProject.call(
|
|
93580
|
+
"generateScreenshot",
|
|
93581
|
+
{
|
|
93582
|
+
html: html3,
|
|
93583
|
+
baseHref: window.location.origin,
|
|
93584
|
+
width: Math.min(window.innerWidth, maxWidth),
|
|
93585
|
+
height: Math.min(window.innerHeight, maxHeight),
|
|
93586
|
+
fullPage: true,
|
|
93587
|
+
imageType: "jpeg",
|
|
93588
|
+
quality: 85,
|
|
93589
|
+
scrollStates
|
|
93590
|
+
},
|
|
93591
|
+
(err, screenshot) => {
|
|
93592
|
+
if (err) reject(err);
|
|
93593
|
+
else resolve(screenshot);
|
|
93594
|
+
}
|
|
93595
|
+
);
|
|
93596
|
+
});
|
|
93597
|
+
} catch (err) {
|
|
93598
|
+
console.error("Screenshot failed", err);
|
|
93599
|
+
return "";
|
|
93600
|
+
}
|
|
93601
|
+
return res.screenshot;
|
|
93602
|
+
} catch (err) {
|
|
93603
|
+
console.error("Screenshot error:", err);
|
|
93604
|
+
throw err;
|
|
93528
93605
|
}
|
|
93529
93606
|
}
|
|
93530
|
-
async function sendPageState(onSendCb, forceUpdate) {
|
|
93607
|
+
async function sendPageState(onSendCb, forceUpdate, reason) {
|
|
93531
93608
|
lastSendPageStateTime = performance.now();
|
|
93532
93609
|
const currentRequestId = ++requestCounter;
|
|
93533
93610
|
try {
|
|
@@ -93574,7 +93651,7 @@ code.hljs {
|
|
|
93574
93651
|
return;
|
|
93575
93652
|
}
|
|
93576
93653
|
if (uiState10.pageState?.screenshot?.enabled) {
|
|
93577
|
-
params.screenshot = await captureScreenshot(currentRequestId);
|
|
93654
|
+
params.screenshot = await captureScreenshot(currentRequestId, reason);
|
|
93578
93655
|
}
|
|
93579
93656
|
window.tutorProject.call("syncPageState", params);
|
|
93580
93657
|
} catch (error) {
|
|
@@ -101617,8 +101694,8 @@ code.hljs {
|
|
|
101617
101694
|
// alan_btn/alan_btn.ts
|
|
101618
101695
|
(function(ns) {
|
|
101619
101696
|
const uiState10 = getUIState();
|
|
101620
|
-
uiState10.lib.version = "alan-version.1.8.
|
|
101621
|
-
window.alanLib = { version: "alan-version.1.8.
|
|
101697
|
+
uiState10.lib.version = "alan-version.1.8.98".replace("alan-version.", "");
|
|
101698
|
+
window.alanLib = { version: "alan-version.1.8.98".replace("alan-version.", "") };
|
|
101622
101699
|
if (window.alanBtn) {
|
|
101623
101700
|
console.warn("Alan: the Alan Button source code has already added (v." + uiState10.lib.version + ")");
|
|
101624
101701
|
}
|
|
@@ -103386,16 +103463,13 @@ ${getSavedDialogId() || "-"} (prev. dialog)`);
|
|
|
103386
103463
|
}
|
|
103387
103464
|
console.info(`Alan: curDialogId:
|
|
103388
103465
|
${curDialogId}`);
|
|
103389
|
-
|
|
103390
|
-
if (!isTutorMode()) {
|
|
103391
|
-
sendSyncPageState();
|
|
103466
|
+
sendSyncPageState(null, "onConnectStatusChange");
|
|
103392
103467
|
}
|
|
103393
103468
|
}
|
|
103394
103469
|
if (options.onConnectionStatus) {
|
|
103395
103470
|
options.onConnectionStatus(res);
|
|
103396
103471
|
}
|
|
103397
103472
|
isMsgTypingInProcess = false;
|
|
103398
|
-
sendSyncPageState(true);
|
|
103399
103473
|
}
|
|
103400
103474
|
function onMicAllowed() {
|
|
103401
103475
|
sendClientEvent({ micAllowed: true });
|
|
@@ -104480,6 +104554,7 @@ ${LEARN_MORE_LABEL}
|
|
|
104480
104554
|
_sendText(text3);
|
|
104481
104555
|
textareaHolderEl.classList.add("alan-btn__inactive");
|
|
104482
104556
|
textChatScrollPosition = null;
|
|
104557
|
+
sendSyncPageState();
|
|
104483
104558
|
}, 1e3);
|
|
104484
104559
|
function getMsgElForMathJax(msgInd) {
|
|
104485
104560
|
const msgEl = document.getElementById("msg-" + msgInd);
|
|
@@ -104699,8 +104774,12 @@ ${LEARN_MORE_LABEL}
|
|
|
104699
104774
|
}
|
|
104700
104775
|
function decryptMessage(encryptedMessage, encryptKey) {
|
|
104701
104776
|
const key = import_sjcl.default.codec.hex.fromBits(import_sjcl.default.hash.sha256.hash(encryptKey || (uiState10.userInfo?.userId || "default")));
|
|
104702
|
-
|
|
104703
|
-
|
|
104777
|
+
try {
|
|
104778
|
+
const decrypted = import_sjcl.default.decrypt(key, JSON.parse(atob(encryptedMessage)));
|
|
104779
|
+
return decrypted;
|
|
104780
|
+
} catch (e) {
|
|
104781
|
+
return null;
|
|
104782
|
+
}
|
|
104704
104783
|
}
|
|
104705
104784
|
function restoreSentMessages() {
|
|
104706
104785
|
let messages = [];
|
|
@@ -104770,11 +104849,11 @@ ${LEARN_MORE_LABEL}
|
|
|
104770
104849
|
}
|
|
104771
104850
|
}
|
|
104772
104851
|
let isMsgTypingInProcess = false;
|
|
104773
|
-
function sendSyncPageState(forceUpdate = false) {
|
|
104852
|
+
function sendSyncPageState(forceUpdate = false, reason) {
|
|
104774
104853
|
if (!isMsgTypingInProcess) {
|
|
104775
104854
|
syncPageState(function() {
|
|
104776
104855
|
isMsgTypingInProcess = true;
|
|
104777
|
-
}, forceUpdate);
|
|
104856
|
+
}, forceUpdate, reason);
|
|
104778
104857
|
setTimeout(() => {
|
|
104779
104858
|
isMsgTypingInProcess = false;
|
|
104780
104859
|
}, 2e3);
|