@alan-ai/alan-sdk-web 1.8.137 → 1.8.139

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
@@ -97620,7 +97620,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97620
97620
  const match = code2.match(regex);
97621
97621
  return match ? match[0] : null;
97622
97622
  }
97623
- function extractFunction(code2, functionName) {
97623
+ function extractFunction(code2, functionName, errorLogger2) {
97624
97624
  try {
97625
97625
  const ast = parse8(code2, { ecmaVersion: 2022, allowImportExportEverywhere: true });
97626
97626
  for (const node of ast.body) {
@@ -97629,7 +97629,8 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97629
97629
  }
97630
97630
  }
97631
97631
  } catch (err) {
97632
- console.error(`Failed to parse code for function "${functionName}":`, err);
97632
+ const msg = `Failed to parse code for function "${functionName}":`;
97633
+ errorLogger2(msg, err);
97633
97634
  }
97634
97635
  return null;
97635
97636
  }
@@ -97651,7 +97652,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97651
97652
  const commentedFn = beforeBody + "\n" + commentedBody + "\n" + afterBody;
97652
97653
  return html3.replace(initIframeFn2, commentedFn);
97653
97654
  }
97654
- function extractAddDefaultStylesParams(code2) {
97655
+ function extractAddDefaultStylesParams(code2, errorLogger2) {
97655
97656
  const regex = /(?:iframe\.)?addDefaultStyles\s*\(\s*([\s\S]*?)\s*\)/g;
97656
97657
  let match;
97657
97658
  let merged = {};
@@ -97668,14 +97669,15 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97668
97669
  merged = { ...merged, ...obj };
97669
97670
  }
97670
97671
  } catch (err) {
97671
- console.error("Failed to parse addDefaultStyles parameter:", err);
97672
+ const msg = "Failed to parse addDefaultStyles parameter:";
97673
+ errorLogger2(msg, err);
97672
97674
  return null;
97673
97675
  }
97674
97676
  }
97675
97677
  if (!found) return null;
97676
97678
  return merged;
97677
97679
  }
97678
- function safelyParseScriptOptions(optionsString) {
97680
+ function safelyParseScriptOptions(optionsString, errorLogger2) {
97679
97681
  if (!optionsString || optionsString === "null" || optionsString === "{}") {
97680
97682
  return null;
97681
97683
  }
@@ -97683,7 +97685,8 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97683
97685
  const cleanOptionsString = optionsString.trim();
97684
97686
  return Function('"use strict"; return (' + cleanOptionsString + ")")();
97685
97687
  } catch (error) {
97686
- console.error("Failed to parse script options:", error);
97688
+ const msg = "Failed to parse script options:";
97689
+ errorLogger2(msg, error);
97687
97690
  return null;
97688
97691
  }
97689
97692
  }
@@ -97739,13 +97742,23 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97739
97742
  data: data3,
97740
97743
  options = {}
97741
97744
  }) {
97745
+ const exportErrors = [];
97746
+ const exportLogs = [];
97747
+ function logError(msg, err) {
97748
+ console.error(msg, err);
97749
+ exportErrors.push({ msg, err, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
97750
+ }
97751
+ function logInfo(msg, details) {
97752
+ console.log(msg, details || "");
97753
+ exportLogs.push({ msg, details, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
97754
+ }
97742
97755
  const chatConteiner = chatEl.cloneNode(true);
97743
97756
  const images = Array.from(chatConteiner.querySelectorAll("img"));
97744
97757
  let imgData;
97745
97758
  try {
97746
- imgData = await replaceImagesToBase64(images);
97759
+ imgData = await replaceImagesToBase64(images, logError);
97747
97760
  } catch (error) {
97748
- console.info("Some images from the chat cannot be converter to base64 for export");
97761
+ logError("Some images from the chat cannot be converter to base64 for export", null);
97749
97762
  }
97750
97763
  const iframes = Array.from(chatConteiner.querySelectorAll("iframe"));
97751
97764
  const fetchWithTimeout = async (url, timeoutMs = 3e4) => {
@@ -97771,20 +97784,20 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97771
97784
  try {
97772
97785
  response = await fetchWithTimeout(srcUrl, options?.iframeLoadTimeoutMs);
97773
97786
  if (!response.ok) {
97774
- console.error(`Error fetching content from ${srcUrl}: ${response.statusText}`);
97787
+ logError(`Error fetching content from ${srcUrl}: ${response.statusText}`, null);
97775
97788
  return;
97776
97789
  }
97777
97790
  initHtmlContent = await response.text();
97778
97791
  } catch (err) {
97779
- console.error(`Iframe content not available from ${srcUrl} (treated as Not Found):`, err.message || err);
97792
+ logError(`Iframe content not available from ${srcUrl} (treated as Not Found):`, err.message || err);
97780
97793
  initHtmlContent = "Not Found!";
97781
97794
  }
97782
97795
  initHtmlContent = applyThemeToHtmlContent(initHtmlContent, data3?.theme);
97783
- let { htmlContent: htmlContent2 } = await inlineExternalResources(initHtmlContent);
97796
+ let { htmlContent: htmlContent2 } = await inlineExternalResources(initHtmlContent, logError, logInfo);
97784
97797
  const initIframeFn2 = extractFunctionWithRegex(htmlContent2, "initIframe");
97785
97798
  if (initIframeFn2) {
97786
97799
  htmlContent2 = commentInitIframeFnInSourceCode(htmlContent2, initIframeFn2);
97787
- console.log("Replaced initIframe function with commented version as resources were successfully inlined.");
97800
+ logInfo("Replaced initIframe function with commented version as resources were successfully inlined.");
97788
97801
  }
97789
97802
  const frameSrc = iframe.getAttribute("src");
97790
97803
  iframe.removeAttribute("src");
@@ -97811,7 +97824,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97811
97824
  parent2.insertBefore(controlsDiv, iframe);
97812
97825
  }
97813
97826
  } catch (error) {
97814
- console.error(`Failed to fetch or process iframe from ${srcUrl}:`, error);
97827
+ logError(`Failed to fetch or process iframe from ${srcUrl}:`, error);
97815
97828
  const errorMessage = error?.message || error?.toString() || "Unknown error";
97816
97829
  const errorHtml = `
97817
97830
  <!DOCTYPE html>
@@ -97876,7 +97889,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
97876
97889
  });
97877
97890
  }
97878
97891
  } catch (error) {
97879
- console.info("Chat will be exported without output graphs", error);
97892
+ logError("Chat will be exported without output graphs", error);
97880
97893
  }
97881
97894
  const alanMainClass = "alan-" + projectId;
97882
97895
  const code2 = `
@@ -98300,9 +98313,9 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98300
98313
  let inlinedLibraries = "";
98301
98314
  try {
98302
98315
  inlinedLibraries = getInlineLibrariesHtml();
98303
- console.log("Successfully prepared inline libraries for saved HTML");
98316
+ logInfo("Successfully prepared inline libraries for saved HTML");
98304
98317
  } catch (error) {
98305
- console.error("Failed to prepare inline libraries:", error);
98318
+ logError("Failed to prepare inline libraries:", error);
98306
98319
  }
98307
98320
  const newHtmlContent = `
98308
98321
  <!DOCTYPE html>
@@ -98318,6 +98331,8 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98318
98331
  function showAlanDebugInfo() {
98319
98332
  console.info('Messages in chat:', ${txtMessages});
98320
98333
  console.info('Messages in socket:', ${socketMessages});
98334
+ console.info('Errors in export:', ${escapeJsonForScriptTag(JSON.stringify(exportErrors, null, 2))});
98335
+ console.info('Logs in export:', ${escapeJsonForScriptTag(JSON.stringify(exportLogs, null, 2))});
98321
98336
  }
98322
98337
  <\/script>
98323
98338
 
@@ -98650,7 +98665,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98650
98665
  link.click();
98651
98666
  URL.revokeObjectURL(link.href);
98652
98667
  }
98653
- async function replaceImagesToBase64(images) {
98668
+ async function replaceImagesToBase64(images, errorLogger2) {
98654
98669
  const result = {};
98655
98670
  for (let img of images) {
98656
98671
  try {
@@ -98669,7 +98684,8 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98669
98684
  }
98670
98685
  img.src = await fetchImageAsBase64(img.src);
98671
98686
  } catch (error) {
98672
- console.error(`Error converting images for msgId ${img.getAttribute("msgInd")}:`, error);
98687
+ const msg = `Error converting images for msgId ${img.getAttribute("msgInd")}:`;
98688
+ errorLogger2(msg, error);
98673
98689
  }
98674
98690
  }
98675
98691
  return result;
@@ -98726,7 +98742,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98726
98742
  resourceCache.set(url, fetchPromise);
98727
98743
  return fetchPromise;
98728
98744
  }
98729
- async function inlineExternalResources(htmlContent) {
98745
+ async function inlineExternalResources(htmlContent, errorLogger, infoLogger) {
98730
98746
  const parser = new DOMParser();
98731
98747
  const doc = parser.parseFromString(htmlContent, "text/html");
98732
98748
  const scriptTags = Array.from(doc.querySelectorAll("script[src]"));
@@ -98743,9 +98759,10 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98743
98759
  inlineScript.setAttribute("inlined-resource-name", src);
98744
98760
  inlineScript.textContent = scriptContent;
98745
98761
  scriptTag.parentNode.replaceChild(inlineScript, scriptTag);
98746
- console.log(`Inlined script from ${src}`);
98762
+ infoLogger(`Inlined external script:`, src);
98747
98763
  } catch (error) {
98748
- console.error(`Failed to inline script from ${src}:`, error);
98764
+ const msg = `Failed to inline script from ${src}:`;
98765
+ errorLogger(msg, error);
98749
98766
  }
98750
98767
  }));
98751
98768
  const linkTags = Array.from(doc.querySelectorAll('link[rel="stylesheet"][href]'));
@@ -98757,14 +98774,15 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98757
98774
  inlineStyle.setAttribute("inlined-resource-name", href);
98758
98775
  inlineStyle.textContent = cssContent;
98759
98776
  linkTag.parentNode.replaceChild(inlineStyle, linkTag);
98760
- console.log(`Inlined stylesheet from ${href}`);
98777
+ infoLogger(`Inlined external stylesheet:`, href);
98761
98778
  } catch (error) {
98762
- console.error(`Failed to inline stylesheet from ${href}:`, error);
98779
+ const msg = `Failed to inline stylesheet from ${href}:`;
98780
+ errorLogger(msg, error);
98763
98781
  }
98764
98782
  }));
98765
98783
  const htmlContentWithInlinedScripts = doc.documentElement.outerHTML;
98766
98784
  const code = extractScriptContents(htmlContentWithInlinedScripts);
98767
- const initIframeFn = extractFunction(code, "initIframe");
98785
+ const initIframeFn = extractFunction(code, "initIframe", errorLogger);
98768
98786
  let allInitIframeResourcesInlined = false;
98769
98787
  if (initIframeFn) {
98770
98788
  let initIframeBody = stripComments(initIframeFn);
@@ -98786,11 +98804,19 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98786
98804
  url: resourceFnMatch[1]
98787
98805
  });
98788
98806
  }
98789
- const isValidUrlFn = extractFunction(code, "isValidUrl");
98790
- const getResourceUrlFn = extractFunction(code, "getResourceUrl");
98791
- const getStudioResourceUrlFn = extractFunction(code, "getStudioResourceUrl");
98792
- const getProjectResourceUrlFn = extractFunction(code, "getProjectResourceUrl");
98793
- const getDefaultResourcesFn = extractFunction(code, "getDefaultResources");
98807
+ if (resourceUrls.length === 0) {
98808
+ errorLogger("Regex found ZERO resources in initIframe function.", {
98809
+ initIframeFnLength: initIframeFn.length,
98810
+ initIframeBodyPreview: initIframeBody.substring(0, 500)
98811
+ });
98812
+ } else {
98813
+ infoLogger(`Detected ${resourceUrls.length} resources in initIframe:`, resourceUrls.map((r) => r.url));
98814
+ }
98815
+ const isValidUrlFn = extractFunction(code, "isValidUrl", errorLogger);
98816
+ const getResourceUrlFn = extractFunction(code, "getResourceUrl", errorLogger);
98817
+ const getStudioResourceUrlFn = extractFunction(code, "getStudioResourceUrl", errorLogger);
98818
+ const getProjectResourceUrlFn = extractFunction(code, "getProjectResourceUrl", errorLogger);
98819
+ const getDefaultResourcesFn = extractFunction(code, "getDefaultResources", errorLogger);
98794
98820
  let iframeGetResourceUrl = null;
98795
98821
  let iframeGetStudioResourceUrl = null;
98796
98822
  let iframeGetProjectResourceUrl = null;
@@ -98822,16 +98848,18 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98822
98848
  iframeGetDefaultResources = extracted.getDefaultResources;
98823
98849
  }
98824
98850
  } catch (error) {
98825
- console.error("Failed to parse resource-related functions using eval:", error);
98851
+ const msg = "Failed to parse resource-related functions using eval:";
98852
+ errorLogger(msg, error);
98826
98853
  }
98827
98854
  let hasInternalFunctions = true;
98828
98855
  if (!iframeGetResourceUrl || !iframeGetStudioResourceUrl || !iframeGetProjectResourceUrl || !iframeIsValidUrl || !iframeGetDefaultResources) {
98829
98856
  hasInternalFunctions = false;
98830
- console.error("Unable to parse resource-related functions from the iframe code. Some iframes may appear without content.");
98857
+ const msg = "Unable to parse resource-related functions from the iframe code. Some iframes may appear without content.";
98858
+ errorLogger(msg, null);
98831
98859
  }
98832
98860
  allInitIframeResourcesInlined = true;
98833
98861
  if (hasInternalFunctions) {
98834
- const addDefaultStylesOptions = extractAddDefaultStylesParams(initIframeBody);
98862
+ const addDefaultStylesOptions = extractAddDefaultStylesParams(initIframeBody, errorLogger);
98835
98863
  if (addDefaultStylesOptions && iframeGetDefaultResources) {
98836
98864
  try {
98837
98865
  const basicResources = iframeGetDefaultResources(addDefaultStylesOptions);
@@ -98845,14 +98873,16 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98845
98873
  inlineStyle.setAttribute("inlined-resource-name", resource.href);
98846
98874
  inlineStyle.textContent = resourceContent;
98847
98875
  doc.head.appendChild(inlineStyle);
98848
- console.log(`Inlined basic style from getDefaultResources: ${resourceUrl}`);
98876
+ infoLogger(`Inlined default stylesheet:`, { name: resource.href, url: resourceUrl });
98849
98877
  }
98850
98878
  } catch (error) {
98851
- console.error(`Failed to inline basic resource from ${resource?.href}:`, error);
98879
+ const msg = `Failed to inline basic resource from ${resource?.href}:`;
98880
+ errorLogger(msg, error);
98852
98881
  }
98853
98882
  }));
98854
98883
  } catch (error) {
98855
- console.error("Failed to get or inline basic resources:", error);
98884
+ const msg = "Failed to get or inline basic resources:";
98885
+ errorLogger(msg, error);
98856
98886
  }
98857
98887
  }
98858
98888
  const resourceResults = await Promise.all(resourceUrls.map(async (resource) => {
@@ -98866,7 +98896,8 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98866
98896
  resourceContent
98867
98897
  };
98868
98898
  } catch (error) {
98869
- console.error(`Failed to fetch resource from ${resource.url}:`, error);
98899
+ const msg = `Failed to fetch resource from ${resource.url}:`;
98900
+ errorLogger(msg, error);
98870
98901
  return {
98871
98902
  success: false,
98872
98903
  resource,
@@ -98887,7 +98918,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98887
98918
  inlineScript.setAttribute("inlined-resource-name", resource.url);
98888
98919
  inlineScript.textContent = resourceContent;
98889
98920
  if (resource.options) {
98890
- const optionsObj = safelyParseScriptOptions(resource.options);
98921
+ const optionsObj = safelyParseScriptOptions(resource.options, errorLogger);
98891
98922
  if (optionsObj && typeof optionsObj === "object") {
98892
98923
  if (optionsObj.type) {
98893
98924
  inlineScript.setAttribute("type", optionsObj.type);
@@ -98900,17 +98931,18 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98900
98931
  }
98901
98932
  doc.head.insertBefore(inlineScript, insertionPoint);
98902
98933
  insertionPoint = inlineScript.nextSibling;
98903
- console.log(`Inlined script: ${resourceUrl}${inlineScript.type ? " (type=" + inlineScript.type + ")" : ""}`);
98934
+ infoLogger(`Inlined initIframe script:`, { name: resource.url, url: resourceUrl, type: inlineScript.type || "text/javascript" });
98904
98935
  } else if (resource.type === "addStyleSheet" || resource.url.endsWith(".css")) {
98905
98936
  const inlineStyle = doc.createElement("style");
98906
98937
  inlineStyle.setAttribute("inlined-resource-name", resource.url);
98907
98938
  inlineStyle.textContent = resourceContent;
98908
98939
  doc.head.insertBefore(inlineStyle, insertionPoint);
98909
98940
  insertionPoint = inlineStyle.nextSibling;
98910
- console.log(`Inlined stylesheet: ${resourceUrl}`);
98941
+ infoLogger(`Inlined initIframe stylesheet:`, { name: resource.url, url: resourceUrl });
98911
98942
  }
98912
98943
  } catch (error) {
98913
- console.error(`Failed to inline resource from ${resource.url}:`, error);
98944
+ const msg = `Failed to inline resource from ${resource.url}:`;
98945
+ errorLogger(msg, error);
98914
98946
  allInitIframeResourcesInlined = false;
98915
98947
  }
98916
98948
  }
@@ -99179,7 +99211,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
99179
99211
  // alan_btn/alan_btn.ts
99180
99212
  (function(ns) {
99181
99213
  const uiState10 = getUIState();
99182
- const version2 = "alan-version.1.8.137".replace("alan-version.", "");
99214
+ const version2 = "alan-version.1.8.139".replace("alan-version.", "");
99183
99215
  uiState10.lib.version = version2;
99184
99216
  window.alanLib = { version: version2 };
99185
99217
  if (window.alanBtn) {
@@ -102278,6 +102310,7 @@ ${reason}` : reason,
102278
102310
  if (savedMsgs?.length > 0) {
102279
102311
  clearDOMChat();
102280
102312
  }
102313
+ canceledRequests = [];
102281
102314
  for (let i2 = 0; i2 < savedMsgs.length; i2++) {
102282
102315
  if (initLoad === true) {
102283
102316
  savedMsgs[i2].initLoad = true;