@promptbook/markdown-utils 0.84.0 โ†’ 0.85.0-1

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 (35) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +213 -160
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +0 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +14 -2
  6. package/esm/typings/src/_packages/utils.index.d.ts +0 -2
  7. package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
  8. package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
  9. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  10. package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
  11. package/esm/typings/src/execution/ExecutionTask.d.ts +71 -0
  12. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  13. package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -5
  14. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -15
  15. package/esm/typings/src/execution/PromptbookFetch.d.ts +8 -1
  16. package/esm/typings/src/execution/{assertsExecutionSuccessful.d.ts โ†’ assertsTaskSuccessful.d.ts} +2 -3
  17. package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +0 -3
  18. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -6
  19. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +3 -6
  20. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  21. package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -0
  22. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +6 -4
  23. package/esm/typings/src/types/typeAliases.d.ts +2 -0
  24. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +2 -2
  25. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +2 -2
  26. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +2 -2
  27. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  28. package/esm/typings/src/utils/random/$randomSeed.d.ts +2 -1
  29. package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
  30. package/esm/typings/src/wizzard/wizzard.d.ts +2 -3
  31. package/package.json +3 -1
  32. package/umd/index.umd.js +220 -169
  33. package/umd/index.umd.js.map +1 -1
  34. package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Progress.d.ts +0 -10
  35. package/esm/typings/src/types/TaskProgress.d.ts +0 -43
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('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('node:path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'node:path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.node_path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, hexEncoder, sha256, node_path, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -1874,6 +1874,58 @@
1874
1874
  return PipelineExecutionError;
1875
1875
  }(Error));
1876
1876
 
1877
+ /**
1878
+ * Determine if the pipeline is fully prepared
1879
+ *
1880
+ * @see https://github.com/webgptorg/promptbook/discussions/196
1881
+ *
1882
+ * @public exported from `@promptbook/core`
1883
+ */
1884
+ function isPipelinePrepared(pipeline) {
1885
+ // Note: Ignoring `pipeline.preparations` @@@
1886
+ // Note: Ignoring `pipeline.knowledgePieces` @@@
1887
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
1888
+ return false;
1889
+ }
1890
+ if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
1891
+ return false;
1892
+ }
1893
+ if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
1894
+ return false;
1895
+ }
1896
+ /*
1897
+ TODO: [๐Ÿง ][๐Ÿซ] `tasks` can not be determined if they are fully prepared SO ignoring them
1898
+ > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
1899
+ > return false;
1900
+ > }
1901
+ */
1902
+ return true;
1903
+ }
1904
+ /**
1905
+ * TODO: [๐Ÿ”ƒ][main] If the pipeline was prepared with different version or different set of models, prepare it once again
1906
+ * TODO: [๐Ÿ ] Maybe base this on `makeValidator`
1907
+ * TODO: [๐ŸงŠ] Pipeline can be partially prepared, this should return true ONLY if fully prepared
1908
+ * TODO: [๐Ÿงฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1909
+ * - [๐Ÿ] ? Is context in each task
1910
+ * - [โ™จ] Are examples prepared
1911
+ * - [โ™จ] Are tasks prepared
1912
+ */
1913
+
1914
+ /**
1915
+ * Generates random token
1916
+ *
1917
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1918
+ *
1919
+ * @private internal helper function
1920
+ * @returns secure random token
1921
+ */
1922
+ function $randomToken(randomness) {
1923
+ return crypto.randomBytes(randomness).toString('hex');
1924
+ }
1925
+ /**
1926
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1927
+ */
1928
+
1877
1929
  /**
1878
1930
  * This error indicates problems parsing the format value
1879
1931
  *
@@ -2091,9 +2143,9 @@
2091
2143
  *
2092
2144
  * @param executionResult - The partial result of the Promptbook execution
2093
2145
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2094
- * @public exported from `@promptbook/core`
2146
+ * @private internal helper function of `asPromise` method of `ExecutionTask`
2095
2147
  */
2096
- function assertsExecutionSuccessful(executionResult) {
2148
+ function assertsTaskSuccessful(executionResult) {
2097
2149
  var e_1, _a;
2098
2150
  var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2099
2151
  try {
@@ -2128,121 +2180,54 @@
2128
2180
  }
2129
2181
  }
2130
2182
  /**
2131
- * TODO: [๐Ÿš] This function should be removed OR changed OR be completely rewritten
2132
2183
  * TODO: [๐Ÿง ] Can this return type be better typed than void
2133
2184
  */
2134
2185
 
2135
2186
  /**
2136
- * Determine if the pipeline is fully prepared
2137
- *
2138
- * @see https://github.com/webgptorg/promptbook/discussions/196
2139
- *
2140
- * @public exported from `@promptbook/core`
2141
- */
2142
- function isPipelinePrepared(pipeline) {
2143
- // Note: Ignoring `pipeline.preparations` @@@
2144
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2145
- if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2146
- return false;
2147
- }
2148
- if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2149
- return false;
2150
- }
2151
- if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2152
- return false;
2153
- }
2154
- /*
2155
- TODO: [๐Ÿง ][๐Ÿซ] `tasks` can not be determined if they are fully prepared SO ignoring them
2156
- > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
2157
- > return false;
2158
- > }
2159
- */
2160
- return true;
2161
- }
2162
- /**
2163
- * TODO: [๐Ÿ”ƒ][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2164
- * TODO: [๐Ÿ ] Maybe base this on `makeValidator`
2165
- * TODO: [๐ŸงŠ] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2166
- * TODO: [๐Ÿงฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2167
- * - [๐Ÿ] ? Is context in each task
2168
- * - [โ™จ] Are examples prepared
2169
- * - [โ™จ] Are tasks prepared
2170
- */
2171
-
2172
- /**
2173
- * Format either small or big number
2187
+ * Helper to create a new task
2174
2188
  *
2175
- * @public exported from `@promptbook/utils`
2189
+ * @private internal helper function
2176
2190
  */
2177
- function numberToString(value) {
2178
- if (value === 0) {
2179
- return '0';
2180
- }
2181
- else if (Number.isNaN(value)) {
2182
- return VALUE_STRINGS.nan;
2183
- }
2184
- else if (value === Infinity) {
2185
- return VALUE_STRINGS.infinity;
2186
- }
2187
- else if (value === -Infinity) {
2188
- return VALUE_STRINGS.negativeInfinity;
2189
- }
2190
- for (var exponent = 0; exponent < 15; exponent++) {
2191
- var factor = Math.pow(10, exponent);
2192
- var valueRounded = Math.round(value * factor) / factor;
2193
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2194
- return valueRounded.toFixed(exponent);
2195
- }
2191
+ function createTask(options) {
2192
+ var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2193
+ var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2194
+ var partialResultSubject = new rxjs.BehaviorSubject({});
2195
+ var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2196
+ partialResultSubject.next(newOngoingResult);
2197
+ });
2198
+ function asPromise(options) {
2199
+ return __awaiter(this, void 0, void 0, function () {
2200
+ var _a, isCrashedOnError, finalResult;
2201
+ return __generator(this, function (_b) {
2202
+ switch (_b.label) {
2203
+ case 0:
2204
+ _a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
2205
+ return [4 /*yield*/, finalResultPromise];
2206
+ case 1:
2207
+ finalResult = _b.sent();
2208
+ if (isCrashedOnError) {
2209
+ assertsTaskSuccessful(finalResult);
2210
+ }
2211
+ return [2 /*return*/, finalResult];
2212
+ }
2213
+ });
2214
+ });
2196
2215
  }
2197
- return value.toString();
2216
+ return {
2217
+ taskType: taskType,
2218
+ taskId: taskId,
2219
+ asPromise: asPromise,
2220
+ asObservable: function () {
2221
+ return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2222
+ isCrashedOnError: true,
2223
+ })));
2224
+ },
2225
+ };
2198
2226
  }
2199
-
2200
2227
  /**
2201
- * Function `valueToString` will convert the given value to string
2202
- * This is useful and used in the `templateParameters` function
2203
- *
2204
- * Note: This function is not just calling `toString` method
2205
- * It's more complex and can handle this conversion specifically for LLM models
2206
- * See `VALUE_STRINGS`
2207
- *
2208
- * Note: There are 2 similar functions
2209
- * - `valueToString` converts value to string for LLM models as human-readable string
2210
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2211
- *
2212
- * @public exported from `@promptbook/utils`
2228
+ * TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
2229
+ * TODO: [๐Ÿš] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2213
2230
  */
2214
- function valueToString(value) {
2215
- try {
2216
- if (value === '') {
2217
- return VALUE_STRINGS.empty;
2218
- }
2219
- else if (value === null) {
2220
- return VALUE_STRINGS.null;
2221
- }
2222
- else if (value === undefined) {
2223
- return VALUE_STRINGS.undefined;
2224
- }
2225
- else if (typeof value === 'string') {
2226
- return value;
2227
- }
2228
- else if (typeof value === 'number') {
2229
- return numberToString(value);
2230
- }
2231
- else if (value instanceof Date) {
2232
- return value.toISOString();
2233
- }
2234
- else {
2235
- return JSON.stringify(value);
2236
- }
2237
- }
2238
- catch (error) {
2239
- if (!(error instanceof Error)) {
2240
- throw error;
2241
- }
2242
- console.error(error);
2243
- return VALUE_STRINGS.unserializable;
2244
- }
2245
- }
2246
2231
 
2247
2232
  /**
2248
2233
  * Serializes an error into a [๐Ÿš‰] JSON-serializable object
@@ -2906,10 +2891,9 @@
2906
2891
  return modelName;
2907
2892
  })
2908
2893
  .join(',');
2909
- return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
2894
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
2910
2895
  case 3:
2911
2896
  result = _d.sent();
2912
- assertsExecutionSuccessful(result);
2913
2897
  outputParameters = result.outputParameters;
2914
2898
  modelRequirementsRaw = outputParameters.modelRequirements;
2915
2899
  modelRequirements = JSON.parse(modelRequirementsRaw);
@@ -3666,7 +3650,7 @@
3666
3650
  value = value.replace(/\.html$/, '');
3667
3651
  }
3668
3652
  else if (isValidFilePath(value)) {
3669
- value = path.basename(value);
3653
+ value = node_path.basename(value);
3670
3654
  // Note: Keeping extension in the name
3671
3655
  }
3672
3656
  value = value.split('/').join('-');
@@ -3772,9 +3756,9 @@
3772
3756
  }
3773
3757
  basename = url.split('/').pop() || titleToName(url);
3774
3758
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
3775
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3776
- 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));
3777
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
3759
+ rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3760
+ 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));
3761
+ return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
3778
3762
  case 2:
3779
3763
  _h.sent();
3780
3764
  _g = (_f = Buffer).from;
@@ -3784,7 +3768,7 @@
3784
3768
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3785
3769
  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."));
3786
3770
  }
3787
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
3771
+ return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
3788
3772
  case 4:
3789
3773
  _h.sent();
3790
3774
  // TODO: [๐Ÿ’ต] Check the file security
@@ -3800,7 +3784,7 @@
3800
3784
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
3801
3785
  // <- TODO: [๐Ÿง ] What is the best error type here`
3802
3786
  }
3803
- filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3787
+ filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3804
3788
  fileExtension = getFileExtension(filename_1);
3805
3789
  mimeType = extensionToMimeType(fileExtension || '');
3806
3790
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
@@ -4115,10 +4099,9 @@
4115
4099
  var content = _a.content;
4116
4100
  return content;
4117
4101
  }).join('\n\n'),
4118
- })];
4102
+ }).asPromise()];
4119
4103
  case 2:
4120
4104
  result = _e.sent();
4121
- assertsExecutionSuccessful(result);
4122
4105
  outputParameters = result.outputParameters;
4123
4106
  titleRaw = outputParameters.title;
4124
4107
  if (isVerbose) {
@@ -4190,6 +4173,81 @@
4190
4173
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
4191
4174
  */
4192
4175
 
4176
+ /**
4177
+ * Format either small or big number
4178
+ *
4179
+ * @public exported from `@promptbook/utils`
4180
+ */
4181
+ function numberToString(value) {
4182
+ if (value === 0) {
4183
+ return '0';
4184
+ }
4185
+ else if (Number.isNaN(value)) {
4186
+ return VALUE_STRINGS.nan;
4187
+ }
4188
+ else if (value === Infinity) {
4189
+ return VALUE_STRINGS.infinity;
4190
+ }
4191
+ else if (value === -Infinity) {
4192
+ return VALUE_STRINGS.negativeInfinity;
4193
+ }
4194
+ for (var exponent = 0; exponent < 15; exponent++) {
4195
+ var factor = Math.pow(10, exponent);
4196
+ var valueRounded = Math.round(value * factor) / factor;
4197
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4198
+ return valueRounded.toFixed(exponent);
4199
+ }
4200
+ }
4201
+ return value.toString();
4202
+ }
4203
+
4204
+ /**
4205
+ * Function `valueToString` will convert the given value to string
4206
+ * This is useful and used in the `templateParameters` function
4207
+ *
4208
+ * Note: This function is not just calling `toString` method
4209
+ * It's more complex and can handle this conversion specifically for LLM models
4210
+ * See `VALUE_STRINGS`
4211
+ *
4212
+ * Note: There are 2 similar functions
4213
+ * - `valueToString` converts value to string for LLM models as human-readable string
4214
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4215
+ *
4216
+ * @public exported from `@promptbook/utils`
4217
+ */
4218
+ function valueToString(value) {
4219
+ try {
4220
+ if (value === '') {
4221
+ return VALUE_STRINGS.empty;
4222
+ }
4223
+ else if (value === null) {
4224
+ return VALUE_STRINGS.null;
4225
+ }
4226
+ else if (value === undefined) {
4227
+ return VALUE_STRINGS.undefined;
4228
+ }
4229
+ else if (typeof value === 'string') {
4230
+ return value;
4231
+ }
4232
+ else if (typeof value === 'number') {
4233
+ return numberToString(value);
4234
+ }
4235
+ else if (value instanceof Date) {
4236
+ return value.toISOString();
4237
+ }
4238
+ else {
4239
+ return JSON.stringify(value);
4240
+ }
4241
+ }
4242
+ catch (error) {
4243
+ if (!(error instanceof Error)) {
4244
+ throw error;
4245
+ }
4246
+ console.error(error);
4247
+ return VALUE_STRINGS.unserializable;
4248
+ }
4249
+ }
4250
+
4193
4251
  /**
4194
4252
  * Parses the given script and returns the list of all used variables that are not defined in the script
4195
4253
  *
@@ -5518,27 +5576,20 @@
5518
5576
  */
5519
5577
  function executeTask(options) {
5520
5578
  return __awaiter(this, void 0, void 0, function () {
5521
- var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
5522
- var e_1, _f, _g;
5523
- return __generator(this, function (_h) {
5524
- switch (_h.label) {
5579
+ var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
5580
+ var _f, e_1, _g, _h, _j;
5581
+ return __generator(this, function (_k) {
5582
+ switch (_k.label) {
5525
5583
  case 0:
5526
5584
  currentTask = options.currentTask, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts, maxParallelCount = options.maxParallelCount, csvSettings = options.csvSettings, isVerbose = options.isVerbose, rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, isAutoInstalled = options.isAutoInstalled, isNotPreparedWarningSupressed = options.isNotPreparedWarningSupressed;
5527
- name = "pipeline-executor-frame-".concat(currentTask.name);
5528
- title = currentTask.title;
5529
5585
  priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5530
5586
  return [4 /*yield*/, onProgress({
5531
- name: name,
5532
- title: title,
5533
- isStarted: false,
5534
- isDone: false,
5535
- taskType: currentTask.taskType,
5536
- parameterName: currentTask.resultingParameterName,
5537
- parameterValue: null,
5538
- // <- [๐Ÿธ]
5587
+ outputParameters: (_f = {},
5588
+ _f[currentTask.resultingParameterName] = '',
5589
+ _f),
5539
5590
  })];
5540
5591
  case 1:
5541
- _h.sent();
5592
+ _k.sent();
5542
5593
  usedParameterNames = extractParameterNamesFromTask(currentTask);
5543
5594
  dependentParameterNames = new Set(currentTask.dependentParameterNames);
5544
5595
  // TODO: [๐Ÿ‘ฉ๐Ÿพโ€๐Ÿคโ€๐Ÿ‘ฉ๐Ÿป] Use here `mapAvailableToExpectedParameters`
@@ -5557,7 +5608,7 @@
5557
5608
  pipelineIdentification: pipelineIdentification,
5558
5609
  })];
5559
5610
  case 2:
5560
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
5611
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
5561
5612
  definedParameterNames = new Set(Object.keys(definedParameters));
5562
5613
  parameters = {};
5563
5614
  _loop_1 = function (parameterName) {
@@ -5585,7 +5636,7 @@
5585
5636
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5586
5637
  finally {
5587
5638
  try {
5588
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
5639
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
5589
5640
  }
5590
5641
  finally { if (e_1) throw e_1.error; }
5591
5642
  }
@@ -5616,24 +5667,19 @@
5616
5667
  isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5617
5668
  })];
5618
5669
  case 3:
5619
- resultString = _h.sent();
5670
+ resultString = _k.sent();
5620
5671
  return [4 /*yield*/, onProgress({
5621
- name: name,
5622
- title: title,
5623
- isStarted: true,
5624
- isDone: true,
5625
- taskType: currentTask.taskType,
5626
- parameterName: currentTask.resultingParameterName,
5627
- parameterValue: resultString,
5628
- // <- [๐Ÿธ]
5672
+ outputParameters: (_h = {},
5673
+ _h[currentTask.resultingParameterName] = resultString,
5674
+ _h),
5629
5675
  })];
5630
5676
  case 4:
5631
- _h.sent();
5632
- return [2 /*return*/, Object.freeze((_g = {},
5633
- _g[currentTask.resultingParameterName] =
5677
+ _k.sent();
5678
+ return [2 /*return*/, Object.freeze((_j = {},
5679
+ _j[currentTask.resultingParameterName] =
5634
5680
  // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
5635
5681
  resultString,
5636
- _g))];
5682
+ _j))];
5637
5683
  }
5638
5684
  });
5639
5685
  });
@@ -5641,9 +5687,6 @@
5641
5687
  /**
5642
5688
  * TODO: [๐Ÿคนโ€โ™‚๏ธ]
5643
5689
  */
5644
- /**
5645
- * TODO: [๐Ÿš] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5646
- */
5647
5690
 
5648
5691
  /**
5649
5692
  * @@@
@@ -5905,15 +5948,15 @@
5905
5948
  return [3 /*break*/, 4];
5906
5949
  case 3:
5907
5950
  unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
5908
- work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
5951
+ work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
5909
5952
  if (isReturned) {
5910
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
5953
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(newOngoingResult, null, 4)
5911
5954
  .split('\n')
5912
5955
  .map(function (line) { return "> ".concat(line); })
5913
5956
  .join('\n')), "\n "); }));
5914
5957
  }
5915
5958
  if (onProgress) {
5916
- onProgress(progress);
5959
+ onProgress(newOngoingResult);
5917
5960
  }
5918
5961
  }, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
5919
5962
  .then(function (newParametersToPass) {
@@ -6016,9 +6059,6 @@
6016
6059
  });
6017
6060
  });
6018
6061
  }
6019
- /**
6020
- * TODO: [๐Ÿš] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6021
- */
6022
6062
 
6023
6063
  /**
6024
6064
  * Creates executor function from pipeline and execution tools.
@@ -6050,7 +6090,7 @@
6050
6090
  console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
6051
6091
  }
6052
6092
  var runCount = 0;
6053
- var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
6093
+ var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
6054
6094
  return __generator(this, function (_a) {
6055
6095
  runCount++;
6056
6096
  return [2 /*return*/, /* not await */ executePipeline({
@@ -6075,11 +6115,23 @@
6075
6115
  })];
6076
6116
  });
6077
6117
  }); };
6118
+ var pipelineExecutor = function (inputParameters) {
6119
+ return createTask({
6120
+ taskType: 'EXECUTION',
6121
+ taskProcessCallback: function (updateOngoingResult) {
6122
+ var _this = this;
6123
+ return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
6124
+ return __generator(this, function (_a) {
6125
+ updateOngoingResult(newOngoingResult);
6126
+ return [2 /*return*/];
6127
+ });
6128
+ }); });
6129
+ },
6130
+ });
6131
+ };
6132
+ // <- TODO: Make types such as there is no need to do `as` for `createTask`
6078
6133
  return pipelineExecutor;
6079
6134
  }
6080
- /**
6081
- * TODO: [๐Ÿš] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6082
- */
6083
6135
 
6084
6136
  /**
6085
6137
  * Metadata of the scraper
@@ -6181,10 +6233,9 @@
6181
6233
  return [4 /*yield*/, source.asText()];
6182
6234
  case 4:
6183
6235
  knowledgeContent = _k.sent();
6184
- return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
6236
+ return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
6185
6237
  case 5:
6186
6238
  result = _k.sent();
6187
- assertsExecutionSuccessful(result);
6188
6239
  outputParameters = result.outputParameters;
6189
6240
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6190
6241
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6207,13 +6258,13 @@
6207
6258
  _c.label = 1;
6208
6259
  case 1:
6209
6260
  _c.trys.push([1, 7, , 8]);
6210
- return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
6261
+ return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6211
6262
  case 2:
6212
6263
  titleResult = _c.sent();
6213
6264
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
6214
6265
  title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
6215
6266
  name = titleToName(title);
6216
- return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
6267
+ return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6217
6268
  case 3:
6218
6269
  keywordsResult = _c.sent();
6219
6270
  _b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;