@alan-ai/alan-sdk-web 1.8.46 → 1.8.48
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 +263 -28
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/alan_lib.js
CHANGED
|
@@ -475,6 +475,9 @@
|
|
|
475
475
|
var MIC_ACTIVE = 'micActive';
|
|
476
476
|
var MIC_STOPPED = 'micStopped';
|
|
477
477
|
|
|
478
|
+
var PROCESSING_IDLE = 'processingIdle';
|
|
479
|
+
var PROCESSING_ACTIVE = 'processingActive';
|
|
480
|
+
|
|
478
481
|
var AUDIO_RUNNING = 'audioRunning';
|
|
479
482
|
|
|
480
483
|
var config = {
|
|
@@ -500,6 +503,7 @@
|
|
|
500
503
|
var handlers = {};
|
|
501
504
|
var micState = MIC_STOPPED;
|
|
502
505
|
var playState = PLAY_STOPPED;
|
|
506
|
+
var processingState = PROCESSING_IDLE;
|
|
503
507
|
var audioQueue = [];
|
|
504
508
|
var audioElement = null;
|
|
505
509
|
var audioContext = null;
|
|
@@ -539,7 +543,9 @@
|
|
|
539
543
|
console.log('Alan: audio worker initialized');
|
|
540
544
|
break;
|
|
541
545
|
case 'page':
|
|
542
|
-
|
|
546
|
+
if (playState !== PLAY_ACTIVE && processingState !== PROCESSING_ACTIVE) {
|
|
547
|
+
fireEvent('frame', config.sampleRate, data['page']);
|
|
548
|
+
}
|
|
543
549
|
break;
|
|
544
550
|
case 'done':
|
|
545
551
|
encoder.removeEventListener("message", encoderCallback);
|
|
@@ -611,6 +617,7 @@
|
|
|
611
617
|
}
|
|
612
618
|
|
|
613
619
|
function playAudio(audio) {
|
|
620
|
+
processingState = PROCESSING_IDLE;
|
|
614
621
|
if (isMobileIos) {
|
|
615
622
|
const base64prefix = "data:audio/mpeg;base64,";
|
|
616
623
|
if (audio.startsWith(base64prefix)) {
|
|
@@ -738,6 +745,10 @@
|
|
|
738
745
|
getAudioElement().muted = true;
|
|
739
746
|
};
|
|
740
747
|
|
|
748
|
+
ns.setProcessingState = function() {
|
|
749
|
+
processingState = PROCESSING_ACTIVE;
|
|
750
|
+
};
|
|
751
|
+
|
|
741
752
|
ns.playText = function (text) {
|
|
742
753
|
if (text && text.ctx && text.ctx.opts && text.ctx.opts.force === true) {
|
|
743
754
|
fireEvent('text', text);
|
|
@@ -827,6 +838,7 @@
|
|
|
827
838
|
// if (micState === MIC_ACTIVE) {
|
|
828
839
|
// return;
|
|
829
840
|
// }
|
|
841
|
+
processingState = PROCESSING_IDLE;
|
|
830
842
|
getAudioElement().setAttribute("src", "");
|
|
831
843
|
playState = PLAY_IDLE;
|
|
832
844
|
openMicrophone()
|
|
@@ -954,11 +966,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
954
966
|
return '<div class="alan-btn__chat-incomming-msg-wrapper"> <div class="alan-btn__chat-incomming-msg msg-1"> </div> <div class="alan-btn__chat-incomming-msg msg-2"> </div> <div class="alan-btn__chat-incomming-msg msg-3"> </div> </div>';
|
|
955
967
|
}
|
|
956
968
|
// alan_btn/src/buildMsgIncommingLoader.ts
|
|
957
|
-
function
|
|
969
|
+
function isFinalMessage(msg) {
|
|
958
970
|
var _a;
|
|
971
|
+
return ((_a = msg.ctx) === null || _a === void 0 ? void 0 : _a.final) !== false;
|
|
972
|
+
}
|
|
973
|
+
function buildMsgIncommingLoader(msg) {
|
|
959
974
|
if (msg.initLoad)
|
|
960
975
|
return "";
|
|
961
|
-
return (
|
|
976
|
+
return !isFinalMessage(msg) ? "<div style=\"margin-top: 12px;margin-bottom: 12px;\">".concat(getMsgLoader(), "</div>") : "";
|
|
962
977
|
}
|
|
963
978
|
// node_modules/marked/lib/marked.esm.js
|
|
964
979
|
function getDefaults() {
|
|
@@ -3321,9 +3336,40 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
3321
3336
|
}
|
|
3322
3337
|
return "<svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M7.22602 9.27842L5.17192 11.3326C5.17192 11.3326 5.17192 11.3326 5.17187 11.3326C5.17187 11.3326 5.17187 11.3327 5.17183 11.3327C4.32239 12.1821 2.94018 12.1822 2.09065 11.3327C1.67911 10.9211 1.45252 10.374 1.45252 9.79203C1.45252 9.21015 1.67911 8.66309 2.09051 8.25154C2.09056 8.25149 2.09061 8.25144 2.09065 8.25139L4.14475 6.19725C4.42833 5.91362 4.42833 5.45375 4.1447 5.17017C3.86112 4.88659 3.40126 4.88659 3.11763 5.17017L1.06353 7.22432C1.06339 7.22447 1.06324 7.22466 1.0631 7.2248C0.377557 7.91058 0 8.82233 0 9.79203C0 10.762 0.377702 11.6739 1.06358 12.3597C1.77154 13.0676 2.70139 13.4216 3.63129 13.4216C4.56119 13.4216 5.49109 13.0676 6.19895 12.3597C6.199 12.3597 6.199 12.3596 6.199 12.3596L8.25309 10.3055C8.53667 10.0219 8.53667 9.56205 8.25305 9.27842C7.96951 8.99484 7.5097 8.99484 7.22602 9.27842Z\" fill=\"#919191\"/>\n <path d=\"M13.4249 3.62955C13.4249 2.65961 13.0472 1.74772 12.3613 1.06184C10.9455 -0.353972 8.64171 -0.353923 7.22595 1.06184C7.2259 1.06194 7.2258 1.06199 7.22576 1.06209L5.17171 3.11609C4.88808 3.39967 4.88808 3.85958 5.17171 4.14316C5.31357 4.28502 5.49939 4.35591 5.68527 4.35591C5.87109 4.35591 6.05701 4.28497 6.19878 4.14316L8.25283 2.08916C8.25288 2.08906 8.25297 2.08901 8.25307 2.08892C9.1025 1.23949 10.4847 1.23944 11.3342 2.08892C11.7457 2.50046 11.9724 3.04762 11.9724 3.62955C11.9724 4.21143 11.7458 4.75849 11.3344 5.17004L11.3342 5.17018L9.28014 7.22433C8.99656 7.50791 8.99656 7.96778 9.28019 8.2514C9.42201 8.39322 9.60788 8.46415 9.7937 8.46415C9.97958 8.46415 10.1655 8.39322 10.3073 8.2514L12.3614 6.19726C12.3615 6.19711 12.3617 6.19692 12.3618 6.19677C13.0473 5.51099 13.4249 4.59925 13.4249 3.62955Z\" fill=\"#919191\"/>\n <path d=\"M4.14491 9.27836C4.28672 9.42018 4.4726 9.49111 4.65842 9.49111C4.8443 9.49111 5.03017 9.42018 5.17198 9.27836L9.28028 5.17007C9.56391 4.88649 9.56391 4.42663 9.28028 4.143C8.9967 3.85942 8.53683 3.85942 8.2532 4.143L4.14491 8.25124C3.86128 8.53492 3.86128 8.99479 4.14491 9.27836Z\" fill=\"#919191\"/>\n</svg>";
|
|
3323
3338
|
}
|
|
3339
|
+
// alan_btn/src/replaceAttrInPopupHtml.ts
|
|
3340
|
+
function replaceAttrInPopupHtml(html) {
|
|
3341
|
+
return html.replace(/send-text/gi, "data-alan-btn-send-text").replace(/call-project-api/gi, "data-alan-btn-call-project-api").replace(/project-api-param/gi, "data-alan-btn-project-api-param");
|
|
3342
|
+
}
|
|
3343
|
+
// alan_btn/src/processClickByButtonInPopup.ts
|
|
3344
|
+
function processClickByButtonInPopup(clickedEl, btnInstance, sendTextCall) {
|
|
3345
|
+
var elWithSendText = clickedEl.closest("[data-alan-btn-send-text]");
|
|
3346
|
+
if (elWithSendText) {
|
|
3347
|
+
var text = elWithSendText.getAttribute("data-alan-btn-send-text");
|
|
3348
|
+
if (text) {
|
|
3349
|
+
sendTextCall(text);
|
|
3350
|
+
return;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
var elWithCallProjectApi = clickedEl.closest("[data-alan-btn-call-project-api]");
|
|
3354
|
+
if (elWithCallProjectApi) {
|
|
3355
|
+
var method = elWithCallProjectApi.getAttribute("data-alan-btn-call-project-api");
|
|
3356
|
+
var data = null;
|
|
3357
|
+
try {
|
|
3358
|
+
data = elWithCallProjectApi.getAttribute("data-alan-btn-project-api-param");
|
|
3359
|
+
data = JSON.parse(data);
|
|
3360
|
+
}
|
|
3361
|
+
catch (err) {
|
|
3362
|
+
console.log("Alan: unable to parse params for calling project api method");
|
|
3363
|
+
}
|
|
3364
|
+
if (method) {
|
|
3365
|
+
btnInstance.callProjectApi(method, data);
|
|
3366
|
+
return;
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3324
3370
|
// alan_btn/alan_btn.ts
|
|
3325
3371
|
(function (ns) {
|
|
3326
|
-
var alanButtonVersion = "alan-version.1.8.
|
|
3372
|
+
var alanButtonVersion = "alan-version.1.8.48";
|
|
3327
3373
|
alanButtonVersion = alanButtonVersion.replace("alan-version.", "");
|
|
3328
3374
|
if (window.alanBtn) {
|
|
3329
3375
|
console.warn("Alan: the Alan Button source code has already added (v." + alanButtonVersion + ")");
|
|
@@ -3400,6 +3446,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
3400
3446
|
var textChatOptions = null;
|
|
3401
3447
|
var clearChatIsInProcess = false;
|
|
3402
3448
|
var textChatScrollPosition = null;
|
|
3449
|
+
var sentMessageInd = null;
|
|
3450
|
+
var sentMessages = [];
|
|
3403
3451
|
var defaultMinChatHeight = 400;
|
|
3404
3452
|
var defaultChatHeight = 700;
|
|
3405
3453
|
var defaultMinChatWidth = 250;
|
|
@@ -3967,7 +4015,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
3967
4015
|
}
|
|
3968
4016
|
el.style.display = "flex";
|
|
3969
4017
|
setTimeout(function () {
|
|
3970
|
-
var textareaEl =
|
|
4018
|
+
var textareaEl = getChatTextareaEl();
|
|
3971
4019
|
if (textareaEl && state === DEFAULT) {
|
|
3972
4020
|
textareaEl.focus();
|
|
3973
4021
|
}
|
|
@@ -4594,6 +4642,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
4594
4642
|
}
|
|
4595
4643
|
keyFrames += ".alan-btn__image-preview-overlay {\n position: fixed;\n top: 0;\n left: 0;\n height: 100vh;\n min-height: 100vh;\n width: 100vw;\n min-width: 100vw;\n background-color: rgba(0,0,0,0.6);\n display: flex;\n align-items: center;\n justify-content: center;\n }";
|
|
4596
4644
|
keyFrames += ".alan-btn__image-preview-overlay img {\n max-width: calc(100% - 100px);\n max-height: calc(100% - 100px);\n }";
|
|
4645
|
+
keyFrames += "@media (orientation: landscape) { \n .alan-btn__image-preview-overlay {\n align-items: flex-start;\n padding-top: 40px;\n }\n .alan-btn__image-preview-overlay img {\n max-height: calc(100% - 120px);\n }\n .alan-btn__image-preview-overlay iframe {\n max-height: calc(100% - 120px);\n }\n }";
|
|
4646
|
+
keyFrames += ".alan-btn__image-preview-overlay iframe {\n max-width: calc(100% - 100px);\n max-height: calc(100% - 100px);\n width: calc(100% - 100px);\n height: calc(100% - 100px);\n }";
|
|
4597
4647
|
keyFrames += ".alan-btn__image-preview-overlay-close-icon {\n position: absolute;\n top: 16px;\n right: 16px;\n cursor: pointer;\n opacity: 0.7;\n }";
|
|
4598
4648
|
if (!isMobile()) {
|
|
4599
4649
|
keyFrames += ".alan-btn__image-preview-overlay-close-icon:hover {\n opacity: 1;\n }";
|
|
@@ -4685,7 +4735,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
4685
4735
|
"img {\n max-width: 100%!important;\n pointer-events: auto!important;\n cursor: pointer;\n }",
|
|
4686
4736
|
"code {\n background-color: #F8F8F8!important;\n border-radius: 3px!important;\n border: 1px solid #DDD!important;\n font-family: Consolas, \"Liberation Mono\", Courier, monospace!important;\n margin: 0 2px!important;\n padding: 0 5px!important;\n white-space: pre-line!important;\n font-size: ".concat(responseBubbleFontSize, "px!important;\n }"),
|
|
4687
4737
|
"pre {\n background-color: #F8F8F8!important;\n border-radius: 3px!important;\n border: 1px solid #DDD!important;\n font-family: Consolas, \"Liberation Mono\", Courier, monospace!important;\n padding: 0 5px!important;\n white-space: pre-line!important;\n font-size: ".concat(responseBubbleFontSize, "px!important;\n }"),
|
|
4688
|
-
"pre code {\n border: none!important;\n margin: 0!important;\n padding: 0!important;\n white-space: pre-
|
|
4738
|
+
"pre code {\n border: none!important;\n margin: 0!important;\n padding: 0!important;\n white-space: pre-wrap!important;\n font-size: ".concat(responseBubbleFontSize, "px!important;\n }"),
|
|
4689
4739
|
"hr {\n display: block!important;\n unicode-bidi: isolate!important;\n margin-block-start: 0.5em!important;\n margin-block-end: 0.5em!important;\n margin-inline-start: auto!important;\n margin-inline-end: auto!important;\n overflow: hidden!important;\n border-style: inset!important;\n border-width: 1px!important;\n }",
|
|
4690
4740
|
"blockquote {\n padding: 5px 20px 0!important;\n border-left: 5px solid #beb7b7!important;\n font-size: ".concat(responseBubbleFontSize, "px!important;\n }"),
|
|
4691
4741
|
"table > tbody > tr > td {\n background-color: #fff!important;\n color: #000!important;\n }",
|
|
@@ -4702,6 +4752,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
4702
4752
|
keyFrames += getStyleSheetMarker(true) + ".hide-alan-btn-when-text-chat-is-opened .alanBtn {\n transform: scale(0);\n opacity: 0;\n animation: text-chat-disappear-anim ".concat(textChatAppearAnimationMs, "ms ease-in-out forwards;\n }");
|
|
4703
4753
|
keyFrames += getStyleSheetMarker(true) + ".text-chat-is-closing .alanBtn {\n transform: scale(0);\n opacity: 0;\n animation: text-chat-appear-anim ".concat(textChatAppearAnimationMs, "ms ease-in-out forwards;\n }");
|
|
4704
4754
|
keyFrames += getStyleSheetMarker(true) + ".hide-alan-btn-when-text-chat-is-opened .alanBtn-recognised-text-holder {\n display: none;\n }";
|
|
4755
|
+
keyFrames += getStyleSheetMarker() + " mjx-container svg {\n max-width: 100%;\n }";
|
|
4705
4756
|
keyFrames += getStyleSheetMarker() + ".alan-overlay {position: fixed;top: 0;left: 0;right: 0;bottom: 0;z-index: 99;background: rgba(0, 0, 0, 0.57);opacity: 0;-webkit-animation: alan-fade-in 0.5s 0.2s forwards;-moz-animation: alan-fade-in 0.5s 0.2s forwards;-o-animation: alan-fade-in 0.5s 0.2s forwards;animation: alan-fade-in 0.5s 0.2s forwards;}";
|
|
4706
4757
|
keyFrames += getStyleSheetMarker() + ".alan-overlay-popup.alan-btn-lib__default-popup {border-radius:10px; box-shadow: 0px 5px 14px rgba(3, 3, 3, 0.25);padding:6px 30px 6px 12px;text-align: left;width: 220px;background: rgb(255 255 255);}";
|
|
4707
4758
|
keyFrames += getStyleSheetMarker() + ".alan-overlay-popup.alan-btn-lib__top.alan-btn-lib__right {border-top-right-radius: 0!important;}";
|
|
@@ -5184,11 +5235,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
5184
5235
|
if (popupOptions.type !== "chat" && isMobile()) {
|
|
5185
5236
|
return;
|
|
5186
5237
|
}
|
|
5238
|
+
if (popupOptions && popupOptions.html) {
|
|
5239
|
+
popupOptions.html = replaceAttrInPopupHtml(popupOptions.html);
|
|
5240
|
+
}
|
|
5187
5241
|
if (options2.onEvent) {
|
|
5188
5242
|
options2.onEvent(Object.assign(p, { name: "popup" }));
|
|
5189
5243
|
}
|
|
5190
5244
|
if (p) {
|
|
5191
|
-
showPopup(
|
|
5245
|
+
showPopup(popupOptions);
|
|
5192
5246
|
}
|
|
5193
5247
|
}
|
|
5194
5248
|
function addPopupStyle(popupOptions, popup) {
|
|
@@ -5528,6 +5582,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
5528
5582
|
curDialogId = dialogId;
|
|
5529
5583
|
saveDialogId(dialogId);
|
|
5530
5584
|
restoreMessageList(true);
|
|
5585
|
+
sentMessages = restoreSentMessages();
|
|
5531
5586
|
}
|
|
5532
5587
|
if (options2.onConnectionStatus) {
|
|
5533
5588
|
options2.onConnectionStatus(res);
|
|
@@ -5730,6 +5785,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
5730
5785
|
text: "",
|
|
5731
5786
|
reqId: event.reqId
|
|
5732
5787
|
});
|
|
5788
|
+
alanAudio.setProcessingState();
|
|
5733
5789
|
}
|
|
5734
5790
|
turnOffVoiceFn();
|
|
5735
5791
|
}
|
|
@@ -5824,7 +5880,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
5824
5880
|
return resultStr;
|
|
5825
5881
|
}
|
|
5826
5882
|
function renderInterimForTextChat(msg) {
|
|
5827
|
-
var textarea =
|
|
5883
|
+
var textarea = getChatTextareaEl();
|
|
5828
5884
|
if (textarea) {
|
|
5829
5885
|
if (msg.final === true) {
|
|
5830
5886
|
renderMessageInTextChat(msg);
|
|
@@ -5840,8 +5896,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
5840
5896
|
imgPreviewOverlayEl.id = "img-preview-overlay";
|
|
5841
5897
|
imgPreviewOverlayEl.classList.add("alan-btn__image-preview-overlay");
|
|
5842
5898
|
imgPreviewOverlayEl.style.zIndex = btnZIndex + 3;
|
|
5843
|
-
|
|
5844
|
-
|
|
5899
|
+
if (parentEl) {
|
|
5900
|
+
imgPreviewOverlayEl.setAttribute("data-img-index", parentEl.getAttribute("data-img-index"));
|
|
5901
|
+
imgPreviewOverlayEl.setAttribute("data-msg-req-id", parentEl.getAttribute("data-msg-req-id"));
|
|
5902
|
+
}
|
|
5845
5903
|
var imgPreviewOverlayCloseIcon = document.createElement("div");
|
|
5846
5904
|
imgPreviewOverlayCloseIcon.id = "img-preview-overlay__close-icon";
|
|
5847
5905
|
imgPreviewOverlayCloseIcon.innerHTML = "\n <svg width=\"17\" height=\"17\" viewBox=\"0 0 17 17\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0.342029 15.0105C-0.113105 15.4658 -0.113035 16.2036 0.34217 16.6587C0.797374 17.1138 1.53533 17.1138 1.99046 16.6586L8.50015 10.1482L15.0104 16.658C15.4655 17.1131 16.2035 17.1131 16.6586 16.658C17.1138 16.2029 17.1138 15.4649 16.6586 15.0098L10.1483 8.49998L16.6582 1.98944C17.1132 1.53427 17.1132 0.796371 16.6579 0.341282C16.2028 -0.113819 15.4648 -0.113749 15.0097 0.341421L8.49991 6.85183L1.98966 0.341981C1.5345 -0.113143 0.796535 -0.113143 0.341377 0.341981C-0.113792 0.797116 -0.113792 1.53502 0.341377 1.99016L6.85187 8.5001L0.342029 15.0105Z\" fill=\"#FFFFFF\"/>\n</svg>\n";
|
|
@@ -6071,8 +6129,77 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6071
6129
|
function buildMsgContent(msg) {
|
|
6072
6130
|
return "".concat(buildImagesContent(msg)).concat(buildMsgTextContent(msg)).concat(buildLinksContent(msg)).concat(buildLikesContent(msg)).concat(buildMsgIncommingLoader(msg));
|
|
6073
6131
|
}
|
|
6132
|
+
function highlightCode() {
|
|
6133
|
+
if (window.hljs) {
|
|
6134
|
+
setTimeout(function () {
|
|
6135
|
+
var msgHolder = document.getElementById("chatMessages");
|
|
6136
|
+
if (msgHolder) {
|
|
6137
|
+
msgHolder.querySelectorAll("pre code:not(.alan-btn__hljs-processed)").forEach(function (el) {
|
|
6138
|
+
window.hljs.highlightElement(el);
|
|
6139
|
+
el.classList.add("alan-btn__hljs-processed");
|
|
6140
|
+
});
|
|
6141
|
+
}
|
|
6142
|
+
});
|
|
6143
|
+
}
|
|
6144
|
+
}
|
|
6145
|
+
function loadHighlightJs() {
|
|
6146
|
+
var script = document.createElement("script");
|
|
6147
|
+
script.src = "https://studio.alan.app/js/hljs/highlight.min.js?v=1";
|
|
6148
|
+
script.async = true;
|
|
6149
|
+
script.onload = function () {
|
|
6150
|
+
highlightCode();
|
|
6151
|
+
};
|
|
6152
|
+
document.head.appendChild(script);
|
|
6153
|
+
var link = document.createElement("link");
|
|
6154
|
+
link.rel = "stylesheet";
|
|
6155
|
+
link.href = "https://studio.alan.app/js/hljs/github.min.css?v=1";
|
|
6156
|
+
document.getElementsByTagName("head")[0].appendChild(link);
|
|
6157
|
+
}
|
|
6158
|
+
loadHighlightJs();
|
|
6159
|
+
function loadMathJax() {
|
|
6160
|
+
window.MathJax = {
|
|
6161
|
+
startup: {
|
|
6162
|
+
pageReady: function () {
|
|
6163
|
+
return window.MathJax.startup.defaultPageReady();
|
|
6164
|
+
}
|
|
6165
|
+
},
|
|
6166
|
+
tex: {
|
|
6167
|
+
inlineMath: [["$", "$"], ["\\(", "\\)"]],
|
|
6168
|
+
processEscapes: true
|
|
6169
|
+
}
|
|
6170
|
+
};
|
|
6171
|
+
var script = document.createElement("script");
|
|
6172
|
+
script.src = "https://studio.alan.app/js/mathjax/tex-svg.js?v=1";
|
|
6173
|
+
script.async = true;
|
|
6174
|
+
script.setAttribute("id", "MathJax-script");
|
|
6175
|
+
script.onload = function () {
|
|
6176
|
+
processFormulasInMsgs();
|
|
6177
|
+
};
|
|
6178
|
+
document.head.appendChild(script);
|
|
6179
|
+
}
|
|
6180
|
+
loadMathJax();
|
|
6181
|
+
function processFormulas(msgInd) {
|
|
6182
|
+
var MathJax = window.MathJax;
|
|
6183
|
+
if (MathJax) {
|
|
6184
|
+
setTimeout(function () {
|
|
6185
|
+
var output = document.getElementById("msg-" + msgInd).querySelectorAll(".alan-btn__chat-response-text-wrapper")[0];
|
|
6186
|
+
if (output && MathJax.texReset) {
|
|
6187
|
+
MathJax.texReset();
|
|
6188
|
+
MathJax.typesetClear();
|
|
6189
|
+
MathJax.typesetPromise([output])["catch"](function (err) {
|
|
6190
|
+
console.error(err);
|
|
6191
|
+
});
|
|
6192
|
+
}
|
|
6193
|
+
});
|
|
6194
|
+
}
|
|
6195
|
+
}
|
|
6196
|
+
function processFormulasInMsgs() {
|
|
6197
|
+
for (var i2 = 0; i2 < textChatMessages.length; i2++) {
|
|
6198
|
+
processFormulas(i2);
|
|
6199
|
+
}
|
|
6200
|
+
}
|
|
6074
6201
|
function renderMessageInTextChat(msg, noAnimation, immidiateScroll) {
|
|
6075
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
6202
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
6076
6203
|
if (!textChatIsAvailable)
|
|
6077
6204
|
return;
|
|
6078
6205
|
var innerMsgPart = "";
|
|
@@ -6113,7 +6240,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6113
6240
|
}
|
|
6114
6241
|
}
|
|
6115
6242
|
msg = __assign(__assign({}, msg), getMsgReadProp(msg, textChatIsHidden));
|
|
6116
|
-
var
|
|
6243
|
+
var _p = processMessageForChat(msg, textChatMessages), isNew = _p.isNew, msgInd = _p.msgInd, replaceLoader = _p.replaceLoader, updateResponse = _p.updateResponse;
|
|
6117
6244
|
if (isNew) {
|
|
6118
6245
|
var div = document.createElement("div");
|
|
6119
6246
|
div.id = "msg-" + msgInd;
|
|
@@ -6131,6 +6258,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6131
6258
|
else {
|
|
6132
6259
|
scrollTextChat(msgHolder);
|
|
6133
6260
|
}
|
|
6261
|
+
if (((_g = msg.ctx) === null || _g === void 0 ? void 0 : _g.final) !== false) {
|
|
6262
|
+
processFormulas(msgInd);
|
|
6263
|
+
highlightCode();
|
|
6264
|
+
}
|
|
6134
6265
|
}
|
|
6135
6266
|
else {
|
|
6136
6267
|
var msgEl = document.getElementById("msg-" + msgInd);
|
|
@@ -6140,7 +6271,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6140
6271
|
if (innerEl) {
|
|
6141
6272
|
innerEl.innerHTML = innerMsgPart;
|
|
6142
6273
|
innerEl.classList.remove("alan-incoming-msg");
|
|
6143
|
-
if (msg.type !== "chat" && ((
|
|
6274
|
+
if (msg.type !== "chat" && ((_h = msg.images) === null || _h === void 0 ? void 0 : _h.length) > 0) {
|
|
6144
6275
|
innerEl.classList.add("with-images");
|
|
6145
6276
|
}
|
|
6146
6277
|
scrollTextChat(msgHolder, "smooth");
|
|
@@ -6150,18 +6281,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6150
6281
|
var innerEl = msgEl.children[0];
|
|
6151
6282
|
var updatedMsg = textChatMessages[msgInd];
|
|
6152
6283
|
var imagesWrapper = innerEl.querySelector(".alan-btn__chat-response-imgs-wrapper");
|
|
6153
|
-
if (((
|
|
6284
|
+
if (((_j = updatedMsg.images) === null || _j === void 0 ? void 0 : _j.length) > 0 && !imagesWrapper) {
|
|
6154
6285
|
innerEl.insertAdjacentHTML("afterbegin", buildImagesContent(updatedMsg));
|
|
6155
6286
|
innerEl = msgEl.children[0];
|
|
6156
6287
|
}
|
|
6157
|
-
if (((
|
|
6288
|
+
if (((_k = updatedMsg.images) === null || _k === void 0 ? void 0 : _k.length) > 1 && imagesWrapper) {
|
|
6158
6289
|
imagesWrapper.querySelector(".alan-btn__chat-response-imgs-wrapper-right-arrow").classList.remove("invisible");
|
|
6159
6290
|
}
|
|
6160
|
-
if (updatedMsg.type !== "chat" && ((
|
|
6291
|
+
if (updatedMsg.type !== "chat" && ((_l = updatedMsg.images) === null || _l === void 0 ? void 0 : _l.length) > 0) {
|
|
6161
6292
|
innerEl.classList.add("with-images");
|
|
6162
6293
|
}
|
|
6163
6294
|
var msgParts = innerEl.children;
|
|
6164
|
-
var stop_1 = ((
|
|
6295
|
+
var stop_1 = ((_m = updatedMsg.images) === null || _m === void 0 ? void 0 : _m.length) === 0 ? 0 : 1;
|
|
6165
6296
|
while (msgParts.length > stop_1) {
|
|
6166
6297
|
msgParts[msgParts.length - 1].remove();
|
|
6167
6298
|
}
|
|
@@ -6177,11 +6308,20 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6177
6308
|
msgEl.innerHTML = msgHtml;
|
|
6178
6309
|
}
|
|
6179
6310
|
}
|
|
6311
|
+
if (((_o = msg.ctx) === null || _o === void 0 ? void 0 : _o.final) !== false) {
|
|
6312
|
+
processFormulas(msgInd);
|
|
6313
|
+
highlightCode();
|
|
6314
|
+
}
|
|
6180
6315
|
}
|
|
6181
6316
|
saveMessageHistory();
|
|
6182
6317
|
if (textChatIsAvailable && textChatIsHidden) {
|
|
6183
6318
|
showChatNotifications();
|
|
6184
6319
|
}
|
|
6320
|
+
if (isFinalMessage(msg) && msg.type === "response" && textChatMessages.filter(function (m) { return !isFinalMessage(m); }).length === 0) {
|
|
6321
|
+
if (msg.name !== "loading") {
|
|
6322
|
+
enableTextareaInTheChat();
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6185
6325
|
}
|
|
6186
6326
|
function scrollTextChat(msgHolder, behavior) {
|
|
6187
6327
|
var scrollOptions = {
|
|
@@ -6299,6 +6439,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6299
6439
|
case 1:
|
|
6300
6440
|
res = _a.sent();
|
|
6301
6441
|
msg = __assign(__assign({}, msg), { reqId: res.reqId });
|
|
6442
|
+
saveSentMessages(text);
|
|
6302
6443
|
renderMessageInTextChat(msg);
|
|
6303
6444
|
renderMessageInTextChat({
|
|
6304
6445
|
type: "response",
|
|
@@ -6312,20 +6453,24 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6312
6453
|
});
|
|
6313
6454
|
}
|
|
6314
6455
|
var lastSendMsgTs = null;
|
|
6456
|
+
function enableTextareaInTheChat() {
|
|
6457
|
+
var textareaHolderEl = document.getElementById("textarea-holder");
|
|
6458
|
+
textareaHolderEl.classList.remove("alan-btn__inactive");
|
|
6459
|
+
clearTimeout(lastSendMsgTs);
|
|
6460
|
+
lastSendMsgTs = null;
|
|
6461
|
+
}
|
|
6315
6462
|
var sendMessageToTextChat = throttle(function sendMessageToTextChat2() {
|
|
6316
6463
|
return __awaiter(this, void 0, void 0, function () {
|
|
6317
6464
|
var textareaEl, textareaHolderEl, text;
|
|
6318
6465
|
return __generator(this, function (_a) {
|
|
6319
|
-
textareaEl =
|
|
6466
|
+
textareaEl = getChatTextareaEl();
|
|
6320
6467
|
textareaHolderEl = document.getElementById("textarea-holder");
|
|
6321
6468
|
text = textareaEl.value;
|
|
6322
6469
|
if (lastSendMsgTs) {
|
|
6323
6470
|
return [2 /*return*/];
|
|
6324
6471
|
}
|
|
6325
6472
|
lastSendMsgTs = setTimeout(function () {
|
|
6326
|
-
|
|
6327
|
-
clearTimeout(lastSendMsgTs);
|
|
6328
|
-
lastSendMsgTs = null;
|
|
6473
|
+
enableTextareaInTheChat();
|
|
6329
6474
|
}, 5e3);
|
|
6330
6475
|
if (text.trim() === "")
|
|
6331
6476
|
return [2 /*return*/];
|
|
@@ -6368,6 +6513,72 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6368
6513
|
}
|
|
6369
6514
|
}
|
|
6370
6515
|
}
|
|
6516
|
+
function getRestoreMsgsLsKey() {
|
|
6517
|
+
var projectId = getProjectId();
|
|
6518
|
+
return "alan-btn-chat-sent-history-".concat(projectId);
|
|
6519
|
+
}
|
|
6520
|
+
function restoreSentMessages() {
|
|
6521
|
+
var messages = [];
|
|
6522
|
+
if (isLocalStorageAvailable) {
|
|
6523
|
+
var key = getRestoreMsgsLsKey();
|
|
6524
|
+
try {
|
|
6525
|
+
messages = JSON.parse(localStorage.getItem(key)) || [];
|
|
6526
|
+
}
|
|
6527
|
+
catch (e) {
|
|
6528
|
+
}
|
|
6529
|
+
}
|
|
6530
|
+
return messages;
|
|
6531
|
+
}
|
|
6532
|
+
function saveSentMessages(text) {
|
|
6533
|
+
if (isLocalStorageAvailable) {
|
|
6534
|
+
var maxSavedForHistoryMsgCount = 25;
|
|
6535
|
+
var key = getRestoreMsgsLsKey();
|
|
6536
|
+
sentMessages.push(text);
|
|
6537
|
+
if (sentMessages.length > 50) {
|
|
6538
|
+
sentMessages = sentMessages.slice(Math.max(sentMessages.length - maxSavedForHistoryMsgCount, 0));
|
|
6539
|
+
}
|
|
6540
|
+
if (sentMessages.length > 0) {
|
|
6541
|
+
localStorage.setItem(key, JSON.stringify(sentMessages));
|
|
6542
|
+
}
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
function switchMessages(keyCode) {
|
|
6546
|
+
var messages = __spreadArray([], sentMessages, true);
|
|
6547
|
+
messages = messages.reverse();
|
|
6548
|
+
if (messages.length === 0) {
|
|
6549
|
+
return;
|
|
6550
|
+
}
|
|
6551
|
+
if (keyCode === 38) {
|
|
6552
|
+
if (sentMessageInd === null || sentMessageInd + 1 === messages.length) {
|
|
6553
|
+
sentMessageInd = 0;
|
|
6554
|
+
}
|
|
6555
|
+
else {
|
|
6556
|
+
sentMessageInd = sentMessageInd + 1;
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6559
|
+
if (keyCode === 40) {
|
|
6560
|
+
if (sentMessageInd === null || sentMessageInd - 1 === -1) {
|
|
6561
|
+
sentMessageInd = messages.length - 1;
|
|
6562
|
+
}
|
|
6563
|
+
else {
|
|
6564
|
+
sentMessageInd = sentMessageInd - 1;
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
var textareaEl = getChatTextareaEl();
|
|
6568
|
+
textareaEl.value = messages[sentMessageInd];
|
|
6569
|
+
moveCursorToEnd(textareaEl);
|
|
6570
|
+
}
|
|
6571
|
+
function moveCursorToEnd(el) {
|
|
6572
|
+
el.focus();
|
|
6573
|
+
if (typeof el.selectionStart == "number") {
|
|
6574
|
+
el.selectionStart = el.selectionEnd = el.value.length;
|
|
6575
|
+
}
|
|
6576
|
+
else if (typeof el.createTextRange != "undefined") {
|
|
6577
|
+
var range = el.createTextRange();
|
|
6578
|
+
range.collapse(false);
|
|
6579
|
+
range.select();
|
|
6580
|
+
}
|
|
6581
|
+
}
|
|
6371
6582
|
function onChatTextAreaKeyDown(e) {
|
|
6372
6583
|
var keyCode = e.keyCode || e.which;
|
|
6373
6584
|
if (keyCode === 13 && e.shiftKey) {
|
|
@@ -6382,6 +6593,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6382
6593
|
e.stopPropagation();
|
|
6383
6594
|
e.preventDefault();
|
|
6384
6595
|
}
|
|
6596
|
+
var goToPrev = keyCode === 38;
|
|
6597
|
+
var goToNext = keyCode === 40;
|
|
6598
|
+
if (goToPrev || goToNext) {
|
|
6599
|
+
switchMessages(keyCode);
|
|
6600
|
+
e.stopPropagation();
|
|
6601
|
+
e.preventDefault();
|
|
6602
|
+
return;
|
|
6603
|
+
}
|
|
6385
6604
|
}
|
|
6386
6605
|
function disableVoiceEnabledBtn() {
|
|
6387
6606
|
var muteAlanBtn = document.getElementById("chat-unmute-btn");
|
|
@@ -6425,7 +6644,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6425
6644
|
}
|
|
6426
6645
|
function hideKeyboard() {
|
|
6427
6646
|
if (isMobile()) {
|
|
6428
|
-
var chatTextarea =
|
|
6647
|
+
var chatTextarea = getChatTextareaEl();
|
|
6429
6648
|
if (chatTextarea) {
|
|
6430
6649
|
chatTextarea.blur();
|
|
6431
6650
|
}
|
|
@@ -6440,10 +6659,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6440
6659
|
}
|
|
6441
6660
|
}
|
|
6442
6661
|
}
|
|
6662
|
+
function onMessageClickListener(e) {
|
|
6663
|
+
var clickedEl = e.target;
|
|
6664
|
+
processClickByButtonInPopup(clickedEl, btnInstance, _sendText);
|
|
6665
|
+
}
|
|
6666
|
+
function getChatTextareaEl() {
|
|
6667
|
+
return document.getElementById("chatTextarea");
|
|
6668
|
+
}
|
|
6443
6669
|
function initTextChat() {
|
|
6444
6670
|
var _a, _b, _c;
|
|
6445
6671
|
var textareaDiv = document.getElementById("textarea-holder");
|
|
6446
|
-
var chatTextarea =
|
|
6672
|
+
var chatTextarea = getChatTextareaEl();
|
|
6447
6673
|
var chatMicBtn = document.getElementById("chat-mic-btn");
|
|
6448
6674
|
var unmuteAlanBtn = document.getElementById("chat-unmute-btn");
|
|
6449
6675
|
var chatSendBtn = document.getElementById("chat-send-btn");
|
|
@@ -6455,6 +6681,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
6455
6681
|
var messagesDiv = document.createElement("div");
|
|
6456
6682
|
messagesDiv.id = "chatMessages";
|
|
6457
6683
|
messagesDiv.classList.add("alan-btn__chat-messages");
|
|
6684
|
+
messagesDiv.removeEventListener("click", onMessageClickListener);
|
|
6685
|
+
messagesDiv.addEventListener("click", onMessageClickListener);
|
|
6458
6686
|
var messagesWrapperDiv = document.createElement("div");
|
|
6459
6687
|
messagesWrapperDiv.id = "chatMessagesWrapper";
|
|
6460
6688
|
messagesWrapperDiv.classList.add("alan-btn__chat-messages-wrapper");
|
|
@@ -7436,7 +7664,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7436
7664
|
return null;
|
|
7437
7665
|
}
|
|
7438
7666
|
var pageScrolled = false;
|
|
7439
|
-
|
|
7667
|
+
if (isMobile()) {
|
|
7668
|
+
window.addEventListener("scroll", onPageScroll);
|
|
7669
|
+
}
|
|
7440
7670
|
var managePageScrollFlag = debounce(function () {
|
|
7441
7671
|
pageScrolled = false;
|
|
7442
7672
|
rootEl.classList.remove("alan-btn__page-scrolled");
|
|
@@ -7454,6 +7684,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7454
7684
|
var dndInitMousePos = [0, 0];
|
|
7455
7685
|
var chatHeight, chatWidth, typeBorderHor, typeBorderVert;
|
|
7456
7686
|
var chatInitLeftPos, chatInitRightPos, chatInitTopPos, chatInitBottomPos;
|
|
7687
|
+
var chatTopPosBeforeResize;
|
|
7688
|
+
var chatBottomPosBeforeResize;
|
|
7457
7689
|
var chatRightAligned, chatLeftAligned, chatTopAligned, chatBottomAligned;
|
|
7458
7690
|
if (!isMobile()) {
|
|
7459
7691
|
chatHolderDiv.addEventListener("mousedown", onMouseDownForResizeTextChat);
|
|
@@ -7496,14 +7728,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7496
7728
|
posInfo.clientX,
|
|
7497
7729
|
posInfo.clientY
|
|
7498
7730
|
];
|
|
7499
|
-
|
|
7500
|
-
|
|
7731
|
+
var chatRect = chatHolderDiv.getBoundingClientRect();
|
|
7732
|
+
chatHeight = chatRect.height;
|
|
7733
|
+
chatWidth = chatRect.width;
|
|
7501
7734
|
typeBorderHor = getBorderType(posInfo).typeBorderHor;
|
|
7502
7735
|
typeBorderVert = getBorderType(posInfo).typeBorderVert;
|
|
7503
7736
|
chatInitLeftPos = parseInt(chatHolderDiv.style.left);
|
|
7504
7737
|
chatInitRightPos = parseInt(chatHolderDiv.style.right);
|
|
7505
7738
|
chatInitTopPos = parseInt(chatHolderDiv.style.top);
|
|
7506
7739
|
chatInitBottomPos = parseInt(chatHolderDiv.style.bottom);
|
|
7740
|
+
chatTopPosBeforeResize = chatRect.top;
|
|
7741
|
+
chatBottomPosBeforeResize = chatRect.bottom;
|
|
7507
7742
|
chatRightAligned = chatHolderDiv.style.right;
|
|
7508
7743
|
chatLeftAligned = chatHolderDiv.style.left;
|
|
7509
7744
|
chatTopAligned = chatHolderDiv.style.top;
|
|
@@ -7556,8 +7791,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7556
7791
|
var minChatHeight = ((_a = textChatOptions === null || textChatOptions === void 0 ? void 0 : textChatOptions.popup) === null || _a === void 0 ? void 0 : _a.minHeight) || defaultMinChatHeight;
|
|
7557
7792
|
var expanding = borderType === "bottom" && delta > 0 || borderType === "top" && delta < 0;
|
|
7558
7793
|
var h = borderType === "bottom" ? chatHeight + delta : chatHeight - delta;
|
|
7559
|
-
var newBottomtPos =
|
|
7560
|
-
var newTopPos =
|
|
7794
|
+
var newBottomtPos = chatBottomPosBeforeResize - delta;
|
|
7795
|
+
var newTopPos = chatTopPosBeforeResize + delta;
|
|
7561
7796
|
if (borderType === "bottom" && newBottomtPos <= 0 && h >= chatHeight) {
|
|
7562
7797
|
return false;
|
|
7563
7798
|
}
|