@promptbook/node 0.103.0-55 → 0.103.0-56

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.
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('jszip'), require('crypto'), require('rxjs'), 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
3
  typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'jszip', 'crypto', 'rxjs', '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.JSZip, global.crypto, global.rxjs, 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, JSZip, crypto, rxjs, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, child_process, dotenv) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim$1, global.JSZip, global.crypto, global.rxjs, 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$1, JSZip, crypto, rxjs, 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
 
@@ -25,7 +25,7 @@
25
25
  }
26
26
 
27
27
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
28
- var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
28
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim$1);
29
29
  var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
30
30
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
31
31
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
@@ -45,12 +45,23 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-55';
48
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-56';
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
52
52
  */
53
53
 
54
+ /**
55
+ * Trims string from all 4 sides
56
+ *
57
+ * Note: This is a re-exported function from the `spacetrim` package which is
58
+ * Developed by same author @hejny as this package
59
+ *
60
+ * @public exported from `@promptbook/utils`
61
+ * @see https://github.com/hejny/spacetrim#usage
62
+ */
63
+ const spaceTrim = spaceTrim$1.spaceTrim;
64
+
54
65
  /**
55
66
  * @private util of `@promptbook/color`
56
67
  * @de
@@ -99,6 +110,7 @@
99
110
  * @public exported from `@promptbook/color`
100
111
  */
101
112
  const CSS_COLORS = {
113
+ promptbook: '#79EAFD',
102
114
  transparent: 'rgba(0,0,0,0)',
103
115
  aliceblue: '#f0f8ff',
104
116
  antiquewhite: '#faebd7',
@@ -314,6 +326,28 @@
314
326
  throw new Error(`Can not create color from given object`);
315
327
  }
316
328
  }
329
+ /**
330
+ * Creates a new Color instance from miscellaneous formats
331
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
332
+ *
333
+ * @param color
334
+ * @returns Color object
335
+ */
336
+ static fromSafe(color) {
337
+ try {
338
+ return Color.from(color);
339
+ }
340
+ catch (error) {
341
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
342
+ console.warn(spaceTrim((block) => `
343
+ Color.fromSafe error:
344
+ ${block(error.message)}
345
+
346
+ Returning default PROMPTBOOK_COLOR.
347
+ `));
348
+ return Color.fromString('promptbook');
349
+ }
350
+ }
317
351
  /**
318
352
  * Creates a new Color instance from miscellaneous string formats
319
353
  *
@@ -923,7 +957,7 @@
923
957
  *
924
958
  * @public exported from `@promptbook/core`
925
959
  */
926
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
960
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
927
961
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
928
962
  /**
929
963
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -1191,7 +1225,7 @@
1191
1225
  */
1192
1226
  class UnexpectedError extends Error {
1193
1227
  constructor(message) {
1194
- super(spaceTrim.spaceTrim((block) => `
1228
+ super(spaceTrim$1.spaceTrim((block) => `
1195
1229
  ${block(message)}
1196
1230
 
1197
1231
  Note: This error should not happen.
@@ -1295,7 +1329,7 @@
1295
1329
  constructor(whatWasThrown) {
1296
1330
  const tag = `[🤮]`;
1297
1331
  console.error(tag, whatWasThrown);
1298
- super(spaceTrim.spaceTrim(`
1332
+ super(spaceTrim$1.spaceTrim(`
1299
1333
  Non-Error object was thrown
1300
1334
 
1301
1335
  Note: Look for ${tag} in the console for more details
@@ -1758,7 +1792,7 @@
1758
1792
  if (!(error instanceof PipelineLogicError)) {
1759
1793
  throw error;
1760
1794
  }
1761
- console.error(spaceTrim.spaceTrim((block) => `
1795
+ console.error(spaceTrim$1.spaceTrim((block) => `
1762
1796
  Pipeline is not valid but logic errors are temporarily disabled via \`IS_PIPELINE_LOGIC_VALIDATED\`
1763
1797
 
1764
1798
  ${block(error.message)}
@@ -1785,7 +1819,7 @@
1785
1819
  })();
1786
1820
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
1787
1821
  // <- Note: [🚲]
1788
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1822
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1789
1823
  Invalid promptbook URL "${pipeline.pipelineUrl}"
1790
1824
 
1791
1825
  ${block(pipelineIdentification)}
@@ -1793,7 +1827,7 @@
1793
1827
  }
1794
1828
  if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
1795
1829
  // <- Note: [🚲]
1796
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1830
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1797
1831
  Invalid Promptbook Version "${pipeline.bookVersion}"
1798
1832
 
1799
1833
  ${block(pipelineIdentification)}
@@ -1802,7 +1836,7 @@
1802
1836
  // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1803
1837
  if (!Array.isArray(pipeline.parameters)) {
1804
1838
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1805
- throw new ParseError(spaceTrim.spaceTrim((block) => `
1839
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
1806
1840
  Pipeline is valid JSON but with wrong structure
1807
1841
 
1808
1842
  \`PipelineJson.parameters\` expected to be an array, but got ${typeof pipeline.parameters}
@@ -1813,7 +1847,7 @@
1813
1847
  // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1814
1848
  if (!Array.isArray(pipeline.tasks)) {
1815
1849
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1816
- throw new ParseError(spaceTrim.spaceTrim((block) => `
1850
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
1817
1851
  Pipeline is valid JSON but with wrong structure
1818
1852
 
1819
1853
  \`PipelineJson.tasks\` expected to be an array, but got ${typeof pipeline.tasks}
@@ -1839,7 +1873,7 @@
1839
1873
  // Note: Check each parameter individually
1840
1874
  for (const parameter of pipeline.parameters) {
1841
1875
  if (parameter.isInput && parameter.isOutput) {
1842
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1876
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1843
1877
 
1844
1878
  Parameter \`{${parameter.name}}\` can not be both input and output
1845
1879
 
@@ -1850,7 +1884,7 @@
1850
1884
  if (!parameter.isInput &&
1851
1885
  !parameter.isOutput &&
1852
1886
  !pipeline.tasks.some((task) => task.dependentParameterNames.includes(parameter.name))) {
1853
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1887
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1854
1888
  Parameter \`{${parameter.name}}\` is created but not used
1855
1889
 
1856
1890
  You can declare {${parameter.name}} as output parameter by adding in the header:
@@ -1862,7 +1896,7 @@
1862
1896
  }
1863
1897
  // Note: Testing that parameter is either input or result of some task
1864
1898
  if (!parameter.isInput && !pipeline.tasks.some((task) => task.resultingParameterName === parameter.name)) {
1865
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1899
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1866
1900
  Parameter \`{${parameter.name}}\` is declared but not defined
1867
1901
 
1868
1902
  You can do one of these:
@@ -1878,14 +1912,14 @@
1878
1912
  // Note: Checking each task individually
1879
1913
  for (const task of pipeline.tasks) {
1880
1914
  if (definedParameters.has(task.resultingParameterName)) {
1881
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1915
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1882
1916
  Parameter \`{${task.resultingParameterName}}\` is defined multiple times
1883
1917
 
1884
1918
  ${block(pipelineIdentification)}
1885
1919
  `));
1886
1920
  }
1887
1921
  if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
1888
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1922
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1889
1923
  Parameter name {${task.resultingParameterName}} is reserved, please use different name
1890
1924
 
1891
1925
  ${block(pipelineIdentification)}
@@ -1895,7 +1929,7 @@
1895
1929
  if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
1896
1930
  if (!task.format &&
1897
1931
  !task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1898
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1932
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1899
1933
  Joker parameters are used for {${task.resultingParameterName}} but no expectations are defined
1900
1934
 
1901
1935
  ${block(pipelineIdentification)}
@@ -1903,7 +1937,7 @@
1903
1937
  }
1904
1938
  for (const joker of task.jokerParameterNames) {
1905
1939
  if (!task.dependentParameterNames.includes(joker)) {
1906
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1940
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1907
1941
  Parameter \`{${joker}}\` is used for {${task.resultingParameterName}} as joker but not in \`dependentParameterNames\`
1908
1942
 
1909
1943
  ${block(pipelineIdentification)}
@@ -1914,21 +1948,21 @@
1914
1948
  if (task.expectations) {
1915
1949
  for (const [unit, { min, max }] of Object.entries(task.expectations)) {
1916
1950
  if (min !== undefined && max !== undefined && min > max) {
1917
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1951
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1918
1952
  Min expectation (=${min}) of ${unit} is higher than max expectation (=${max})
1919
1953
 
1920
1954
  ${block(pipelineIdentification)}
1921
1955
  `));
1922
1956
  }
1923
1957
  if (min !== undefined && min < 0) {
1924
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1958
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1925
1959
  Min expectation of ${unit} must be zero or positive
1926
1960
 
1927
1961
  ${block(pipelineIdentification)}
1928
1962
  `));
1929
1963
  }
1930
1964
  if (max !== undefined && max <= 0) {
1931
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
1965
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
1932
1966
  Max expectation of ${unit} must be positive
1933
1967
 
1934
1968
  ${block(pipelineIdentification)}
@@ -1950,7 +1984,7 @@
1950
1984
  while (unresovedTasks.length > 0) {
1951
1985
  if (loopLimit-- < 0) {
1952
1986
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
1953
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
1987
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
1954
1988
  Loop limit reached during detection of circular dependencies in \`validatePipeline\`
1955
1989
 
1956
1990
  ${block(pipelineIdentification)}
@@ -1960,7 +1994,7 @@
1960
1994
  if (currentlyResovedTasks.length === 0) {
1961
1995
  throw new PipelineLogicError(
1962
1996
  // TODO: [🐎] DRY
1963
- spaceTrim.spaceTrim((block) => `
1997
+ spaceTrim$1.spaceTrim((block) => `
1964
1998
 
1965
1999
  Can not resolve some parameters:
1966
2000
  Either you are using a parameter that is not defined, or there are some circular dependencies.
@@ -2442,7 +2476,7 @@
2442
2476
  for (const pipeline of pipelines) {
2443
2477
  // TODO: [👠] DRY
2444
2478
  if (pipeline.pipelineUrl === undefined) {
2445
- throw new PipelineUrlError(spaceTrim.spaceTrim(`
2479
+ throw new PipelineUrlError(spaceTrim$1.spaceTrim(`
2446
2480
  Pipeline with name "${pipeline.title}" does not have defined URL
2447
2481
 
2448
2482
  File:
@@ -2464,7 +2498,7 @@
2464
2498
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
2465
2499
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
2466
2500
  const existing = this.collection.get(pipeline.pipelineUrl);
2467
- throw new PipelineUrlError(spaceTrim.spaceTrim(`
2501
+ throw new PipelineUrlError(spaceTrim$1.spaceTrim(`
2468
2502
  Pipeline with URL ${pipeline.pipelineUrl} is already in the collection 🍎
2469
2503
 
2470
2504
  Conflicting files:
@@ -2496,13 +2530,13 @@
2496
2530
  const pipeline = this.collection.get(url);
2497
2531
  if (!pipeline) {
2498
2532
  if (this.listPipelines().length === 0) {
2499
- throw new NotFoundError(spaceTrim.spaceTrim(`
2533
+ throw new NotFoundError(spaceTrim$1.spaceTrim(`
2500
2534
  Pipeline with url "${url}" not found
2501
2535
 
2502
2536
  No pipelines available
2503
2537
  `));
2504
2538
  }
2505
- throw new NotFoundError(spaceTrim.spaceTrim((block) => `
2539
+ throw new NotFoundError(spaceTrim$1.spaceTrim((block) => `
2506
2540
  Pipeline with url "${url}" not found
2507
2541
 
2508
2542
  Available pipelines:
@@ -2543,7 +2577,7 @@
2543
2577
  */
2544
2578
  class MissingToolsError extends Error {
2545
2579
  constructor(message) {
2546
- super(spaceTrim.spaceTrim((block) => `
2580
+ super(spaceTrim$1.spaceTrim((block) => `
2547
2581
  ${block(message)}
2548
2582
 
2549
2583
  Note: You have probably forgot to provide some tools for pipeline execution or preparation
@@ -2741,7 +2775,7 @@
2741
2775
  */
2742
2776
  class NotYetImplementedError extends Error {
2743
2777
  constructor(message) {
2744
- super(spaceTrim.spaceTrim((block) => `
2778
+ super(spaceTrim$1.spaceTrim((block) => `
2745
2779
  ${block(message)}
2746
2780
 
2747
2781
  Note: This feature is not implemented yet but it will be soon.
@@ -2980,11 +3014,11 @@
2980
3014
  throw deserializeError(errors[0]);
2981
3015
  }
2982
3016
  else {
2983
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
3017
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
2984
3018
  Multiple errors occurred during Promptbook execution
2985
3019
 
2986
3020
  ${block(errors
2987
- .map(({ name, stack, message }, index) => spaceTrim.spaceTrim((block) => `
3021
+ .map(({ name, stack, message }, index) => spaceTrim$1.spaceTrim((block) => `
2988
3022
  ${name} ${index + 1}:
2989
3023
  ${block(stack || message)}
2990
3024
  `))
@@ -3438,7 +3472,7 @@
3438
3472
  }
3439
3473
  catch (error) {
3440
3474
  assertsError(error);
3441
- throw new ParseError(spaceTrim.spaceTrim((block) => `
3475
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
3442
3476
  Can not extract variables from the script
3443
3477
  ${block(error.stack || error.message)}
3444
3478
 
@@ -4801,7 +4835,7 @@
4801
4835
  }
4802
4836
  catch (error) {
4803
4837
  keepUnused(error);
4804
- throw new ExpectError(spaceTrim.spaceTrim((block) => `
4838
+ throw new ExpectError(spaceTrim$1.spaceTrim((block) => `
4805
4839
  Expected valid JSON string
4806
4840
 
4807
4841
  The expected JSON text:
@@ -4864,7 +4898,7 @@
4864
4898
  const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
4865
4899
  // TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
4866
4900
  if (isJokerAttempt && !jokerParameterName) {
4867
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
4901
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
4868
4902
  Joker not found in attempt ${attemptIndex}
4869
4903
 
4870
4904
  ${block(pipelineIdentification)}
@@ -4875,7 +4909,7 @@
4875
4909
  $ongoingTaskResult.$expectError = null;
4876
4910
  if (isJokerAttempt) {
4877
4911
  if (parameters[jokerParameterName] === undefined) {
4878
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
4912
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4879
4913
  Joker parameter {${jokerParameterName}} not defined
4880
4914
 
4881
4915
  ${block(pipelineIdentification)}
@@ -4933,7 +4967,7 @@
4933
4967
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
4934
4968
  break variant;
4935
4969
  case 'EMBEDDING':
4936
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
4970
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4937
4971
  Embedding model can not be used in pipeline
4938
4972
 
4939
4973
  This should be catched during parsing
@@ -4944,7 +4978,7 @@
4944
4978
  break variant;
4945
4979
  // <- case [🤖]:
4946
4980
  default:
4947
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
4981
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4948
4982
  Unknown model variant "${task.modelRequirements.modelVariant}"
4949
4983
 
4950
4984
  ${block(pipelineIdentification)}
@@ -4955,14 +4989,14 @@
4955
4989
  break;
4956
4990
  case 'SCRIPT_TASK':
4957
4991
  if (arrayableToArray(tools.script).length === 0) {
4958
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
4992
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4959
4993
  No script execution tools are available
4960
4994
 
4961
4995
  ${block(pipelineIdentification)}
4962
4996
  `));
4963
4997
  }
4964
4998
  if (!task.contentLanguage) {
4965
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
4999
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4966
5000
  Script language is not defined for SCRIPT TASK "${task.name}"
4967
5001
 
4968
5002
  ${block(pipelineIdentification)}
@@ -4993,7 +5027,7 @@
4993
5027
  throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
4994
5028
  }
4995
5029
  else {
4996
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5030
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
4997
5031
  Script execution failed ${$ongoingTaskResult.$scriptPipelineExecutionErrors.length}x
4998
5032
 
4999
5033
  ${block(pipelineIdentification)}
@@ -5007,7 +5041,7 @@
5007
5041
  break taskType;
5008
5042
  case 'DIALOG_TASK':
5009
5043
  if (tools.userInterface === undefined) {
5010
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5044
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
5011
5045
  User interface tools are not available
5012
5046
 
5013
5047
  ${block(pipelineIdentification)}
@@ -5025,7 +5059,7 @@
5025
5059
  break taskType;
5026
5060
  // <- case: [🅱]
5027
5061
  default:
5028
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5062
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
5029
5063
  Unknown execution type "${task.taskType}"
5030
5064
 
5031
5065
  ${block(pipelineIdentification)}
@@ -5123,7 +5157,7 @@
5123
5157
  if ($ongoingTaskResult.$expectError !== null && attemptIndex === maxAttempts - 1) {
5124
5158
  // Note: Create a summary of all failures
5125
5159
  const failuresSummary = $ongoingTaskResult.$failedResults
5126
- .map((failure) => spaceTrim.spaceTrim((block) => {
5160
+ .map((failure) => spaceTrim$1.spaceTrim((block) => {
5127
5161
  var _a, _b;
5128
5162
  return `
5129
5163
  Attempt ${failure.attemptIndex + 1}:
@@ -5133,14 +5167,14 @@
5133
5167
  Result:
5134
5168
  ${block(failure.result === null
5135
5169
  ? 'null'
5136
- : spaceTrim.spaceTrim(failure.result)
5170
+ : spaceTrim$1.spaceTrim(failure.result)
5137
5171
  .split('\n')
5138
5172
  .map((line) => `> ${line}`)
5139
5173
  .join('\n'))}
5140
5174
  `;
5141
5175
  }))
5142
5176
  .join('\n\n---\n\n');
5143
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => {
5177
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => {
5144
5178
  var _a;
5145
5179
  return `
5146
5180
  LLM execution failed ${maxExecutionAttempts}x
@@ -5160,7 +5194,7 @@
5160
5194
  }
5161
5195
  }
5162
5196
  if ($ongoingTaskResult.$resultString === null) {
5163
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5197
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5164
5198
  Something went wrong and prompt result is null
5165
5199
 
5166
5200
  ${block(pipelineIdentification)}
@@ -5466,7 +5500,7 @@
5466
5500
  // Note: Doublecheck that ALL reserved parameters are defined:
5467
5501
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
5468
5502
  if (reservedParameters[parameterName] === undefined) {
5469
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5503
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5470
5504
  Reserved parameter {${parameterName}} is not defined
5471
5505
 
5472
5506
  ${block(pipelineIdentification)}
@@ -5492,7 +5526,7 @@
5492
5526
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
5493
5527
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5494
5528
  if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
5495
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5529
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5496
5530
  Dependent parameters are not consistent with used parameters:
5497
5531
 
5498
5532
  Dependent parameters:
@@ -5536,7 +5570,7 @@
5536
5570
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
5537
5571
  // Houston, we have a problem
5538
5572
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
5539
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5573
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5540
5574
  Parameter \`{${parameterName}}\` is NOT defined
5541
5575
  BUT used in task "${currentTask.title || currentTask.name}"
5542
5576
 
@@ -5605,7 +5639,7 @@
5605
5639
  for (const parameter of preparedPipeline.parameters.filter(({ isOutput }) => isOutput)) {
5606
5640
  if (parametersToPass[parameter.name] === undefined) {
5607
5641
  // [4]
5608
- $warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5642
+ $warnings.push(new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
5609
5643
  Parameter \`{${parameter.name}}\` should be an output parameter, but it was not generated during pipeline execution
5610
5644
 
5611
5645
  Note: This is a warning which happened after the pipeline was executed, and \`{${parameter.name}}\` was not for some reason defined in output parameters
@@ -5713,7 +5747,7 @@
5713
5747
  for (const parameterName of Object.keys(inputParameters)) {
5714
5748
  const parameter = preparedPipeline.parameters.find(({ name }) => name === parameterName);
5715
5749
  if (parameter === undefined) {
5716
- warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5750
+ warnings.push(new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
5717
5751
  Extra parameter {${parameterName}} is being passed which is not part of the pipeline.
5718
5752
 
5719
5753
  ${block(pipelineIdentification)}
@@ -5728,7 +5762,7 @@
5728
5762
  // TODO: [🧠] This should be also non-critical error
5729
5763
  return exportJson({
5730
5764
  name: 'pipelineExecutorResult',
5731
- message: spaceTrim.spaceTrim((block) => `
5765
+ message: spaceTrim$1.spaceTrim((block) => `
5732
5766
  Unsuccessful PipelineExecutorResult (with extra parameter {${parameter.name}}) PipelineExecutorResult
5733
5767
 
5734
5768
  ${block(pipelineIdentification)}
@@ -5737,7 +5771,7 @@
5737
5771
  value: {
5738
5772
  isSuccessful: false,
5739
5773
  errors: [
5740
- new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
5774
+ new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
5741
5775
  Parameter \`{${parameter.name}}\` is passed as input parameter but it is not input
5742
5776
 
5743
5777
  ${block(pipelineIdentification)}
@@ -5764,7 +5798,7 @@
5764
5798
  while (unresovedTasks.length > 0) {
5765
5799
  if (loopLimit-- < 0) {
5766
5800
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
5767
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5801
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5768
5802
  Loop limit reached during resolving parameters pipeline execution
5769
5803
 
5770
5804
  ${block(pipelineIdentification)}
@@ -5774,7 +5808,7 @@
5774
5808
  if (!currentTask && resolving.length === 0) {
5775
5809
  throw new UnexpectedError(
5776
5810
  // TODO: [🐎] DRY
5777
- spaceTrim.spaceTrim((block) => `
5811
+ spaceTrim$1.spaceTrim((block) => `
5778
5812
  Can not resolve some parameters:
5779
5813
 
5780
5814
  ${block(pipelineIdentification)}
@@ -5814,7 +5848,7 @@
5814
5848
  tools,
5815
5849
  onProgress(newOngoingResult) {
5816
5850
  if (isReturned) {
5817
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5851
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
5818
5852
  Can not call \`onProgress\` after pipeline execution is finished
5819
5853
 
5820
5854
  ${block(pipelineIdentification)}
@@ -5831,7 +5865,7 @@
5831
5865
  },
5832
5866
  logLlmCall,
5833
5867
  $executionReport: executionReport,
5834
- pipelineIdentification: spaceTrim.spaceTrim((block) => `
5868
+ pipelineIdentification: spaceTrim$1.spaceTrim((block) => `
5835
5869
  ${block(pipelineIdentification)}
5836
5870
  Task name: ${currentTask.name}
5837
5871
  Task title: ${currentTask.title}
@@ -5940,7 +5974,7 @@
5940
5974
  preparedPipeline = pipeline;
5941
5975
  }
5942
5976
  else if (isNotPreparedWarningSuppressed !== true) {
5943
- console.warn(spaceTrim.spaceTrim((block) => `
5977
+ console.warn(spaceTrim$1.spaceTrim((block) => `
5944
5978
  Pipeline is not prepared
5945
5979
 
5946
5980
  ${block(pipelineIdentification)}
@@ -5965,7 +5999,7 @@
5965
5999
  tools,
5966
6000
  onProgress,
5967
6001
  logLlmCall,
5968
- pipelineIdentification: spaceTrim.spaceTrim((block) => `
6002
+ pipelineIdentification: spaceTrim$1.spaceTrim((block) => `
5969
6003
  ${block(pipelineIdentification)}
5970
6004
  ${runCount === 1 ? '' : `Run #${runCount}`}
5971
6005
  `),
@@ -7032,7 +7066,7 @@
7032
7066
  if (task.taskType === 'PROMPT_TASK' &&
7033
7067
  knowledgePiecesCount > 0 &&
7034
7068
  !dependentParameterNames.includes('knowledge')) {
7035
- preparedContent = spaceTrim.spaceTrim(`
7069
+ preparedContent = spaceTrim$1.spaceTrim(`
7036
7070
  {content}
7037
7071
 
7038
7072
  ## Knowledge
@@ -9549,7 +9583,7 @@
9549
9583
  function getParserForCommand(command) {
9550
9584
  const commandParser = COMMANDS.find((commandParser) => commandParser.name === command.type);
9551
9585
  if (commandParser === undefined) {
9552
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
9586
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
9553
9587
  Command ${command.type} parser is not found
9554
9588
 
9555
9589
  ${block(JSON.stringify(command, null, 4)
@@ -9625,7 +9659,7 @@
9625
9659
  .map(removeMarkdownFormatting)
9626
9660
  .map((item) => item.trim());
9627
9661
  if (items.length === 0 || items[0] === '') {
9628
- throw new ParseError(spaceTrim.spaceTrim((block) => `
9662
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
9629
9663
  Malformed command:
9630
9664
  - ${raw}
9631
9665
 
@@ -9661,7 +9695,7 @@
9661
9695
  return command;
9662
9696
  }
9663
9697
  }
9664
- throw new ParseError(spaceTrim.spaceTrim((block) => `
9698
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
9665
9699
  Malformed or unknown command:
9666
9700
  - ${raw}
9667
9701
 
@@ -9712,7 +9746,7 @@
9712
9746
  if (!(error instanceof ParseError)) {
9713
9747
  throw error;
9714
9748
  }
9715
- throw new ParseError(spaceTrim.spaceTrim((block) => `
9749
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
9716
9750
  Invalid ${commandName} command:
9717
9751
 
9718
9752
  Your command:
@@ -10028,7 +10062,7 @@
10028
10062
  * @public exported from `@promptbook/markdown-utils`
10029
10063
  */
10030
10064
  function removeMarkdownComments(content) {
10031
- return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
10065
+ return spaceTrim$1.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
10032
10066
  }
10033
10067
 
10034
10068
  /**
@@ -10344,7 +10378,7 @@
10344
10378
  if (pipelineString.startsWith('#!')) {
10345
10379
  const [shebangLine, ...restLines] = pipelineString.split('\n');
10346
10380
  if (!(shebangLine || '').includes('ptbk')) {
10347
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10381
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10348
10382
  It seems that you try to parse a book file which has non-standard shebang line for book files:
10349
10383
  Shebang line must contain 'ptbk'
10350
10384
 
@@ -10360,7 +10394,7 @@
10360
10394
  pipelineString = validatePipelineString(restLines.join('\n'));
10361
10395
  }
10362
10396
  pipelineString = removeMarkdownComments(pipelineString);
10363
- pipelineString = spaceTrim.spaceTrim(pipelineString);
10397
+ pipelineString = spaceTrim$1.spaceTrim(pipelineString);
10364
10398
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
10365
10399
  pipelineString = deflatePipeline(pipelineString);
10366
10400
  // ==============
@@ -10372,7 +10406,7 @@
10372
10406
  // ==============
10373
10407
  // Note: 1️⃣◽4️⃣ Check markdown structure
10374
10408
  if (pipelineHead === undefined) {
10375
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
10409
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
10376
10410
  Pipeline head is not defined
10377
10411
 
10378
10412
  ${block(getPipelineIdentification())}
@@ -10381,7 +10415,7 @@
10381
10415
  `));
10382
10416
  }
10383
10417
  if (pipelineHead.level !== 1) {
10384
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
10418
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
10385
10419
  Pipeline head is not h1
10386
10420
 
10387
10421
  ${block(getPipelineIdentification())}
@@ -10390,7 +10424,7 @@
10390
10424
  `));
10391
10425
  }
10392
10426
  if (!pipelineSections.every((section) => section.level === 2)) {
10393
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
10427
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
10394
10428
  Not every pipeline section is h2
10395
10429
 
10396
10430
  ${block(getPipelineIdentification())}
@@ -10403,7 +10437,7 @@
10403
10437
  const defineParam = (parameterCommand) => {
10404
10438
  const { parameterName, parameterDescription, isInput, isOutput } = parameterCommand;
10405
10439
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
10406
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10440
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10407
10441
  Parameter name {${parameterName}} is reserved and cannot be used as resulting parameter name
10408
10442
 
10409
10443
  ${block(getPipelineIdentification())}
@@ -10414,7 +10448,7 @@
10414
10448
  existingParameter.description &&
10415
10449
  existingParameter.description !== parameterDescription &&
10416
10450
  parameterDescription) {
10417
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10451
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10418
10452
  Parameter \`{${parameterName}}\` is defined multiple times with different description:
10419
10453
 
10420
10454
  ${block(getPipelineIdentification())}
@@ -10452,7 +10486,7 @@
10452
10486
  description = description.split(/^>.*$/gm).join('');
10453
10487
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
10454
10488
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
10455
- description = spaceTrim.spaceTrim(description);
10489
+ description = spaceTrim$1.spaceTrim(description);
10456
10490
  if (description === '') {
10457
10491
  description = undefined;
10458
10492
  }
@@ -10463,7 +10497,7 @@
10463
10497
  const command = parseCommand(listItem, 'PIPELINE_HEAD');
10464
10498
  const commandParser = getParserForCommand(command);
10465
10499
  if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
10466
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10500
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10467
10501
  Command \`${command.type}\` is not allowed in the head of the pipeline ONLY at the pipeline task
10468
10502
 
10469
10503
  ${block(getPipelineIdentification())}
@@ -10477,7 +10511,7 @@
10477
10511
  if (!(error instanceof ParseError)) {
10478
10512
  throw error;
10479
10513
  }
10480
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10514
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10481
10515
  Command ${command.type} failed to apply to the pipeline
10482
10516
 
10483
10517
  The error:
@@ -10530,7 +10564,7 @@
10530
10564
  description = description.split(/^>.*$/gm).join('');
10531
10565
  //Note: Remove lists and return statement - TODO: [🎾]
10532
10566
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
10533
- description = spaceTrim.spaceTrim(description);
10567
+ description = spaceTrim$1.spaceTrim(description);
10534
10568
  if (description === '') {
10535
10569
  description = undefined;
10536
10570
  }
@@ -10564,7 +10598,7 @@
10564
10598
  for (const { listItem, command } of commands) {
10565
10599
  const commandParser = getParserForCommand(command);
10566
10600
  if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
10567
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10601
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10568
10602
  Command \`${command.type}\` is not allowed in the task of the promptbook ONLY at the pipeline head
10569
10603
 
10570
10604
  ${block(getPipelineIdentification())}
@@ -10579,7 +10613,7 @@
10579
10613
  if (!(error instanceof ParseError)) {
10580
10614
  throw error;
10581
10615
  }
10582
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10616
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10583
10617
  Command \`${command.type}\` failed to apply to the task
10584
10618
 
10585
10619
  The error:
@@ -10610,14 +10644,14 @@
10610
10644
  // TODO: [🍧] Should be done in SECTION command
10611
10645
  if ($taskJson.taskType === 'SCRIPT_TASK') {
10612
10646
  if (!language) {
10613
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10647
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10614
10648
  You must specify the language of the script in the \`SCRIPT\` task
10615
10649
 
10616
10650
  ${block(getPipelineIdentification())}
10617
10651
  `));
10618
10652
  }
10619
10653
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
10620
- throw new ParseError(spaceTrim.spaceTrim((block) => `
10654
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
10621
10655
  Script language ${language} is not supported.
10622
10656
 
10623
10657
  Supported languages are:
@@ -10913,11 +10947,11 @@
10913
10947
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
10914
10948
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
10915
10949
  }
10916
- resolve(spaceTrim.spaceTrim(output.join('\n')));
10950
+ resolve(spaceTrim$1.spaceTrim(output.join('\n')));
10917
10951
  }
10918
10952
  }
10919
10953
  else {
10920
- resolve(spaceTrim.spaceTrim(output.join('\n')));
10954
+ resolve(spaceTrim$1.spaceTrim(output.join('\n')));
10921
10955
  }
10922
10956
  };
10923
10957
  commandProcess.on('close', finishWithCode);
@@ -10935,7 +10969,7 @@
10935
10969
  console.warn(error);
10936
10970
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
10937
10971
  }
10938
- resolve(spaceTrim.spaceTrim(output.join('\n')));
10972
+ resolve(spaceTrim$1.spaceTrim(output.join('\n')));
10939
10973
  }
10940
10974
  });
10941
10975
  }
@@ -11750,7 +11784,7 @@
11750
11784
  let trimmedText = text;
11751
11785
  // Remove leading and trailing spaces and newlines
11752
11786
  if (isTrimmed) {
11753
- trimmedText = spaceTrim.spaceTrim(trimmedText);
11787
+ trimmedText = spaceTrim$1.spaceTrim(trimmedText);
11754
11788
  }
11755
11789
  let processedText = trimmedText;
11756
11790
  if (isIntroduceSentenceRemoved) {
@@ -11759,7 +11793,7 @@
11759
11793
  // Remove the introduce sentence and quotes by replacing it with an empty string
11760
11794
  processedText = processedText.replace(introduceSentenceRegex, '');
11761
11795
  }
11762
- processedText = spaceTrim.spaceTrim(processedText);
11796
+ processedText = spaceTrim$1.spaceTrim(processedText);
11763
11797
  }
11764
11798
  if (processedText.length < 3) {
11765
11799
  return trimmedText;
@@ -11866,13 +11900,13 @@
11866
11900
  * @public exported from `@promptbook/markdown-utils`
11867
11901
  */
11868
11902
  function trimCodeBlock(value) {
11869
- value = spaceTrim.spaceTrim(value);
11903
+ value = spaceTrim$1.spaceTrim(value);
11870
11904
  if (!/^```[a-z]*(.*)```$/is.test(value)) {
11871
11905
  return value;
11872
11906
  }
11873
11907
  value = value.replace(/^```[a-z]*/i, '');
11874
11908
  value = value.replace(/```$/i, '');
11875
- value = spaceTrim.spaceTrim(value);
11909
+ value = spaceTrim$1.spaceTrim(value);
11876
11910
  return value;
11877
11911
  }
11878
11912
 
@@ -11885,9 +11919,9 @@
11885
11919
  * @public exported from `@promptbook/markdown-utils`
11886
11920
  */
11887
11921
  function trimEndOfCodeBlock(value) {
11888
- value = spaceTrim.spaceTrim(value);
11922
+ value = spaceTrim$1.spaceTrim(value);
11889
11923
  value = value.replace(/```$/g, '');
11890
- value = spaceTrim.spaceTrim(value);
11924
+ value = spaceTrim$1.spaceTrim(value);
11891
11925
  return value;
11892
11926
  }
11893
11927