@alan-ai/alan-sdk-web 1.8.104 → 1.8.105
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 +119 -29
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -85639,6 +85639,7 @@ code.hljs {
|
|
|
85639
85639
|
|
|
85640
85640
|
// alan_btn/src/autosync.ts
|
|
85641
85641
|
var SEND_PAGE_STATE_THROTTLE_MS = 2e3;
|
|
85642
|
+
var IFRAME_CONTENT_TIMEOUT_MS = 3e3;
|
|
85642
85643
|
var autoSyncEnabled = false;
|
|
85643
85644
|
var requestCounter = 0;
|
|
85644
85645
|
var lastSendPageStateTime = 0;
|
|
@@ -85722,6 +85723,86 @@ code.hljs {
|
|
|
85722
85723
|
});
|
|
85723
85724
|
return scrollableStates;
|
|
85724
85725
|
}
|
|
85726
|
+
async function collectIframeContent() {
|
|
85727
|
+
const iframes = Array.from(document.querySelectorAll("iframe"));
|
|
85728
|
+
if (iframes.length === 0) {
|
|
85729
|
+
return [];
|
|
85730
|
+
}
|
|
85731
|
+
return new Promise((resolve) => {
|
|
85732
|
+
const responses = /* @__PURE__ */ new Map();
|
|
85733
|
+
const expectedIds = /* @__PURE__ */ new Set();
|
|
85734
|
+
iframes.forEach((iframe, index2) => {
|
|
85735
|
+
expectedIds.add(iframe.id);
|
|
85736
|
+
});
|
|
85737
|
+
const messageHandler = (event) => {
|
|
85738
|
+
if (event.data && event.data.source === "alan-chat-iframe" && event.data.type === "alan-iframe-content-response") {
|
|
85739
|
+
const { iframeId, html: html3 } = event.data;
|
|
85740
|
+
if (expectedIds.has(iframeId)) {
|
|
85741
|
+
responses.set(iframeId, html3);
|
|
85742
|
+
if (responses.size === expectedIds.size) {
|
|
85743
|
+
window.removeEventListener("message", messageHandler);
|
|
85744
|
+
const result = Array.from(responses.entries()).map(([id, html4]) => ({ id, html: html4 }));
|
|
85745
|
+
resolve(result);
|
|
85746
|
+
}
|
|
85747
|
+
}
|
|
85748
|
+
}
|
|
85749
|
+
};
|
|
85750
|
+
window.addEventListener("message", messageHandler);
|
|
85751
|
+
iframes.forEach((iframe) => {
|
|
85752
|
+
try {
|
|
85753
|
+
if (iframe.contentWindow) {
|
|
85754
|
+
iframe.contentWindow.postMessage({
|
|
85755
|
+
type: "alan-return-iframe-content",
|
|
85756
|
+
id: iframe.id
|
|
85757
|
+
}, "*");
|
|
85758
|
+
}
|
|
85759
|
+
} catch (error) {
|
|
85760
|
+
console.error(`Failed to send message to iframe ${iframe.id}`, error);
|
|
85761
|
+
responses.set(iframe.id, "");
|
|
85762
|
+
}
|
|
85763
|
+
});
|
|
85764
|
+
setTimeout(() => {
|
|
85765
|
+
window.removeEventListener("message", messageHandler);
|
|
85766
|
+
const result = Array.from(expectedIds).map((id) => ({
|
|
85767
|
+
id,
|
|
85768
|
+
html: responses.get(id) || ""
|
|
85769
|
+
}));
|
|
85770
|
+
resolve(result);
|
|
85771
|
+
}, IFRAME_CONTENT_TIMEOUT_MS);
|
|
85772
|
+
});
|
|
85773
|
+
}
|
|
85774
|
+
function replaceIframesWithSrcDoc(page, iframeContents) {
|
|
85775
|
+
const contentMap = new Map(iframeContents.map((item) => [item.id, item.html]));
|
|
85776
|
+
const iframes = page.querySelectorAll("iframe");
|
|
85777
|
+
iframes.forEach((iframe) => {
|
|
85778
|
+
const iframeId = iframe.id;
|
|
85779
|
+
const html3 = contentMap.get(iframeId);
|
|
85780
|
+
if (html3) {
|
|
85781
|
+
iframe.removeAttribute("src");
|
|
85782
|
+
iframe.setAttribute("srcdoc", html3);
|
|
85783
|
+
}
|
|
85784
|
+
});
|
|
85785
|
+
}
|
|
85786
|
+
function isElementVisibleInViewport(element) {
|
|
85787
|
+
const rect = element.getBoundingClientRect();
|
|
85788
|
+
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
85789
|
+
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
85790
|
+
return rect.top < viewportHeight && rect.bottom > 0 && rect.left < viewportWidth && rect.right > 0;
|
|
85791
|
+
}
|
|
85792
|
+
function markIframeVisibility(page) {
|
|
85793
|
+
const liveIframes = Array.from(document.querySelectorAll("iframe"));
|
|
85794
|
+
const visibilityMap = /* @__PURE__ */ new Map();
|
|
85795
|
+
liveIframes.forEach((iframe) => {
|
|
85796
|
+
if (iframe.id) {
|
|
85797
|
+
visibilityMap.set(iframe.id, isElementVisibleInViewport(iframe));
|
|
85798
|
+
}
|
|
85799
|
+
});
|
|
85800
|
+
const pageIframes = page.querySelectorAll("iframe");
|
|
85801
|
+
pageIframes.forEach((iframe) => {
|
|
85802
|
+
const isVisible = visibilityMap.get(iframe.id) || false;
|
|
85803
|
+
iframe.setAttribute("visible-on-screen", String(isVisible));
|
|
85804
|
+
});
|
|
85805
|
+
}
|
|
85725
85806
|
function generateContentHash(content) {
|
|
85726
85807
|
let hash = 0;
|
|
85727
85808
|
for (let i = 0; i < content.length; i++) {
|
|
@@ -85799,17 +85880,19 @@ code.hljs {
|
|
|
85799
85880
|
}
|
|
85800
85881
|
const page = document.createElement("html");
|
|
85801
85882
|
page.innerHTML = document.getElementsByTagName("html")[0].innerHTML;
|
|
85802
|
-
const originalHtml = page.outerHTML;
|
|
85803
85883
|
const scripts = page.getElementsByTagName("script");
|
|
85804
|
-
const
|
|
85805
|
-
const chatElements = page.querySelectorAll('[alan-chat-exclude-from-page-context="true"]');
|
|
85806
|
-
const elementsToRemove = [...scripts, ...styles, ...chatElements];
|
|
85884
|
+
const elementsToRemove = [...scripts];
|
|
85807
85885
|
for (let i = 0; i < elementsToRemove.length; i++) {
|
|
85808
85886
|
if (elementsToRemove[i] && elementsToRemove[i].remove) {
|
|
85809
85887
|
elementsToRemove[i].remove();
|
|
85810
85888
|
}
|
|
85811
85889
|
}
|
|
85812
85890
|
const pageContent = page.outerHTML;
|
|
85891
|
+
const iframeContents = await collectIframeContent();
|
|
85892
|
+
if (iframeContents.length > 0) {
|
|
85893
|
+
replaceIframesWithSrcDoc(page, iframeContents);
|
|
85894
|
+
}
|
|
85895
|
+
markIframeVisibility(page);
|
|
85813
85896
|
if (onSendCb) {
|
|
85814
85897
|
onSendCb();
|
|
85815
85898
|
}
|
|
@@ -85821,7 +85904,7 @@ code.hljs {
|
|
|
85821
85904
|
return;
|
|
85822
85905
|
}
|
|
85823
85906
|
const params = {
|
|
85824
|
-
html:
|
|
85907
|
+
html: page.outerHTML,
|
|
85825
85908
|
url: window.location.href,
|
|
85826
85909
|
scrollPosition: {
|
|
85827
85910
|
x: prevPageState.scrollX,
|
|
@@ -85836,16 +85919,11 @@ code.hljs {
|
|
|
85836
85919
|
if (uiState10.pageState?.autoSync === false) {
|
|
85837
85920
|
return;
|
|
85838
85921
|
}
|
|
85839
|
-
const maxWidth = 1280;
|
|
85840
|
-
const maxHeight = 1024;
|
|
85841
85922
|
if (uiState10.pageState?.screenshot?.enabled) {
|
|
85842
85923
|
params.screenshot_data = {
|
|
85843
85924
|
baseHref: window.location.origin,
|
|
85844
|
-
width:
|
|
85845
|
-
height:
|
|
85846
|
-
fullPage: true,
|
|
85847
|
-
imageType: "jpeg",
|
|
85848
|
-
quality: 85,
|
|
85925
|
+
width: window.innerWidth,
|
|
85926
|
+
height: window.innerHeight,
|
|
85849
85927
|
scrollStates: collectScrollableElementStates()
|
|
85850
85928
|
};
|
|
85851
85929
|
}
|
|
@@ -93890,8 +93968,8 @@ code.hljs {
|
|
|
93890
93968
|
// alan_btn/alan_btn.ts
|
|
93891
93969
|
(function(ns) {
|
|
93892
93970
|
const uiState10 = getUIState();
|
|
93893
|
-
uiState10.lib.version = "alan-version.1.8.
|
|
93894
|
-
window.alanLib = { version: "alan-version.1.8.
|
|
93971
|
+
uiState10.lib.version = "alan-version.1.8.105".replace("alan-version.", "");
|
|
93972
|
+
window.alanLib = { version: "alan-version.1.8.105".replace("alan-version.", "") };
|
|
93895
93973
|
if (window.alanBtn) {
|
|
93896
93974
|
console.warn("Alan: the Alan Button source code has already added (v." + uiState10.lib.version + ")");
|
|
93897
93975
|
}
|
|
@@ -95665,7 +95743,6 @@ ${curDialogId}`);
|
|
|
95665
95743
|
if (options.onConnectionStatus) {
|
|
95666
95744
|
options.onConnectionStatus(res);
|
|
95667
95745
|
}
|
|
95668
|
-
isMsgTypingInProcess = false;
|
|
95669
95746
|
}
|
|
95670
95747
|
function onMicAllowed() {
|
|
95671
95748
|
sendClientEvent({ micAllowed: true });
|
|
@@ -95811,6 +95888,9 @@ ${curDialogId}`);
|
|
|
95811
95888
|
}
|
|
95812
95889
|
renderMessageInTextChat(event);
|
|
95813
95890
|
turnOffVoiceFn();
|
|
95891
|
+
if (e?.ctx?.final === true) {
|
|
95892
|
+
syncPageState(null, null, "final_msg_received");
|
|
95893
|
+
}
|
|
95814
95894
|
}
|
|
95815
95895
|
function onTextCbInMicBtn(e) {
|
|
95816
95896
|
if (!isAlanActive && e.ctx?.opts?.activate === true) {
|
|
@@ -96710,6 +96790,7 @@ ${LEARN_MORE_LABEL}
|
|
|
96710
96790
|
reqId: res.reqId
|
|
96711
96791
|
});
|
|
96712
96792
|
saveSentMessages(text3);
|
|
96793
|
+
sendSyncPageState(null, "send");
|
|
96713
96794
|
}
|
|
96714
96795
|
var lastSendMsgTs = null;
|
|
96715
96796
|
function isMsgShouldBeSkipped(msg) {
|
|
@@ -96733,7 +96814,6 @@ ${LEARN_MORE_LABEL}
|
|
|
96733
96814
|
lastSendMsgTs = null;
|
|
96734
96815
|
}
|
|
96735
96816
|
const sendMessageToTextChat = throttle(async function sendMessageToTextChat2() {
|
|
96736
|
-
isMsgTypingInProcess = false;
|
|
96737
96817
|
var textareaEl = getChatTextareaEl();
|
|
96738
96818
|
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
96739
96819
|
var text3 = textareaEl.value;
|
|
@@ -96747,10 +96827,10 @@ ${LEARN_MORE_LABEL}
|
|
|
96747
96827
|
lastSendMsgTs = Date.now();
|
|
96748
96828
|
if (text3.trim() === "") return;
|
|
96749
96829
|
textareaEl.value = "";
|
|
96830
|
+
previousTextValue = "";
|
|
96750
96831
|
_sendText(text3);
|
|
96751
96832
|
textareaHolderEl.classList.add("alan-btn__inactive");
|
|
96752
96833
|
textChatScrollPosition = null;
|
|
96753
|
-
sendSyncPageState();
|
|
96754
96834
|
}, 1e3);
|
|
96755
96835
|
function getMsgElForMathJax(msgInd) {
|
|
96756
96836
|
const msgEl = document.getElementById("msg-" + msgInd);
|
|
@@ -97044,27 +97124,37 @@ ${LEARN_MORE_LABEL}
|
|
|
97044
97124
|
el.scrollLeft = el.scrollWidth;
|
|
97045
97125
|
}
|
|
97046
97126
|
}
|
|
97047
|
-
let
|
|
97127
|
+
let hasRefocusedTextarea = false;
|
|
97128
|
+
let previousTextValue = "";
|
|
97048
97129
|
function sendSyncPageState(forceUpdate = false, reason) {
|
|
97049
|
-
|
|
97050
|
-
syncPageState(function() {
|
|
97051
|
-
isMsgTypingInProcess = true;
|
|
97052
|
-
}, forceUpdate, reason);
|
|
97053
|
-
setTimeout(() => {
|
|
97054
|
-
isMsgTypingInProcess = false;
|
|
97055
|
-
}, 2e3);
|
|
97056
|
-
}
|
|
97130
|
+
syncPageState(null, forceUpdate, reason);
|
|
97057
97131
|
}
|
|
97058
97132
|
function onChatTextAreaFocus() {
|
|
97059
|
-
|
|
97133
|
+
const textareaEl = getChatTextareaEl();
|
|
97134
|
+
if (textareaEl && textareaEl.value.trim() !== "") {
|
|
97135
|
+
hasRefocusedTextarea = true;
|
|
97136
|
+
}
|
|
97060
97137
|
}
|
|
97061
97138
|
function onChatTextAreaBlur() {
|
|
97062
|
-
|
|
97139
|
+
hasRefocusedTextarea = false;
|
|
97140
|
+
const textareaEl = getChatTextareaEl();
|
|
97141
|
+
if (textareaEl) {
|
|
97142
|
+
previousTextValue = textareaEl.value;
|
|
97143
|
+
}
|
|
97063
97144
|
}
|
|
97064
97145
|
let delPressed = 0;
|
|
97065
97146
|
function onChatTextAreaKeyDown(e) {
|
|
97066
97147
|
const keyCode = e.keyCode || e.which;
|
|
97067
|
-
|
|
97148
|
+
const textareaEl = e.target;
|
|
97149
|
+
const currentText = textareaEl.value;
|
|
97150
|
+
const isTypingNewChar = e.key && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
97151
|
+
if (previousTextValue.trim() === "" && currentText.trim() === "" && isTypingNewChar || hasRefocusedTextarea && isTypingNewChar && currentText.length >= previousTextValue.length) {
|
|
97152
|
+
sendSyncPageState(null, "user_started_typing");
|
|
97153
|
+
hasRefocusedTextarea = false;
|
|
97154
|
+
previousTextValue = currentText;
|
|
97155
|
+
} else if (isTypingNewChar) {
|
|
97156
|
+
previousTextValue = currentText;
|
|
97157
|
+
}
|
|
97068
97158
|
if (keyCode === 13 && e.shiftKey) {
|
|
97069
97159
|
return;
|
|
97070
97160
|
}
|