@promptbook/core 0.100.0-1 โ†’ 0.100.0-11

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/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-11';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -5920,12 +5920,58 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5920
5920
  // <- TODO: [๐Ÿฅฌ] Encapsulate sha256 to some private utility function
5921
5921
  const rootDirname = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5922
5922
  const filepath = join(...nameToSubfolderPath(hash /* <- TODO: [๐ŸŽŽ] Maybe add some SHA256 prefix */), `${basename.substring(0, MAX_FILENAME_LENGTH)}.${mimeTypeToExtension(mimeType)}`);
5923
- await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
5923
+ // Note: Try to create cache directory, but don't fail if filesystem has issues
5924
+ try {
5925
+ await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
5926
+ }
5927
+ catch (error) {
5928
+ // Note: If we can't create cache directory, we'll handle it when trying to write the file
5929
+ // This handles read-only filesystems, permission issues, and missing parent directories
5930
+ if (error instanceof Error && (error.message.includes('EROFS') ||
5931
+ error.message.includes('read-only') ||
5932
+ error.message.includes('EACCES') ||
5933
+ error.message.includes('EPERM') ||
5934
+ error.message.includes('ENOENT'))) ;
5935
+ else {
5936
+ // Re-throw other unexpected errors
5937
+ throw error;
5938
+ }
5939
+ }
5924
5940
  const fileContent = Buffer.from(await response.arrayBuffer());
5925
5941
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5926
5942
  throw new LimitReachedError(`File is too large (${Math.round(fileContent.length / 1024 / 1024)}MB). Maximum allowed size is ${Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024)}MB.`);
5927
5943
  }
5928
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
5944
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
5945
+ try {
5946
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
5947
+ }
5948
+ catch (error) {
5949
+ // Note: If we can't write to cache, we'll process the file directly from memory
5950
+ // This handles read-only filesystems like Vercel
5951
+ if (error instanceof Error && (error.message.includes('EROFS') ||
5952
+ error.message.includes('read-only') ||
5953
+ error.message.includes('EACCES') ||
5954
+ error.message.includes('EPERM') ||
5955
+ error.message.includes('ENOENT'))) {
5956
+ // Return a handler that works directly with the downloaded content
5957
+ return {
5958
+ source: name,
5959
+ filename: null,
5960
+ url,
5961
+ mimeType,
5962
+ async asJson() {
5963
+ return JSON.parse(fileContent.toString('utf-8'));
5964
+ },
5965
+ async asText() {
5966
+ return fileContent.toString('utf-8');
5967
+ },
5968
+ };
5969
+ }
5970
+ else {
5971
+ // Re-throw other unexpected errors
5972
+ throw error;
5973
+ }
5974
+ }
5929
5975
  // TODO: [๐Ÿ’ต] Check the file security
5930
5976
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
5931
5977
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {