@alan-ai/alan-sdk-web 1.8.140 → 1.8.141
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 +98 -11
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -86476,9 +86476,11 @@ ${reason}`;
|
|
|
86476
86476
|
if (lastRequestWithoutResIdIndex > -1) {
|
|
86477
86477
|
messages[lastRequestWithoutResIdIndex] = {
|
|
86478
86478
|
...messages[lastRequestWithoutResIdIndex],
|
|
86479
|
-
ctx: {
|
|
86479
|
+
ctx: msg?.ctx?.tsFinal ? {
|
|
86480
86480
|
...messages[lastRequestWithoutResIdIndex].ctx,
|
|
86481
86481
|
tsFinal: msg?.ctx?.tsFinal
|
|
86482
|
+
} : {
|
|
86483
|
+
...messages[lastRequestWithoutResIdIndex].ctx
|
|
86482
86484
|
}
|
|
86483
86485
|
};
|
|
86484
86486
|
}
|
|
@@ -100110,7 +100112,7 @@ if (window.parent && window.parent !== window && !window.showAlanDebugInfo) {
|
|
|
100110
100112
|
// alan_btn/alan_btn.ts
|
|
100111
100113
|
(function(ns) {
|
|
100112
100114
|
const uiState10 = getUIState();
|
|
100113
|
-
const version2 = "alan-version.1.8.
|
|
100115
|
+
const version2 = "alan-version.1.8.141".replace("alan-version.", "");
|
|
100114
100116
|
uiState10.lib.version = version2;
|
|
100115
100117
|
window.alanLib = { version: version2 };
|
|
100116
100118
|
if (window.alanBtn) {
|
|
@@ -102719,6 +102721,7 @@ ${reason}` : reason,
|
|
|
102719
102721
|
ctx: {
|
|
102720
102722
|
...msg.ctx,
|
|
102721
102723
|
final: true,
|
|
102724
|
+
cancelled: true,
|
|
102722
102725
|
tsFinal: msg.ctx?.tsFinal || Date.now()
|
|
102723
102726
|
}
|
|
102724
102727
|
}, true);
|
|
@@ -103189,6 +103192,25 @@ ${reason}` : reason,
|
|
|
103189
103192
|
localStorage.setItem(LOCAL_STORAGE_KEYS.getTabIdKey(), tabId);
|
|
103190
103193
|
}
|
|
103191
103194
|
}
|
|
103195
|
+
function normalizeMessage(msg) {
|
|
103196
|
+
const normalized = { ...msg };
|
|
103197
|
+
if (normalized.queryProgress && Array.isArray(normalized.queryProgress)) {
|
|
103198
|
+
normalized.queryProgress = normalized.queryProgress.map((progress) => {
|
|
103199
|
+
const { isShown, ...rest } = progress;
|
|
103200
|
+
return rest;
|
|
103201
|
+
});
|
|
103202
|
+
}
|
|
103203
|
+
if (normalized.ctx) {
|
|
103204
|
+
const { cancelled, ...restCtx } = normalized.ctx;
|
|
103205
|
+
normalized.ctx = restCtx;
|
|
103206
|
+
}
|
|
103207
|
+
delete normalized.initLoad;
|
|
103208
|
+
return normalized;
|
|
103209
|
+
}
|
|
103210
|
+
function normalizeMessagesForComparison(messages) {
|
|
103211
|
+
if (!Array.isArray(messages)) return messages;
|
|
103212
|
+
return messages.map((msg) => normalizeMessage(msg));
|
|
103213
|
+
}
|
|
103192
103214
|
function restoreMessagesInChat(initLoad) {
|
|
103193
103215
|
var savedMsgs;
|
|
103194
103216
|
if (isTutorMode()) {
|
|
@@ -103201,17 +103223,17 @@ ${reason}` : reason,
|
|
|
103201
103223
|
if (savedMsgs) {
|
|
103202
103224
|
savedMsgs = decryptMessage(savedMsgs);
|
|
103203
103225
|
}
|
|
103204
|
-
|
|
103226
|
+
const parsedSavedMsgs = savedMsgs ? JSON.parse(savedMsgs) : [];
|
|
103227
|
+
const normalizedSaved = JSON.stringify(normalizeMessagesForComparison(parsedSavedMsgs));
|
|
103228
|
+
const normalizedCurrent = JSON.stringify(normalizeMessagesForComparison(textChatMessages));
|
|
103229
|
+
if (normalizedSaved === normalizedCurrent) {
|
|
103205
103230
|
return;
|
|
103206
103231
|
}
|
|
103207
|
-
savedMsgs =
|
|
103232
|
+
savedMsgs = parsedSavedMsgs;
|
|
103208
103233
|
if (Array.isArray(savedMsgs)) {
|
|
103209
|
-
if (savedMsgs?.length > 0) {
|
|
103210
|
-
clearDOMChat();
|
|
103211
|
-
}
|
|
103212
103234
|
canceledRequests = [];
|
|
103213
|
-
|
|
103214
|
-
|
|
103235
|
+
if (initLoad === true) {
|
|
103236
|
+
for (let i2 = 0; i2 < savedMsgs.length; i2++) {
|
|
103215
103237
|
savedMsgs[i2].initLoad = true;
|
|
103216
103238
|
if (savedMsgs[i2].name === "loading") {
|
|
103217
103239
|
savedMsgs[i2].name = "text";
|
|
@@ -103220,10 +103242,64 @@ ${reason}` : reason,
|
|
|
103220
103242
|
} else {
|
|
103221
103243
|
renderMessageInTextChat(savedMsgs[i2], true, true);
|
|
103222
103244
|
}
|
|
103223
|
-
} else {
|
|
103224
|
-
renderMessageInTextChat(savedMsgs[i2], true, true);
|
|
103225
103245
|
}
|
|
103246
|
+
refillCancelMessages(savedMsgs);
|
|
103247
|
+
return;
|
|
103248
|
+
}
|
|
103249
|
+
const chatChildren = document.getElementById("chatMessages");
|
|
103250
|
+
if (!chatChildren) {
|
|
103251
|
+
return;
|
|
103252
|
+
}
|
|
103253
|
+
const messagesInTheDom = chatChildren.querySelectorAll('[id^="msg-"]');
|
|
103254
|
+
const firstMsgInTheDom = messagesInTheDom[0];
|
|
103255
|
+
if (!firstMsgInTheDom) {
|
|
103256
|
+
return;
|
|
103257
|
+
}
|
|
103258
|
+
const firstMsgReqId = firstMsgInTheDom.getAttribute("data-request-id");
|
|
103259
|
+
let canUseSmartRestore = false;
|
|
103260
|
+
if (firstMsgReqId === getMsgReqId(savedMsgs[0])) {
|
|
103261
|
+
canUseSmartRestore = true;
|
|
103226
103262
|
}
|
|
103263
|
+
if (canUseSmartRestore) {
|
|
103264
|
+
let desyncIndex = -1;
|
|
103265
|
+
for (let i2 = 0; i2 < messagesInTheDom.length; i2++) {
|
|
103266
|
+
const curRenderedMsgReqId = messagesInTheDom[i2].getAttribute("data-request-id");
|
|
103267
|
+
const curSavedMsgReqId = savedMsgs[i2] ? getMsgReqId(savedMsgs[i2]) : null;
|
|
103268
|
+
if (curSavedMsgReqId === curRenderedMsgReqId) {
|
|
103269
|
+
const existingInTextChatMsgs = textChatMessages[i2];
|
|
103270
|
+
if (existingInTextChatMsgs && JSON.stringify(normalizeMessage(existingInTextChatMsgs)) === JSON.stringify(normalizeMessage(savedMsgs[i2]))) {
|
|
103271
|
+
savedMsgs[i2].processed = true;
|
|
103272
|
+
} else {
|
|
103273
|
+
desyncIndex = i2;
|
|
103274
|
+
break;
|
|
103275
|
+
}
|
|
103276
|
+
}
|
|
103277
|
+
}
|
|
103278
|
+
const newSavedMsgs = savedMsgs.filter((m) => m.processed !== true);
|
|
103279
|
+
if (newSavedMsgs.length > 0 && desyncIndex === -1) {
|
|
103280
|
+
for (let i2 = 0; i2 < newSavedMsgs.length; i2++) {
|
|
103281
|
+
renderMessageInTextChat(newSavedMsgs[i2], true, true);
|
|
103282
|
+
}
|
|
103283
|
+
}
|
|
103284
|
+
if (desyncIndex > -1) {
|
|
103285
|
+
for (let i2 = desyncIndex; i2 < messagesInTheDom.length; i2++) {
|
|
103286
|
+
messagesInTheDom[i2].remove();
|
|
103287
|
+
}
|
|
103288
|
+
textChatMessages = textChatMessages.slice(0, desyncIndex);
|
|
103289
|
+
for (let i2 = desyncIndex; i2 < savedMsgs.length; i2++) {
|
|
103290
|
+
renderMessageInTextChat(savedMsgs[i2], true, true);
|
|
103291
|
+
}
|
|
103292
|
+
}
|
|
103293
|
+
refillCancelMessages(savedMsgs);
|
|
103294
|
+
return;
|
|
103295
|
+
}
|
|
103296
|
+
if (savedMsgs?.length > 0) {
|
|
103297
|
+
clearDOMChat();
|
|
103298
|
+
}
|
|
103299
|
+
for (let i2 = 0; i2 < savedMsgs.length; i2++) {
|
|
103300
|
+
renderMessageInTextChat(savedMsgs[i2], true, true);
|
|
103301
|
+
}
|
|
103302
|
+
refillCancelMessages(savedMsgs);
|
|
103227
103303
|
}
|
|
103228
103304
|
} catch (e) {
|
|
103229
103305
|
console.warn("Alan: unable to restore text chat history");
|
|
@@ -103231,6 +103307,16 @@ ${reason}` : reason,
|
|
|
103231
103307
|
}
|
|
103232
103308
|
}
|
|
103233
103309
|
}
|
|
103310
|
+
function refillCancelMessages(savedMsgs) {
|
|
103311
|
+
for (let i2 = 0; i2 < savedMsgs.length; i2++) {
|
|
103312
|
+
if (savedMsgs[i2].ctx?.cancelled === true) {
|
|
103313
|
+
const reqId = getMsgReqId(savedMsgs[i2]);
|
|
103314
|
+
if (!canceledRequests.includes(reqId)) {
|
|
103315
|
+
canceledRequests.push(reqId);
|
|
103316
|
+
}
|
|
103317
|
+
}
|
|
103318
|
+
}
|
|
103319
|
+
}
|
|
103234
103320
|
function clearChatHistoryStorage() {
|
|
103235
103321
|
if (isTutorMode()) {
|
|
103236
103322
|
return;
|
|
@@ -103665,6 +103751,7 @@ ${reason}` : reason,
|
|
|
103665
103751
|
const textareaEl = getChatTextareaEl();
|
|
103666
103752
|
textareaEl.value = messages[sentMessageInd];
|
|
103667
103753
|
moveCursorToEnd(textareaEl);
|
|
103754
|
+
manageSendButtonAvailability();
|
|
103668
103755
|
}
|
|
103669
103756
|
function moveCursorToEnd(el) {
|
|
103670
103757
|
el.focus();
|