@promptbook/pdf 0.100.0-1 โ†’ 0.100.0-3

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
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-3';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -3502,7 +3502,36 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3502
3502
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3503
3503
  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.`);
3504
3504
  }
3505
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3505
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
3506
+ try {
3507
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
3508
+ }
3509
+ catch (error) {
3510
+ // Note: If we can't write to cache, we'll process the file directly from memory
3511
+ // This handles read-only filesystems like Vercel
3512
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3513
+ error.message.includes('read-only') ||
3514
+ error.message.includes('EACCES') ||
3515
+ error.message.includes('EPERM'))) {
3516
+ // Return a handler that works directly with the downloaded content
3517
+ return {
3518
+ source: name,
3519
+ filename: null,
3520
+ url,
3521
+ mimeType,
3522
+ async asJson() {
3523
+ return JSON.parse(fileContent.toString('utf-8'));
3524
+ },
3525
+ async asText() {
3526
+ return fileContent.toString('utf-8');
3527
+ },
3528
+ };
3529
+ }
3530
+ else {
3531
+ // Re-throw other unexpected errors
3532
+ throw error;
3533
+ }
3534
+ }
3506
3535
  // TODO: [๐Ÿ’ต] Check the file security
3507
3536
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
3508
3537
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
@@ -6288,7 +6317,22 @@ class MarkitdownScraper {
6288
6317
  // <- TODO: [๐Ÿ€] Make MarkitdownError
6289
6318
  }
6290
6319
  // console.log('!!', { result, cacheFilehandler });
6291
- await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
6320
+ // Note: Try to cache the converted content, but don't fail if the filesystem is read-only
6321
+ try {
6322
+ await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
6323
+ }
6324
+ catch (error) {
6325
+ // Note: If we can't write to cache, we'll continue without caching
6326
+ // This handles read-only filesystems like Vercel
6327
+ if (error instanceof Error && (error.message.includes('EROFS') ||
6328
+ error.message.includes('read-only') ||
6329
+ error.message.includes('EACCES') ||
6330
+ error.message.includes('EPERM'))) ;
6331
+ else {
6332
+ // Re-throw other unexpected errors
6333
+ throw error;
6334
+ }
6335
+ }
6292
6336
  }
6293
6337
  return cacheFilehandler;
6294
6338
  }