@alan-ai/alan-sdk-web 1.8.130 → 1.8.132

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
@@ -89356,7 +89356,7 @@
89356
89356
  hasFooterLinks = !!tempNode.querySelector(".footnotes");
89357
89357
  tempNode.remove();
89358
89358
  }
89359
- const links = msg.links?.filter((link) => isValidUrl2(link?.href));
89359
+ const links = msg.links?.filter((link) => isValidUrl(link?.href));
89360
89360
  for (let i = 0; i < links?.length; i++) {
89361
89361
  const curLink = links[i];
89362
89362
  const target = getLinkTarget(curLink);
@@ -89383,7 +89383,7 @@
89383
89383
  return "_blank";
89384
89384
  }
89385
89385
  }
89386
- function isValidUrl2(url) {
89386
+ function isValidUrl(url) {
89387
89387
  try {
89388
89388
  const parsedUrl = new URL(url);
89389
89389
  const hasValidProtocol = parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:";
@@ -98713,6 +98713,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98713
98713
  inlineScript.setAttribute(attr2.name, attr2.value);
98714
98714
  }
98715
98715
  });
98716
+ inlineScript.setAttribute("inlined-resource-name", src);
98716
98717
  inlineScript.textContent = scriptContent;
98717
98718
  scriptTag.parentNode.replaceChild(inlineScript, scriptTag);
98718
98719
  console.log(`Inlined script from ${src}`);
@@ -98726,6 +98727,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98726
98727
  try {
98727
98728
  const cssContent = await fetchResourceWithCache(href);
98728
98729
  const inlineStyle = doc.createElement("style");
98730
+ inlineStyle.setAttribute("inlined-resource-name", href);
98729
98731
  inlineStyle.textContent = cssContent;
98730
98732
  linkTag.parentNode.replaceChild(inlineStyle, linkTag);
98731
98733
  console.log(`Inlined stylesheet from ${href}`);
@@ -98762,48 +98764,58 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98762
98764
  const getStudioResourceUrlFn = extractFunction(code, "getStudioResourceUrl");
98763
98765
  const getProjectResourceUrlFn = extractFunction(code, "getProjectResourceUrl");
98764
98766
  const getDefaultResourcesFn = extractFunction(code, "getDefaultResources");
98765
- let getResourceUrl = null;
98766
- let getStudioResourceUrl = null;
98767
- let getProjectResourceUrl = null;
98768
- let isValidUrl = null;
98769
- let getDefaultResources = null;
98767
+ let iframeGetResourceUrl = null;
98768
+ let iframeGetStudioResourceUrl = null;
98769
+ let iframeGetProjectResourceUrl = null;
98770
+ let iframeIsValidUrl = null;
98771
+ let iframeGetDefaultResources = null;
98770
98772
  try {
98771
- if (isValidUrlFn) {
98772
- eval(`isValidUrl = ${isValidUrlFn}`);
98773
- }
98774
- if (getResourceUrlFn) {
98775
- eval(`getResourceUrl = ${getResourceUrlFn}`);
98776
- }
98777
- if (getStudioResourceUrlFn) {
98778
- eval(`getStudioResourceUrl = ${getStudioResourceUrlFn}`);
98779
- }
98780
- if (getProjectResourceUrlFn) {
98781
- eval(`getProjectResourceUrl = ${getProjectResourceUrlFn}`);
98782
- }
98783
- if (getDefaultResourcesFn) {
98784
- eval(`getDefaultResources = ${getDefaultResourcesFn}`);
98773
+ const extracted = eval(`
98774
+ (function() {
98775
+ const isValidUrl = ${isValidUrlFn || "null"};
98776
+ const getResourceUrl = ${getResourceUrlFn || "null"};
98777
+ const getStudioResourceUrl = ${getStudioResourceUrlFn || "null"};
98778
+ const getProjectResourceUrl = ${getProjectResourceUrlFn || "null"};
98779
+ const getDefaultResources = ${getDefaultResourcesFn || "null"};
98780
+
98781
+ return {
98782
+ isValidUrl,
98783
+ getResourceUrl,
98784
+ getStudioResourceUrl,
98785
+ getProjectResourceUrl,
98786
+ getDefaultResources
98787
+ };
98788
+ })()
98789
+ `);
98790
+ if (extracted) {
98791
+ iframeIsValidUrl = extracted.isValidUrl;
98792
+ iframeGetResourceUrl = extracted.getResourceUrl;
98793
+ iframeGetStudioResourceUrl = extracted.getStudioResourceUrl;
98794
+ iframeGetProjectResourceUrl = extracted.getProjectResourceUrl;
98795
+ iframeGetDefaultResources = extracted.getDefaultResources;
98785
98796
  }
98786
98797
  } catch (error) {
98787
98798
  console.error("Failed to parse resource-related functions using eval:", error);
98788
98799
  }
98789
98800
  let hasInternalFunctions = true;
98790
- if (!getResourceUrl || !getStudioResourceUrl || !getProjectResourceUrl || !isValidUrl || !getDefaultResources) {
98801
+ if (!iframeGetResourceUrl || !iframeGetStudioResourceUrl || !iframeGetProjectResourceUrl || !iframeIsValidUrl || !iframeGetDefaultResources) {
98791
98802
  hasInternalFunctions = false;
98792
98803
  console.error("Unable to parse resource-related functions from the iframe code. Some iframes may appear without content.");
98793
98804
  }
98794
98805
  allInitIframeResourcesInlined = true;
98795
98806
  if (hasInternalFunctions) {
98796
98807
  const addDefaultStylesOptions = extractAddDefaultStylesParams(initIframeBody);
98797
- if (addDefaultStylesOptions && getDefaultResources) {
98808
+ if (addDefaultStylesOptions && iframeGetDefaultResources) {
98798
98809
  try {
98799
- const basicResources = getDefaultResources(addDefaultStylesOptions);
98810
+ const basicResources = iframeGetDefaultResources(addDefaultStylesOptions);
98800
98811
  await Promise.all(basicResources.map(async (resource) => {
98801
98812
  try {
98802
98813
  const resourceType = resource.type;
98803
98814
  if (resourceType === "stylesheet" && resource.href) {
98804
- const resourceUrl = getResourceUrl(resource.href);
98815
+ const resourceUrl = iframeGetResourceUrl(resource.href);
98805
98816
  const resourceContent = await fetchResourceWithCache(resourceUrl);
98806
98817
  const inlineStyle = doc.createElement("style");
98818
+ inlineStyle.setAttribute("inlined-resource-name", resource.href);
98807
98819
  inlineStyle.textContent = resourceContent;
98808
98820
  doc.head.appendChild(inlineStyle);
98809
98821
  console.log(`Inlined basic style from getDefaultResources: ${resourceUrl}`);
@@ -98816,12 +98828,36 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98816
98828
  console.error("Failed to get or inline basic resources:", error);
98817
98829
  }
98818
98830
  }
98819
- await Promise.all(resourceUrls.map(async (resource) => {
98831
+ const resourceResults = await Promise.all(resourceUrls.map(async (resource) => {
98820
98832
  try {
98821
- const resourceUrl = getResourceUrl(resource.url);
98833
+ const resourceUrl = iframeGetResourceUrl(resource.url);
98822
98834
  const resourceContent = await fetchResourceWithCache(resourceUrl);
98835
+ return {
98836
+ success: true,
98837
+ resource,
98838
+ resourceUrl,
98839
+ resourceContent
98840
+ };
98841
+ } catch (error) {
98842
+ console.error(`Failed to fetch resource from ${resource.url}:`, error);
98843
+ return {
98844
+ success: false,
98845
+ resource,
98846
+ error
98847
+ };
98848
+ }
98849
+ }));
98850
+ let insertionPoint = doc.head.firstChild;
98851
+ for (const result of resourceResults) {
98852
+ if (!result.success) {
98853
+ allInitIframeResourcesInlined = false;
98854
+ continue;
98855
+ }
98856
+ const { resource, resourceUrl, resourceContent } = result;
98857
+ try {
98823
98858
  if (resource.type === "addScript" || resource.url.endsWith(".js")) {
98824
98859
  const inlineScript = doc.createElement("script");
98860
+ inlineScript.setAttribute("inlined-resource-name", resource.url);
98825
98861
  inlineScript.textContent = resourceContent;
98826
98862
  if (resource.options) {
98827
98863
  const optionsObj = safelyParseScriptOptions(resource.options);
@@ -98835,19 +98871,22 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
98835
98871
  if (optionsObj.crossOrigin) inlineScript.setAttribute("crossorigin", optionsObj.crossOrigin);
98836
98872
  }
98837
98873
  }
98838
- doc.head.appendChild(inlineScript);
98874
+ doc.head.insertBefore(inlineScript, insertionPoint);
98875
+ insertionPoint = inlineScript.nextSibling;
98839
98876
  console.log(`Inlined script: ${resourceUrl}${inlineScript.type ? " (type=" + inlineScript.type + ")" : ""}`);
98840
98877
  } else if (resource.type === "addStyleSheet" || resource.url.endsWith(".css")) {
98841
98878
  const inlineStyle = doc.createElement("style");
98879
+ inlineStyle.setAttribute("inlined-resource-name", resource.url);
98842
98880
  inlineStyle.textContent = resourceContent;
98843
- doc.head.appendChild(inlineStyle);
98881
+ doc.head.insertBefore(inlineStyle, insertionPoint);
98882
+ insertionPoint = inlineStyle.nextSibling;
98844
98883
  console.log(`Inlined stylesheet: ${resourceUrl}`);
98845
98884
  }
98846
98885
  } catch (error) {
98847
98886
  console.error(`Failed to inline resource from ${resource.url}:`, error);
98848
98887
  allInitIframeResourcesInlined = false;
98849
98888
  }
98850
- }));
98889
+ }
98851
98890
  }
98852
98891
  }
98853
98892
  return {
@@ -99026,7 +99065,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
99026
99065
  }
99027
99066
 
99028
99067
  // alan_btn/src/textChat/helpers/resources.ts
99029
- function isValidUrl3(url) {
99068
+ function isValidUrl2(url) {
99030
99069
  try {
99031
99070
  new URL(url);
99032
99071
  return true;
@@ -99034,21 +99073,21 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
99034
99073
  return false;
99035
99074
  }
99036
99075
  }
99037
- function getProjectResourceUrl2(resourcePath) {
99076
+ function getProjectResourceUrl(resourcePath) {
99038
99077
  const resourceBaseUrl = uiState.resourceBaseUrl;
99039
99078
  return `${resourceBaseUrl}/` + resourcePath;
99040
99079
  }
99041
- function getResourceUrl2(resourceUrl) {
99080
+ function getResourceUrl(resourceUrl) {
99042
99081
  const resourceBaseUrl = uiState.resourceBaseUrl;
99043
99082
  const projectResPrefix = "resource://";
99044
99083
  const studioResPrefix = "studio-resource://";
99045
- const withPublicUrl = isValidUrl3(resourceUrl);
99084
+ const withPublicUrl = isValidUrl2(resourceUrl);
99046
99085
  if (!resourceUrl) {
99047
99086
  return `${resourceBaseUrl}`;
99048
99087
  }
99049
99088
  if (!withPublicUrl || resourceUrl.startsWith(projectResPrefix)) {
99050
99089
  const cleanResource = resourceUrl.startsWith(projectResPrefix) ? resourceUrl.slice(projectResPrefix.length) : resourceUrl;
99051
- return getProjectResourceUrl2(cleanResource);
99090
+ return getProjectResourceUrl(cleanResource);
99052
99091
  }
99053
99092
  return resourceUrl;
99054
99093
  }
@@ -99057,19 +99096,19 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
99057
99096
  let el;
99058
99097
  if (resource.type === "script" && resource.src) {
99059
99098
  el = document.createElement("script");
99060
- el.src = getResourceUrl2(resource.src);
99099
+ el.src = getResourceUrl(resource.src);
99061
99100
  el.onload = () => resolve(resource);
99062
99101
  el.onerror = () => reject(new Error("Failed to load script:", resource.src));
99063
99102
  } else if (resource.type === "stylesheet" && resource.href) {
99064
99103
  el = document.createElement("link");
99065
99104
  el.rel = "stylesheet";
99066
- el.href = getResourceUrl2(resource.href);
99105
+ el.href = getResourceUrl(resource.href);
99067
99106
  el.onload = () => resolve(resource);
99068
99107
  el.onerror = () => reject(new Error("Failed to load stylesheet:", resource.href));
99069
99108
  } else if (resource.type === "font" && resource.href) {
99070
99109
  el = document.createElement("link");
99071
99110
  el.rel = "stylesheet";
99072
- el.href = getResourceUrl2(resource.href);
99111
+ el.href = getResourceUrl(resource.href);
99073
99112
  el.onload = () => resolve(resource);
99074
99113
  el.onerror = () => reject(new Error("Failed to load stylesheet:", resource.href));
99075
99114
  }
@@ -99113,7 +99152,7 @@ var hljs=function(){"use strict";function e(n){return n instanceof Map?n.clear=n
99113
99152
  // alan_btn/alan_btn.ts
99114
99153
  (function(ns) {
99115
99154
  const uiState10 = getUIState();
99116
- const version2 = "alan-version.1.8.130".replace("alan-version.", "");
99155
+ const version2 = "alan-version.1.8.132".replace("alan-version.", "");
99117
99156
  uiState10.lib.version = version2;
99118
99157
  window.alanLib = { version: version2 };
99119
99158
  if (window.alanBtn) {