@promptbook/node 0.85.0-4 → 0.85.0-5

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fs from 'node:fs/promises';
2
+ import type fs from 'fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.85.0-4",
3
+ "version": "0.85.0-5",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.85.0-4"
50
+ "@promptbook/core": "0.85.0-5"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
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('colors'), require('node:fs/promises'), require('node:path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('node:child_process'), require('dotenv')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'node:fs/promises', 'node:path', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'node:child_process', 'dotenv'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.node_path, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.node_child_process, global.dotenv));
5
- })(this, (function (exports, colors, promises, node_path, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, node_child_process, dotenv) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('child_process'), require('dotenv')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'child_process', 'dotenv'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.child_process, global.dotenv));
5
+ })(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, child_process, dotenv) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -45,7 +45,7 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-3';
48
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
49
49
  /**
50
50
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
51
51
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2065,6 +2065,24 @@
2065
2065
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2066
2066
  partialResultSubject.next(newOngoingResult);
2067
2067
  });
2068
+ finalResultPromise
2069
+ .catch(function (error) {
2070
+ // console.error('!!!!! Task failed:', error);
2071
+ partialResultSubject.error(error);
2072
+ })
2073
+ .then(function (value) {
2074
+ // console.error('!!!!! Task finished:', value);
2075
+ if (value) {
2076
+ try {
2077
+ assertsTaskSuccessful(value);
2078
+ partialResultSubject.next(value);
2079
+ }
2080
+ catch (error) {
2081
+ partialResultSubject.error(error);
2082
+ }
2083
+ }
2084
+ partialResultSubject.complete();
2085
+ });
2068
2086
  function asPromise(options) {
2069
2087
  return __awaiter(this, void 0, void 0, function () {
2070
2088
  var _a, isCrashedOnError, finalResult;
@@ -2075,7 +2093,9 @@
2075
2093
  return [4 /*yield*/, finalResultPromise];
2076
2094
  case 1:
2077
2095
  finalResult = _b.sent();
2096
+ console.error('!!!!! finalResult:', finalResult);
2078
2097
  if (isCrashedOnError) {
2098
+ console.error('!!!!! isCrashedOnError:', finalResult);
2079
2099
  assertsTaskSuccessful(finalResult);
2080
2100
  }
2081
2101
  return [2 /*return*/, finalResult];
@@ -2088,9 +2108,7 @@
2088
2108
  taskId: taskId,
2089
2109
  asPromise: asPromise,
2090
2110
  asObservable: function () {
2091
- return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2092
- isCrashedOnError: true,
2093
- })));
2111
+ return partialResultSubject.asObservable();
2094
2112
  },
2095
2113
  get currentValue() {
2096
2114
  return partialResultSubject.value;
@@ -5599,7 +5617,7 @@
5599
5617
  value = value.replace(/\.html$/, '');
5600
5618
  }
5601
5619
  else if (isValidFilePath(value)) {
5602
- value = node_path.basename(value);
5620
+ value = path.basename(value);
5603
5621
  // Note: Keeping extension in the name
5604
5622
  }
5605
5623
  value = value.split('/').join('-');
@@ -5705,9 +5723,9 @@
5705
5723
  }
5706
5724
  basename = url.split('/').pop() || titleToName(url);
5707
5725
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5708
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5709
- filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
5710
- return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
5726
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5727
+ filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
5728
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
5711
5729
  case 2:
5712
5730
  _h.sent();
5713
5731
  _g = (_f = Buffer).from;
@@ -5717,7 +5735,7 @@
5717
5735
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5718
5736
  throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
5719
5737
  }
5720
- return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
5738
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
5721
5739
  case 4:
5722
5740
  _h.sent();
5723
5741
  // TODO: [💵] Check the file security
@@ -5733,7 +5751,7 @@
5733
5751
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
5734
5752
  // <- TODO: [🧠] What is the best error type here`
5735
5753
  }
5736
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5754
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5737
5755
  fileExtension = getFileExtension(filename_1);
5738
5756
  mimeType = extensionToMimeType(fileExtension || '');
5739
5757
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -9729,7 +9747,7 @@
9729
9747
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
9730
9748
  }
9731
9749
  try {
9732
- var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
9750
+ var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
9733
9751
  if (isVerbose) {
9734
9752
  commandProcess.on('message', function (message) {
9735
9753
  console.info({ message: message });
@@ -9939,7 +9957,7 @@
9939
9957
  function locateAppOnWindows(_a) {
9940
9958
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
9941
9959
  return __awaiter(this, void 0, void 0, function () {
9942
- var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
9960
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path$1, e_1_1, error_1;
9943
9961
  var e_1, _b;
9944
9962
  return __generator(this, function (_c) {
9945
9963
  switch (_c.label) {
@@ -9947,7 +9965,7 @@
9947
9965
  _c.trys.push([0, 9, , 10]);
9948
9966
  prefixes = [
9949
9967
  process.env.LOCALAPPDATA,
9950
- node_path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9968
+ path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9951
9969
  process.env.PROGRAMFILES,
9952
9970
  process.env['PROGRAMFILES(X86)'],
9953
9971
  ];
@@ -9959,11 +9977,11 @@
9959
9977
  case 2:
9960
9978
  if (!!prefixes_1_1.done) return [3 /*break*/, 5];
9961
9979
  prefix = prefixes_1_1.value;
9962
- path = prefix + windowsSuffix;
9963
- return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
9980
+ path$1 = prefix + windowsSuffix;
9981
+ return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
9964
9982
  case 3:
9965
9983
  if (_c.sent()) {
9966
- return [2 /*return*/, path];
9984
+ return [2 /*return*/, path$1];
9967
9985
  }
9968
9986
  _c.label = 4;
9969
9987
  case 4:
@@ -10359,7 +10377,7 @@
10359
10377
  case 3:
10360
10378
  if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
10361
10379
  pattern = envFilePatterns_1_1.value;
10362
- envFilename = node_path.join(rootDirname, pattern);
10380
+ envFilename = path.join(rootDirname, pattern);
10363
10381
  return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
10364
10382
  case 4:
10365
10383
  if (_b.sent()) {
@@ -10387,7 +10405,7 @@
10387
10405
  return [3 /*break*/, 11];
10388
10406
  }
10389
10407
  // Note: If the directory does not exist, try the parent directory
10390
- rootDirname = node_path.join(rootDirname, '..');
10408
+ rootDirname = path.join(rootDirname, '..');
10391
10409
  _b.label = 10;
10392
10410
  case 10:
10393
10411
  i++;
@@ -11134,19 +11152,19 @@
11134
11152
  * @returns List of all files in the directory
11135
11153
  * @private internal function of `createCollectionFromDirectory`
11136
11154
  */
11137
- function listAllFiles(path, isRecursive, fs) {
11155
+ function listAllFiles(path$1, isRecursive, fs) {
11138
11156
  return __awaiter(this, void 0, void 0, function () {
11139
11157
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
11140
11158
  var e_1, _g;
11141
11159
  return __generator(this, function (_h) {
11142
11160
  switch (_h.label) {
11143
- case 0: return [4 /*yield*/, isDirectoryExisting(path, fs)];
11161
+ case 0: return [4 /*yield*/, isDirectoryExisting(path$1, fs)];
11144
11162
  case 1:
11145
11163
  if (!(_h.sent())) {
11146
- throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
11164
+ throw new Error("Directory \"".concat(path$1, "\" does not exist or is not readable"));
11147
11165
  // <- TODO: Use some custom error class
11148
11166
  }
11149
- return [4 /*yield*/, fs.readdir(path, {
11167
+ return [4 /*yield*/, fs.readdir(path$1, {
11150
11168
  withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
11151
11169
  })];
11152
11170
  case 2:
@@ -11155,7 +11173,7 @@
11155
11173
  .filter(function (dirent) { return dirent.isFile(); })
11156
11174
  .map(function (_a) {
11157
11175
  var name = _a.name;
11158
- return node_path.join(path, name).split('\\').join('/');
11176
+ return path.join(path$1, name).split('\\').join('/');
11159
11177
  });
11160
11178
  if (!isRecursive) return [3 /*break*/, 10];
11161
11179
  _h.label = 3;
@@ -11166,7 +11184,7 @@
11166
11184
  case 4:
11167
11185
  if (!!_b.done) return [3 /*break*/, 7];
11168
11186
  dirent = _b.value;
11169
- subPath = node_path.join(path, dirent.name);
11187
+ subPath = path.join(path$1, dirent.name);
11170
11188
  _d = (_c = fileNames.push).apply;
11171
11189
  _e = [fileNames];
11172
11190
  _f = [[]];
@@ -11297,7 +11315,7 @@
11297
11315
  * @returns PipelineCollection
11298
11316
  * @public exported from `@promptbook/node`
11299
11317
  */
11300
- function createCollectionFromDirectory(path, tools, options) {
11318
+ function createCollectionFromDirectory(path$1, tools, options) {
11301
11319
  return __awaiter(this, void 0, void 0, function () {
11302
11320
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11303
11321
  var _this = this;
@@ -11314,7 +11332,7 @@
11314
11332
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11315
11333
  // <- TODO: [🧠] What is the best error type here`
11316
11334
  }
11317
- madeLibraryFilePath = node_path.join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11335
+ madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11318
11336
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11319
11337
  , ".json"));
11320
11338
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11333,9 +11351,9 @@
11333
11351
  switch (_b.label) {
11334
11352
  case 0:
11335
11353
  if (isVerbose) {
11336
- console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
11354
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
11337
11355
  }
11338
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
11356
+ return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
11339
11357
  case 1:
11340
11358
  fileNames = _b.sent();
11341
11359
  // Note: First load all .book.json and then .book.md files
@@ -11356,7 +11374,7 @@
11356
11374
  switch (_f.label) {
11357
11375
  case 0:
11358
11376
  sourceFile = './' + fileName.split('\\').join('/');
11359
- rootDirname = node_path.dirname(sourceFile).split('\\').join('/');
11377
+ rootDirname = path.dirname(sourceFile).split('\\').join('/');
11360
11378
  _f.label = 1;
11361
11379
  case 1:
11362
11380
  _f.trys.push([1, 8, , 9]);
@@ -11550,7 +11568,7 @@
11550
11568
  var name = titleToName(key);
11551
11569
  var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
11552
11570
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
11553
- return node_path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
11571
+ return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
11554
11572
  };
11555
11573
  /**
11556
11574
  * @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
@@ -11591,7 +11609,7 @@
11591
11609
  throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
11592
11610
  }
11593
11611
  fileContent = stringifyPipelineJson(value);
11594
- return [4 /*yield*/, promises.mkdir(node_path.dirname(filename), { recursive: true })];
11612
+ return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
11595
11613
  case 1:
11596
11614
  _a.sent(); // <- [0]
11597
11615
  return [4 /*yield*/, promises.writeFile(filename, fileContent, 'utf-8')];