@alan-ai/alan-sdk-web 1.8.83 → 1.8.85

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.
@@ -21,6 +21,7 @@ export interface AlanButton {
21
21
  isAudioOutputEnabled: () => boolean,
22
22
  setFullScreenMode: (value: boolean) => void,
23
23
  close: () => void,
24
+ minimize: () => void,
24
25
  open: () => void,
25
26
  clear: () => void,
26
27
  };
@@ -1,6 +1,7 @@
1
1
  export interface AlanButtonOptions {
2
2
  key: string;
3
3
  rootEl?: HTMLElement | undefined;
4
+ chatEl?: HTMLElement | undefined;
4
5
  right?: number | string;
5
6
  bottom?: number | string;
6
7
  left?: number | string;
@@ -16,8 +17,12 @@ export interface AlanButtonOptions {
16
17
  onEvent?: (event: object) => void;
17
18
  onButtonState?: (state: string) => void;
18
19
  onConnectionStatus?: (status: string) => void;
19
- textChat: {
20
+ textChat?: {
21
+ closeDelay?: number;
22
+ showBtnIfChatOpen?: boolean;
23
+ openByDefault?: boolean;
20
24
  onClose?: () => void;
21
25
  onMinimize?: () => void;
26
+ onOpen?: () => void;
22
27
  }
23
28
  }
package/dist/alan_lib.js CHANGED
@@ -90534,6 +90534,14 @@
90534
90534
  };
90535
90535
  }
90536
90536
 
90537
+ // alan_btn/src/helpers/mini/guid.ts
90538
+ function guid() {
90539
+ function s4() {
90540
+ return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
90541
+ }
90542
+ return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
90543
+ }
90544
+
90537
90545
  // alan_btn/src/textChat/helpers/mergeProgressiveMessages.ts
90538
90546
  function mergeProgressiveMessages(messages, i, message) {
90539
90547
  const maxLinksCount = 9;
@@ -90543,6 +90551,20 @@
90543
90551
  messages[i].text = oldText + newText;
90544
90552
  messages[i].images = [...messages[i].images || [], ...newImages];
90545
90553
  messages[i].links = [...messages[i].links || [], ...message.links || []].splice(0, maxLinksCount);
90554
+ if (!messages[i].parts) {
90555
+ messages[i].parts = [];
90556
+ }
90557
+ const msgPart = getMsgPart(newText);
90558
+ if (msgPart.type === "iframe") {
90559
+ messages[i].parts.push(msgPart);
90560
+ } else {
90561
+ const lastPart = messages[i].parts.at(-1);
90562
+ if (lastPart && lastPart.type === "text") {
90563
+ lastPart.chunks.push(msgPart.chunks[0]);
90564
+ } else {
90565
+ messages[i].parts.push(msgPart);
90566
+ }
90567
+ }
90546
90568
  if (message.ctx?.format === "markdown") {
90547
90569
  if (messages[i].ctx) {
90548
90570
  messages[i].ctx.format = "markdown";
@@ -90554,6 +90576,18 @@
90554
90576
  messages[i].ctx.final = message.ctx?.final;
90555
90577
  }
90556
90578
  }
90579
+ function getMsgPart(text) {
90580
+ const iframeRegex = /<iframe[^>]*src=["']([^"']+)["'][^>]*>(.*?)<\/iframe>/gis;
90581
+ let match = iframeRegex.exec(text);
90582
+ if (match) {
90583
+ return { id: guid(), chunks: [text], type: "iframe", src: match[1] };
90584
+ }
90585
+ return {
90586
+ id: guid(),
90587
+ chunks: [text],
90588
+ type: "text"
90589
+ };
90590
+ }
90557
90591
 
90558
90592
  // alan_btn/src/textChat/helpers/processMessageForChat.ts
90559
90593
  var import_lodash = __toESM(require_lodash());
@@ -90778,14 +90812,6 @@
90778
90812
  }
90779
90813
  }
90780
90814
 
90781
- // alan_btn/src/helpers/mini/guid.ts
90782
- function guid() {
90783
- function s4() {
90784
- return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
90785
- }
90786
- return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
90787
- }
90788
-
90789
90815
  // alan_btn/src/helpers/mini/isStorageAvailable.ts
90790
90816
  var _isLocalStorageAvailable = false;
90791
90817
  try {
@@ -91727,6 +91753,10 @@
91727
91753
  opacity: 0;
91728
91754
  animation: text-chat-appear-anim ${textChatAppearAnimationMs}ms ease-in-out forwards;
91729
91755
  }`;
91756
+ keyFrames += getStyleSheetMarker() + `.alan-text-chat__openning-immidiately {
91757
+ opacity: 1;
91758
+ transform: scale(1);
91759
+ }`;
91730
91760
  keyFrames += getStyleSheetMarker() + generateKeyFrame(
91731
91761
  "text-chat-appear-anim",
91732
91762
  `
@@ -93916,6 +93946,7 @@
93916
93946
  style.setAttribute("id", "alan-stylesheet-" + projectId);
93917
93947
  style.type = "text/css";
93918
93948
  keyFrames += `.alanBtn-root * { box-sizing: border-box; font-family: ${webOptions?.chatOptions?.textChat?.popup?.fontFamily || "Poppins"}; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}`;
93949
+ keyFrames += `.alanBtn-chat-root-inlined {height: 100%;}`;
93919
93950
  var hoverSelector = !isMobile() ? ":hover" : ":active";
93920
93951
  if (!isMobile()) {
93921
93952
  keyFrames += getStyleSheetMarker() + ".alanBtn{transform: scale(1); transition: " + transitionCss + ";} .alanBtn" + hoverSelector + "{transform: scale(1.11111);transition:" + transitionCss + ";}.alanBtn:focus {transform: scale(1);" + transitionCss + "; border: solid 3px #50e3c2; outline: none; }";
@@ -95012,7 +95043,7 @@ code.hljs {
95012
95043
  // alan_btn/alan_btn.ts
95013
95044
  var import_sjcl = __toESM(require_sjcl());
95014
95045
  (function(ns) {
95015
- uiState.lib.version = "alan-version.1.8.83".replace("alan-version.", "");
95046
+ uiState.lib.version = "alan-version.1.8.85".replace("alan-version.", "");
95016
95047
  if (window.alanBtn) {
95017
95048
  console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
95018
95049
  }
@@ -95037,7 +95068,8 @@ code.hljs {
95037
95068
  var keepButtonPositionAfterDnD = false;
95038
95069
  var dragAndDropEnabled = true;
95039
95070
  var curDialogId = null;
95040
- var textChatIsHidden = true;
95071
+ var closeChatTimeoutId;
95072
+ var textChatIsHidden = !options.textChat?.openByDefault;
95041
95073
  var textChatWasClosedManually = false;
95042
95074
  var voiceEnabledInTextChat = true;
95043
95075
  var textChatMessages = [];
@@ -95046,11 +95078,12 @@ code.hljs {
95046
95078
  var sentMessageInd = null;
95047
95079
  var sentMessages = [];
95048
95080
  const LOCAL_STORAGE_KEYS = {
95081
+ textChatMessagesKeyPrefix: "alan-btn-text-chat-message-history",
95049
95082
  getDialogIdKey: () => {
95050
95083
  return `alan-btn-dialogId${getUserIdLsPrefix()}-${getProjectId()}`;
95051
95084
  },
95052
95085
  getTextChatMessagesKey: () => {
95053
- return `alan-btn-text-chat-message-history${getUserIdLsPrefix()}-${getProjectId()}`;
95086
+ return `${LOCAL_STORAGE_KEYS.textChatMessagesKeyPrefix}${getUserIdLsPrefix()}-${getProjectId()}`;
95054
95087
  },
95055
95088
  getSentMessagesKey: () => {
95056
95089
  return `alan-btn-text-chat-sent-message-history${getUserIdLsPrefix()}-${getProjectId()}`;
@@ -95198,6 +95231,9 @@ code.hljs {
95198
95231
  showTextChat();
95199
95232
  broadcastReloadIframeToIframes();
95200
95233
  },
95234
+ minimize: () => {
95235
+ minimizeTextChat();
95236
+ },
95201
95237
  close: () => {
95202
95238
  closeTextChat();
95203
95239
  },
@@ -95523,6 +95559,9 @@ code.hljs {
95523
95559
  function isInlinedMode() {
95524
95560
  return uiState.textChat.inlined;
95525
95561
  }
95562
+ function isChatOpenedByDefault() {
95563
+ return options?.textChat?.openByDefault;
95564
+ }
95526
95565
  btnSize = btnModes[mode].btnSize;
95527
95566
  function setDefautlPositionProps(value) {
95528
95567
  if (/^\d+$/.test(value)) {
@@ -95538,6 +95577,7 @@ code.hljs {
95538
95577
  if (uiState.btn.zIndex) {
95539
95578
  rootEl.style.zIndex = uiState.btn.zIndex;
95540
95579
  }
95580
+ chatHolderDiv.style.zIndex = uiState.btn.zIndex + 2;
95541
95581
  setButtonPosition();
95542
95582
  recognisedTextContent.classList.add("alanBtn-recognised-text-content");
95543
95583
  recognisedTextHolder.classList.add("alanBtn-recognised-text-holder");
@@ -95569,7 +95609,7 @@ code.hljs {
95569
95609
  sideBtnPos = setDefautlPositionProps(options.right !== void 0 ? options.right : btnModes[mode].rightPos);
95570
95610
  initRightPos = parseInt(sideBtnPos, 10);
95571
95611
  }
95572
- if (isInlinedMode()) {
95612
+ if (isInlinedMode() && !options.chatEl) {
95573
95613
  rootEl.style.position = "static";
95574
95614
  } else {
95575
95615
  rootEl.style.position = options.position ? options.position : "fixed";
@@ -95740,7 +95780,7 @@ code.hljs {
95740
95780
  btn.style.height = size + "px";
95741
95781
  btn.style.maxHeight = size + "px";
95742
95782
  rootEl.style.width = size + "px";
95743
- if (isInlinedMode()) {
95783
+ if (isInlinedMode() && !options.chatEl) {
95744
95784
  rootEl.style.width = "100%";
95745
95785
  rootEl.style.minWidth = "100%";
95746
95786
  rootEl.style.maxWidth = "100%";
@@ -96154,8 +96194,12 @@ code.hljs {
96154
96194
  return;
96155
96195
  if (!dndBackAnimFinished)
96156
96196
  return;
96157
- if (uiState.textChat.available && textChatIsHidden) {
96158
- activateAlanButton();
96197
+ if (uiState.textChat.available) {
96198
+ if (textChatIsHidden) {
96199
+ activateAlanButton();
96200
+ } else {
96201
+ closeTextChat();
96202
+ }
96159
96203
  } else {
96160
96204
  activateVoiceBtn();
96161
96205
  this.blur();
@@ -96611,7 +96655,12 @@ code.hljs {
96611
96655
  }
96612
96656
  updateMsgLoaderIcons(options2?.chatOptions?.textChat);
96613
96657
  initTextChat();
96614
- if (isInlinedMode() || options2?.chatOptions?.textChat?.popup?.openByDefualt === true || isTextChatSavedStateOpened()) {
96658
+ if (options2?.chatOptions?.textChat?.popup?.openByDefualt === true || !isInlinedMode() && isTextChatSavedStateOpened()) {
96659
+ if (!textChatWasClosedManually) {
96660
+ showTextChat(true);
96661
+ }
96662
+ }
96663
+ if (isChatOpenedByDefault()) {
96615
96664
  if (!textChatWasClosedManually) {
96616
96665
  showTextChat(true);
96617
96666
  }
@@ -96674,7 +96723,7 @@ code.hljs {
96674
96723
  }
96675
96724
  function savePrevUserId(userId) {
96676
96725
  if (isLocalStorageAvailable) {
96677
- localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId, "userId"));
96726
+ localStorage.setItem(LOCAL_STORAGE_KEYS.getPrevUserIdKey(), encryptMessage(userId || "default", "userId"));
96678
96727
  }
96679
96728
  }
96680
96729
  function getPrevUserId() {
@@ -97707,7 +97756,7 @@ ${LEARN_MORE_LABEL}
97707
97756
  console.info("Alan: clear messages history", curDialogId);
97708
97757
  for (let i2 = 0; i2 < localStorage.length; i2++) {
97709
97758
  const key = localStorage.key(i2);
97710
- if (key.indexOf("alan-btn-text-chat-msgs-") > -1) {
97759
+ if (key.indexOf(LOCAL_STORAGE_KEYS.textChatMessagesKeyPrefix) > -1) {
97711
97760
  localStorage.removeItem(key);
97712
97761
  }
97713
97762
  }
@@ -98289,38 +98338,56 @@ ${LEARN_MORE_LABEL}
98289
98338
  }
98290
98339
  }
98291
98340
  function showTextChat(noAnimation) {
98341
+ if (chatHolderDiv.classList.contains("is-alan-chat-opened"))
98342
+ return;
98343
+ clearTimeout(closeChatTimeoutId);
98292
98344
  textChatWasClosedManually = false;
98293
- if (options.onEvent) {
98294
- options.onEvent({ name: "textChatOpened" });
98295
- }
98296
98345
  fixPopupScrollOnMobileForTextChat(true);
98297
98346
  hideChatNotifications();
98298
98347
  hidePopup();
98299
98348
  chatHolderDiv.style.display = "flex";
98300
98349
  textChatIsHidden = false;
98301
- if (noAnimation === true) {
98302
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98350
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98351
+ if (noAnimation === true) {
98352
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened-immediately");
98353
+ } else {
98354
+ rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98355
+ }
98356
+ }
98357
+ chatHolderDiv.classList.add("is-alan-chat-opened");
98358
+ if (isInlinedMode()) {
98359
+ chatHolderDiv.classList.add("alan-text-chat__openning-immidiately");
98303
98360
  } else {
98304
- rootEl.classList.add("hide-alan-btn-when-text-chat-is-opened");
98361
+ chatHolderDiv.classList.add("alan-text-chat__openning");
98305
98362
  }
98306
- chatHolderDiv.classList.add("alan-text-chat__openning");
98307
98363
  if (isLocalStorageAvailable) {
98308
98364
  if (!isMobile()) {
98309
98365
  localStorage.setItem(LOCAL_STORAGE_KEYS.getOpenedClosedTextChatStateKey(), "1");
98310
98366
  }
98311
98367
  }
98368
+ if (options?.textChat?.onOpen) {
98369
+ options?.textChat?.onOpen();
98370
+ }
98371
+ if (options.onEvent) {
98372
+ options.onEvent({ name: "textChatOpened" });
98373
+ }
98312
98374
  }
98313
98375
  function hideTextChat() {
98314
98376
  if (textChatIsHidden)
98315
98377
  return;
98316
98378
  deactivateAlanButton();
98379
+ chatHolderDiv.classList.remove("is-alan-chat-opened");
98317
98380
  chatHolderDiv.classList.add("alan-text-chat__closing");
98318
- rootEl.classList.add("text-chat-is-closing");
98381
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98382
+ rootEl.classList.add("text-chat-is-closing");
98383
+ }
98319
98384
  setTimeout(() => {
98320
98385
  chatHolderDiv.style.display = "none";
98321
98386
  chatHolderDiv.classList.remove("alan-text-chat__closing");
98322
- rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened");
98323
- rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened-immediately");
98387
+ if (options.textChat?.showBtnIfChatOpen !== true) {
98388
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened");
98389
+ rootEl.classList.remove("hide-alan-btn-when-text-chat-is-opened-immediately");
98390
+ }
98324
98391
  rootEl.classList.remove("text-chat-is-closing");
98325
98392
  fixPopupScrollOnMobileForTextChat(false);
98326
98393
  }, uiState.textChat.defaults.appearAnimationMs);
@@ -98339,26 +98406,47 @@ ${LEARN_MORE_LABEL}
98339
98406
  }
98340
98407
  function closeTextChat() {
98341
98408
  textChatWasClosedManually = true;
98342
- if (options.onEvent) {
98343
- options.onEvent({ name: "textChatClosed" });
98344
- }
98345
98409
  if (options?.textChat?.onClose) {
98346
98410
  options?.textChat?.onClose();
98411
+ }
98412
+ const closeDelay = options?.textChat?.closeDelay;
98413
+ if (closeDelay) {
98414
+ clearTimeout(closeChatTimeoutId);
98415
+ closeChatTimeoutId = setTimeout(() => {
98416
+ _closeChat();
98417
+ }, closeDelay);
98347
98418
  } else {
98348
- hideTextChat();
98419
+ _closeChat();
98420
+ }
98421
+ }
98422
+ function _closeChat() {
98423
+ if (options.onEvent) {
98424
+ options.onEvent({ name: "textChatClosed" });
98349
98425
  }
98426
+ hideTextChat();
98350
98427
  if (uiState.textChat.options?.popup?.clearChatOnClose === true) {
98351
98428
  onClearTextChatBtnClick();
98352
98429
  }
98353
98430
  }
98354
- function minimizeTextChat() {
98431
+ function _minimizeChat() {
98355
98432
  if (options.onEvent) {
98356
98433
  options.onEvent({ name: "textChatMinimized" });
98357
98434
  }
98435
+ hideTextChat();
98436
+ }
98437
+ function minimizeTextChat() {
98438
+ textChatWasClosedManually = true;
98358
98439
  if (options?.textChat?.onMinimize) {
98359
98440
  options?.textChat?.onMinimize();
98441
+ }
98442
+ const closeDelay = options?.textChat?.closeDelay;
98443
+ if (closeDelay) {
98444
+ clearTimeout(closeChatTimeoutId);
98445
+ closeChatTimeoutId = setTimeout(() => {
98446
+ _minimizeChat();
98447
+ }, closeDelay);
98360
98448
  } else {
98361
- hideTextChat();
98449
+ _minimizeChat();
98362
98450
  }
98363
98451
  }
98364
98452
  function expandCollapseChatSidePanel() {
@@ -98482,7 +98570,7 @@ ${LEARN_MORE_LABEL}
98482
98570
  changeBgColors(DEFAULT);
98483
98571
  micIconDiv.style.opacity = "1";
98484
98572
  roundedTriangleIconDiv.style.opacity = "0";
98485
- disconnectedMicLoaderIconImg.style.opacity = "0";
98573
+ disconnectedMicLoaderIconImg.style.opacity = "1";
98486
98574
  changeCustomLogoVisibility(
98487
98575
  defaultStateBtnIconImg,
98488
98576
  [
@@ -98853,13 +98941,20 @@ ${LEARN_MORE_LABEL}
98853
98941
  }
98854
98942
  function showBtn() {
98855
98943
  rootEl.innerHTML = "";
98856
- if (!isInlinedMode()) {
98857
- recognisedTextHolder.appendChild(recognisedTextContent);
98858
- rootEl.appendChild(recognisedTextHolder);
98859
- rootEl.appendChild(btn);
98860
- btn.appendChild(chatNotificationsBubble);
98944
+ recognisedTextHolder.appendChild(recognisedTextContent);
98945
+ rootEl.appendChild(recognisedTextHolder);
98946
+ rootEl.appendChild(btn);
98947
+ btn.appendChild(chatNotificationsBubble);
98948
+ if (isInlinedMode()) {
98949
+ if (options.chatEl) {
98950
+ options.chatEl.append(chatHolderDiv);
98951
+ } else {
98952
+ console.error("Text Chat element is not defined. Set chatEl in Alan Button options");
98953
+ return;
98954
+ }
98955
+ } else {
98956
+ rootEl.appendChild(chatHolderDiv);
98861
98957
  }
98862
- rootEl.appendChild(chatHolderDiv);
98863
98958
  resizeTextArea();
98864
98959
  btnDisabled = false;
98865
98960
  }
@@ -98930,6 +99025,13 @@ ${LEARN_MORE_LABEL}
98930
99025
  }
98931
99026
  rootEl.classList.add("alanBtn-root");
98932
99027
  rootEl.classList.add("alan-" + getProjectId());
99028
+ if (options.chatEl) {
99029
+ options.chatEl.classList.add("alanBtn-root");
99030
+ if (isInlinedMode()) {
99031
+ options.chatEl.classList.add("alanBtn-chat-root-inlined");
99032
+ }
99033
+ options.chatEl.classList.add("alan-" + getProjectId());
99034
+ }
98933
99035
  var alanBtnSavedOptions = null;
98934
99036
  if (isTutorMode()) {
98935
99037
  showBtn();
@@ -99005,10 +99107,10 @@ ${LEARN_MORE_LABEL}
99005
99107
  rootEl.style.setProperty("top", dndBtnTopPos + "px", "important");
99006
99108
  rootEl.style.setProperty("bottom", "auto", "important");
99007
99109
  }
99008
- if (Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) {
99110
+ if ((Math.abs(tempDeltaX) > 15 || Math.abs(tempDeltaY) > 15) && !isInlinedMode()) {
99009
99111
  hideTextChat();
99010
- afterMouseMove = true;
99011
99112
  }
99113
+ afterMouseMove = true;
99012
99114
  newLeftPos = dndBtnLeftPos + posInfo.clientX - dndInitMousePos2[0];
99013
99115
  newTopPos = dndBtnTopPos + posInfo.clientY - dndInitMousePos2[1];
99014
99116
  tempDeltaX = posInfo.clientX - dndInitMousePos2[0];