@promptbook/documents 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 +216 -163
  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 +4 -2
  32. package/umd/index.umd.js +224 -173
  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/documents`
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,13 +1,15 @@
1
- import { mkdir, rm, readFile } from 'fs/promises';
1
+ import { mkdir, rm, readFile } from 'node:fs/promises';
2
2
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
- import { spawn } from 'child_process';
4
3
  import colors from 'colors';
4
+ import { spawn } from 'node:child_process';
5
5
  import { forTime } from 'waitasecond';
6
6
  import { SHA256 } from 'crypto-js';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
8
- import { basename, join, dirname } from 'path';
8
+ import { basename, join, dirname } from 'node:path';
9
9
  import { format } from 'prettier';
10
10
  import parserHtml from 'prettier/parser-html';
11
+ import { BehaviorSubject, concat, from } from 'rxjs';
12
+ import { randomBytes } from 'crypto';
11
13
  import sha256 from 'crypto-js/sha256';
12
14
  import { lookup, extension } from 'mime-types';
13
15
  import { unparse, parse } from 'papaparse';
@@ -26,7 +28,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
28
  * @generated
27
29
  * @see https://github.com/webgptorg/promptbook
28
30
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
30
32
  /**
31
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -407,7 +409,7 @@ var UnexpectedError = /** @class */ (function (_super) {
407
409
  */
408
410
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
409
411
  /**
410
- * TODO: []
412
+ * TODO: [🎺]
411
413
  */
412
414
 
413
415
  /**
@@ -2402,6 +2404,58 @@ var PipelineExecutionError = /** @class */ (function (_super) {
2402
2404
  return PipelineExecutionError;
2403
2405
  }(Error));
2404
2406
 
2407
+ /**
2408
+ * Determine if the pipeline is fully prepared
2409
+ *
2410
+ * @see https://github.com/webgptorg/promptbook/discussions/196
2411
+ *
2412
+ * @public exported from `@promptbook/core`
2413
+ */
2414
+ function isPipelinePrepared(pipeline) {
2415
+ // Note: Ignoring `pipeline.preparations` @@@
2416
+ // Note: Ignoring `pipeline.knowledgePieces` @@@
2417
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2418
+ return false;
2419
+ }
2420
+ if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2421
+ return false;
2422
+ }
2423
+ if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2424
+ return false;
2425
+ }
2426
+ /*
2427
+ TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
2428
+ > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
2429
+ > return false;
2430
+ > }
2431
+ */
2432
+ return true;
2433
+ }
2434
+ /**
2435
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2436
+ * TODO: [🐠] Maybe base this on `makeValidator`
2437
+ * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2438
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2439
+ * - [🏍] ? Is context in each task
2440
+ * - [♨] Are examples prepared
2441
+ * - [♨] Are tasks prepared
2442
+ */
2443
+
2444
+ /**
2445
+ * Generates random token
2446
+ *
2447
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2448
+ *
2449
+ * @private internal helper function
2450
+ * @returns secure random token
2451
+ */
2452
+ function $randomToken(randomness) {
2453
+ return randomBytes(randomness).toString('hex');
2454
+ }
2455
+ /**
2456
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2457
+ */
2458
+
2405
2459
  /**
2406
2460
  * This error indicates problems parsing the format value
2407
2461
  *
@@ -2587,9 +2641,9 @@ function deserializeError(error) {
2587
2641
  *
2588
2642
  * @param executionResult - The partial result of the Promptbook execution
2589
2643
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2590
- * @public exported from `@promptbook/core`
2644
+ * @private internal helper function of `asPromise` method of `ExecutionTask`
2591
2645
  */
2592
- function assertsExecutionSuccessful(executionResult) {
2646
+ function assertsTaskSuccessful(executionResult) {
2593
2647
  var e_1, _a;
2594
2648
  var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2595
2649
  try {
@@ -2624,121 +2678,54 @@ function assertsExecutionSuccessful(executionResult) {
2624
2678
  }
2625
2679
  }
2626
2680
  /**
2627
- * TODO: [🐚] This function should be removed OR changed OR be completely rewritten
2628
2681
  * TODO: [🧠] Can this return type be better typed than void
2629
2682
  */
2630
2683
 
2631
2684
  /**
2632
- * Determine if the pipeline is fully prepared
2633
- *
2634
- * @see https://github.com/webgptorg/promptbook/discussions/196
2635
- *
2636
- * @public exported from `@promptbook/core`
2637
- */
2638
- function isPipelinePrepared(pipeline) {
2639
- // Note: Ignoring `pipeline.preparations` @@@
2640
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2641
- if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2642
- return false;
2643
- }
2644
- if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2645
- return false;
2646
- }
2647
- if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2648
- return false;
2649
- }
2650
- /*
2651
- TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
2652
- > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
2653
- > return false;
2654
- > }
2655
- */
2656
- return true;
2657
- }
2658
- /**
2659
- * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2660
- * TODO: [🐠] Maybe base this on `makeValidator`
2661
- * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2662
- * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2663
- * - [🏍] ? Is context in each task
2664
- * - [♨] Are examples prepared
2665
- * - [♨] Are tasks prepared
2666
- */
2667
-
2668
- /**
2669
- * Format either small or big number
2685
+ * Helper to create a new task
2670
2686
  *
2671
- * @public exported from `@promptbook/utils`
2687
+ * @private internal helper function
2672
2688
  */
2673
- function numberToString(value) {
2674
- if (value === 0) {
2675
- return '0';
2676
- }
2677
- else if (Number.isNaN(value)) {
2678
- return VALUE_STRINGS.nan;
2679
- }
2680
- else if (value === Infinity) {
2681
- return VALUE_STRINGS.infinity;
2682
- }
2683
- else if (value === -Infinity) {
2684
- return VALUE_STRINGS.negativeInfinity;
2685
- }
2686
- for (var exponent = 0; exponent < 15; exponent++) {
2687
- var factor = Math.pow(10, exponent);
2688
- var valueRounded = Math.round(value * factor) / factor;
2689
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2690
- return valueRounded.toFixed(exponent);
2691
- }
2689
+ function createTask(options) {
2690
+ var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2691
+ var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2692
+ var partialResultSubject = new BehaviorSubject({});
2693
+ var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2694
+ partialResultSubject.next(newOngoingResult);
2695
+ });
2696
+ function asPromise(options) {
2697
+ return __awaiter(this, void 0, void 0, function () {
2698
+ var _a, isCrashedOnError, finalResult;
2699
+ return __generator(this, function (_b) {
2700
+ switch (_b.label) {
2701
+ case 0:
2702
+ _a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
2703
+ return [4 /*yield*/, finalResultPromise];
2704
+ case 1:
2705
+ finalResult = _b.sent();
2706
+ if (isCrashedOnError) {
2707
+ assertsTaskSuccessful(finalResult);
2708
+ }
2709
+ return [2 /*return*/, finalResult];
2710
+ }
2711
+ });
2712
+ });
2692
2713
  }
2693
- return value.toString();
2714
+ return {
2715
+ taskType: taskType,
2716
+ taskId: taskId,
2717
+ asPromise: asPromise,
2718
+ asObservable: function () {
2719
+ return concat(partialResultSubject.asObservable(), from(asPromise({
2720
+ isCrashedOnError: true,
2721
+ })));
2722
+ },
2723
+ };
2694
2724
  }
2695
-
2696
2725
  /**
2697
- * Function `valueToString` will convert the given value to string
2698
- * This is useful and used in the `templateParameters` function
2699
- *
2700
- * Note: This function is not just calling `toString` method
2701
- * It's more complex and can handle this conversion specifically for LLM models
2702
- * See `VALUE_STRINGS`
2703
- *
2704
- * Note: There are 2 similar functions
2705
- * - `valueToString` converts value to string for LLM models as human-readable string
2706
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2707
- *
2708
- * @public exported from `@promptbook/utils`
2726
+ * TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
2727
+ * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2709
2728
  */
2710
- function valueToString(value) {
2711
- try {
2712
- if (value === '') {
2713
- return VALUE_STRINGS.empty;
2714
- }
2715
- else if (value === null) {
2716
- return VALUE_STRINGS.null;
2717
- }
2718
- else if (value === undefined) {
2719
- return VALUE_STRINGS.undefined;
2720
- }
2721
- else if (typeof value === 'string') {
2722
- return value;
2723
- }
2724
- else if (typeof value === 'number') {
2725
- return numberToString(value);
2726
- }
2727
- else if (value instanceof Date) {
2728
- return value.toISOString();
2729
- }
2730
- else {
2731
- return JSON.stringify(value);
2732
- }
2733
- }
2734
- catch (error) {
2735
- if (!(error instanceof Error)) {
2736
- throw error;
2737
- }
2738
- console.error(error);
2739
- return VALUE_STRINGS.unserializable;
2740
- }
2741
- }
2742
2729
 
2743
2730
  /**
2744
2731
  * Serializes an error into a [🚉] JSON-serializable object
@@ -3402,10 +3389,9 @@ function preparePersona(personaDescription, tools, options) {
3402
3389
  return modelName;
3403
3390
  })
3404
3391
  .join(',');
3405
- return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
3392
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
3406
3393
  case 3:
3407
3394
  result = _d.sent();
3408
- assertsExecutionSuccessful(result);
3409
3395
  outputParameters = result.outputParameters;
3410
3396
  modelRequirementsRaw = outputParameters.modelRequirements;
3411
3397
  modelRequirements = JSON.parse(modelRequirementsRaw);
@@ -4193,10 +4179,9 @@ function preparePipeline(pipeline, tools, options) {
4193
4179
  var content = _a.content;
4194
4180
  return content;
4195
4181
  }).join('\n\n'),
4196
- })];
4182
+ }).asPromise()];
4197
4183
  case 2:
4198
4184
  result = _e.sent();
4199
- assertsExecutionSuccessful(result);
4200
4185
  outputParameters = result.outputParameters;
4201
4186
  titleRaw = outputParameters.title;
4202
4187
  if (isVerbose) {
@@ -4268,6 +4253,81 @@ function preparePipeline(pipeline, tools, options) {
4268
4253
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
4269
4254
  */
4270
4255
 
4256
+ /**
4257
+ * Format either small or big number
4258
+ *
4259
+ * @public exported from `@promptbook/utils`
4260
+ */
4261
+ function numberToString(value) {
4262
+ if (value === 0) {
4263
+ return '0';
4264
+ }
4265
+ else if (Number.isNaN(value)) {
4266
+ return VALUE_STRINGS.nan;
4267
+ }
4268
+ else if (value === Infinity) {
4269
+ return VALUE_STRINGS.infinity;
4270
+ }
4271
+ else if (value === -Infinity) {
4272
+ return VALUE_STRINGS.negativeInfinity;
4273
+ }
4274
+ for (var exponent = 0; exponent < 15; exponent++) {
4275
+ var factor = Math.pow(10, exponent);
4276
+ var valueRounded = Math.round(value * factor) / factor;
4277
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4278
+ return valueRounded.toFixed(exponent);
4279
+ }
4280
+ }
4281
+ return value.toString();
4282
+ }
4283
+
4284
+ /**
4285
+ * Function `valueToString` will convert the given value to string
4286
+ * This is useful and used in the `templateParameters` function
4287
+ *
4288
+ * Note: This function is not just calling `toString` method
4289
+ * It's more complex and can handle this conversion specifically for LLM models
4290
+ * See `VALUE_STRINGS`
4291
+ *
4292
+ * Note: There are 2 similar functions
4293
+ * - `valueToString` converts value to string for LLM models as human-readable string
4294
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4295
+ *
4296
+ * @public exported from `@promptbook/utils`
4297
+ */
4298
+ function valueToString(value) {
4299
+ try {
4300
+ if (value === '') {
4301
+ return VALUE_STRINGS.empty;
4302
+ }
4303
+ else if (value === null) {
4304
+ return VALUE_STRINGS.null;
4305
+ }
4306
+ else if (value === undefined) {
4307
+ return VALUE_STRINGS.undefined;
4308
+ }
4309
+ else if (typeof value === 'string') {
4310
+ return value;
4311
+ }
4312
+ else if (typeof value === 'number') {
4313
+ return numberToString(value);
4314
+ }
4315
+ else if (value instanceof Date) {
4316
+ return value.toISOString();
4317
+ }
4318
+ else {
4319
+ return JSON.stringify(value);
4320
+ }
4321
+ }
4322
+ catch (error) {
4323
+ if (!(error instanceof Error)) {
4324
+ throw error;
4325
+ }
4326
+ console.error(error);
4327
+ return VALUE_STRINGS.unserializable;
4328
+ }
4329
+ }
4330
+
4271
4331
  /**
4272
4332
  * Parses the given script and returns the list of all used variables that are not defined in the script
4273
4333
  *
@@ -5712,27 +5772,20 @@ function getReservedParametersForTask(options) {
5712
5772
  */
5713
5773
  function executeTask(options) {
5714
5774
  return __awaiter(this, void 0, void 0, function () {
5715
- 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;
5716
- var e_1, _f, _g;
5717
- return __generator(this, function (_h) {
5718
- switch (_h.label) {
5775
+ 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;
5776
+ var _f, e_1, _g, _h, _j;
5777
+ return __generator(this, function (_k) {
5778
+ switch (_k.label) {
5719
5779
  case 0:
5720
5780
  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;
5721
- name = "pipeline-executor-frame-".concat(currentTask.name);
5722
- title = currentTask.title;
5723
5781
  priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5724
5782
  return [4 /*yield*/, onProgress({
5725
- name: name,
5726
- title: title,
5727
- isStarted: false,
5728
- isDone: false,
5729
- taskType: currentTask.taskType,
5730
- parameterName: currentTask.resultingParameterName,
5731
- parameterValue: null,
5732
- // <- [🍸]
5783
+ outputParameters: (_f = {},
5784
+ _f[currentTask.resultingParameterName] = '',
5785
+ _f),
5733
5786
  })];
5734
5787
  case 1:
5735
- _h.sent();
5788
+ _k.sent();
5736
5789
  usedParameterNames = extractParameterNamesFromTask(currentTask);
5737
5790
  dependentParameterNames = new Set(currentTask.dependentParameterNames);
5738
5791
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
@@ -5751,7 +5804,7 @@ function executeTask(options) {
5751
5804
  pipelineIdentification: pipelineIdentification,
5752
5805
  })];
5753
5806
  case 2:
5754
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
5807
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
5755
5808
  definedParameterNames = new Set(Object.keys(definedParameters));
5756
5809
  parameters = {};
5757
5810
  _loop_1 = function (parameterName) {
@@ -5779,7 +5832,7 @@ function executeTask(options) {
5779
5832
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5780
5833
  finally {
5781
5834
  try {
5782
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
5835
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
5783
5836
  }
5784
5837
  finally { if (e_1) throw e_1.error; }
5785
5838
  }
@@ -5810,24 +5863,19 @@ function executeTask(options) {
5810
5863
  isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5811
5864
  })];
5812
5865
  case 3:
5813
- resultString = _h.sent();
5866
+ resultString = _k.sent();
5814
5867
  return [4 /*yield*/, onProgress({
5815
- name: name,
5816
- title: title,
5817
- isStarted: true,
5818
- isDone: true,
5819
- taskType: currentTask.taskType,
5820
- parameterName: currentTask.resultingParameterName,
5821
- parameterValue: resultString,
5822
- // <- [🍸]
5868
+ outputParameters: (_h = {},
5869
+ _h[currentTask.resultingParameterName] = resultString,
5870
+ _h),
5823
5871
  })];
5824
5872
  case 4:
5825
- _h.sent();
5826
- return [2 /*return*/, Object.freeze((_g = {},
5827
- _g[currentTask.resultingParameterName] =
5873
+ _k.sent();
5874
+ return [2 /*return*/, Object.freeze((_j = {},
5875
+ _j[currentTask.resultingParameterName] =
5828
5876
  // <- Note: [👩‍👩‍👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
5829
5877
  resultString,
5830
- _g))];
5878
+ _j))];
5831
5879
  }
5832
5880
  });
5833
5881
  });
@@ -5835,9 +5883,6 @@ function executeTask(options) {
5835
5883
  /**
5836
5884
  * TODO: [🤹‍♂️]
5837
5885
  */
5838
- /**
5839
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5840
- */
5841
5886
 
5842
5887
  /**
5843
5888
  * @@@
@@ -6099,15 +6144,15 @@ function executePipeline(options) {
6099
6144
  return [3 /*break*/, 4];
6100
6145
  case 3:
6101
6146
  unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
6102
- work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
6147
+ work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
6103
6148
  if (isReturned) {
6104
- throw new UnexpectedError(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)
6149
+ throw new UnexpectedError(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)
6105
6150
  .split('\n')
6106
6151
  .map(function (line) { return "> ".concat(line); })
6107
6152
  .join('\n')), "\n "); }));
6108
6153
  }
6109
6154
  if (onProgress) {
6110
- onProgress(progress);
6155
+ onProgress(newOngoingResult);
6111
6156
  }
6112
6157
  }, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
6113
6158
  .then(function (newParametersToPass) {
@@ -6210,9 +6255,6 @@ function executePipeline(options) {
6210
6255
  });
6211
6256
  });
6212
6257
  }
6213
- /**
6214
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6215
- */
6216
6258
 
6217
6259
  /**
6218
6260
  * Creates executor function from pipeline and execution tools.
@@ -6244,7 +6286,7 @@ function createPipelineExecutor(options) {
6244
6286
  console.warn(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 "); }));
6245
6287
  }
6246
6288
  var runCount = 0;
6247
- var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
6289
+ var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
6248
6290
  return __generator(this, function (_a) {
6249
6291
  runCount++;
6250
6292
  return [2 /*return*/, /* not await */ executePipeline({
@@ -6269,11 +6311,23 @@ function createPipelineExecutor(options) {
6269
6311
  })];
6270
6312
  });
6271
6313
  }); };
6314
+ var pipelineExecutor = function (inputParameters) {
6315
+ return createTask({
6316
+ taskType: 'EXECUTION',
6317
+ taskProcessCallback: function (updateOngoingResult) {
6318
+ var _this = this;
6319
+ return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
6320
+ return __generator(this, function (_a) {
6321
+ updateOngoingResult(newOngoingResult);
6322
+ return [2 /*return*/];
6323
+ });
6324
+ }); });
6325
+ },
6326
+ });
6327
+ };
6328
+ // <- TODO: Make types such as there is no need to do `as` for `createTask`
6272
6329
  return pipelineExecutor;
6273
6330
  }
6274
- /**
6275
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
6276
- */
6277
6331
 
6278
6332
  /**
6279
6333
  * Metadata of the scraper
@@ -6375,10 +6429,9 @@ var MarkdownScraper = /** @class */ (function () {
6375
6429
  return [4 /*yield*/, source.asText()];
6376
6430
  case 4:
6377
6431
  knowledgeContent = _k.sent();
6378
- return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
6432
+ return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
6379
6433
  case 5:
6380
6434
  result = _k.sent();
6381
- assertsExecutionSuccessful(result);
6382
6435
  outputParameters = result.outputParameters;
6383
6436
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6384
6437
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6401,13 +6454,13 @@ var MarkdownScraper = /** @class */ (function () {
6401
6454
  _c.label = 1;
6402
6455
  case 1:
6403
6456
  _c.trys.push([1, 7, , 8]);
6404
- return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
6457
+ return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6405
6458
  case 2:
6406
6459
  titleResult = _c.sent();
6407
6460
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
6408
6461
  title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
6409
6462
  name = titleToName(title);
6410
- return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
6463
+ return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
6411
6464
  case 3:
6412
6465
  keywordsResult = _c.sent();
6413
6466
  _b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;