@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/README.md CHANGED
@@ -24,6 +24,10 @@
24
24
 
25
25
 
26
26
 
27
+ <blockquote style="color: #ff8811">
28
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
29
+ </blockquote>
30
+
27
31
  ## 📦 Package `@promptbook/markdown-utils`
28
32
 
29
33
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
2
  import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
+ import { BehaviorSubject, concat, from } from 'rxjs';
5
+ import { randomBytes } from 'crypto';
4
6
  import { forTime } from 'waitasecond';
5
7
  import hexEncoder from 'crypto-js/enc-hex';
6
8
  import sha256 from 'crypto-js/sha256';
7
- import { basename, join, dirname } from 'path';
9
+ import { basename, join, dirname } from 'node:path';
8
10
  import { SHA256 } from 'crypto-js';
9
11
  import { lookup, extension } from 'mime-types';
10
12
  import { unparse, parse } from 'papaparse';
@@ -23,7 +25,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
23
25
  * @generated
24
26
  * @see https://github.com/webgptorg/promptbook
25
27
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
27
29
  /**
28
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1872,6 +1874,58 @@ var PipelineExecutionError = /** @class */ (function (_super) {
1872
1874
  return PipelineExecutionError;
1873
1875
  }(Error));
1874
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 randomBytes(randomness).toString('hex');
1924
+ }
1925
+ /**
1926
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1927
+ */
1928
+
1875
1929
  /**
1876
1930
  * This error indicates problems parsing the format value
1877
1931
  *
@@ -2089,9 +2143,9 @@ function deserializeError(error) {
2089
2143
  *
2090
2144
  * @param executionResult - The partial result of the Promptbook execution
2091
2145
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2092
- * @public exported from `@promptbook/core`
2146
+ * @private internal helper function of `asPromise` method of `ExecutionTask`
2093
2147
  */
2094
- function assertsExecutionSuccessful(executionResult) {
2148
+ function assertsTaskSuccessful(executionResult) {
2095
2149
  var e_1, _a;
2096
2150
  var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2097
2151
  try {
@@ -2126,121 +2180,54 @@ function assertsExecutionSuccessful(executionResult) {
2126
2180
  }
2127
2181
  }
2128
2182
  /**
2129
- * TODO: [🐚] This function should be removed OR changed OR be completely rewritten
2130
2183
  * TODO: [🧠] Can this return type be better typed than void
2131
2184
  */
2132
2185
 
2133
2186
  /**
2134
- * Determine if the pipeline is fully prepared
2135
- *
2136
- * @see https://github.com/webgptorg/promptbook/discussions/196
2137
- *
2138
- * @public exported from `@promptbook/core`
2139
- */
2140
- function isPipelinePrepared(pipeline) {
2141
- // Note: Ignoring `pipeline.preparations` @@@
2142
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2143
- if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2144
- return false;
2145
- }
2146
- if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2147
- return false;
2148
- }
2149
- if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2150
- return false;
2151
- }
2152
- /*
2153
- TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
2154
- > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
2155
- > return false;
2156
- > }
2157
- */
2158
- return true;
2159
- }
2160
- /**
2161
- * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2162
- * TODO: [🐠] Maybe base this on `makeValidator`
2163
- * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2164
- * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2165
- * - [🏍] ? Is context in each task
2166
- * - [♨] Are examples prepared
2167
- * - [♨] Are tasks prepared
2168
- */
2169
-
2170
- /**
2171
- * Format either small or big number
2187
+ * Helper to create a new task
2172
2188
  *
2173
- * @public exported from `@promptbook/utils`
2189
+ * @private internal helper function
2174
2190
  */
2175
- function numberToString(value) {
2176
- if (value === 0) {
2177
- return '0';
2178
- }
2179
- else if (Number.isNaN(value)) {
2180
- return VALUE_STRINGS.nan;
2181
- }
2182
- else if (value === Infinity) {
2183
- return VALUE_STRINGS.infinity;
2184
- }
2185
- else if (value === -Infinity) {
2186
- return VALUE_STRINGS.negativeInfinity;
2187
- }
2188
- for (var exponent = 0; exponent < 15; exponent++) {
2189
- var factor = Math.pow(10, exponent);
2190
- var valueRounded = Math.round(value * factor) / factor;
2191
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2192
- return valueRounded.toFixed(exponent);
2193
- }
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 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
+ });
2194
2215
  }
2195
- return value.toString();
2216
+ return {
2217
+ taskType: taskType,
2218
+ taskId: taskId,
2219
+ asPromise: asPromise,
2220
+ asObservable: function () {
2221
+ return concat(partialResultSubject.asObservable(), from(asPromise({
2222
+ isCrashedOnError: true,
2223
+ })));
2224
+ },
2225
+ };
2196
2226
  }
2197
-
2198
2227
  /**
2199
- * Function `valueToString` will convert the given value to string
2200
- * This is useful and used in the `templateParameters` function
2201
- *
2202
- * Note: This function is not just calling `toString` method
2203
- * It's more complex and can handle this conversion specifically for LLM models
2204
- * See `VALUE_STRINGS`
2205
- *
2206
- * Note: There are 2 similar functions
2207
- * - `valueToString` converts value to string for LLM models as human-readable string
2208
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2209
- *
2210
- * @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
2211
2230
  */
2212
- function valueToString(value) {
2213
- try {
2214
- if (value === '') {
2215
- return VALUE_STRINGS.empty;
2216
- }
2217
- else if (value === null) {
2218
- return VALUE_STRINGS.null;
2219
- }
2220
- else if (value === undefined) {
2221
- return VALUE_STRINGS.undefined;
2222
- }
2223
- else if (typeof value === 'string') {
2224
- return value;
2225
- }
2226
- else if (typeof value === 'number') {
2227
- return numberToString(value);
2228
- }
2229
- else if (value instanceof Date) {
2230
- return value.toISOString();
2231
- }
2232
- else {
2233
- return JSON.stringify(value);
2234
- }
2235
- }
2236
- catch (error) {
2237
- if (!(error instanceof Error)) {
2238
- throw error;
2239
- }
2240
- console.error(error);
2241
- return VALUE_STRINGS.unserializable;
2242
- }
2243
- }
2244
2231
 
2245
2232
  /**
2246
2233
  * Serializes an error into a [🚉] JSON-serializable object
@@ -2904,10 +2891,9 @@ function preparePersona(personaDescription, tools, options) {
2904
2891
  return modelName;
2905
2892
  })
2906
2893
  .join(',');
2907
- return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
2894
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
2908
2895
  case 3:
2909
2896
  result = _d.sent();
2910
- assertsExecutionSuccessful(result);
2911
2897
  outputParameters = result.outputParameters;
2912
2898
  modelRequirementsRaw = outputParameters.modelRequirements;
2913
2899
  modelRequirements = JSON.parse(modelRequirementsRaw);
@@ -4113,10 +4099,9 @@ function preparePipeline(pipeline, tools, options) {
4113
4099
  var content = _a.content;
4114
4100
  return content;
4115
4101
  }).join('\n\n'),
4116
- })];
4102
+ }).asPromise()];
4117
4103
  case 2:
4118
4104
  result = _e.sent();
4119
- assertsExecutionSuccessful(result);
4120
4105
  outputParameters = result.outputParameters;
4121
4106
  titleRaw = outputParameters.title;
4122
4107
  if (isVerbose) {
@@ -4188,6 +4173,81 @@ function preparePipeline(pipeline, tools, options) {
4188
4173
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
4189
4174
  */
4190
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
+
4191
4251
  /**
4192
4252
  * Parses the given script and returns the list of all used variables that are not defined in the script
4193
4253
  *
@@ -5516,27 +5576,20 @@ function getReservedParametersForTask(options) {
5516
5576
  */
5517
5577
  function executeTask(options) {
5518
5578
  return __awaiter(this, void 0, void 0, function () {
5519
- 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;
5520
- var e_1, _f, _g;
5521
- return __generator(this, function (_h) {
5522
- 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) {
5523
5583
  case 0:
5524
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;
5525
- name = "pipeline-executor-frame-".concat(currentTask.name);
5526
- title = currentTask.title;
5527
5585
  priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5528
5586
  return [4 /*yield*/, onProgress({
5529
- name: name,
5530
- title: title,
5531
- isStarted: false,
5532
- isDone: false,
5533
- taskType: currentTask.taskType,
5534
- parameterName: currentTask.resultingParameterName,
5535
- parameterValue: null,
5536
- // <- [🍸]
5587
+ outputParameters: (_f = {},
5588
+ _f[currentTask.resultingParameterName] = '',
5589
+ _f),
5537
5590
  })];
5538
5591
  case 1:
5539
- _h.sent();
5592
+ _k.sent();
5540
5593
  usedParameterNames = extractParameterNamesFromTask(currentTask);
5541
5594
  dependentParameterNames = new Set(currentTask.dependentParameterNames);
5542
5595
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
@@ -5555,7 +5608,7 @@ function executeTask(options) {
5555
5608
  pipelineIdentification: pipelineIdentification,
5556
5609
  })];
5557
5610
  case 2:
5558
- 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])]);
5559
5612
  definedParameterNames = new Set(Object.keys(definedParameters));
5560
5613
  parameters = {};
5561
5614
  _loop_1 = function (parameterName) {
@@ -5583,7 +5636,7 @@ function executeTask(options) {
5583
5636
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5584
5637
  finally {
5585
5638
  try {
5586
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
5639
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
5587
5640
  }
5588
5641
  finally { if (e_1) throw e_1.error; }
5589
5642
  }
@@ -5614,24 +5667,19 @@ function executeTask(options) {
5614
5667
  isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5615
5668
  })];
5616
5669
  case 3:
5617
- resultString = _h.sent();
5670
+ resultString = _k.sent();
5618
5671
  return [4 /*yield*/, onProgress({
5619
- name: name,
5620
- title: title,
5621
- isStarted: true,
5622
- isDone: true,
5623
- taskType: currentTask.taskType,
5624
- parameterName: currentTask.resultingParameterName,
5625
- parameterValue: resultString,
5626
- // <- [🍸]
5672
+ outputParameters: (_h = {},
5673
+ _h[currentTask.resultingParameterName] = resultString,
5674
+ _h),
5627
5675
  })];
5628
5676
  case 4:
5629
- _h.sent();
5630
- return [2 /*return*/, Object.freeze((_g = {},
5631
- _g[currentTask.resultingParameterName] =
5677
+ _k.sent();
5678
+ return [2 /*return*/, Object.freeze((_j = {},
5679
+ _j[currentTask.resultingParameterName] =
5632
5680
  // <- Note: [👩‍👩‍👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
5633
5681
  resultString,
5634
- _g))];
5682
+ _j))];
5635
5683
  }
5636
5684
  });
5637
5685
  });
@@ -5639,9 +5687,6 @@ function executeTask(options) {
5639
5687
  /**
5640
5688
  * TODO: [🤹‍♂️]
5641
5689
  */
5642
- /**
5643
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5644
- */
5645
5690
 
5646
5691
  /**
5647
5692
  * @@@
@@ -5903,15 +5948,15 @@ function executePipeline(options) {
5903
5948
  return [3 /*break*/, 4];
5904
5949
  case 3:
5905
5950
  unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
5906
- 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) {
5907
5952
  if (isReturned) {
5908
- throw new UnexpectedError(spaceTrim$1(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$1(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)
5909
5954
  .split('\n')
5910
5955
  .map(function (line) { return "> ".concat(line); })
5911
5956
  .join('\n')), "\n "); }));
5912
5957
  }
5913
5958
  if (onProgress) {
5914
- onProgress(progress);
5959
+ onProgress(newOngoingResult);
5915
5960
  }
5916
5961
  }, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
5917
5962
  .then(function (newParametersToPass) {
@@ -6014,9 +6059,6 @@ function executePipeline(options) {
6014
6059
  });
6015
6060
  });
6016
6061
  }
6017
- /**
6018
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6019
- */
6020
6062
 
6021
6063
  /**
6022
6064
  * Creates executor function from pipeline and execution tools.
@@ -6048,7 +6090,7 @@ function createPipelineExecutor(options) {
6048
6090
  console.warn(spaceTrim$1(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 "); }));
6049
6091
  }
6050
6092
  var runCount = 0;
6051
- 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 () {
6052
6094
  return __generator(this, function (_a) {
6053
6095
  runCount++;
6054
6096
  return [2 /*return*/, /* not await */ executePipeline({
@@ -6073,11 +6115,23 @@ function createPipelineExecutor(options) {
6073
6115
  })];
6074
6116
  });
6075
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`
6076
6133
  return pipelineExecutor;
6077
6134
  }
6078
- /**
6079
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6080
- */
6081
6135
 
6082
6136
  /**
6083
6137
  * Metadata of the scraper
@@ -6179,10 +6233,9 @@ var MarkdownScraper = /** @class */ (function () {
6179
6233
  return [4 /*yield*/, source.asText()];
6180
6234
  case 4:
6181
6235
  knowledgeContent = _k.sent();
6182
- return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
6236
+ return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
6183
6237
  case 5:
6184
6238
  result = _k.sent();
6185
- assertsExecutionSuccessful(result);
6186
6239
  outputParameters = result.outputParameters;
6187
6240
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6188
6241
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6205,13 +6258,13 @@ var MarkdownScraper = /** @class */ (function () {
6205
6258
  _c.label = 1;
6206
6259
  case 1:
6207
6260
  _c.trys.push([1, 7, , 8]);
6208
- return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
6261
+ return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6209
6262
  case 2:
6210
6263
  titleResult = _c.sent();
6211
6264
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
6212
6265
  title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
6213
6266
  name = titleToName(title);
6214
- return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
6267
+ return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6215
6268
  case 3:
6216
6269
  keywordsResult = _c.sent();
6217
6270
  _b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;