@promptbook/core 0.52.0-14 → 0.52.0-16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
2
2
  import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
- import { join } from 'path';
4
+ import glob from 'glob-promise';
5
5
  import moment from 'moment';
6
6
 
7
7
  /*! *****************************************************************************
@@ -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-13';
451
+ var PROMPTBOOK_VERSION = '0.52.0-15';
452
452
 
453
453
  /**
454
454
  * Parses the template and returns the list of all parameter names
@@ -3169,23 +3169,6 @@ var isRunningInNode = new Function("\n try {\n return this === global;
3169
3169
  */
3170
3170
  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");
3171
3171
 
3172
- /**
3173
- * Returns the same value that is passed as argument.
3174
- * No side effects.
3175
- *
3176
- * Note: It can be usefull for leveling indentation
3177
- *
3178
- * @param value any values
3179
- * @returns the same values
3180
- */
3181
- function just(value) {
3182
- if (value === undefined) {
3183
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3184
- return undefined;
3185
- }
3186
- return value;
3187
- }
3188
-
3189
3172
  /**
3190
3173
  * This error indicates that promptbook not found in the library
3191
3174
  */
@@ -3431,28 +3414,37 @@ function createPromptbookLibraryFromDirectory(path, options) {
3431
3414
  }
3432
3415
  var _a = (options || {}).isRecursive, isRecursive = _a === void 0 ? true : _a;
3433
3416
  return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3434
- var readdir, dirents, fileNames;
3435
3417
  return __generator(this, function (_a) {
3436
- switch (_a.label) {
3437
- case 0:
3438
- readdir = require(just('fs/promises')).readdir;
3439
- return [4 /*yield*/, readdir(path, {
3440
- withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
3441
- })];
3442
- case 1:
3443
- dirents = _a.sent();
3444
- fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
3445
- var name = _a.name;
3446
- return join(name, path);
3447
- });
3448
- // TODO: !!! Implement
3449
- console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3450
- throw new Error('Not implemented yet');
3451
- }
3418
+ /*
3419
+ const justR_equire = require; /* <- Note: [1] * /
3420
+ const readdir = justR_equire(just('fs/promises') /* <- Note: [2] * /).readdir as typeof readdirType;
3421
+
3422
+ // TODO: !!!! Implement recursive reading
3423
+ // TODO: !!!!! readAllFiles util
3424
+
3425
+ const dirents = await readdir(path, {
3426
+ withFileTypes: true /* Note: This is not working: recursive: isRecursive * /,
3427
+ });
3428
+ const fileNames = dirents.filter((dirent) => dirent.isFile()).map(({ name }) => join(name, path));
3429
+
3430
+ // TODO: !!! Implement
3431
+
3432
+ console.info('createPromptbookLibraryFromDirectory', { path, isRecursive, fileNames });
3433
+ throw new Error('Not implemented yet');
3434
+
3435
+ */
3436
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive });
3437
+ return [2 /*return*/, []];
3452
3438
  });
3453
3439
  }); });
3454
3440
  }
3455
3441
  /***
3442
+ * Note: [1] Fixing the dynamic import issue in Webpack
3443
+ * > ./node_modules/@promptbook/core/esm/index.es.js
3444
+ * > Critical dependency: the request of a dependency is an expression
3445
+ *
3446
+ * Note: [2] Using require(just('fs/promises')) to allow
3447
+ * the `@promptbook/core` work for both Node.js and browser environments
3456
3448
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3457
3449
  */
3458
3450
 
@@ -3554,6 +3546,28 @@ function createPromptbookSublibrary(library, predicate) {
3554
3546
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3555
3547
  */
3556
3548
 
3549
+ /**
3550
+ * Just testing imports and compatibility
3551
+ */
3552
+ function justTestFsImport() {
3553
+ return __awaiter(this, void 0, void 0, function () {
3554
+ var files;
3555
+ return __generator(this, function (_a) {
3556
+ switch (_a.label) {
3557
+ case 0:
3558
+ if (!isRunningInNode()) {
3559
+ throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
3560
+ }
3561
+ return [4 /*yield*/, glob('/**/*')];
3562
+ case 1:
3563
+ files = _a.sent();
3564
+ console.info('testFiles', { files: files });
3565
+ return [2 /*return*/];
3566
+ }
3567
+ });
3568
+ });
3569
+ }
3570
+
3557
3571
  /**
3558
3572
  * Format either small or big number
3559
3573
  *
@@ -3574,6 +3588,23 @@ function formatNumber(value) {
3574
3588
  return value.toString();
3575
3589
  }
3576
3590
 
3591
+ /**
3592
+ * Returns the same value that is passed as argument.
3593
+ * No side effects.
3594
+ *
3595
+ * Note: It can be usefull for leveling indentation
3596
+ *
3597
+ * @param value any values
3598
+ * @returns the same values
3599
+ */
3600
+ function just(value) {
3601
+ if (value === undefined) {
3602
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3603
+ return undefined;
3604
+ }
3605
+ return value;
3606
+ }
3607
+
3577
3608
  /**
3578
3609
  * Create a markdown table from a 2D array of strings
3579
3610
  *
@@ -3854,5 +3885,5 @@ function executionReportJsonToString(executionReportJson, options) {
3854
3885
  * TODO: [🧠] Allow to filter out some parts of the report by options
3855
3886
  */
3856
3887
 
3857
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
3888
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
3858
3889
  //# sourceMappingURL=index.es.js.map