@promptbook/cli 0.77.0 → 0.78.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/README.md +5 -1
  2. package/esm/index.es.js +202 -141
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +8 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +4 -8
  7. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  8. package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
  9. package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
  10. package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
  11. package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
  12. package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
  13. package/esm/typings/src/errors/0-index.d.ts +46 -1
  14. package/esm/typings/src/errors/utils/ErrorJson.d.ts +2 -2
  15. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
  16. package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
  17. package/package.json +1 -1
  18. package/umd/index.umd.js +202 -141
  19. package/umd/index.umd.js.map +1 -1
  20. /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
  21. /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
  22. /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
  23. /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/cli`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -92,7 +96,7 @@ There is also a javascript and json format available.
92
96
  ## Prettify
93
97
 
94
98
  ```bash
95
- npx ptbk prettify promptbook/**/*.book.md
99
+ npx ptbk prettify 'promptbook/**/*.book.md'
96
100
  ```
97
101
 
98
102
  This will prettify all promptbooks in `promptbook` directory and adds Mermaid graphs to them.
package/esm/index.es.js CHANGED
@@ -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.0-6';
40
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
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
@@ -756,6 +756,84 @@ function stringifyPipelineJson(pipeline) {
756
756
  * TODO: [🍙] Make some standard order of json properties
757
757
  */
758
758
 
759
+ /**
760
+ * Checks if the file exists
761
+ *
762
+ * @private within the repository
763
+ */
764
+ function isFileExisting(filename, fs) {
765
+ return __awaiter(this, void 0, void 0, function () {
766
+ var isReadAccessAllowed, isFile;
767
+ return __generator(this, function (_a) {
768
+ switch (_a.label) {
769
+ case 0: return [4 /*yield*/, fs
770
+ .access(filename, fs.constants.R_OK)
771
+ .then(function () { return true; })
772
+ .catch(function () { return false; })];
773
+ case 1:
774
+ isReadAccessAllowed = _a.sent();
775
+ if (!isReadAccessAllowed) {
776
+ return [2 /*return*/, false];
777
+ }
778
+ return [4 /*yield*/, fs
779
+ .stat(filename)
780
+ .then(function (fileStat) { return fileStat.isFile(); })
781
+ .catch(function () { return false; })];
782
+ case 2:
783
+ isFile = _a.sent();
784
+ return [2 /*return*/, isFile];
785
+ }
786
+ });
787
+ });
788
+ }
789
+ /**
790
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
791
+ * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
792
+ * TODO: [🖇] What about symlinks?
793
+ */
794
+
795
+ /**
796
+ * Removes emojis from a string and fix whitespaces
797
+ *
798
+ * @param text with emojis
799
+ * @returns text without emojis
800
+ * @public exported from `@promptbook/utils`
801
+ */
802
+ function removeEmojis(text) {
803
+ // Replace emojis (and also ZWJ sequence) with hyphens
804
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
805
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
806
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
807
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
808
+ return text;
809
+ }
810
+
811
+ /**
812
+ * Tests if given string is valid URL.
813
+ *
814
+ * Note: This does not check if the file exists only if the path is valid
815
+ * @public exported from `@promptbook/utils`
816
+ */
817
+ function isValidFilePath(filename) {
818
+ if (typeof filename !== 'string') {
819
+ return false;
820
+ }
821
+ var filenameSlashes = filename.split('\\').join('/');
822
+ // Absolute Unix path: /hello.txt
823
+ if (/^(\/)/i.test(filenameSlashes)) {
824
+ return true;
825
+ }
826
+ // Absolute Windows path: /hello.txt
827
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
828
+ return true;
829
+ }
830
+ // Relative path: ./hello.txt
831
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
832
+ return true;
833
+ }
834
+ return false;
835
+ }
836
+
759
837
  /**
760
838
  * Tests if given string is valid URL.
761
839
  *
@@ -1108,48 +1186,6 @@ function normalizeToKebabCase(text) {
1108
1186
  * Note: [💞] Ignore a discrepancy between file name and entity name
1109
1187
  */
1110
1188
 
1111
- /**
1112
- * Removes emojis from a string and fix whitespaces
1113
- *
1114
- * @param text with emojis
1115
- * @returns text without emojis
1116
- * @public exported from `@promptbook/utils`
1117
- */
1118
- function removeEmojis(text) {
1119
- // Replace emojis (and also ZWJ sequence) with hyphens
1120
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1121
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1122
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1123
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
1124
- return text;
1125
- }
1126
-
1127
- /**
1128
- * Tests if given string is valid URL.
1129
- *
1130
- * Note: This does not check if the file exists only if the path is valid
1131
- * @public exported from `@promptbook/utils`
1132
- */
1133
- function isValidFilePath(filename) {
1134
- if (typeof filename !== 'string') {
1135
- return false;
1136
- }
1137
- var filenameSlashes = filename.split('\\').join('/');
1138
- // Absolute Unix path: /hello.txt
1139
- if (/^(\/)/i.test(filenameSlashes)) {
1140
- return true;
1141
- }
1142
- // Absolute Windows path: /hello.txt
1143
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1144
- return true;
1145
- }
1146
- // Relative path: ./hello.txt
1147
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1148
- return true;
1149
- }
1150
- return false;
1151
- }
1152
-
1153
1189
  /**
1154
1190
  * @@@
1155
1191
  *
@@ -1174,42 +1210,6 @@ function titleToName(value) {
1174
1210
  return value;
1175
1211
  }
1176
1212
 
1177
- /**
1178
- * Checks if the file exists
1179
- *
1180
- * @private within the repository
1181
- */
1182
- function isFileExisting(filename, fs) {
1183
- return __awaiter(this, void 0, void 0, function () {
1184
- var isReadAccessAllowed, isFile;
1185
- return __generator(this, function (_a) {
1186
- switch (_a.label) {
1187
- case 0: return [4 /*yield*/, fs
1188
- .access(filename, fs.constants.R_OK)
1189
- .then(function () { return true; })
1190
- .catch(function () { return false; })];
1191
- case 1:
1192
- isReadAccessAllowed = _a.sent();
1193
- if (!isReadAccessAllowed) {
1194
- return [2 /*return*/, false];
1195
- }
1196
- return [4 /*yield*/, fs
1197
- .stat(filename)
1198
- .then(function (fileStat) { return fileStat.isFile(); })
1199
- .catch(function () { return false; })];
1200
- case 2:
1201
- isFile = _a.sent();
1202
- return [2 /*return*/, isFile];
1203
- }
1204
- });
1205
- });
1206
- }
1207
- /**
1208
- * Note: Not [~🟢~] because it is not directly dependent on `fs
1209
- * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
1210
- * TODO: [🖇] What about symlinks?
1211
- */
1212
-
1213
1213
  /**
1214
1214
  * @@@
1215
1215
  *
@@ -3623,7 +3623,7 @@ var LimitReachedError = /** @class */ (function (_super) {
3623
3623
  *
3624
3624
  * @public exported from `@promptbook/core`
3625
3625
  */
3626
- var ERRORS = {
3626
+ var PROMPTBOOK_ERRORS = {
3627
3627
  AbstractFormatError: AbstractFormatError,
3628
3628
  CsvFormatError: CsvFormatError,
3629
3629
  CollectionError: CollectionError,
@@ -3641,6 +3641,35 @@ var ERRORS = {
3641
3641
  UnexpectedError: UnexpectedError,
3642
3642
  // TODO: [🪑]> VersionMismatchError,
3643
3643
  };
3644
+ /**
3645
+ * Index of all javascript errors
3646
+ *
3647
+ * @private for internal usage
3648
+ */
3649
+ var COMMON_JAVASCRIPT_ERRORS = {
3650
+ Error: Error,
3651
+ EvalError: EvalError,
3652
+ RangeError: RangeError,
3653
+ ReferenceError: ReferenceError,
3654
+ SyntaxError: SyntaxError,
3655
+ TypeError: TypeError,
3656
+ URIError: URIError,
3657
+ AggregateError: AggregateError,
3658
+ /*
3659
+ Note: Not widely supported
3660
+ > InternalError,
3661
+ > ModuleError,
3662
+ > HeapError,
3663
+ > WebAssemblyCompileError,
3664
+ > WebAssemblyRuntimeError,
3665
+ */
3666
+ };
3667
+ /**
3668
+ * Index of all errors
3669
+ *
3670
+ * @private for internal usage
3671
+ */
3672
+ var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
3644
3673
  /**
3645
3674
  * Note: [💞] Ignore a discrepancy between file name and entity name
3646
3675
  */
@@ -3651,11 +3680,11 @@ var ERRORS = {
3651
3680
  * @public exported from `@promptbook/utils`
3652
3681
  */
3653
3682
  function deserializeError(error) {
3654
- if (error.name === 'Error') {
3655
- return new Error(error.message);
3683
+ var ErrorClass = ALL_ERRORS[error.name];
3684
+ if (ErrorClass === undefined) {
3685
+ return new Error("".concat(error.name, ": ").concat(error.message));
3656
3686
  }
3657
- var CustomError = ERRORS[error.name];
3658
- return new CustomError(error.message);
3687
+ return new ErrorClass(error.message);
3659
3688
  }
3660
3689
 
3661
3690
  /**
@@ -3729,8 +3758,8 @@ function isPipelinePrepared(pipeline) {
3729
3758
  */
3730
3759
  function serializeError(error) {
3731
3760
  var name = error.name, message = error.message, stack = error.stack;
3732
- if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
3733
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
3761
+ 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 "); }));
3734
3763
  }
3735
3764
  return {
3736
3765
  name: name,
@@ -3745,9 +3774,9 @@ function serializeError(error) {
3745
3774
  * @param script from which to extract the variables
3746
3775
  * @returns the list of variable names
3747
3776
  * @throws {ParseError} if the script is invalid
3748
- * @public exported from `@promptbook/utils`
3777
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3749
3778
  */
3750
- function extractVariables(script) {
3779
+ function extractVariablesFromScript(script) {
3751
3780
  var variables = new Set();
3752
3781
  script = "(()=>{".concat(script, "})()");
3753
3782
  try {
@@ -3794,7 +3823,7 @@ function extractVariables(script) {
3794
3823
  * @param task the task with used parameters
3795
3824
  * @returns the set of parameter names
3796
3825
  * @throws {ParseError} if the script is invalid
3797
- * @public exported from `@promptbook/utils`
3826
+ * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
3798
3827
  */
3799
3828
  function extractParameterNamesFromTask(task) {
3800
3829
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
@@ -3815,7 +3844,7 @@ function extractParameterNamesFromTask(task) {
3815
3844
  }
3816
3845
  if (taskType === 'SCRIPT_TASK') {
3817
3846
  try {
3818
- for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3847
+ for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3819
3848
  var parameterName = _h.value;
3820
3849
  parameterNames.add(parameterName);
3821
3850
  }
@@ -8903,6 +8932,7 @@ function splitMarkdownIntoSections(markdown) {
8903
8932
  var e_1, _a;
8904
8933
  var lines = markdown.split('\n');
8905
8934
  var sections = [];
8935
+ // TODO: [🧽] DRY
8906
8936
  var currentType = 'MARKDOWN';
8907
8937
  var buffer = [];
8908
8938
  var finishSection = function () {
@@ -9043,7 +9073,7 @@ function removeContentComments(content) {
9043
9073
  * @public exported from `@promptbook/core`
9044
9074
  */
9045
9075
  function pipelineStringToJsonSync(pipelineString) {
9046
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
9076
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
9047
9077
  var $pipelineJson = {
9048
9078
  title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
9049
9079
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
@@ -9072,7 +9102,7 @@ function pipelineStringToJsonSync(pipelineString) {
9072
9102
  // =============================================================
9073
9103
  // Note: 1️⃣ Parsing of the markdown into object
9074
9104
  if (pipelineString.startsWith('#!')) {
9075
- var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
9105
+ var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
9076
9106
  if (!(shebangLine_1 || '').includes('ptbk')) {
9077
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 "); }));
9078
9108
  }
@@ -9082,7 +9112,7 @@ function pipelineStringToJsonSync(pipelineString) {
9082
9112
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
9083
9113
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
9084
9114
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
9085
- var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
9115
+ var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
9086
9116
  if (pipelineHead === undefined) {
9087
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 "); }));
9088
9118
  }
@@ -9173,11 +9203,41 @@ function pipelineStringToJsonSync(pipelineString) {
9173
9203
  }
9174
9204
  finally { if (e_1) throw e_1.error; }
9175
9205
  }
9206
+ // =============================================================
9207
+ // Note: 4️⃣ Prepare unique section names with indexes when needed
9208
+ var sectionCounts = {};
9209
+ try {
9210
+ for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
9211
+ var section = pipelineSections_1_1.value;
9212
+ var name_1 = titleToName(section.title);
9213
+ if (sectionCounts[name_1] === undefined) {
9214
+ sectionCounts[name_1] = { count: 0, currentIndex: 0 };
9215
+ }
9216
+ sectionCounts[name_1].count++;
9217
+ }
9218
+ }
9219
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
9220
+ finally {
9221
+ try {
9222
+ if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
9223
+ }
9224
+ finally { if (e_2) throw e_2.error; }
9225
+ }
9226
+ var getUniqueSectionName = function (title) {
9227
+ var name = titleToName(title);
9228
+ var count = sectionCounts[name];
9229
+ if (count.count === 1) {
9230
+ return name;
9231
+ }
9232
+ var nameWithSuffix = "".concat(name, "-").concat(count.currentIndex);
9233
+ count.currentIndex++;
9234
+ return nameWithSuffix;
9235
+ };
9176
9236
  var _loop_2 = function (section) {
9177
- var e_5, _l, e_6, _m;
9237
+ var e_6, _m, e_7, _o;
9178
9238
  // TODO: Parse section's description (the content out of the codeblock and lists)
9179
9239
  var listItems_2 = extractAllListItemsFromMarkdown(section.content);
9180
- var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
9240
+ var _p = extractOneBlockFromMarkdown(section.content), language = _p.language, content = _p.content;
9181
9241
  // TODO: [🎾][1] DRY description
9182
9242
  var description_1 = section.content;
9183
9243
  // Note: Remove codeblocks - TODO: [🎾]
@@ -9193,7 +9253,7 @@ function pipelineStringToJsonSync(pipelineString) {
9193
9253
  isSectionTypeSet: false,
9194
9254
  isTask: true,
9195
9255
  taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
9196
- name: titleToName(section.title),
9256
+ name: getUniqueSectionName(section.title),
9197
9257
  title: section.title,
9198
9258
  description: description_1,
9199
9259
  content: content,
@@ -9241,17 +9301,17 @@ function pipelineStringToJsonSync(pipelineString) {
9241
9301
  };
9242
9302
  try {
9243
9303
  // TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
9244
- for (var commands_1 = (e_5 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
9245
- var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
9304
+ for (var commands_1 = (e_6 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
9305
+ var _q = commands_1_1.value, listItem = _q.listItem, command = _q.command;
9246
9306
  _loop_4(listItem, command);
9247
9307
  }
9248
9308
  }
9249
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
9309
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
9250
9310
  finally {
9251
9311
  try {
9252
- if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
9312
+ if (commands_1_1 && !commands_1_1.done && (_m = commands_1.return)) _m.call(commands_1);
9253
9313
  }
9254
- finally { if (e_5) throw e_5.error; }
9314
+ finally { if (e_6) throw e_6.error; }
9255
9315
  }
9256
9316
  // TODO: [🍧] Should be done in SECTION command
9257
9317
  if ($taskJson.taskType === 'SCRIPT_TASK') {
@@ -9265,8 +9325,8 @@ function pipelineStringToJsonSync(pipelineString) {
9265
9325
  }
9266
9326
  $taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
9267
9327
  try {
9268
- for (var _q = (e_6 = void 0, __values($taskJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
9269
- var parameterName = _r.value;
9328
+ for (var _r = (e_7 = void 0, __values($taskJson.dependentParameterNames)), _s = _r.next(); !_s.done; _s = _r.next()) {
9329
+ var parameterName = _s.value;
9270
9330
  // TODO: [🧠] This definition should be made first in the task
9271
9331
  defineParam({
9272
9332
  parameterName: parameterName,
@@ -9277,12 +9337,12 @@ function pipelineStringToJsonSync(pipelineString) {
9277
9337
  });
9278
9338
  }
9279
9339
  }
9280
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
9340
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
9281
9341
  finally {
9282
9342
  try {
9283
- if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
9343
+ if (_s && !_s.done && (_o = _r.return)) _o.call(_r);
9284
9344
  }
9285
- finally { if (e_6) throw e_6.error; }
9345
+ finally { if (e_7) throw e_7.error; }
9286
9346
  }
9287
9347
  /*
9288
9348
  // TODO: [🍧] This should be checked in `MODEL` command + better error message
@@ -9311,21 +9371,21 @@ function pipelineStringToJsonSync(pipelineString) {
9311
9371
  };
9312
9372
  try {
9313
9373
  // =============================================================
9314
- // Note: 4️⃣ Process each section of the pipeline
9315
- for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
9316
- var section = pipelineSections_1_1.value;
9374
+ // Note: 5️⃣ Process each section of the pipeline
9375
+ for (var pipelineSections_2 = __values(pipelineSections), pipelineSections_2_1 = pipelineSections_2.next(); !pipelineSections_2_1.done; pipelineSections_2_1 = pipelineSections_2.next()) {
9376
+ var section = pipelineSections_2_1.value;
9317
9377
  _loop_2(section);
9318
9378
  }
9319
9379
  }
9320
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
9380
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
9321
9381
  finally {
9322
9382
  try {
9323
- if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
9383
+ if (pipelineSections_2_1 && !pipelineSections_2_1.done && (_c = pipelineSections_2.return)) _c.call(pipelineSections_2);
9324
9384
  }
9325
- finally { if (e_2) throw e_2.error; }
9385
+ finally { if (e_3) throw e_3.error; }
9326
9386
  }
9327
9387
  // =============================================================
9328
- // Note: 5️⃣ Mark parameters as INPUT if not explicitly set
9388
+ // Note: 6️⃣ Mark parameters as INPUT if not explicitly set
9329
9389
  if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
9330
9390
  var _loop_3 = function (parameter) {
9331
9391
  var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
@@ -9334,42 +9394,42 @@ function pipelineStringToJsonSync(pipelineString) {
9334
9394
  }
9335
9395
  };
9336
9396
  try {
9337
- for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
9338
- var parameter = _h.value;
9397
+ for (var _h = __values($pipelineJson.parameters), _j = _h.next(); !_j.done; _j = _h.next()) {
9398
+ var parameter = _j.value;
9339
9399
  _loop_3(parameter);
9340
9400
  }
9341
9401
  }
9342
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
9402
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
9343
9403
  finally {
9344
9404
  try {
9345
- if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
9405
+ if (_j && !_j.done && (_d = _h.return)) _d.call(_h);
9346
9406
  }
9347
- finally { if (e_3) throw e_3.error; }
9407
+ finally { if (e_4) throw e_4.error; }
9348
9408
  }
9349
9409
  }
9350
9410
  // =============================================================
9351
- // Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
9411
+ // Note: 7️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
9352
9412
  if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
9353
9413
  try {
9354
- for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
9355
- var parameter = _k.value;
9414
+ for (var _k = __values($pipelineJson.parameters), _l = _k.next(); !_l.done; _l = _k.next()) {
9415
+ var parameter = _l.value;
9356
9416
  if (!parameter.isInput) {
9357
9417
  parameter.isOutput = true;
9358
9418
  }
9359
9419
  }
9360
9420
  }
9361
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
9421
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
9362
9422
  finally {
9363
9423
  try {
9364
- if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
9424
+ if (_l && !_l.done && (_e = _k.return)) _e.call(_k);
9365
9425
  }
9366
- finally { if (e_4) throw e_4.error; }
9426
+ finally { if (e_5) throw e_5.error; }
9367
9427
  }
9368
9428
  }
9369
9429
  // =============================================================
9370
- // Note: 7️⃣ Cleanup of undefined values
9430
+ // Note: 8️⃣ Cleanup of undefined values
9371
9431
  $pipelineJson.tasks.forEach(function (tasks) {
9372
- var e_7, _a;
9432
+ var e_8, _a;
9373
9433
  try {
9374
9434
  for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
9375
9435
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -9378,16 +9438,16 @@ function pipelineStringToJsonSync(pipelineString) {
9378
9438
  }
9379
9439
  }
9380
9440
  }
9381
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
9441
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
9382
9442
  finally {
9383
9443
  try {
9384
9444
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
9385
9445
  }
9386
- finally { if (e_7) throw e_7.error; }
9446
+ finally { if (e_8) throw e_8.error; }
9387
9447
  }
9388
9448
  });
9389
9449
  $pipelineJson.parameters.forEach(function (parameter) {
9390
- var e_8, _a;
9450
+ var e_9, _a;
9391
9451
  try {
9392
9452
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
9393
9453
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -9396,12 +9456,12 @@ function pipelineStringToJsonSync(pipelineString) {
9396
9456
  }
9397
9457
  }
9398
9458
  }
9399
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
9459
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
9400
9460
  finally {
9401
9461
  try {
9402
9462
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
9403
9463
  }
9404
- finally { if (e_8) throw e_8.error; }
9464
+ finally { if (e_9) throw e_9.error; }
9405
9465
  }
9406
9466
  });
9407
9467
  // =============================================================
@@ -10981,18 +11041,19 @@ function addAutoGeneratedSection(content, options) {
10981
11041
  var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
10982
11042
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
10983
11043
  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 "); });
10984
11045
  if (sectionMatch) {
10985
- return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
11046
+ return content.replace(sectionRegex, contentToInsert);
10986
11047
  }
11048
+ // Note: Following is the case when the section is not found in the file so we add it there
10987
11049
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
10988
- if (!placeForSection) {
10989
- throw new ParseError(
10990
- // <- [🧠] Maybe something better tha `ParseError`
10991
- "No place where to put the section <!--".concat(sectionName, "-->"));
10992
- // <- [🚞]
11050
+ if (placeForSection !== null) {
11051
+ 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 "); }));
10993
11053
  }
10994
- var _a = __read(placeForSection, 1), heading = _a[0];
10995
- return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
11054
+ 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 "); });
10996
11057
  }
10997
11058
  /**
10998
11059
  * TODO: [🏛] This can be part of markdown builder
@@ -11020,7 +11081,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
11020
11081
  if (!task) {
11021
11082
  throw new Error("Could not find task for {".concat(parameterName, "}"));
11022
11083
  }
11023
- return normalizeTo_camelCase('task-' + titleToName(task.title));
11084
+ return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
11024
11085
  };
11025
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
11026
11087
  .flatMap(function (_a) {
@@ -11083,7 +11144,7 @@ function prettifyPipelineString(pipelineString, options) {
11083
11144
  return { href: "#".concat(task.name), title: task.title };
11084
11145
  },
11085
11146
  });
11086
- promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
11147
+ promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
11087
11148
  pipelineString = addAutoGeneratedSection(pipelineString, {
11088
11149
  sectionName: 'Graph',
11089
11150
  sectionContent: promptbookMermaidBlock,