@promptbook/core 0.52.0-9 → 0.52.0

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.
Files changed (50) hide show
  1. package/README.md +1 -13
  2. package/esm/index.es.js +321 -44
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +4 -2
  5. package/esm/typings/_packages/utils.index.d.ts +2 -0
  6. package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
  7. package/esm/typings/execution/ExecutionTools.d.ts +5 -3
  8. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -1
  9. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -1
  10. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  11. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  12. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -1
  13. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
  14. package/esm/typings/execution/utils/forEachAsync.d.ts +18 -0
  15. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +28 -4
  16. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  17. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  18. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  19. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  20. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +22 -5
  21. package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
  22. package/esm/typings/types/Prompt.d.ts +1 -1
  23. package/esm/typings/types/typeAliases.d.ts +2 -2
  24. package/package.json +2 -2
  25. package/umd/index.umd.js +325 -48
  26. package/umd/index.umd.js.map +1 -1
  27. package/umd/typings/_packages/core.index.d.ts +4 -2
  28. package/umd/typings/_packages/utils.index.d.ts +2 -0
  29. package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
  30. package/umd/typings/execution/ExecutionTools.d.ts +5 -3
  31. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -1
  32. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -1
  33. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  34. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  35. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -1
  36. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
  37. package/umd/typings/execution/utils/forEachAsync.d.ts +18 -0
  38. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +28 -4
  39. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  40. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  41. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  42. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  43. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +22 -5
  44. package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
  45. package/umd/typings/types/Prompt.d.ts +1 -1
  46. package/umd/typings/types/typeAliases.d.ts +2 -2
  47. package/esm/typings/wizzard/Wizzard.d.ts +0 -4
  48. package/esm/typings/wizzard/sample.d.ts +0 -6
  49. package/umd/typings/wizzard/Wizzard.d.ts +0 -4
  50. package/umd/typings/wizzard/sample.d.ts +0 -6
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.moment));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, moment) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('path'), require('moment')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'path', 'moment'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.path, global.moment));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, path, moment) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -454,7 +454,7 @@
454
454
  /**
455
455
  * The version of the Promptbook library
456
456
  */
457
- var PROMPTBOOK_VERSION = '0.52.0-8';
457
+ var PROMPTBOOK_VERSION = '0.52.0-33';
458
458
 
459
459
  /**
460
460
  * Parses the template and returns the list of all parameter names
@@ -1831,6 +1831,9 @@
1831
1831
  postprocessing = undefined;
1832
1832
  }
1833
1833
  dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
1834
+ if (templateModelRequirements.modelVariant === undefined) {
1835
+ templateModelRequirements.modelVariant = 'CHAT';
1836
+ }
1834
1837
  promptbookJson.promptTemplates.push({
1835
1838
  name: titleToName(section.title),
1836
1839
  title: section.title,
@@ -2176,6 +2179,7 @@
2176
2179
  * @throws {PromptbookLogicError} on logical error in the promptbook
2177
2180
  */
2178
2181
  function validatePromptbookJson(promptbook) {
2182
+ // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
2179
2183
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
2180
2184
  if (promptbook.promptbookUrl !== undefined) {
2181
2185
  if (!isValidUrl(promptbook.promptbookUrl)) {
@@ -2183,6 +2187,16 @@
2183
2187
  throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
2184
2188
  }
2185
2189
  }
2190
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
2191
+ if (!Array.isArray(promptbook.parameters)) {
2192
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2193
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
2194
+ }
2195
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
2196
+ if (!Array.isArray(promptbook.promptTemplates)) {
2197
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2198
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
2199
+ }
2186
2200
  var _loop_1 = function (parameter) {
2187
2201
  if (parameter.isInput && parameter.isOutput) {
2188
2202
  throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
@@ -2229,9 +2243,8 @@
2229
2243
  }
2230
2244
  definedParameters.add(template.resultingParameterName);
2231
2245
  if (template.executionType === 'PROMPT_TEMPLATE' &&
2232
- (template.modelRequirements.modelVariant === undefined ||
2233
- template.modelRequirements.modelName === undefined)) {
2234
- throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
2246
+ (template.modelRequirements.modelVariant === undefined)) {
2247
+ throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
2235
2248
  }
2236
2249
  if (template.jokers && template.jokers.length > 0) {
2237
2250
  if (!template.expectFormat &&
@@ -2532,7 +2545,7 @@
2532
2545
  title: currentTemplate.title,
2533
2546
  promptbookUrl: "".concat(promptbook.promptbookUrl
2534
2547
  ? promptbook.promptbookUrl
2535
- : 'anonymous' /* <- [🧠][🈴] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2548
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2536
2549
  parameters: parametersToPass,
2537
2550
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
2538
2551
  modelRequirements: currentTemplate.modelRequirements,
@@ -3162,6 +3175,20 @@
3162
3175
  return SimplePromptInterfaceTools;
3163
3176
  }());
3164
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
+
3165
3192
  /**
3166
3193
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3167
3194
  */
@@ -3175,6 +3202,23 @@
3175
3202
  */
3176
3203
  new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
3177
3204
 
3205
+ /**
3206
+ * Returns the same value that is passed as argument.
3207
+ * No side effects.
3208
+ *
3209
+ * Note: It can be usefull for leveling indentation
3210
+ *
3211
+ * @param value any values
3212
+ * @returns the same values
3213
+ */
3214
+ function just(value) {
3215
+ if (value === undefined) {
3216
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3217
+ return undefined;
3218
+ }
3219
+ return value;
3220
+ }
3221
+
3178
3222
  /**
3179
3223
  * This error indicates that promptbook not found in the library
3180
3224
  */
@@ -3232,6 +3276,12 @@
3232
3276
  throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
3233
3277
  }
3234
3278
  validatePromptbookJson(promptbook);
3279
+ // Note: [🦄]
3280
+ if (this.library.has(promptbook.promptbookUrl) &&
3281
+ promptbookJsonToString(promptbook) !==
3282
+ promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
3283
+ throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
3284
+ }
3235
3285
  this.library.set(promptbook.promptbookUrl, promptbook);
3236
3286
  }
3237
3287
  }
@@ -3258,6 +3308,9 @@
3258
3308
  var _this = this;
3259
3309
  var promptbook = this.library.get(url);
3260
3310
  if (!promptbook) {
3311
+ if (this.listPromptbooks().length === 0) {
3312
+ throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
3313
+ }
3261
3314
  throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
3262
3315
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
3263
3316
  .join('\n')), "\n\n "); }));
@@ -3330,11 +3383,11 @@
3330
3383
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3331
3384
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3332
3385
  *
3386
+ * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
3333
3387
  *
3334
3388
  * @param promptbookSourcesPromiseOrFactory
3335
3389
  * @returns PromptbookLibrary
3336
- *
3337
- * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3390
+ * @private Just internal tool for other constructor functions
3338
3391
  */
3339
3392
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3340
3393
  var library;
@@ -3407,37 +3460,252 @@
3407
3460
  * Constructs Promptbook from given directory
3408
3461
  *
3409
3462
  * Note: Works only in Node.js environment because it reads the file system
3410
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
3411
- * SO during the construction syntax and logic sources IS NOT validated
3412
3463
  *
3413
3464
  * @param path - path to the directory with promptbooks
3414
3465
  * @param options - Misc options for the library
3415
3466
  * @returns PromptbookLibrary
3416
3467
  */
3417
3468
  function createPromptbookLibraryFromDirectory(path, options) {
3418
- var _this = this;
3419
- if (!isRunningInNode()) {
3420
- throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3421
- }
3422
- var _a = (options || {}).isRecursive, isRecursive = _a === void 0 ? true : _a;
3423
- return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3424
- var readdir, readdirResult;
3425
- return __generator(this, function (_a) {
3426
- switch (_a.label) {
3427
- case 0: return [4 /*yield*/, import('fs/promises')];
3469
+ return __awaiter(this, void 0, void 0, function () {
3470
+ var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
3471
+ var _this = this;
3472
+ return __generator(this, function (_f) {
3473
+ switch (_f.label) {
3474
+ case 0:
3475
+ if (!isRunningInNode()) {
3476
+ throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3477
+ }
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;
3479
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
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) {
3484
+ case 0:
3485
+ if (isVerbose) {
3486
+ console.info("Creating promptbook library from path ".concat(path));
3487
+ }
3488
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3489
+ readFile = fsPromises.readFile;
3490
+ return [4 /*yield*/, listAllFiles(path, isRecursive)];
3491
+ case 1:
3492
+ fileNames = _b.sent();
3493
+ if (isVerbose) {
3494
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3495
+ }
3496
+ promptbooks = [];
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
+ // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
3540
+ // But be handled in current try-catch block
3541
+ validatePromptbookJson(promptbook);
3542
+ }
3543
+ // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3544
+ promptbooks.push(promptbook);
3545
+ }
3546
+ }
3547
+ return [3 /*break*/, 7];
3548
+ case 6:
3549
+ error_1 = _e.sent();
3550
+ if (!(error_1 instanceof Error)) {
3551
+ throw error_1;
3552
+ }
3553
+ 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 "); });
3554
+ if (isCrashOnError) {
3555
+ throw new PromptbookLibraryError(wrappedErrorMessage);
3556
+ }
3557
+ console.error(wrappedErrorMessage);
3558
+ return [3 /*break*/, 7];
3559
+ case 7: return [2 /*return*/];
3560
+ }
3561
+ });
3562
+ };
3563
+ _b.label = 2;
3564
+ case 2:
3565
+ _b.trys.push([2, 7, 8, 9]);
3566
+ fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
3567
+ _b.label = 3;
3568
+ case 3:
3569
+ if (!!fileNames_1_1.done) return [3 /*break*/, 6];
3570
+ fileName = fileNames_1_1.value;
3571
+ return [5 /*yield**/, _loop_1(fileName)];
3572
+ case 4:
3573
+ _b.sent();
3574
+ _b.label = 5;
3575
+ case 5:
3576
+ fileNames_1_1 = fileNames_1.next();
3577
+ return [3 /*break*/, 3];
3578
+ case 6: return [3 /*break*/, 9];
3579
+ case 7:
3580
+ e_1_1 = _b.sent();
3581
+ e_1 = { error: e_1_1 };
3582
+ return [3 /*break*/, 9];
3583
+ case 8:
3584
+ try {
3585
+ if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
3586
+ }
3587
+ finally { if (e_1) throw e_1.error; }
3588
+ return [7 /*endfinally*/];
3589
+ case 9: return [2 /*return*/, promptbooks];
3590
+ }
3591
+ });
3592
+ }); });
3593
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3594
+ return [4 /*yield*/, library.listPromptbooks()];
3595
+ case 1:
3596
+ _f.sent();
3597
+ _f.label = 2;
3598
+ case 2: return [2 /*return*/, library];
3599
+ }
3600
+ });
3601
+ });
3602
+ }
3603
+ /**
3604
+ * Reads all files in the directory
3605
+ *
3606
+ * @param path
3607
+ * @param isRecursive
3608
+ * @returns List of all files in the directory
3609
+ * @private internal function for `createPromptbookLibraryFromDirectory`
3610
+ */
3611
+ function listAllFiles(path$1, isRecursive) {
3612
+ return __awaiter(this, void 0, void 0, function () {
3613
+ var fsPromises, readdir, dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_2_1;
3614
+ var e_2, _g;
3615
+ return __generator(this, function (_h) {
3616
+ switch (_h.label) {
3617
+ case 0:
3618
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3619
+ readdir = fsPromises.readdir;
3620
+ return [4 /*yield*/, readdir(path$1, {
3621
+ withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
3622
+ })];
3428
3623
  case 1:
3429
- readdir = (_a.sent()).readdir;
3430
- return [4 /*yield*/, readdir(path)];
3624
+ dirents = _h.sent();
3625
+ fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
3626
+ var name = _a.name;
3627
+ return path.join(path$1, name);
3628
+ });
3629
+ if (!isRecursive) return [3 /*break*/, 9];
3630
+ _h.label = 2;
3431
3631
  case 2:
3432
- readdirResult = _a.sent();
3433
- // TODO: !!! Implement
3434
- console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, readdirResult: readdirResult });
3435
- throw new Error('Not implemented yet');
3632
+ _h.trys.push([2, 7, 8, 9]);
3633
+ _a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
3634
+ _h.label = 3;
3635
+ case 3:
3636
+ if (!!_b.done) return [3 /*break*/, 6];
3637
+ dirent = _b.value;
3638
+ subPath = path.join(path$1, dirent.name);
3639
+ _d = (_c = fileNames.push).apply;
3640
+ _e = [fileNames];
3641
+ _f = [[]];
3642
+ return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
3643
+ case 4:
3644
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
3645
+ _h.label = 5;
3646
+ case 5:
3647
+ _b = _a.next();
3648
+ return [3 /*break*/, 3];
3649
+ case 6: return [3 /*break*/, 9];
3650
+ case 7:
3651
+ e_2_1 = _h.sent();
3652
+ e_2 = { error: e_2_1 };
3653
+ return [3 /*break*/, 9];
3654
+ case 8:
3655
+ try {
3656
+ if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
3657
+ }
3658
+ finally { if (e_2) throw e_2.error; }
3659
+ return [7 /*endfinally*/];
3660
+ case 9: return [2 /*return*/, fileNames];
3436
3661
  }
3437
3662
  });
3438
- }); });
3663
+ });
3439
3664
  }
3440
3665
  /***
3666
+ * TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
3667
+ * [🍓][🚯] maybe make `@promptbook/library` package
3668
+ * TODO: Fix the dynamic import issue in Webpack (! Not working !)
3669
+ * > ./node_modules/@promptbook/core/esm/index.es.js
3670
+ * > Critical dependency: the request of a dependency is an expression
3671
+ *
3672
+ * Note: [1] Using require(just('fs/promises')) to allow
3673
+ * the `@promptbook/core` work for both Node.js and browser environments
3674
+ */
3675
+
3676
+ /**
3677
+ * Constructs Promptbook from remote Promptbase URL
3678
+
3679
+ * @returns PromptbookLibrary
3680
+ */
3681
+ function createPromptbookLibraryFromUrl(url, options) {
3682
+ return __awaiter(this, void 0, void 0, function () {
3683
+ var _a, _b, isVerbose, _c, isLazyLoaded, library;
3684
+ var _this = this;
3685
+ return __generator(this, function (_d) {
3686
+ switch (_d.label) {
3687
+ case 0:
3688
+ _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3689
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3690
+ return __generator(this, function (_a) {
3691
+ if (isVerbose) {
3692
+ console.info("Creating promptbook library from url ".concat(url.toString()));
3693
+ }
3694
+ throw new Error('Not implemented yet');
3695
+ });
3696
+ }); });
3697
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3698
+ return [4 /*yield*/, library.listPromptbooks()];
3699
+ case 1:
3700
+ _d.sent();
3701
+ _d.label = 2;
3702
+ case 2: return [2 /*return*/, library];
3703
+ }
3704
+ });
3705
+ });
3706
+ }
3707
+ /***
3708
+ * TODO: [⚖] Compatible with remote server
3441
3709
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3442
3710
  */
3443
3711
 
@@ -3523,6 +3791,31 @@
3523
3791
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3524
3792
  */
3525
3793
 
3794
+ /**
3795
+ * Just testing imports and compatibility
3796
+ */
3797
+ function justTestFsImport() {
3798
+ return __awaiter(this, void 0, void 0, function () {
3799
+ var files;
3800
+ return __generator(this, function (_a) {
3801
+ switch (_a.label) {
3802
+ case 0:
3803
+ if (!isRunningInNode()) {
3804
+ throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
3805
+ }
3806
+ return [4 /*yield*/, require(just('glob-promise'))('/**/*')];
3807
+ case 1:
3808
+ files = _a.sent();
3809
+ console.info('testFiles', { files: files });
3810
+ return [2 /*return*/];
3811
+ }
3812
+ });
3813
+ });
3814
+ }
3815
+ /**
3816
+ * TODO: !!! Remove this file
3817
+ */
3818
+
3526
3819
  /**
3527
3820
  * Format either small or big number
3528
3821
  *
@@ -3543,23 +3836,6 @@
3543
3836
  return value.toString();
3544
3837
  }
3545
3838
 
3546
- /**
3547
- * Returns the same value that is passed as argument.
3548
- * No side effects.
3549
- *
3550
- * Note: It can be usefull for leveling indentation
3551
- *
3552
- * @param value any values
3553
- * @returns the same values
3554
- */
3555
- function just(value) {
3556
- if (value === undefined) {
3557
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3558
- return undefined;
3559
- }
3560
- return value;
3561
- }
3562
-
3563
3839
  /**
3564
3840
  * Create a markdown table from a 2D array of strings
3565
3841
  *
@@ -3851,11 +4127,12 @@
3851
4127
  exports.checkExpectations = checkExpectations;
3852
4128
  exports.createPromptbookExecutor = createPromptbookExecutor;
3853
4129
  exports.createPromptbookLibraryFromDirectory = createPromptbookLibraryFromDirectory;
3854
- exports.createPromptbookLibraryFromPromise = createPromptbookLibraryFromPromise;
3855
4130
  exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
4131
+ exports.createPromptbookLibraryFromUrl = createPromptbookLibraryFromUrl;
3856
4132
  exports.createPromptbookSublibrary = createPromptbookSublibrary;
3857
4133
  exports.executionReportJsonToString = executionReportJsonToString;
3858
4134
  exports.isPassingExpectations = isPassingExpectations;
4135
+ exports.justTestFsImport = justTestFsImport;
3859
4136
  exports.prettifyPromptbookString = prettifyPromptbookString;
3860
4137
  exports.promptbookJsonToString = promptbookJsonToString;
3861
4138
  exports.promptbookStringToJson = promptbookStringToJson;