@promptbook/wizard 0.100.0-2 → 0.100.0-4
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 +74 -17
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/esm/typings/src/wizard/wizard.d.ts +14 -4
- package/package.json +2 -2
- package/umd/index.umd.js +74 -17
- package/umd/index.umd.js.map +1 -1
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-
|
41
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-4';
|
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
|
@@ -5963,7 +5963,23 @@ async function getScraperIntermediateSource(source, options) {
|
|
5963
5963
|
.join('/') +
|
5964
5964
|
'.' +
|
5965
5965
|
extension;
|
5966
|
-
|
5966
|
+
// Note: Try to create cache directory, but don't fail if filesystem has issues
|
5967
|
+
try {
|
5968
|
+
await mkdir(dirname(cacheFilename), { recursive: true });
|
5969
|
+
}
|
5970
|
+
catch (error) {
|
5971
|
+
// Note: If we can't create cache directory, continue without it
|
5972
|
+
// This handles read-only filesystems, permission issues, and missing parent directories
|
5973
|
+
if (error instanceof Error && (error.message.includes('EROFS') ||
|
5974
|
+
error.message.includes('read-only') ||
|
5975
|
+
error.message.includes('EACCES') ||
|
5976
|
+
error.message.includes('EPERM') ||
|
5977
|
+
error.message.includes('ENOENT'))) ;
|
5978
|
+
else {
|
5979
|
+
// Re-throw other unexpected errors
|
5980
|
+
throw error;
|
5981
|
+
}
|
5982
|
+
}
|
5967
5983
|
let isDestroyed = true;
|
5968
5984
|
const fileHandler = {
|
5969
5985
|
filename: cacheFilename,
|
@@ -7727,7 +7743,23 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
7727
7743
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
7728
7744
|
const rootDirname = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
7729
7745
|
const filepath = join(...nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */), `${basename.substring(0, MAX_FILENAME_LENGTH)}.${mimeTypeToExtension(mimeType)}`);
|
7730
|
-
|
7746
|
+
// Note: Try to create cache directory, but don't fail if filesystem has issues
|
7747
|
+
try {
|
7748
|
+
await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
|
7749
|
+
}
|
7750
|
+
catch (error) {
|
7751
|
+
// Note: If we can't create cache directory, we'll handle it when trying to write the file
|
7752
|
+
// This handles read-only filesystems, permission issues, and missing parent directories
|
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
|
+
error.message.includes('ENOENT'))) ;
|
7758
|
+
else {
|
7759
|
+
// Re-throw other unexpected errors
|
7760
|
+
throw error;
|
7761
|
+
}
|
7762
|
+
}
|
7731
7763
|
const fileContent = Buffer.from(await response.arrayBuffer());
|
7732
7764
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
7733
7765
|
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.`);
|
@@ -7742,7 +7774,8 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
7742
7774
|
if (error instanceof Error && (error.message.includes('EROFS') ||
|
7743
7775
|
error.message.includes('read-only') ||
|
7744
7776
|
error.message.includes('EACCES') ||
|
7745
|
-
error.message.includes('EPERM')
|
7777
|
+
error.message.includes('EPERM') ||
|
7778
|
+
error.message.includes('ENOENT'))) {
|
7746
7779
|
// Return a handler that works directly with the downloaded content
|
7747
7780
|
return {
|
7748
7781
|
source: name,
|
@@ -10849,7 +10882,8 @@ class MarkitdownScraper {
|
|
10849
10882
|
if (error instanceof Error && (error.message.includes('EROFS') ||
|
10850
10883
|
error.message.includes('read-only') ||
|
10851
10884
|
error.message.includes('EACCES') ||
|
10852
|
-
error.message.includes('EPERM')
|
10885
|
+
error.message.includes('EPERM') ||
|
10886
|
+
error.message.includes('ENOENT'))) ;
|
10853
10887
|
else {
|
10854
10888
|
// Re-throw other unexpected errors
|
10855
10889
|
throw error;
|
@@ -11152,7 +11186,8 @@ class WebsiteScraper {
|
|
11152
11186
|
if (error instanceof Error && (error.message.includes('EROFS') ||
|
11153
11187
|
error.message.includes('read-only') ||
|
11154
11188
|
error.message.includes('EACCES') ||
|
11155
|
-
error.message.includes('EPERM')
|
11189
|
+
error.message.includes('EPERM') ||
|
11190
|
+
error.message.includes('ENOENT'))) ;
|
11156
11191
|
else {
|
11157
11192
|
// Re-throw other unexpected errors
|
11158
11193
|
throw error;
|
@@ -11898,8 +11933,27 @@ class FileCacheStorage {
|
|
11898
11933
|
throw new UnexpectedError(`The "${key}" you want to store in JSON file is not serializable as JSON`);
|
11899
11934
|
}
|
11900
11935
|
const fileContent = stringifyPipelineJson(value);
|
11901
|
-
|
11902
|
-
|
11936
|
+
// Note: Try to create cache directory and write file, but don't fail if filesystem is read-only or has permission issues
|
11937
|
+
try {
|
11938
|
+
await mkdir(dirname(filename), { recursive: true }); // <- [0]
|
11939
|
+
await writeFile(filename, fileContent, 'utf-8');
|
11940
|
+
}
|
11941
|
+
catch (error) {
|
11942
|
+
// Note: If we can't write to cache, silently ignore the error
|
11943
|
+
// This handles read-only filesystems, permission issues, and missing parent directories
|
11944
|
+
if (error instanceof Error && (error.message.includes('EROFS') ||
|
11945
|
+
error.message.includes('read-only') ||
|
11946
|
+
error.message.includes('EACCES') ||
|
11947
|
+
error.message.includes('EPERM') ||
|
11948
|
+
error.message.includes('ENOENT'))) {
|
11949
|
+
// Silently ignore filesystem errors - caching is optional
|
11950
|
+
return;
|
11951
|
+
}
|
11952
|
+
else {
|
11953
|
+
// Re-throw other unexpected errors
|
11954
|
+
throw error;
|
11955
|
+
}
|
11956
|
+
}
|
11903
11957
|
}
|
11904
11958
|
/**
|
11905
11959
|
* Removes the key/value pair with the given key from the storage, if a key/value pair with the given key exists.
|
@@ -16779,7 +16833,8 @@ async function $getCompiledBook(tools, pipelineSource, options) {
|
|
16779
16833
|
if (error instanceof Error && (error.message.includes('EROFS') ||
|
16780
16834
|
error.message.includes('read-only') ||
|
16781
16835
|
error.message.includes('EACCES') ||
|
16782
|
-
error.message.includes('EPERM')
|
16836
|
+
error.message.includes('EPERM') ||
|
16837
|
+
error.message.includes('ENOENT'))) ;
|
16783
16838
|
else {
|
16784
16839
|
// Re-throw other unexpected errors
|
16785
16840
|
throw error;
|
@@ -16906,14 +16961,14 @@ class Wizard {
|
|
16906
16961
|
*
|
16907
16962
|
* Note: This works similar to the `ptbk run` command
|
16908
16963
|
*/
|
16909
|
-
async execute(book, inputParameters) {
|
16964
|
+
async execute(book, inputParameters, options = {}) {
|
16910
16965
|
if (!$isRunningInNode()) {
|
16911
16966
|
throw new EnvironmentMismatchError('Wizard works only in Node.js environment');
|
16912
16967
|
}
|
16913
16968
|
// ▶ Get the tools
|
16914
|
-
const tools = await this.getExecutionTools();
|
16969
|
+
const tools = await this.getExecutionTools(options);
|
16915
16970
|
// ▶ Get the Pipeline
|
16916
|
-
const pipeline = await this.getCompiledBook(book);
|
16971
|
+
const pipeline = await this.getCompiledBook(book, options);
|
16917
16972
|
// ▶ Create executor - the function that will execute the Pipeline
|
16918
16973
|
const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
|
16919
16974
|
// 🚀▶ Execute the Pipeline
|
@@ -16936,15 +16991,16 @@ class Wizard {
|
|
16936
16991
|
/**
|
16937
16992
|
* Provides the tools automatically for the Node.js environment
|
16938
16993
|
*
|
16939
|
-
* @param
|
16994
|
+
* @param options
|
16940
16995
|
*/
|
16941
|
-
async getExecutionTools() {
|
16996
|
+
async getExecutionTools(options = {}) {
|
16997
|
+
var _a;
|
16942
16998
|
if (this.executionTools !== null) {
|
16943
16999
|
return this.executionTools;
|
16944
17000
|
}
|
16945
17001
|
// TODO: DRY [◽]
|
16946
17002
|
const prepareAndScrapeOptions = {
|
16947
|
-
isVerbose: false,
|
17003
|
+
isVerbose: (_a = options.isVerbose) !== null && _a !== void 0 ? _a : false,
|
16948
17004
|
isCacheReloaded: false, // <- TODO: Allow to pass
|
16949
17005
|
}; /* <- TODO: ` satisfies PrepareAndScrapeOptions` */
|
16950
17006
|
const fs = $provideFilesystemForNode();
|
@@ -16974,9 +17030,10 @@ class Wizard {
|
|
16974
17030
|
* 3) As a string
|
16975
17031
|
*
|
16976
17032
|
* @param pipelineSource
|
17033
|
+
* @param options
|
16977
17034
|
*/
|
16978
|
-
async getCompiledBook(pipelineSource) {
|
16979
|
-
const tools = await this.getExecutionTools();
|
17035
|
+
async getCompiledBook(pipelineSource, options = {}) {
|
17036
|
+
const tools = await this.getExecutionTools(options);
|
16980
17037
|
return /* not await */ $getCompiledBook(tools, pipelineSource);
|
16981
17038
|
}
|
16982
17039
|
}
|