@promptbook/core 0.52.0-19 → 0.52.0-24

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/README.md CHANGED
@@ -96,7 +96,7 @@ File `write-website-content.ptbk.md`:
96
96
  >
97
97
  > Instructions for creating web page content.
98
98
  >
99
- > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md@v0.1.0
99
+ > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md
100
100
  > - PROMPTBOOK VERSION 0.0.1
101
101
  > - INPUT  PARAM `{rawTitle}` Automatically suggested a site name or empty text
102
102
  > - INPUT  PARAM `{rawAssigment}` Automatically generated site entry from image recognition
package/esm/index.es.js CHANGED
@@ -448,7 +448,7 @@ function union() {
448
448
  /**
449
449
  * The version of the Promptbook library
450
450
  */
451
- var PROMPTBOOK_VERSION = '0.52.0-18';
451
+ var PROMPTBOOK_VERSION = '0.52.0-23';
452
452
 
453
453
  /**
454
454
  * Parses the template and returns the list of all parameter names
@@ -3354,6 +3354,7 @@ function createPromptbookLibraryFromSources() {
3354
3354
  *
3355
3355
  * @param promptbookSourcesPromiseOrFactory
3356
3356
  * @returns PromptbookLibrary
3357
+ * @private Just internal tool for other constructor functions
3357
3358
  */
3358
3359
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3359
3360
  var library;
@@ -3426,100 +3427,115 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3426
3427
  * Constructs Promptbook from given directory
3427
3428
  *
3428
3429
  * Note: Works only in Node.js environment because it reads the file system
3429
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
3430
- * SO during the construction syntax and logic sources IS NOT validated
3431
3430
  *
3432
3431
  * @param path - path to the directory with promptbooks
3433
3432
  * @param options - Misc options for the library
3434
3433
  * @returns PromptbookLibrary
3435
3434
  */
3436
3435
  function createPromptbookLibraryFromDirectory(path, options) {
3437
- var _this = this;
3438
- if (!isRunningInNode()) {
3439
- throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3440
- }
3441
- var _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c;
3442
- return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3443
- var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbook, promptbookString, _a, _b, e_1_1;
3444
- var e_1, _c;
3445
- return __generator(this, function (_d) {
3446
- switch (_d.label) {
3436
+ return __awaiter(this, void 0, void 0, function () {
3437
+ var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, library;
3438
+ var _this = this;
3439
+ return __generator(this, function (_e) {
3440
+ switch (_e.label) {
3447
3441
  case 0:
3448
- fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3449
- readFile = fsPromises.readFile;
3450
- return [4 /*yield*/, listAllFiles(path, isRecursive)];
3451
- case 1:
3452
- fileNames = _d.sent();
3453
- if (isVerbose) {
3454
- console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3455
- }
3456
- promptbooks = [];
3457
- _d.label = 2;
3458
- case 2:
3459
- _d.trys.push([2, 11, 12, 13]);
3460
- fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
3461
- _d.label = 3;
3462
- case 3:
3463
- if (!!fileNames_1_1.done) return [3 /*break*/, 10];
3464
- fileName = fileNames_1_1.value;
3465
- promptbook = null;
3466
- if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
3467
- return [4 /*yield*/, readFile(fileName, 'utf8')];
3468
- case 4:
3469
- promptbookString = (_d.sent());
3470
- promptbook = promptbookStringToJson(promptbookString);
3471
- return [3 /*break*/, 8];
3472
- case 5:
3473
- if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
3474
- if (isVerbose) {
3475
- console.info("Loading ".concat(fileName));
3476
- }
3477
- _b = (_a = JSON).parse;
3478
- return [4 /*yield*/, readFile(fileName, 'utf8')];
3479
- case 6:
3480
- // TODO: Handle non-valid JSON files
3481
- promptbook = _b.apply(_a, [_d.sent()]);
3482
- return [3 /*break*/, 8];
3483
- case 7:
3484
- if (isVerbose) {
3485
- console.info("Skipping file ".concat(fileName));
3442
+ if (!isRunningInNode()) {
3443
+ throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3486
3444
  }
3487
- _d.label = 8;
3488
- case 8:
3489
- // ---
3490
- if (promptbook !== null) {
3491
- if (!promptbook.promptbookUrl) {
3492
- if (isVerbose) {
3493
- console.info("Not loading ".concat(fileName, " - missing URL"));
3494
- }
3495
- }
3496
- else {
3497
- if (isVerbose) {
3498
- console.info("Loading ".concat(fileName));
3445
+ _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d;
3446
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3447
+ var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbook, promptbookString, _a, _b, e_1_1;
3448
+ var e_1, _c;
3449
+ return __generator(this, function (_d) {
3450
+ switch (_d.label) {
3451
+ case 0:
3452
+ if (isVerbose) {
3453
+ console.info("Creating promptbook library from path ".concat(path));
3454
+ }
3455
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3456
+ readFile = fsPromises.readFile;
3457
+ return [4 /*yield*/, listAllFiles(path, isRecursive)];
3458
+ case 1:
3459
+ fileNames = _d.sent();
3460
+ if (isVerbose) {
3461
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3462
+ }
3463
+ promptbooks = [];
3464
+ _d.label = 2;
3465
+ case 2:
3466
+ _d.trys.push([2, 11, 12, 13]);
3467
+ fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
3468
+ _d.label = 3;
3469
+ case 3:
3470
+ if (!!fileNames_1_1.done) return [3 /*break*/, 10];
3471
+ fileName = fileNames_1_1.value;
3472
+ promptbook = null;
3473
+ if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
3474
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3475
+ case 4:
3476
+ promptbookString = (_d.sent());
3477
+ promptbook = promptbookStringToJson(promptbookString);
3478
+ return [3 /*break*/, 8];
3479
+ case 5:
3480
+ if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
3481
+ if (isVerbose) {
3482
+ console.info("Loading ".concat(fileName));
3483
+ }
3484
+ _b = (_a = JSON).parse;
3485
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3486
+ case 6:
3487
+ // TODO: Handle non-valid JSON files
3488
+ promptbook = _b.apply(_a, [_d.sent()]);
3489
+ return [3 /*break*/, 8];
3490
+ case 7:
3491
+ if (isVerbose) {
3492
+ console.info("Skipping file ".concat(fileName));
3493
+ }
3494
+ _d.label = 8;
3495
+ case 8:
3496
+ // ---
3497
+ if (promptbook !== null) {
3498
+ if (!promptbook.promptbookUrl) {
3499
+ if (isVerbose) {
3500
+ console.info("Not loading ".concat(fileName, " - missing URL"));
3501
+ }
3502
+ }
3503
+ else {
3504
+ if (isVerbose) {
3505
+ console.info("Loading ".concat(fileName));
3506
+ }
3507
+ // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3508
+ promptbooks.push(promptbook);
3509
+ }
3510
+ }
3511
+ _d.label = 9;
3512
+ case 9:
3513
+ fileNames_1_1 = fileNames_1.next();
3514
+ return [3 /*break*/, 3];
3515
+ case 10: return [3 /*break*/, 13];
3516
+ case 11:
3517
+ e_1_1 = _d.sent();
3518
+ e_1 = { error: e_1_1 };
3519
+ return [3 /*break*/, 13];
3520
+ case 12:
3521
+ try {
3522
+ if (fileNames_1_1 && !fileNames_1_1.done && (_c = fileNames_1.return)) _c.call(fileNames_1);
3523
+ }
3524
+ finally { if (e_1) throw e_1.error; }
3525
+ return [7 /*endfinally*/];
3526
+ case 13: return [2 /*return*/, promptbooks];
3499
3527
  }
3500
- // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3501
- promptbooks.push(promptbook);
3502
- }
3503
- }
3504
- _d.label = 9;
3505
- case 9:
3506
- fileNames_1_1 = fileNames_1.next();
3507
- return [3 /*break*/, 3];
3508
- case 10: return [3 /*break*/, 13];
3509
- case 11:
3510
- e_1_1 = _d.sent();
3511
- e_1 = { error: e_1_1 };
3512
- return [3 /*break*/, 13];
3513
- case 12:
3514
- try {
3515
- if (fileNames_1_1 && !fileNames_1_1.done && (_c = fileNames_1.return)) _c.call(fileNames_1);
3516
- }
3517
- finally { if (e_1) throw e_1.error; }
3518
- return [7 /*endfinally*/];
3519
- case 13: return [2 /*return*/, promptbooks];
3528
+ });
3529
+ }); });
3530
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3531
+ return [4 /*yield*/, library.listPromptbooks()];
3532
+ case 1:
3533
+ _e.sent();
3534
+ _e.label = 2;
3535
+ case 2: return [2 /*return*/, library];
3520
3536
  }
3521
3537
  });
3522
- }); });
3538
+ });
3523
3539
  }
3524
3540
  /**
3525
3541
  * Reads all files in the directory
@@ -3596,15 +3612,34 @@ function listAllFiles(path, isRecursive) {
3596
3612
 
3597
3613
  /**
3598
3614
  * Constructs Promptbook from remote Promptbase URL
3599
- *
3600
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
3601
- * SO during the construction syntax and logic sources IS NOT validated
3602
- *
3615
+
3603
3616
  * @returns PromptbookLibrary
3604
3617
  */
3605
- function createPromptbookLibraryFromUrl() {
3606
- throw new Error('Not implemented yet');
3607
- // TODO: !! Load dynamically DO NOT use createPromptbookLibraryFromPromise
3618
+ function createPromptbookLibraryFromUrl(url, options) {
3619
+ return __awaiter(this, void 0, void 0, function () {
3620
+ var _a, _b, isVerbose, _c, isLazyLoaded, library;
3621
+ var _this = this;
3622
+ return __generator(this, function (_d) {
3623
+ switch (_d.label) {
3624
+ case 0:
3625
+ _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3626
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3627
+ return __generator(this, function (_a) {
3628
+ if (isVerbose) {
3629
+ console.info("Creating promptbook library from url ".concat(url.toString()));
3630
+ }
3631
+ throw new Error('Not implemented yet');
3632
+ });
3633
+ }); });
3634
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3635
+ return [4 /*yield*/, library.listPromptbooks()];
3636
+ case 1:
3637
+ _d.sent();
3638
+ _d.label = 2;
3639
+ case 2: return [2 /*return*/, library];
3640
+ }
3641
+ });
3642
+ });
3608
3643
  }
3609
3644
  /***
3610
3645
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
@@ -3713,6 +3748,9 @@ function justTestFsImport() {
3713
3748
  });
3714
3749
  });
3715
3750
  }
3751
+ /**
3752
+ * TODO: !!! Remove this file
3753
+ */
3716
3754
 
3717
3755
  /**
3718
3756
  * Format either small or big number
@@ -4014,5 +4052,5 @@ function executionReportJsonToString(executionReportJson, options) {
4014
4052
  * TODO: [🧠] Allow to filter out some parts of the report by options
4015
4053
  */
4016
4054
 
4017
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4055
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4018
4056
  //# sourceMappingURL=index.es.js.map