@promptbook/core 0.67.9 → 0.68.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +2 -2
  2. package/esm/index.es.js +1217 -640
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +7 -16
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +20 -24
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  8. package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +1 -1
  9. package/esm/typings/src/commands/BLOCK/blockCommandParser.d.ts +2 -2
  10. package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +14 -6
  11. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -2
  12. package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +9 -0
  13. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +14 -0
  14. package/esm/typings/src/commands/{EXPECT/ExpectFormatCommand.d.ts → FORMAT/FormatCommand.d.ts} +2 -2
  15. package/esm/typings/src/commands/FORMAT/formatCommand.test.d.ts +1 -0
  16. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +9 -0
  17. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +2 -2
  18. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +2 -2
  19. package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +2 -2
  20. package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +2 -2
  21. package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +2 -2
  22. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +2 -2
  23. package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +2 -2
  24. package/esm/typings/src/commands/URL/urlCommandParser.d.ts +2 -2
  25. package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +2 -2
  26. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +2 -2
  27. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +6 -4
  28. package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
  29. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +137 -30
  30. package/esm/typings/src/commands/index.d.ts +1 -1
  31. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  32. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
  33. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -2
  34. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -2
  35. package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +14 -0
  36. package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.test.d.ts +1 -0
  37. package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
  38. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
  39. package/esm/typings/src/errors/{ParsingError.d.ts → ParseError.d.ts} +5 -2
  40. package/esm/typings/src/errors/index.d.ts +2 -2
  41. package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +5 -0
  42. package/esm/typings/src/execution/PromptResult.d.ts +2 -0
  43. package/esm/typings/src/execution/PromptResultUsage.d.ts +1 -1
  44. package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -1
  45. package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  46. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
  47. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +2 -2
  48. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +3 -3
  49. package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -4
  50. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -1
  51. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  52. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +1 -1
  53. package/esm/typings/src/types/ModelRequirements.d.ts +2 -0
  54. package/esm/typings/src/types/PipelineJson/DialogTemplateJson.d.ts +13 -0
  55. package/esm/typings/src/types/PipelineJson/Expectations.d.ts +1 -1
  56. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +1 -1
  57. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  58. package/esm/typings/src/types/PipelineJson/{PromptTemplateParameterJson.d.ts → ParameterJson.d.ts} +2 -2
  59. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
  60. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +10 -5
  61. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  62. package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +20 -9
  63. package/esm/typings/src/types/PipelineJson/{ScriptJson.d.ts → ScriptTemplateJson.d.ts} +4 -4
  64. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +3 -3
  65. package/esm/typings/src/types/PipelineJson/TemplateJson.d.ts +11 -0
  66. package/esm/typings/src/types/PipelineJson/{PromptTemplateJsonCommon.d.ts → TemplateJsonCommon.d.ts} +3 -4
  67. package/esm/typings/src/types/Prompt.d.ts +4 -2
  68. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -0
  69. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  70. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  71. package/esm/typings/src/utils/organization/___and___.d.ts +7 -0
  72. package/esm/typings/src/utils/organization/{___.d.ts → ___or___.d.ts} +1 -1
  73. package/esm/typings/src/utils/parseNumber.d.ts +1 -1
  74. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +1 -1
  75. package/package.json +1 -1
  76. package/umd/index.umd.js +1217 -640
  77. package/umd/index.umd.js.map +1 -1
  78. package/esm/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +0 -17
  79. package/esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +0 -14
  80. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +0 -27
  81. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +0 -14
  82. /package/esm/typings/src/{conversion/utils/extractParameterNamesFromPromptTemplate.test.d.ts → commands/FOREACH/foreachCommand.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -10,7 +10,7 @@ import moment from 'moment';
10
10
  /**
11
11
  * The version of the Promptbook library
12
12
  */
13
- var PROMPTBOOK_VERSION = '0.67.8';
13
+ var PROMPTBOOK_VERSION = '0.68.0-0';
14
14
  // TODO: !!!! List here all the versions and annotate + put into script
15
15
 
16
16
  /*! *****************************************************************************
@@ -211,7 +211,7 @@ function capitalize(word) {
211
211
  */
212
212
  function pipelineJsonToString(pipelineJson) {
213
213
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
214
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
214
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
215
215
  var pipelineString = "# ".concat(title);
216
216
  if (description) {
217
217
  pipelineString += '\n\n';
@@ -231,7 +231,7 @@ function pipelineJsonToString(pipelineJson) {
231
231
  return isInput;
232
232
  })), _h = _g.next(); !_h.done; _h = _g.next()) {
233
233
  var parameter = _h.value;
234
- commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
234
+ commands.push("INPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
235
235
  }
236
236
  }
237
237
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -247,7 +247,7 @@ function pipelineJsonToString(pipelineJson) {
247
247
  return isOutput;
248
248
  })), _k = _j.next(); !_k.done; _k = _j.next()) {
249
249
  var parameter = _k.value;
250
- commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
250
+ commands.push("OUTPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
251
251
  }
252
252
  }
253
253
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -260,13 +260,13 @@ function pipelineJsonToString(pipelineJson) {
260
260
  pipelineString += '\n\n';
261
261
  pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
262
262
  try {
263
- for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
264
- var promptTemplate = promptTemplates_1_1.value;
263
+ for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
264
+ var template = templates_1_1.value;
265
265
  var
266
266
  /* Note: Not using:> name, */
267
- title_1 = promptTemplate.title, description_1 = promptTemplate.description,
267
+ title_1 = template.title, description_1 = template.description,
268
268
  /* Note: dependentParameterNames, */
269
- jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
269
+ jokers = template.jokerParameterNames, blockType = template.blockType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
270
270
  pipelineString += '\n\n';
271
271
  pipelineString += "## ".concat(title_1);
272
272
  if (description_1) {
@@ -277,7 +277,7 @@ function pipelineJsonToString(pipelineJson) {
277
277
  var commands_1 = [];
278
278
  var contentLanguage = 'text';
279
279
  if (blockType === 'PROMPT_TEMPLATE') {
280
- var modelRequirements = promptTemplate.modelRequirements;
280
+ var modelRequirements = template.modelRequirements;
281
281
  var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
282
282
  commands_1.push("EXECUTE PROMPT TEMPLATE");
283
283
  if (modelVariant) {
@@ -291,17 +291,17 @@ function pipelineJsonToString(pipelineJson) {
291
291
  commands_1.push("SIMPLE TEMPLATE");
292
292
  // Note: Nothing special here
293
293
  }
294
- else if (blockType === 'SCRIPT') {
294
+ else if (blockType === 'SCRIPT_TEMPLATE') {
295
295
  commands_1.push("EXECUTE SCRIPT");
296
- if (promptTemplate.contentLanguage) {
297
- contentLanguage = promptTemplate.contentLanguage;
296
+ if (template.contentLanguage) {
297
+ contentLanguage = template.contentLanguage;
298
298
  }
299
299
  else {
300
300
  contentLanguage = '';
301
301
  }
302
302
  }
303
- else if (blockType === 'PROMPT_DIALOG') {
304
- commands_1.push("PROMPT DIALOG");
303
+ else if (blockType === 'DIALOG_TEMPLATE') {
304
+ commands_1.push("DIALOG BLOCK");
305
305
  // Note: Nothing special here
306
306
  } // <- }else if([🅱]
307
307
  if (jokers) {
@@ -359,10 +359,10 @@ function pipelineJsonToString(pipelineJson) {
359
359
  finally { if (e_6) throw e_6.error; }
360
360
  }
361
361
  } /* not else */
362
- if (expectFormat) {
363
- if (expectFormat === 'JSON') {
362
+ if (format) {
363
+ if (format === 'JSON') {
364
364
  // TODO: @deprecated remove
365
- commands_1.push("EXPECT JSON");
365
+ commands_1.push("FORMAT JSON");
366
366
  }
367
367
  } /* not else */
368
368
  pipelineString += '\n\n';
@@ -376,13 +376,13 @@ function pipelineJsonToString(pipelineJson) {
376
376
  pipelineString += '\n';
377
377
  pipelineString += '```';
378
378
  pipelineString += '\n\n';
379
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
379
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use templateParameterJsonToString
380
380
  }
381
381
  }
382
382
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
383
383
  finally {
384
384
  try {
385
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
385
+ if (templates_1_1 && !templates_1_1.done && (_c = templates_1.return)) _c.call(templates_1);
386
386
  }
387
387
  finally { if (e_3) throw e_3.error; }
388
388
  }
@@ -391,8 +391,8 @@ function pipelineJsonToString(pipelineJson) {
391
391
  /**
392
392
  * @private internal utility of `pipelineJsonToString`
393
393
  */
394
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
395
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
394
+ function templateParameterJsonToString(templateParameterJson) {
395
+ var name = templateParameterJson.name, description = templateParameterJson.description;
396
396
  var parameterString = "{".concat(name, "}");
397
397
  if (description) {
398
398
  parameterString = "".concat(parameterString, " ").concat(description);
@@ -400,7 +400,7 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
400
400
  return parameterString;
401
401
  }
402
402
  /**
403
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
403
+ * TODO: !!!!!! Implement new features and commands into `templateParameterJsonToString`
404
404
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
405
405
  * TODO: [🏛] Maybe make some markdown builder
406
406
  * TODO: [🏛] Escape all
@@ -761,16 +761,19 @@ var IS_VERBOSE = false;
761
761
  *
762
762
  * @public exported from `@promptbook/core`
763
763
  */
764
- var ParsingError = /** @class */ (function (_super) {
765
- __extends(ParsingError, _super);
766
- function ParsingError(message) {
764
+ var ParseError = /** @class */ (function (_super) {
765
+ __extends(ParseError, _super);
766
+ function ParseError(message) {
767
767
  var _this = _super.call(this, message) || this;
768
- _this.name = 'ParsingError';
769
- Object.setPrototypeOf(_this, ParsingError.prototype);
768
+ _this.name = 'ParseError';
769
+ Object.setPrototypeOf(_this, ParseError.prototype);
770
770
  return _this;
771
771
  }
772
- return ParsingError;
772
+ return ParseError;
773
773
  }(Error));
774
+ /**
775
+ * TODO: Maybe split `ParseError` and `ApplyError`
776
+ */
774
777
 
775
778
  /**
776
779
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
@@ -982,12 +985,12 @@ function validatePipeline(pipeline) {
982
985
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
983
986
  if (!Array.isArray(pipeline.parameters)) {
984
987
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
985
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
988
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
986
989
  }
987
990
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
988
- if (!Array.isArray(pipeline.promptTemplates)) {
991
+ if (!Array.isArray(pipeline.templates)) {
989
992
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
990
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
993
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.templates` expected to be an array, but got ".concat(typeof pipeline.templates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
991
994
  }
992
995
  var _loop_1 = function (parameter) {
993
996
  if (parameter.isInput && parameter.isOutput) {
@@ -996,12 +999,12 @@ function validatePipeline(pipeline) {
996
999
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
997
1000
  if (!parameter.isInput &&
998
1001
  !parameter.isOutput &&
999
- !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1002
+ !pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1000
1003
  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 "); }));
1001
1004
  }
1002
1005
  // Note: Testing that parameter is either input or result of some template
1003
1006
  if (!parameter.isInput &&
1004
- !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1007
+ !pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1005
1008
  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 - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
1006
1009
  }
1007
1010
  };
@@ -1037,7 +1040,7 @@ function validatePipeline(pipeline) {
1037
1040
  }
1038
1041
  definedParameters.add(template.resultingParameterName);
1039
1042
  if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1040
- if (!template.expectFormat &&
1043
+ if (!template.format &&
1041
1044
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1042
1045
  throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1043
1046
  }
@@ -1089,7 +1092,7 @@ function validatePipeline(pipeline) {
1089
1092
  };
1090
1093
  try {
1091
1094
  // Note: Checking each template individually
1092
- for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
1095
+ for (var _f = __values(pipeline.templates), _g = _f.next(); !_g.done; _g = _f.next()) {
1093
1096
  var template = _g.value;
1094
1097
  _loop_2(template);
1095
1098
  }
@@ -1125,8 +1128,7 @@ function validatePipeline(pipeline) {
1125
1128
  }
1126
1129
  finally { if (e_3) throw e_3.error; }
1127
1130
  }
1128
- var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
1129
- // <- TODO: [🧠][🥜]
1131
+ var unresovedTemplates = __spreadArray([], __read(pipeline.templates), false);
1130
1132
  var loopLimit = LOOP_LIMIT;
1131
1133
  var _loop_3 = function () {
1132
1134
  if (loopLimit-- < 0) {
@@ -1139,14 +1141,14 @@ function validatePipeline(pipeline) {
1139
1141
  if (currentlyResovedTemplates.length === 0) {
1140
1142
  throw new PipelineLogicError(
1141
1143
  // TODO: [🐎] DRY
1142
- 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 Can not resolve:\n ".concat(block(unresovedTemplates
1144
+ 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(unresovedTemplates
1143
1145
  .map(function (_a) {
1144
1146
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1145
1147
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
1146
1148
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1147
1149
  .join(' and '));
1148
1150
  })
1149
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1151
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n\n "); }));
1150
1152
  }
1151
1153
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1152
1154
  var resultingParameterName = _a.resultingParameterName;
@@ -1246,23 +1248,23 @@ function extractParameterNames(template) {
1246
1248
  * @public exported from `@promptbook/core`
1247
1249
  */
1248
1250
  function unpreparePipeline(pipeline) {
1249
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1251
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, templates = pipeline.templates;
1250
1252
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1251
1253
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1252
- promptTemplates = promptTemplates.map(function (promptTemplate) {
1253
- var dependentParameterNames = promptTemplate.dependentParameterNames;
1254
- var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
1254
+ templates = templates.map(function (template) {
1255
+ var dependentParameterNames = template.dependentParameterNames;
1256
+ var parameterNames = extractParameterNames(template.preparedContent || '');
1255
1257
  dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1256
- var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
1257
- delete promptTemplateUnprepared.preparedContent;
1258
- return promptTemplateUnprepared;
1258
+ var templateUnprepared = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames });
1259
+ delete templateUnprepared.preparedContent;
1260
+ return templateUnprepared;
1259
1261
  });
1260
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1262
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { templates: templates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1261
1263
  }
1262
1264
  /**
1263
1265
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1264
1266
  * TODO: Write tests for `preparePipeline`
1265
- * TODO: [🍙] Make some standart order of json properties
1267
+ * TODO: [🍙] Make some standard order of json properties
1266
1268
  */
1267
1269
 
1268
1270
  /**
@@ -1581,8 +1583,8 @@ function createSubcollection(collection, predicate) {
1581
1583
  var BlockTypes = [
1582
1584
  'PROMPT_TEMPLATE',
1583
1585
  'SIMPLE_TEMPLATE',
1584
- 'SCRIPT',
1585
- 'PROMPT_DIALOG',
1586
+ 'SCRIPT_TEMPLATE',
1587
+ 'DIALOG_TEMPLATE',
1586
1588
  'SAMPLE',
1587
1589
  'KNOWLEDGE',
1588
1590
  'INSTRUMENT',
@@ -1786,7 +1788,7 @@ function forEachAsync(array, options, callbackfunction) {
1786
1788
  });
1787
1789
  }
1788
1790
 
1789
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.8",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.8",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.8",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.8",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1791
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1790
1792
 
1791
1793
  var defaultDiacriticsRemovalMap = [
1792
1794
  {
@@ -2262,7 +2264,7 @@ var ERRORS = {
2262
2264
  LimitReachedError: LimitReachedError,
2263
2265
  NotFoundError: NotFoundError,
2264
2266
  NotYetImplementedError: NotYetImplementedError,
2265
- ParsingError: ParsingError,
2267
+ ParseError: ParseError,
2266
2268
  PipelineExecutionError: PipelineExecutionError,
2267
2269
  PipelineLogicError: PipelineLogicError,
2268
2270
  PipelineUrlError: PipelineUrlError,
@@ -2319,7 +2321,7 @@ function assertsExecutionSuccessful(executionResult) {
2319
2321
  *
2320
2322
  * @param script from which to extract the variables
2321
2323
  * @returns the list of variable names
2322
- * @throws {ParsingError} if the script is invalid
2324
+ * @throws {ParseError} if the script is invalid
2323
2325
  * @public exported from `@promptbook/utils`
2324
2326
  */
2325
2327
  function extractVariables(script) {
@@ -2355,7 +2357,7 @@ function extractVariables(script) {
2355
2357
  if (!(error instanceof Error)) {
2356
2358
  throw error;
2357
2359
  }
2358
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2360
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2359
2361
  }
2360
2362
  return variables;
2361
2363
  }
@@ -2366,14 +2368,14 @@ function extractVariables(script) {
2366
2368
  /**
2367
2369
  * Parses the prompt template and returns the set of all used parameters
2368
2370
  *
2369
- * @param promptTemplate the template with used parameters
2371
+ * @param template the template with used parameters
2370
2372
  * @returns the set of parameter names
2371
- * @throws {ParsingError} if the script is invalid
2373
+ * @throws {ParseError} if the script is invalid
2372
2374
  * @public exported from `@promptbook/utils`
2373
2375
  */
2374
- function extractParameterNamesFromPromptTemplate(promptTemplate) {
2376
+ function extractParameterNamesFromTemplate(template) {
2375
2377
  var e_1, _a, e_2, _b, e_3, _c;
2376
- var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
2378
+ var title = template.title, description = template.description, blockType = template.blockType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
2377
2379
  var parameterNames = new Set();
2378
2380
  try {
2379
2381
  for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
@@ -2388,7 +2390,7 @@ function extractParameterNamesFromPromptTemplate(promptTemplate) {
2388
2390
  }
2389
2391
  finally { if (e_1) throw e_1.error; }
2390
2392
  }
2391
- if (blockType === 'SCRIPT') {
2393
+ if (blockType === 'SCRIPT_TEMPLATE') {
2392
2394
  try {
2393
2395
  for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
2394
2396
  var parameterName = _g.value;
@@ -2766,7 +2768,7 @@ function joinLlmExecutionTools() {
2766
2768
  *
2767
2769
  * @param markdown any valid markdown
2768
2770
  * @returns code blocks with language and content
2769
- * @throws {ParsingError} if block is not closed properly
2771
+ * @throws {ParseError} if block is not closed properly
2770
2772
  * @public exported from `@promptbook/markdown-utils`
2771
2773
  */
2772
2774
  function extractAllBlocksFromMarkdown(markdown) {
@@ -2802,7 +2804,7 @@ function extractAllBlocksFromMarkdown(markdown) {
2802
2804
  }
2803
2805
  else {
2804
2806
  if (language !== null) {
2805
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2807
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2806
2808
  }
2807
2809
  codeBlocks.push(currentCodeBlock);
2808
2810
  currentCodeBlock = null;
@@ -2824,7 +2826,7 @@ function extractAllBlocksFromMarkdown(markdown) {
2824
2826
  finally { if (e_1) throw e_1.error; }
2825
2827
  }
2826
2828
  if (currentCodeBlock !== null) {
2827
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2829
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2828
2830
  }
2829
2831
  return codeBlocks;
2830
2832
  }
@@ -2836,8 +2838,8 @@ function extractAllBlocksFromMarkdown(markdown) {
2836
2838
  * Extracts extracts exactly one valid JSON code block
2837
2839
  *
2838
2840
  * - When given string is a valid JSON as it is, it just returns it
2839
- * - When there is no JSON code block the function throws a `ParsingError`
2840
- * - When there are multiple JSON code blocks the function throws a `ParsingError`
2841
+ * - When there is no JSON code block the function throws a `ParseError`
2842
+ * - When there are multiple JSON code blocks the function throws a `ParseError`
2841
2843
  *
2842
2844
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
2843
2845
  * Note: There are multiple simmilar function:
@@ -2847,7 +2849,7 @@ function extractAllBlocksFromMarkdown(markdown) {
2847
2849
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2848
2850
  *
2849
2851
  * @public exported from `@promptbook/markdown-utils`
2850
- * @throws {ParsingError} if there is no valid JSON block in the markdown
2852
+ * @throws {ParseError} if there is no valid JSON block in the markdown
2851
2853
  */
2852
2854
  function extractJsonBlock(markdown) {
2853
2855
  if (isValidJsonString(markdown)) {
@@ -2886,8 +2888,8 @@ function isPipelinePrepared(pipeline) {
2886
2888
  return false;
2887
2889
  }
2888
2890
  /*
2889
- TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2890
- > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2891
+ TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
2892
+ > if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
2891
2893
  > return false;
2892
2894
  > }
2893
2895
  */
@@ -3296,8 +3298,7 @@ function createPipelineExecutor(options) {
3296
3298
  }
3297
3299
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
3298
3300
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
3299
- function getContextForTemplate(// <- TODO: [🧠][🥜]
3300
- template) {
3301
+ function getContextForTemplate(template) {
3301
3302
  return __awaiter(this, void 0, void 0, function () {
3302
3303
  return __generator(this, function (_a) {
3303
3304
  TODO_USE(template);
@@ -3305,8 +3306,7 @@ function createPipelineExecutor(options) {
3305
3306
  });
3306
3307
  });
3307
3308
  }
3308
- function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
3309
- template) {
3309
+ function getKnowledgeForTemplate(template) {
3310
3310
  return __awaiter(this, void 0, void 0, function () {
3311
3311
  return __generator(this, function (_a) {
3312
3312
  // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
@@ -3318,8 +3318,7 @@ function createPipelineExecutor(options) {
3318
3318
  });
3319
3319
  });
3320
3320
  }
3321
- function getSamplesForTemplate(// <- TODO: [🧠][🥜]
3322
- template) {
3321
+ function getSamplesForTemplate(template) {
3323
3322
  return __awaiter(this, void 0, void 0, function () {
3324
3323
  return __generator(this, function (_a) {
3325
3324
  // TODO: [♨] Implement Better - use real index and keyword search
@@ -3386,7 +3385,7 @@ function createPipelineExecutor(options) {
3386
3385
  case 0:
3387
3386
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
3388
3387
  title = currentTemplate.title;
3389
- priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
3388
+ priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3390
3389
  if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
3391
3390
  progress_1 = {
3392
3391
  name: name,
@@ -3409,7 +3408,7 @@ function createPipelineExecutor(options) {
3409
3408
  _h.sent();
3410
3409
  _h.label = 2;
3411
3410
  case 2:
3412
- usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3411
+ usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3413
3412
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3414
3413
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3415
3414
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
@@ -3458,13 +3457,13 @@ function createPipelineExecutor(options) {
3458
3457
  result = null;
3459
3458
  resultString = null;
3460
3459
  expectError = null;
3461
- maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
3460
+ maxAttempts = currentTemplate.blockType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3462
3461
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3463
3462
  preparedContent = (currentTemplate.preparedContent || '{content}')
3464
3463
  .split('{content}')
3465
3464
  .join(currentTemplate.content);
3466
3465
  _loop_5 = function (attempt) {
3467
- var isJokerAttempt, jokerParameterName, _j, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
3466
+ var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
3468
3467
  var e_5, _s, e_7, _t, e_6, _u;
3469
3468
  return __generator(this, function (_v) {
3470
3469
  switch (_v.label) {
@@ -3494,14 +3493,15 @@ function createPipelineExecutor(options) {
3494
3493
  switch (_j) {
3495
3494
  case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3496
3495
  case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3497
- case 'SCRIPT': return [3 /*break*/, 12];
3498
- case 'PROMPT_DIALOG': return [3 /*break*/, 23];
3496
+ case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
3497
+ case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
3499
3498
  }
3500
3499
  return [3 /*break*/, 25];
3501
3500
  case 2:
3502
3501
  resultString = replaceParameters(preparedContent, parameters);
3503
3502
  return [3 /*break*/, 26];
3504
3503
  case 3:
3504
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3505
3505
  prompt = {
3506
3506
  title: currentTemplate.title,
3507
3507
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
@@ -3509,15 +3509,15 @@ function createPipelineExecutor(options) {
3509
3509
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3510
3510
  parameters: parameters,
3511
3511
  content: preparedContent,
3512
- modelRequirements: currentTemplate.modelRequirements,
3512
+ modelRequirements: modelRequirements,
3513
3513
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3514
3514
  var name = _a.name;
3515
3515
  return name === currentTemplate.personaName;
3516
3516
  }) || {})), currentTemplate.expectations),
3517
- expectFormat: currentTemplate.expectFormat,
3517
+ format: currentTemplate.format,
3518
3518
  postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3519
3519
  }; // <- TODO: Not very good type guard
3520
- _k = currentTemplate.modelRequirements.modelVariant;
3520
+ _k = modelRequirements.modelVariant;
3521
3521
  switch (_k) {
3522
3522
  case 'CHAT': return [3 /*break*/, 4];
3523
3523
  case 'COMPLETION': return [3 /*break*/, 6];
@@ -3543,7 +3543,8 @@ function createPipelineExecutor(options) {
3543
3543
  result = embeddingResult;
3544
3544
  resultString = embeddingResult.content.join(',');
3545
3545
  return [3 /*break*/, 11];
3546
- case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n\n "); }));
3546
+ case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
3547
+ .modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3547
3548
  case 11: return [3 /*break*/, 26];
3548
3549
  case 12:
3549
3550
  if (arrayableToArray(tools.script).length === 0) {
@@ -3622,7 +3623,7 @@ function createPipelineExecutor(options) {
3622
3623
  priority: priority,
3623
3624
  }))];
3624
3625
  case 24:
3625
- // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
3626
+ // TODO: [🌹] When making next attempt for `DIALOG BLOCK`, preserve the previous user input
3626
3627
  resultString = _v.sent();
3627
3628
  return [3 /*break*/, 26];
3628
3629
  case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -3708,8 +3709,8 @@ function createPipelineExecutor(options) {
3708
3709
  return [7 /*endfinally*/];
3709
3710
  case 43:
3710
3711
  // TODO: [💝] Unite object for expecting amount and format
3711
- if (currentTemplate.expectFormat) {
3712
- if (currentTemplate.expectFormat === 'JSON') {
3712
+ if (currentTemplate.format) {
3713
+ if (currentTemplate.format === 'JSON') {
3713
3714
  if (!isValidJsonString(resultString || '')) {
3714
3715
  // TODO: [🏢] Do more universally via `FormatDefinition`
3715
3716
  try {
@@ -3723,7 +3724,7 @@ function createPipelineExecutor(options) {
3723
3724
  }
3724
3725
  }
3725
3726
  else {
3726
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3727
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3727
3728
  }
3728
3729
  }
3729
3730
  // TODO: [💝] Unite object for expecting amount and format
@@ -3999,7 +4000,7 @@ function createPipelineExecutor(options) {
3999
4000
  var name = _a.name;
4000
4001
  return name;
4001
4002
  });
4002
- unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.promptTemplates), false);
4003
+ unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.templates), false);
4003
4004
  resolving_1 = [];
4004
4005
  loopLimit = LOOP_LIMIT;
4005
4006
  _loop_2 = function () {
@@ -4120,7 +4121,7 @@ function createPipelineExecutor(options) {
4120
4121
  * TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
4121
4122
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
4122
4123
  * TODO: [♈] Probbably move expectations from templates to parameters
4123
- * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
4124
+ * TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
4124
4125
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
4125
4126
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
4126
4127
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
@@ -4490,7 +4491,7 @@ function preparePersona(personaDescription, options) {
4490
4491
  */
4491
4492
  function clonePipeline(pipeline) {
4492
4493
  // Note: Not using spread operator (...) because @@@
4493
- var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
4494
+ var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
4494
4495
  return {
4495
4496
  pipelineUrl: pipelineUrl,
4496
4497
  sourceFile: sourceFile,
@@ -4498,7 +4499,7 @@ function clonePipeline(pipeline) {
4498
4499
  promptbookVersion: promptbookVersion,
4499
4500
  description: description,
4500
4501
  parameters: parameters,
4501
- promptTemplates: promptTemplates,
4502
+ templates: templates,
4502
4503
  knowledgeSources: knowledgeSources,
4503
4504
  knowledgePieces: knowledgePieces,
4504
4505
  personas: personas,
@@ -4506,7 +4507,7 @@ function clonePipeline(pipeline) {
4506
4507
  };
4507
4508
  }
4508
4509
  /**
4509
- * TODO: [🍙] Make some standart order of json properties
4510
+ * TODO: [🍙] Make some standard order of json properties
4510
4511
  */
4511
4512
 
4512
4513
  /**
@@ -4516,19 +4517,19 @@ function clonePipeline(pipeline) {
4516
4517
  */
4517
4518
  function prepareTemplates(pipeline, options) {
4518
4519
  return __awaiter(this, void 0, void 0, function () {
4519
- var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
4520
+ var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
4520
4521
  var _this = this;
4521
4522
  return __generator(this, function (_b) {
4522
4523
  switch (_b.label) {
4523
4524
  case 0:
4524
4525
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
4525
- promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4526
+ templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4526
4527
  // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
4527
4528
  TODO_USE(parameters);
4528
- promptTemplatesPrepared = new Array(
4529
+ templatesPrepared = new Array(
4529
4530
  // <- TODO: [🧱] Implement in a functional (not new Class) way
4530
- promptTemplates.length);
4531
- return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
4531
+ templates.length);
4532
+ return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
4532
4533
  var dependentParameterNames, preparedContent, preparedTemplate;
4533
4534
  return __generator(this, function (_a) {
4534
4535
  dependentParameterNames = template.dependentParameterNames;
@@ -4541,13 +4542,13 @@ function prepareTemplates(pipeline, options) {
4541
4542
  ], false);
4542
4543
  }
4543
4544
  preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
4544
- promptTemplatesPrepared[index] = preparedTemplate;
4545
+ templatesPrepared[index] = preparedTemplate;
4545
4546
  return [2 /*return*/];
4546
4547
  });
4547
4548
  }); })];
4548
4549
  case 1:
4549
4550
  _b.sent();
4550
- return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
4551
+ return [2 /*return*/, { templatesPrepared: templatesPrepared }];
4551
4552
  }
4552
4553
  });
4553
4554
  });
@@ -4560,7 +4561,6 @@ function prepareTemplates(pipeline, options) {
4560
4561
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4561
4562
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
4562
4563
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4563
- * TODO: [🧠][🥜]
4564
4564
  */
4565
4565
 
4566
4566
  /**
@@ -4573,12 +4573,12 @@ function prepareTemplates(pipeline, options) {
4573
4573
  */
4574
4574
  function preparePipeline(pipeline, options) {
4575
4575
  return __awaiter(this, void 0, void 0, function () {
4576
- var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
4576
+ var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, templates,
4577
4577
  /*
4578
4578
  <- TODO: [🧠][🪑] `promptbookVersion` */
4579
4579
  knowledgeSources /*
4580
4580
  <- TODO: [🧊] `knowledgePieces` */, personas /*
4581
- <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
4581
+ <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
4582
4582
  var _this = this;
4583
4583
  return __generator(this, function (_c) {
4584
4584
  switch (_c.label) {
@@ -4587,7 +4587,7 @@ function preparePipeline(pipeline, options) {
4587
4587
  return [2 /*return*/, pipeline];
4588
4588
  }
4589
4589
  llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
4590
- parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4590
+ parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4591
4591
  llmToolsWithUsage = countTotalUsage(llmTools);
4592
4592
  currentPreparation = {
4593
4593
  id: 1,
@@ -4633,7 +4633,7 @@ function preparePipeline(pipeline, options) {
4633
4633
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
4634
4634
  return [4 /*yield*/, prepareTemplates({
4635
4635
  parameters: parameters,
4636
- promptTemplates: promptTemplates,
4636
+ templates: templates,
4637
4637
  knowledgePiecesCount: knowledgePiecesPrepared.length,
4638
4638
  }, {
4639
4639
  llmTools: llmToolsWithUsage,
@@ -4641,11 +4641,11 @@ function preparePipeline(pipeline, options) {
4641
4641
  isVerbose: isVerbose,
4642
4642
  })];
4643
4643
  case 3:
4644
- promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
4644
+ templatesPrepared = (_c.sent()).templatesPrepared;
4645
4645
  // ----- /Templates preparation -----
4646
4646
  // Note: Count total usage
4647
4647
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
4648
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4648
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: templatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4649
4649
  }
4650
4650
  });
4651
4651
  });
@@ -4699,7 +4699,8 @@ var knowledgeCommandParser = {
4699
4699
  /**
4700
4700
  * BOILERPLATE command can be used in:
4701
4701
  */
4702
- usagePlaces: ['PIPELINE_HEAD'],
4702
+ isUsedInPipelineHead: true,
4703
+ isUsedInPipelineTemplate: false,
4703
4704
  /**
4704
4705
  * Description of the KNOWLEDGE command
4705
4706
  */
@@ -4725,17 +4726,17 @@ var knowledgeCommandParser = {
4725
4726
  var args = input.args;
4726
4727
  var sourceContent = spaceTrim(args[0] || '');
4727
4728
  if (sourceContent === '') {
4728
- throw new ParsingError("Source is not defined");
4729
+ throw new ParseError("Source is not defined");
4729
4730
  }
4730
4731
  // TODO: !!!! Following checks should be applied every link in the `sourceContent`
4731
4732
  if (sourceContent.startsWith('http://')) {
4732
- throw new ParsingError("Source is not secure");
4733
+ throw new ParseError("Source is not secure");
4733
4734
  }
4734
4735
  if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
4735
- throw new ParsingError("Source not valid");
4736
+ throw new ParseError("Source not valid");
4736
4737
  }
4737
4738
  if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
4738
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
4739
+ throw new ParseError("Source cannot be outside of the .ptbk.md folder");
4739
4740
  }
4740
4741
  return {
4741
4742
  type: 'KNOWLEDGE',
@@ -4743,194 +4744,40 @@ var knowledgeCommandParser = {
4743
4744
  };
4744
4745
  },
4745
4746
  /**
4746
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4747
+ * Apply the KNOWLEDGE command to the `pipelineJson`
4748
+ *
4749
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
4747
4750
  */
4748
- applyToPipelineJson: function (personaCommand, subjects) {
4749
- var sourceContent = personaCommand.sourceContent;
4750
- var pipelineJson = subjects.pipelineJson;
4751
+ $applyToPipelineJson: function (command, $pipelineJson) {
4752
+ var sourceContent = command.sourceContent;
4751
4753
  var name = 'source-' + sha256(hexEncoder.parse(JSON.stringify(sourceContent))).toString( /* hex */);
4752
4754
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
4753
4755
  // <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
4754
- pipelineJson.knowledgeSources.push({
4756
+ $pipelineJson.knowledgeSources.push({
4755
4757
  name: name,
4756
4758
  sourceContent: sourceContent,
4757
4759
  });
4758
4760
  },
4759
- };
4760
-
4761
- /**
4762
- * Parses the persona command
4763
- *
4764
- * @see ./PERSONA-README.md for more details
4765
- * @private within the commands folder
4766
- */
4767
- var personaCommandParser = {
4768
- /**
4769
- * Name of the command
4770
- */
4771
- name: 'PERSONA',
4772
- /**
4773
- * Aliases for the PERSONA command
4774
- */
4775
- aliasNames: ['PERSON'],
4776
- /**
4777
- * PERSONA command can be used in:
4778
- */
4779
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
4780
- /**
4781
- * Description of the PERSONA command
4782
- */
4783
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
4784
- /**
4785
- * Link to discussion
4786
- */
4787
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
4788
- /**
4789
- * Example usages of the PERSONA command
4790
- */
4791
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
4792
4761
  /**
4793
- * Parses the PERSONA command
4762
+ * Converts the KNOWLEDGE command back to string
4763
+ *
4764
+ * Note: This is used in `pipelineJsonToString` utility
4794
4765
  */
4795
- parse: function (input) {
4796
- var rawArgs = input.rawArgs;
4797
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
4798
- var personaName = (personaNameRaw || '').trim();
4799
- if (personaName === '') {
4800
- throw new ParsingError("You must set name for the persona");
4801
- }
4802
- var personaDescription = (personaDescriptionRaw || '').trim();
4803
- if (personaDescription === '') {
4804
- personaDescription = null;
4805
- }
4806
- return {
4807
- type: 'PERSONA',
4808
- personaName: personaName,
4809
- personaDescription: personaDescription,
4810
- };
4766
+ stringify: function (command) {
4767
+ keepUnused(command);
4768
+ return "!!!!!!";
4811
4769
  },
4812
4770
  /**
4813
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4771
+ * Reads the KNOWLEDGE command from the `PipelineJson`
4772
+ *
4773
+ * Note: This is used in `pipelineJsonToString` utility
4814
4774
  */
4815
- applyToPipelineJson: function (personaCommand, subjects) {
4816
- var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
4817
- var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
4818
- if (templateJson !== null) {
4819
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
4820
- throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
4821
- }
4822
- templateJson.personaName = personaName;
4823
- }
4824
- var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
4825
- if (persona === undefined) {
4826
- pipelineJson.personas.push({
4827
- name: personaName,
4828
- description: personaDescription || '',
4829
- });
4830
- return;
4831
- }
4832
- if (persona.description === personaDescription) {
4833
- return;
4834
- }
4835
- if (personaDescription === null) {
4836
- return;
4837
- }
4838
- if (persona.description === '') {
4839
- persona.description = personaDescription;
4840
- return;
4841
- }
4842
- 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 ")));
4843
- persona.description += spaceTrim('\n\n' + personaDescription);
4775
+ takeFromPipelineJson: function (pipelineJson) {
4776
+ keepUnused(pipelineJson);
4777
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4844
4778
  },
4845
4779
  };
4846
4780
 
4847
- /**
4848
- * Removes Markdown formatting tags from a string.
4849
- *
4850
- * @param {string} str - The string to remove Markdown tags from.
4851
- * @returns {string} The input string with all Markdown tags removed.
4852
- * @public exported from `@promptbook/markdown-utils`
4853
- */
4854
- function removeMarkdownFormatting(str) {
4855
- // Remove bold formatting
4856
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
4857
- // Remove italic formatting
4858
- str = str.replace(/\*(.*?)\*/g, '$1');
4859
- // Remove code formatting
4860
- str = str.replace(/`(.*?)`/g, '$1');
4861
- return str;
4862
- }
4863
-
4864
- /**
4865
- * @@@
4866
- *
4867
- * @param text @@@
4868
- * @returns @@@
4869
- * @example 'HELLO_WORLD'
4870
- * @example 'I_LOVE_PROMPTBOOK'
4871
- * @public exported from `@promptbook/utils`
4872
- */
4873
- function normalizeTo_SCREAMING_CASE(text) {
4874
- var e_1, _a;
4875
- var charType;
4876
- var lastCharType = 'OTHER';
4877
- var normalizedName = '';
4878
- try {
4879
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
4880
- var char = text_1_1.value;
4881
- var normalizedChar = void 0;
4882
- if (/^[a-z]$/.test(char)) {
4883
- charType = 'LOWERCASE';
4884
- normalizedChar = char.toUpperCase();
4885
- }
4886
- else if (/^[A-Z]$/.test(char)) {
4887
- charType = 'UPPERCASE';
4888
- normalizedChar = char;
4889
- }
4890
- else if (/^[0-9]$/.test(char)) {
4891
- charType = 'NUMBER';
4892
- normalizedChar = char;
4893
- }
4894
- else if (/^\/$/.test(char)) {
4895
- charType = 'SLASH';
4896
- normalizedChar = char;
4897
- }
4898
- else {
4899
- charType = 'OTHER';
4900
- normalizedChar = '_';
4901
- }
4902
- if (charType !== lastCharType &&
4903
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
4904
- !(lastCharType === 'NUMBER') &&
4905
- !(charType === 'NUMBER')) {
4906
- normalizedName += '_';
4907
- }
4908
- normalizedName += normalizedChar;
4909
- lastCharType = charType;
4910
- }
4911
- }
4912
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4913
- finally {
4914
- try {
4915
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
4916
- }
4917
- finally { if (e_1) throw e_1.error; }
4918
- }
4919
- normalizedName = normalizedName.replace(/_+/g, '_');
4920
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
4921
- normalizedName = normalizedName.replace(/^_/, '');
4922
- normalizedName = normalizedName.replace(/_$/, '');
4923
- return normalizedName;
4924
- }
4925
- /**
4926
- * TODO: Tests
4927
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
4928
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
4929
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
4930
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
4931
- * TODO: [🌺] Use some intermediate util splitWords
4932
- */
4933
-
4934
4781
  /**
4935
4782
  * Parses the block command
4936
4783
  *
@@ -4948,8 +4795,8 @@ var blockCommandParser = {
4948
4795
  aliasNames: [
4949
4796
  'PROMPT_TEMPLATE',
4950
4797
  'SIMPLE_TEMPLATE',
4951
- 'SCRIPT',
4952
- 'PROMPT_DIALOG',
4798
+ 'SCRIPT_TEMPLATE',
4799
+ 'DIALOG_TEMPLATE',
4953
4800
  'SAMPLE',
4954
4801
  'EXAMPLE',
4955
4802
  'KNOWLEDGE',
@@ -4964,7 +4811,8 @@ var blockCommandParser = {
4964
4811
  /**
4965
4812
  * BOILERPLATE command can be used in:
4966
4813
  */
4967
- usagePlaces: ['PIPELINE_TEMPLATE'],
4814
+ isUsedInPipelineHead: false,
4815
+ isUsedInPipelineTemplate: true,
4968
4816
  /**
4969
4817
  * Description of the BLOCK command
4970
4818
  */
@@ -4977,19 +4825,24 @@ var blockCommandParser = {
4977
4825
  * Example usages of the BLOCK command
4978
4826
  */
4979
4827
  examples: [
4980
- 'Prompt template BLOCK',
4981
- 'Prompt template',
4982
- 'Simple template BLOCK',
4983
- 'Simple template',
4984
- 'Script BLOCK',
4985
- 'Script',
4986
- 'Prompt dialog BLOCK',
4987
- 'Prompt dialog',
4988
- 'Sample BLOCK',
4989
- 'Sample',
4990
- 'Example BLOCK',
4991
- 'Example',
4992
- 'Knowledge BLOCK',
4828
+ // Recommended form:
4829
+ 'PROMPT BLOCK',
4830
+ 'SIMPLE BLOCK',
4831
+ 'SCRIPT BLOCK',
4832
+ 'DIALOG BLOCK',
4833
+ // <- [🅱]
4834
+ // Long form:
4835
+ 'PROMPT TEMPLATE BLOCK',
4836
+ 'SIMPLE TEMPLATE BLOCK',
4837
+ 'SCRIPT TEMPLATE BLOCK',
4838
+ 'DIALOG TEMPLATE BLOCK',
4839
+ // <- [🅱]
4840
+ // Reversed form:
4841
+ 'BLOCK PROMPT TEMPLATE',
4842
+ 'BLOCK SIMPLE TEMPLATE',
4843
+ 'BLOCK SCRIPT TEMPLATE',
4844
+ 'BLOCK DIALOG TEMPLATE',
4845
+ // <- [🅱]
4993
4846
  // 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
4994
4847
  //---
4995
4848
  /* Note: Not implemented block types will be in examples in future -> */
@@ -5007,9 +4860,9 @@ var blockCommandParser = {
5007
4860
  parse: function (input) {
5008
4861
  var normalized = input.normalized;
5009
4862
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
5010
- var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
4863
+ var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType.split('_TEMPLATE').join('')); });
5011
4864
  if (blockTypes.length !== 1) {
5012
- throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
4865
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
5013
4866
  }
5014
4867
  var blockType = blockTypes[0];
5015
4868
  return {
@@ -5017,6 +4870,94 @@ var blockCommandParser = {
5017
4870
  blockType: blockType,
5018
4871
  };
5019
4872
  },
4873
+ /**
4874
+ * Apply the BLOCK command to the `pipelineJson`
4875
+ *
4876
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
4877
+ */
4878
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
4879
+ // TODO: !!!!!! Test multiple / no block type
4880
+ if ($templateJson.isBlockTypeSet === true) {
4881
+ throw new ParseError("Block type is already defined in the prompt template. It can be defined only once.");
4882
+ }
4883
+ $templateJson.isBlockTypeSet = true;
4884
+ // TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
4885
+ var expectResultingParameterName = function () {
4886
+ if ($templateJson.resultingParameterName) {
4887
+ return;
4888
+ }
4889
+ throw new ParseError(" Template section must end with -> {parameterName}");
4890
+ };
4891
+ if ($templateJson.content === undefined) {
4892
+ throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
4893
+ }
4894
+ if (command.blockType === 'SAMPLE') {
4895
+ expectResultingParameterName();
4896
+ var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
4897
+ if (parameter === undefined) {
4898
+ throw new ParseError("Can not find parameter {".concat($templateJson.resultingParameterName, "} to assign sample value on it"));
4899
+ }
4900
+ parameter.sampleValues = parameter.sampleValues || [];
4901
+ parameter.sampleValues.push($templateJson.content);
4902
+ // TODO: !!!!!! How to implement this?
4903
+ // continue templates;
4904
+ $templateJson.isTemplateBlock = false;
4905
+ return;
4906
+ }
4907
+ if (command.blockType === 'KNOWLEDGE') {
4908
+ knowledgeCommandParser.$applyToPipelineJson({
4909
+ type: 'KNOWLEDGE',
4910
+ sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
4911
+ }, $pipelineJson);
4912
+ // TODO: !!!!!! How to implement this?
4913
+ // continue templates;
4914
+ $templateJson.isTemplateBlock = false;
4915
+ return;
4916
+ }
4917
+ if (command.blockType === 'ACTION') {
4918
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
4919
+ // TODO: !!!!!! How to implement this?
4920
+ // continue templates;
4921
+ $templateJson.isTemplateBlock = false;
4922
+ return;
4923
+ }
4924
+ if (command.blockType === 'INSTRUMENT') {
4925
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4926
+ // TODO: !!!!!! How to implement this?
4927
+ // continue templates;
4928
+ $templateJson.isTemplateBlock = false;
4929
+ return;
4930
+ }
4931
+ expectResultingParameterName();
4932
+ $templateJson.blockType = command.blockType;
4933
+ /*
4934
+ TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
4935
+ if (command.blockType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
4936
+ templateModelRequirements.modelVariant = 'CHAT';
4937
+ }
4938
+ */
4939
+ // !!!!!!
4940
+ // isBlockTypeSet = true; //<- Note: [2]
4941
+ $templateJson.isTemplateBlock = true;
4942
+ },
4943
+ /**
4944
+ * Converts the BLOCK command back to string
4945
+ *
4946
+ * Note: This is used in `pipelineJsonToString` utility
4947
+ */
4948
+ stringify: function (command) {
4949
+ keepUnused(command);
4950
+ return "!!!!!!";
4951
+ },
4952
+ /**
4953
+ * Reads the BLOCK command from the `TemplateJson`
4954
+ *
4955
+ * Note: This is used in `pipelineJsonToString` utility
4956
+ */
4957
+ takeFromTemplateJson: function ($templateJson) {
4958
+ keepUnused($templateJson);
4959
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4960
+ },
5020
4961
  };
5021
4962
 
5022
4963
  /**
@@ -5027,7 +4968,7 @@ var blockCommandParser = {
5027
4968
  */
5028
4969
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
5029
4970
  /**
5030
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
4971
+ * TODO: [💝] Unite object for expecting amount and format - remove format
5031
4972
  */
5032
4973
 
5033
4974
  /**
@@ -5037,7 +4978,7 @@ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPH
5037
4978
  * Note: it also works only with decimal numbers
5038
4979
  *
5039
4980
  * @returns parsed number
5040
- * @throws {ParsingError} if the value is not a number
4981
+ * @throws {ParseError} if the value is not a number
5041
4982
  *
5042
4983
  * @public exported from `@promptbook/utils`
5043
4984
  */
@@ -5073,7 +5014,7 @@ function parseNumber(value) {
5073
5014
  var numerator = parseNumber(numerator_);
5074
5015
  var denominator = parseNumber(denominator_);
5075
5016
  if (denominator === 0) {
5076
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
5017
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
5077
5018
  }
5078
5019
  return numerator / denominator;
5079
5020
  }
@@ -5085,11 +5026,11 @@ function parseNumber(value) {
5085
5026
  return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
5086
5027
  }
5087
5028
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
5088
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\""));
5029
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
5089
5030
  }
5090
5031
  var num = parseFloat(value);
5091
5032
  if (isNaN(num)) {
5092
- throw new ParsingError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
5033
+ throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
5093
5034
  }
5094
5035
  return num;
5095
5036
  }
@@ -5112,9 +5053,10 @@ var expectCommandParser = {
5112
5053
  /**
5113
5054
  * BOILERPLATE command can be used in:
5114
5055
  */
5115
- usagePlaces: ['PIPELINE_TEMPLATE'],
5056
+ isUsedInPipelineHead: false,
5057
+ isUsedInPipelineTemplate: true,
5116
5058
  /**
5117
- * Description of the EXPECT command
5059
+ * Description of the FORMAT command
5118
5060
  */
5119
5061
  description: spaceTrim("\n Expect command describes the desired output of the prompt template (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 "),
5120
5062
  /**
@@ -5122,7 +5064,7 @@ var expectCommandParser = {
5122
5064
  */
5123
5065
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
5124
5066
  /**
5125
- * Example usages of the EXPECT command
5067
+ * Example usages of the FORMAT command
5126
5068
  */
5127
5069
  examples: [
5128
5070
  'EXPECT MIN 100 Characters',
@@ -5130,22 +5072,13 @@ var expectCommandParser = {
5130
5072
  'EXPECT EXACTLY 3 Sentences',
5131
5073
  'EXPECT EXACTLY 1 Paragraph',
5132
5074
  // <- TODO: 'EXPECT 1 Paragraph',
5133
- 'Expect JSON',
5134
5075
  ],
5135
5076
  /**
5136
- * Parses the EXPECT command
5077
+ * Parses the FORMAT command
5137
5078
  */
5138
5079
  parse: function (input) {
5139
5080
  var e_1, _a;
5140
- var args = input.args, normalized = input.normalized;
5141
- if (normalized.startsWith('EXPECT_JSON')) {
5142
- return {
5143
- type: 'EXPECT_FORMAT',
5144
- format: 'JSON',
5145
- };
5146
- // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5147
- // [🥤]
5148
- }
5081
+ var args = input.args;
5149
5082
  try {
5150
5083
  var sign = void 0;
5151
5084
  var signRaw = args.shift();
@@ -5159,15 +5092,15 @@ var expectCommandParser = {
5159
5092
  sign = 'MAXIMUM';
5160
5093
  }
5161
5094
  else {
5162
- throw new ParsingError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
5095
+ throw new ParseError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
5163
5096
  }
5164
5097
  var amountRaw = args.shift();
5165
5098
  var amount = parseNumber(amountRaw);
5166
5099
  if (amount < 0) {
5167
- throw new ParsingError('Amount must be positive number or zero');
5100
+ throw new ParseError('Amount must be positive number or zero');
5168
5101
  }
5169
5102
  if (amount !== Math.floor(amount)) {
5170
- throw new ParsingError('Amount must be whole number');
5103
+ throw new ParseError('Amount must be whole number');
5171
5104
  }
5172
5105
  var unitRaw = args.shift();
5173
5106
  var unit = undefined;
@@ -5182,7 +5115,7 @@ var expectCommandParser = {
5182
5115
  if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
5183
5116
  new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
5184
5117
  if (unit !== undefined) {
5185
- throw new ParsingError("Ambiguous unit \"".concat(unitRaw, "\""));
5118
+ throw new ParseError("Ambiguous unit \"".concat(unitRaw, "\""));
5186
5119
  }
5187
5120
  unit = existingUnit;
5188
5121
  }
@@ -5196,10 +5129,10 @@ var expectCommandParser = {
5196
5129
  finally { if (e_1) throw e_1.error; }
5197
5130
  }
5198
5131
  if (unit === undefined) {
5199
- throw new ParsingError("Invalid unit \"".concat(unitRaw, "\""));
5132
+ throw new ParseError("Invalid unit \"".concat(unitRaw, "\""));
5200
5133
  }
5201
5134
  return {
5202
- type: 'EXPECT_AMOUNT',
5135
+ type: 'EXPECT',
5203
5136
  sign: sign,
5204
5137
  unit: unit,
5205
5138
  amount: amount,
@@ -5209,97 +5142,321 @@ var expectCommandParser = {
5209
5142
  if (!(error instanceof Error)) {
5210
5143
  throw error;
5211
5144
  }
5212
- throw new ParsingError(spaceTrim(function (block) {
5213
- return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
5145
+ throw new ParseError(spaceTrim(function (block) {
5146
+ return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
5214
5147
  }));
5215
5148
  }
5216
5149
  },
5150
+ /**
5151
+ * Apply the FORMAT command to the `pipelineJson`
5152
+ *
5153
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5154
+ */
5155
+ $applyToTemplateJson: function (command, $templateJson) {
5156
+ // eslint-disable-next-line no-case-declarations
5157
+ var unit = command.unit.toLowerCase();
5158
+ $templateJson.expectations = $templateJson.expectations || {};
5159
+ $templateJson.expectations[unit] = $templateJson.expectations[unit] || {};
5160
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
5161
+ if ($templateJson.expectations[unit].min !== undefined) {
5162
+ throw new ParseError("Already defined minumum ".concat($templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5163
+ }
5164
+ $templateJson.expectations[unit].min = command.amount;
5165
+ } /* not else */
5166
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
5167
+ if ($templateJson.expectations[unit].max !== undefined) {
5168
+ throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5169
+ }
5170
+ $templateJson.expectations[unit].max = command.amount;
5171
+ }
5172
+ },
5173
+ /**
5174
+ * Converts the FORMAT command back to string
5175
+ *
5176
+ * Note: This is used in `pipelineJsonToString` utility
5177
+ */
5178
+ stringify: function (command) {
5179
+ keepUnused(command);
5180
+ return "!!!!!!";
5181
+ },
5182
+ /**
5183
+ * Reads the FORMAT command from the `TemplateJson`
5184
+ *
5185
+ * Note: This is used in `pipelineJsonToString` utility
5186
+ */
5187
+ takeFromTemplateJson: function ($templateJson) {
5188
+ keepUnused($templateJson);
5189
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5190
+ },
5217
5191
  };
5218
5192
 
5219
5193
  /**
5220
- * Parses the joker command
5194
+ * Parses the foreach command
5221
5195
  *
5222
- * @see ./JOKER-README.md for more details
5196
+ * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
5197
+ *
5198
+ * @see ./FOREACH-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5223
5199
  * @private within the commands folder
5224
5200
  */
5225
- var jokerCommandParser = {
5201
+ var foreachCommandParser = {
5226
5202
  /**
5227
5203
  * Name of the command
5228
5204
  */
5229
- name: 'JOKER',
5205
+ name: 'FOREACH',
5230
5206
  /**
5231
- * BOILERPLATE command can be used in:
5207
+ * Aliases for the FOREACH command
5232
5208
  */
5233
- usagePlaces: ['PIPELINE_TEMPLATE'],
5209
+ aliasNames: ['FOR', 'EACH'],
5234
5210
  /**
5235
- * Description of the JOKER command
5211
+ * FOREACH command can be used in:
5236
5212
  */
5237
- description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5213
+ isUsedInPipelineHead: false,
5214
+ isUsedInPipelineTemplate: true,
5215
+ /**
5216
+ * Description of the FOREACH command
5217
+ */
5218
+ description: "@@",
5238
5219
  /**
5239
5220
  * Link to discussion
5240
5221
  */
5241
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5222
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5242
5223
  /**
5243
- * Example usages of the JOKER command
5224
+ * Example usages of the FOREACH command
5244
5225
  */
5245
- examples: ['JOKER {documentTitle}'],
5226
+ examples: [
5227
+ 'FOREACH List Line -> `{customer}`',
5228
+ 'FOR List Line -> `{customer}`',
5229
+ 'EACH List Line -> `{customer}`',
5230
+ // <- TODO: [🍭] More
5231
+ ],
5246
5232
  /**
5247
- * Parses the JOKER command
5233
+ * Parses the FOREACH command
5248
5234
  */
5249
5235
  parse: function (input) {
5250
5236
  var args = input.args;
5251
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5252
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5253
- throw new ParsingError("Invalid joker");
5254
- }
5255
- var parameterName = parametersMatch.groups.parameterName;
5237
+ keepUnused(args);
5238
+ // <- TODO: [🍭] Implement
5256
5239
  return {
5257
- type: 'JOKER',
5258
- parameterName: parameterName,
5240
+ type: 'FOREACH',
5259
5241
  };
5260
5242
  },
5243
+ /**
5244
+ * Apply the FOREACH command to the `pipelineJson`
5245
+ *
5246
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5247
+ */
5248
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5249
+ keepUnused(command, $templateJson, $pipelineJson);
5250
+ // <- TODO: [🍭] Implement
5251
+ },
5252
+ /**
5253
+ * Converts the FOREACH command back to string
5254
+ *
5255
+ * Note: This is used in `pipelineJsonToString` utility
5256
+ */
5257
+ stringify: function (command) {
5258
+ keepUnused(command);
5259
+ return "";
5260
+ // <- TODO: [🍭] Implement
5261
+ },
5262
+ /**
5263
+ * Reads the FOREACH command from the `TemplateJson`
5264
+ *
5265
+ * Note: This is used in `pipelineJsonToString` utility
5266
+ */
5267
+ takeFromTemplateJson: function ($templateJson) {
5268
+ keepUnused($templateJson);
5269
+ return [];
5270
+ // <- TODO: [🍭] Implement
5271
+ },
5261
5272
  };
5262
-
5263
5273
  /**
5264
- * @@@
5265
- *
5266
- * @public exported from `@promptbook/core`
5274
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong syntax and logic
5267
5275
  */
5268
- var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5269
5276
 
5270
5277
  /**
5271
- * Parses the model command
5278
+ * Parses the format command
5272
5279
  *
5273
- * @see ./MODEL-README.md for more details
5280
+ * @see ./FORMAT-README.md for more details
5274
5281
  * @private within the commands folder
5275
5282
  */
5276
- var modelCommandParser = {
5283
+ var formatCommandParser = {
5277
5284
  /**
5278
5285
  * Name of the command
5279
5286
  */
5280
- name: 'MODEL',
5287
+ name: 'FORMAT',
5281
5288
  /**
5282
5289
  * BOILERPLATE command can be used in:
5283
5290
  */
5284
- usagePlaces: [
5285
- 'PIPELINE_HEAD',
5286
- // <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
5287
- 'PIPELINE_TEMPLATE',
5288
- ],
5291
+ isUsedInPipelineHead: false,
5292
+ isUsedInPipelineTemplate: true,
5289
5293
  /**
5290
- * Description of the MODEL command
5294
+ * Description of the FORMAT command
5291
5295
  */
5292
- description: "Tells which model and modelRequirements to use for the prompt template execution",
5296
+ description: spaceTrim("\n Format command describes the desired output of the prompt template (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 "),
5293
5297
  /**
5294
5298
  * Link to discussion
5295
5299
  */
5296
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5300
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
5297
5301
  /**
5298
- * Example usages of the MODEL command
5302
+ * Example usages of the FORMAT command
5299
5303
  */
5300
- examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5304
+ examples: ['FORMAT JSON'],
5301
5305
  /**
5302
- * Parses the MODEL command
5306
+ * Parses the FORMAT command
5307
+ */
5308
+ parse: function (input) {
5309
+ var normalized = input.normalized;
5310
+ if (!normalized.startsWith('FORMAT_JSON')) {
5311
+ throw new ParseError("For now only JSON format is supported, in future we will support more formats");
5312
+ }
5313
+ return {
5314
+ type: 'FORMAT',
5315
+ format: 'JSON',
5316
+ };
5317
+ // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5318
+ // [🥤]
5319
+ },
5320
+ /**
5321
+ * Apply the FORMAT command to the `pipelineJson`
5322
+ *
5323
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5324
+ */
5325
+ $applyToTemplateJson: function (command, $templateJson) {
5326
+ if ($templateJson.format !== undefined && command.format !== $templateJson.format) {
5327
+ throw new ParseError("Format format is already defined to \"".concat($templateJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
5328
+ }
5329
+ $templateJson.format = command.format;
5330
+ },
5331
+ /**
5332
+ * Converts the FORMAT command back to string
5333
+ *
5334
+ * Note: This is used in `pipelineJsonToString` utility
5335
+ */
5336
+ stringify: function (command) {
5337
+ keepUnused(command);
5338
+ return "!!!!!!";
5339
+ },
5340
+ /**
5341
+ * Reads the FORMAT command from the `TemplateJson`
5342
+ *
5343
+ * Note: This is used in `pipelineJsonToString` utility
5344
+ */
5345
+ takeFromTemplateJson: function ($templateJson) {
5346
+ keepUnused($templateJson);
5347
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5348
+ },
5349
+ };
5350
+
5351
+ /**
5352
+ * Parses the joker command
5353
+ *
5354
+ * @see ./JOKER-README.md for more details
5355
+ * @private within the commands folder
5356
+ */
5357
+ var jokerCommandParser = {
5358
+ /**
5359
+ * Name of the command
5360
+ */
5361
+ name: 'JOKER',
5362
+ /**
5363
+ * BOILERPLATE command can be used in:
5364
+ */
5365
+ isUsedInPipelineHead: false,
5366
+ isUsedInPipelineTemplate: true,
5367
+ /**
5368
+ * Description of the JOKER command
5369
+ */
5370
+ description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5371
+ /**
5372
+ * Link to discussion
5373
+ */
5374
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5375
+ /**
5376
+ * Example usages of the JOKER command
5377
+ */
5378
+ examples: ['JOKER {documentTitle}'],
5379
+ /**
5380
+ * Parses the JOKER command
5381
+ */
5382
+ parse: function (input) {
5383
+ var args = input.args;
5384
+ var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5385
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5386
+ throw new ParseError("Invalid joker");
5387
+ }
5388
+ var parameterName = parametersMatch.groups.parameterName;
5389
+ return {
5390
+ type: 'JOKER',
5391
+ parameterName: parameterName,
5392
+ };
5393
+ },
5394
+ /**
5395
+ * Apply the JOKER command to the `pipelineJson`
5396
+ *
5397
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5398
+ */
5399
+ $applyToTemplateJson: function (command, $templateJson) {
5400
+ $templateJson.jokerParameterNames = $templateJson.jokerParameterNames || [];
5401
+ $templateJson.jokerParameterNames.push(command.parameterName);
5402
+ },
5403
+ /**
5404
+ * Converts the JOKER command back to string
5405
+ *
5406
+ * Note: This is used in `pipelineJsonToString` utility
5407
+ */
5408
+ stringify: function (command) {
5409
+ keepUnused(command);
5410
+ return "!!!!!!";
5411
+ },
5412
+ /**
5413
+ * Reads the JOKER command from the `TemplateJson`
5414
+ *
5415
+ * Note: This is used in `pipelineJsonToString` utility
5416
+ */
5417
+ takeFromTemplateJson: function ($templateJson) {
5418
+ keepUnused($templateJson);
5419
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5420
+ },
5421
+ };
5422
+
5423
+ /**
5424
+ * @@@
5425
+ *
5426
+ * @public exported from `@promptbook/core`
5427
+ */
5428
+ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5429
+
5430
+ /**
5431
+ * Parses the model command
5432
+ *
5433
+ * @see ./MODEL-README.md for more details
5434
+ * @private within the commands folder
5435
+ */
5436
+ var modelCommandParser = {
5437
+ /**
5438
+ * Name of the command
5439
+ */
5440
+ name: 'MODEL',
5441
+ /**
5442
+ * BOILERPLATE command can be used in:
5443
+ */
5444
+ isUsedInPipelineHead: true,
5445
+ isUsedInPipelineTemplate: true,
5446
+ /**
5447
+ * Description of the MODEL command
5448
+ */
5449
+ description: "Tells which model and modelRequirements to use for the prompt template execution",
5450
+ /**
5451
+ * Link to discussion
5452
+ */
5453
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5454
+ /**
5455
+ * Example usages of the MODEL command
5456
+ */
5457
+ examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5458
+ /**
5459
+ * Parses the MODEL command
5303
5460
  */
5304
5461
  parse: function (input) {
5305
5462
  var args = input.args, normalized = input.normalized;
@@ -5328,7 +5485,7 @@ var modelCommandParser = {
5328
5485
  // <- Note: [🤖]
5329
5486
  }
5330
5487
  else {
5331
- throw new ParsingError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
5488
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
5332
5489
  }
5333
5490
  }
5334
5491
  if (normalized.startsWith('MODEL_NAME')) {
@@ -5339,9 +5496,60 @@ var modelCommandParser = {
5339
5496
  };
5340
5497
  }
5341
5498
  else {
5342
- throw new ParsingError(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\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
5499
+ 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\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
5343
5500
  }
5344
5501
  },
5502
+ /**
5503
+ * Apply the MODEL command to the `pipelineJson`
5504
+ *
5505
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5506
+ */
5507
+ $applyToPipelineJson: function (command, $pipelineJson) {
5508
+ // TODO: !!!!!! Error on redefine
5509
+ $pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
5510
+ $pipelineJson.defaultModelRequirements[command.key] = command.value;
5511
+ },
5512
+ /**
5513
+ * Apply the MODEL command to the `pipelineJson`
5514
+ *
5515
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5516
+ */
5517
+ $applyToTemplateJson: function (command, $templateJson) {
5518
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5519
+ throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
5520
+ }
5521
+ // TODO: !!!!!! Error on redefine
5522
+ // TODO: Warn if setting same as default in `$pipelineJson`
5523
+ $templateJson.modelRequirements = $templateJson.modelRequirements || {};
5524
+ $templateJson.modelRequirements[command.key] = command.value;
5525
+ },
5526
+ /**
5527
+ * Converts the MODEL command back to string
5528
+ *
5529
+ * Note: This is used in `pipelineJsonToString` utility
5530
+ */
5531
+ stringify: function (command) {
5532
+ keepUnused(command);
5533
+ return "!!!!!!";
5534
+ },
5535
+ /**
5536
+ * Reads the MODEL command from the `PipelineJson`
5537
+ *
5538
+ * Note: This is used in `pipelineJsonToString` utility
5539
+ */
5540
+ takeFromPipelineJson: function (pipelineJson) {
5541
+ keepUnused(pipelineJson);
5542
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5543
+ },
5544
+ /**
5545
+ * Reads the MODEL command from the `TemplateJson`
5546
+ *
5547
+ * Note: This is used in `pipelineJsonToString` utility
5548
+ */
5549
+ takeFromTemplateJson: function ($templateJson) {
5550
+ keepUnused($templateJson);
5551
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5552
+ },
5345
5553
  };
5346
5554
 
5347
5555
  /**
@@ -5365,7 +5573,8 @@ var parameterCommandParser = {
5365
5573
  /**
5366
5574
  * BOILERPLATE command can be used in:
5367
5575
  */
5368
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
5576
+ isUsedInPipelineHead: true,
5577
+ isUsedInPipelineTemplate: true,
5369
5578
  /**
5370
5579
  * Description of the PARAMETER command
5371
5580
  */
@@ -5385,11 +5594,11 @@ var parameterCommandParser = {
5385
5594
  var normalized = input.normalized, raw = input.raw;
5386
5595
  var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
5387
5596
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5388
- throw new ParsingError("Invalid parameter");
5597
+ throw new ParseError("Invalid parameter");
5389
5598
  }
5390
5599
  var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
5391
5600
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
5392
- throw new ParsingError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5601
+ throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5393
5602
  }
5394
5603
  var isInput = normalized.startsWith('INPUT');
5395
5604
  var isOutput = normalized.startsWith('OUTPUT');
@@ -5405,8 +5614,177 @@ var parameterCommandParser = {
5405
5614
  isOutput: isOutput,
5406
5615
  };
5407
5616
  },
5617
+ /**
5618
+ * Apply the PARAMETER command to the `pipelineJson`
5619
+ *
5620
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5621
+ */
5622
+ $applyToPipelineJson: function (command, $pipelineJson) {
5623
+ keepUnused(command, $pipelineJson);
5624
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5625
+ },
5626
+ /**
5627
+ * Apply the PARAMETER command to the `pipelineJson`
5628
+ *
5629
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5630
+ */
5631
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5632
+ keepUnused(command, $templateJson, $pipelineJson);
5633
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5634
+ },
5635
+ /**
5636
+ * Converts the PARAMETER command back to string
5637
+ *
5638
+ * Note: This is used in `pipelineJsonToString` utility
5639
+ */
5640
+ stringify: function (command) {
5641
+ keepUnused(command);
5642
+ return "!!!!!!";
5643
+ },
5644
+ /**
5645
+ * Reads the PARAMETER command from the `PipelineJson`
5646
+ *
5647
+ * Note: This is used in `pipelineJsonToString` utility
5648
+ */
5649
+ takeFromPipelineJson: function (pipelineJson) {
5650
+ keepUnused(pipelineJson);
5651
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5652
+ },
5653
+ /**
5654
+ * Reads the PARAMETER command from the `TemplateJson`
5655
+ *
5656
+ * Note: This is used in `pipelineJsonToString` utility
5657
+ */
5658
+ takeFromTemplateJson: function ($templateJson) {
5659
+ keepUnused($templateJson);
5660
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5661
+ },
5408
5662
  };
5409
5663
 
5664
+ /**
5665
+ * Parses the persona command
5666
+ *
5667
+ * @see ./PERSONA-README.md for more details
5668
+ * @private within the commands folder
5669
+ */
5670
+ var personaCommandParser = {
5671
+ /**
5672
+ * Name of the command
5673
+ */
5674
+ name: 'PERSONA',
5675
+ /**
5676
+ * Aliases for the PERSONA command
5677
+ */
5678
+ aliasNames: ['PERSON'],
5679
+ /**
5680
+ * PERSONA command can be used in:
5681
+ */
5682
+ isUsedInPipelineHead: true,
5683
+ isUsedInPipelineTemplate: true,
5684
+ /**
5685
+ * Description of the PERSONA command
5686
+ */
5687
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
5688
+ /**
5689
+ * Link to discussion
5690
+ */
5691
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
5692
+ /**
5693
+ * Example usages of the PERSONA command
5694
+ */
5695
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
5696
+ /**
5697
+ * Parses the PERSONA command
5698
+ */
5699
+ parse: function (input) {
5700
+ var rawArgs = input.rawArgs;
5701
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
5702
+ var personaName = (personaNameRaw || '').trim();
5703
+ if (personaName === '') {
5704
+ throw new ParseError("You must set name for the persona");
5705
+ }
5706
+ var personaDescription = (personaDescriptionRaw || '').trim();
5707
+ if (personaDescription === '') {
5708
+ personaDescription = null;
5709
+ }
5710
+ return {
5711
+ type: 'PERSONA',
5712
+ personaName: personaName,
5713
+ personaDescription: personaDescription,
5714
+ };
5715
+ },
5716
+ /**
5717
+ * Apply the PERSONA command to the `pipelineJson`
5718
+ *
5719
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5720
+ */
5721
+ $applyToPipelineJson: function (command, $pipelineJson) {
5722
+ $applyToTemplateJson(command, null, $pipelineJson);
5723
+ },
5724
+ $applyToTemplateJson: $applyToTemplateJson,
5725
+ /**
5726
+ * Converts the PERSONA command back to string
5727
+ *
5728
+ * Note: This is used in `pipelineJsonToString` utility
5729
+ */
5730
+ stringify: function (command) {
5731
+ keepUnused(command);
5732
+ return "!!!!!!";
5733
+ },
5734
+ /**
5735
+ * Reads the PERSONA command from the `PipelineJson`
5736
+ *
5737
+ * Note: This is used in `pipelineJsonToString` utility
5738
+ */
5739
+ takeFromPipelineJson: function (pipelineJson) {
5740
+ keepUnused(pipelineJson);
5741
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5742
+ },
5743
+ /**
5744
+ * Reads the PERSONA command from the `TemplateJson`
5745
+ *
5746
+ * Note: This is used in `pipelineJsonToString` utility
5747
+ */
5748
+ takeFromTemplateJson: function ($templateJson) {
5749
+ keepUnused($templateJson);
5750
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5751
+ },
5752
+ };
5753
+ /**
5754
+ * Apply the PERSONA command to the `pipelineJson`
5755
+ *
5756
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5757
+ */
5758
+ function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
5759
+ var personaName = command.personaName, personaDescription = command.personaDescription;
5760
+ if ($templateJson !== null) {
5761
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5762
+ throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
5763
+ }
5764
+ $templateJson.personaName = personaName;
5765
+ }
5766
+ var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
5767
+ if (persona === undefined) {
5768
+ $pipelineJson.personas.push({
5769
+ name: personaName,
5770
+ description: personaDescription || '',
5771
+ });
5772
+ return;
5773
+ }
5774
+ if (persona.description === personaDescription) {
5775
+ return;
5776
+ }
5777
+ if (personaDescription === null) {
5778
+ return;
5779
+ }
5780
+ if (persona.description === '') {
5781
+ persona.description = personaDescription;
5782
+ return;
5783
+ }
5784
+ 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 ")));
5785
+ persona.description += spaceTrim('\n\n' + personaDescription);
5786
+ }
5787
+
5410
5788
  /**
5411
5789
  * @@@
5412
5790
  *
@@ -5436,7 +5814,8 @@ var postprocessCommandParser = {
5436
5814
  /**
5437
5815
  * BOILERPLATE command can be used in:
5438
5816
  */
5439
- usagePlaces: ['PIPELINE_TEMPLATE'],
5817
+ isUsedInPipelineHead: false,
5818
+ isUsedInPipelineTemplate: true,
5440
5819
  /**
5441
5820
  * Description of the POSTPROCESS command
5442
5821
  */
@@ -5458,19 +5837,46 @@ var postprocessCommandParser = {
5458
5837
  var args = input.args;
5459
5838
  var functionName = args.pop();
5460
5839
  if (functionName === undefined) {
5461
- throw new ParsingError("Postprocess function name is required");
5840
+ throw new ParseError("Postprocess function name is required");
5462
5841
  }
5463
5842
  if (!isValidJavascriptName(functionName)) {
5464
- throw new ParsingError("Invalid postprocess function name \"".concat(functionName, "\""));
5843
+ throw new ParseError("Invalid postprocess function name \"".concat(functionName, "\""));
5465
5844
  }
5466
5845
  if (args.length > 0) {
5467
- throw new ParsingError("Can not have more than one postprocess function");
5846
+ throw new ParseError("Can not have more than one postprocess function");
5468
5847
  }
5469
5848
  return {
5470
5849
  type: 'POSTPROCESS',
5471
5850
  functionName: functionName,
5472
5851
  };
5473
5852
  },
5853
+ /**
5854
+ * Apply the POSTPROCESS command to the `pipelineJson`
5855
+ *
5856
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5857
+ */
5858
+ $applyToTemplateJson: function (command, $templateJson) {
5859
+ $templateJson.postprocessingFunctionNames = $templateJson.postprocessingFunctionNames || [];
5860
+ $templateJson.postprocessingFunctionNames.push(command.functionName);
5861
+ },
5862
+ /**
5863
+ * Converts the POSTPROCESS command back to string
5864
+ *
5865
+ * Note: This is used in `pipelineJsonToString` utility
5866
+ */
5867
+ stringify: function (command) {
5868
+ keepUnused(command);
5869
+ return "!!!!!!";
5870
+ },
5871
+ /**
5872
+ * Reads the POSTPROCESS command from the `TemplateJson`
5873
+ *
5874
+ * Note: This is used in `pipelineJsonToString` utility
5875
+ */
5876
+ takeFromTemplateJson: function ($templateJson) {
5877
+ keepUnused($templateJson);
5878
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5879
+ },
5474
5880
  };
5475
5881
 
5476
5882
  /**
@@ -5488,7 +5894,8 @@ var promptbookVersionCommandParser = {
5488
5894
  /**
5489
5895
  * BOILERPLATE command can be used in:
5490
5896
  */
5491
- usagePlaces: ['PIPELINE_HEAD'],
5897
+ isUsedInPipelineHead: true,
5898
+ isUsedInPipelineTemplate: false,
5492
5899
  /**
5493
5900
  * Description of the PROMPTBOOK_VERSION command
5494
5901
  */
@@ -5508,19 +5915,45 @@ var promptbookVersionCommandParser = {
5508
5915
  var args = input.args;
5509
5916
  var promptbookVersion = args.pop();
5510
5917
  if (promptbookVersion === undefined) {
5511
- throw new ParsingError("Version is required");
5918
+ throw new ParseError("Version is required");
5512
5919
  }
5513
5920
  if (!isValidPromptbookVersion(promptbookVersion)) {
5514
- throw new ParsingError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5921
+ throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5515
5922
  }
5516
5923
  if (args.length > 0) {
5517
- throw new ParsingError("Can not have more than one Promptbook version");
5924
+ throw new ParseError("Can not have more than one Promptbook version");
5518
5925
  }
5519
5926
  return {
5520
5927
  type: 'PROMPTBOOK_VERSION',
5521
5928
  promptbookVersion: promptbookVersion,
5522
5929
  };
5523
5930
  },
5931
+ /**
5932
+ * Apply the PROMPTBOOK_VERSION command to the `pipelineJson`
5933
+ *
5934
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5935
+ */
5936
+ $applyToPipelineJson: function (command, $pipelineJson) {
5937
+ $pipelineJson.promptbookVersion = command.promptbookVersion;
5938
+ },
5939
+ /**
5940
+ * Converts the PROMPTBOOK_VERSION command back to string
5941
+ *
5942
+ * Note: This is used in `pipelineJsonToString` utility
5943
+ */
5944
+ stringify: function (command) {
5945
+ keepUnused(command);
5946
+ return "!!!!!!";
5947
+ },
5948
+ /**
5949
+ * Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
5950
+ *
5951
+ * Note: This is used in `pipelineJsonToString` utility
5952
+ */
5953
+ takeFromPipelineJson: function (pipelineJson) {
5954
+ keepUnused(pipelineJson);
5955
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5956
+ },
5524
5957
  };
5525
5958
 
5526
5959
  /**
@@ -5542,7 +5975,8 @@ var urlCommandParser = {
5542
5975
  /**
5543
5976
  * BOILERPLATE command can be used in:
5544
5977
  */
5545
- usagePlaces: ['PIPELINE_HEAD'],
5978
+ isUsedInPipelineHead: true,
5979
+ isUsedInPipelineTemplate: false,
5546
5980
  /**
5547
5981
  * Description of the URL command
5548
5982
  */
@@ -5566,23 +6000,23 @@ var urlCommandParser = {
5566
6000
  var args = input.args;
5567
6001
  var pipelineUrl = args.pop();
5568
6002
  if (pipelineUrl === undefined) {
5569
- throw new ParsingError("URL is required");
6003
+ throw new ParseError("URL is required");
5570
6004
  }
5571
6005
  // TODO: [🧠][🚲] This should be maybe tested as logic not syntax
5572
6006
  if (!isValidPipelineUrl(pipelineUrl)) {
5573
- throw new ParsingError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
6007
+ throw new ParseError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
5574
6008
  }
5575
6009
  if (args.length > 0) {
5576
- throw new ParsingError("Can not have more than one pipeline URL");
6010
+ throw new ParseError("Can not have more than one pipeline URL");
5577
6011
  }
5578
6012
  /*
5579
6013
  TODO: [🐠 Maybe more info from `isValidPipelineUrl`:
5580
6014
  if (pipelineUrl.protocol !== 'https:') {
5581
- throw new ParsingError(`Protocol must be HTTPS`);
6015
+ throw new ParseError(`Protocol must be HTTPS`);
5582
6016
  }
5583
6017
 
5584
6018
  if (pipelineUrl.hash !== '') {
5585
- throw new ParsingError(
6019
+ throw new ParseError(
5586
6020
  spaceTrim(
5587
6021
  `
5588
6022
  URL must not contain hash
@@ -5597,6 +6031,32 @@ var urlCommandParser = {
5597
6031
  pipelineUrl: new URL(pipelineUrl),
5598
6032
  };
5599
6033
  },
6034
+ /**
6035
+ * Apply the URL command to the `pipelineJson`
6036
+ *
6037
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6038
+ */
6039
+ $applyToPipelineJson: function (command, $pipelineJson) {
6040
+ $pipelineJson.pipelineUrl = command.pipelineUrl.href;
6041
+ },
6042
+ /**
6043
+ * Converts the URL command back to string
6044
+ *
6045
+ * Note: This is used in `pipelineJsonToString` utility
6046
+ */
6047
+ stringify: function (command) {
6048
+ keepUnused(command);
6049
+ return "!!!!!!";
6050
+ },
6051
+ /**
6052
+ * Reads the URL command from the `PipelineJson`
6053
+ *
6054
+ * Note: This is used in `pipelineJsonToString` utility
6055
+ */
6056
+ takeFromPipelineJson: function (pipelineJson) {
6057
+ keepUnused(pipelineJson);
6058
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6059
+ },
5600
6060
  };
5601
6061
 
5602
6062
  /**
@@ -5613,7 +6073,8 @@ var actionCommandParser = {
5613
6073
  /**
5614
6074
  * ACTION command can be used in:
5615
6075
  */
5616
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6076
+ isUsedInPipelineHead: true,
6077
+ isUsedInPipelineTemplate: false,
5617
6078
  /**
5618
6079
  * Description of the ACTION command
5619
6080
  */
@@ -5636,6 +6097,33 @@ var actionCommandParser = {
5636
6097
  type: 'ACTION',
5637
6098
  };
5638
6099
  },
6100
+ /**
6101
+ * Apply the ACTION command to the `pipelineJson`
6102
+ *
6103
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6104
+ */
6105
+ $applyToPipelineJson: function (command, $pipelineJson) {
6106
+ keepUnused(command, $pipelineJson);
6107
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
6108
+ },
6109
+ /**
6110
+ * Converts the ACTION command back to string
6111
+ *
6112
+ * Note: This is used in `pipelineJsonToString` utility
6113
+ */
6114
+ stringify: function (command) {
6115
+ keepUnused(command);
6116
+ return "!!!!!!";
6117
+ },
6118
+ /**
6119
+ * Reads the ACTION command from the `PipelineJson`
6120
+ *
6121
+ * Note: This is used in `pipelineJsonToString` utility
6122
+ */
6123
+ takeFromPipelineJson: function (pipelineJson) {
6124
+ keepUnused(pipelineJson);
6125
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6126
+ },
5639
6127
  };
5640
6128
 
5641
6129
  /**
@@ -5652,7 +6140,8 @@ var instrumentCommandParser = {
5652
6140
  /**
5653
6141
  * INSTRUMENT command can be used in:
5654
6142
  */
5655
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6143
+ isUsedInPipelineHead: true,
6144
+ isUsedInPipelineTemplate: false,
5656
6145
  /**
5657
6146
  * Description of the INSTRUMENT command
5658
6147
  */
@@ -5675,12 +6164,41 @@ var instrumentCommandParser = {
5675
6164
  type: 'INSTRUMENT',
5676
6165
  };
5677
6166
  },
6167
+ /**
6168
+ * Apply the INSTRUMENT command to the `pipelineJson`
6169
+ *
6170
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6171
+ */
6172
+ $applyToPipelineJson: function (command, $pipelineJson) {
6173
+ keepUnused(command, $pipelineJson);
6174
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6175
+ },
6176
+ /**
6177
+ * Converts the INSTRUMENT command back to string
6178
+ *
6179
+ * Note: This is used in `pipelineJsonToString` utility
6180
+ */
6181
+ stringify: function (command) {
6182
+ keepUnused(command);
6183
+ return "!!!!!!";
6184
+ },
6185
+ /**
6186
+ * Reads the INSTRUMENT command from the `PipelineJson`
6187
+ *
6188
+ * Note: This is used in `pipelineJsonToString` utility
6189
+ */
6190
+ takeFromPipelineJson: function (pipelineJson) {
6191
+ keepUnused(pipelineJson);
6192
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6193
+ },
5678
6194
  };
5679
6195
 
5680
6196
  /**
5681
6197
  * Parses the boilerplate command
5682
6198
  *
5683
- * @see ./BOILERPLATE-README.md for more details
6199
+ * Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
6200
+ *
6201
+ * @see ./BOILERPLATE-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5684
6202
  * @private within the commands folder
5685
6203
  */
5686
6204
  var boilerplateCommandParser = {
@@ -5695,7 +6213,8 @@ var boilerplateCommandParser = {
5695
6213
  /**
5696
6214
  * BOILERPLATE command can be used in:
5697
6215
  */
5698
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6216
+ isUsedInPipelineHead: true,
6217
+ isUsedInPipelineTemplate: true,
5699
6218
  /**
5700
6219
  * Description of the BOILERPLATE command
5701
6220
  */
@@ -5714,20 +6233,65 @@ var boilerplateCommandParser = {
5714
6233
  parse: function (input) {
5715
6234
  var args = input.args;
5716
6235
  if (args.length !== 1) {
5717
- throw new ParsingError("BOILERPLATE command requires exactly one argument");
6236
+ throw new ParseError("BOILERPLATE command requires exactly one argument");
5718
6237
  }
5719
6238
  var value = args[0].toLowerCase();
5720
6239
  if (value.includes('brr')) {
5721
- throw new ParsingError("BOILERPLATE value can not contain brr");
6240
+ throw new ParseError("BOILERPLATE value can not contain brr");
5722
6241
  }
5723
6242
  return {
5724
6243
  type: 'BOILERPLATE',
5725
6244
  value: value,
5726
6245
  };
5727
6246
  },
6247
+ /**
6248
+ * Apply the BOILERPLATE command to the `pipelineJson`
6249
+ *
6250
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6251
+ */
6252
+ $applyToPipelineJson: function (command, $pipelineJson) {
6253
+ keepUnused(command, $pipelineJson);
6254
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6255
+ },
6256
+ /**
6257
+ * Apply the BOILERPLATE command to the `pipelineJson`
6258
+ *
6259
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
6260
+ */
6261
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6262
+ keepUnused(command, $templateJson, $pipelineJson);
6263
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6264
+ },
6265
+ /**
6266
+ * Converts the BOILERPLATE command back to string
6267
+ *
6268
+ * Note: This is used in `pipelineJsonToString` utility
6269
+ */
6270
+ stringify: function (command) {
6271
+ keepUnused(command);
6272
+ return "!!!!!!";
6273
+ },
6274
+ /**
6275
+ * Reads the BOILERPLATE command from the `PipelineJson`
6276
+ *
6277
+ * Note: This is used in `pipelineJsonToString` utility
6278
+ */
6279
+ takeFromPipelineJson: function (pipelineJson) {
6280
+ keepUnused(pipelineJson);
6281
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6282
+ },
6283
+ /**
6284
+ * Reads the BOILERPLATE command from the `TemplateJson`
6285
+ *
6286
+ * Note: This is used in `pipelineJsonToString` utility
6287
+ */
6288
+ takeFromTemplateJson: function ($templateJson) {
6289
+ keepUnused($templateJson);
6290
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6291
+ },
5728
6292
  };
5729
6293
  /**
5730
- * TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
6294
+ * TODO: !!!!!! Make .ptbk.md file with examples of the BOILERPLATE command and fail
5731
6295
  */
5732
6296
 
5733
6297
  /**
@@ -5738,6 +6302,7 @@ var boilerplateCommandParser = {
5738
6302
  var COMMANDS = [
5739
6303
  blockCommandParser,
5740
6304
  expectCommandParser,
6305
+ formatCommandParser,
5741
6306
  jokerCommandParser,
5742
6307
  modelCommandParser,
5743
6308
  parameterCommandParser,
@@ -5748,20 +6313,108 @@ var COMMANDS = [
5748
6313
  actionCommandParser,
5749
6314
  instrumentCommandParser,
5750
6315
  personaCommandParser,
6316
+ foreachCommandParser,
5751
6317
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
5752
6318
  ];
5753
6319
 
6320
+ /**
6321
+ * Removes Markdown formatting tags from a string.
6322
+ *
6323
+ * @param {string} str - The string to remove Markdown tags from.
6324
+ * @returns {string} The input string with all Markdown tags removed.
6325
+ * @public exported from `@promptbook/markdown-utils`
6326
+ */
6327
+ function removeMarkdownFormatting(str) {
6328
+ // Remove bold formatting
6329
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
6330
+ // Remove italic formatting
6331
+ str = str.replace(/\*(.*?)\*/g, '$1');
6332
+ // Remove code formatting
6333
+ str = str.replace(/`(.*?)`/g, '$1');
6334
+ return str;
6335
+ }
6336
+
6337
+ /**
6338
+ * @@@
6339
+ *
6340
+ * @param text @@@
6341
+ * @returns @@@
6342
+ * @example 'HELLO_WORLD'
6343
+ * @example 'I_LOVE_PROMPTBOOK'
6344
+ * @public exported from `@promptbook/utils`
6345
+ */
6346
+ function normalizeTo_SCREAMING_CASE(text) {
6347
+ var e_1, _a;
6348
+ var charType;
6349
+ var lastCharType = 'OTHER';
6350
+ var normalizedName = '';
6351
+ try {
6352
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
6353
+ var char = text_1_1.value;
6354
+ var normalizedChar = void 0;
6355
+ if (/^[a-z]$/.test(char)) {
6356
+ charType = 'LOWERCASE';
6357
+ normalizedChar = char.toUpperCase();
6358
+ }
6359
+ else if (/^[A-Z]$/.test(char)) {
6360
+ charType = 'UPPERCASE';
6361
+ normalizedChar = char;
6362
+ }
6363
+ else if (/^[0-9]$/.test(char)) {
6364
+ charType = 'NUMBER';
6365
+ normalizedChar = char;
6366
+ }
6367
+ else if (/^\/$/.test(char)) {
6368
+ charType = 'SLASH';
6369
+ normalizedChar = char;
6370
+ }
6371
+ else {
6372
+ charType = 'OTHER';
6373
+ normalizedChar = '_';
6374
+ }
6375
+ if (charType !== lastCharType &&
6376
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
6377
+ !(lastCharType === 'NUMBER') &&
6378
+ !(charType === 'NUMBER')) {
6379
+ normalizedName += '_';
6380
+ }
6381
+ normalizedName += normalizedChar;
6382
+ lastCharType = charType;
6383
+ }
6384
+ }
6385
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6386
+ finally {
6387
+ try {
6388
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
6389
+ }
6390
+ finally { if (e_1) throw e_1.error; }
6391
+ }
6392
+ normalizedName = normalizedName.replace(/_+/g, '_');
6393
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
6394
+ normalizedName = normalizedName.replace(/^_/, '');
6395
+ normalizedName = normalizedName.replace(/_$/, '');
6396
+ return normalizedName;
6397
+ }
6398
+ /**
6399
+ * TODO: Tests
6400
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
6401
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
6402
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
6403
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
6404
+ * TODO: [🌺] Use some intermediate util splitWords
6405
+ */
6406
+
5754
6407
  /**
5755
6408
  * Parses one line of ul/ol to command
5756
6409
  *
5757
6410
  * @returns parsed command object
5758
- * @throws {ParsingError} if the command is invalid
6411
+ * @throws {ParseError} if the command is invalid
5759
6412
  *
5760
6413
  * @private within the pipelineStringToJson
5761
6414
  */
5762
6415
  function parseCommand(raw, usagePlace) {
5763
6416
  if (raw.includes('\n') || raw.includes('\r')) {
5764
- throw new ParsingError('Command can not contain new line characters' /* <- TODO: [🚞] */);
6417
+ throw new ParseError('Command can not contain new line characters' /* <- TODO: [🚞] */);
5765
6418
  }
5766
6419
  var normalized = raw.trim();
5767
6420
  normalized = normalized.split('`').join('');
@@ -5798,7 +6451,7 @@ function parseCommand(raw, usagePlace) {
5798
6451
  .map(removeMarkdownFormatting)
5799
6452
  .map(function (item) { return item.trim(); });
5800
6453
  if (items.length === 0 || items[0] === '') {
5801
- throw new ParsingError(spaceTrim$1(function (block) {
6454
+ throw new ParseError(spaceTrim$1(function (block) {
5802
6455
  return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5803
6456
  }));
5804
6457
  }
@@ -5825,7 +6478,7 @@ function parseCommand(raw, usagePlace) {
5825
6478
  return command;
5826
6479
  }
5827
6480
  }
5828
- throw new ParsingError(spaceTrim$1(function (block) {
6481
+ throw new ParseError(spaceTrim$1(function (block) {
5829
6482
  return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5830
6483
  }));
5831
6484
  }
@@ -5835,6 +6488,7 @@ function parseCommand(raw, usagePlace) {
5835
6488
  function getSupportedCommandsMessage() {
5836
6489
  return COMMANDS.flatMap(function (_a) {
5837
6490
  var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
6491
+ // <- Note: [🦦] Its strange that this type assertion is needed
5838
6492
  return __spreadArray([
5839
6493
  "- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
5840
6494
  ], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
@@ -5848,27 +6502,34 @@ function parseCommandVariant(input) {
5848
6502
  var commandNameRaw = input.commandNameRaw, usagePlace = input.usagePlace, normalized = input.normalized, args = input.args, raw = input.raw, rawArgs = input.rawArgs;
5849
6503
  var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
5850
6504
  var _loop_1 = function (commandParser) {
5851
- var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6505
+ // <- Note: [🦦] Its strange that this type assertion is needed
6506
+ var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6507
+ if (just(false)) {
6508
+ keepUnused( /* for better indentation */);
6509
+ }
6510
+ else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
6511
+ return "continue";
6512
+ }
6513
+ else if (usagePlace === 'PIPELINE_TEMPLATE' && !isUsedInPipelineTemplate) {
6514
+ return "continue";
6515
+ }
5852
6516
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
5853
6517
  if (names.includes(commandName)) {
5854
6518
  try {
5855
6519
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
5856
6520
  }
5857
6521
  catch (error) {
5858
- if (!(error instanceof ParsingError)) {
6522
+ if (!(error instanceof ParseError)) {
5859
6523
  throw error;
5860
6524
  }
5861
- throw new ParsingError(spaceTrim$1(function (block) {
6525
+ throw new ParseError(spaceTrim$1(function (block) {
5862
6526
  return "\n Invalid ".concat(commandName, " command:\n ").concat(block(error.message), "\n\n - ").concat(raw, "\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 ");
5863
6527
  }));
5864
6528
  }
5865
6529
  }
5866
6530
  };
5867
6531
  try {
5868
- for (var _b = __values(COMMANDS.filter(function (_a) {
5869
- var places = _a.usagePlaces;
5870
- return places.includes(usagePlace);
5871
- })), _c = _b.next(); !_c.done; _c = _b.next()) {
6532
+ for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
5872
6533
  var commandParser = _c.value;
5873
6534
  var state_1 = _loop_1(commandParser);
5874
6535
  if (typeof state_1 === "object")
@@ -5935,7 +6596,7 @@ function extractAllListItemsFromMarkdown(markdown) {
5935
6596
  /**
5936
6597
  * Extracts exactly ONE code block from markdown.
5937
6598
  *
5938
- * - When there are multiple or no code blocks the function throws a `ParsingError`
6599
+ * - When there are multiple or no code blocks the function throws a `ParseError`
5939
6600
  *
5940
6601
  * Note: There are multiple simmilar function:
5941
6602
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
@@ -5946,12 +6607,12 @@ function extractAllListItemsFromMarkdown(markdown) {
5946
6607
  * @param markdown any valid markdown
5947
6608
  * @returns code block with language and content
5948
6609
  * @public exported from `@promptbook/markdown-utils`
5949
- * @throws {ParsingError} if there is not exactly one code block in the markdown
6610
+ * @throws {ParseError} if there is not exactly one code block in the markdown
5950
6611
  */
5951
6612
  function extractOneBlockFromMarkdown(markdown) {
5952
6613
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
5953
6614
  if (codeBlocks.length !== 1) {
5954
- throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, 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 "); }));
6615
+ throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, 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 "); }));
5955
6616
  }
5956
6617
  return codeBlocks[0];
5957
6618
  }
@@ -5968,13 +6629,13 @@ function parseMarkdownSection(value) {
5968
6629
  var _a, _b;
5969
6630
  var lines = value.split('\n');
5970
6631
  if (!lines[0].startsWith('#')) {
5971
- throw new ParsingError('Markdown section must start with heading');
6632
+ throw new ParseError('Markdown section must start with heading');
5972
6633
  }
5973
6634
  var title = lines[0].replace(/^#+\s*/, '');
5974
6635
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
5975
6636
  var content = spaceTrim(lines.slice(1).join('\n'));
5976
6637
  if (level < 1 || level > 6) {
5977
- throw new ParsingError('Markdown section must have heading level between 1 and 6');
6638
+ throw new ParseError('Markdown section must have heading level between 1 and 6');
5978
6639
  }
5979
6640
  return { title: title, level: level, content: content };
5980
6641
  }
@@ -6130,31 +6791,32 @@ function removeContentComments(content) {
6130
6791
  *
6131
6792
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
6132
6793
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6133
- * @throws {ParsingError} if the promptbook string is not valid
6794
+ * @throws {ParseError} if the promptbook string is not valid
6134
6795
  * @public exported from `@promptbook/core`
6135
6796
  */
6136
6797
  function pipelineStringToJsonSync(pipelineString) {
6137
6798
  var e_1, _a, e_2, _b;
6138
- var pipelineJson = {
6139
- title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
6799
+ var $pipelineJson = {
6800
+ title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
6140
6801
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
6141
6802
  promptbookVersion: PROMPTBOOK_VERSION,
6142
- description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
6803
+ description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
6143
6804
  parameters: [],
6144
- promptTemplates: [],
6805
+ templates: [],
6145
6806
  knowledgeSources: [],
6146
6807
  knowledgePieces: [],
6147
6808
  personas: [],
6148
6809
  preparations: [],
6810
+ // <- TODO: [🍙] Some standard order of properties
6149
6811
  };
6150
6812
  function getPipelineIdentification() {
6151
6813
  // Note: This is a 😐 implementation of [🚞]
6152
6814
  var _ = [];
6153
- if (pipelineJson.sourceFile !== undefined) {
6154
- _.push("File: ".concat(pipelineJson.sourceFile));
6815
+ if ($pipelineJson.sourceFile !== undefined) {
6816
+ _.push("File: ".concat($pipelineJson.sourceFile));
6155
6817
  }
6156
- if (pipelineJson.pipelineUrl !== undefined) {
6157
- _.push("Url: ".concat(pipelineJson.pipelineUrl));
6818
+ if ($pipelineJson.pipelineUrl !== undefined) {
6819
+ _.push("Url: ".concat($pipelineJson.pipelineUrl));
6158
6820
  }
6159
6821
  return _.join('\n');
6160
6822
  }
@@ -6179,14 +6841,14 @@ function pipelineStringToJsonSync(pipelineString) {
6179
6841
  var defineParam = function (parameterCommand) {
6180
6842
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
6181
6843
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
6182
- throw new ParsingError(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: [🚞] */);
6844
+ 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: [🚞] */);
6183
6845
  }
6184
- var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6846
+ var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6185
6847
  if (existingParameter &&
6186
6848
  existingParameter.description &&
6187
6849
  existingParameter.description !== parameterDescription &&
6188
6850
  parameterDescription) {
6189
- throw new ParsingError(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 "); }));
6851
+ 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 "); }));
6190
6852
  }
6191
6853
  if (existingParameter) {
6192
6854
  if (parameterDescription) {
@@ -6194,7 +6856,7 @@ function pipelineStringToJsonSync(pipelineString) {
6194
6856
  }
6195
6857
  }
6196
6858
  else {
6197
- pipelineJson.parameters.push({
6859
+ $pipelineJson.parameters.push({
6198
6860
  name: parameterName,
6199
6861
  description: parameterDescription || undefined,
6200
6862
  isInput: isInput,
@@ -6204,7 +6866,7 @@ function pipelineStringToJsonSync(pipelineString) {
6204
6866
  };
6205
6867
  // =============================================================
6206
6868
  // Note: 3️⃣ Process pipeline head
6207
- pipelineJson.title = pipelineHead.title;
6869
+ $pipelineJson.title = pipelineHead.title;
6208
6870
  // TODO: [🎾][1] DRY description
6209
6871
  var description = pipelineHead.content;
6210
6872
  // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
@@ -6216,43 +6878,31 @@ function pipelineStringToJsonSync(pipelineString) {
6216
6878
  if (description === '') {
6217
6879
  description = undefined;
6218
6880
  }
6219
- pipelineJson.description = description;
6220
- var defaultModelRequirements = {};
6881
+ $pipelineJson.description = description;
6221
6882
  var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
6222
6883
  var _loop_1 = function (listItem) {
6884
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineHeadCommands`
6223
6885
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
6224
- switch (command.type) {
6225
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6226
- case 'MODEL':
6227
- defaultModelRequirements[command.key] = command.value;
6228
- break;
6229
- case 'PARAMETER':
6230
- defineParam(command);
6231
- break;
6232
- case 'PROMPTBOOK_VERSION':
6233
- pipelineJson.promptbookVersion = command.promptbookVersion;
6234
- break;
6235
- case 'URL':
6236
- pipelineJson.pipelineUrl = command.pipelineUrl.href;
6237
- break;
6238
- case 'KNOWLEDGE':
6239
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6240
- break;
6241
- case 'ACTION':
6242
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6243
- break;
6244
- case 'INSTRUMENT':
6245
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6246
- break;
6247
- case 'PERSONA':
6248
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6249
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6250
- break;
6251
- case 'BOILERPLATE':
6252
- throw new ParsingError(spaceTrim$1(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
6253
- // <- [💐]
6254
- default:
6255
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
6886
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6887
+ if (commandParser === undefined) {
6888
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4E\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6889
+ }
6890
+ if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
6891
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
6892
+ }
6893
+ try {
6894
+ commandParser.$applyToPipelineJson(command, $pipelineJson);
6895
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6896
+ }
6897
+ catch (error) {
6898
+ if (!(error instanceof ParseError)) {
6899
+ throw error;
6900
+ }
6901
+ 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: [🚞]
6902
+ }
6903
+ if (command.type === 'PARAMETER') {
6904
+ defineParam(command);
6905
+ // <- Note: [🍣]
6256
6906
  }
6257
6907
  };
6258
6908
  try {
@@ -6271,27 +6921,7 @@ function pipelineStringToJsonSync(pipelineString) {
6271
6921
  var _loop_2 = function (section) {
6272
6922
  var e_3, _d;
6273
6923
  // TODO: Parse prompt template description (the content out of the codeblock and lists)
6274
- var templateModelRequirements = __assign({}, defaultModelRequirements);
6275
- var listItems_3 = extractAllListItemsFromMarkdown(section.content);
6276
- var lastLine = section.content.split('\n').pop();
6277
- var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6278
- var resultingParameterName = null;
6279
- if (resultingParameterNameMatch &&
6280
- resultingParameterNameMatch.groups !== undefined &&
6281
- resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6282
- resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6283
- }
6284
- var expectResultingParameterName = function () {
6285
- if (resultingParameterName !== null) {
6286
- return resultingParameterName;
6287
- }
6288
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(getPipelineIdentification()), "\n\n Invalid section:\n ").concat(block(
6289
- // TODO: Show code of invalid sections each time + DRY
6290
- section.content
6291
- .split('\n')
6292
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
6293
- .join('\n')), "\n "); }));
6294
- };
6924
+ var listItems_2 = extractAllListItemsFromMarkdown(section.content);
6295
6925
  var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
6296
6926
  // TODO: [🎾][1] DRY description
6297
6927
  var description_1 = section.content;
@@ -6304,176 +6934,121 @@ function pipelineStringToJsonSync(pipelineString) {
6304
6934
  if (description_1 === '') {
6305
6935
  description_1 = undefined;
6306
6936
  }
6307
- var templateJson = {
6308
- blockType: 'PROMPT_TEMPLATE',
6937
+ var $templateJson = {
6938
+ isBlockTypeSet: false,
6939
+ isTemplateBlock: true,
6940
+ blockType: undefined /* <- Note: [🍙] Putting here placeholder to keep `blockType` on top at final JSON */,
6309
6941
  name: titleToName(section.title),
6310
6942
  title: section.title,
6311
6943
  description: description_1,
6312
- modelRequirements: templateModelRequirements,
6313
6944
  content: content,
6945
+ // <- TODO: [🍙] Some standard order of properties
6314
6946
  };
6315
- /**
6316
- * This is nessesary because block type can be
6317
- * - Set zero times, so anticipate 'PROMPT_TEMPLATE'
6318
- * - Set one time
6319
- * - Set more times - throw error
6320
- *
6321
- * Note: [2]
6322
- */
6323
- var isBlockTypeSet = false;
6324
- var _loop_3 = function (listItem) {
6325
- var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
6326
- // TODO [🍧][♓️] List commands and before apply order them
6327
- switch (command.type) {
6328
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6329
- case 'BLOCK':
6330
- if (isBlockTypeSet) {
6331
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Block type is already defined in the prompt template. It can be defined only once.\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
6332
- }
6333
- if (command.blockType === 'SAMPLE') {
6334
- expectResultingParameterName();
6335
- var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
6336
- if (parameter === undefined) {
6337
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6338
- }
6339
- parameter.sampleValues = parameter.sampleValues || [];
6340
- parameter.sampleValues.push(content);
6341
- return "continue-templates";
6342
- }
6343
- if (command.blockType === 'KNOWLEDGE') {
6344
- knowledgeCommandParser.applyToPipelineJson({
6345
- type: 'KNOWLEDGE',
6346
- sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6347
- }, {
6348
- pipelineJson: pipelineJson,
6349
- templateJson: templateJson,
6350
- });
6351
- return "continue-templates";
6352
- }
6353
- if (command.blockType === 'ACTION') {
6354
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6355
- return "continue-templates";
6356
- }
6357
- if (command.blockType === 'INSTRUMENT') {
6358
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6359
- return "continue-templates";
6360
- }
6361
- expectResultingParameterName();
6362
- templateJson.blockType = command.blockType;
6363
- isBlockTypeSet = true; //<- Note: [2]
6364
- break;
6365
- case 'EXPECT_AMOUNT':
6366
- // eslint-disable-next-line no-case-declarations
6367
- var unit_1 = command.unit.toLowerCase();
6368
- templateJson.expectations = templateJson.expectations || {};
6369
- templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
6370
- if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6371
- if (templateJson.expectations[unit_1].min !== undefined) {
6372
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Already defined minumum ".concat(templateJson.expectations[unit_1].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6373
- }
6374
- templateJson.expectations[unit_1].min = command.amount;
6375
- } /* not else */
6376
- if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6377
- if (templateJson.expectations[unit_1].max !== undefined) {
6378
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Already defined maximum ".concat(templateJson.expectations[unit_1].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6379
- }
6380
- templateJson.expectations[unit_1].max = command.amount;
6381
- }
6382
- break;
6383
- case 'EXPECT_FORMAT':
6384
- if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
6385
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6386
- }
6387
- templateJson.expectFormat = command.format;
6388
- break;
6389
- case 'JOKER':
6390
- templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
6391
- templateJson.jokerParameterNames.push(command.parameterName);
6392
- break;
6393
- case 'MODEL':
6394
- templateModelRequirements[command.key] = command.value;
6395
- break;
6396
- case 'PARAMETER':
6397
- // Note: This is just for detecting resulitng parameter name
6398
- defineParam(command);
6399
- break;
6400
- case 'POSTPROCESS':
6401
- templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
6402
- templateJson.postprocessingFunctionNames.push(command.functionName);
6403
- break;
6404
- case 'KNOWLEDGE':
6405
- // TODO: [👙] The knowledge is maybe relevant for just this template
6406
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6407
- break;
6408
- case 'ACTION':
6409
- // TODO: [👙] The action is maybe relevant for just this template
6410
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6411
- break;
6412
- case 'INSTRUMENT':
6413
- // TODO: [👙] The instrument is maybe relevant for just this template
6414
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6415
- break;
6416
- case 'PERSONA':
6417
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6418
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6419
- break;
6420
- case 'BOILERPLATE':
6421
- console.error(new ParsingError(spaceTrim$1(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(getPipelineIdentification()), "\n "); })));
6422
- break;
6423
- // <- [💐]
6424
- default:
6425
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the pipeline\n\n ").concat(block(getPipelineIdentification()), "\n\n "); }));
6947
+ var lastLine = section.content.split('\n').pop();
6948
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6949
+ if (resultingParameterNameMatch &&
6950
+ resultingParameterNameMatch.groups !== undefined &&
6951
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6952
+ $templateJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6953
+ }
6954
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTemplateCommands`
6955
+ var commands = listItems_2.map(function (listItem) { return ({
6956
+ listItem: listItem,
6957
+ command: parseCommand(listItem, 'PIPELINE_TEMPLATE'),
6958
+ }); });
6959
+ // Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
6960
+ if (commands.some(function (_a) {
6961
+ var command = _a.command;
6962
+ return command.type === 'BLOCK';
6963
+ }) === false) {
6964
+ blockCommandParser.$applyToTemplateJson({ type: 'BLOCK', blockType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
6965
+ }
6966
+ var _loop_3 = function (listItem, command) {
6967
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6968
+ if (commandParser === undefined) {
6969
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4F\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6970
+ }
6971
+ if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
6972
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
6973
+ }
6974
+ try {
6975
+ commandParser.$applyToTemplateJson(
6976
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6977
+ command, $templateJson, $pipelineJson);
6978
+ }
6979
+ catch (error) {
6980
+ if (!(error instanceof ParseError)) {
6981
+ throw error;
6982
+ }
6983
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " failed to apply to the template\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the template:\n ").concat(block(JSON.stringify($templateJson, 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: [🚞]
6984
+ }
6985
+ // TODO: !!!!!! Multiple problematic things in BLOCK command - blockCommandParser.$applyToTemplateJson
6986
+ if (command.type === 'PARAMETER') {
6987
+ defineParam(command);
6988
+ // <- Note: [🍣]
6426
6989
  }
6427
6990
  };
6428
6991
  try {
6429
- for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
6430
- var listItem = listItems_2_1.value;
6431
- var state_2 = _loop_3(listItem);
6432
- switch (state_2) {
6433
- case "continue-templates": return state_2;
6434
- }
6992
+ // TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE BLOCK`
6993
+ // TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE BLOCK`
6994
+ // TODO [♓️] List commands and before apply order them
6995
+ for (var commands_1 = (e_3 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
6996
+ var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
6997
+ _loop_3(listItem, command);
6435
6998
  }
6436
6999
  }
6437
7000
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
6438
7001
  finally {
6439
7002
  try {
6440
- if (listItems_2_1 && !listItems_2_1.done && (_d = listItems_2.return)) _d.call(listItems_2);
7003
+ if (commands_1_1 && !commands_1_1.done && (_d = commands_1.return)) _d.call(commands_1);
6441
7004
  }
6442
7005
  finally { if (e_3) throw e_3.error; }
6443
7006
  }
6444
- // TODO: [🍧] Should be done in BLOCK command
6445
- if (templateJson.blockType === 'SCRIPT') {
7007
+ // TODO: [🍧] !!!!!! Should be done in BLOCK command
7008
+ if ($templateJson.blockType === 'SCRIPT_TEMPLATE') {
6446
7009
  if (!language) {
6447
- throw new ParsingError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
7010
+ throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
6448
7011
  }
6449
7012
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
6450
- throw new ParsingError(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 "); }));
7013
+ 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 "); }));
6451
7014
  }
6452
- templateJson.contentLanguage = language;
7015
+ $templateJson.contentLanguage =
7016
+ language;
6453
7017
  }
6454
- // TODO: [🍧][❔] Should be done in BLOCK command
6455
- if (templateModelRequirements.modelVariant === undefined) {
6456
- templateModelRequirements.modelVariant = 'CHAT';
7018
+ $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
7019
+ /*
7020
+ // TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
7021
+ // TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
7022
+ // TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
7023
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
7024
+ throw new UnexpectedError(
7025
+ spaceTrim(
7026
+ (block) => `
7027
+ Model requirements are defined for the block type ${
7028
+ $templateJson.blockType
7029
+ } which is not a prompt template
7030
+
7031
+ This should be avoided by the \`modelCommandParser\`
7032
+
7033
+ ${block(getPipelineIdentification())}
7034
+ `,
7035
+ ),
7036
+ );
6457
7037
  }
6458
- templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
6459
- // TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
6460
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
6461
- delete templateJson.modelRequirements;
7038
+ */
7039
+ if ($templateJson.isTemplateBlock) {
7040
+ delete $templateJson.isBlockTypeSet;
7041
+ delete $templateJson.isTemplateBlock;
7042
+ // TODO: [🍙] Maybe do reorder of `$templateJson` here
7043
+ $pipelineJson.templates.push($templateJson);
6462
7044
  }
6463
- // TODO: [🍧] Make this better - for example each command parser can call and apply this
6464
- templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
6465
- // TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
6466
- pipelineJson.promptTemplates.push(templateJson);
6467
7045
  };
6468
7046
  try {
6469
7047
  // =============================================================
6470
7048
  // Note: 4️⃣ Process each template of the pipeline
6471
- templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
7049
+ /* TODO: !!!!!! Remove `templates:` */ for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
6472
7050
  var section = pipelineSections_1_1.value;
6473
- var state_1 = _loop_2(section);
6474
- switch (state_1) {
6475
- case "continue-templates": continue templates;
6476
- }
7051
+ _loop_2(section);
6477
7052
  }
6478
7053
  }
6479
7054
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -6485,13 +7060,13 @@ function pipelineStringToJsonSync(pipelineString) {
6485
7060
  }
6486
7061
  // =============================================================
6487
7062
  // Note: 5️⃣ Cleanup of undefined values
6488
- pipelineJson.promptTemplates.forEach(function (promptTemplates) {
7063
+ $pipelineJson.templates.forEach(function (templates) {
6489
7064
  var e_4, _a;
6490
7065
  try {
6491
- for (var _b = __values(Object.entries(promptTemplates)), _c = _b.next(); !_c.done; _c = _b.next()) {
7066
+ for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
6492
7067
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
6493
7068
  if (value === undefined) {
6494
- delete promptTemplates[key];
7069
+ delete templates[key];
6495
7070
  }
6496
7071
  }
6497
7072
  }
@@ -6503,7 +7078,7 @@ function pipelineStringToJsonSync(pipelineString) {
6503
7078
  finally { if (e_4) throw e_4.error; }
6504
7079
  }
6505
7080
  });
6506
- pipelineJson.parameters.forEach(function (parameter) {
7081
+ $pipelineJson.parameters.forEach(function (parameter) {
6507
7082
  var e_5, _a;
6508
7083
  try {
6509
7084
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -6522,7 +7097,8 @@ function pipelineStringToJsonSync(pipelineString) {
6522
7097
  }
6523
7098
  });
6524
7099
  // =============================================================
6525
- return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
7100
+ // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
7101
+ return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
6526
7102
  }
6527
7103
  /**
6528
7104
  * TODO: !!!! Warn if used only sync version
@@ -6532,7 +7108,7 @@ function pipelineStringToJsonSync(pipelineString) {
6532
7108
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
6533
7109
  * TODO: [♈] Probbably move expectations from templates to parameters
6534
7110
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
6535
- * TODO: [🍙] Make some standart order of json properties
7111
+ * TODO: [🍙] Make some standard order of json properties
6536
7112
  */
6537
7113
 
6538
7114
  /**
@@ -6549,7 +7125,7 @@ function pipelineStringToJsonSync(pipelineString) {
6549
7125
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
6550
7126
  * @param options - Options and tools for the compilation
6551
7127
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6552
- * @throws {ParsingError} if the promptbook string is not valid
7128
+ * @throws {ParseError} if the promptbook string is not valid
6553
7129
  * @public exported from `@promptbook/core`
6554
7130
  */
6555
7131
  function pipelineStringToJson(pipelineString, options) {
@@ -6594,8 +7170,8 @@ function addAutoGeneratedSection(content, options) {
6594
7170
  }
6595
7171
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
6596
7172
  if (!placeForSection) {
6597
- throw new ParsingError(
6598
- // <- [🧠] Maybe something better tha `ParsingError`
7173
+ throw new ParseError(
7174
+ // <- [🧠] Maybe something better tha `ParseError`
6599
7175
  "No place where to put the section <!--".concat(sectionName, "-->"));
6600
7176
  // <- [🚞]
6601
7177
  }
@@ -6603,6 +7179,7 @@ function addAutoGeneratedSection(content, options) {
6603
7179
  return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
6604
7180
  }
6605
7181
  /**
7182
+ * TODO: !!!!!! Somw way how to connect this with commands
6606
7183
  * TODO: [🏛] This can be part of markdown builder
6607
7184
  */
6608
7185
 
@@ -6678,7 +7255,7 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
6678
7255
  * @public exported from `@promptbook/utils`
6679
7256
  */
6680
7257
  function renderPromptbookMermaid(pipelineJson, options) {
6681
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
7258
+ var _a = (options || {}).linkTemplate, linkTemplate = _a === void 0 ? function () { return null; } : _a;
6682
7259
  var parameterNameToTemplateName = function (parameterName) {
6683
7260
  var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6684
7261
  if (!parameter) {
@@ -6687,13 +7264,13 @@ function renderPromptbookMermaid(pipelineJson, options) {
6687
7264
  if (parameter.isInput) {
6688
7265
  return 'input';
6689
7266
  }
6690
- var template = pipelineJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
7267
+ var template = pipelineJson.templates.find(function (template) { return template.resultingParameterName === parameterName; });
6691
7268
  if (!template) {
6692
7269
  throw new Error("Could not find template for {".concat(parameterName, "}"));
6693
7270
  }
6694
7271
  return normalizeTo_camelCase('template-' + titleToName(template.title));
6695
7272
  };
6696
- 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.promptTemplates
7273
+ 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.templates
6697
7274
  .flatMap(function (_a) {
6698
7275
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
6699
7276
  return __spreadArray([
@@ -6711,14 +7288,14 @@ function renderPromptbookMermaid(pipelineJson, options) {
6711
7288
  var name = _a.name;
6712
7289
  return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
6713
7290
  })
6714
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.promptTemplates
6715
- .map(function (promptTemplate) {
6716
- var link = linkPromptTemplate(promptTemplate);
7291
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.templates
7292
+ .map(function (template) {
7293
+ var link = linkTemplate(template);
6717
7294
  if (link === null) {
6718
7295
  return '';
6719
7296
  }
6720
7297
  var href = link.href, title = link.title;
6721
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
7298
+ var templateName = parameterNameToTemplateName(template.resultingParameterName);
6722
7299
  return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
6723
7300
  })
6724
7301
  .filter(function (line) { return line !== ''; })
@@ -6747,8 +7324,8 @@ function prettifyPipelineString(pipelineString, options) {
6747
7324
  case 1:
6748
7325
  pipelineJson = _a.sent();
6749
7326
  promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
6750
- linkPromptTemplate: function (promptTemplate) {
6751
- return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
7327
+ linkTemplate: function (template) {
7328
+ return { href: "#".concat(template.name), title: template.title };
6752
7329
  },
6753
7330
  });
6754
7331
  promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
@@ -6828,7 +7405,7 @@ function stringifyPipelineJson(pipeline) {
6828
7405
  * TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
6829
7406
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
6830
7407
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
6831
- * TODO: [🍙] Make some standart order of json properties
7408
+ * TODO: [🍙] Make some standard order of json properties
6832
7409
  */
6833
7410
 
6834
7411
  /**
@@ -7820,5 +8397,5 @@ function executionReportJsonToString(executionReportJson, options) {
7820
8397
  * TODO: [🧠] Should be in generated file GENERATOR_WARNING
7821
8398
  */
7822
8399
 
7823
- export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, ERRORS, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, IS_VERBOSE, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _OpenAiMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
8400
+ export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, ERRORS, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, IS_VERBOSE, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _OpenAiMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
7824
8401
  //# sourceMappingURL=index.es.js.map