@promptbook/legacy-documents 0.100.0-1 โ†’ 0.100.0-10

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
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-10';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -1026,7 +1026,23 @@ async function getScraperIntermediateSource(source, options) {
1026
1026
  .join('/') +
1027
1027
  '.' +
1028
1028
  extension;
1029
- await mkdir(dirname(cacheFilename), { recursive: true });
1029
+ // Note: Try to create cache directory, but don't fail if filesystem has issues
1030
+ try {
1031
+ await mkdir(dirname(cacheFilename), { recursive: true });
1032
+ }
1033
+ catch (error) {
1034
+ // Note: If we can't create cache directory, continue without it
1035
+ // This handles read-only filesystems, permission issues, and missing parent directories
1036
+ if (error instanceof Error && (error.message.includes('EROFS') ||
1037
+ error.message.includes('read-only') ||
1038
+ error.message.includes('EACCES') ||
1039
+ error.message.includes('EPERM') ||
1040
+ error.message.includes('ENOENT'))) ;
1041
+ else {
1042
+ // Re-throw other unexpected errors
1043
+ throw error;
1044
+ }
1045
+ }
1030
1046
  let isDestroyed = true;
1031
1047
  const fileHandler = {
1032
1048
  filename: cacheFilename,
@@ -3648,12 +3664,58 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3648
3664
  // <- TODO: [๐Ÿฅฌ] Encapsulate sha256 to some private utility function
3649
3665
  const rootDirname = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3650
3666
  const filepath = join(...nameToSubfolderPath(hash /* <- TODO: [๐ŸŽŽ] Maybe add some SHA256 prefix */), `${basename.substring(0, MAX_FILENAME_LENGTH)}.${mimeTypeToExtension(mimeType)}`);
3651
- await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
3667
+ // Note: Try to create cache directory, but don't fail if filesystem has issues
3668
+ try {
3669
+ await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
3670
+ }
3671
+ catch (error) {
3672
+ // Note: If we can't create cache directory, we'll handle it when trying to write the file
3673
+ // This handles read-only filesystems, permission issues, and missing parent directories
3674
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3675
+ error.message.includes('read-only') ||
3676
+ error.message.includes('EACCES') ||
3677
+ error.message.includes('EPERM') ||
3678
+ error.message.includes('ENOENT'))) ;
3679
+ else {
3680
+ // Re-throw other unexpected errors
3681
+ throw error;
3682
+ }
3683
+ }
3652
3684
  const fileContent = Buffer.from(await response.arrayBuffer());
3653
3685
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3654
3686
  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.`);
3655
3687
  }
3656
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3688
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
3689
+ try {
3690
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3691
+ }
3692
+ catch (error) {
3693
+ // Note: If we can't write to cache, we'll process the file directly from memory
3694
+ // This handles read-only filesystems like Vercel
3695
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3696
+ error.message.includes('read-only') ||
3697
+ error.message.includes('EACCES') ||
3698
+ error.message.includes('EPERM') ||
3699
+ error.message.includes('ENOENT'))) {
3700
+ // Return a handler that works directly with the downloaded content
3701
+ return {
3702
+ source: name,
3703
+ filename: null,
3704
+ url,
3705
+ mimeType,
3706
+ async asJson() {
3707
+ return JSON.parse(fileContent.toString('utf-8'));
3708
+ },
3709
+ async asText() {
3710
+ return fileContent.toString('utf-8');
3711
+ },
3712
+ };
3713
+ }
3714
+ else {
3715
+ // Re-throw other unexpected errors
3716
+ throw error;
3717
+ }
3718
+ }
3657
3719
  // TODO: [๐Ÿ’ต] Check the file security
3658
3720
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
3659
3721
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {