@alan-ai/alan-sdk-web 1.8.103 → 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 +139 -35
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -81169,7 +81169,7 @@
|
|
|
81169
81169
|
messages[msgInd] = { ...msg };
|
|
81170
81170
|
}
|
|
81171
81171
|
const curMsg = messages[msgInd];
|
|
81172
|
-
if ((curMsg?.text || curMsg?.images || curMsg.suggestions) && isFinalMessage(
|
|
81172
|
+
if ((curMsg?.text || curMsg?.images || curMsg.suggestions) && isFinalMessage(curMsg)) {
|
|
81173
81173
|
skipUpdating = true;
|
|
81174
81174
|
}
|
|
81175
81175
|
isNew = false;
|
|
@@ -81177,7 +81177,18 @@
|
|
|
81177
81177
|
isNew = false;
|
|
81178
81178
|
msgInd = existingMsgReqId;
|
|
81179
81179
|
const curMsg = messages[msgInd];
|
|
81180
|
-
if (
|
|
81180
|
+
if (curMsg?.ctx?.final !== true) {
|
|
81181
|
+
if (msg.queryProgress) {
|
|
81182
|
+
messages[msgInd] = {
|
|
81183
|
+
...messages[msgInd],
|
|
81184
|
+
queryProgress: [
|
|
81185
|
+
...messages[msgInd]?.queryProgress || [],
|
|
81186
|
+
...msg.queryProgress
|
|
81187
|
+
]
|
|
81188
|
+
};
|
|
81189
|
+
}
|
|
81190
|
+
}
|
|
81191
|
+
if ((curMsg?.text || curMsg?.images || curMsg.suggestions) && isFinalMessage(curMsg)) {
|
|
81181
81192
|
skipUpdating = true;
|
|
81182
81193
|
}
|
|
81183
81194
|
}
|
|
@@ -82107,13 +82118,13 @@
|
|
|
82107
82118
|
return btoa(unescape(encodeURIComponent(svg)));
|
|
82108
82119
|
}
|
|
82109
82120
|
function parseSvgSize(svgString) {
|
|
82110
|
-
|
|
82121
|
+
const defaultSize = uiState6.textChat.defaults.defaultSvgIconSize;
|
|
82122
|
+
if (!svgString) return [defaultSize, defaultSize];
|
|
82111
82123
|
const parser2 = new DOMParser();
|
|
82112
82124
|
const svgDoc = parser2.parseFromString(svgString, "image/svg+xml");
|
|
82113
82125
|
const svgElement = svgDoc.querySelector("svg");
|
|
82114
82126
|
const width = svgElement.getAttribute("width");
|
|
82115
82127
|
const height = svgElement.getAttribute("height");
|
|
82116
|
-
const defaultSize = uiState6.textChat.defaults.defaultSvgIconSize;
|
|
82117
82128
|
return [width || defaultSize, height || defaultSize];
|
|
82118
82129
|
}
|
|
82119
82130
|
|
|
@@ -83974,6 +83985,7 @@
|
|
|
83974
83985
|
keyFrames += styleSheetMarker + `.alan-btn__chat-incomming-msg-wrapper {
|
|
83975
83986
|
display: flex;
|
|
83976
83987
|
max-width: 100%;
|
|
83988
|
+
position: relative;
|
|
83977
83989
|
align-items: ${waitingResponseBubbleLabelIconAlignment};
|
|
83978
83990
|
gap: ${waitingResponseBubbleLoaderIconGap}px;
|
|
83979
83991
|
${waitingResponseBubbleLayout !== "default" ? `
|
|
@@ -83990,8 +84002,8 @@
|
|
|
83990
84002
|
keyFrames += styleSheetMarker + `.alan-btn__chat-incomming-msg-loader-icon-holder:not(.alan-btn__bottom-loader) {
|
|
83991
84003
|
${waitingResponseBubbleLoaderWithDetails ? `
|
|
83992
84004
|
position:absolute;
|
|
83993
|
-
top:
|
|
83994
|
-
left:
|
|
84005
|
+
top: -2px;
|
|
84006
|
+
left: -1px;
|
|
83995
84007
|
` : ``}
|
|
83996
84008
|
}`;
|
|
83997
84009
|
keyFrames += styleSheetMarker + `.alan-btn__chat-incomming-msg-loader-icon-holder:hover svg {
|
|
@@ -85627,6 +85639,7 @@ code.hljs {
|
|
|
85627
85639
|
|
|
85628
85640
|
// alan_btn/src/autosync.ts
|
|
85629
85641
|
var SEND_PAGE_STATE_THROTTLE_MS = 2e3;
|
|
85642
|
+
var IFRAME_CONTENT_TIMEOUT_MS = 3e3;
|
|
85630
85643
|
var autoSyncEnabled = false;
|
|
85631
85644
|
var requestCounter = 0;
|
|
85632
85645
|
var lastSendPageStateTime = 0;
|
|
@@ -85710,6 +85723,86 @@ code.hljs {
|
|
|
85710
85723
|
});
|
|
85711
85724
|
return scrollableStates;
|
|
85712
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
|
+
}
|
|
85713
85806
|
function generateContentHash(content) {
|
|
85714
85807
|
let hash = 0;
|
|
85715
85808
|
for (let i = 0; i < content.length; i++) {
|
|
@@ -85788,16 +85881,18 @@ code.hljs {
|
|
|
85788
85881
|
const page = document.createElement("html");
|
|
85789
85882
|
page.innerHTML = document.getElementsByTagName("html")[0].innerHTML;
|
|
85790
85883
|
const scripts = page.getElementsByTagName("script");
|
|
85791
|
-
const
|
|
85792
|
-
const alanBtnEl = page.getElementsByClassName("alanBtn-root");
|
|
85793
|
-
const debugChatEl = page.getElementsByClassName("alanStudio-debug-chat");
|
|
85794
|
-
const elementsToRemove = [...scripts, ...styles, ...alanBtnEl, ...debugChatEl];
|
|
85884
|
+
const elementsToRemove = [...scripts];
|
|
85795
85885
|
for (let i = 0; i < elementsToRemove.length; i++) {
|
|
85796
85886
|
if (elementsToRemove[i] && elementsToRemove[i].remove) {
|
|
85797
85887
|
elementsToRemove[i].remove();
|
|
85798
85888
|
}
|
|
85799
85889
|
}
|
|
85800
85890
|
const pageContent = page.outerHTML;
|
|
85891
|
+
const iframeContents = await collectIframeContent();
|
|
85892
|
+
if (iframeContents.length > 0) {
|
|
85893
|
+
replaceIframesWithSrcDoc(page, iframeContents);
|
|
85894
|
+
}
|
|
85895
|
+
markIframeVisibility(page);
|
|
85801
85896
|
if (onSendCb) {
|
|
85802
85897
|
onSendCb();
|
|
85803
85898
|
}
|
|
@@ -85809,7 +85904,7 @@ code.hljs {
|
|
|
85809
85904
|
return;
|
|
85810
85905
|
}
|
|
85811
85906
|
const params = {
|
|
85812
|
-
html:
|
|
85907
|
+
html: page.outerHTML,
|
|
85813
85908
|
url: window.location.href,
|
|
85814
85909
|
scrollPosition: {
|
|
85815
85910
|
x: prevPageState.scrollX,
|
|
@@ -85824,16 +85919,11 @@ code.hljs {
|
|
|
85824
85919
|
if (uiState10.pageState?.autoSync === false) {
|
|
85825
85920
|
return;
|
|
85826
85921
|
}
|
|
85827
|
-
const maxWidth = 1280;
|
|
85828
|
-
const maxHeight = 1024;
|
|
85829
85922
|
if (uiState10.pageState?.screenshot?.enabled) {
|
|
85830
85923
|
params.screenshot_data = {
|
|
85831
85924
|
baseHref: window.location.origin,
|
|
85832
|
-
width:
|
|
85833
|
-
height:
|
|
85834
|
-
fullPage: true,
|
|
85835
|
-
imageType: "jpeg",
|
|
85836
|
-
quality: 85,
|
|
85925
|
+
width: window.innerWidth,
|
|
85926
|
+
height: window.innerHeight,
|
|
85837
85927
|
scrollStates: collectScrollableElementStates()
|
|
85838
85928
|
};
|
|
85839
85929
|
}
|
|
@@ -93878,8 +93968,8 @@ code.hljs {
|
|
|
93878
93968
|
// alan_btn/alan_btn.ts
|
|
93879
93969
|
(function(ns) {
|
|
93880
93970
|
const uiState10 = getUIState();
|
|
93881
|
-
uiState10.lib.version = "alan-version.1.8.
|
|
93882
|
-
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.", "") };
|
|
93883
93973
|
if (window.alanBtn) {
|
|
93884
93974
|
console.warn("Alan: the Alan Button source code has already added (v." + uiState10.lib.version + ")");
|
|
93885
93975
|
}
|
|
@@ -95653,7 +95743,6 @@ ${curDialogId}`);
|
|
|
95653
95743
|
if (options.onConnectionStatus) {
|
|
95654
95744
|
options.onConnectionStatus(res);
|
|
95655
95745
|
}
|
|
95656
|
-
isMsgTypingInProcess = false;
|
|
95657
95746
|
}
|
|
95658
95747
|
function onMicAllowed() {
|
|
95659
95748
|
sendClientEvent({ micAllowed: true });
|
|
@@ -95799,6 +95888,9 @@ ${curDialogId}`);
|
|
|
95799
95888
|
}
|
|
95800
95889
|
renderMessageInTextChat(event);
|
|
95801
95890
|
turnOffVoiceFn();
|
|
95891
|
+
if (e?.ctx?.final === true) {
|
|
95892
|
+
syncPageState(null, null, "final_msg_received");
|
|
95893
|
+
}
|
|
95802
95894
|
}
|
|
95803
95895
|
function onTextCbInMicBtn(e) {
|
|
95804
95896
|
if (!isAlanActive && e.ctx?.opts?.activate === true) {
|
|
@@ -96698,6 +96790,7 @@ ${LEARN_MORE_LABEL}
|
|
|
96698
96790
|
reqId: res.reqId
|
|
96699
96791
|
});
|
|
96700
96792
|
saveSentMessages(text3);
|
|
96793
|
+
sendSyncPageState(null, "send");
|
|
96701
96794
|
}
|
|
96702
96795
|
var lastSendMsgTs = null;
|
|
96703
96796
|
function isMsgShouldBeSkipped(msg) {
|
|
@@ -96721,7 +96814,6 @@ ${LEARN_MORE_LABEL}
|
|
|
96721
96814
|
lastSendMsgTs = null;
|
|
96722
96815
|
}
|
|
96723
96816
|
const sendMessageToTextChat = throttle(async function sendMessageToTextChat2() {
|
|
96724
|
-
isMsgTypingInProcess = false;
|
|
96725
96817
|
var textareaEl = getChatTextareaEl();
|
|
96726
96818
|
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
96727
96819
|
var text3 = textareaEl.value;
|
|
@@ -96735,10 +96827,10 @@ ${LEARN_MORE_LABEL}
|
|
|
96735
96827
|
lastSendMsgTs = Date.now();
|
|
96736
96828
|
if (text3.trim() === "") return;
|
|
96737
96829
|
textareaEl.value = "";
|
|
96830
|
+
previousTextValue = "";
|
|
96738
96831
|
_sendText(text3);
|
|
96739
96832
|
textareaHolderEl.classList.add("alan-btn__inactive");
|
|
96740
96833
|
textChatScrollPosition = null;
|
|
96741
|
-
sendSyncPageState();
|
|
96742
96834
|
}, 1e3);
|
|
96743
96835
|
function getMsgElForMathJax(msgInd) {
|
|
96744
96836
|
const msgEl = document.getElementById("msg-" + msgInd);
|
|
@@ -97032,27 +97124,37 @@ ${LEARN_MORE_LABEL}
|
|
|
97032
97124
|
el.scrollLeft = el.scrollWidth;
|
|
97033
97125
|
}
|
|
97034
97126
|
}
|
|
97035
|
-
let
|
|
97127
|
+
let hasRefocusedTextarea = false;
|
|
97128
|
+
let previousTextValue = "";
|
|
97036
97129
|
function sendSyncPageState(forceUpdate = false, reason) {
|
|
97037
|
-
|
|
97038
|
-
syncPageState(function() {
|
|
97039
|
-
isMsgTypingInProcess = true;
|
|
97040
|
-
}, forceUpdate, reason);
|
|
97041
|
-
setTimeout(() => {
|
|
97042
|
-
isMsgTypingInProcess = false;
|
|
97043
|
-
}, 2e3);
|
|
97044
|
-
}
|
|
97130
|
+
syncPageState(null, forceUpdate, reason);
|
|
97045
97131
|
}
|
|
97046
97132
|
function onChatTextAreaFocus() {
|
|
97047
|
-
|
|
97133
|
+
const textareaEl = getChatTextareaEl();
|
|
97134
|
+
if (textareaEl && textareaEl.value.trim() !== "") {
|
|
97135
|
+
hasRefocusedTextarea = true;
|
|
97136
|
+
}
|
|
97048
97137
|
}
|
|
97049
97138
|
function onChatTextAreaBlur() {
|
|
97050
|
-
|
|
97139
|
+
hasRefocusedTextarea = false;
|
|
97140
|
+
const textareaEl = getChatTextareaEl();
|
|
97141
|
+
if (textareaEl) {
|
|
97142
|
+
previousTextValue = textareaEl.value;
|
|
97143
|
+
}
|
|
97051
97144
|
}
|
|
97052
97145
|
let delPressed = 0;
|
|
97053
97146
|
function onChatTextAreaKeyDown(e) {
|
|
97054
97147
|
const keyCode = e.keyCode || e.which;
|
|
97055
|
-
|
|
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
|
+
}
|
|
97056
97158
|
if (keyCode === 13 && e.shiftKey) {
|
|
97057
97159
|
return;
|
|
97058
97160
|
}
|
|
@@ -98198,9 +98300,11 @@ ${LEARN_MORE_LABEL}
|
|
|
98198
98300
|
playReadyToListenSound = playSound;
|
|
98199
98301
|
}
|
|
98200
98302
|
rootEl.classList.add("alanBtn-root");
|
|
98303
|
+
rootEl.setAttribute("alan-chat-exclude-from-page-context", "true");
|
|
98201
98304
|
rootEl.classList.add("alan-" + getProjectId());
|
|
98202
98305
|
if (options.chatEl) {
|
|
98203
98306
|
options.chatEl.classList.add("alanBtn-root");
|
|
98307
|
+
options.chatEl.setAttribute("alan-chat-exclude-from-page-context", "true");
|
|
98204
98308
|
if (isInlinedMode()) {
|
|
98205
98309
|
options.chatEl.classList.add("alanBtn-chat-root-inlined");
|
|
98206
98310
|
}
|