@promptbook/markdown-utils 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
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-10';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -3570,12 +3570,58 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3570
3570
  // <- TODO: [๐Ÿฅฌ] Encapsulate sha256 to some private utility function
3571
3571
  const rootDirname = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3572
3572
  const filepath = join(...nameToSubfolderPath(hash /* <- TODO: [๐ŸŽŽ] Maybe add some SHA256 prefix */), `${basename.substring(0, MAX_FILENAME_LENGTH)}.${mimeTypeToExtension(mimeType)}`);
3573
- await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
3573
+ // Note: Try to create cache directory, but don't fail if filesystem has issues
3574
+ try {
3575
+ await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
3576
+ }
3577
+ catch (error) {
3578
+ // Note: If we can't create cache directory, we'll handle it when trying to write the file
3579
+ // This handles read-only filesystems, permission issues, and missing parent directories
3580
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3581
+ error.message.includes('read-only') ||
3582
+ error.message.includes('EACCES') ||
3583
+ error.message.includes('EPERM') ||
3584
+ error.message.includes('ENOENT'))) ;
3585
+ else {
3586
+ // Re-throw other unexpected errors
3587
+ throw error;
3588
+ }
3589
+ }
3574
3590
  const fileContent = Buffer.from(await response.arrayBuffer());
3575
3591
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3576
3592
  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.`);
3577
3593
  }
3578
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3594
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
3595
+ try {
3596
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3597
+ }
3598
+ catch (error) {
3599
+ // Note: If we can't write to cache, we'll process the file directly from memory
3600
+ // This handles read-only filesystems like Vercel
3601
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3602
+ error.message.includes('read-only') ||
3603
+ error.message.includes('EACCES') ||
3604
+ error.message.includes('EPERM') ||
3605
+ error.message.includes('ENOENT'))) {
3606
+ // Return a handler that works directly with the downloaded content
3607
+ return {
3608
+ source: name,
3609
+ filename: null,
3610
+ url,
3611
+ mimeType,
3612
+ async asJson() {
3613
+ return JSON.parse(fileContent.toString('utf-8'));
3614
+ },
3615
+ async asText() {
3616
+ return fileContent.toString('utf-8');
3617
+ },
3618
+ };
3619
+ }
3620
+ else {
3621
+ // Re-throw other unexpected errors
3622
+ throw error;
3623
+ }
3624
+ }
3579
3625
  // TODO: [๐Ÿ’ต] Check the file security
3580
3626
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
3581
3627
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {