@promptbook/core 0.52.0-31 → 0.52.0-33
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 +0 -1
- package/esm/index.es.js +107 -62
- package/esm/index.es.js.map +1 -1
- package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -0
- package/package.json +1 -1
- package/umd/index.umd.js +107 -62
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -0
package/umd/index.umd.js
CHANGED
|
@@ -454,7 +454,7 @@
|
|
|
454
454
|
/**
|
|
455
455
|
* The version of the Promptbook library
|
|
456
456
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.52.0-
|
|
457
|
+
var PROMPTBOOK_VERSION = '0.52.0-32';
|
|
458
458
|
|
|
459
459
|
/**
|
|
460
460
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3175,6 +3175,20 @@
|
|
|
3175
3175
|
return SimplePromptInterfaceTools;
|
|
3176
3176
|
}());
|
|
3177
3177
|
|
|
3178
|
+
/**
|
|
3179
|
+
* This error indicates that the promptbook library cannot be propperly loaded
|
|
3180
|
+
*/
|
|
3181
|
+
var PromptbookLibraryError = /** @class */ (function (_super) {
|
|
3182
|
+
__extends(PromptbookLibraryError, _super);
|
|
3183
|
+
function PromptbookLibraryError(message) {
|
|
3184
|
+
var _this = _super.call(this, message) || this;
|
|
3185
|
+
_this.name = 'PromptbookLibraryError';
|
|
3186
|
+
Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
|
|
3187
|
+
return _this;
|
|
3188
|
+
}
|
|
3189
|
+
return PromptbookLibraryError;
|
|
3190
|
+
}(Error));
|
|
3191
|
+
|
|
3178
3192
|
/**
|
|
3179
3193
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
3180
3194
|
*/
|
|
@@ -3453,20 +3467,20 @@
|
|
|
3453
3467
|
*/
|
|
3454
3468
|
function createPromptbookLibraryFromDirectory(path, options) {
|
|
3455
3469
|
return __awaiter(this, void 0, void 0, function () {
|
|
3456
|
-
var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, library;
|
|
3470
|
+
var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
|
|
3457
3471
|
var _this = this;
|
|
3458
|
-
return __generator(this, function (
|
|
3459
|
-
switch (
|
|
3472
|
+
return __generator(this, function (_f) {
|
|
3473
|
+
switch (_f.label) {
|
|
3460
3474
|
case 0:
|
|
3461
3475
|
if (!isRunningInNode()) {
|
|
3462
3476
|
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3463
3477
|
}
|
|
3464
|
-
_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;
|
|
3478
|
+
_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, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
|
|
3465
3479
|
library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3466
|
-
var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName,
|
|
3467
|
-
var e_1,
|
|
3468
|
-
return __generator(this, function (
|
|
3469
|
-
switch (
|
|
3480
|
+
var fsPromises, readFile, fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
3481
|
+
var e_1, _a;
|
|
3482
|
+
return __generator(this, function (_b) {
|
|
3483
|
+
switch (_b.label) {
|
|
3470
3484
|
case 0:
|
|
3471
3485
|
if (isVerbose) {
|
|
3472
3486
|
console.info("Creating promptbook library from path ".concat(path));
|
|
@@ -3475,82 +3489,113 @@
|
|
|
3475
3489
|
readFile = fsPromises.readFile;
|
|
3476
3490
|
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
3477
3491
|
case 1:
|
|
3478
|
-
fileNames =
|
|
3492
|
+
fileNames = _b.sent();
|
|
3479
3493
|
if (isVerbose) {
|
|
3480
3494
|
console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
|
|
3481
3495
|
}
|
|
3482
3496
|
promptbooks = [];
|
|
3483
|
-
|
|
3497
|
+
_loop_1 = function (fileName) {
|
|
3498
|
+
var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
|
|
3499
|
+
return __generator(this, function (_e) {
|
|
3500
|
+
switch (_e.label) {
|
|
3501
|
+
case 0:
|
|
3502
|
+
_e.trys.push([0, 6, , 7]);
|
|
3503
|
+
promptbook = null;
|
|
3504
|
+
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 2];
|
|
3505
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3506
|
+
case 1:
|
|
3507
|
+
promptbookString = (_e.sent());
|
|
3508
|
+
promptbook = promptbookStringToJson(promptbookString);
|
|
3509
|
+
return [3 /*break*/, 5];
|
|
3510
|
+
case 2:
|
|
3511
|
+
if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 4];
|
|
3512
|
+
if (isVerbose) {
|
|
3513
|
+
console.info("Loading ".concat(fileName));
|
|
3514
|
+
}
|
|
3515
|
+
_d = (_c = JSON).parse;
|
|
3516
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3517
|
+
case 3:
|
|
3518
|
+
// TODO: Handle non-valid JSON files
|
|
3519
|
+
promptbook = _d.apply(_c, [_e.sent()]);
|
|
3520
|
+
return [3 /*break*/, 5];
|
|
3521
|
+
case 4:
|
|
3522
|
+
if (isVerbose) {
|
|
3523
|
+
console.info("Skipping file ".concat(fileName));
|
|
3524
|
+
}
|
|
3525
|
+
_e.label = 5;
|
|
3526
|
+
case 5:
|
|
3527
|
+
// ---
|
|
3528
|
+
if (promptbook !== null) {
|
|
3529
|
+
if (!promptbook.promptbookUrl) {
|
|
3530
|
+
if (isVerbose) {
|
|
3531
|
+
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
else {
|
|
3535
|
+
if (isVerbose) {
|
|
3536
|
+
console.info("Loading ".concat(fileName));
|
|
3537
|
+
}
|
|
3538
|
+
if (!isCrashOnError) {
|
|
3539
|
+
// TODO: !!!! Is it working
|
|
3540
|
+
// Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
|
|
3541
|
+
// But be handled in current try-catch block
|
|
3542
|
+
validatePromptbookJson(promptbook);
|
|
3543
|
+
}
|
|
3544
|
+
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
|
|
3545
|
+
promptbooks.push(promptbook);
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
return [3 /*break*/, 7];
|
|
3549
|
+
case 6:
|
|
3550
|
+
error_1 = _e.sent();
|
|
3551
|
+
if (!(error_1 instanceof Error)) {
|
|
3552
|
+
throw error_1;
|
|
3553
|
+
}
|
|
3554
|
+
wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading promptbook from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
3555
|
+
if (isCrashOnError) {
|
|
3556
|
+
throw new PromptbookLibraryError(wrappedErrorMessage);
|
|
3557
|
+
}
|
|
3558
|
+
console.error(wrappedErrorMessage);
|
|
3559
|
+
return [3 /*break*/, 7];
|
|
3560
|
+
case 7: return [2 /*return*/];
|
|
3561
|
+
}
|
|
3562
|
+
});
|
|
3563
|
+
};
|
|
3564
|
+
_b.label = 2;
|
|
3484
3565
|
case 2:
|
|
3485
|
-
|
|
3566
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
3486
3567
|
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3487
|
-
|
|
3568
|
+
_b.label = 3;
|
|
3488
3569
|
case 3:
|
|
3489
|
-
if (!!fileNames_1_1.done) return [3 /*break*/,
|
|
3570
|
+
if (!!fileNames_1_1.done) return [3 /*break*/, 6];
|
|
3490
3571
|
fileName = fileNames_1_1.value;
|
|
3491
|
-
|
|
3492
|
-
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3493
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3572
|
+
return [5 /*yield**/, _loop_1(fileName)];
|
|
3494
3573
|
case 4:
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
return [3 /*break*/, 8];
|
|
3574
|
+
_b.sent();
|
|
3575
|
+
_b.label = 5;
|
|
3498
3576
|
case 5:
|
|
3499
|
-
if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
|
|
3500
|
-
if (isVerbose) {
|
|
3501
|
-
console.info("Loading ".concat(fileName));
|
|
3502
|
-
}
|
|
3503
|
-
_b = (_a = JSON).parse;
|
|
3504
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3505
|
-
case 6:
|
|
3506
|
-
// TODO: Handle non-valid JSON files
|
|
3507
|
-
promptbook = _b.apply(_a, [_d.sent()]);
|
|
3508
|
-
return [3 /*break*/, 8];
|
|
3509
|
-
case 7:
|
|
3510
|
-
if (isVerbose) {
|
|
3511
|
-
console.info("Skipping file ".concat(fileName));
|
|
3512
|
-
}
|
|
3513
|
-
_d.label = 8;
|
|
3514
|
-
case 8:
|
|
3515
|
-
// ---
|
|
3516
|
-
if (promptbook !== null) {
|
|
3517
|
-
if (!promptbook.promptbookUrl) {
|
|
3518
|
-
if (isVerbose) {
|
|
3519
|
-
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3520
|
-
}
|
|
3521
|
-
}
|
|
3522
|
-
else {
|
|
3523
|
-
if (isVerbose) {
|
|
3524
|
-
console.info("Loading ".concat(fileName));
|
|
3525
|
-
}
|
|
3526
|
-
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
|
|
3527
|
-
promptbooks.push(promptbook);
|
|
3528
|
-
}
|
|
3529
|
-
}
|
|
3530
|
-
_d.label = 9;
|
|
3531
|
-
case 9:
|
|
3532
3577
|
fileNames_1_1 = fileNames_1.next();
|
|
3533
3578
|
return [3 /*break*/, 3];
|
|
3534
|
-
case
|
|
3535
|
-
case
|
|
3536
|
-
e_1_1 =
|
|
3579
|
+
case 6: return [3 /*break*/, 9];
|
|
3580
|
+
case 7:
|
|
3581
|
+
e_1_1 = _b.sent();
|
|
3537
3582
|
e_1 = { error: e_1_1 };
|
|
3538
|
-
return [3 /*break*/,
|
|
3539
|
-
case
|
|
3583
|
+
return [3 /*break*/, 9];
|
|
3584
|
+
case 8:
|
|
3540
3585
|
try {
|
|
3541
|
-
if (fileNames_1_1 && !fileNames_1_1.done && (
|
|
3586
|
+
if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
|
|
3542
3587
|
}
|
|
3543
3588
|
finally { if (e_1) throw e_1.error; }
|
|
3544
3589
|
return [7 /*endfinally*/];
|
|
3545
|
-
case
|
|
3590
|
+
case 9: return [2 /*return*/, promptbooks];
|
|
3546
3591
|
}
|
|
3547
3592
|
});
|
|
3548
3593
|
}); });
|
|
3549
3594
|
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3550
3595
|
return [4 /*yield*/, library.listPromptbooks()];
|
|
3551
3596
|
case 1:
|
|
3552
|
-
|
|
3553
|
-
|
|
3597
|
+
_f.sent();
|
|
3598
|
+
_f.label = 2;
|
|
3554
3599
|
case 2: return [2 /*return*/, library];
|
|
3555
3600
|
}
|
|
3556
3601
|
});
|