@promptbook/cli 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,6 +1,6 @@
1
1
  import colors from 'colors';
2
2
  import commander from 'commander';
3
- import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
+ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
4
4
  import { forTime } from 'waitasecond';
5
5
  import { basename, join, dirname } from 'path';
6
6
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
37
37
  *
38
38
  * @see https://github.com/webgptorg/promptbook
39
39
  */
40
- var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
40
+ var PROMPTBOOK_ENGINE_VERSION = '0.78.2';
41
41
  /**
42
42
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
43
43
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -183,204 +183,31 @@ function just(value) {
183
183
  }
184
184
 
185
185
  /**
186
- * @@@
187
- *
188
- * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
189
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
190
- *
191
- * @returns The same object as the input, but deeply frozen
192
- * @public exported from `@promptbook/utils`
193
- */
194
- function $deepFreeze(objectValue) {
195
- var e_1, _a;
196
- var propertyNames = Object.getOwnPropertyNames(objectValue);
197
- try {
198
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
199
- var propertyName = propertyNames_1_1.value;
200
- var value = objectValue[propertyName];
201
- if (value && typeof value === 'object') {
202
- $deepFreeze(value);
203
- }
204
- }
205
- }
206
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
207
- finally {
208
- try {
209
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
210
- }
211
- finally { if (e_1) throw e_1.error; }
212
- }
213
- return Object.freeze(objectValue);
214
- }
215
- /**
216
- * TODO: [🧠] Is there a way how to meaningfully test this utility
217
- */
218
-
219
- /**
220
- * This error type indicates that the error should not happen and its last check before crashing with some other error
186
+ * Warning message for the generated sections and files files
221
187
  *
222
- * @public exported from `@promptbook/core`
188
+ * @private within the repository
223
189
  */
224
- var UnexpectedError = /** @class */ (function (_super) {
225
- __extends(UnexpectedError, _super);
226
- function UnexpectedError(message) {
227
- 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;
228
- _this.name = 'UnexpectedError';
229
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
230
- return _this;
231
- }
232
- return UnexpectedError;
233
- }(Error));
234
-
190
+ var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
235
191
  /**
236
- * Checks if the value is [🚉] serializable as JSON
237
- * If not, throws an UnexpectedError with a rich error message and tracking
192
+ * Name for the Promptbook
238
193
  *
239
- * - Almost all primitives are serializable BUT:
240
- * - `undefined` is not serializable
241
- * - `NaN` is not serializable
242
- * - Objects and arrays are serializable if all their properties are serializable
243
- * - Functions are not serializable
244
- * - Circular references are not serializable
245
- * - `Date` objects are not serializable
246
- * - `Map` and `Set` objects are not serializable
247
- * - `RegExp` objects are not serializable
248
- * - `Error` objects are not serializable
249
- * - `Symbol` objects are not serializable
250
- * - And much more...
194
+ * TODO: [🗽] Unite branding and make single place for it
251
195
  *
252
- * @throws UnexpectedError if the value is not serializable as JSON
253
- * @public exported from `@promptbook/utils`
254
- */
255
- function checkSerializableAsJson(name, value) {
256
- var e_1, _a;
257
- if (value === undefined) {
258
- throw new UnexpectedError("".concat(name, " is undefined"));
259
- }
260
- else if (value === null) {
261
- return;
262
- }
263
- else if (typeof value === 'boolean') {
264
- return;
265
- }
266
- else if (typeof value === 'number' && !isNaN(value)) {
267
- return;
268
- }
269
- else if (typeof value === 'string') {
270
- return;
271
- }
272
- else if (typeof value === 'symbol') {
273
- throw new UnexpectedError("".concat(name, " is symbol"));
274
- }
275
- else if (typeof value === 'function') {
276
- throw new UnexpectedError("".concat(name, " is function"));
277
- }
278
- else if (typeof value === 'object' && Array.isArray(value)) {
279
- for (var i = 0; i < value.length; i++) {
280
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
281
- }
282
- }
283
- else if (typeof value === 'object') {
284
- if (value instanceof Date) {
285
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
286
- }
287
- else if (value instanceof Map) {
288
- throw new UnexpectedError("".concat(name, " is Map"));
289
- }
290
- else if (value instanceof Set) {
291
- throw new UnexpectedError("".concat(name, " is Set"));
292
- }
293
- else if (value instanceof RegExp) {
294
- throw new UnexpectedError("".concat(name, " is RegExp"));
295
- }
296
- else if (value instanceof Error) {
297
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
298
- }
299
- else {
300
- try {
301
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
302
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
303
- if (subValue === undefined) {
304
- // Note: undefined in object is serializable - it is just omited
305
- continue;
306
- }
307
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
308
- }
309
- }
310
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
311
- finally {
312
- try {
313
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
314
- }
315
- finally { if (e_1) throw e_1.error; }
316
- }
317
- try {
318
- JSON.stringify(value); // <- TODO: [0]
319
- }
320
- catch (error) {
321
- if (!(error instanceof Error)) {
322
- throw error;
323
- }
324
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
325
- }
326
- /*
327
- TODO: [0] Is there some more elegant way to check circular references?
328
- const seen = new Set();
329
- const stack = [{ value }];
330
- while (stack.length > 0) {
331
- const { value } = stack.pop()!;
332
- if (typeof value === 'object' && value !== null) {
333
- if (seen.has(value)) {
334
- throw new UnexpectedError(`${name} has circular reference`);
335
- }
336
- seen.add(value);
337
- if (Array.isArray(value)) {
338
- stack.push(...value.map((value) => ({ value })));
339
- } else {
340
- stack.push(...Object.values(value).map((value) => ({ value })));
341
- }
342
- }
343
- }
344
- */
345
- return;
346
- }
347
- }
348
- else {
349
- throw new UnexpectedError("".concat(name, " is unknown"));
350
- }
351
- }
352
- /**
353
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
354
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
355
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
196
+ * @public exported from `@promptbook/core`
356
197
  */
357
-
198
+ var NAME = "Promptbook";
358
199
  /**
359
- * @@@
360
- * @@@
361
- *
362
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
200
+ * Email of the responsible person
363
201
  *
364
- * @param name - Name of the object for debugging purposes
365
- * @param objectValue - Object to be deeply frozen
366
- * @returns The same object as the input, but deeply frozen
367
- * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
368
- */
369
- function $asDeeplyFrozenSerializableJson(name, objectValue) {
370
- checkSerializableAsJson(name, objectValue);
371
- return $deepFreeze(objectValue);
372
- }
373
- /**
374
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
375
- * TODO: [🧠] Is there a way how to meaningfully test this utility
202
+ * @public exported from `@promptbook/core`
376
203
  */
377
-
204
+ var ADMIN_EMAIL = 'me@pavolhejny.com';
378
205
  /**
379
- * Warning message for the generated sections and files files
206
+ * Name of the responsible person for the Promptbook on GitHub
380
207
  *
381
- * @private within the repository
208
+ * @public exported from `@promptbook/core`
382
209
  */
383
- var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
210
+ var ADMIN_GITHUB_NAME = 'hejny';
384
211
  /**
385
212
  * Claim for the Promptbook
386
213
  *
@@ -492,7 +319,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
492
319
  *
493
320
  * @public exported from `@promptbook/core`
494
321
  */
495
- var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
322
+ var RESERVED_PARAMETER_NAMES =
323
+ /* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
496
324
  'content',
497
325
  'context',
498
326
  'knowledge',
@@ -502,7 +330,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
502
330
  // <- TODO: list here all command names
503
331
  // <- TODO: Add more like 'date', 'modelName',...
504
332
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
505
- ]);
333
+ ];
506
334
  /**
507
335
  * @@@
508
336
  *
@@ -608,7 +436,7 @@ var $isRunningInNode = new Function("\n try {\n return this === global
608
436
  function initializeAboutCommand(program) {
609
437
  var _this = this;
610
438
  var makeCommand = program.command('about');
611
- makeCommand.description(spaceTrim$1("\n Tells about Promptbook CLI and its abilities\n "));
439
+ makeCommand.description(spaceTrim("\n Tells about Promptbook CLI and its abilities\n "));
612
440
  makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
613
441
  return __generator(this, function (_a) {
614
442
  console.info(colors.bold(colors.cyan("Promptbook: ".concat(CLAIM))));
@@ -634,7 +462,7 @@ function initializeAboutCommand(program) {
634
462
  function initializeHelloCommand(program) {
635
463
  var _this = this;
636
464
  var helloCommand = program.command('hello');
637
- helloCommand.description(spaceTrim$1("\n Just command for testing\n "));
465
+ helloCommand.description(spaceTrim("\n Just command for testing\n "));
638
466
  helloCommand.argument('[name]', 'Your name', 'Paul');
639
467
  helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
640
468
  helloCommand.action(function (name, _a) {
@@ -696,6 +524,163 @@ function $provideFilesystemForNode(options) {
696
524
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
697
525
  */
698
526
 
527
+ /**
528
+ * Make error report URL for the given error
529
+ *
530
+ * @private !!!!!!
531
+ */
532
+ function getErrorReportUrl(error) {
533
+ var report = {
534
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
535
+ 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 "); }),
536
+ };
537
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
538
+ reportUrl.searchParams.set('labels', 'bug');
539
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
540
+ reportUrl.searchParams.set('title', report.title);
541
+ reportUrl.searchParams.set('body', report.body);
542
+ return reportUrl;
543
+ }
544
+
545
+ /**
546
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
547
+ *
548
+ * @public exported from `@promptbook/core`
549
+ */
550
+ var UnexpectedError = /** @class */ (function (_super) {
551
+ __extends(UnexpectedError, _super);
552
+ function UnexpectedError(message) {
553
+ 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;
554
+ _this.name = 'UnexpectedError';
555
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
556
+ return _this;
557
+ }
558
+ return UnexpectedError;
559
+ }(Error));
560
+
561
+ /**
562
+ * Checks if the value is [🚉] serializable as JSON
563
+ * If not, throws an UnexpectedError with a rich error message and tracking
564
+ *
565
+ * - Almost all primitives are serializable BUT:
566
+ * - `undefined` is not serializable
567
+ * - `NaN` is not serializable
568
+ * - Objects and arrays are serializable if all their properties are serializable
569
+ * - Functions are not serializable
570
+ * - Circular references are not serializable
571
+ * - `Date` objects are not serializable
572
+ * - `Map` and `Set` objects are not serializable
573
+ * - `RegExp` objects are not serializable
574
+ * - `Error` objects are not serializable
575
+ * - `Symbol` objects are not serializable
576
+ * - And much more...
577
+ *
578
+ * @throws UnexpectedError if the value is not serializable as JSON
579
+ * @public exported from `@promptbook/utils`
580
+ */
581
+ function checkSerializableAsJson(name, value) {
582
+ var e_1, _a;
583
+ if (value === undefined) {
584
+ throw new UnexpectedError("".concat(name, " is undefined"));
585
+ }
586
+ else if (value === null) {
587
+ return;
588
+ }
589
+ else if (typeof value === 'boolean') {
590
+ return;
591
+ }
592
+ else if (typeof value === 'number' && !isNaN(value)) {
593
+ return;
594
+ }
595
+ else if (typeof value === 'string') {
596
+ return;
597
+ }
598
+ else if (typeof value === 'symbol') {
599
+ throw new UnexpectedError("".concat(name, " is symbol"));
600
+ }
601
+ else if (typeof value === 'function') {
602
+ throw new UnexpectedError("".concat(name, " is function"));
603
+ }
604
+ else if (typeof value === 'object' && Array.isArray(value)) {
605
+ for (var i = 0; i < value.length; i++) {
606
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
607
+ }
608
+ }
609
+ else if (typeof value === 'object') {
610
+ if (value instanceof Date) {
611
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
612
+ }
613
+ else if (value instanceof Map) {
614
+ throw new UnexpectedError("".concat(name, " is Map"));
615
+ }
616
+ else if (value instanceof Set) {
617
+ throw new UnexpectedError("".concat(name, " is Set"));
618
+ }
619
+ else if (value instanceof RegExp) {
620
+ throw new UnexpectedError("".concat(name, " is RegExp"));
621
+ }
622
+ else if (value instanceof Error) {
623
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
624
+ }
625
+ else {
626
+ try {
627
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
628
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
629
+ if (subValue === undefined) {
630
+ // Note: undefined in object is serializable - it is just omited
631
+ continue;
632
+ }
633
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
634
+ }
635
+ }
636
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
637
+ finally {
638
+ try {
639
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
640
+ }
641
+ finally { if (e_1) throw e_1.error; }
642
+ }
643
+ try {
644
+ JSON.stringify(value); // <- TODO: [0]
645
+ }
646
+ catch (error) {
647
+ if (!(error instanceof Error)) {
648
+ throw error;
649
+ }
650
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
651
+ }
652
+ /*
653
+ TODO: [0] Is there some more elegant way to check circular references?
654
+ const seen = new Set();
655
+ const stack = [{ value }];
656
+ while (stack.length > 0) {
657
+ const { value } = stack.pop()!;
658
+ if (typeof value === 'object' && value !== null) {
659
+ if (seen.has(value)) {
660
+ throw new UnexpectedError(`${name} has circular reference`);
661
+ }
662
+ seen.add(value);
663
+ if (Array.isArray(value)) {
664
+ stack.push(...value.map((value) => ({ value })));
665
+ } else {
666
+ stack.push(...Object.values(value).map((value) => ({ value })));
667
+ }
668
+ }
669
+ }
670
+ */
671
+ return;
672
+ }
673
+ }
674
+ else {
675
+ throw new UnexpectedError("".concat(name, " is unknown"));
676
+ }
677
+ }
678
+ /**
679
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
680
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
681
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
682
+ */
683
+
699
684
  /**
700
685
  * Tests if the value is [🚉] serializable as JSON
701
686
  *
@@ -739,7 +724,7 @@ function isSerializableAsJson(value) {
739
724
  */
740
725
  function stringifyPipelineJson(pipeline) {
741
726
  if (!isSerializableAsJson(pipeline)) {
742
- 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 "));
727
+ 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 "));
743
728
  }
744
729
  var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
745
730
  for (var i = 0; i < LOOP_LIMIT; i++) {
@@ -1538,6 +1523,40 @@ function deepClone(objectValue) {
1538
1523
  * TODO: [🧠] Is there a way how to meaningfully test this utility
1539
1524
  */
1540
1525
 
1526
+ /**
1527
+ * @@@
1528
+ *
1529
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
1530
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1531
+ *
1532
+ * @returns The same object as the input, but deeply frozen
1533
+ * @public exported from `@promptbook/utils`
1534
+ */
1535
+ function $deepFreeze(objectValue) {
1536
+ var e_1, _a;
1537
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
1538
+ try {
1539
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1540
+ var propertyName = propertyNames_1_1.value;
1541
+ var value = objectValue[propertyName];
1542
+ if (value && typeof value === 'object') {
1543
+ $deepFreeze(value);
1544
+ }
1545
+ }
1546
+ }
1547
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1548
+ finally {
1549
+ try {
1550
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1551
+ }
1552
+ finally { if (e_1) throw e_1.error; }
1553
+ }
1554
+ return Object.freeze(objectValue);
1555
+ }
1556
+ /**
1557
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1558
+ */
1559
+
1541
1560
  /**
1542
1561
  * Represents the usage with no resources consumed
1543
1562
  *
@@ -1761,7 +1780,7 @@ function countTotalUsage(llmTools) {
1761
1780
  var NotYetImplementedError = /** @class */ (function (_super) {
1762
1781
  __extends(NotYetImplementedError, _super);
1763
1782
  function NotYetImplementedError(message) {
1764
- 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;
1783
+ 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;
1765
1784
  _this.name = 'NotYetImplementedError';
1766
1785
  Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
1767
1786
  return _this;
@@ -2050,7 +2069,7 @@ function $registeredLlmToolsMessage() {
2050
2069
  if (metadata.length === 0) {
2051
2070
  return "No LLM providers are available.";
2052
2071
  }
2053
- return spaceTrim$1(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
2072
+ return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
2054
2073
  .filter(function (envVariableName) {
2055
2074
  return metadata.some(function (_a) {
2056
2075
  var envVariables = _a.envVariables;
@@ -2094,7 +2113,7 @@ function $registeredLlmToolsMessage() {
2094
2113
  morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
2095
2114
  }
2096
2115
  }
2097
- var providerMessage = spaceTrim$1("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
2116
+ var providerMessage = spaceTrim("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
2098
2117
  if ($isRunningInNode) {
2099
2118
  if (isInstalled && isFullyConfigured) {
2100
2119
  providerMessage = colors.green(providerMessage);
@@ -2334,7 +2353,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2334
2353
  // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2335
2354
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2336
2355
  // 3) ...
2337
- spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2356
+ spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2338
2357
  .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2339
2358
  .join('\n')), "\n\n "); }));
2340
2359
  }
@@ -2342,7 +2361,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2342
2361
  throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
2343
2362
  }
2344
2363
  else {
2345
- 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 "); }));
2364
+ 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 "); }));
2346
2365
  }
2347
2366
  }
2348
2367
  });
@@ -2377,7 +2396,7 @@ function joinLlmExecutionTools() {
2377
2396
  llmExecutionTools[_i] = arguments[_i];
2378
2397
  }
2379
2398
  if (llmExecutionTools.length === 0) {
2380
- 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 ");
2399
+ 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 ");
2381
2400
  // TODO: [🟥] Detect browser / node and make it colorfull
2382
2401
  console.warn(warningMessage);
2383
2402
  /*
@@ -2426,7 +2445,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
2426
2445
  return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
2427
2446
  });
2428
2447
  if (registeredItem === undefined) {
2429
- 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 "); }));
2448
+ 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 "); }));
2430
2449
  }
2431
2450
  return registeredItem(__assign({ isVerbose: isVerbose, userId: userId }, llmConfiguration.options));
2432
2451
  });
@@ -2465,7 +2484,7 @@ function $provideLlmToolsFromEnv(options) {
2465
2484
  var configuration = $provideLlmToolsConfigurationFromEnv();
2466
2485
  if (configuration.length === 0) {
2467
2486
  // TODO: [🥃]
2468
- 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 "); }));
2487
+ 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 "); }));
2469
2488
  }
2470
2489
  return createLlmToolsFromConfiguration(configuration, options);
2471
2490
  }
@@ -2514,7 +2533,7 @@ function $provideLlmToolsForCli(options) {
2514
2533
  function initializeListModelsCommand(program) {
2515
2534
  var _this = this;
2516
2535
  var listModelsCommand = program.command('list-models');
2517
- listModelsCommand.description(spaceTrim$1("\n List all available and configured LLM models\n "));
2536
+ listModelsCommand.description(spaceTrim("\n List all available and configured LLM models\n "));
2518
2537
  listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
2519
2538
  return __generator(this, function (_a) {
2520
2539
  $provideLlmToolsForCli({});
@@ -2768,7 +2787,7 @@ function pipelineJsonToString(pipelineJson) {
2768
2787
  pipelineString += '\n\n';
2769
2788
  pipelineString += '```' + contentLanguage;
2770
2789
  pipelineString += '\n';
2771
- pipelineString += spaceTrim$1(content);
2790
+ pipelineString += spaceTrim(content);
2772
2791
  // <- TODO: [main] !!! Escape
2773
2792
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
2774
2793
  pipelineString += '\n';
@@ -2813,7 +2832,7 @@ function taskParameterJsonToString(taskParameterJson) {
2813
2832
  var MissingToolsError = /** @class */ (function (_super) {
2814
2833
  __extends(MissingToolsError, _super);
2815
2834
  function MissingToolsError(message) {
2816
- 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;
2835
+ 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;
2817
2836
  _this.name = 'MissingToolsError';
2818
2837
  Object.setPrototypeOf(_this, MissingToolsError.prototype);
2819
2838
  return _this;
@@ -3086,7 +3105,7 @@ function validatePipeline(pipeline) {
3086
3105
  if (!(error instanceof PipelineLogicError)) {
3087
3106
  throw error;
3088
3107
  }
3089
- 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 "); }));
3108
+ 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 "); }));
3090
3109
  }
3091
3110
  }
3092
3111
  return pipeline;
@@ -3110,35 +3129,35 @@ function validatePipelineCore(pipeline) {
3110
3129
  })();
3111
3130
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
3112
3131
  // <- Note: [🚲]
3113
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3132
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3114
3133
  }
3115
3134
  if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
3116
3135
  // <- Note: [🚲]
3117
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3136
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3118
3137
  }
3119
3138
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
3120
3139
  if (!Array.isArray(pipeline.parameters)) {
3121
3140
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
3122
- 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 "); }));
3141
+ 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 "); }));
3123
3142
  }
3124
3143
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
3125
3144
  if (!Array.isArray(pipeline.tasks)) {
3126
3145
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
3127
- 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 "); }));
3146
+ 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 "); }));
3128
3147
  }
3129
3148
  var _loop_1 = function (parameter) {
3130
3149
  if (parameter.isInput && parameter.isOutput) {
3131
- 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 "); }));
3150
+ 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 "); }));
3132
3151
  }
3133
3152
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
3134
3153
  if (!parameter.isInput &&
3135
3154
  !parameter.isOutput &&
3136
3155
  !pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
3137
- 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 "); }));
3156
+ 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 "); }));
3138
3157
  }
3139
3158
  // Note: Testing that parameter is either input or result of some task
3140
3159
  if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
3141
- 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 "); }));
3160
+ 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 "); }));
3142
3161
  }
3143
3162
  };
3144
3163
  try {
@@ -3166,20 +3185,20 @@ function validatePipelineCore(pipeline) {
3166
3185
  var _loop_2 = function (task) {
3167
3186
  var e_4, _h, e_5, _j;
3168
3187
  if (definedParameters.has(task.resultingParameterName)) {
3169
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
3188
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
3170
3189
  }
3171
3190
  if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
3172
- 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 "); }));
3191
+ 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 "); }));
3173
3192
  }
3174
3193
  definedParameters.add(task.resultingParameterName);
3175
3194
  if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
3176
3195
  if (!task.format &&
3177
3196
  !task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
3178
- 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 "); }));
3197
+ 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 "); }));
3179
3198
  }
3180
3199
  var _loop_4 = function (joker) {
3181
3200
  if (!task.dependentParameterNames.includes(joker)) {
3182
- 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 "); }));
3201
+ 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 "); }));
3183
3202
  }
3184
3203
  };
3185
3204
  try {
@@ -3199,13 +3218,13 @@ function validatePipelineCore(pipeline) {
3199
3218
  if (task.expectations) {
3200
3219
  var _loop_5 = function (unit, min, max) {
3201
3220
  if (min !== undefined && max !== undefined && min > max) {
3202
- 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 "); }));
3221
+ 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 "); }));
3203
3222
  }
3204
3223
  if (min !== undefined && min < 0) {
3205
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
3224
+ 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 "); }));
3206
3225
  }
3207
3226
  if (max !== undefined && max <= 0) {
3208
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
3227
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
3209
3228
  }
3210
3229
  };
3211
3230
  try {
@@ -3266,7 +3285,7 @@ function validatePipelineCore(pipeline) {
3266
3285
  var _loop_3 = function () {
3267
3286
  if (loopLimit-- < 0) {
3268
3287
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
3269
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
3288
+ 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 "); }));
3270
3289
  }
3271
3290
  var currentlyResovedTasks = unresovedTasks.filter(function (task) {
3272
3291
  return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -3274,7 +3293,7 @@ function validatePipelineCore(pipeline) {
3274
3293
  if (currentlyResovedTasks.length === 0) {
3275
3294
  throw new PipelineLogicError(
3276
3295
  // TODO: [🐎] DRY
3277
- 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
3296
+ 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
3278
3297
  .map(function (_a) {
3279
3298
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
3280
3299
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -3385,6 +3404,26 @@ function extractParameterNames(template) {
3385
3404
  return parameterNames;
3386
3405
  }
3387
3406
 
3407
+ /**
3408
+ * @@@
3409
+ * @@@
3410
+ *
3411
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
3412
+ *
3413
+ * @param name - Name of the object for debugging purposes
3414
+ * @param objectValue - Object to be deeply frozen
3415
+ * @returns The same object as the input, but deeply frozen
3416
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
3417
+ */
3418
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
3419
+ checkSerializableAsJson(name, objectValue);
3420
+ return $deepFreeze(objectValue);
3421
+ }
3422
+ /**
3423
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
3424
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
3425
+ */
3426
+
3388
3427
  /**
3389
3428
  * Unprepare just strips the preparation data of the pipeline
3390
3429
  *
@@ -3438,7 +3477,7 @@ var SimplePipelineCollection = /** @class */ (function () {
3438
3477
  var pipeline = pipelines_1_1.value;
3439
3478
  // TODO: [👠] DRY
3440
3479
  if (pipeline.pipelineUrl === undefined) {
3441
- 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 ")));
3480
+ 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 ")));
3442
3481
  }
3443
3482
  // Note: [🐨]
3444
3483
  validatePipeline(pipeline);
@@ -3450,7 +3489,7 @@ var SimplePipelineCollection = /** @class */ (function () {
3450
3489
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
3451
3490
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
3452
3491
  var existing = this.collection.get(pipeline.pipelineUrl);
3453
- 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 ")));
3492
+ 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 ")));
3454
3493
  }
3455
3494
  // Note: [🧠] Overwrite existing pipeline with the same URL
3456
3495
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -3480,9 +3519,9 @@ var SimplePipelineCollection = /** @class */ (function () {
3480
3519
  var pipeline = this.collection.get(url);
3481
3520
  if (!pipeline) {
3482
3521
  if (this.listPipelines().length === 0) {
3483
- throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
3522
+ throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
3484
3523
  }
3485
- throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
3524
+ 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()
3486
3525
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
3487
3526
  .join('\n')), "\n\n "); }));
3488
3527
  }
@@ -3706,10 +3745,10 @@ function assertsExecutionSuccessful(executionResult) {
3706
3745
  throw deserializeError(errors[0]);
3707
3746
  }
3708
3747
  else {
3709
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
3748
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
3710
3749
  .map(function (_a, index) {
3711
3750
  var name = _a.name, stack = _a.stack, message = _a.message;
3712
- return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
3751
+ return spaceTrim$1(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
3713
3752
  })
3714
3753
  .join('\n')), "\n "); }));
3715
3754
  }
@@ -3759,7 +3798,7 @@ function isPipelinePrepared(pipeline) {
3759
3798
  function serializeError(error) {
3760
3799
  var name = error.name, message = error.message, stack = error.stack;
3761
3800
  if (!Object.keys(ALL_ERRORS).includes(name)) {
3762
- console.error(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
3801
+ console.error(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
3763
3802
  }
3764
3803
  return {
3765
3804
  name: name,
@@ -3778,6 +3817,7 @@ function serializeError(error) {
3778
3817
  */
3779
3818
  function extractVariablesFromScript(script) {
3780
3819
  var variables = new Set();
3820
+ var originalScript = script;
3781
3821
  script = "(()=>{".concat(script, "})()");
3782
3822
  try {
3783
3823
  for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
@@ -3788,20 +3828,32 @@ function extractVariablesFromScript(script) {
3788
3828
  if (!(error instanceof ReferenceError)) {
3789
3829
  throw error;
3790
3830
  }
3791
- var undefinedName = error.message.split(' ')[0];
3792
3831
  /*
3793
3832
  Note: Parsing the error
3833
+ 🌟 Most devices:
3794
3834
  [PipelineUrlError: thing is not defined]
3835
+
3836
+ 🍏 iPhone`s Safari:
3837
+ [PipelineUrlError: Can't find variable: thing]
3795
3838
  */
3796
- if (!undefinedName) {
3839
+ var variableName = undefined;
3840
+ if (error.message.startsWith("Can't")) {
3841
+ // 🍏 Case
3842
+ variableName = error.message.split(' ').pop();
3843
+ }
3844
+ else {
3845
+ // 🌟 Case
3846
+ variableName = error.message.split(' ').shift();
3847
+ }
3848
+ if (variableName === undefined) {
3797
3849
  throw error;
3798
3850
  }
3799
- if (script.includes(undefinedName + '(')) {
3800
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
3851
+ if (script.includes(variableName + '(')) {
3852
+ script = "const ".concat(variableName, " = ()=>'';") + script;
3801
3853
  }
3802
3854
  else {
3803
- variables.add(undefinedName);
3804
- script = "const ".concat(undefinedName, " = '';") + script;
3855
+ variables.add(variableName);
3856
+ script = "const ".concat(variableName, " = '';") + script;
3805
3857
  }
3806
3858
  }
3807
3859
  }
@@ -3809,7 +3861,9 @@ function extractVariablesFromScript(script) {
3809
3861
  if (!(error instanceof Error)) {
3810
3862
  throw error;
3811
3863
  }
3812
- throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
3864
+ 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)
3865
+ .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
3866
+ .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
3813
3867
  }
3814
3868
  return variables;
3815
3869
  }
@@ -4013,7 +4067,7 @@ var CsvFormatDefinition = {
4013
4067
  case 0:
4014
4068
  csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
4015
4069
  if (csv.errors.length !== 0) {
4016
- 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 "); }));
4070
+ 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 "); }));
4017
4071
  }
4018
4072
  return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
4019
4073
  var _a, _b;
@@ -4051,7 +4105,7 @@ var CsvFormatDefinition = {
4051
4105
  case 0:
4052
4106
  csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
4053
4107
  if (csv.errors.length !== 0) {
4054
- 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 "); }));
4108
+ 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 "); }));
4055
4109
  }
4056
4110
  return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
4057
4111
  var _this = this;
@@ -4292,7 +4346,7 @@ function mapAvailableToExpectedParameters(options) {
4292
4346
  }
4293
4347
  // Phase 2️⃣: Non-matching mapping
4294
4348
  if (expectedParameterNames.size !== availableParametersNames.size) {
4295
- 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)
4349
+ 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)
4296
4350
  .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
4297
4351
  .join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
4298
4352
  .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
@@ -4705,14 +4759,14 @@ function executeAttempts(options) {
4705
4759
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
4706
4760
  // TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
4707
4761
  if (isJokerAttempt && !jokerParameterName) {
4708
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
4762
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
4709
4763
  }
4710
4764
  $ongoingTaskResult.$result = null;
4711
4765
  $ongoingTaskResult.$resultString = null;
4712
4766
  $ongoingTaskResult.$expectError = null;
4713
4767
  if (isJokerAttempt) {
4714
4768
  if (parameters[jokerParameterName] === undefined) {
4715
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
4769
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
4716
4770
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
4717
4771
  }
4718
4772
  else {
@@ -4781,15 +4835,15 @@ function executeAttempts(options) {
4781
4835
  $ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
4782
4836
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
4783
4837
  return [3 /*break*/, 10];
4784
- 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 "); }));
4785
- case 9: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4838
+ 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 "); }));
4839
+ 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 "); }));
4786
4840
  case 10: return [3 /*break*/, 25];
4787
4841
  case 11:
4788
4842
  if (arrayableToArray(tools.script).length === 0) {
4789
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
4843
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
4790
4844
  }
4791
4845
  if (!task.contentLanguage) {
4792
- 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 "); }));
4846
+ 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 "); }));
4793
4847
  }
4794
4848
  _t.label = 12;
4795
4849
  case 12:
@@ -4843,13 +4897,13 @@ function executeAttempts(options) {
4843
4897
  throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
4844
4898
  }
4845
4899
  else {
4846
- 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
4900
+ 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
4847
4901
  .map(function (error) { return '- ' + error.message; })
4848
4902
  .join('\n\n')), "\n "); }));
4849
4903
  }
4850
4904
  case 22:
4851
4905
  if (tools.userInterface === undefined) {
4852
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
4906
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
4853
4907
  }
4854
4908
  // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
4855
4909
  _j = $ongoingTaskResult;
@@ -4865,7 +4919,7 @@ function executeAttempts(options) {
4865
4919
  // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
4866
4920
  _j.$resultString = _t.sent();
4867
4921
  return [3 /*break*/, 25];
4868
- case 24: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
4922
+ case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
4869
4923
  case 25:
4870
4924
  if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
4871
4925
  _t.label = 26;
@@ -4955,13 +5009,13 @@ function executeAttempts(options) {
4955
5009
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
4956
5010
  }
4957
5011
  catch (error) {
4958
- throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
5012
+ throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
4959
5013
  /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
4960
5014
  }
4961
5015
  }
4962
5016
  }
4963
5017
  else {
4964
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
5018
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
4965
5019
  }
4966
5020
  }
4967
5021
  // TODO: [💝] Unite object for expecting amount and format
@@ -4995,7 +5049,7 @@ function executeAttempts(options) {
4995
5049
  return [7 /*endfinally*/];
4996
5050
  case 45:
4997
5051
  if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
4998
- throw new PipelineExecutionError(spaceTrim(function (block) {
5052
+ throw new PipelineExecutionError(spaceTrim$1(function (block) {
4999
5053
  var _a, _b, _c;
5000
5054
  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) || '')
5001
5055
  .split('\n')
@@ -5031,7 +5085,7 @@ function executeAttempts(options) {
5031
5085
  return [3 /*break*/, 1];
5032
5086
  case 4:
5033
5087
  if ($ongoingTaskResult.$resultString === null) {
5034
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
5088
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
5035
5089
  }
5036
5090
  return [2 /*return*/, $ongoingTaskResult.$resultString];
5037
5091
  }
@@ -5059,7 +5113,7 @@ function executeFormatSubvalues(options) {
5059
5113
  return [2 /*return*/, /* not await */ executeAttempts(options)];
5060
5114
  }
5061
5115
  if (jokerParameterNames.length !== 0) {
5062
- 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 "); }));
5116
+ 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 "); }));
5063
5117
  }
5064
5118
  parameterValue = parameters[task.foreach.parameterName] || '';
5065
5119
  formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
@@ -5068,7 +5122,7 @@ function executeFormatSubvalues(options) {
5068
5122
  if (formatDefinition === undefined) {
5069
5123
  throw new UnexpectedError(
5070
5124
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5071
- 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; })
5125
+ 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; })
5072
5126
  .map(function (formatName) { return "- ".concat(formatName); })
5073
5127
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
5074
5128
  }
@@ -5078,7 +5132,7 @@ function executeFormatSubvalues(options) {
5078
5132
  if (subvalueDefinition === undefined) {
5079
5133
  throw new UnexpectedError(
5080
5134
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5081
- 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
5135
+ 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
5082
5136
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
5083
5137
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
5084
5138
  .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -5104,12 +5158,12 @@ function executeFormatSubvalues(options) {
5104
5158
  if (!(error instanceof PipelineExecutionError)) {
5105
5159
  throw error;
5106
5160
  }
5107
- 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 "); }));
5161
+ 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 "); }));
5108
5162
  }
5109
5163
  allSubparameters = __assign(__assign({}, parameters), mappedParameters);
5110
5164
  // 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
5111
5165
  Object.freeze(allSubparameters);
5112
- 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 "); }) }))];
5166
+ 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 "); }) }))];
5113
5167
  case 1:
5114
5168
  subresultString = _a.sent();
5115
5169
  return [2 /*return*/, subresultString];
@@ -5202,7 +5256,7 @@ function getReservedParametersForTask(options) {
5202
5256
  };
5203
5257
  _loop_1 = function (parameterName) {
5204
5258
  if (reservedParameters[parameterName] === undefined) {
5205
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
5259
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
5206
5260
  }
5207
5261
  };
5208
5262
  try {
@@ -5257,7 +5311,7 @@ function executeTask(options) {
5257
5311
  dependentParameterNames = new Set(currentTask.dependentParameterNames);
5258
5312
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5259
5313
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
5260
- 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)
5314
+ 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)
5261
5315
  .map(function (name) { return "{".concat(name, "}"); })
5262
5316
  .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
5263
5317
  .map(function (name) { return "{".concat(name, "}"); })
@@ -5285,7 +5339,7 @@ function executeTask(options) {
5285
5339
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
5286
5340
  // Houston, we have a problem
5287
5341
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
5288
- 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 "); }));
5342
+ 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 "); }));
5289
5343
  }
5290
5344
  };
5291
5345
  try {
@@ -5371,7 +5425,7 @@ function filterJustOutputParameters(options) {
5371
5425
  var _loop_1 = function (parameter) {
5372
5426
  if (parametersToPass[parameter.name] === undefined) {
5373
5427
  // [4]
5374
- $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 "); })));
5428
+ $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 "); })));
5375
5429
  return "continue";
5376
5430
  }
5377
5431
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -5491,7 +5545,7 @@ function executePipeline(options) {
5491
5545
  return name === parameterName;
5492
5546
  });
5493
5547
  if (!(parameter === undefined)) return [3 /*break*/, 1];
5494
- 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 "); })));
5548
+ 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 "); })));
5495
5549
  return [3 /*break*/, 4];
5496
5550
  case 1:
5497
5551
  if (!(parameter.isInput === false)) return [3 /*break*/, 4];
@@ -5503,10 +5557,10 @@ function executePipeline(options) {
5503
5557
  // Note: Wait a short time to prevent race conditions
5504
5558
  _h.sent();
5505
5559
  _h.label = 3;
5506
- 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 "); }), {
5560
+ 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 "); }), {
5507
5561
  isSuccessful: false,
5508
5562
  errors: __spreadArray([
5509
- 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 "); }))
5563
+ 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 "); }))
5510
5564
  ], __read(errors), false).map(serializeError),
5511
5565
  warnings: warnings.map(serializeError),
5512
5566
  executionReport: executionReport,
@@ -5570,7 +5624,7 @@ function executePipeline(options) {
5570
5624
  case 0:
5571
5625
  if (loopLimit-- < 0) {
5572
5626
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
5573
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
5627
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
5574
5628
  }
5575
5629
  currentTask = unresovedTasks_1.find(function (task) {
5576
5630
  return task.dependentParameterNames.every(function (name) {
@@ -5580,7 +5634,7 @@ function executePipeline(options) {
5580
5634
  if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
5581
5635
  throw new UnexpectedError(
5582
5636
  // TODO: [🐎] DRY
5583
- 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
5637
+ 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
5584
5638
  .map(function (_a) {
5585
5639
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
5586
5640
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -5608,7 +5662,7 @@ function executePipeline(options) {
5608
5662
  unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
5609
5663
  work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
5610
5664
  if (isReturned) {
5611
- 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)
5665
+ 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)
5612
5666
  .split('\n')
5613
5667
  .map(function (line) { return "> ".concat(line); })
5614
5668
  .join('\n')), "\n "); }));
@@ -5616,7 +5670,7 @@ function executePipeline(options) {
5616
5670
  if (onProgress) {
5617
5671
  onProgress(progress);
5618
5672
  }
5619
- }, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
5673
+ }, $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 "); }) }))
5620
5674
  .then(function (newParametersToPass) {
5621
5675
  parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
5622
5676
  resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
@@ -5738,7 +5792,7 @@ function createPipelineExecutor(options) {
5738
5792
  preparedPipeline = pipeline;
5739
5793
  }
5740
5794
  else if (isNotPreparedWarningSupressed !== true) {
5741
- 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 "); }));
5795
+ 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 "); }));
5742
5796
  }
5743
5797
  var runCount = 0;
5744
5798
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
@@ -5753,7 +5807,7 @@ function createPipelineExecutor(options) {
5753
5807
  inputParameters: inputParameters,
5754
5808
  tools: tools,
5755
5809
  onProgress: onProgress,
5756
- pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
5810
+ pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
5757
5811
  maxExecutionAttempts: maxExecutionAttempts,
5758
5812
  maxParallelCount: maxParallelCount,
5759
5813
  csvSettings: csvSettings,
@@ -5948,9 +6002,9 @@ function $registeredScrapersMessage(availableScrapers) {
5948
6002
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
5949
6003
  });
5950
6004
  if (metadata.length === 0) {
5951
- 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 ");
6005
+ 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 ");
5952
6006
  }
5953
- return spaceTrim$1(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
6007
+ return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
5954
6008
  .map(function (_a, i) {
5955
6009
  var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
5956
6010
  var more = [];
@@ -6104,7 +6158,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6104
6158
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6105
6159
  case 3:
6106
6160
  if (!(_e.sent())) {
6107
- 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 "); }));
6161
+ 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 "); }));
6108
6162
  }
6109
6163
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
6110
6164
  return [2 /*return*/, {
@@ -6217,7 +6271,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
6217
6271
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
6218
6272
  return [2 /*return*/, "break"];
6219
6273
  }
6220
- 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
6274
+ 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
6221
6275
  .split('\n')
6222
6276
  .map(function (line) { return "> ".concat(line); })
6223
6277
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -6255,7 +6309,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
6255
6309
  return [7 /*endfinally*/];
6256
6310
  case 9:
6257
6311
  if (partialPieces === null) {
6258
- throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
6312
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
6259
6313
  .split('\n')
6260
6314
  .map(function (line) { return "> ".concat(line); })
6261
6315
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -6354,7 +6408,7 @@ function prepareTasks(pipeline, tools, options) {
6354
6408
  dependentParameterNames = task.dependentParameterNames;
6355
6409
  preparedContent = undefined;
6356
6410
  if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
6357
- preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
6411
+ preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
6358
6412
  // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
6359
6413
  dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
6360
6414
  'knowledge',
@@ -6553,7 +6607,7 @@ var knowledgeCommandParser = {
6553
6607
  */
6554
6608
  parse: function (input) {
6555
6609
  var args = input.args;
6556
- var sourceContent = spaceTrim$1(args[0] || '');
6610
+ var sourceContent = spaceTrim(args[0] || '');
6557
6611
  if (sourceContent === '') {
6558
6612
  throw new ParseError("Source is not defined");
6559
6613
  }
@@ -6697,7 +6751,7 @@ var sectionCommandParser = {
6697
6751
  return normalized.includes(sectionType.split('_TASK').join(''));
6698
6752
  });
6699
6753
  if (taskTypes.length !== 1) {
6700
- 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 "); }));
6754
+ 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 "); }));
6701
6755
  }
6702
6756
  var taskType = taskTypes[0];
6703
6757
  return {
@@ -6712,10 +6766,10 @@ var sectionCommandParser = {
6712
6766
  */
6713
6767
  $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
6714
6768
  if ($taskJson.isSectionTypeSet === true) {
6715
- throw new ParseError(spaceTrim$1("\n Section type is already defined in the section.\n It can be defined only once.\n "));
6769
+ throw new ParseError(spaceTrim("\n Section type is already defined in the section.\n It can be defined only once.\n "));
6716
6770
  }
6717
6771
  $taskJson.isSectionTypeSet = true;
6718
- // TODO: [🍧] Rearrange better - but at bottom and unwrap from function
6772
+ // TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
6719
6773
  var expectResultingParameterName = function () {
6720
6774
  if ($taskJson.resultingParameterName) {
6721
6775
  return;
@@ -7054,7 +7108,7 @@ var expectCommandParser = {
7054
7108
  /**
7055
7109
  * Description of the FORMAT command
7056
7110
  */
7057
- 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 "),
7111
+ 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 "),
7058
7112
  /**
7059
7113
  * Link to documentation
7060
7114
  */
@@ -7138,7 +7192,7 @@ var expectCommandParser = {
7138
7192
  if (!(error instanceof Error)) {
7139
7193
  throw error;
7140
7194
  }
7141
- throw new ParseError(spaceTrim$1(function (block) {
7195
+ throw new ParseError(spaceTrim(function (block) {
7142
7196
  return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
7143
7197
  }));
7144
7198
  }
@@ -7344,7 +7398,7 @@ function validateParameterName(parameterName) {
7344
7398
  if (!(error instanceof ParseError)) {
7345
7399
  throw error;
7346
7400
  }
7347
- 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 "); }));
7401
+ throw new ParseError(spaceTrim(function (block) { return "\n ".concat(block(error.message), "\n\n Tried to validate parameter name:\n ").concat(block(rawParameterName), "\n "); }));
7348
7402
  }
7349
7403
  return parameterName;
7350
7404
  }
@@ -7402,7 +7456,7 @@ var foreachCommandParser = {
7402
7456
  return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
7403
7457
  });
7404
7458
  if (formatDefinition === undefined) {
7405
- 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; })
7459
+ 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; })
7406
7460
  .map(function (formatName) { return "- ".concat(formatName); })
7407
7461
  .join('\n')), "\n "); }));
7408
7462
  // <- TODO: [🏢] List all supported format names
@@ -7411,7 +7465,7 @@ var foreachCommandParser = {
7411
7465
  return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
7412
7466
  });
7413
7467
  if (subvalueDefinition === undefined) {
7414
- 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
7468
+ 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
7415
7469
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
7416
7470
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
7417
7471
  .join('\n')), "\n "); }));
@@ -7454,7 +7508,7 @@ var foreachCommandParser = {
7454
7508
  outputSubparameterName = 'newLine';
7455
7509
  }
7456
7510
  else {
7457
- 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 ")));
7511
+ 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 ")));
7458
7512
  }
7459
7513
  }
7460
7514
  return {
@@ -7524,7 +7578,7 @@ var formatCommandParser = {
7524
7578
  /**
7525
7579
  * Description of the FORMAT command
7526
7580
  */
7527
- 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 "),
7581
+ 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 "),
7528
7582
  /**
7529
7583
  * Link to documentation
7530
7584
  */
@@ -7801,7 +7855,7 @@ var formfactorCommandParser = {
7801
7855
  return __spreadArray([definition.name], __read(__assign({ aliasNames: [] }, definition).aliasNames), false).includes(formfactorNameCandidate);
7802
7856
  });
7803
7857
  if (formfactor === undefined) {
7804
- 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) {
7858
+ 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) {
7805
7859
  var name = _a.name;
7806
7860
  return "- ".concat(name);
7807
7861
  }).join('\n')), "\n "); }));
@@ -7952,7 +8006,7 @@ var modelCommandParser = {
7952
8006
  */
7953
8007
  parse: function (input) {
7954
8008
  var args = input.args, normalized = input.normalized;
7955
- var availableVariantsMessage = spaceTrim$1(function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
8009
+ var availableVariantsMessage = spaceTrim(function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
7956
8010
  return "- ".concat(variantName).concat(variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)');
7957
8011
  }).join('\n')), "\n "); });
7958
8012
  // TODO: Make this more elegant and dynamically
@@ -7973,10 +8027,10 @@ var modelCommandParser = {
7973
8027
  // <- Note: [🤖]
7974
8028
  }
7975
8029
  else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
7976
- spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
8030
+ spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
7977
8031
  }
7978
8032
  else {
7979
- throw new ParseError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
8033
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
7980
8034
  }
7981
8035
  }
7982
8036
  if (normalized.startsWith('MODEL_NAME')) {
@@ -7987,7 +8041,7 @@ var modelCommandParser = {
7987
8041
  };
7988
8042
  }
7989
8043
  else {
7990
- 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 "); }));
8044
+ 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 "); }));
7991
8045
  }
7992
8046
  },
7993
8047
  /**
@@ -8001,10 +8055,10 @@ var modelCommandParser = {
8001
8055
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
8002
8056
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
8003
8057
  console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
8004
- // <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
8058
+ // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
8005
8059
  }
8006
8060
  else {
8007
- 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 ")));
8061
+ 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 ")));
8008
8062
  }
8009
8063
  }
8010
8064
  $pipelineJson.defaultModelRequirements[command.key] = command.value;
@@ -8029,11 +8083,11 @@ var modelCommandParser = {
8029
8083
  }[command.key], " ").concat(command.value, "` in the task \"").concat($taskJson.title || $taskJson.name, "\""));
8030
8084
  }
8031
8085
  else {
8032
- 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 ")));
8086
+ 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 ")));
8033
8087
  }
8034
8088
  }
8035
8089
  if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
8036
- 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 ")));
8090
+ 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 ")));
8037
8091
  }
8038
8092
  $taskJson.modelRequirements[command.key] = command.value;
8039
8093
  },
@@ -8108,7 +8162,7 @@ var parameterCommandParser = {
8108
8162
  // <- TODO: When [🥶] fixed, change to:
8109
8163
  // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
8110
8164
  if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
8111
- 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 "); }));
8165
+ 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 "); }));
8112
8166
  }
8113
8167
  var isInput = normalized.startsWith('INPUT');
8114
8168
  var isOutput = normalized.startsWith('OUTPUT');
@@ -8285,8 +8339,8 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
8285
8339
  persona.description = personaDescription;
8286
8340
  return;
8287
8341
  }
8288
- 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 ")));
8289
- persona.description += spaceTrim$1('\n\n' + personaDescription);
8342
+ 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 ")));
8343
+ persona.description += spaceTrim('\n\n' + personaDescription);
8290
8344
  }
8291
8345
 
8292
8346
  /**
@@ -8636,7 +8690,7 @@ var COMMANDS = [
8636
8690
  personaCommandParser,
8637
8691
  foreachCommandParser,
8638
8692
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
8639
- // <- 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
8693
+ // <- 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
8640
8694
  ];
8641
8695
  /**
8642
8696
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8653,7 +8707,7 @@ var COMMANDS = [
8653
8707
  function getParserForCommand(command) {
8654
8708
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
8655
8709
  if (commandParser === undefined) {
8656
- 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)
8710
+ 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)
8657
8711
  .split('\n')
8658
8712
  .map(function (line) { return "> ".concat(line); })
8659
8713
  .join('\n')), "\n "); }));
@@ -8725,7 +8779,7 @@ function parseCommand(raw, usagePlace) {
8725
8779
  .map(removeMarkdownFormatting)
8726
8780
  .map(function (item) { return item.trim(); });
8727
8781
  if (items.length === 0 || items[0] === '') {
8728
- throw new ParseError(spaceTrim(function (block) {
8782
+ throw new ParseError(spaceTrim$1(function (block) {
8729
8783
  return "\n Malformed command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
8730
8784
  }));
8731
8785
  }
@@ -8756,7 +8810,7 @@ function parseCommand(raw, usagePlace) {
8756
8810
  return command;
8757
8811
  }
8758
8812
  }
8759
- throw new ParseError(spaceTrim(function (block) {
8813
+ throw new ParseError(spaceTrim$1(function (block) {
8760
8814
  return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
8761
8815
  }));
8762
8816
  }
@@ -8798,7 +8852,7 @@ function parseCommandVariant(input) {
8798
8852
  if (!(error instanceof ParseError)) {
8799
8853
  throw error;
8800
8854
  }
8801
- throw new ParseError(spaceTrim(function (block) {
8855
+ throw new ParseError(spaceTrim$1(function (block) {
8802
8856
  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 ");
8803
8857
  }));
8804
8858
  }
@@ -8889,7 +8943,7 @@ function extractAllListItemsFromMarkdown(markdown) {
8889
8943
  function extractOneBlockFromMarkdown(markdown) {
8890
8944
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
8891
8945
  if (codeBlocks.length !== 1) {
8892
- 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 "); }));
8946
+ 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 "); }));
8893
8947
  }
8894
8948
  return codeBlocks[0];
8895
8949
  }
@@ -8910,7 +8964,7 @@ function parseMarkdownSection(value) {
8910
8964
  }
8911
8965
  var title = lines[0].replace(/^#+\s*/, '');
8912
8966
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
8913
- var content = spaceTrim$1(lines.slice(1).join('\n'));
8967
+ var content = spaceTrim(lines.slice(1).join('\n'));
8914
8968
  if (level < 1 || level > 6) {
8915
8969
  throw new ParseError('Markdown section must have heading level between 1 and 6');
8916
8970
  }
@@ -8939,7 +8993,7 @@ function splitMarkdownIntoSections(markdown) {
8939
8993
  if (buffer.length === 0) {
8940
8994
  return;
8941
8995
  }
8942
- var section = spaceTrim$1(buffer.join('\n'));
8996
+ var section = spaceTrim(buffer.join('\n'));
8943
8997
  if (section === '') {
8944
8998
  return;
8945
8999
  }
@@ -9035,7 +9089,7 @@ function flattenMarkdown(markdown) {
9035
9089
  }
9036
9090
  finally { if (e_1) throw e_1.error; }
9037
9091
  }
9038
- return spaceTrim$1(flattenedMarkdown);
9092
+ return spaceTrim(flattenedMarkdown);
9039
9093
  }
9040
9094
  /**
9041
9095
  * TODO: [🏛] This can be part of markdown builder
@@ -9053,7 +9107,7 @@ function flattenMarkdown(markdown) {
9053
9107
  * @public exported from `@promptbook/markdown-utils`
9054
9108
  */
9055
9109
  function removeContentComments(content) {
9056
- return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
9110
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
9057
9111
  }
9058
9112
 
9059
9113
  /**
@@ -9104,7 +9158,7 @@ function pipelineStringToJsonSync(pipelineString) {
9104
9158
  if (pipelineString.startsWith('#!')) {
9105
9159
  var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
9106
9160
  if (!(shebangLine_1 || '').includes('ptbk')) {
9107
- 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 "); }));
9161
+ 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 "); }));
9108
9162
  }
9109
9163
  pipelineString = restLines.join('\n');
9110
9164
  }
@@ -9114,27 +9168,27 @@ function pipelineStringToJsonSync(pipelineString) {
9114
9168
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
9115
9169
  var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
9116
9170
  if (pipelineHead === undefined) {
9117
- 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 "); }));
9171
+ 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 "); }));
9118
9172
  }
9119
9173
  if (pipelineHead.level !== 1) {
9120
- 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 "); }));
9174
+ 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 "); }));
9121
9175
  }
9122
9176
  if (!pipelineSections.every(function (section) { return section.level === 2; })) {
9123
- 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 "); }));
9177
+ 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 "); }));
9124
9178
  }
9125
9179
  // =============================================================
9126
9180
  ///Note: 2️⃣ Function for defining parameters
9127
9181
  var defineParam = function (parameterCommand) {
9128
9182
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
9129
9183
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
9130
- 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: [🚞] */);
9184
+ 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: [🚞] */);
9131
9185
  }
9132
9186
  var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
9133
9187
  if (existingParameter &&
9134
9188
  existingParameter.description &&
9135
9189
  existingParameter.description !== parameterDescription &&
9136
9190
  parameterDescription) {
9137
- 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 "); }));
9191
+ 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 "); }));
9138
9192
  }
9139
9193
  if (existingParameter) {
9140
9194
  if (parameterDescription) {
@@ -9162,7 +9216,7 @@ function pipelineStringToJsonSync(pipelineString) {
9162
9216
  description = description.split(/^>.*$/gm).join('');
9163
9217
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
9164
9218
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
9165
- description = spaceTrim(description);
9219
+ description = spaceTrim$1(description);
9166
9220
  if (description === '') {
9167
9221
  description = undefined;
9168
9222
  }
@@ -9173,7 +9227,7 @@ function pipelineStringToJsonSync(pipelineString) {
9173
9227
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
9174
9228
  var commandParser = getParserForCommand(command);
9175
9229
  if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
9176
- 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: [🚞]
9230
+ 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: [🚞]
9177
9231
  }
9178
9232
  try {
9179
9233
  commandParser.$applyToPipelineJson(command, $pipelineJson);
@@ -9183,7 +9237,7 @@ function pipelineStringToJsonSync(pipelineString) {
9183
9237
  if (!(error instanceof ParseError)) {
9184
9238
  throw error;
9185
9239
  }
9186
- 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: [🚞]
9240
+ 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: [🚞]
9187
9241
  }
9188
9242
  if (command.type === 'PARAMETER') {
9189
9243
  defineParam(command);
@@ -9245,7 +9299,7 @@ function pipelineStringToJsonSync(pipelineString) {
9245
9299
  description_1 = description_1.split(/^>.*$/gm).join('');
9246
9300
  //Note: Remove lists and return statement - TODO: [🎾]
9247
9301
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
9248
- description_1 = spaceTrim(description_1);
9302
+ description_1 = spaceTrim$1(description_1);
9249
9303
  if (description_1 === '') {
9250
9304
  description_1 = undefined;
9251
9305
  }
@@ -9281,7 +9335,7 @@ function pipelineStringToJsonSync(pipelineString) {
9281
9335
  var _loop_4 = function (listItem, command) {
9282
9336
  var commandParser = getParserForCommand(command);
9283
9337
  if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
9284
- 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: [🚞]
9338
+ 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: [🚞]
9285
9339
  }
9286
9340
  try {
9287
9341
  commandParser.$applyToTaskJson(
@@ -9292,7 +9346,7 @@ function pipelineStringToJsonSync(pipelineString) {
9292
9346
  if (!(error instanceof ParseError)) {
9293
9347
  throw error;
9294
9348
  }
9295
- 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: [🚞]
9349
+ 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: [🚞]
9296
9350
  }
9297
9351
  if (command.type === 'PARAMETER') {
9298
9352
  defineParam(command);
@@ -9316,10 +9370,10 @@ function pipelineStringToJsonSync(pipelineString) {
9316
9370
  // TODO: [🍧] Should be done in SECTION command
9317
9371
  if ($taskJson.taskType === 'SCRIPT_TASK') {
9318
9372
  if (!language) {
9319
- 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 "); }));
9373
+ 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 "); }));
9320
9374
  }
9321
9375
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
9322
- 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 "); }));
9376
+ 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 "); }));
9323
9377
  }
9324
9378
  $taskJson.contentLanguage = language;
9325
9379
  }
@@ -9980,13 +10034,13 @@ function parseKeywordsFromString(input) {
9980
10034
  * @public exported from `@promptbook/utils`
9981
10035
  */
9982
10036
  function trimCodeBlock(value) {
9983
- value = spaceTrim(value);
10037
+ value = spaceTrim$1(value);
9984
10038
  if (!/^```[a-z]*(.*)```$/is.test(value)) {
9985
10039
  return value;
9986
10040
  }
9987
10041
  value = value.replace(/^```[a-z]*/i, '');
9988
10042
  value = value.replace(/```$/i, '');
9989
- value = spaceTrim(value);
10043
+ value = spaceTrim$1(value);
9990
10044
  return value;
9991
10045
  }
9992
10046
 
@@ -9999,9 +10053,9 @@ function trimCodeBlock(value) {
9999
10053
  * @public exported from `@promptbook/utils`
10000
10054
  */
10001
10055
  function trimEndOfCodeBlock(value) {
10002
- value = spaceTrim(value);
10056
+ value = spaceTrim$1(value);
10003
10057
  value = value.replace(/```$/g, '');
10004
- value = spaceTrim(value);
10058
+ value = spaceTrim$1(value);
10005
10059
  return value;
10006
10060
  }
10007
10061
 
@@ -10023,7 +10077,7 @@ function unwrapResult(text, options) {
10023
10077
  var trimmedText = text;
10024
10078
  // Remove leading and trailing spaces and newlines
10025
10079
  if (isTrimmed) {
10026
- trimmedText = spaceTrim(trimmedText);
10080
+ trimmedText = spaceTrim$1(trimmedText);
10027
10081
  }
10028
10082
  var processedText = trimmedText;
10029
10083
  if (isIntroduceSentenceRemoved) {
@@ -10032,7 +10086,7 @@ function unwrapResult(text, options) {
10032
10086
  // Remove the introduce sentence and quotes by replacing it with an empty string
10033
10087
  processedText = processedText.replace(introduceSentenceRegex, '');
10034
10088
  }
10035
- processedText = spaceTrim(processedText);
10089
+ processedText = spaceTrim$1(processedText);
10036
10090
  }
10037
10091
  if (processedText.length < 3) {
10038
10092
  return trimmedText;
@@ -10092,10 +10146,10 @@ function preserve(func) {
10092
10146
  return __generator(this, function (_a) {
10093
10147
  switch (_a.label) {
10094
10148
  case 0:
10095
- // TODO: Change to `await forEver` or something better
10149
+ // TODO: [💩] Change to `await forEver` or something better
10096
10150
  return [4 /*yield*/, forTime(100000000)];
10097
10151
  case 1:
10098
- // TODO: Change to `await forEver` or something better
10152
+ // TODO: [💩] Change to `await forEver` or something better
10099
10153
  _a.sent();
10100
10154
  _a.label = 2;
10101
10155
  case 2:
@@ -10159,7 +10213,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
10159
10213
  */
10160
10214
  JavascriptEvalExecutionTools.prototype.execute = function (options) {
10161
10215
  return __awaiter(this, void 0, void 0, function () {
10162
- 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;
10216
+ 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;
10163
10217
  return __generator(this, function (_a) {
10164
10218
  switch (_a.label) {
10165
10219
  case 0:
@@ -10168,8 +10222,8 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
10168
10222
  if (scriptLanguage !== 'javascript') {
10169
10223
  throw new PipelineExecutionError("Script language ".concat(scriptLanguage, " not supported to be executed by JavascriptEvalExecutionTools"));
10170
10224
  }
10171
- spaceTrim = function (_) { return spaceTrim$1(_); };
10172
- preserve(spaceTrim);
10225
+ spaceTrim$1 = function (_) { return spaceTrim(_); };
10226
+ preserve(spaceTrim$1);
10173
10227
  removeQuotes$1 = removeQuotes;
10174
10228
  preserve(removeQuotes$1);
10175
10229
  unwrapResult$1 = unwrapResult;
@@ -10219,7 +10273,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
10219
10273
  }
10220
10274
  buildinFunctions = {
10221
10275
  // TODO: [🍯] DRY all these functions across the file
10222
- spaceTrim: spaceTrim,
10276
+ spaceTrim: spaceTrim$1,
10223
10277
  removeQuotes: removeQuotes$1,
10224
10278
  unwrapResult: unwrapResult$1,
10225
10279
  trimEndOfCodeBlock: trimEndOfCodeBlock$1,
@@ -10255,14 +10309,14 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
10255
10309
  return "const ".concat(functionName, " = customFunctions.").concat(functionName, ";");
10256
10310
  })
10257
10311
  .join('\n');
10258
- 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)
10312
+ 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)
10259
10313
  .map(function (_a) {
10260
10314
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
10261
10315
  return "const ".concat(key, " = ").concat(JSON.stringify(value), ";");
10262
10316
  })
10263
10317
  .join('\n')), "\n (()=>{ ").concat(script, " })()\n "); });
10264
10318
  if (this.options.isVerbose) {
10265
- console.info(spaceTrim$1(function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
10319
+ console.info(spaceTrim(function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
10266
10320
  }
10267
10321
  _a.label = 1;
10268
10322
  case 1:
@@ -10287,12 +10341,12 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
10287
10341
  To: [PipelineExecutionError: Parameter `{thing}` is not defined],
10288
10342
  */
10289
10343
  if (!statementToEvaluate.includes(undefinedName_1 + '(')) {
10290
- 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)
10344
+ 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)
10291
10345
  .map(function (key) { return " - ".concat(key, "\n"); })
10292
10346
  .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 "); }));
10293
10347
  }
10294
10348
  else {
10295
- 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 "); }));
10349
+ 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 "); }));
10296
10350
  }
10297
10351
  }
10298
10352
  throw error_1;
@@ -10695,7 +10749,7 @@ function createCollectionFromDirectory(path, tools, options) {
10695
10749
  }
10696
10750
  else {
10697
10751
  existing = collection.get(pipeline.pipelineUrl);
10698
- 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 ")));
10752
+ 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 ")));
10699
10753
  }
10700
10754
  }
10701
10755
  }
@@ -10705,7 +10759,7 @@ function createCollectionFromDirectory(path, tools, options) {
10705
10759
  if (!(error_1 instanceof Error)) {
10706
10760
  throw error_1;
10707
10761
  }
10708
- 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 "); });
10762
+ 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 "); });
10709
10763
  if (isCrashedOnError) {
10710
10764
  throw new CollectionError(wrappedErrorMessage);
10711
10765
  }
@@ -10815,7 +10869,7 @@ function usageToHuman(usage) {
10815
10869
  // Note: For negligible usage, we report at least something
10816
10870
  reportItems.push('Negligible');
10817
10871
  }
10818
- return spaceTrim$1(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
10872
+ return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
10819
10873
  }
10820
10874
  /**
10821
10875
  * TODO: [🍓][🧞‍♂️] Use "$1" not "1 USD"
@@ -10834,18 +10888,18 @@ function usageToHuman(usage) {
10834
10888
  function initializeMakeCommand(program) {
10835
10889
  var _this = this;
10836
10890
  var makeCommand = program.command('make');
10837
- makeCommand.description(spaceTrim$1("\n Makes a new pipeline collection in given folder\n "));
10891
+ makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
10838
10892
  // TODO: [🧅] DRY command arguments
10839
10893
  makeCommand.argument('[path]',
10840
10894
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
10841
10895
  'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
10842
10896
  makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
10843
- makeCommand.option('-f, --format <format>', spaceTrim$1("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
10897
+ makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
10844
10898
  makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
10845
10899
  makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
10846
10900
  makeCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
10847
10901
  makeCommand.option('-v, --verbose', "Is output verbose", false);
10848
- makeCommand.option('-o, --out-file <path>', spaceTrim$1("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
10902
+ makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
10849
10903
  makeCommand.action(function (path, _a) {
10850
10904
  var projectName = _a.projectName, format = _a.format, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, outFile = _a.outFile;
10851
10905
  return __awaiter(_this, void 0, void 0, function () {
@@ -10964,7 +11018,7 @@ function initializeMakeCommand(program) {
10964
11018
  if (lastChar !== ']') {
10965
11019
  throw new UnexpectedError("Last character of serialized collection should be \"]\" not \"".concat(lastChar, "\""));
10966
11020
  }
10967
- return spaceTrim$1(collectionJsonString.substring(1, collectionJsonString.length - 1));
11021
+ return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
10968
11022
  })();
10969
11023
  saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
10970
11024
  var filename;
@@ -10998,14 +11052,14 @@ function initializeMakeCommand(program) {
10998
11052
  case 21:
10999
11053
  if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 23];
11000
11054
  formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
11001
- return [4 /*yield*/, saveFile('js', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
11055
+ return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
11002
11056
  case 22:
11003
11057
  (_g.sent()) + '\n';
11004
11058
  _g.label = 23;
11005
11059
  case 23:
11006
11060
  if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 25];
11007
11061
  formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
11008
- return [4 /*yield*/, saveFile('ts', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
11062
+ return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
11009
11063
  case 24:
11010
11064
  _g.sent();
11011
11065
  _g.label = 25;
@@ -11041,7 +11095,7 @@ function addAutoGeneratedSection(content, options) {
11041
11095
  var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
11042
11096
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
11043
11097
  var sectionMatch = content.match(sectionRegex);
11044
- var contentToInsert = spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
11098
+ var contentToInsert = spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
11045
11099
  if (sectionMatch) {
11046
11100
  return content.replace(sectionRegex, contentToInsert);
11047
11101
  }
@@ -11049,11 +11103,11 @@ function addAutoGeneratedSection(content, options) {
11049
11103
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
11050
11104
  if (placeForSection !== null) {
11051
11105
  var _a = __read(placeForSection, 1), heading_1 = _a[0];
11052
- return content.replace(heading_1, spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n \n ").concat(block(heading_1), "\n "); }));
11106
+ return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
11053
11107
  }
11054
11108
  console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
11055
- // <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
11056
- return spaceTrim(function (block) { return "\n ".concat(block(content), "\n \n ").concat(block(contentToInsert), "\n "); });
11109
+ // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
11110
+ return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
11057
11111
  }
11058
11112
  /**
11059
11113
  * TODO: [🏛] This can be part of markdown builder
@@ -11083,7 +11137,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
11083
11137
  }
11084
11138
  return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
11085
11139
  };
11086
- var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
11140
+ var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
11087
11141
  .flatMap(function (_a) {
11088
11142
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
11089
11143
  return __spreadArray([
@@ -11144,7 +11198,7 @@ function prettifyPipelineString(pipelineString, options) {
11144
11198
  return { href: "#".concat(task.name), title: task.title };
11145
11199
  },
11146
11200
  });
11147
- promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
11201
+ promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
11148
11202
  pipelineString = addAutoGeneratedSection(pipelineString, {
11149
11203
  sectionName: 'Graph',
11150
11204
  sectionContent: promptbookMermaidBlock,
@@ -11172,7 +11226,7 @@ function prettifyPipelineString(pipelineString, options) {
11172
11226
  function initializePrettifyCommand(program) {
11173
11227
  var _this = this;
11174
11228
  var prettifyCommand = program.command('prettify');
11175
- prettifyCommand.description(spaceTrim$1("\n Iterates over `.book.md` files and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
11229
+ prettifyCommand.description(spaceTrim("\n Iterates over `.book.md` files and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
11176
11230
  prettifyCommand.argument('<filesGlob>',
11177
11231
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
11178
11232
  'Pipelines to prettify as glob pattern');
@@ -11420,7 +11474,7 @@ function executionReportJsonToString(executionReportJson, options) {
11420
11474
  var e_1, _a;
11421
11475
  var _b, _c, _d, _e, _f, _g;
11422
11476
  var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
11423
- var executionReportString = spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
11477
+ var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
11424
11478
  var headerList = [];
11425
11479
  if (executionReportJson.pipelineUrl) {
11426
11480
  headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
@@ -11478,7 +11532,7 @@ function executionReportJsonToString(executionReportJson, options) {
11478
11532
  '\n\n' +
11479
11533
  executionReportJson.promptExecutions
11480
11534
  .map(function (promptExecution) {
11481
- // TODO: Make some better system to convert hedings to links
11535
+ // TODO: [💩] Make some better system to convert headings to links
11482
11536
  var hash = normalizeToKebabCase(promptExecution.prompt.title);
11483
11537
  if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
11484
11538
  hash = '-' + hash;
@@ -11540,7 +11594,7 @@ function executionReportJsonToString(executionReportJson, options) {
11540
11594
  if (just(true)) {
11541
11595
  executionReportString +=
11542
11596
  '\n\n\n\n' +
11543
- spaceTrim(function (block) {
11597
+ spaceTrim$1(function (block) {
11544
11598
  var _a;
11545
11599
  return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
11546
11600
  });
@@ -11551,7 +11605,7 @@ function executionReportJsonToString(executionReportJson, options) {
11551
11605
  executionReportString += '*No result*';
11552
11606
  }
11553
11607
  else if (typeof promptExecution.result.content === 'string') {
11554
- executionReportString += spaceTrim(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
11608
+ executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
11555
11609
  }
11556
11610
  else {
11557
11611
  executionReportString += embeddingVectorToString(promptExecution.result.content);
@@ -11560,7 +11614,7 @@ function executionReportJsonToString(executionReportJson, options) {
11560
11614
  if (promptExecution.error && promptExecution.error.message) {
11561
11615
  executionReportString +=
11562
11616
  '\n\n\n\n' +
11563
- spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
11617
+ spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
11564
11618
  }
11565
11619
  };
11566
11620
  try {
@@ -11593,7 +11647,7 @@ function executionReportJsonToString(executionReportJson, options) {
11593
11647
  function initializeRunCommand(program) {
11594
11648
  var _this = this;
11595
11649
  var runCommand = program.command('run', { isDefault: true });
11596
- runCommand.description(spaceTrim$1("\n Runs a pipeline\n "));
11650
+ runCommand.description(spaceTrim("\n Runs a pipeline\n "));
11597
11651
  // TODO: [🧅] DRY command arguments
11598
11652
  runCommand.argument('<path>',
11599
11653
  // <- Note: [🧟‍♂️] This is NOT promptbook collection directory BUT direct path to .book.md file
@@ -11678,7 +11732,7 @@ function initializeRunCommand(program) {
11678
11732
  if (!error.message.includes('No LLM tools')) {
11679
11733
  throw error;
11680
11734
  }
11681
- console.error(colors.red(spaceTrim$1(function (block) { return "\n You need to configure LLM tools first\n\n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n \n For example:\n ".concat(block($llmToolsMetadataRegister
11735
+ console.error(colors.red(spaceTrim(function (block) { return "\n You need to configure LLM tools first\n\n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n \n For example:\n ".concat(block($llmToolsMetadataRegister
11682
11736
  .list()
11683
11737
  .map(function (_a) {
11684
11738
  var title = _a.title, envVariables = _a.envVariables;
@@ -11722,7 +11776,7 @@ function initializeRunCommand(program) {
11722
11776
  if (!(error_1 instanceof ParseError)) {
11723
11777
  throw error_1;
11724
11778
  }
11725
- console.error(colors.red(spaceTrim$1(function (block) { return "\n ".concat(block(error_1.message), "\n\n in ").concat(filePath, "\n "); })));
11779
+ console.error(colors.red(spaceTrim(function (block) { return "\n ".concat(block(error_1.message), "\n\n in ").concat(filePath, "\n "); })));
11726
11780
  return [2 /*return*/, process.exit(1)];
11727
11781
  case 15:
11728
11782
  if (isVerbose) {
@@ -11773,7 +11827,7 @@ function initializeRunCommand(program) {
11773
11827
  };
11774
11828
  });
11775
11829
  if (isInteractive === false && questions.length !== 0) {
11776
- console.error(colors.red(spaceTrim$1(function (block) { return "\n When using --no-interactive you need to pass all the input parameters through --json\n\n You are missing:\n ".concat(block(pipeline.parameters
11830
+ console.error(colors.red(spaceTrim(function (block) { return "\n When using --no-interactive you need to pass all the input parameters through --json\n\n You are missing:\n ".concat(block(pipeline.parameters
11777
11831
  .filter(function (_a) {
11778
11832
  var isInput = _a.isInput;
11779
11833
  return isInput;
@@ -11919,7 +11973,7 @@ function initializeRunCommand(program) {
11919
11973
  function initializeTestCommand(program) {
11920
11974
  var _this = this;
11921
11975
  var testCommand = program.command('test');
11922
- testCommand.description(spaceTrim$1("\n Iterates over `.book.md` and `.book.json` and checks if they are parsable and logically valid\n "));
11976
+ testCommand.description(spaceTrim("\n Iterates over `.book.md` and `.book.json` and checks if they are parsable and logically valid\n "));
11923
11977
  testCommand.argument('<filesGlob>',
11924
11978
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
11925
11979
  'Pipelines to test as glob pattern');
@@ -12045,7 +12099,7 @@ function promptbookCli() {
12045
12099
  var isVerbose, program;
12046
12100
  return __generator(this, function (_a) {
12047
12101
  if (!$isRunningInNode()) {
12048
- throw new EnvironmentMismatchError(spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
12102
+ throw new EnvironmentMismatchError(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
12049
12103
  }
12050
12104
  isVerbose = process.argv.some(function (arg) { return arg === '--verbose' || arg === '-v'; });
12051
12105
  // <- TODO: Can be this be done with commander before the commander commands are initialized?
@@ -12246,7 +12300,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
12246
12300
  socket.on('connect', function () {
12247
12301
  resolve(socket);
12248
12302
  });
12249
- // TODO: [main] !!!! Better timeout handling
12303
+ // TODO: [💩] Better timeout handling
12250
12304
  setTimeout(function () {
12251
12305
  reject(new Error("Timeout while connecting to ".concat(_this.options.remoteUrl)));
12252
12306
  }, CONNECTION_TIMEOUT_MS);
@@ -12744,7 +12798,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
12744
12798
  return modelName.startsWith(defaultModelName);
12745
12799
  });
12746
12800
  if (model === undefined) {
12747
- throw new UnexpectedError(spaceTrim$1(function (block) {
12801
+ throw new UnexpectedError(spaceTrim(function (block) {
12748
12802
  return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(ANTHROPIC_CLAUDE_MODELS.map(function (_a) {
12749
12803
  var modelName = _a.modelName;
12750
12804
  return "- \"".concat(modelName, "\"");
@@ -13224,7 +13278,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
13224
13278
  modelVariant: 'CHAT',
13225
13279
  modelTitle: 'o1-preview-2024-09-12',
13226
13280
  modelName: 'o1-preview-2024-09-12',
13227
- // <- TODO: [main] !!! Some better system to organize theese date suffixes and versions
13281
+ // <- TODO: [💩] Some better system to organize theese date suffixes and versions
13228
13282
  pricing: {
13229
13283
  prompt: computeUsage("$15.00 / 1M tokens"),
13230
13284
  output: computeUsage("$60.00 / 1M tokens"),
@@ -13274,7 +13328,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
13274
13328
  * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
13275
13329
  * @see https://openai.com/api/pricing/
13276
13330
  * @see /other/playground/playground.ts
13277
- * TODO: [🍓] Make better
13331
+ * TODO: [🍓][💩] Make better
13278
13332
  * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
13279
13333
  * TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
13280
13334
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -13758,7 +13812,7 @@ function createExecutionToolsFromVercelProvider(options) {
13758
13812
  return modelVariant === 'CHAT';
13759
13813
  })) === null || _a === void 0 ? void 0 : _a.modelName);
13760
13814
  if (!modelName) {
13761
- throw new PipelineExecutionError(spaceTrim$1("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
13815
+ throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
13762
13816
  }
13763
13817
  return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
13764
13818
  case 1:
@@ -14370,7 +14424,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
14370
14424
  return modelName === defaultModelName;
14371
14425
  });
14372
14426
  if (model === undefined) {
14373
- throw new UnexpectedError(spaceTrim$1(function (block) {
14427
+ throw new UnexpectedError(spaceTrim(function (block) {
14374
14428
  return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(OPENAI_MODELS.map(function (_a) {
14375
14429
  var modelName = _a.modelName;
14376
14430
  return "- \"".concat(modelName, "\"");
@@ -14768,11 +14822,11 @@ function $execCommand(options) {
14768
14822
  if (isVerbose) {
14769
14823
  console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
14770
14824
  }
14771
- resolve(spaceTrim(output_1.join('\n')));
14825
+ resolve(spaceTrim$1(output_1.join('\n')));
14772
14826
  }
14773
14827
  }
14774
14828
  else {
14775
- resolve(spaceTrim(output_1.join('\n')));
14829
+ resolve(spaceTrim$1(output_1.join('\n')));
14776
14830
  }
14777
14831
  };
14778
14832
  commandProcess.on('close', finishWithCode);
@@ -14789,7 +14843,7 @@ function $execCommand(options) {
14789
14843
  if (isVerbose) {
14790
14844
  console.warn(error);
14791
14845
  }
14792
- resolve(spaceTrim(output_1.join('\n')));
14846
+ resolve(spaceTrim$1(output_1.join('\n')));
14793
14847
  }
14794
14848
  });
14795
14849
  }
@@ -14991,8 +15045,8 @@ var MarkdownScraper = /** @class */ (function () {
14991
15045
  switch (_c.label) {
14992
15046
  case 0:
14993
15047
  name = "piece-".concat(i);
14994
- title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
14995
- knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
15048
+ title = spaceTrim(knowledgeTextPiece.substring(0, 100));
15049
+ knowledgePieceContent = spaceTrim(knowledgeTextPiece);
14996
15050
  keywords = [];
14997
15051
  index = [];
14998
15052
  _c.label = 1;
@@ -15002,7 +15056,7 @@ var MarkdownScraper = /** @class */ (function () {
15002
15056
  case 2:
15003
15057
  titleResult = _c.sent();
15004
15058
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
15005
- title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
15059
+ title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
15006
15060
  name = titleToName(title);
15007
15061
  return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
15008
15062
  case 3:
@@ -15168,7 +15222,7 @@ var DocumentScraper = /** @class */ (function () {
15168
15222
  case 4:
15169
15223
  // Note: [0]
15170
15224
  if (!(_g.sent())) {
15171
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
15225
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
15172
15226
  }
15173
15227
  _g.label = 5;
15174
15228
  case 5: return [2 /*return*/, cacheFilehandler];
@@ -15341,7 +15395,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
15341
15395
  case 4:
15342
15396
  files_1 = _g.sent();
15343
15397
  if (files_1.length !== 1) {
15344
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
15398
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
15345
15399
  }
15346
15400
  file = files_1[0];
15347
15401
  return [4 /*yield*/, rename(join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
@@ -15353,7 +15407,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
15353
15407
  return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
15354
15408
  case 7:
15355
15409
  if (!(_g.sent())) {
15356
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n File that was supposed to be created by LibreOffice does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
15410
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n File that was supposed to be created by LibreOffice does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
15357
15411
  }
15358
15412
  _g.label = 8;
15359
15413
  case 8: return [2 /*return*/, cacheFilehandler];