@promptbook/node 0.100.0-1 โ†’ 0.100.0-2

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
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-2';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -5615,7 +5615,36 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5615
5615
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5616
5616
  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.`);
5617
5617
  }
5618
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
5618
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
5619
+ try {
5620
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
5621
+ }
5622
+ catch (error) {
5623
+ // Note: If we can't write to cache, we'll process the file directly from memory
5624
+ // This handles read-only filesystems like Vercel
5625
+ if (error instanceof Error && (error.message.includes('EROFS') ||
5626
+ error.message.includes('read-only') ||
5627
+ error.message.includes('EACCES') ||
5628
+ error.message.includes('EPERM'))) {
5629
+ // Return a handler that works directly with the downloaded content
5630
+ return {
5631
+ source: name,
5632
+ filename: null,
5633
+ url,
5634
+ mimeType,
5635
+ async asJson() {
5636
+ return JSON.parse(fileContent.toString('utf-8'));
5637
+ },
5638
+ async asText() {
5639
+ return fileContent.toString('utf-8');
5640
+ },
5641
+ };
5642
+ }
5643
+ else {
5644
+ // Re-throw other unexpected errors
5645
+ throw error;
5646
+ }
5647
+ }
5619
5648
  // TODO: [๐Ÿ’ต] Check the file security
5620
5649
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
5621
5650
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {