@promptbook/wizard 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.
@@ -138,9 +138,6 @@ export declare const SMALL_NUMBER = 0.001;
138
138
  /**
139
139
  * Timeout for the connections in milliseconds
140
140
  *
141
- * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
142
- * like Facebook login which may require user interaction and redirects
143
- *
144
141
  * @private within the repository - too low-level in comparison with other `MAX_...`
145
142
  */
146
143
  export declare const CONNECTION_TIMEOUT_MS: number;
@@ -150,13 +147,6 @@ export declare const CONNECTION_TIMEOUT_MS: number;
150
147
  * @private within the repository - too low-level in comparison with other `MAX_...`
151
148
  */
152
149
  export declare const CONNECTION_RETRIES_LIMIT = 5;
153
- /**
154
- * Timeout specifically for OAuth authentication flows in milliseconds
155
- * OAuth flows typically require more time due to user interaction and redirects
156
- *
157
- * @private within the repository - too low-level in comparison with other `MAX_...`
158
- */
159
- export declare const OAUTH_TIMEOUT_MS: number;
160
150
  /**
161
151
  * Short time interval to prevent race conditions in milliseconds
162
152
  *
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.100.0-0`).
18
+ * It follows semantic versioning (e.g., `0.100.0-2`).
19
19
  *
20
20
  * @generated
21
21
  */
@@ -6,6 +6,15 @@ import type { InputParameters } from '../types/typeAliases';
6
6
  import type { string_filename } from '../types/typeAliases';
7
7
  import type { string_parameter_value } from '../types/typeAliases';
8
8
  import type { string_pipeline_url } from '../types/typeAliases';
9
+ /**
10
+ * Options for wizard methods
11
+ */
12
+ interface WizardOptions {
13
+ /**
14
+ * Whether to enable verbose logging
15
+ */
16
+ isVerbose?: boolean;
17
+ }
9
18
  /**
10
19
  * Wizard for simple usage of the Promptbook
11
20
  * Look at `wizard` for more details
@@ -26,7 +35,7 @@ declare class Wizard {
26
35
  *
27
36
  * Note: This works similar to the `ptbk run` command
28
37
  */
29
- execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters): Promise<{
38
+ execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters, options?: WizardOptions): Promise<{
30
39
  /**
31
40
  * Simple result of the execution
32
41
  */
@@ -36,9 +45,9 @@ declare class Wizard {
36
45
  /**
37
46
  * Provides the tools automatically for the Node.js environment
38
47
  *
39
- * @param pipelineSource
48
+ * @param options
40
49
  */
41
- getExecutionTools(): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
50
+ getExecutionTools(options?: WizardOptions): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
42
51
  /**
43
52
  * Load book from the source
44
53
  *
@@ -49,8 +58,9 @@ declare class Wizard {
49
58
  * 3) As a string
50
59
  *
51
60
  * @param pipelineSource
61
+ * @param options
52
62
  */
53
- getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
63
+ getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString, options?: WizardOptions): Promise<PipelineJson>;
54
64
  }
55
65
  /**
56
66
  * Wizard for simple usage of the Promptbook
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/wizard",
3
- "version": "0.100.0-1",
3
+ "version": "0.100.0-3",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/wizard.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.100.0-1"
98
+ "@promptbook/core": "0.100.0-3"
99
99
  },
100
100
  "dependencies": {
101
101
  "@ai-sdk/deepseek": "0.1.6",
package/umd/index.umd.js CHANGED
@@ -49,7 +49,7 @@
49
49
  * @generated
50
50
  * @see https://github.com/webgptorg/promptbook
51
51
  */
52
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
52
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-3';
53
53
  /**
54
54
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
55
55
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -203,12 +203,9 @@
203
203
  /**
204
204
  * Timeout for the connections in milliseconds
205
205
  *
206
- * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
207
- * like Facebook login which may require user interaction and redirects
208
- *
209
206
  * @private within the repository - too low-level in comparison with other `MAX_...`
210
207
  */
211
- const CONNECTION_TIMEOUT_MS = 30 * 1000;
208
+ const CONNECTION_TIMEOUT_MS = 7 * 1000;
212
209
  // <- TODO: [โณ] Standardize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
213
210
  /**
214
211
  * How many times to retry the connections
@@ -1400,39 +1397,13 @@
1400
1397
  transports: ['polling', 'websocket' /*, <- TODO: [๐ŸŒฌ] Allow to pass `transports`, add 'webtransport' */],
1401
1398
  });
1402
1399
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
1403
- let isResolved = false;
1404
1400
  socket.on('connect', () => {
1405
- if (!isResolved) {
1406
- isResolved = true;
1407
- resolve(socket);
1408
- }
1409
- });
1410
- socket.on('connect_error', (error) => {
1411
- if (!isResolved) {
1412
- isResolved = true;
1413
- reject(new Error(`Failed to connect to ${remoteServerUrl}: ${error.message || error}`));
1414
- }
1401
+ resolve(socket);
1415
1402
  });
1416
- socket.on('disconnect', (reason) => {
1417
- if (!isResolved) {
1418
- isResolved = true;
1419
- reject(new Error(`Connection to ${remoteServerUrl} was disconnected: ${reason}`));
1420
- }
1421
- });
1422
- // Better timeout handling with more descriptive error message
1423
- const timeoutId = setTimeout(() => {
1424
- if (!isResolved) {
1425
- isResolved = true;
1426
- socket.disconnect();
1427
- reject(new Error(`Connection timeout after ${CONNECTION_TIMEOUT_MS / 1000} seconds while connecting to ${remoteServerUrl}. ` +
1428
- `This may indicate network issues or the server may be experiencing high load. ` +
1429
- `For authentication flows like social login, ensure sufficient time is allowed for user interaction.`));
1430
- }
1403
+ // TODO: [๐Ÿ’ฉ] Better timeout handling
1404
+ setTimeout(() => {
1405
+ reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
1431
1406
  }, CONNECTION_TIMEOUT_MS);
1432
- // Clean up timeout if connection succeeds
1433
- socket.on('connect', () => {
1434
- clearTimeout(timeoutId);
1435
- });
1436
1407
  });
1437
1408
  }
1438
1409
 
@@ -1478,33 +1449,8 @@
1478
1449
  * Check the configuration of all execution tools
1479
1450
  */
1480
1451
  async checkConfiguration() {
1481
- try {
1482
- const socket = await createRemoteClient(this.options);
1483
- socket.disconnect();
1484
- }
1485
- catch (error) {
1486
- if (error instanceof Error) {
1487
- // Provide user-friendly error messages for common connection issues
1488
- if (error.message.includes('timeout') || error.message.includes('Timeout')) {
1489
- throw new Error(`Connection to Promptbook server timed out. This may happen during authentication flows like Facebook login. ` +
1490
- `Please ensure: 1) Server is running at ${this.options.remoteServerUrl}, ` +
1491
- `2) Network connection is stable, 3) Authentication process is completed within the timeout period. ` +
1492
- `Original error: ${error.message}`);
1493
- }
1494
- if (error.message.includes('connect') || error.message.includes('ECONNREFUSED')) {
1495
- throw new Error(`Cannot connect to Promptbook server at ${this.options.remoteServerUrl}. ` +
1496
- `Please check if the server is running and accessible. ` +
1497
- `Original error: ${error.message}`);
1498
- }
1499
- if (error.message.includes('authentication') || error.message.includes('auth')) {
1500
- throw new Error(`Authentication failed when connecting to Promptbook server. ` +
1501
- `This may happen if social login (like Facebook) was not completed properly. ` +
1502
- `Please retry the authentication process. ` +
1503
- `Original error: ${error.message}`);
1504
- }
1505
- }
1506
- throw error; // Re-throw if not a recognized error pattern
1507
- }
1452
+ const socket = await createRemoteClient(this.options);
1453
+ socket.disconnect();
1508
1454
  // TODO: [main] !!3 Check version of the remote server and compatibility
1509
1455
  // TODO: [๐ŸŽ] Send checkConfiguration
1510
1456
  }
@@ -7797,7 +7743,36 @@
7797
7743
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
7798
7744
  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.`);
7799
7745
  }
7800
- await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
7746
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
7747
+ try {
7748
+ await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
7749
+ }
7750
+ catch (error) {
7751
+ // Note: If we can't write to cache, we'll process the file directly from memory
7752
+ // This handles read-only filesystems like Vercel
7753
+ if (error instanceof Error && (error.message.includes('EROFS') ||
7754
+ error.message.includes('read-only') ||
7755
+ error.message.includes('EACCES') ||
7756
+ error.message.includes('EPERM'))) {
7757
+ // Return a handler that works directly with the downloaded content
7758
+ return {
7759
+ source: name,
7760
+ filename: null,
7761
+ url,
7762
+ mimeType,
7763
+ async asJson() {
7764
+ return JSON.parse(fileContent.toString('utf-8'));
7765
+ },
7766
+ async asText() {
7767
+ return fileContent.toString('utf-8');
7768
+ },
7769
+ };
7770
+ }
7771
+ else {
7772
+ // Re-throw other unexpected errors
7773
+ throw error;
7774
+ }
7775
+ }
7801
7776
  // TODO: [๐Ÿ’ต] Check the file security
7802
7777
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
7803
7778
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
@@ -10875,7 +10850,22 @@
10875
10850
  // <- TODO: [๐Ÿ€] Make MarkitdownError
10876
10851
  }
10877
10852
  // console.log('!!', { result, cacheFilehandler });
10878
- await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
10853
+ // Note: Try to cache the converted content, but don't fail if the filesystem is read-only
10854
+ try {
10855
+ await this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content);
10856
+ }
10857
+ catch (error) {
10858
+ // Note: If we can't write to cache, we'll continue without caching
10859
+ // This handles read-only filesystems like Vercel
10860
+ if (error instanceof Error && (error.message.includes('EROFS') ||
10861
+ error.message.includes('read-only') ||
10862
+ error.message.includes('EACCES') ||
10863
+ error.message.includes('EPERM'))) ;
10864
+ else {
10865
+ // Re-throw other unexpected errors
10866
+ throw error;
10867
+ }
10868
+ }
10879
10869
  }
10880
10870
  return cacheFilehandler;
10881
10871
  }
@@ -11163,7 +11153,22 @@
11163
11153
  extension: 'html',
11164
11154
  isVerbose,
11165
11155
  });
11166
- await this.tools.fs.writeFile(cacheFilehandler.filename, html, 'utf-8');
11156
+ // Note: Try to cache the scraped content, but don't fail if the filesystem is read-only
11157
+ try {
11158
+ await this.tools.fs.writeFile(cacheFilehandler.filename, html, 'utf-8');
11159
+ }
11160
+ catch (error) {
11161
+ // Note: If we can't write to cache, we'll continue without caching
11162
+ // This handles read-only filesystems like Vercel
11163
+ if (error instanceof Error && (error.message.includes('EROFS') ||
11164
+ error.message.includes('read-only') ||
11165
+ error.message.includes('EACCES') ||
11166
+ error.message.includes('EPERM'))) ;
11167
+ else {
11168
+ // Re-throw other unexpected errors
11169
+ throw error;
11170
+ }
11171
+ }
11167
11172
  const markdown = this.showdownConverter.makeMarkdown(html, jsdom$1.window.document);
11168
11173
  return { ...cacheFilehandler, markdown };
11169
11174
  }
@@ -16775,7 +16780,22 @@
16775
16780
  ...options,
16776
16781
  });
16777
16782
  const compiledFilePath = filePath.replace('.book.md', '.book').replace('.book', '.bookc');
16778
- await saveArchive(compiledFilePath, [pipelineJson], fs);
16783
+ // Note: Try to save the compiled book to disk for caching, but don't fail if the filesystem is read-only
16784
+ try {
16785
+ await saveArchive(compiledFilePath, [pipelineJson], fs);
16786
+ }
16787
+ catch (error) {
16788
+ // Note: Ignore filesystem errors (like EROFS on read-only systems like Vercel)
16789
+ // The compiled book can still be used even if it can't be cached
16790
+ if (error instanceof Error && (error.message.includes('EROFS') ||
16791
+ error.message.includes('read-only') ||
16792
+ error.message.includes('EACCES') ||
16793
+ error.message.includes('EPERM'))) ;
16794
+ else {
16795
+ // Re-throw other unexpected errors
16796
+ throw error;
16797
+ }
16798
+ }
16779
16799
  return pipelineJson;
16780
16800
  }
16781
16801
  }
@@ -16897,14 +16917,14 @@
16897
16917
  *
16898
16918
  * Note: This works similar to the `ptbk run` command
16899
16919
  */
16900
- async execute(book, inputParameters) {
16920
+ async execute(book, inputParameters, options = {}) {
16901
16921
  if (!$isRunningInNode()) {
16902
16922
  throw new EnvironmentMismatchError('Wizard works only in Node.js environment');
16903
16923
  }
16904
16924
  // โ–ถ Get the tools
16905
- const tools = await this.getExecutionTools();
16925
+ const tools = await this.getExecutionTools(options);
16906
16926
  // โ–ถ Get the Pipeline
16907
- const pipeline = await this.getCompiledBook(book);
16927
+ const pipeline = await this.getCompiledBook(book, options);
16908
16928
  // โ–ถ Create executor - the function that will execute the Pipeline
16909
16929
  const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
16910
16930
  // ๐Ÿš€โ–ถ Execute the Pipeline
@@ -16927,15 +16947,16 @@
16927
16947
  /**
16928
16948
  * Provides the tools automatically for the Node.js environment
16929
16949
  *
16930
- * @param pipelineSource
16950
+ * @param options
16931
16951
  */
16932
- async getExecutionTools() {
16952
+ async getExecutionTools(options = {}) {
16953
+ var _a;
16933
16954
  if (this.executionTools !== null) {
16934
16955
  return this.executionTools;
16935
16956
  }
16936
16957
  // TODO: DRY [โ—ฝ]
16937
16958
  const prepareAndScrapeOptions = {
16938
- isVerbose: false,
16959
+ isVerbose: (_a = options.isVerbose) !== null && _a !== void 0 ? _a : false,
16939
16960
  isCacheReloaded: false, // <- TODO: Allow to pass
16940
16961
  }; /* <- TODO: ` satisfies PrepareAndScrapeOptions` */
16941
16962
  const fs = $provideFilesystemForNode();
@@ -16965,9 +16986,10 @@
16965
16986
  * 3) As a string
16966
16987
  *
16967
16988
  * @param pipelineSource
16989
+ * @param options
16968
16990
  */
16969
- async getCompiledBook(pipelineSource) {
16970
- const tools = await this.getExecutionTools();
16991
+ async getCompiledBook(pipelineSource, options = {}) {
16992
+ const tools = await this.getExecutionTools(options);
16971
16993
  return /* not await */ $getCompiledBook(tools, pipelineSource);
16972
16994
  }
16973
16995
  }