@promptbook/wizard 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
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
38
38
  * @generated
39
39
  * @see https://github.com/webgptorg/promptbook
40
40
  */
41
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
41
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-2';
42
42
  /**
43
43
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
44
44
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -192,12 +192,9 @@ const SMALL_NUMBER = 0.001;
192
192
  /**
193
193
  * Timeout for the connections in milliseconds
194
194
  *
195
- * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
196
- * like Facebook login which may require user interaction and redirects
197
- *
198
195
  * @private within the repository - too low-level in comparison with other `MAX_...`
199
196
  */
200
- const CONNECTION_TIMEOUT_MS = 30 * 1000;
197
+ const CONNECTION_TIMEOUT_MS = 7 * 1000;
201
198
  // <- TODO: [โณ] Standardize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
202
199
  /**
203
200
  * How many times to retry the connections
@@ -1389,39 +1386,13 @@ async function createRemoteClient(options) {
1389
1386
  transports: ['polling', 'websocket' /*, <- TODO: [๐ŸŒฌ] Allow to pass `transports`, add 'webtransport' */],
1390
1387
  });
1391
1388
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
1392
- let isResolved = false;
1393
1389
  socket.on('connect', () => {
1394
- if (!isResolved) {
1395
- isResolved = true;
1396
- resolve(socket);
1397
- }
1398
- });
1399
- socket.on('connect_error', (error) => {
1400
- if (!isResolved) {
1401
- isResolved = true;
1402
- reject(new Error(`Failed to connect to ${remoteServerUrl}: ${error.message || error}`));
1403
- }
1390
+ resolve(socket);
1404
1391
  });
1405
- socket.on('disconnect', (reason) => {
1406
- if (!isResolved) {
1407
- isResolved = true;
1408
- reject(new Error(`Connection to ${remoteServerUrl} was disconnected: ${reason}`));
1409
- }
1410
- });
1411
- // Better timeout handling with more descriptive error message
1412
- const timeoutId = setTimeout(() => {
1413
- if (!isResolved) {
1414
- isResolved = true;
1415
- socket.disconnect();
1416
- reject(new Error(`Connection timeout after ${CONNECTION_TIMEOUT_MS / 1000} seconds while connecting to ${remoteServerUrl}. ` +
1417
- `This may indicate network issues or the server may be experiencing high load. ` +
1418
- `For authentication flows like social login, ensure sufficient time is allowed for user interaction.`));
1419
- }
1392
+ // TODO: [๐Ÿ’ฉ] Better timeout handling
1393
+ setTimeout(() => {
1394
+ reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
1420
1395
  }, CONNECTION_TIMEOUT_MS);
1421
- // Clean up timeout if connection succeeds
1422
- socket.on('connect', () => {
1423
- clearTimeout(timeoutId);
1424
- });
1425
1396
  });
1426
1397
  }
1427
1398
 
@@ -1467,33 +1438,8 @@ class RemoteLlmExecutionTools {
1467
1438
  * Check the configuration of all execution tools
1468
1439
  */
1469
1440
  async checkConfiguration() {
1470
- try {
1471
- const socket = await createRemoteClient(this.options);
1472
- socket.disconnect();
1473
- }
1474
- catch (error) {
1475
- if (error instanceof Error) {
1476
- // Provide user-friendly error messages for common connection issues
1477
- if (error.message.includes('timeout') || error.message.includes('Timeout')) {
1478
- throw new Error(`Connection to Promptbook server timed out. This may happen during authentication flows like Facebook login. ` +
1479
- `Please ensure: 1) Server is running at ${this.options.remoteServerUrl}, ` +
1480
- `2) Network connection is stable, 3) Authentication process is completed within the timeout period. ` +
1481
- `Original error: ${error.message}`);
1482
- }
1483
- if (error.message.includes('connect') || error.message.includes('ECONNREFUSED')) {
1484
- throw new Error(`Cannot connect to Promptbook server at ${this.options.remoteServerUrl}. ` +
1485
- `Please check if the server is running and accessible. ` +
1486
- `Original error: ${error.message}`);
1487
- }
1488
- if (error.message.includes('authentication') || error.message.includes('auth')) {
1489
- throw new Error(`Authentication failed when connecting to Promptbook server. ` +
1490
- `This may happen if social login (like Facebook) was not completed properly. ` +
1491
- `Please retry the authentication process. ` +
1492
- `Original error: ${error.message}`);
1493
- }
1494
- }
1495
- throw error; // Re-throw if not a recognized error pattern
1496
- }
1441
+ const socket = await createRemoteClient(this.options);
1442
+ socket.disconnect();
1497
1443
  // TODO: [main] !!3 Check version of the remote server and compatibility
1498
1444
  // TODO: [๐ŸŽ] Send checkConfiguration
1499
1445
  }
@@ -7786,7 +7732,36 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
7786
7732
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
7787
7733
  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.`);
7788
7734
  }
7789
- await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
7735
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
7736
+ try {
7737
+ await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
7738
+ }
7739
+ catch (error) {
7740
+ // Note: If we can't write to cache, we'll process the file directly from memory
7741
+ // This handles read-only filesystems like Vercel
7742
+ if (error instanceof Error && (error.message.includes('EROFS') ||
7743
+ error.message.includes('read-only') ||
7744
+ error.message.includes('EACCES') ||
7745
+ error.message.includes('EPERM'))) {
7746
+ // Return a handler that works directly with the downloaded content
7747
+ return {
7748
+ source: name,
7749
+ filename: null,
7750
+ url,
7751
+ mimeType,
7752
+ async asJson() {
7753
+ return JSON.parse(fileContent.toString('utf-8'));
7754
+ },
7755
+ async asText() {
7756
+ return fileContent.toString('utf-8');
7757
+ },
7758
+ };
7759
+ }
7760
+ else {
7761
+ // Re-throw other unexpected errors
7762
+ throw error;
7763
+ }
7764
+ }
7790
7765
  // TODO: [๐Ÿ’ต] Check the file security
7791
7766
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
7792
7767
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
@@ -10864,7 +10839,22 @@ class MarkitdownScraper {
10864
10839
  // <- TODO: [๐Ÿ€] Make MarkitdownError
10865
10840
  }
10866
10841
  // console.log('!!', { result, cacheFilehandler });
10867
- await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
10842
+ // Note: Try to cache the converted content, but don't fail if the filesystem is read-only
10843
+ try {
10844
+ await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
10845
+ }
10846
+ catch (error) {
10847
+ // Note: If we can't write to cache, we'll continue without caching
10848
+ // This handles read-only filesystems like Vercel
10849
+ if (error instanceof Error && (error.message.includes('EROFS') ||
10850
+ error.message.includes('read-only') ||
10851
+ error.message.includes('EACCES') ||
10852
+ error.message.includes('EPERM'))) ;
10853
+ else {
10854
+ // Re-throw other unexpected errors
10855
+ throw error;
10856
+ }
10857
+ }
10868
10858
  }
10869
10859
  return cacheFilehandler;
10870
10860
  }
@@ -11152,7 +11142,22 @@ class WebsiteScraper {
11152
11142
  extension: 'html',
11153
11143
  isVerbose,
11154
11144
  });
11155
- await this.tools.fs.writeFile(cacheFilehandler.filename, html, 'utf-8');
11145
+ // Note: Try to cache the scraped content, but don't fail if the filesystem is read-only
11146
+ try {
11147
+ await this.tools.fs.writeFile(cacheFilehandler.filename, html, 'utf-8');
11148
+ }
11149
+ catch (error) {
11150
+ // Note: If we can't write to cache, we'll continue without caching
11151
+ // This handles read-only filesystems like Vercel
11152
+ if (error instanceof Error && (error.message.includes('EROFS') ||
11153
+ error.message.includes('read-only') ||
11154
+ error.message.includes('EACCES') ||
11155
+ error.message.includes('EPERM'))) ;
11156
+ else {
11157
+ // Re-throw other unexpected errors
11158
+ throw error;
11159
+ }
11160
+ }
11156
11161
  const markdown = this.showdownConverter.makeMarkdown(html, jsdom.window.document);
11157
11162
  return { ...cacheFilehandler, markdown };
11158
11163
  }
@@ -16764,7 +16769,22 @@ async function $getCompiledBook(tools, pipelineSource, options) {
16764
16769
  ...options,
16765
16770
  });
16766
16771
  const compiledFilePath = filePath.replace('.book.md', '.book').replace('.book', '.bookc');
16767
- await saveArchive(compiledFilePath, [pipelineJson], fs);
16772
+ // Note: Try to save the compiled book to disk for caching, but don't fail if the filesystem is read-only
16773
+ try {
16774
+ await saveArchive(compiledFilePath, [pipelineJson], fs);
16775
+ }
16776
+ catch (error) {
16777
+ // Note: Ignore filesystem errors (like EROFS on read-only systems like Vercel)
16778
+ // The compiled book can still be used even if it can't be cached
16779
+ if (error instanceof Error && (error.message.includes('EROFS') ||
16780
+ error.message.includes('read-only') ||
16781
+ error.message.includes('EACCES') ||
16782
+ error.message.includes('EPERM'))) ;
16783
+ else {
16784
+ // Re-throw other unexpected errors
16785
+ throw error;
16786
+ }
16787
+ }
16768
16788
  return pipelineJson;
16769
16789
  }
16770
16790
  }