@alan-ai/alan-sdk-web 1.8.87 → 1.8.89

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 CHANGED
@@ -90463,7 +90463,10 @@
90463
90463
  `,
90464
90464
  minimize: `<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
90465
90465
  <path d="M3 17.25L18 17.25" stroke="none" stroke-width="1.5" stroke-linecap="round"/>
90466
- </svg>`
90466
+ </svg>`,
90467
+ graph: `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
90468
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M18.032 1H5.96802C5.52939 0.999989 5.15087 0.999979 4.83762 1.02135C4.50779 1.04386 4.17788 1.09336 3.85195 1.22836C3.11687 1.53285 2.53284 2.11687 2.22836 2.85195C2.09336 3.17788 2.04385 3.50779 2.02135 3.83762C1.99998 4.15087 1.99999 4.52936 2 4.968V5.03198C1.99999 5.47063 1.99998 5.84913 2.02135 6.16238C2.04385 6.49221 2.09336 6.82212 2.22836 7.14805C2.53284 7.88314 3.11687 8.46716 3.85195 8.77164C4.17788 8.90664 4.50779 8.95615 4.83762 8.97865C5.15088 9.00002 5.52936 9.00002 5.96801 9H11V12H8.7587C7.95376 12 7.28935 12 6.74817 12.0442C6.18608 12.0901 5.66937 12.1887 5.18404 12.436C4.43139 12.8195 3.81947 13.4314 3.43597 14.184C3.18868 14.6694 3.09012 15.1861 3.04419 15.7482C3.01124 16.1515 3.00285 16.6232 3.00072 17.1705C1.83515 17.5821 1 18.6935 1 20C1 21.6569 2.34315 23 4 23C5.65685 23 7 21.6569 7 20C7 18.6941 6.16559 17.5831 5.00083 17.171C5.00297 16.6425 5.01058 16.2412 5.03755 15.911C5.07337 15.4726 5.1383 15.2484 5.21799 15.092C5.40973 14.7157 5.7157 14.4097 6.09202 14.218C6.24842 14.1383 6.47262 14.0734 6.91104 14.0376C7.36113 14.0008 7.94342 14 8.8 14H11V17.1707C9.83481 17.5825 9 18.6938 9 20C9 21.6569 10.3431 23 12 23C13.6569 23 15 21.6569 15 20C15 18.6938 14.1652 17.5825 13 17.1707V14H15.2C16.0566 14 16.6389 14.0008 17.089 14.0376C17.5274 14.0734 17.7516 14.1383 17.908 14.218C18.2843 14.4097 18.5903 14.7157 18.782 15.092C18.8617 15.2484 18.9266 15.4726 18.9624 15.911C18.9894 16.2412 18.997 16.6425 18.9992 17.171C17.8344 17.5831 17 18.6941 17 20C17 21.6569 18.3431 23 20 23C21.6569 23 23 21.6569 23 20C23 18.6935 22.1648 17.5821 20.9993 17.1705C20.9971 16.6232 20.9888 16.1515 20.9558 15.7482C20.9099 15.1861 20.8113 14.6694 20.564 14.184C20.1805 13.4314 19.5686 12.8195 18.816 12.436C18.3306 12.1887 17.8139 12.0901 17.2518 12.0442C16.7106 12 16.0463 12 15.2414 12H13V9H18.032C18.4706 9.00002 18.8491 9.00002 19.1624 8.97865C19.4922 8.95615 19.8221 8.90664 20.1481 8.77164C20.8831 8.46716 21.4672 7.88314 21.7716 7.14805C21.9066 6.82212 21.9561 6.49221 21.9787 6.16238C22 5.84913 22 5.47064 22 5.03199V4.96801C22 4.52936 22 4.15088 21.9787 3.83762C21.9561 3.50779 21.9066 3.17788 21.7716 2.85195C21.4672 2.11687 20.8831 1.53285 20.1481 1.22836C19.8221 1.09336 19.4922 1.04386 19.1624 1.02135C18.8491 0.999979 18.4706 0.999989 18.032 1Z" fill="black" />
90469
+ </svg>`
90467
90470
  };
90468
90471
  function getCloseChatIcon(textChatOptions) {
90469
90472
  return textChatOptions?.popup?.icons?.close?.svg || chatIcons.closeChat;
@@ -90546,10 +90549,12 @@
90546
90549
  function mergeProgressiveMessages(messages, i, message) {
90547
90550
  const maxLinksCount = 9;
90548
90551
  const newImages = message.images || [];
90552
+ const newSuggestions = message.suggestions || [];
90549
90553
  const oldText = messages[i].text || "";
90550
90554
  const newText = message.text || "";
90551
90555
  messages[i].text = oldText + newText;
90552
90556
  messages[i].images = [...messages[i].images || [], ...newImages];
90557
+ messages[i].suggestions = [...messages[i].suggestions || [], ...newSuggestions];
90553
90558
  messages[i].links = [...messages[i].links || [], ...message.links || []].splice(0, maxLinksCount);
90554
90559
  if (!messages[i].parts) {
90555
90560
  messages[i].parts = [];
@@ -90645,6 +90650,17 @@
90645
90650
  replaceLoader = false;
90646
90651
  isNew = false;
90647
90652
  mergeProgressiveMessages(messages, msgInd, msg);
90653
+ } else if (msg?.suggestions?.length > 0) {
90654
+ const lastResponseMsgInd = (0, import_lodash.findLastIndex)(messages, (m) => {
90655
+ return msg.type === "response" && msgReqId && (m?.ctx?.reqId || m.reqId) === msgReqId;
90656
+ });
90657
+ if (lastResponseMsgInd > -1) {
90658
+ msgInd = lastResponseMsgInd;
90659
+ updateResponse = true;
90660
+ replaceLoader = false;
90661
+ isNew = false;
90662
+ mergeProgressiveMessages(messages, msgInd, msg);
90663
+ }
90648
90664
  }
90649
90665
  }
90650
90666
  }
@@ -90905,6 +90921,14 @@
90905
90921
  }
90906
90922
  return "none";
90907
90923
  }
90924
+ function getEnvironment() {
90925
+ var key;
90926
+ if (uiState.project.id) {
90927
+ key = uiState.project.id;
90928
+ return key.substr(key.indexOf("/"));
90929
+ }
90930
+ return "none";
90931
+ }
90908
90932
  function getDeviceId() {
90909
90933
  if (!uiState.project.id)
90910
90934
  return;
@@ -90970,14 +90994,17 @@
90970
90994
  setTimeout(() => {
90971
90995
  broadcastThemeToIframes();
90972
90996
  iframeEl.classList.remove("alan-iframe-hidden");
90997
+ removeIframeLoader(iframeEl);
90973
90998
  }, 200);
90974
90999
  } else {
90975
91000
  setTimeout(() => {
90976
91001
  iframeEl.classList.remove("alan-iframe-hidden");
91002
+ removeIframeLoader(iframeEl);
90977
91003
  }, 1200);
90978
91004
  }
90979
91005
  if (Math.abs(iframeEl.clientHeight - height) !== 20) {
90980
91006
  iframeEl.style.height = (+height > maxIFrameHeight ? maxIFrameHeight : height) + "px";
91007
+ iframeEl.style.minHeight = "0px";
90981
91008
  }
90982
91009
  if ((!withSvg || !iframeEl.src) && !window.alanIframes[iframeId]?.initialized) {
90983
91010
  broadcastReloadIframeToIframes(currentIframeId);
@@ -91079,8 +91106,15 @@
91079
91106
  broadcastReloadIframeToIframes,
91080
91107
  adjustIFrameSize,
91081
91108
  getThemeSrc,
91082
- addImgToThePage
91109
+ addImgToThePage,
91110
+ removeIframeLoader
91083
91111
  ];
91112
+ function removeIframeLoader(iframe) {
91113
+ const iframeWrapper = iframe.closest(".act-embed-container");
91114
+ if (iframeWrapper) {
91115
+ iframeWrapper.classList.remove("loading");
91116
+ }
91117
+ }
91084
91118
  function onIFrameSizeListener(event) {
91085
91119
  if (event.data && event.data.source !== "alan-chat-iframe") {
91086
91120
  return;
@@ -91617,8 +91651,8 @@
91617
91651
  const responseBubbleLabelFontSize = getNumPropVal(textChatOptions?.bubbles?.response?.label?.fontSize, 15);
91618
91652
  const responseBubbleLabelColor = textChatOptions?.bubbles?.response?.label?.color || `#171717`;
91619
91653
  const responseBubbleLabelEnabled = uiState?.textChat?.options?.bubbles?.response?.label?.enabled === true;
91620
- const btnAlignment = textChatOptions?.buttons?.alignment?.default || "center";
91621
- const btnAlignmentFullscreen = textChatOptions?.buttons?.alignment?.fullScreen || "center";
91654
+ const btnAlignment = textChatOptions?.buttons?.alignment?.default || "right";
91655
+ const btnAlignmentFullscreen = textChatOptions?.buttons?.alignment?.fullScreen || "right";
91622
91656
  const textChatAppearAnimationMs = uiState.textChat.defaults.appearAnimationMs;
91623
91657
  const headerLayoutName = textChatOptions?.header?.layout?.name || "centered-title";
91624
91658
  let cssChatHeight = getTextChatSizeAfterResize("height");
@@ -92714,7 +92748,7 @@
92714
92748
  padding-left: ${avatarSize + avatarRightMargin}px;
92715
92749
  }`;
92716
92750
  keyFrames += getStyleSheetMarker() + `.alan-btn__chat-buttons .alan-chat__chat-btn {
92717
- text-align: ${textChatOptions?.buttons?.textAlign?.default || "center"};
92751
+ text-align: ${textChatOptions?.buttons?.textAlign?.default || "left"};
92718
92752
  }`;
92719
92753
  const defaultButtonBorderRadius = 20;
92720
92754
  keyFrames += getStyleSheetMarker() + `.alan-chat__chat-btn {
@@ -92745,6 +92779,48 @@
92745
92779
  box-shadow: ${textChatOptions?.buttons?.active?.hasShadow === false ? "none" : `0px 1px 3px rgba(16, 39, 126, 0.2)`};
92746
92780
  color: ${textChatOptions?.buttons?.active?.color || `#0078ff`};
92747
92781
  }`;
92782
+ keyFrames += getStyleSheetMarker() + `.alan-btn__chat-suggestions {
92783
+ margin-bottom: 16px;
92784
+ display:flex;
92785
+ flex-wrap: wrap;
92786
+ gap: ${btnsGap}px;
92787
+ clear: both;
92788
+ justify-content: ${flexMap[btnAlignment]};
92789
+ }`;
92790
+ keyFrames += getStyleSheetMarker() + `.alan-btn_text-chat-full-screen .alan-btn__chat-suggestions {
92791
+ justify-content: ${flexMap[btnAlignmentFullscreen]};
92792
+ }`;
92793
+ keyFrames += getStyleSheetMarker() + `.alan-btn__chat-suggestions .alan-chat__suggestion {
92794
+ text-align: ${textChatOptions?.buttons?.textAlign?.default || "left"};
92795
+ }`;
92796
+ keyFrames += getStyleSheetMarker() + `.alan-chat__suggestion {
92797
+ margin-bottom: 8px;
92798
+ padding: ${getPaddingProp(buttonsTopPadding, buttonsRightPadding, buttonsBottomPadding, buttonsLeftPadding)};
92799
+ line-height: 1.53;
92800
+ display: inline-block;
92801
+ border-radius: ${textChatOptions?.buttons?.borderRadius?.topLeft || defaultButtonBorderRadius}px ${textChatOptions?.buttons?.borderRadius?.topRight || defaultButtonBorderRadius}px ${textChatOptions?.buttons?.borderRadius?.bottomRight || defaultButtonBorderRadius}px ${textChatOptions?.buttons?.borderRadius?.bottomLeft || defaultButtonBorderRadius}px;
92802
+ position: relative;
92803
+ background-color: ${textChatOptions?.buttons?.default?.backgroundColor || `#ffffff`};
92804
+ border: 1px solid ${textChatOptions?.buttons?.default?.borderColor || `#ffffff`};
92805
+ box-shadow: ${textChatOptions?.buttons?.default?.hasShadow === false ? "none" : `0px 1px 3px rgba(16, 39, 126, 0.2)`};
92806
+ color: ${textChatOptions?.buttons?.default?.color || `#171717`};
92807
+ font-size: ${textChatOptions?.buttons?.fontSize || `15`}px;
92808
+ word-break: break-word;
92809
+ text-align: left;
92810
+ cursor: pointer;
92811
+ }`;
92812
+ keyFrames += getStyleSheetMarker() + `.alan-chat__suggestion:hover {
92813
+ background-color: ${textChatOptions?.buttons?.hover?.backgroundColor || `#ffffff`};
92814
+ border: 1px solid ${textChatOptions?.buttons?.hover?.borderColor || `#ffffff`};
92815
+ box-shadow: ${textChatOptions?.buttons?.hover?.hasShadow === false ? "none" : `0px 1px 3px rgba(16, 39, 126, 0.2)`};
92816
+ color: ${textChatOptions?.buttons?.hover?.color || `#0078ff`};
92817
+ }`;
92818
+ keyFrames += getStyleSheetMarker() + `.alan-chat__suggestion:active {
92819
+ background-color: ${textChatOptions?.buttons?.active?.backgroundColor || `#bcdafd`};
92820
+ border: 1px solid ${textChatOptions?.buttons?.active?.borderColor || `#bcdafd`};
92821
+ box-shadow: ${textChatOptions?.buttons?.active?.hasShadow === false ? "none" : `0px 1px 3px rgba(16, 39, 126, 0.2)`};
92822
+ color: ${textChatOptions?.buttons?.active?.color || `#0078ff`};
92823
+ }`;
92748
92824
  var chatResponseCssDeltaWidth = 82;
92749
92825
  keyFrames += getStyleSheetMarker() + `.alan-btn_text-chat-full-screen .alan-btn__chat-response {
92750
92826
  margin-bottom: 16px;
@@ -93208,6 +93284,15 @@
93208
93284
  keyFrames += styleSheetMarker + `.alan-btn__chat-response__dislike-btn svg path {
93209
93285
  fill: ${bottomBtnsColor};
93210
93286
  }`;
93287
+ keyFrames += styleSheetMarker + `.alan-btn__chat-graph {
93288
+ display: none;
93289
+ }`;
93290
+ keyFrames += styleSheetMarker + `.alan-btn__chat-graph svg path {
93291
+ fill: ${bottomBtnsColor};
93292
+ }`;
93293
+ keyFrames += styleSheetMarker + `.alan-btn__chat-graph:hover svg path {
93294
+ opacity: 0.8;
93295
+ }`;
93211
93296
  keyFrames += styleSheetMarker + `.alan-btn__chat-response__copy-btn alan-btn__copy-icon {
93212
93297
  width: 22px;
93213
93298
  }`;
@@ -94193,6 +94278,10 @@
94193
94278
  style.textContent = highlightJsCss(theme);
94194
94279
  style.id = hljsStylesId;
94195
94280
  doc.getElementsByTagName("head")[0].appendChild(style);
94281
+ var lightHLJSOnlyStyle = doc.createElement("style");
94282
+ lightHLJSOnlyStyle.textContent = highlightJsCssForOnlyLightTheme();
94283
+ lightHLJSOnlyStyle.id = `alan-hljs-styles-light-only`;
94284
+ doc.getElementsByTagName("head")[0].appendChild(lightHLJSOnlyStyle);
94196
94285
  }
94197
94286
  function highlightCode(msgsHolder) {
94198
94287
  if (window.hljs) {
@@ -94451,6 +94540,96 @@ code.hljs {
94451
94540
  };
94452
94541
  return themes[theme];
94453
94542
  }
94543
+ function highlightJsCssForOnlyLightTheme() {
94544
+ const lightOnlyTheme = `
94545
+ .hljs-light-override pre code.hljs {
94546
+ display: block;
94547
+ overflow-x: auto;
94548
+ overflow-y: hidden;
94549
+ padding: 1em;
94550
+ }
94551
+ .hljs-light-override code.hljs {
94552
+ padding: 3px 5px;
94553
+ }
94554
+ .hljs-light-override .hljs {
94555
+ background-color: #f8f8f8 !important;
94556
+ }
94557
+ .hljs-light-override .hljs-doctag,
94558
+ .hljs-light-override .hljs-keyword,
94559
+ .hljs-light-override .hljs-meta .hljs-keyword,
94560
+ .hljs-light-override .hljs-template-tag,
94561
+ .hljs-light-override .hljs-template-variable,
94562
+ .hljs-light-override .hljs-type,
94563
+ .hljs-light-override .hljs-variable.language_ {
94564
+ color: #d73a49;
94565
+ }
94566
+ .hljs-light-override .hljs-title,
94567
+ .hljs-light-override .hljs-title.class_,
94568
+ .hljs-light-override .hljs-title.class_.inherited__,
94569
+ .hljs-light-override .hljs-title.function_ {
94570
+ color: #6f42c1;
94571
+ }
94572
+ .hljs-light-override .hljs-attr,
94573
+ .hljs-light-override .hljs-attribute,
94574
+ .hljs-light-override .hljs-literal,
94575
+ .hljs-light-override .hljs-meta,
94576
+ .hljs-light-override .hljs-number,
94577
+ .hljs-light-override .hljs-operator,
94578
+ .hljs-light-override .hljs-variable,
94579
+ .hljs-light-override .hljs-selector-attr,
94580
+ .hljs-light-override .hljs-selector-class,
94581
+ .hljs-light-override .hljs-selector-id {
94582
+ color: #005cc5;
94583
+ }
94584
+ .hljs-light-override .hljs-regexp,
94585
+ .hljs-light-override .hljs-string,
94586
+ .hljs-light-override .hljs-meta .hljs-string {
94587
+ color: #032f62;
94588
+ }
94589
+ .hljs-light-override .hljs-built_in,
94590
+ .hljs-light-override .hljs-symbol {
94591
+ color: #e36209;
94592
+ }
94593
+ .hljs-light-override .hljs-comment,
94594
+ .hljs-light-override .hljs-code,
94595
+ .hljs-light-override .hljs-formula {
94596
+ color: #6a737d;
94597
+ }
94598
+ .hljs-light-override .hljs-name,
94599
+ .hljs-light-override .hljs-quote,
94600
+ .hljs-light-override .hljs-selector-tag,
94601
+ .hljs-light-override .hljs-selector-pseudo {
94602
+ color: #22863a;
94603
+ }
94604
+ .hljs-light-override .hljs-subst {
94605
+ color: #24292e;
94606
+ }
94607
+ .hljs-light-override .hljs-section {
94608
+ color: #005cc5;
94609
+ font-weight: bold;
94610
+ }
94611
+ .hljs-light-override .hljs-bullet {
94612
+ color: #735c0f;
94613
+ }
94614
+ .hljs-light-override .hljs-emphasis {
94615
+ color: #24292e;
94616
+ font-style: italic;
94617
+ }
94618
+ .hljs-light-override .hljs-strong {
94619
+ color: #24292e;
94620
+ font-weight: bold;
94621
+ }
94622
+ .hljs-light-override .hljs-addition {
94623
+ color: #22863a;
94624
+ background-color: #f0fff4;
94625
+ }
94626
+ .hljs-light-override .hljs-deletion {
94627
+ color: #b31d28;
94628
+ background-color: #ffeef0;
94629
+ }
94630
+ `;
94631
+ return lightOnlyTheme;
94632
+ }
94454
94633
 
94455
94634
  // alan_btn/src/helpers/mini/keepJSONInAttr.ts
94456
94635
  function encodeValueForHtmlAttr(data) {
@@ -94485,7 +94664,8 @@ code.hljs {
94485
94664
 
94486
94665
  // alan_btn/src/textChat/helpers/processClickByButtonInChat.ts
94487
94666
  function processClickByButtonInChat(clickedEl, btnInstance, sendTextCall) {
94488
- if (clickedEl.classList.contains("alan-chat__chat-btn")) {
94667
+ clickedEl = clickedEl.classList.contains("alan-chat__chat-btn") || clickedEl.closest(".alan-chat__suggestion");
94668
+ if (clickedEl) {
94489
94669
  const btnLabel = clickedEl.getAttribute("data-alan-button-label");
94490
94670
  const btnText = clickedEl.getAttribute("data-alan-button-send-text");
94491
94671
  const vsAttr = clickedEl.getAttribute("data-alan-button-set-visual-state");
@@ -94599,7 +94779,7 @@ code.hljs {
94599
94779
  const reqId = msg.ctx?.reqId || msg.reqId;
94600
94780
  if (reqId) {
94601
94781
  window.tutorProject.call("sendFeedback", { reqId, status: msg.liked });
94602
- if (options.onEvent) {
94782
+ if (options?.onEvent) {
94603
94783
  options.onEvent({ name: "feedbackSent", status: msg.liked, reqId });
94604
94784
  }
94605
94785
  }
@@ -94617,9 +94797,16 @@ code.hljs {
94617
94797
  }
94618
94798
 
94619
94799
  // alan_btn/src/textChat/saveChatStateToFile.ts
94620
- var functionsToInsert = iFrameSizeListenerFunctions.map((fn) => fn.toString()).join("\n\n");
94621
- var onIFrameSizeListenerString = onIFrameSizeListener.toString();
94622
- async function saveChatState(chatName, chatEl, width, projectId, headContent, codeContent) {
94800
+ var LIBS_PREFIX = "https://storage.googleapis.com/alan-ai-public-resources/save-debug-chat-resources";
94801
+ async function saveChatState({
94802
+ chatName,
94803
+ chatEl,
94804
+ width,
94805
+ projectId,
94806
+ environment,
94807
+ requestIds,
94808
+ headContent
94809
+ }) {
94623
94810
  const chatConteiner = chatEl.cloneNode(true);
94624
94811
  const images = Array.from(chatConteiner.querySelectorAll("img"));
94625
94812
  let imgData;
@@ -94666,13 +94853,410 @@ code.hljs {
94666
94853
  console.error(`Failed to fetch or process iframe from ${srcUrl}:`, error);
94667
94854
  }
94668
94855
  }
94856
+ const functionsToInsert = iFrameSizeListenerFunctions.map((fn) => fn.toString()).join("\n\n");
94857
+ const onIFrameSizeListenerString = onIFrameSizeListener.toString();
94858
+ const copyTextToBufferString = copyTextToBuffer.toString();
94859
+ const outputPhrases = await getOutputLogs({
94860
+ projectId,
94861
+ environment,
94862
+ requestIds
94863
+ });
94669
94864
  const alanMainClass = "alan-" + projectId;
94865
+ const code = `
94866
+ <script type="text/javascript">
94867
+
94868
+ ${functionsToInsert}
94869
+ ${copyTextToBufferString}
94870
+
94871
+ function copyCodeHandler(text){
94872
+ copyTextToBuffer(text);
94873
+
94874
+ copyButton.classList.add('alan-copy-btn-copied');
94875
+ setTimeout(() => {
94876
+ copyButton.classList.remove('alan-copy-btn-copied');
94877
+ }, 2000);
94878
+ }
94879
+
94880
+
94881
+ window.hljs.addPlugin({
94882
+ "after:highlightElement": ({ el, text }) => {
94883
+ const wrapper = el.parentElement;
94884
+ if (wrapper == null) {
94885
+ return;
94886
+ }
94887
+
94888
+ wrapper.classList.add("alan-btn__chat-response__code-wrapper");
94889
+
94890
+ const copyButton = document.createElement("span");
94891
+ copyButton.classList.add(
94892
+ "alan-btn__chat-response__copy-code-btn",
94893
+ );
94894
+
94895
+ const chatIcons = {
94896
+ copy: '<svg class="alan-btn__copy-icon" width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M19.5 16.5L19.5 4.5L18.75 3.75H9L8.25 4.5L8.25 7.5L5.25 7.5L4.5 8.25V20.25L5.25 21H15L15.75 20.25V17.25H18.75L19.5 16.5ZM15.75 15.75L15.75 8.25L15 7.5L9.75 7.5V5.25L18 5.25V15.75H15.75ZM6 9L14.25 9L14.25 19.5L6 19.5L6 9Z" fill="#080341"/></svg>',
94897
+ copied: '<svg class="alan-btn__copied-icon" width="24px" height="24px" viewBox="0 0 24 24" role="img" xmlns="http://www.w3.org/2000/svg" aria-labelledby="okIconTitle" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none" color="#000000"> <title id="okIconTitle">Copied!</title> <polyline points="4 13 9 18 20 7"/> </svg>'
94898
+ };
94899
+
94900
+ copyButton.innerHTML = chatIcons.copy + chatIcons.copied;
94901
+
94902
+ copyButton.onclick = () => {
94903
+ copyCodeHandler(text)
94904
+ };
94905
+
94906
+ wrapper.appendChild(copyButton);
94907
+ },
94908
+ });
94909
+
94910
+ window.addEventListener("message", ${onIFrameSizeListenerString});
94911
+
94912
+ function unescapeHtml(safe) {
94913
+ return safe
94914
+ .replace(/&lt;(?!w)/g, "<")
94915
+ .replace(/(?<!w)&gt;/g, ">")
94916
+ .replace(/&amp;/g, "&")
94917
+ .replace(/&quot;/g, '"')
94918
+ .replace(/&#039;/g, "'");
94919
+ }
94920
+
94921
+ function escapeHtml(unsafe) {
94922
+ return unsafe
94923
+ .replace(/&/g, "&amp;")
94924
+ .replace(/</g, "&lt;")
94925
+ .replace(/>/g, "&gt;")
94926
+ .replace(/"/g, "&quot;")
94927
+ .replace(/'/g, "&#039;");
94928
+ }
94929
+
94930
+ var logs = ${JSON.stringify(outputPhrases)};
94931
+
94932
+ logs = logs.map(el => ({
94933
+ ...el,
94934
+ context: unescapeHtml(el.context)
94935
+ }));
94936
+
94937
+ var zoomInstance;
94938
+ var xRef, yRef, isDraggingRef;
94939
+ var dragThreshold = 5;
94940
+ var detailsId = null;
94941
+ var detailsMap = {};
94942
+
94943
+ checkMsgLogs();
94944
+
94945
+ function checkMsgLogs() {
94946
+
94947
+ var graphIcons = document.querySelectorAll('.chat-bubble_graph, .alan-btn__chat-graph');
94948
+
94949
+ graphIcons.forEach((child) => {
94950
+ var msgReqId = child.getAttribute('data-request-id');
94951
+ const foundLog = logs.find(l => l.requestId === msgReqId);
94952
+ if (!foundLog || foundLog?.context === '') {
94953
+ child.parentElement.removeChild(child);
94954
+ }
94955
+ });
94956
+ }
94957
+
94958
+ document.addEventListener('mousedown', function onGraphClick(e) {
94959
+ var isOverlayEl = e.target.id === "overlay";
94960
+
94961
+ if (isOverlayEl) {
94962
+ closePopup(e.target.getAttribute('popup-id'));
94963
+ return;
94964
+ }
94965
+ })
94966
+
94967
+ document.addEventListener('click', function onCopyClick(e) {
94968
+ let clickedEl = e.target;
94969
+ clickedEl = clickedEl.closest('.alan-btn__chat-response__copy-code-btn');
94970
+
94971
+ if (clickedEl) {
94972
+ clickedEl.classList.add('alan-copy-btn-copied');
94973
+ setTimeout(() => {
94974
+ clickedEl.classList.remove('alan-copy-btn-copied');
94975
+ }, 2000);
94976
+
94977
+ const codeBlockEl = clickedEl.closest('.alan-btn__chat-response__code-wrapper');
94978
+ if (codeBlockEl) {
94979
+ copyTextToBuffer(codeBlockEl.innerText);
94980
+ }
94981
+ }
94982
+ });
94983
+
94984
+ document.addEventListener('click', function onGraphClick(e) {
94985
+ var graphEl = e.target.closest('.chat-bubble_graph, .alan-btn__chat-graph');
94986
+ if (graphEl) {
94987
+ var phrase = logs.filter(l => l.requestId === graphEl.getAttribute('data-request-id'))[0];
94988
+
94989
+ if (phrase) {
94990
+ var graphData, graph, graphTitle;
94991
+
94992
+ try {
94993
+ graphData = JSON.parse(phrase.context);
94994
+ if (graphData && graphData.opGraph) {
94995
+ graph = graphData.opGraph.dot;
94996
+ graphTitle = graphData.opGraph.title;
94997
+ detailsMap = graphData.opGraph.val;
94998
+ }
94999
+
95000
+ console.info('graphData', graphData)
95001
+ } catch (err) {
95002
+ console.log(err);
95003
+ }
95004
+
95005
+ createPopup('graph-popup','graph', graphTitle );
95006
+
95007
+ renderSvg(graph);
95008
+ }
95009
+ }
95010
+ })
95011
+
95012
+ function createPopup (id, bodyId, title) {
95013
+ var overlay = document.createElement('div');
95014
+ var popup = document.createElement('div');
95015
+ var popupBody = document.createElement('div');
95016
+ var popupTitle = document.createElement('div');
95017
+ var popupCloseBtn = document.createElement('div');
95018
+ popupCloseBtn.innerHTML = '<svg width="20px" height="20px" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M195.2 195.2a64 64 0 0 1 90.496 0L512 421.504 738.304 195.2a64 64 0 0 1 90.496 90.496L602.496 512 828.8 738.304a64 64 0 0 1-90.496 90.496L512 602.496 285.696 828.8a64 64 0 0 1-90.496-90.496L421.504 512 195.2 285.696a64 64 0 0 1 0-90.496z"/></svg>';
95019
+ overlay.id = 'overlay';
95020
+ overlay.setAttribute('popup-id', id)
95021
+ overlay.classList.add('${alanMainClass}');
95022
+ overlay.classList.add('hljs-light-override');
95023
+ popupBody.id = bodyId;
95024
+ if(bodyId === 'details'){
95025
+ popup.classList.add('alan-btn__chat-messages');
95026
+ }
95027
+
95028
+ popup.id = 'popup';
95029
+ popupTitle.id = 'popup-title';
95030
+ popupCloseBtn.id = 'popup-close-btn';
95031
+
95032
+ overlay.appendChild(popup);
95033
+ popup.appendChild(popupTitle);
95034
+ popup.appendChild(popupBody);
95035
+
95036
+ popupTitle.innerText = title;
95037
+ popupTitle.appendChild(popupCloseBtn);
95038
+
95039
+ popupCloseBtn.addEventListener('click', ()=>{closePopup(id)});
95040
+
95041
+ document.body.appendChild(overlay);
95042
+ }
95043
+
95044
+ function cancelEvent(e) {
95045
+ e.stopPropagation();
95046
+ e.preventDefault();
95047
+ }
95048
+
95049
+ const resetSelection = () => {
95050
+ d3.selectAll('#graph .selected').classed('selected', false);
95051
+ }
95052
+
95053
+ const addGraphEvents = () => {
95054
+ const nodes = d3.selectAll('.node,.edge,.w-clicked-elements text');
95055
+ nodes.on("click", function (e) {
95056
+ if (isDraggingRef) {
95057
+ cancelEvent(e);
95058
+ return;
95059
+ }
95060
+
95061
+ cancelEvent(e);
95062
+ resetSelection();
95063
+ const el = this.closest('[id]');
95064
+
95065
+ if (el?.classList?.contains('node')) {
95066
+ const id = el.getAttribute('id');
95067
+ console.info('Id:', id);
95068
+ if (detailsMap[id]) {
95069
+ openDetailsPopup(id);
95070
+ }
95071
+ el.classList.add("selected");
95072
+ } else if (el?.firstChild?.tagName?.toLowerCase() === 'a') {
95073
+ const id = el.getAttribute('id')?.replace('a_', '');
95074
+ console.info('Id:', id);
95075
+ if (detailsMap[id]) {
95076
+ openDetailsPopup(id);
95077
+ }
95078
+ el.classList.add("selected");
95079
+ } else {
95080
+ this.classList.add("selected");
95081
+ }
95082
+ });
95083
+ };
95084
+
95085
+ function closePopup(popupId){
95086
+ var overlayEl = document.querySelector('[popup-id="'+popupId+'"]');
95087
+ if (overlayEl) {
95088
+ overlayEl.remove();
95089
+ }
95090
+ }
95091
+
95092
+ function getSvg(graph, engine) {
95093
+ return new Promise((resolve, reject) => {
95094
+ try {
95095
+ Viz.instance().then(viz => {
95096
+ resolve(viz.renderSVGElement(graph, { engine }));
95097
+ });
95098
+ } catch (error) {
95099
+ console.info(error)
95100
+ reject(error);
95101
+ }
95102
+ });
95103
+ }
95104
+
95105
+ document.addEventListener('click', function (e){
95106
+ const clickedEl = e.target.closest('.mode-btn');
95107
+ if (!clickedEl) return;
95108
+
95109
+ const mode = clickedEl.getAttribute('mode');
95110
+
95111
+ if (!detailsId) return;
95112
+
95113
+ renderDetailsContent(detailsId, mode);
95114
+ });
95115
+
95116
+ function renderDetailsContent(id, mode){
95117
+ var detailsData = detailsMap[id];
95118
+
95119
+ if (!detailsData) return;
95120
+ const detailsEl = document.getElementById('details');
95121
+
95122
+ const elementsWithMode = document.querySelectorAll('[mode]');
95123
+ elementsWithMode.forEach(el => {
95124
+ el.classList.remove('active');
95125
+ });
95126
+
95127
+ const curMode = document.querySelector('[mode="'+mode+'"]');
95128
+ if (curMode) {
95129
+ curMode.classList.add('active');
95130
+ }
95131
+
95132
+ detailsEl.className = '';
95133
+ detailsEl.classList.add('mode-'+mode);
95134
+
95135
+ var codePart = typeof detailsData.value === 'object' && detailsData.value !== null ? JSON.stringify(detailsData.value,null,2): escapeHtml(detailsData.value);
95136
+ var markdownPart = '';
95137
+
95138
+ if (detailsData.type === 'markdown') {
95139
+ markdownPart = alanMarkdown(detailsData.value);
95140
+ }
95141
+
95142
+ if (mode === 'code') {
95143
+ detailsEl.innerHTML = '<div class="details-content">'+codePart+'</div>';
95144
+ }
95145
+
95146
+ if (mode === 'split') {
95147
+ detailsEl.innerHTML = '<div class="details-content">'+codePart+'</div><div class="details-content with-markdown">'+markdownPart+'</div>';
95148
+ }
95149
+
95150
+ if (mode === 'preview') {
95151
+ detailsEl.innerHTML = '<div class="details-content with-markdown">'+markdownPart+'</div>';
95152
+ }
95153
+
95154
+ detailsEl.querySelectorAll('pre code:not(.alan-btn__hljs-processed)').forEach((el) => {
95155
+ window.hljs.highlightElement(el);
95156
+ el.classList.add('alan-btn__hljs-processed');
95157
+ });
95158
+ }
95159
+
95160
+ function openDetailsPopup(id){
95161
+ detailsId = id;
95162
+ var detailsData = detailsMap[id];
95163
+
95164
+ if (!detailsData) return;
95165
+
95166
+ createPopup('details-popup', 'details', detailsData.name);
95167
+
95168
+ if (detailsData.type === 'markdown') {
95169
+ const detailsPopupEl = document.querySelector('[popup-id="details-popup"]');
95170
+ if (detailsPopupEl) {
95171
+
95172
+ const codeSvg = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><g clipPath="url(#clip0_1_30)"><path d="M6.12023 14.2531L0 10.9153V9.06662L6.12023 5.74774V7.91913L1.85555 9.96778L6.12023 12.0937V14.2531Z" fill="#010002" /><path d="M7.16559 15.4212L11.2243 4.5788H12.5066L8.43841 15.4212H7.16559Z" fill="#010002" /><path d="M13.8798 14.2531V12.0937L18.1436 9.98499L13.8798 7.89254V5.74689L20 9.07006V10.9076L13.8798 14.2531Z" fill="#010002" /></g><defs><clipPath id="clip0_1_30"><rect width="20" height="20" fill="white" /></clipPath></defs></svg>';
95173
+ const splitSvg = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.22222 17H4.55556C3.69689 17 3 16.3031 3 15.4444V4.55556C3 3.69611 3.69689 3 4.55556 3H15.4444C16.3039 3 17 3.69611 17 4.55556V15.4444C17 16.3031 16.3039 17 15.4444 17H10.7778V17.0179H9.22222V17ZM9.22222 15.4444V4.55556H4.55556V15.4444H9.22222ZM15.4444 4.55556H10.7778V15.4444H15.4444V4.55556Z" fill="black" /></svg>';
95174
+ const previewSvg = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fillRule="evenodd" clipRule="evenodd" d="M9.99535 12.9166C11.6062 12.9166 12.912 11.6108 12.912 9.99998C12.912 8.38915 11.6062 7.08331 9.99535 7.08331C8.38452 7.08331 7.07867 8.38915 7.07867 9.99998C7.07867 11.6108 8.38452 12.9166 9.99535 12.9166ZM9.99535 11.2453C9.3076 11.2453 8.75002 10.6877 8.75002 9.99998C8.75002 9.31223 9.3076 8.75465 9.99535 8.75465C10.6831 8.75465 11.2407 9.31223 11.2407 9.99998C11.2407 10.6877 10.6831 11.2453 9.99535 11.2453Z" fill="#0F0F0F" /><path fillRule="evenodd" clipRule="evenodd" d="M10 4.16669C5.99069 4.16669 3.26395 6.3409 1.82445 7.89984C0.714523 9.10185 0.714524 10.8982 1.82445 12.1002C3.26395 13.6592 5.99069 15.8334 10 15.8334C14.0094 15.8334 16.7361 13.6592 18.1756 12.1002C19.2855 10.8982 19.2855 9.10185 18.1756 7.89984C16.7361 6.3409 14.0094 4.16669 10 4.16669ZM3.04893 9.03052C4.32363 7.65004 6.63911 5.83335 10 5.83335C13.3609 5.83335 15.6764 7.65004 16.9511 9.03052C17.4714 9.59402 17.4714 10.406 16.9511 10.9695C15.6764 12.35 13.3609 14.1667 10 14.1667C6.63911 14.1667 4.32363 12.35 3.04893 10.9695C2.52858 10.406 2.52858 9.59402 3.04893 9.03052Z" fill="#0F0F0F" /></svg>';
95175
+
95176
+ const popupHeaderEl = detailsPopupEl.querySelector('#popup-title');
95177
+ const modeSwitcherElement = document.createElement('div');
95178
+ modeSwitcherElement.classList.add('switcher-modes');
95179
+ modeSwitcherElement.innerHTML = '<div class="mode-btn" mode="code">'+codeSvg+'</div><div class="mode-btn" mode="split">'+splitSvg+'</div><div class="mode-btn" mode="preview">'+previewSvg+'</div>';
95180
+ popupHeaderEl.appendChild(modeSwitcherElement);
95181
+ }
95182
+ }
95183
+
95184
+ renderDetailsContent(id, 'code');
95185
+
95186
+ }
95187
+
95188
+ const renderSvg = async (graph) => {
95189
+
95190
+ const graphEl = document.getElementById('graph');
95191
+
95192
+ const height = graphEl.clientHeight || 500;
95193
+ const width = graphEl.clientWidth || 900;
95194
+
95195
+ try {
95196
+ const svgEl = await getSvg(graph, 'dot');
95197
+ svgEl.setAttribute('width', width + 'px');
95198
+ svgEl.setAttribute('height', height + 'px');
95199
+
95200
+ document.getElementById("graph").innerHTML = '';
95201
+ document.getElementById("graph").appendChild(svgEl);
95202
+
95203
+ const svgD3 = d3.select('#graph svg');
95204
+
95205
+ svgD3.on("mousedown", function (event) {
95206
+ xRef = event.clientX;
95207
+ yRef = event.clientY;
95208
+ isDraggingRef = false;
95209
+ });
95210
+
95211
+ svgD3.on("mousemove", function (event) {
95212
+ if (event.buttons === 1) {
95213
+ const dx = event.clientX - xRef;
95214
+ const dy = event.clientY - yRef;
95215
+ if (Math.sqrt(dx * dx + dy * dy) > dragThreshold) {
95216
+ isDraggingRef = true;
95217
+ }
95218
+ }
95219
+ });
95220
+
95221
+ zoomInstance = svgPanZoom(svgEl, {
95222
+ zoomEnabled: true,
95223
+ controlIconsEnabled: true,
95224
+ fit: true,
95225
+ center: true,
95226
+ minZoom: 0.1,
95227
+ maxZoom: 400
95228
+ });
95229
+
95230
+ svgEl.addEventListener('paneresize', function (e) {
95231
+ zoomInstance.resize();
95232
+ }, false);
95233
+ window.addEventListener('resize', function (e) {
95234
+ zoomInstance.resize();
95235
+ });
95236
+ console.timeEnd('render graph');
95237
+
95238
+ addGraphEvents();
95239
+
95240
+
95241
+ } catch (error) {
95242
+ console.info(error)
95243
+ }
95244
+ };
95245
+ <\/script>
95246
+ `;
94670
95247
  const newHtmlContent = `
94671
95248
  <!DOCTYPE html>
94672
95249
  <html lang="en">
94673
95250
  <head>
94674
95251
  <meta charset="UTF-8">
94675
95252
  <title>Alan Text Chat History</title>
95253
+ <link href="${LIBS_PREFIX}/main.css?v=1" rel="stylesheet" />
95254
+ <link href="${LIBS_PREFIX}/highlight.light.css" rel="stylesheet" />
95255
+ <script src="${LIBS_PREFIX}/d3.v7.min.js" type="text/javascript"><\/script>
95256
+ <script src="${LIBS_PREFIX}/viz-standalone.js" type="text/javascript"><\/script>
95257
+ <script src="${LIBS_PREFIX}/svg-pan-zoom.min.js" type="text/javascript"><\/script>
95258
+ <script src="${LIBS_PREFIX}/alan_markdown.js" type="text/javascript"><\/script>
95259
+ <script src="${LIBS_PREFIX}/highlight.min.js?v=2" type="text/javascript"><\/script>
94676
95260
  ${headContent ? headContent : ""}
94677
95261
  <style>
94678
95262
  * {
@@ -94700,6 +95284,9 @@ code.hljs {
94700
95284
  .alan-btn__history-chat-header > h1 {
94701
95285
  padding-left: 10px !important;
94702
95286
  color: #000;
95287
+ font-size: 2em;
95288
+ margin-block-start: 0.67em;
95289
+ margin-block-end: 0.67em;
94703
95290
  }
94704
95291
  .alan-btn__history-chat-header {
94705
95292
  margin: 0px auto;
@@ -94730,6 +95317,143 @@ code.hljs {
94730
95317
  gap: 20px;
94731
95318
  justify-content: flex-end;
94732
95319
  }
95320
+
95321
+ .alan-btn__chat-graph {
95322
+ display: flex!important;
95323
+ cursor:pointer;
95324
+ margin-top: 4px;
95325
+ align-items: flex-end;
95326
+ }
95327
+
95328
+ .alan-btn__chat-graph svg {
95329
+ max-width: 16px;
95330
+ }
95331
+
95332
+ #overlay {
95333
+ position: fixed;
95334
+ top: 0;
95335
+ left: 0;
95336
+ width: 100%;
95337
+ height: 100%;
95338
+ background: #0000004d;
95339
+ display: flex;
95340
+ align-items: center;
95341
+ justify-content: center;
95342
+ }
95343
+
95344
+ #popup {
95345
+ height: 90%;
95346
+ width: 90%;
95347
+ border-radius: 8px;
95348
+ background: #fff;
95349
+ color:#000;
95350
+ }
95351
+
95352
+ #popup-title {
95353
+ padding: 0 20px;
95354
+ height: 40px;
95355
+ position:relative;
95356
+ display:flex;
95357
+ align-items: center;
95358
+ justify-content: flex-start;
95359
+ font-weight: bold;
95360
+ font-size: 20px;
95361
+ border-bottom: 1px solid rgba(211, 211, 211, .5);
95362
+ }
95363
+
95364
+ #popup-close-btn {
95365
+ position: absolute;
95366
+ top:10px;
95367
+ right:10px;
95368
+ cursor: pointer;
95369
+ }
95370
+
95371
+ #graph {
95372
+ height:calc(100% - 40px);
95373
+ width: 100%;
95374
+ display: flex;
95375
+ align-items: center;
95376
+ justify-content: center;
95377
+ }
95378
+
95379
+ #graph svg {
95380
+ backface-visibility: hidden;
95381
+ will-change: transform;
95382
+ width: 100%;
95383
+ }
95384
+
95385
+ #graph svg text {
95386
+ font-size: 8.5px;
95387
+ font-family: monospace
95388
+ }
95389
+
95390
+ #details {
95391
+ overflow: auto;
95392
+ height: calc(100% - 40px);
95393
+ font-family: monospace;
95394
+ white-space: pre;
95395
+ }
95396
+
95397
+ .details-content {
95398
+ padding: 20px;
95399
+ overflow: auto;
95400
+ height: 100%;
95401
+ }
95402
+
95403
+ .switcher-modes {
95404
+ position: absolute;
95405
+ right: 40px;
95406
+ display: flex;
95407
+ top: 50%;
95408
+ transform: translateY(-50%);
95409
+ border: 1px solid rgba(0, 121, 232,.5);
95410
+ background-color: rgba(176, 217, 255, 0.15);
95411
+ border-radius: 8px;
95412
+ align-items: center;
95413
+ justify-content: center;
95414
+ }
95415
+
95416
+ .mode-btn {
95417
+ display: flex;
95418
+ align-items: center;
95419
+ justify-content: center;
95420
+ cursor: pointer;
95421
+ padding: 4px;
95422
+ }
95423
+
95424
+ .mode-btn.active {
95425
+ background-color: #b0d9ff73;
95426
+ }
95427
+
95428
+ .mode-btn:first-of-type {
95429
+ border-right: 1px solid rgba(0, 121, 232,.5);
95430
+ }
95431
+
95432
+ .mode-btn:last-of-type {
95433
+ border-left: 1px solid rgba(0, 121, 232,.5);
95434
+ }
95435
+
95436
+ .mode-btn svg path {
95437
+ fill: rgba(0, 121, 232, 1);
95438
+ }
95439
+
95440
+ .mode-btn:hover svg path {
95441
+ fill: #ff8800;
95442
+ }
95443
+
95444
+ .mode-split {
95445
+ display: flex;
95446
+ justify-content: center;
95447
+ }
95448
+
95449
+ .mode-split > div {
95450
+ width: 50%;
95451
+ min-width: 50%;
95452
+ max-width: 50%;
95453
+ }
95454
+ .mode-split > div:first-of-type {
95455
+ border-right: 1px solid rgba(211, 211, 211, .5);
95456
+ }
94733
95457
  </style>
94734
95458
  </head>
94735
95459
  <body class="alan-btn__history-body">
@@ -94825,7 +95549,7 @@ code.hljs {
94825
95549
  ${chatConteiner.outerHTML}
94826
95550
  </div>
94827
95551
  </div>
94828
- ${codeContent ? codeContent : ""}
95552
+ ${code}
94829
95553
  </body>
94830
95554
  </html>
94831
95555
  `;
@@ -94878,6 +95602,33 @@ code.hljs {
94878
95602
  reader.readAsDataURL(blob);
94879
95603
  });
94880
95604
  }
95605
+ async function getOutputLogs(param) {
95606
+ return new Promise((resolve, reject) => {
95607
+ if (!window.tutorProject)
95608
+ reject();
95609
+ window.tutorProject.call("getMessageGraphs", param, function(e, res) {
95610
+ if (e) {
95611
+ reject({ error: e });
95612
+ } else if (res && res.error) {
95613
+ reject({ ...res });
95614
+ } else {
95615
+ if (res.graphs) {
95616
+ resolve(
95617
+ res.graphs.map((el) => ({
95618
+ ...el,
95619
+ context: escapeHtmlForGraph(el?.context || "")
95620
+ }))
95621
+ );
95622
+ } else {
95623
+ reject();
95624
+ }
95625
+ }
95626
+ });
95627
+ });
95628
+ }
95629
+ function escapeHtmlForGraph(unsafe) {
95630
+ return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
95631
+ }
94881
95632
  async function inlineExternalScripts(htmlContent) {
94882
95633
  const parser = new DOMParser();
94883
95634
  const doc = parser.parseFromString(htmlContent, "text/html");
@@ -95046,8 +95797,33 @@ code.hljs {
95046
95797
 
95047
95798
  // alan_btn/alan_btn.ts
95048
95799
  var import_sjcl = __toESM(require_sjcl());
95800
+
95801
+ // alan_btn/src/textChat/chatSuggestions.ts
95802
+ function renderSuggestions(suggestions) {
95803
+ return `<div class="alan-btn__chat-suggestions">
95804
+ ${suggestions?.map((suggestion) => {
95805
+ const { textToAsk, label } = getSuggestionMetadata(suggestion);
95806
+ return `<div class="alan-chat__suggestion" data-alan-button-send-text="${textToAsk}">${label}</div>`;
95807
+ }).join("") || ""}</div>`;
95808
+ }
95809
+ function getSuggestionMetadata(suggestion) {
95810
+ const { text, markdown } = suggestion;
95811
+ let label = "";
95812
+ if (markdown) {
95813
+ label = alanMarkdown(markdown || "");
95814
+ } else {
95815
+ label = text || "";
95816
+ }
95817
+ const textToAsk = (text || label?.replace(/<\/?[^>]+(>|$)/g, "")).replace(/\n/g, " ").trim();
95818
+ return {
95819
+ textToAsk,
95820
+ label
95821
+ };
95822
+ }
95823
+
95824
+ // alan_btn/alan_btn.ts
95049
95825
  (function(ns) {
95050
- uiState.lib.version = "alan-version.1.8.87".replace("alan-version.", "");
95826
+ uiState.lib.version = "alan-version.1.8.89".replace("alan-version.", "");
95051
95827
  if (window.alanBtn) {
95052
95828
  console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
95053
95829
  }
@@ -97352,8 +98128,14 @@ ${curDialogId}`);
97352
98128
  }
97353
98129
  return result ? `<span class="alan-btn__chat-response-text-wrapper">${fixTargetForLinks(result)}</span>` : "";
97354
98130
  }
98131
+ function addGraphIcon(msg) {
98132
+ if (msg.type === "response" /* Response */) {
98133
+ return `<span class='alan-btn__chat-graph' data-request-id="${getMsgReqId(msg)}">${chatIcons.graph}</span>`;
98134
+ }
98135
+ return "";
98136
+ }
97355
98137
  function buildMsgContent(msg) {
97356
- return `${buildImagesContent(msg)}${buildMsgTextContent(msg)}${buildLinksContent(msg)}${buildCommandsBlock(msg, uiState?.textChat?.options)}${buildMsgIncommingLoader(msg)}`;
98138
+ return `${buildImagesContent(msg)}${buildMsgTextContent(msg)}${buildLinksContent(msg)}${buildCommandsBlock(msg, uiState?.textChat?.options)}${buildMsgIncommingLoader(msg)}${addGraphIcon(msg)}`;
97357
98139
  }
97358
98140
  initMathJax(textChatMessages.length, (i2) => getMsgElForMathJax(i2));
97359
98141
  document.addEventListener("click", (e) => {
@@ -97399,7 +98181,10 @@ ${LEARN_MORE_LABEL}
97399
98181
  }, false);
97400
98182
  window.addEventListener("click", (e) => {
97401
98183
  var clickedEl = e.target;
97402
- processClickByButtonInChat(clickedEl, btnInstance, _sendText);
98184
+ processClickByButtonInChat(clickedEl, btnInstance, (text) => {
98185
+ textChatScrollPosition = null;
98186
+ _sendText(text);
98187
+ });
97403
98188
  });
97404
98189
  function getMsgBubbleLabel(msg) {
97405
98190
  if (msg.type === "request" || msg.type === "response") {
@@ -97439,6 +98224,7 @@ ${LEARN_MORE_LABEL}
97439
98224
  if (window.fakeMsg) {
97440
98225
  msg.text = window.fakeMsg?.text || msg.text;
97441
98226
  msg.images = window.fakeMsg?.images || msg.images;
98227
+ msg.suggestions = window.fakeMsg?.suggestions || msg.suggestions;
97442
98228
  msg.links = window.fakeMsg?.links || msg.links;
97443
98229
  if (window.fakeMsg?.text) {
97444
98230
  if (msg.ctx) {
@@ -97472,7 +98258,11 @@ ${LEARN_MORE_LABEL}
97472
98258
  } else {
97473
98259
  innerMsgPart = buildMsgContent(msg);
97474
98260
  }
97475
- msgHtml = `<div class="alan-btn__chat-inner-msg ${msg.type === "request" ? "alan-btn__chat-request" : "alan-btn__chat-response"} ${msg.images?.length > 0 ? "with-images" : ""} ${isMsgContainsTable(innerMsgPart) ? "with-table" : ""} ${isMsgContainsIFrame(innerMsgPart) ? "with-iframe" : ""}">${innerMsgPart}</div>`;
98261
+ let suggestionsHtml = "";
98262
+ if (msg?.suggestions?.length > 0) {
98263
+ suggestionsHtml += renderSuggestions(msg.suggestions);
98264
+ }
98265
+ msgHtml = `<div class="alan-btn__chat-inner-msg ${msg.type === "request" ? "alan-btn__chat-request" : "alan-btn__chat-response"} ${msg.images?.length > 0 ? "with-images" : ""} ${isMsgContainsTable(innerMsgPart) ? "with-table" : ""} ${isMsgContainsIFrame(innerMsgPart) ? "with-iframe" : ""}">${innerMsgPart}</div>${suggestionsHtml}`;
97476
98266
  }
97477
98267
  if (msg.name === "loading") {
97478
98268
  const loaderId = `loading-msg-${guid()}`;
@@ -97490,6 +98280,7 @@ ${LEARN_MORE_LABEL}
97490
98280
  if (isNew) {
97491
98281
  var div = document.createElement("div");
97492
98282
  div.id = "msg-" + msgInd;
98283
+ div.setAttribute("data-request-id", getMsgReqId(msg));
97493
98284
  div.classList.add("alan-btn__chat-msg-holder");
97494
98285
  div.setAttribute("data-msg-index", msgInd);
97495
98286
  if (msg.type === "chat") {
@@ -97499,7 +98290,12 @@ ${LEARN_MORE_LABEL}
97499
98290
  if (msg.type === "connection-separator") {
97500
98291
  div.innerHTML = msgHtml;
97501
98292
  } else {
97502
- div.innerHTML = `${msg.name !== "loading" ? getMsgBubbleLabel(msg) : ""}<div class="alan-btn__chat-bubble-holder">${(msg.type === "chat" || msg.type === "buttons" ? "" : avatarHtml) + msgHtml}</div>`;
98293
+ div.innerHTML = `
98294
+ ${msg.name !== "loading" ? getMsgBubbleLabel(msg) : ""}
98295
+ <div class="alan-btn__chat-bubble-holder">
98296
+ ${msg.type === "chat" || msg.type === "buttons" ? "" : avatarHtml}
98297
+ <div class="supper1">${msgHtml}</div>
98298
+ </div>`;
97503
98299
  }
97504
98300
  msgHolder.appendChild(div);
97505
98301
  if (uiState.textChat.available && textChatIsHidden && msg.type === "response" && msg.read !== true) {
@@ -97526,7 +98322,10 @@ ${LEARN_MORE_LABEL}
97526
98322
  innerEl.innerHTML = innerMsgPart;
97527
98323
  innerEl.classList.remove("alan-incoming-msg");
97528
98324
  innerEl.id = "";
97529
- innerEl.parentElement.insertAdjacentHTML("beforebegin", getMsgBubbleLabel(msg));
98325
+ const chatHolder = innerEl.closest(".alan-btn__chat-bubble-holder");
98326
+ if (chatHolder) {
98327
+ chatHolder.insertAdjacentHTML("beforebegin", getMsgBubbleLabel(msg));
98328
+ }
97530
98329
  if (msg.type === "response" && msg.images?.length > 0) {
97531
98330
  innerEl.classList.add("with-images");
97532
98331
  }
@@ -97564,7 +98363,14 @@ ${LEARN_MORE_LABEL}
97564
98363
  innerEl.insertAdjacentHTML("beforeend", buildMsgTextContent(updatedMsg));
97565
98364
  innerEl.insertAdjacentHTML("beforeend", buildLinksContent(updatedMsg));
97566
98365
  innerEl.insertAdjacentHTML("beforeend", buildCommandsBlock(msg, uiState?.textChat?.options));
97567
- innerEl.insertAdjacentHTML("beforeend", buildMsgIncommingLoader(msg));
98366
+ innerEl.insertAdjacentHTML("beforeend", buildMsgIncommingLoader(updatedMsg));
98367
+ const newSuggestions = msg?.suggestions;
98368
+ if (newSuggestions?.length > 0) {
98369
+ if (innerEl.nextElementSibling?.classList.contains("alan-btn__chat-suggestions")) {
98370
+ innerEl.nextElementSibling.remove();
98371
+ }
98372
+ innerEl.insertAdjacentHTML("afterend", renderSuggestions(updatedMsg.suggestions));
98373
+ }
97568
98374
  if (isMsgContainsTable(innerEl?.innerHTML)) {
97569
98375
  innerEl.classList.add("with-table");
97570
98376
  }
@@ -98186,7 +98992,9 @@ ${LEARN_MORE_LABEL}
98186
98992
  rightHeaderIconsHolder.appendChild(saveChatStateBtnImg);
98187
98993
  rightHeaderIconsHolder.appendChild(expandCollapseChatBtnImg);
98188
98994
  saveChatStateBtnImg.addEventListener("click", async () => {
98189
- const headContent = document.head.innerHTML;
98995
+ const customHeadContent = `
98996
+ ${document.head.innerHTML}
98997
+ `;
98190
98998
  const initChat = document.querySelector("#chatMessagesWrapper");
98191
98999
  if (!initChat)
98192
99000
  return;
@@ -98198,7 +99006,15 @@ ${LEARN_MORE_LABEL}
98198
99006
  saveChatStateBtnImg.classList.remove("saving");
98199
99007
  }, 8e3);
98200
99008
  try {
98201
- await saveChatState(title, initChat, chatWidth2, getProjectId(), headContent);
99009
+ await saveChatState({
99010
+ chatName: title,
99011
+ chatEl: initChat,
99012
+ width: chatWidth2,
99013
+ projectId: getProjectId(),
99014
+ environment: getEnvironment(),
99015
+ requestIds: textChatMessages?.length > 0 ? textChatMessages.filter((m) => m.type === "response" /* Response */).map((m) => getMsgReqId(m)) : [],
99016
+ headContent: customHeadContent
99017
+ });
98202
99018
  saveChatStateBtnImg.classList.remove("saving");
98203
99019
  } catch (error) {
98204
99020
  saveChatStateBtnImg.classList.remove("saving");