@promptbook/node 0.85.0-3 → 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,7 +1,7 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  import { PartialDeep } from 'type-fest';
3
- import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
4
3
  import type { task_id } from '../types/typeAliases';
4
+ import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
5
5
  import type { AbstractTaskResult } from './AbstractTaskResult';
6
6
  import type { PipelineExecutorResult } from './PipelineExecutorResult';
7
7
  /**
@@ -30,7 +30,7 @@ export declare function createTask<TTaskResult extends AbstractTaskResult>(optio
30
30
  */
31
31
  export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
32
32
  readonly taskType: 'EXECUTION';
33
- readonly taskId: `execution-${task_id}`;
33
+ readonly taskId: `exec-${task_id}`;
34
34
  };
35
35
  /**
36
36
  * Represents a task that prepares a pipeline
@@ -38,7 +38,7 @@ export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
38
38
  */
39
39
  export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
40
40
  readonly taskType: 'PREPARATION';
41
- readonly taskId: `preparation-${task_id}`;
41
+ readonly taskId: `prep-${task_id}`;
42
42
  };
43
43
  /**
44
44
  * Base interface for all task types
@@ -62,6 +62,10 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
62
62
  * Gets an observable stream of partial task results
63
63
  */
64
64
  asObservable(): Observable<PartialDeep<TTaskResult>>;
65
+ /**
66
+ * Gets just the current value which is mutated during the task processing
67
+ */
68
+ currentValue: PartialDeep<TTaskResult>;
65
69
  };
66
70
  export type Task = ExecutionTask | PreparationTask;
67
71
  export {};
@@ -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-3",
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-3"
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-2';
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
@@ -2060,11 +2060,29 @@
2060
2060
  */
2061
2061
  function createTask(options) {
2062
2062
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2063
- var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2063
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
2064
2064
  var partialResultSubject = new rxjs.BehaviorSubject({});
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,10 @@
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();
2112
+ },
2113
+ get currentValue() {
2114
+ return partialResultSubject.value;
2094
2115
  },
2095
2116
  };
2096
2117
  }
@@ -5596,7 +5617,7 @@
5596
5617
  value = value.replace(/\.html$/, '');
5597
5618
  }
5598
5619
  else if (isValidFilePath(value)) {
5599
- value = node_path.basename(value);
5620
+ value = path.basename(value);
5600
5621
  // Note: Keeping extension in the name
5601
5622
  }
5602
5623
  value = value.split('/').join('-');
@@ -5702,9 +5723,9 @@
5702
5723
  }
5703
5724
  basename = url.split('/').pop() || titleToName(url);
5704
5725
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5705
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5706
- 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));
5707
- 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 })];
5708
5729
  case 2:
5709
5730
  _h.sent();
5710
5731
  _g = (_f = Buffer).from;
@@ -5714,7 +5735,7 @@
5714
5735
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5715
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."));
5716
5737
  }
5717
- 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)];
5718
5739
  case 4:
5719
5740
  _h.sent();
5720
5741
  // TODO: [💵] Check the file security
@@ -5730,7 +5751,7 @@
5730
5751
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
5731
5752
  // <- TODO: [🧠] What is the best error type here`
5732
5753
  }
5733
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5754
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5734
5755
  fileExtension = getFileExtension(filename_1);
5735
5756
  mimeType = extensionToMimeType(fileExtension || '');
5736
5757
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -9726,7 +9747,7 @@
9726
9747
  console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
9727
9748
  }
9728
9749
  try {
9729
- var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
9750
+ var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
9730
9751
  if (isVerbose) {
9731
9752
  commandProcess.on('message', function (message) {
9732
9753
  console.info({ message: message });
@@ -9936,7 +9957,7 @@
9936
9957
  function locateAppOnWindows(_a) {
9937
9958
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
9938
9959
  return __awaiter(this, void 0, void 0, function () {
9939
- 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;
9940
9961
  var e_1, _b;
9941
9962
  return __generator(this, function (_c) {
9942
9963
  switch (_c.label) {
@@ -9944,7 +9965,7 @@
9944
9965
  _c.trys.push([0, 9, , 10]);
9945
9966
  prefixes = [
9946
9967
  process.env.LOCALAPPDATA,
9947
- node_path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9968
+ path.join(process.env.LOCALAPPDATA || '', 'Programs'),
9948
9969
  process.env.PROGRAMFILES,
9949
9970
  process.env['PROGRAMFILES(X86)'],
9950
9971
  ];
@@ -9956,11 +9977,11 @@
9956
9977
  case 2:
9957
9978
  if (!!prefixes_1_1.done) return [3 /*break*/, 5];
9958
9979
  prefix = prefixes_1_1.value;
9959
- path = prefix + windowsSuffix;
9960
- return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
9980
+ path$1 = prefix + windowsSuffix;
9981
+ return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
9961
9982
  case 3:
9962
9983
  if (_c.sent()) {
9963
- return [2 /*return*/, path];
9984
+ return [2 /*return*/, path$1];
9964
9985
  }
9965
9986
  _c.label = 4;
9966
9987
  case 4:
@@ -10356,7 +10377,7 @@
10356
10377
  case 3:
10357
10378
  if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
10358
10379
  pattern = envFilePatterns_1_1.value;
10359
- envFilename = node_path.join(rootDirname, pattern);
10380
+ envFilename = path.join(rootDirname, pattern);
10360
10381
  return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
10361
10382
  case 4:
10362
10383
  if (_b.sent()) {
@@ -10384,7 +10405,7 @@
10384
10405
  return [3 /*break*/, 11];
10385
10406
  }
10386
10407
  // Note: If the directory does not exist, try the parent directory
10387
- rootDirname = node_path.join(rootDirname, '..');
10408
+ rootDirname = path.join(rootDirname, '..');
10388
10409
  _b.label = 10;
10389
10410
  case 10:
10390
10411
  i++;
@@ -11131,19 +11152,19 @@
11131
11152
  * @returns List of all files in the directory
11132
11153
  * @private internal function of `createCollectionFromDirectory`
11133
11154
  */
11134
- function listAllFiles(path, isRecursive, fs) {
11155
+ function listAllFiles(path$1, isRecursive, fs) {
11135
11156
  return __awaiter(this, void 0, void 0, function () {
11136
11157
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
11137
11158
  var e_1, _g;
11138
11159
  return __generator(this, function (_h) {
11139
11160
  switch (_h.label) {
11140
- case 0: return [4 /*yield*/, isDirectoryExisting(path, fs)];
11161
+ case 0: return [4 /*yield*/, isDirectoryExisting(path$1, fs)];
11141
11162
  case 1:
11142
11163
  if (!(_h.sent())) {
11143
- 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"));
11144
11165
  // <- TODO: Use some custom error class
11145
11166
  }
11146
- return [4 /*yield*/, fs.readdir(path, {
11167
+ return [4 /*yield*/, fs.readdir(path$1, {
11147
11168
  withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
11148
11169
  })];
11149
11170
  case 2:
@@ -11152,7 +11173,7 @@
11152
11173
  .filter(function (dirent) { return dirent.isFile(); })
11153
11174
  .map(function (_a) {
11154
11175
  var name = _a.name;
11155
- return node_path.join(path, name).split('\\').join('/');
11176
+ return path.join(path$1, name).split('\\').join('/');
11156
11177
  });
11157
11178
  if (!isRecursive) return [3 /*break*/, 10];
11158
11179
  _h.label = 3;
@@ -11163,7 +11184,7 @@
11163
11184
  case 4:
11164
11185
  if (!!_b.done) return [3 /*break*/, 7];
11165
11186
  dirent = _b.value;
11166
- subPath = node_path.join(path, dirent.name);
11187
+ subPath = path.join(path$1, dirent.name);
11167
11188
  _d = (_c = fileNames.push).apply;
11168
11189
  _e = [fileNames];
11169
11190
  _f = [[]];
@@ -11294,7 +11315,7 @@
11294
11315
  * @returns PipelineCollection
11295
11316
  * @public exported from `@promptbook/node`
11296
11317
  */
11297
- function createCollectionFromDirectory(path, tools, options) {
11318
+ function createCollectionFromDirectory(path$1, tools, options) {
11298
11319
  return __awaiter(this, void 0, void 0, function () {
11299
11320
  var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, rootUrl, collection;
11300
11321
  var _this = this;
@@ -11311,7 +11332,7 @@
11311
11332
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
11312
11333
  // <- TODO: [🧠] What is the best error type here`
11313
11334
  }
11314
- madeLibraryFilePath = node_path.join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11335
+ madeLibraryFilePath = path.join(path$1, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11315
11336
  // <- TODO: [🦒] Allow to override (pass different value into the function)
11316
11337
  , ".json"));
11317
11338
  return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
@@ -11330,9 +11351,9 @@
11330
11351
  switch (_b.label) {
11331
11352
  case 0:
11332
11353
  if (isVerbose) {
11333
- 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('/'))));
11334
11355
  }
11335
- return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
11356
+ return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
11336
11357
  case 1:
11337
11358
  fileNames = _b.sent();
11338
11359
  // Note: First load all .book.json and then .book.md files
@@ -11353,7 +11374,7 @@
11353
11374
  switch (_f.label) {
11354
11375
  case 0:
11355
11376
  sourceFile = './' + fileName.split('\\').join('/');
11356
- rootDirname = node_path.dirname(sourceFile).split('\\').join('/');
11377
+ rootDirname = path.dirname(sourceFile).split('\\').join('/');
11357
11378
  _f.label = 1;
11358
11379
  case 1:
11359
11380
  _f.trys.push([1, 8, , 9]);
@@ -11547,7 +11568,7 @@
11547
11568
  var name = titleToName(key);
11548
11569
  var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
11549
11570
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
11550
- 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));
11551
11572
  };
11552
11573
  /**
11553
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.
@@ -11588,7 +11609,7 @@
11588
11609
  throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
11589
11610
  }
11590
11611
  fileContent = stringifyPipelineJson(value);
11591
- return [4 /*yield*/, promises.mkdir(node_path.dirname(filename), { recursive: true })];
11612
+ return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
11592
11613
  case 1:
11593
11614
  _a.sent(); // <- [0]
11594
11615
  return [4 /*yield*/, promises.writeFile(filename, fileContent, 'utf-8')];