@promptbook/core 0.52.0-30 → 0.52.0-32
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 +102 -62
- package/esm/index.es.js.map +1 -1
- package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
- package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +102 -62
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
- package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +7 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +1 -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-31';
|
|
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,107 @@
|
|
|
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
|
+
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
|
|
3539
|
+
promptbooks.push(promptbook);
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
return [3 /*break*/, 7];
|
|
3543
|
+
case 6:
|
|
3544
|
+
error_1 = _e.sent();
|
|
3545
|
+
if (!(error_1 instanceof Error)) {
|
|
3546
|
+
throw error_1;
|
|
3547
|
+
}
|
|
3548
|
+
wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading promptbook from file ".concat(fileName, ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
3549
|
+
if (isCrashOnError) {
|
|
3550
|
+
throw new PromptbookLibraryError(wrappedErrorMessage);
|
|
3551
|
+
}
|
|
3552
|
+
console.error(wrappedErrorMessage);
|
|
3553
|
+
return [3 /*break*/, 7];
|
|
3554
|
+
case 7: return [2 /*return*/];
|
|
3555
|
+
}
|
|
3556
|
+
});
|
|
3557
|
+
};
|
|
3558
|
+
_b.label = 2;
|
|
3484
3559
|
case 2:
|
|
3485
|
-
|
|
3560
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
3486
3561
|
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3487
|
-
|
|
3562
|
+
_b.label = 3;
|
|
3488
3563
|
case 3:
|
|
3489
|
-
if (!!fileNames_1_1.done) return [3 /*break*/,
|
|
3564
|
+
if (!!fileNames_1_1.done) return [3 /*break*/, 6];
|
|
3490
3565
|
fileName = fileNames_1_1.value;
|
|
3491
|
-
|
|
3492
|
-
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3493
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3566
|
+
return [5 /*yield**/, _loop_1(fileName)];
|
|
3494
3567
|
case 4:
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
return [3 /*break*/, 8];
|
|
3568
|
+
_b.sent();
|
|
3569
|
+
_b.label = 5;
|
|
3498
3570
|
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
3571
|
fileNames_1_1 = fileNames_1.next();
|
|
3533
3572
|
return [3 /*break*/, 3];
|
|
3534
|
-
case
|
|
3535
|
-
case
|
|
3536
|
-
e_1_1 =
|
|
3573
|
+
case 6: return [3 /*break*/, 9];
|
|
3574
|
+
case 7:
|
|
3575
|
+
e_1_1 = _b.sent();
|
|
3537
3576
|
e_1 = { error: e_1_1 };
|
|
3538
|
-
return [3 /*break*/,
|
|
3539
|
-
case
|
|
3577
|
+
return [3 /*break*/, 9];
|
|
3578
|
+
case 8:
|
|
3540
3579
|
try {
|
|
3541
|
-
if (fileNames_1_1 && !fileNames_1_1.done && (
|
|
3580
|
+
if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
|
|
3542
3581
|
}
|
|
3543
3582
|
finally { if (e_1) throw e_1.error; }
|
|
3544
3583
|
return [7 /*endfinally*/];
|
|
3545
|
-
case
|
|
3584
|
+
case 9: return [2 /*return*/, promptbooks];
|
|
3546
3585
|
}
|
|
3547
3586
|
});
|
|
3548
3587
|
}); });
|
|
3549
3588
|
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3550
3589
|
return [4 /*yield*/, library.listPromptbooks()];
|
|
3551
3590
|
case 1:
|
|
3552
|
-
|
|
3553
|
-
|
|
3591
|
+
_f.sent();
|
|
3592
|
+
_f.label = 2;
|
|
3554
3593
|
case 2: return [2 /*return*/, library];
|
|
3555
3594
|
}
|
|
3556
3595
|
});
|
|
@@ -3661,6 +3700,7 @@
|
|
|
3661
3700
|
});
|
|
3662
3701
|
}
|
|
3663
3702
|
/***
|
|
3703
|
+
* TODO: [⚖] Compatible with remote server
|
|
3664
3704
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
3665
3705
|
*/
|
|
3666
3706
|
|