@promptbook/node 0.78.0-0 → 0.78.3

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/esm/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import colors from 'colors';
2
2
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink } from 'fs/promises';
3
3
  import { join, basename, dirname } from 'path';
4
- import spaceTrim$1, { spaceTrim } from 'spacetrim';
4
+ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
5
5
  import { format } from 'prettier';
6
6
  import parserHtml from 'prettier/parser-html';
7
7
  import { forTime } from 'waitasecond';
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  *
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.78.2';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -172,198 +172,25 @@ function just(value) {
172
172
  }
173
173
 
174
174
  /**
175
- * @@@
176
- *
177
- * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
178
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
175
+ * Name for the Promptbook
179
176
  *
180
- * @returns The same object as the input, but deeply frozen
181
- * @public exported from `@promptbook/utils`
182
- */
183
- function $deepFreeze(objectValue) {
184
- var e_1, _a;
185
- var propertyNames = Object.getOwnPropertyNames(objectValue);
186
- try {
187
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
188
- var propertyName = propertyNames_1_1.value;
189
- var value = objectValue[propertyName];
190
- if (value && typeof value === 'object') {
191
- $deepFreeze(value);
192
- }
193
- }
194
- }
195
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
196
- finally {
197
- try {
198
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
199
- }
200
- finally { if (e_1) throw e_1.error; }
201
- }
202
- return Object.freeze(objectValue);
203
- }
204
- /**
205
- * TODO: [🧠] Is there a way how to meaningfully test this utility
206
- */
207
-
208
- /**
209
- * This error type indicates that the error should not happen and its last check before crashing with some other error
177
+ * TODO: [🗽] Unite branding and make single place for it
210
178
  *
211
179
  * @public exported from `@promptbook/core`
212
180
  */
213
- var UnexpectedError = /** @class */ (function (_super) {
214
- __extends(UnexpectedError, _super);
215
- function UnexpectedError(message) {
216
- var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
217
- _this.name = 'UnexpectedError';
218
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
219
- return _this;
220
- }
221
- return UnexpectedError;
222
- }(Error));
223
-
181
+ var NAME = "Promptbook";
224
182
  /**
225
- * Checks if the value is [🚉] serializable as JSON
226
- * If not, throws an UnexpectedError with a rich error message and tracking
183
+ * Email of the responsible person
227
184
  *
228
- * - Almost all primitives are serializable BUT:
229
- * - `undefined` is not serializable
230
- * - `NaN` is not serializable
231
- * - Objects and arrays are serializable if all their properties are serializable
232
- * - Functions are not serializable
233
- * - Circular references are not serializable
234
- * - `Date` objects are not serializable
235
- * - `Map` and `Set` objects are not serializable
236
- * - `RegExp` objects are not serializable
237
- * - `Error` objects are not serializable
238
- * - `Symbol` objects are not serializable
239
- * - And much more...
240
- *
241
- * @throws UnexpectedError if the value is not serializable as JSON
242
- * @public exported from `@promptbook/utils`
243
- */
244
- function checkSerializableAsJson(name, value) {
245
- var e_1, _a;
246
- if (value === undefined) {
247
- throw new UnexpectedError("".concat(name, " is undefined"));
248
- }
249
- else if (value === null) {
250
- return;
251
- }
252
- else if (typeof value === 'boolean') {
253
- return;
254
- }
255
- else if (typeof value === 'number' && !isNaN(value)) {
256
- return;
257
- }
258
- else if (typeof value === 'string') {
259
- return;
260
- }
261
- else if (typeof value === 'symbol') {
262
- throw new UnexpectedError("".concat(name, " is symbol"));
263
- }
264
- else if (typeof value === 'function') {
265
- throw new UnexpectedError("".concat(name, " is function"));
266
- }
267
- else if (typeof value === 'object' && Array.isArray(value)) {
268
- for (var i = 0; i < value.length; i++) {
269
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
270
- }
271
- }
272
- else if (typeof value === 'object') {
273
- if (value instanceof Date) {
274
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
275
- }
276
- else if (value instanceof Map) {
277
- throw new UnexpectedError("".concat(name, " is Map"));
278
- }
279
- else if (value instanceof Set) {
280
- throw new UnexpectedError("".concat(name, " is Set"));
281
- }
282
- else if (value instanceof RegExp) {
283
- throw new UnexpectedError("".concat(name, " is RegExp"));
284
- }
285
- else if (value instanceof Error) {
286
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
287
- }
288
- else {
289
- try {
290
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
291
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
292
- if (subValue === undefined) {
293
- // Note: undefined in object is serializable - it is just omited
294
- continue;
295
- }
296
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
297
- }
298
- }
299
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
300
- finally {
301
- try {
302
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
303
- }
304
- finally { if (e_1) throw e_1.error; }
305
- }
306
- try {
307
- JSON.stringify(value); // <- TODO: [0]
308
- }
309
- catch (error) {
310
- if (!(error instanceof Error)) {
311
- throw error;
312
- }
313
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
314
- }
315
- /*
316
- TODO: [0] Is there some more elegant way to check circular references?
317
- const seen = new Set();
318
- const stack = [{ value }];
319
- while (stack.length > 0) {
320
- const { value } = stack.pop()!;
321
- if (typeof value === 'object' && value !== null) {
322
- if (seen.has(value)) {
323
- throw new UnexpectedError(`${name} has circular reference`);
324
- }
325
- seen.add(value);
326
- if (Array.isArray(value)) {
327
- stack.push(...value.map((value) => ({ value })));
328
- } else {
329
- stack.push(...Object.values(value).map((value) => ({ value })));
330
- }
331
- }
332
- }
333
- */
334
- return;
335
- }
336
- }
337
- else {
338
- throw new UnexpectedError("".concat(name, " is unknown"));
339
- }
340
- }
341
- /**
342
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
343
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
344
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
185
+ * @public exported from `@promptbook/core`
345
186
  */
346
-
187
+ var ADMIN_EMAIL = 'me@pavolhejny.com';
347
188
  /**
348
- * @@@
349
- * @@@
189
+ * Name of the responsible person for the Promptbook on GitHub
350
190
  *
351
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
352
- *
353
- * @param name - Name of the object for debugging purposes
354
- * @param objectValue - Object to be deeply frozen
355
- * @returns The same object as the input, but deeply frozen
356
- * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
191
+ * @public exported from `@promptbook/core`
357
192
  */
358
- function $asDeeplyFrozenSerializableJson(name, objectValue) {
359
- checkSerializableAsJson(name, objectValue);
360
- return $deepFreeze(objectValue);
361
- }
362
- /**
363
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
364
- * TODO: [🧠] Is there a way how to meaningfully test this utility
365
- */
366
-
193
+ var ADMIN_GITHUB_NAME = 'hejny';
367
194
  /**
368
195
  * When the title is not provided, the default title is used
369
196
  *
@@ -433,7 +260,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
433
260
  *
434
261
  * @public exported from `@promptbook/core`
435
262
  */
436
- var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
263
+ var RESERVED_PARAMETER_NAMES =
264
+ /* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
437
265
  'content',
438
266
  'context',
439
267
  'knowledge',
@@ -443,7 +271,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
443
271
  // <- TODO: list here all command names
444
272
  // <- TODO: Add more like 'date', 'modelName',...
445
273
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
446
- ]);
274
+ ];
447
275
  /**
448
276
  * @@@
449
277
  *
@@ -707,7 +535,7 @@ function pipelineJsonToString(pipelineJson) {
707
535
  pipelineString += '\n\n';
708
536
  pipelineString += '```' + contentLanguage;
709
537
  pipelineString += '\n';
710
- pipelineString += spaceTrim$1(content);
538
+ pipelineString += spaceTrim(content);
711
539
  // <- TODO: [main] !!! Escape
712
540
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
713
541
  pipelineString += '\n';
@@ -752,7 +580,7 @@ function taskParameterJsonToString(taskParameterJson) {
752
580
  var MissingToolsError = /** @class */ (function (_super) {
753
581
  __extends(MissingToolsError, _super);
754
582
  function MissingToolsError(message) {
755
- var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
583
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
756
584
  _this.name = 'MissingToolsError';
757
585
  Object.setPrototypeOf(_this, MissingToolsError.prototype);
758
586
  return _this;
@@ -836,6 +664,40 @@ function forEachAsync(array, options, callbackfunction) {
836
664
  });
837
665
  }
838
666
 
667
+ /**
668
+ * @@@
669
+ *
670
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
671
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
672
+ *
673
+ * @returns The same object as the input, but deeply frozen
674
+ * @public exported from `@promptbook/utils`
675
+ */
676
+ function $deepFreeze(objectValue) {
677
+ var e_1, _a;
678
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
679
+ try {
680
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
681
+ var propertyName = propertyNames_1_1.value;
682
+ var value = objectValue[propertyName];
683
+ if (value && typeof value === 'object') {
684
+ $deepFreeze(value);
685
+ }
686
+ }
687
+ }
688
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
689
+ finally {
690
+ try {
691
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
692
+ }
693
+ finally { if (e_1) throw e_1.error; }
694
+ }
695
+ return Object.freeze(objectValue);
696
+ }
697
+ /**
698
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
699
+ */
700
+
839
701
  /**
840
702
  * Represents the usage with no resources consumed
841
703
  *
@@ -1090,6 +952,40 @@ var PipelineExecutionError = /** @class */ (function (_super) {
1090
952
  return PipelineExecutionError;
1091
953
  }(Error));
1092
954
 
955
+ /**
956
+ * Make error report URL for the given error
957
+ *
958
+ * @private !!!!!!
959
+ */
960
+ function getErrorReportUrl(error) {
961
+ var report = {
962
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
963
+ body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
964
+ };
965
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
966
+ reportUrl.searchParams.set('labels', 'bug');
967
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
968
+ reportUrl.searchParams.set('title', report.title);
969
+ reportUrl.searchParams.set('body', report.body);
970
+ return reportUrl;
971
+ }
972
+
973
+ /**
974
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
975
+ *
976
+ * @public exported from `@promptbook/core`
977
+ */
978
+ var UnexpectedError = /** @class */ (function (_super) {
979
+ __extends(UnexpectedError, _super);
980
+ function UnexpectedError(message) {
981
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
982
+ _this.name = 'UnexpectedError';
983
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
984
+ return _this;
985
+ }
986
+ return UnexpectedError;
987
+ }(Error));
988
+
1093
989
  /**
1094
990
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
1095
991
  *
@@ -1309,7 +1205,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1309
1205
  // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
1310
1206
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
1311
1207
  // 3) ...
1312
- spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
1208
+ spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
1313
1209
  .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
1314
1210
  .join('\n')), "\n\n "); }));
1315
1211
  }
@@ -1317,7 +1213,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1317
1213
  throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
1318
1214
  }
1319
1215
  else {
1320
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
1216
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
1321
1217
  }
1322
1218
  }
1323
1219
  });
@@ -1352,7 +1248,7 @@ function joinLlmExecutionTools() {
1352
1248
  llmExecutionTools[_i] = arguments[_i];
1353
1249
  }
1354
1250
  if (llmExecutionTools.length === 0) {
1355
- var warningMessage = spaceTrim$1("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
1251
+ var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
1356
1252
  // TODO: [🟥] Detect browser / node and make it colorfull
1357
1253
  console.warn(warningMessage);
1358
1254
  /*
@@ -1600,7 +1496,7 @@ function validatePipeline(pipeline) {
1600
1496
  if (!(error instanceof PipelineLogicError)) {
1601
1497
  throw error;
1602
1498
  }
1603
- console.error(spaceTrim(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
1499
+ console.error(spaceTrim$1(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
1604
1500
  }
1605
1501
  }
1606
1502
  return pipeline;
@@ -1624,35 +1520,35 @@ function validatePipelineCore(pipeline) {
1624
1520
  })();
1625
1521
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
1626
1522
  // <- Note: [🚲]
1627
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1523
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1628
1524
  }
1629
1525
  if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
1630
1526
  // <- Note: [🚲]
1631
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1527
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1632
1528
  }
1633
1529
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1634
1530
  if (!Array.isArray(pipeline.parameters)) {
1635
1531
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1636
- throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1532
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1637
1533
  }
1638
1534
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1639
1535
  if (!Array.isArray(pipeline.tasks)) {
1640
1536
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1641
- throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1537
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1642
1538
  }
1643
1539
  var _loop_1 = function (parameter) {
1644
1540
  if (parameter.isInput && parameter.isOutput) {
1645
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Parameter `{".concat(parameter.name, "}` can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
1541
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Parameter `{".concat(parameter.name, "}` can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
1646
1542
  }
1647
1543
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
1648
1544
  if (!parameter.isInput &&
1649
1545
  !parameter.isOutput &&
1650
1546
  !pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
1651
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
1547
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
1652
1548
  }
1653
1549
  // Note: Testing that parameter is either input or result of some task
1654
1550
  if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
1655
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1551
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1656
1552
  }
1657
1553
  };
1658
1554
  try {
@@ -1680,20 +1576,20 @@ function validatePipelineCore(pipeline) {
1680
1576
  var _loop_2 = function (task) {
1681
1577
  var e_4, _h, e_5, _j;
1682
1578
  if (definedParameters.has(task.resultingParameterName)) {
1683
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1579
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1684
1580
  }
1685
1581
  if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
1686
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1582
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1687
1583
  }
1688
1584
  definedParameters.add(task.resultingParameterName);
1689
1585
  if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
1690
1586
  if (!task.format &&
1691
1587
  !task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1692
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1588
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1693
1589
  }
1694
1590
  var _loop_4 = function (joker) {
1695
1591
  if (!task.dependentParameterNames.includes(joker)) {
1696
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1592
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1697
1593
  }
1698
1594
  };
1699
1595
  try {
@@ -1713,13 +1609,13 @@ function validatePipelineCore(pipeline) {
1713
1609
  if (task.expectations) {
1714
1610
  var _loop_5 = function (unit, min, max) {
1715
1611
  if (min !== undefined && max !== undefined && min > max) {
1716
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
1612
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
1717
1613
  }
1718
1614
  if (min !== undefined && min < 0) {
1719
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1615
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1720
1616
  }
1721
1617
  if (max !== undefined && max <= 0) {
1722
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1618
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1723
1619
  }
1724
1620
  };
1725
1621
  try {
@@ -1780,7 +1676,7 @@ function validatePipelineCore(pipeline) {
1780
1676
  var _loop_3 = function () {
1781
1677
  if (loopLimit-- < 0) {
1782
1678
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
1783
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1679
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1784
1680
  }
1785
1681
  var currentlyResovedTasks = unresovedTasks.filter(function (task) {
1786
1682
  return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -1788,7 +1684,7 @@ function validatePipelineCore(pipeline) {
1788
1684
  if (currentlyResovedTasks.length === 0) {
1789
1685
  throw new PipelineLogicError(
1790
1686
  // TODO: [🐎] DRY
1791
- spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks
1687
+ spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks
1792
1688
  .map(function (_a) {
1793
1689
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1794
1690
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -1899,6 +1795,149 @@ function extractParameterNames(template) {
1899
1795
  return parameterNames;
1900
1796
  }
1901
1797
 
1798
+ /**
1799
+ * Checks if the value is [🚉] serializable as JSON
1800
+ * If not, throws an UnexpectedError with a rich error message and tracking
1801
+ *
1802
+ * - Almost all primitives are serializable BUT:
1803
+ * - `undefined` is not serializable
1804
+ * - `NaN` is not serializable
1805
+ * - Objects and arrays are serializable if all their properties are serializable
1806
+ * - Functions are not serializable
1807
+ * - Circular references are not serializable
1808
+ * - `Date` objects are not serializable
1809
+ * - `Map` and `Set` objects are not serializable
1810
+ * - `RegExp` objects are not serializable
1811
+ * - `Error` objects are not serializable
1812
+ * - `Symbol` objects are not serializable
1813
+ * - And much more...
1814
+ *
1815
+ * @throws UnexpectedError if the value is not serializable as JSON
1816
+ * @public exported from `@promptbook/utils`
1817
+ */
1818
+ function checkSerializableAsJson(name, value) {
1819
+ var e_1, _a;
1820
+ if (value === undefined) {
1821
+ throw new UnexpectedError("".concat(name, " is undefined"));
1822
+ }
1823
+ else if (value === null) {
1824
+ return;
1825
+ }
1826
+ else if (typeof value === 'boolean') {
1827
+ return;
1828
+ }
1829
+ else if (typeof value === 'number' && !isNaN(value)) {
1830
+ return;
1831
+ }
1832
+ else if (typeof value === 'string') {
1833
+ return;
1834
+ }
1835
+ else if (typeof value === 'symbol') {
1836
+ throw new UnexpectedError("".concat(name, " is symbol"));
1837
+ }
1838
+ else if (typeof value === 'function') {
1839
+ throw new UnexpectedError("".concat(name, " is function"));
1840
+ }
1841
+ else if (typeof value === 'object' && Array.isArray(value)) {
1842
+ for (var i = 0; i < value.length; i++) {
1843
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
1844
+ }
1845
+ }
1846
+ else if (typeof value === 'object') {
1847
+ if (value instanceof Date) {
1848
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
1849
+ }
1850
+ else if (value instanceof Map) {
1851
+ throw new UnexpectedError("".concat(name, " is Map"));
1852
+ }
1853
+ else if (value instanceof Set) {
1854
+ throw new UnexpectedError("".concat(name, " is Set"));
1855
+ }
1856
+ else if (value instanceof RegExp) {
1857
+ throw new UnexpectedError("".concat(name, " is RegExp"));
1858
+ }
1859
+ else if (value instanceof Error) {
1860
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
1861
+ }
1862
+ else {
1863
+ try {
1864
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1865
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1866
+ if (subValue === undefined) {
1867
+ // Note: undefined in object is serializable - it is just omited
1868
+ continue;
1869
+ }
1870
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
1871
+ }
1872
+ }
1873
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1874
+ finally {
1875
+ try {
1876
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1877
+ }
1878
+ finally { if (e_1) throw e_1.error; }
1879
+ }
1880
+ try {
1881
+ JSON.stringify(value); // <- TODO: [0]
1882
+ }
1883
+ catch (error) {
1884
+ if (!(error instanceof Error)) {
1885
+ throw error;
1886
+ }
1887
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
1888
+ }
1889
+ /*
1890
+ TODO: [0] Is there some more elegant way to check circular references?
1891
+ const seen = new Set();
1892
+ const stack = [{ value }];
1893
+ while (stack.length > 0) {
1894
+ const { value } = stack.pop()!;
1895
+ if (typeof value === 'object' && value !== null) {
1896
+ if (seen.has(value)) {
1897
+ throw new UnexpectedError(`${name} has circular reference`);
1898
+ }
1899
+ seen.add(value);
1900
+ if (Array.isArray(value)) {
1901
+ stack.push(...value.map((value) => ({ value })));
1902
+ } else {
1903
+ stack.push(...Object.values(value).map((value) => ({ value })));
1904
+ }
1905
+ }
1906
+ }
1907
+ */
1908
+ return;
1909
+ }
1910
+ }
1911
+ else {
1912
+ throw new UnexpectedError("".concat(name, " is unknown"));
1913
+ }
1914
+ }
1915
+ /**
1916
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1917
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1918
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1919
+ */
1920
+
1921
+ /**
1922
+ * @@@
1923
+ * @@@
1924
+ *
1925
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1926
+ *
1927
+ * @param name - Name of the object for debugging purposes
1928
+ * @param objectValue - Object to be deeply frozen
1929
+ * @returns The same object as the input, but deeply frozen
1930
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
1931
+ */
1932
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
1933
+ checkSerializableAsJson(name, objectValue);
1934
+ return $deepFreeze(objectValue);
1935
+ }
1936
+ /**
1937
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1938
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1939
+ */
1940
+
1902
1941
  /**
1903
1942
  * Unprepare just strips the preparation data of the pipeline
1904
1943
  *
@@ -1952,7 +1991,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1952
1991
  var pipeline = pipelines_1_1.value;
1953
1992
  // TODO: [👠] DRY
1954
1993
  if (pipeline.pipelineUrl === undefined) {
1955
- throw new PipelineUrlError(spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1994
+ throw new PipelineUrlError(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1956
1995
  }
1957
1996
  // Note: [🐨]
1958
1997
  validatePipeline(pipeline);
@@ -1964,7 +2003,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1964
2003
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1965
2004
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1966
2005
  var existing = this.collection.get(pipeline.pipelineUrl);
1967
- throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
2006
+ throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1968
2007
  }
1969
2008
  // Note: [🧠] Overwrite existing pipeline with the same URL
1970
2009
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1994,9 +2033,9 @@ var SimplePipelineCollection = /** @class */ (function () {
1994
2033
  var pipeline = this.collection.get(url);
1995
2034
  if (!pipeline) {
1996
2035
  if (this.listPipelines().length === 0) {
1997
- throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
2036
+ throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1998
2037
  }
1999
- throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
2038
+ throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
2000
2039
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
2001
2040
  .join('\n')), "\n\n "); }));
2002
2041
  }
@@ -2156,7 +2195,7 @@ var LimitReachedError = /** @class */ (function (_super) {
2156
2195
  var NotYetImplementedError = /** @class */ (function (_super) {
2157
2196
  __extends(NotYetImplementedError, _super);
2158
2197
  function NotYetImplementedError(message) {
2159
- var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
2198
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
2160
2199
  _this.name = 'NotYetImplementedError';
2161
2200
  Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
2162
2201
  return _this;
@@ -2252,10 +2291,10 @@ function assertsExecutionSuccessful(executionResult) {
2252
2291
  throw deserializeError(errors[0]);
2253
2292
  }
2254
2293
  else {
2255
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
2294
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
2256
2295
  .map(function (_a, index) {
2257
2296
  var name = _a.name, stack = _a.stack, message = _a.message;
2258
- return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
2297
+ return spaceTrim$1(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
2259
2298
  })
2260
2299
  .join('\n')), "\n "); }));
2261
2300
  }
@@ -2305,7 +2344,7 @@ function isPipelinePrepared(pipeline) {
2305
2344
  function serializeError(error) {
2306
2345
  var name = error.name, message = error.message, stack = error.stack;
2307
2346
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2308
- console.error(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2347
+ console.error(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2309
2348
  }
2310
2349
  return {
2311
2350
  name: name,
@@ -2324,6 +2363,7 @@ function serializeError(error) {
2324
2363
  */
2325
2364
  function extractVariablesFromScript(script) {
2326
2365
  var variables = new Set();
2366
+ var originalScript = script;
2327
2367
  script = "(()=>{".concat(script, "})()");
2328
2368
  try {
2329
2369
  for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
@@ -2334,20 +2374,32 @@ function extractVariablesFromScript(script) {
2334
2374
  if (!(error instanceof ReferenceError)) {
2335
2375
  throw error;
2336
2376
  }
2337
- var undefinedName = error.message.split(' ')[0];
2338
2377
  /*
2339
2378
  Note: Parsing the error
2379
+ 🌟 Most devices:
2340
2380
  [PipelineUrlError: thing is not defined]
2381
+
2382
+ 🍏 iPhone`s Safari:
2383
+ [PipelineUrlError: Can't find variable: thing]
2341
2384
  */
2342
- if (!undefinedName) {
2385
+ var variableName = undefined;
2386
+ if (error.message.startsWith("Can't")) {
2387
+ // 🍏 Case
2388
+ variableName = error.message.split(' ').pop();
2389
+ }
2390
+ else {
2391
+ // 🌟 Case
2392
+ variableName = error.message.split(' ').shift();
2393
+ }
2394
+ if (variableName === undefined) {
2343
2395
  throw error;
2344
2396
  }
2345
- if (script.includes(undefinedName + '(')) {
2346
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
2397
+ if (script.includes(variableName + '(')) {
2398
+ script = "const ".concat(variableName, " = ()=>'';") + script;
2347
2399
  }
2348
2400
  else {
2349
- variables.add(undefinedName);
2350
- script = "const ".concat(undefinedName, " = '';") + script;
2401
+ variables.add(variableName);
2402
+ script = "const ".concat(variableName, " = '';") + script;
2351
2403
  }
2352
2404
  }
2353
2405
  }
@@ -2355,7 +2407,9 @@ function extractVariablesFromScript(script) {
2355
2407
  if (!(error instanceof Error)) {
2356
2408
  throw error;
2357
2409
  }
2358
- throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2410
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
2411
+ .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
2412
+ .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
2359
2413
  }
2360
2414
  return variables;
2361
2415
  }
@@ -2559,7 +2613,7 @@ var CsvFormatDefinition = {
2559
2613
  case 0:
2560
2614
  csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
2561
2615
  if (csv.errors.length !== 0) {
2562
- throw new CsvFormatError(spaceTrim$1(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
2616
+ throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
2563
2617
  }
2564
2618
  return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
2565
2619
  var _a, _b;
@@ -2597,7 +2651,7 @@ var CsvFormatDefinition = {
2597
2651
  case 0:
2598
2652
  csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
2599
2653
  if (csv.errors.length !== 0) {
2600
- throw new CsvFormatError(spaceTrim$1(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
2654
+ throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
2601
2655
  }
2602
2656
  return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
2603
2657
  var _this = this;
@@ -2838,7 +2892,7 @@ function mapAvailableToExpectedParameters(options) {
2838
2892
  }
2839
2893
  // Phase 2️⃣: Non-matching mapping
2840
2894
  if (expectedParameterNames.size !== availableParametersNames.size) {
2841
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
2895
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
2842
2896
  .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
2843
2897
  .join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
2844
2898
  .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
@@ -3512,14 +3566,14 @@ function executeAttempts(options) {
3512
3566
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3513
3567
  // TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
3514
3568
  if (isJokerAttempt && !jokerParameterName) {
3515
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3569
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3516
3570
  }
3517
3571
  $ongoingTaskResult.$result = null;
3518
3572
  $ongoingTaskResult.$resultString = null;
3519
3573
  $ongoingTaskResult.$expectError = null;
3520
3574
  if (isJokerAttempt) {
3521
3575
  if (parameters[jokerParameterName] === undefined) {
3522
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3576
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3523
3577
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3524
3578
  }
3525
3579
  else {
@@ -3588,15 +3642,15 @@ function executeAttempts(options) {
3588
3642
  $ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
3589
3643
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
3590
3644
  return [3 /*break*/, 10];
3591
- case 8: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
3592
- case 9: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3645
+ case 8: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
3646
+ case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3593
3647
  case 10: return [3 /*break*/, 25];
3594
3648
  case 11:
3595
3649
  if (arrayableToArray(tools.script).length === 0) {
3596
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3650
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3597
3651
  }
3598
3652
  if (!task.contentLanguage) {
3599
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3653
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3600
3654
  }
3601
3655
  _t.label = 12;
3602
3656
  case 12:
@@ -3650,13 +3704,13 @@ function executeAttempts(options) {
3650
3704
  throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
3651
3705
  }
3652
3706
  else {
3653
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
3707
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
3654
3708
  .map(function (error) { return '- ' + error.message; })
3655
3709
  .join('\n\n')), "\n "); }));
3656
3710
  }
3657
3711
  case 22:
3658
3712
  if (tools.userInterface === undefined) {
3659
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3713
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3660
3714
  }
3661
3715
  // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
3662
3716
  _j = $ongoingTaskResult;
@@ -3672,7 +3726,7 @@ function executeAttempts(options) {
3672
3726
  // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
3673
3727
  _j.$resultString = _t.sent();
3674
3728
  return [3 /*break*/, 25];
3675
- case 24: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3729
+ case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3676
3730
  case 25:
3677
3731
  if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
3678
3732
  _t.label = 26;
@@ -3762,13 +3816,13 @@ function executeAttempts(options) {
3762
3816
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
3763
3817
  }
3764
3818
  catch (error) {
3765
- throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3819
+ throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3766
3820
  /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3767
3821
  }
3768
3822
  }
3769
3823
  }
3770
3824
  else {
3771
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3825
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3772
3826
  }
3773
3827
  }
3774
3828
  // TODO: [💝] Unite object for expecting amount and format
@@ -3802,7 +3856,7 @@ function executeAttempts(options) {
3802
3856
  return [7 /*endfinally*/];
3803
3857
  case 45:
3804
3858
  if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
3805
- throw new PipelineExecutionError(spaceTrim(function (block) {
3859
+ throw new PipelineExecutionError(spaceTrim$1(function (block) {
3806
3860
  var _a, _b, _c;
3807
3861
  return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
3808
3862
  .split('\n')
@@ -3838,7 +3892,7 @@ function executeAttempts(options) {
3838
3892
  return [3 /*break*/, 1];
3839
3893
  case 4:
3840
3894
  if ($ongoingTaskResult.$resultString === null) {
3841
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3895
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3842
3896
  }
3843
3897
  return [2 /*return*/, $ongoingTaskResult.$resultString];
3844
3898
  }
@@ -3866,7 +3920,7 @@ function executeFormatSubvalues(options) {
3866
3920
  return [2 /*return*/, /* not await */ executeAttempts(options)];
3867
3921
  }
3868
3922
  if (jokerParameterNames.length !== 0) {
3869
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
3923
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
3870
3924
  }
3871
3925
  parameterValue = parameters[task.foreach.parameterName] || '';
3872
3926
  formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
@@ -3875,7 +3929,7 @@ function executeFormatSubvalues(options) {
3875
3929
  if (formatDefinition === undefined) {
3876
3930
  throw new UnexpectedError(
3877
3931
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
3878
- spaceTrim$1(function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
3932
+ spaceTrim(function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
3879
3933
  .map(function (formatName) { return "- ".concat(formatName); })
3880
3934
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
3881
3935
  }
@@ -3885,7 +3939,7 @@ function executeFormatSubvalues(options) {
3885
3939
  if (subvalueDefinition === undefined) {
3886
3940
  throw new UnexpectedError(
3887
3941
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
3888
- spaceTrim$1(function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
3942
+ spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
3889
3943
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
3890
3944
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
3891
3945
  .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -3911,12 +3965,12 @@ function executeFormatSubvalues(options) {
3911
3965
  if (!(error instanceof PipelineExecutionError)) {
3912
3966
  throw error;
3913
3967
  }
3914
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
3968
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
3915
3969
  }
3916
3970
  allSubparameters = __assign(__assign({}, parameters), mappedParameters);
3917
3971
  // Note: [👨‍👨‍👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
3918
3972
  Object.freeze(allSubparameters);
3919
- return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
3973
+ return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
3920
3974
  case 1:
3921
3975
  subresultString = _a.sent();
3922
3976
  return [2 /*return*/, subresultString];
@@ -4009,7 +4063,7 @@ function getReservedParametersForTask(options) {
4009
4063
  };
4010
4064
  _loop_1 = function (parameterName) {
4011
4065
  if (reservedParameters[parameterName] === undefined) {
4012
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
4066
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
4013
4067
  }
4014
4068
  };
4015
4069
  try {
@@ -4064,7 +4118,7 @@ function executeTask(options) {
4064
4118
  dependentParameterNames = new Set(currentTask.dependentParameterNames);
4065
4119
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
4066
4120
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
4067
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
4121
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
4068
4122
  .map(function (name) { return "{".concat(name, "}"); })
4069
4123
  .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
4070
4124
  .map(function (name) { return "{".concat(name, "}"); })
@@ -4092,7 +4146,7 @@ function executeTask(options) {
4092
4146
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
4093
4147
  // Houston, we have a problem
4094
4148
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
4095
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4149
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4096
4150
  }
4097
4151
  };
4098
4152
  try {
@@ -4178,7 +4232,7 @@ function filterJustOutputParameters(options) {
4178
4232
  var _loop_1 = function (parameter) {
4179
4233
  if (parametersToPass[parameter.name] === undefined) {
4180
4234
  // [4]
4181
- $warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
4235
+ $warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
4182
4236
  return "continue";
4183
4237
  }
4184
4238
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -4298,7 +4352,7 @@ function executePipeline(options) {
4298
4352
  return name === parameterName;
4299
4353
  });
4300
4354
  if (!(parameter === undefined)) return [3 /*break*/, 1];
4301
- warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
4355
+ warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
4302
4356
  return [3 /*break*/, 4];
4303
4357
  case 1:
4304
4358
  if (!(parameter.isInput === false)) return [3 /*break*/, 4];
@@ -4310,10 +4364,10 @@ function executePipeline(options) {
4310
4364
  // Note: Wait a short time to prevent race conditions
4311
4365
  _h.sent();
4312
4366
  _h.label = 3;
4313
- case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
4367
+ case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
4314
4368
  isSuccessful: false,
4315
4369
  errors: __spreadArray([
4316
- new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
4370
+ new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
4317
4371
  ], __read(errors), false).map(serializeError),
4318
4372
  warnings: warnings.map(serializeError),
4319
4373
  executionReport: executionReport,
@@ -4377,7 +4431,7 @@ function executePipeline(options) {
4377
4431
  case 0:
4378
4432
  if (loopLimit-- < 0) {
4379
4433
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
4380
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
4434
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
4381
4435
  }
4382
4436
  currentTask = unresovedTasks_1.find(function (task) {
4383
4437
  return task.dependentParameterNames.every(function (name) {
@@ -4387,7 +4441,7 @@ function executePipeline(options) {
4387
4441
  if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
4388
4442
  throw new UnexpectedError(
4389
4443
  // TODO: [🐎] DRY
4390
- spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
4444
+ spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
4391
4445
  .map(function (_a) {
4392
4446
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
4393
4447
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -4415,7 +4469,7 @@ function executePipeline(options) {
4415
4469
  unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
4416
4470
  work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
4417
4471
  if (isReturned) {
4418
- 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)
4472
+ 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)
4419
4473
  .split('\n')
4420
4474
  .map(function (line) { return "> ".concat(line); })
4421
4475
  .join('\n')), "\n "); }));
@@ -4423,7 +4477,7 @@ function executePipeline(options) {
4423
4477
  if (onProgress) {
4424
4478
  onProgress(progress);
4425
4479
  }
4426
- }, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
4480
+ }, $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 "); }) }))
4427
4481
  .then(function (newParametersToPass) {
4428
4482
  parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
4429
4483
  resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
@@ -4545,7 +4599,7 @@ function createPipelineExecutor(options) {
4545
4599
  preparedPipeline = pipeline;
4546
4600
  }
4547
4601
  else if (isNotPreparedWarningSupressed !== true) {
4548
- 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 "); }));
4602
+ 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 "); }));
4549
4603
  }
4550
4604
  var runCount = 0;
4551
4605
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
@@ -4560,7 +4614,7 @@ function createPipelineExecutor(options) {
4560
4614
  inputParameters: inputParameters,
4561
4615
  tools: tools,
4562
4616
  onProgress: onProgress,
4563
- pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
4617
+ pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
4564
4618
  maxExecutionAttempts: maxExecutionAttempts,
4565
4619
  maxParallelCount: maxParallelCount,
4566
4620
  csvSettings: csvSettings,
@@ -4894,9 +4948,9 @@ function $registeredScrapersMessage(availableScrapers) {
4894
4948
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
4895
4949
  });
4896
4950
  if (metadata.length === 0) {
4897
- return spaceTrim$1("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
4951
+ return spaceTrim("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
4898
4952
  }
4899
- return spaceTrim$1(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
4953
+ return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
4900
4954
  .map(function (_a, i) {
4901
4955
  var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
4902
4956
  var more = [];
@@ -5174,7 +5228,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5174
5228
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5175
5229
  case 3:
5176
5230
  if (!(_e.sent())) {
5177
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5231
+ throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5178
5232
  }
5179
5233
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5180
5234
  return [2 /*return*/, {
@@ -5287,7 +5341,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5287
5341
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
5288
5342
  return [2 /*return*/, "break"];
5289
5343
  }
5290
- console.warn(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n \n The source:\n > ").concat(block(knowledgeSource.sourceContent
5344
+ console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n \n The source:\n > ").concat(block(knowledgeSource.sourceContent
5291
5345
  .split('\n')
5292
5346
  .map(function (line) { return "> ".concat(line); })
5293
5347
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -5325,7 +5379,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5325
5379
  return [7 /*endfinally*/];
5326
5380
  case 9:
5327
5381
  if (partialPieces === null) {
5328
- throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
5382
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
5329
5383
  .split('\n')
5330
5384
  .map(function (line) { return "> ".concat(line); })
5331
5385
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -5424,7 +5478,7 @@ function prepareTasks(pipeline, tools, options) {
5424
5478
  dependentParameterNames = task.dependentParameterNames;
5425
5479
  preparedContent = undefined;
5426
5480
  if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
5427
- preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
5481
+ preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
5428
5482
  // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
5429
5483
  dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
5430
5484
  'knowledge',
@@ -5623,7 +5677,7 @@ var knowledgeCommandParser = {
5623
5677
  */
5624
5678
  parse: function (input) {
5625
5679
  var args = input.args;
5626
- var sourceContent = spaceTrim$1(args[0] || '');
5680
+ var sourceContent = spaceTrim(args[0] || '');
5627
5681
  if (sourceContent === '') {
5628
5682
  throw new ParseError("Source is not defined");
5629
5683
  }
@@ -5767,7 +5821,7 @@ var sectionCommandParser = {
5767
5821
  return normalized.includes(sectionType.split('_TASK').join(''));
5768
5822
  });
5769
5823
  if (taskTypes.length !== 1) {
5770
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unknown section type \"".concat(normalized, "\"\n\n Supported section types are:\n ").concat(block(SectionTypes.join(', ')), "\n "); }));
5824
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown section type \"".concat(normalized, "\"\n\n Supported section types are:\n ").concat(block(SectionTypes.join(', ')), "\n "); }));
5771
5825
  }
5772
5826
  var taskType = taskTypes[0];
5773
5827
  return {
@@ -5782,10 +5836,10 @@ var sectionCommandParser = {
5782
5836
  */
5783
5837
  $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
5784
5838
  if ($taskJson.isSectionTypeSet === true) {
5785
- throw new ParseError(spaceTrim$1("\n Section type is already defined in the section.\n It can be defined only once.\n "));
5839
+ throw new ParseError(spaceTrim("\n Section type is already defined in the section.\n It can be defined only once.\n "));
5786
5840
  }
5787
5841
  $taskJson.isSectionTypeSet = true;
5788
- // TODO: [🍧] Rearrange better - but at bottom and unwrap from function
5842
+ // TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
5789
5843
  var expectResultingParameterName = function () {
5790
5844
  if ($taskJson.resultingParameterName) {
5791
5845
  return;
@@ -6124,7 +6178,7 @@ var expectCommandParser = {
6124
6178
  /**
6125
6179
  * Description of the FORMAT command
6126
6180
  */
6127
- description: spaceTrim$1("\n Expect command describes the desired output of the task *(after post-processing)*\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6181
+ description: spaceTrim("\n Expect command describes the desired output of the task *(after post-processing)*\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6128
6182
  /**
6129
6183
  * Link to documentation
6130
6184
  */
@@ -6208,7 +6262,7 @@ var expectCommandParser = {
6208
6262
  if (!(error instanceof Error)) {
6209
6263
  throw error;
6210
6264
  }
6211
- throw new ParseError(spaceTrim$1(function (block) {
6265
+ throw new ParseError(spaceTrim(function (block) {
6212
6266
  return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
6213
6267
  }));
6214
6268
  }
@@ -6430,7 +6484,7 @@ function validateParameterName(parameterName) {
6430
6484
  if (!(error instanceof ParseError)) {
6431
6485
  throw error;
6432
6486
  }
6433
- throw new ParseError(spaceTrim$1(function (block) { return "\n ".concat(block(error.message), "\n\n Tried to validate parameter name:\n ").concat(block(rawParameterName), "\n "); }));
6487
+ throw new ParseError(spaceTrim(function (block) { return "\n ".concat(block(error.message), "\n\n Tried to validate parameter name:\n ").concat(block(rawParameterName), "\n "); }));
6434
6488
  }
6435
6489
  return parameterName;
6436
6490
  }
@@ -6488,7 +6542,7 @@ var foreachCommandParser = {
6488
6542
  return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
6489
6543
  });
6490
6544
  if (formatDefinition === undefined) {
6491
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unsupported format \"".concat(formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
6545
+ throw new ParseError(spaceTrim(function (block) { return "\n Unsupported format \"".concat(formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
6492
6546
  .map(function (formatName) { return "- ".concat(formatName); })
6493
6547
  .join('\n')), "\n "); }));
6494
6548
  // <- TODO: [🏢] List all supported format names
@@ -6497,7 +6551,7 @@ var foreachCommandParser = {
6497
6551
  return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
6498
6552
  });
6499
6553
  if (subvalueDefinition === undefined) {
6500
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
6554
+ throw new ParseError(spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
6501
6555
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
6502
6556
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
6503
6557
  .join('\n')), "\n "); }));
@@ -6540,7 +6594,7 @@ var foreachCommandParser = {
6540
6594
  outputSubparameterName = 'newLine';
6541
6595
  }
6542
6596
  else {
6543
- throw new ParseError(spaceTrim$1("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
6597
+ throw new ParseError(spaceTrim("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
6544
6598
  }
6545
6599
  }
6546
6600
  return {
@@ -6610,7 +6664,7 @@ var formatCommandParser = {
6610
6664
  /**
6611
6665
  * Description of the FORMAT command
6612
6666
  */
6613
- description: spaceTrim$1("\n Format command describes the desired output of the task (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6667
+ description: spaceTrim("\n Format command describes the desired output of the task (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6614
6668
  /**
6615
6669
  * Link to documentation
6616
6670
  */
@@ -6887,7 +6941,7 @@ var formfactorCommandParser = {
6887
6941
  return __spreadArray([definition.name], __read(__assign({ aliasNames: [] }, definition).aliasNames), false).includes(formfactorNameCandidate);
6888
6942
  });
6889
6943
  if (formfactor === undefined) {
6890
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unknown formfactor name \"".concat(formfactorNameCandidate, "\"\n\n Available formfactors:\n ").concat(block(FORMFACTOR_DEFINITIONS.map(function (_a) {
6944
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown formfactor name \"".concat(formfactorNameCandidate, "\"\n\n Available formfactors:\n ").concat(block(FORMFACTOR_DEFINITIONS.map(function (_a) {
6891
6945
  var name = _a.name;
6892
6946
  return "- ".concat(name);
6893
6947
  }).join('\n')), "\n "); }));
@@ -7038,7 +7092,7 @@ var modelCommandParser = {
7038
7092
  */
7039
7093
  parse: function (input) {
7040
7094
  var args = input.args, normalized = input.normalized;
7041
- var availableVariantsMessage = spaceTrim$1(function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
7095
+ var availableVariantsMessage = spaceTrim(function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
7042
7096
  return "- ".concat(variantName).concat(variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)');
7043
7097
  }).join('\n')), "\n "); });
7044
7098
  // TODO: Make this more elegant and dynamically
@@ -7059,10 +7113,10 @@ var modelCommandParser = {
7059
7113
  // <- Note: [🤖]
7060
7114
  }
7061
7115
  else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
7062
- spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
7116
+ spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
7063
7117
  }
7064
7118
  else {
7065
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
7119
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
7066
7120
  }
7067
7121
  }
7068
7122
  if (normalized.startsWith('MODEL_NAME')) {
@@ -7073,7 +7127,7 @@ var modelCommandParser = {
7073
7127
  };
7074
7128
  }
7075
7129
  else {
7076
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
7130
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
7077
7131
  }
7078
7132
  },
7079
7133
  /**
@@ -7087,10 +7141,10 @@ var modelCommandParser = {
7087
7141
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7088
7142
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7089
7143
  console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
7090
- // <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
7144
+ // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
7091
7145
  }
7092
7146
  else {
7093
- throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7147
+ throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7094
7148
  }
7095
7149
  }
7096
7150
  $pipelineJson.defaultModelRequirements[command.key] = command.value;
@@ -7115,11 +7169,11 @@ var modelCommandParser = {
7115
7169
  }[command.key], " ").concat(command.value, "` in the task \"").concat($taskJson.title || $taskJson.name, "\""));
7116
7170
  }
7117
7171
  else {
7118
- throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($taskJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7172
+ throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($taskJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7119
7173
  }
7120
7174
  }
7121
7175
  if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
7122
- console.log(spaceTrim$1("\n Setting MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the task:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7176
+ console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the task:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7123
7177
  }
7124
7178
  $taskJson.modelRequirements[command.key] = command.value;
7125
7179
  },
@@ -7194,7 +7248,7 @@ var parameterCommandParser = {
7194
7248
  // <- TODO: When [🥶] fixed, change to:
7195
7249
  // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
7196
7250
  if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
7197
- throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterNameRaw, "}` can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
7251
+ throw new ParseError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterNameRaw, "}` can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
7198
7252
  }
7199
7253
  var isInput = normalized.startsWith('INPUT');
7200
7254
  var isOutput = normalized.startsWith('OUTPUT');
@@ -7371,8 +7425,8 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7371
7425
  persona.description = personaDescription;
7372
7426
  return;
7373
7427
  }
7374
- console.warn(spaceTrim$1("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
7375
- persona.description += spaceTrim$1('\n\n' + personaDescription);
7428
+ console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
7429
+ persona.description += spaceTrim('\n\n' + personaDescription);
7376
7430
  }
7377
7431
 
7378
7432
  /**
@@ -7722,7 +7776,7 @@ var COMMANDS = [
7722
7776
  personaCommandParser,
7723
7777
  foreachCommandParser,
7724
7778
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
7725
- // <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
7779
+ // <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
7726
7780
  ];
7727
7781
  /**
7728
7782
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7739,7 +7793,7 @@ var COMMANDS = [
7739
7793
  function getParserForCommand(command) {
7740
7794
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
7741
7795
  if (commandParser === undefined) {
7742
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found\n\n ").concat(block(JSON.stringify(command, null, 4)
7796
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " parser is not found\n\n ").concat(block(JSON.stringify(command, null, 4)
7743
7797
  .split('\n')
7744
7798
  .map(function (line) { return "> ".concat(line); })
7745
7799
  .join('\n')), "\n "); }));
@@ -7811,7 +7865,7 @@ function parseCommand(raw, usagePlace) {
7811
7865
  .map(removeMarkdownFormatting)
7812
7866
  .map(function (item) { return item.trim(); });
7813
7867
  if (items.length === 0 || items[0] === '') {
7814
- throw new ParseError(spaceTrim(function (block) {
7868
+ throw new ParseError(spaceTrim$1(function (block) {
7815
7869
  return "\n Malformed command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
7816
7870
  }));
7817
7871
  }
@@ -7842,7 +7896,7 @@ function parseCommand(raw, usagePlace) {
7842
7896
  return command;
7843
7897
  }
7844
7898
  }
7845
- throw new ParseError(spaceTrim(function (block) {
7899
+ throw new ParseError(spaceTrim$1(function (block) {
7846
7900
  return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
7847
7901
  }));
7848
7902
  }
@@ -7884,7 +7938,7 @@ function parseCommandVariant(input) {
7884
7938
  if (!(error instanceof ParseError)) {
7885
7939
  throw error;
7886
7940
  }
7887
- throw new ParseError(spaceTrim(function (block) {
7941
+ throw new ParseError(spaceTrim$1(function (block) {
7888
7942
  return "\n Invalid ".concat(commandName, " command:\n\n Your command:\n - ").concat(raw, "\n\n The detailed error:\n ").concat(block(error.message), "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
7889
7943
  }));
7890
7944
  }
@@ -7975,7 +8029,7 @@ function extractAllListItemsFromMarkdown(markdown) {
7975
8029
  function extractOneBlockFromMarkdown(markdown) {
7976
8030
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
7977
8031
  if (codeBlocks.length !== 1) {
7978
- throw new ParseError(spaceTrim$1(function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
8032
+ throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
7979
8033
  }
7980
8034
  return codeBlocks[0];
7981
8035
  }
@@ -7996,7 +8050,7 @@ function parseMarkdownSection(value) {
7996
8050
  }
7997
8051
  var title = lines[0].replace(/^#+\s*/, '');
7998
8052
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
7999
- var content = spaceTrim$1(lines.slice(1).join('\n'));
8053
+ var content = spaceTrim(lines.slice(1).join('\n'));
8000
8054
  if (level < 1 || level > 6) {
8001
8055
  throw new ParseError('Markdown section must have heading level between 1 and 6');
8002
8056
  }
@@ -8025,7 +8079,7 @@ function splitMarkdownIntoSections(markdown) {
8025
8079
  if (buffer.length === 0) {
8026
8080
  return;
8027
8081
  }
8028
- var section = spaceTrim$1(buffer.join('\n'));
8082
+ var section = spaceTrim(buffer.join('\n'));
8029
8083
  if (section === '') {
8030
8084
  return;
8031
8085
  }
@@ -8121,7 +8175,7 @@ function flattenMarkdown(markdown) {
8121
8175
  }
8122
8176
  finally { if (e_1) throw e_1.error; }
8123
8177
  }
8124
- return spaceTrim$1(flattenedMarkdown);
8178
+ return spaceTrim(flattenedMarkdown);
8125
8179
  }
8126
8180
  /**
8127
8181
  * TODO: [🏛] This can be part of markdown builder
@@ -8139,7 +8193,7 @@ function flattenMarkdown(markdown) {
8139
8193
  * @public exported from `@promptbook/markdown-utils`
8140
8194
  */
8141
8195
  function removeContentComments(content) {
8142
- return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
8196
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
8143
8197
  }
8144
8198
 
8145
8199
  /**
@@ -8214,7 +8268,7 @@ function pipelineStringToJsonSync(pipelineString) {
8214
8268
  if (pipelineString.startsWith('#!')) {
8215
8269
  var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
8216
8270
  if (!(shebangLine_1 || '').includes('ptbk')) {
8217
- throw new ParseError(spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
8271
+ throw new ParseError(spaceTrim$1(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
8218
8272
  }
8219
8273
  pipelineString = restLines.join('\n');
8220
8274
  }
@@ -8224,27 +8278,27 @@ function pipelineStringToJsonSync(pipelineString) {
8224
8278
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
8225
8279
  var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
8226
8280
  if (pipelineHead === undefined) {
8227
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8281
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8228
8282
  }
8229
8283
  if (pipelineHead.level !== 1) {
8230
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8284
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8231
8285
  }
8232
8286
  if (!pipelineSections.every(function (section) { return section.level === 2; })) {
8233
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8287
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8234
8288
  }
8235
8289
  // =============================================================
8236
8290
  ///Note: 2️⃣ Function for defining parameters
8237
8291
  var defineParam = function (parameterCommand) {
8238
8292
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
8239
8293
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
8240
- throw new ParseError(spaceTrim(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
8294
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
8241
8295
  }
8242
8296
  var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
8243
8297
  if (existingParameter &&
8244
8298
  existingParameter.description &&
8245
8299
  existingParameter.description !== parameterDescription &&
8246
8300
  parameterDescription) {
8247
- throw new ParseError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
8301
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
8248
8302
  }
8249
8303
  if (existingParameter) {
8250
8304
  if (parameterDescription) {
@@ -8272,7 +8326,7 @@ function pipelineStringToJsonSync(pipelineString) {
8272
8326
  description = description.split(/^>.*$/gm).join('');
8273
8327
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
8274
8328
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
8275
- description = spaceTrim(description);
8329
+ description = spaceTrim$1(description);
8276
8330
  if (description === '') {
8277
8331
  description = undefined;
8278
8332
  }
@@ -8283,7 +8337,7 @@ function pipelineStringToJsonSync(pipelineString) {
8283
8337
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
8284
8338
  var commandParser = getParserForCommand(command);
8285
8339
  if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
8286
- throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8340
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8287
8341
  }
8288
8342
  try {
8289
8343
  commandParser.$applyToPipelineJson(command, $pipelineJson);
@@ -8293,7 +8347,7 @@ function pipelineStringToJsonSync(pipelineString) {
8293
8347
  if (!(error instanceof ParseError)) {
8294
8348
  throw error;
8295
8349
  }
8296
- throw new ParseError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8350
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8297
8351
  }
8298
8352
  if (command.type === 'PARAMETER') {
8299
8353
  defineParam(command);
@@ -8355,7 +8409,7 @@ function pipelineStringToJsonSync(pipelineString) {
8355
8409
  description_1 = description_1.split(/^>.*$/gm).join('');
8356
8410
  //Note: Remove lists and return statement - TODO: [🎾]
8357
8411
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
8358
- description_1 = spaceTrim(description_1);
8412
+ description_1 = spaceTrim$1(description_1);
8359
8413
  if (description_1 === '') {
8360
8414
  description_1 = undefined;
8361
8415
  }
@@ -8391,7 +8445,7 @@ function pipelineStringToJsonSync(pipelineString) {
8391
8445
  var _loop_4 = function (listItem, command) {
8392
8446
  var commandParser = getParserForCommand(command);
8393
8447
  if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
8394
- throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8448
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8395
8449
  }
8396
8450
  try {
8397
8451
  commandParser.$applyToTaskJson(
@@ -8402,7 +8456,7 @@ function pipelineStringToJsonSync(pipelineString) {
8402
8456
  if (!(error instanceof ParseError)) {
8403
8457
  throw error;
8404
8458
  }
8405
- throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8459
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8406
8460
  }
8407
8461
  if (command.type === 'PARAMETER') {
8408
8462
  defineParam(command);
@@ -8426,10 +8480,10 @@ function pipelineStringToJsonSync(pipelineString) {
8426
8480
  // TODO: [🍧] Should be done in SECTION command
8427
8481
  if ($taskJson.taskType === 'SCRIPT_TASK') {
8428
8482
  if (!language) {
8429
- throw new ParseError(spaceTrim(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
8483
+ throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
8430
8484
  }
8431
8485
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
8432
- throw new ParseError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
8486
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
8433
8487
  }
8434
8488
  $taskJson.contentLanguage = language;
8435
8489
  }
@@ -9103,7 +9157,7 @@ function $registeredLlmToolsMessage() {
9103
9157
  if (metadata.length === 0) {
9104
9158
  return "No LLM providers are available.";
9105
9159
  }
9106
- return spaceTrim$1(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9160
+ return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9107
9161
  .filter(function (envVariableName) {
9108
9162
  return metadata.some(function (_a) {
9109
9163
  var envVariables = _a.envVariables;
@@ -9147,7 +9201,7 @@ function $registeredLlmToolsMessage() {
9147
9201
  morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
9148
9202
  }
9149
9203
  }
9150
- var providerMessage = spaceTrim$1("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9204
+ var providerMessage = spaceTrim("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9151
9205
  if ($isRunningInNode) {
9152
9206
  if (isInstalled && isFullyConfigured) {
9153
9207
  providerMessage = colors.green(providerMessage);
@@ -9187,7 +9241,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
9187
9241
  return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
9188
9242
  });
9189
9243
  if (registeredItem === undefined) {
9190
- throw new Error(spaceTrim$1(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
9244
+ throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
9191
9245
  }
9192
9246
  return registeredItem(__assign({ isVerbose: isVerbose, userId: userId }, llmConfiguration.options));
9193
9247
  });
@@ -9226,7 +9280,7 @@ function $provideLlmToolsFromEnv(options) {
9226
9280
  var configuration = $provideLlmToolsConfigurationFromEnv();
9227
9281
  if (configuration.length === 0) {
9228
9282
  // TODO: [🥃]
9229
- throw new Error(spaceTrim$1(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
9283
+ throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
9230
9284
  }
9231
9285
  return createLlmToolsFromConfiguration(configuration, options);
9232
9286
  }
@@ -9401,13 +9455,13 @@ function parseKeywordsFromString(input) {
9401
9455
  * @public exported from `@promptbook/utils`
9402
9456
  */
9403
9457
  function trimCodeBlock(value) {
9404
- value = spaceTrim(value);
9458
+ value = spaceTrim$1(value);
9405
9459
  if (!/^```[a-z]*(.*)```$/is.test(value)) {
9406
9460
  return value;
9407
9461
  }
9408
9462
  value = value.replace(/^```[a-z]*/i, '');
9409
9463
  value = value.replace(/```$/i, '');
9410
- value = spaceTrim(value);
9464
+ value = spaceTrim$1(value);
9411
9465
  return value;
9412
9466
  }
9413
9467
 
@@ -9420,9 +9474,9 @@ function trimCodeBlock(value) {
9420
9474
  * @public exported from `@promptbook/utils`
9421
9475
  */
9422
9476
  function trimEndOfCodeBlock(value) {
9423
- value = spaceTrim(value);
9477
+ value = spaceTrim$1(value);
9424
9478
  value = value.replace(/```$/g, '');
9425
- value = spaceTrim(value);
9479
+ value = spaceTrim$1(value);
9426
9480
  return value;
9427
9481
  }
9428
9482
 
@@ -9444,7 +9498,7 @@ function unwrapResult(text, options) {
9444
9498
  var trimmedText = text;
9445
9499
  // Remove leading and trailing spaces and newlines
9446
9500
  if (isTrimmed) {
9447
- trimmedText = spaceTrim(trimmedText);
9501
+ trimmedText = spaceTrim$1(trimmedText);
9448
9502
  }
9449
9503
  var processedText = trimmedText;
9450
9504
  if (isIntroduceSentenceRemoved) {
@@ -9453,7 +9507,7 @@ function unwrapResult(text, options) {
9453
9507
  // Remove the introduce sentence and quotes by replacing it with an empty string
9454
9508
  processedText = processedText.replace(introduceSentenceRegex, '');
9455
9509
  }
9456
- processedText = spaceTrim(processedText);
9510
+ processedText = spaceTrim$1(processedText);
9457
9511
  }
9458
9512
  if (processedText.length < 3) {
9459
9513
  return trimmedText;
@@ -9513,10 +9567,10 @@ function preserve(func) {
9513
9567
  return __generator(this, function (_a) {
9514
9568
  switch (_a.label) {
9515
9569
  case 0:
9516
- // TODO: Change to `await forEver` or something better
9570
+ // TODO: [💩] Change to `await forEver` or something better
9517
9571
  return [4 /*yield*/, forTime(100000000)];
9518
9572
  case 1:
9519
- // TODO: Change to `await forEver` or something better
9573
+ // TODO: [💩] Change to `await forEver` or something better
9520
9574
  _a.sent();
9521
9575
  _a.label = 2;
9522
9576
  case 2:
@@ -9580,7 +9634,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
9580
9634
  */
9581
9635
  JavascriptEvalExecutionTools.prototype.execute = function (options) {
9582
9636
  return __awaiter(this, void 0, void 0, function () {
9583
- var scriptLanguage, parameters, script, spaceTrim, removeQuotes$1, unwrapResult$1, trimEndOfCodeBlock$1, trimCodeBlock$1, trim, reverse, removeEmojis$1, prettifyMarkdown$1, capitalize$1, decapitalize$1, nameToUriPart$1, nameToUriParts$1, removeDiacritics$1, normalizeWhitespaces$1, normalizeToKebabCase$1, normalizeTo_camelCase$1, normalizeTo_snake_case$1, normalizeTo_PascalCase$1, parseKeywords, normalizeTo_SCREAMING_CASE$1, buildinFunctions, buildinFunctionsStatement, customFunctions, customFunctionsStatement, statementToEvaluate, result, error_1, undefinedName_1;
9637
+ var scriptLanguage, parameters, script, spaceTrim$1, removeQuotes$1, unwrapResult$1, trimEndOfCodeBlock$1, trimCodeBlock$1, trim, reverse, removeEmojis$1, prettifyMarkdown$1, capitalize$1, decapitalize$1, nameToUriPart$1, nameToUriParts$1, removeDiacritics$1, normalizeWhitespaces$1, normalizeToKebabCase$1, normalizeTo_camelCase$1, normalizeTo_snake_case$1, normalizeTo_PascalCase$1, parseKeywords, normalizeTo_SCREAMING_CASE$1, buildinFunctions, buildinFunctionsStatement, customFunctions, customFunctionsStatement, statementToEvaluate, result, error_1, undefinedName_1;
9584
9638
  return __generator(this, function (_a) {
9585
9639
  switch (_a.label) {
9586
9640
  case 0:
@@ -9589,8 +9643,8 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
9589
9643
  if (scriptLanguage !== 'javascript') {
9590
9644
  throw new PipelineExecutionError("Script language ".concat(scriptLanguage, " not supported to be executed by JavascriptEvalExecutionTools"));
9591
9645
  }
9592
- spaceTrim = function (_) { return spaceTrim$1(_); };
9593
- preserve(spaceTrim);
9646
+ spaceTrim$1 = function (_) { return spaceTrim(_); };
9647
+ preserve(spaceTrim$1);
9594
9648
  removeQuotes$1 = removeQuotes;
9595
9649
  preserve(removeQuotes$1);
9596
9650
  unwrapResult$1 = unwrapResult;
@@ -9640,7 +9694,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
9640
9694
  }
9641
9695
  buildinFunctions = {
9642
9696
  // TODO: [🍯] DRY all these functions across the file
9643
- spaceTrim: spaceTrim,
9697
+ spaceTrim: spaceTrim$1,
9644
9698
  removeQuotes: removeQuotes$1,
9645
9699
  unwrapResult: unwrapResult$1,
9646
9700
  trimEndOfCodeBlock: trimEndOfCodeBlock$1,
@@ -9676,14 +9730,14 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
9676
9730
  return "const ".concat(functionName, " = customFunctions.").concat(functionName, ";");
9677
9731
  })
9678
9732
  .join('\n');
9679
- statementToEvaluate = spaceTrim$1(function (block) { return "\n\n // Build-in functions:\n ".concat(block(buildinFunctionsStatement), "\n\n // Custom functions:\n ").concat(block(customFunctionsStatement || '// -- No custom functions --'), "\n\n // The script:\n ").concat(block(Object.entries(parameters)
9733
+ statementToEvaluate = spaceTrim(function (block) { return "\n\n // Build-in functions:\n ".concat(block(buildinFunctionsStatement), "\n\n // Custom functions:\n ").concat(block(customFunctionsStatement || '// -- No custom functions --'), "\n\n // The script:\n ").concat(block(Object.entries(parameters)
9680
9734
  .map(function (_a) {
9681
9735
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
9682
9736
  return "const ".concat(key, " = ").concat(JSON.stringify(value), ";");
9683
9737
  })
9684
9738
  .join('\n')), "\n (()=>{ ").concat(script, " })()\n "); });
9685
9739
  if (this.options.isVerbose) {
9686
- console.info(spaceTrim$1(function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
9740
+ console.info(spaceTrim(function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
9687
9741
  }
9688
9742
  _a.label = 1;
9689
9743
  case 1:
@@ -9708,12 +9762,12 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
9708
9762
  To: [PipelineExecutionError: Parameter `{thing}` is not defined],
9709
9763
  */
9710
9764
  if (!statementToEvaluate.includes(undefinedName_1 + '(')) {
9711
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n\n Parameter `{".concat(undefinedName_1, "}` is not defined\n\n This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:\n\n ").concat(block(Object.keys(parameters)
9765
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n\n Parameter `{".concat(undefinedName_1, "}` is not defined\n\n This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:\n\n ").concat(block(Object.keys(parameters)
9712
9766
  .map(function (key) { return " - ".concat(key, "\n"); })
9713
9767
  .join('')), "\n\n The script is:\n ```javascript\n ").concat(block(script), "\n ```\n\n Original error message:\n ").concat(block(error_1.message), "\n\n\n "); }));
9714
9768
  }
9715
9769
  else {
9716
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Function ".concat(undefinedName_1, "() is not defined\n\n - Make sure that the function is one of built-in functions\n - Or you have to defined the function during construction of JavascriptEvalExecutionTools\n\n Original error message:\n ").concat(block(error_1.message), "\n\n "); }));
9770
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Function ".concat(undefinedName_1, "() is not defined\n\n - Make sure that the function is one of built-in functions\n - Or you have to defined the function during construction of JavascriptEvalExecutionTools\n\n Original error message:\n ").concat(block(error_1.message), "\n\n "); }));
9717
9771
  }
9718
9772
  }
9719
9773
  throw error_1;
@@ -10116,7 +10170,7 @@ function createCollectionFromDirectory(path, tools, options) {
10116
10170
  }
10117
10171
  else {
10118
10172
  existing = collection.get(pipeline.pipelineUrl);
10119
- throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
10173
+ throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
10120
10174
  }
10121
10175
  }
10122
10176
  }
@@ -10126,7 +10180,7 @@ function createCollectionFromDirectory(path, tools, options) {
10126
10180
  if (!(error_1 instanceof Error)) {
10127
10181
  throw error_1;
10128
10182
  }
10129
- wrappedErrorMessage = spaceTrim$1(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
10183
+ wrappedErrorMessage = spaceTrim(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
10130
10184
  if (isCrashedOnError) {
10131
10185
  throw new CollectionError(wrappedErrorMessage);
10132
10186
  }
@@ -10225,7 +10279,7 @@ function isSerializableAsJson(value) {
10225
10279
  */
10226
10280
  function stringifyPipelineJson(pipeline) {
10227
10281
  if (!isSerializableAsJson(pipeline)) {
10228
- throw new UnexpectedError(spaceTrim$1("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
10282
+ throw new UnexpectedError(spaceTrim("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
10229
10283
  }
10230
10284
  var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
10231
10285
  for (var i = 0; i < LOOP_LIMIT; i++) {
@@ -10478,11 +10532,11 @@ function $execCommand(options) {
10478
10532
  if (isVerbose) {
10479
10533
  console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
10480
10534
  }
10481
- resolve(spaceTrim(output_1.join('\n')));
10535
+ resolve(spaceTrim$1(output_1.join('\n')));
10482
10536
  }
10483
10537
  }
10484
10538
  else {
10485
- resolve(spaceTrim(output_1.join('\n')));
10539
+ resolve(spaceTrim$1(output_1.join('\n')));
10486
10540
  }
10487
10541
  };
10488
10542
  commandProcess.on('close', finishWithCode);
@@ -10499,7 +10553,7 @@ function $execCommand(options) {
10499
10553
  if (isVerbose) {
10500
10554
  console.warn(error);
10501
10555
  }
10502
- resolve(spaceTrim(output_1.join('\n')));
10556
+ resolve(spaceTrim$1(output_1.join('\n')));
10503
10557
  }
10504
10558
  });
10505
10559
  }