@promptbook/core 0.68.0-0 → 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/umd/index.umd.js CHANGED
@@ -16,7 +16,7 @@
16
16
  /**
17
17
  * The version of the Promptbook library
18
18
  */
19
- var PROMPTBOOK_VERSION = '0.67.9';
19
+ var PROMPTBOOK_VERSION = '0.68.0-0';
20
20
  // TODO: !!!! List here all the versions and annotate + put into script
21
21
 
22
22
  /*! *****************************************************************************
@@ -217,7 +217,7 @@
217
217
  */
218
218
  function pipelineJsonToString(pipelineJson) {
219
219
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
220
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
220
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
221
221
  var pipelineString = "# ".concat(title);
222
222
  if (description) {
223
223
  pipelineString += '\n\n';
@@ -237,7 +237,7 @@
237
237
  return isInput;
238
238
  })), _h = _g.next(); !_h.done; _h = _g.next()) {
239
239
  var parameter = _h.value;
240
- commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
240
+ commands.push("INPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
241
241
  }
242
242
  }
243
243
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -253,7 +253,7 @@
253
253
  return isOutput;
254
254
  })), _k = _j.next(); !_k.done; _k = _j.next()) {
255
255
  var parameter = _k.value;
256
- commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
256
+ commands.push("OUTPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
257
257
  }
258
258
  }
259
259
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -266,13 +266,13 @@
266
266
  pipelineString += '\n\n';
267
267
  pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
268
268
  try {
269
- for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
270
- var promptTemplate = promptTemplates_1_1.value;
269
+ for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
270
+ var template = templates_1_1.value;
271
271
  var
272
272
  /* Note: Not using:> name, */
273
- title_1 = promptTemplate.title, description_1 = promptTemplate.description,
273
+ title_1 = template.title, description_1 = template.description,
274
274
  /* Note: dependentParameterNames, */
275
- jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
275
+ jokers = template.jokerParameterNames, blockType = template.blockType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
276
276
  pipelineString += '\n\n';
277
277
  pipelineString += "## ".concat(title_1);
278
278
  if (description_1) {
@@ -283,7 +283,7 @@
283
283
  var commands_1 = [];
284
284
  var contentLanguage = 'text';
285
285
  if (blockType === 'PROMPT_TEMPLATE') {
286
- var modelRequirements = promptTemplate.modelRequirements;
286
+ var modelRequirements = template.modelRequirements;
287
287
  var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
288
288
  commands_1.push("EXECUTE PROMPT TEMPLATE");
289
289
  if (modelVariant) {
@@ -297,17 +297,17 @@
297
297
  commands_1.push("SIMPLE TEMPLATE");
298
298
  // Note: Nothing special here
299
299
  }
300
- else if (blockType === 'SCRIPT') {
300
+ else if (blockType === 'SCRIPT_TEMPLATE') {
301
301
  commands_1.push("EXECUTE SCRIPT");
302
- if (promptTemplate.contentLanguage) {
303
- contentLanguage = promptTemplate.contentLanguage;
302
+ if (template.contentLanguage) {
303
+ contentLanguage = template.contentLanguage;
304
304
  }
305
305
  else {
306
306
  contentLanguage = '';
307
307
  }
308
308
  }
309
- else if (blockType === 'PROMPT_DIALOG') {
310
- commands_1.push("PROMPT DIALOG");
309
+ else if (blockType === 'DIALOG_TEMPLATE') {
310
+ commands_1.push("DIALOG BLOCK");
311
311
  // Note: Nothing special here
312
312
  } // <- }else if([🅱]
313
313
  if (jokers) {
@@ -365,10 +365,10 @@
365
365
  finally { if (e_6) throw e_6.error; }
366
366
  }
367
367
  } /* not else */
368
- if (expectFormat) {
369
- if (expectFormat === 'JSON') {
368
+ if (format) {
369
+ if (format === 'JSON') {
370
370
  // TODO: @deprecated remove
371
- commands_1.push("EXPECT JSON");
371
+ commands_1.push("FORMAT JSON");
372
372
  }
373
373
  } /* not else */
374
374
  pipelineString += '\n\n';
@@ -382,13 +382,13 @@
382
382
  pipelineString += '\n';
383
383
  pipelineString += '```';
384
384
  pipelineString += '\n\n';
385
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
385
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use templateParameterJsonToString
386
386
  }
387
387
  }
388
388
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
389
389
  finally {
390
390
  try {
391
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
391
+ if (templates_1_1 && !templates_1_1.done && (_c = templates_1.return)) _c.call(templates_1);
392
392
  }
393
393
  finally { if (e_3) throw e_3.error; }
394
394
  }
@@ -397,8 +397,8 @@
397
397
  /**
398
398
  * @private internal utility of `pipelineJsonToString`
399
399
  */
400
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
401
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
400
+ function templateParameterJsonToString(templateParameterJson) {
401
+ var name = templateParameterJson.name, description = templateParameterJson.description;
402
402
  var parameterString = "{".concat(name, "}");
403
403
  if (description) {
404
404
  parameterString = "".concat(parameterString, " ").concat(description);
@@ -406,7 +406,7 @@
406
406
  return parameterString;
407
407
  }
408
408
  /**
409
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
409
+ * TODO: !!!!!! Implement new features and commands into `templateParameterJsonToString`
410
410
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
411
411
  * TODO: [🏛] Maybe make some markdown builder
412
412
  * TODO: [🏛] Escape all
@@ -767,16 +767,19 @@
767
767
  *
768
768
  * @public exported from `@promptbook/core`
769
769
  */
770
- var ParsingError = /** @class */ (function (_super) {
771
- __extends(ParsingError, _super);
772
- function ParsingError(message) {
770
+ var ParseError = /** @class */ (function (_super) {
771
+ __extends(ParseError, _super);
772
+ function ParseError(message) {
773
773
  var _this = _super.call(this, message) || this;
774
- _this.name = 'ParsingError';
775
- Object.setPrototypeOf(_this, ParsingError.prototype);
774
+ _this.name = 'ParseError';
775
+ Object.setPrototypeOf(_this, ParseError.prototype);
776
776
  return _this;
777
777
  }
778
- return ParsingError;
778
+ return ParseError;
779
779
  }(Error));
780
+ /**
781
+ * TODO: Maybe split `ParseError` and `ApplyError`
782
+ */
780
783
 
781
784
  /**
782
785
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
@@ -988,12 +991,12 @@
988
991
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
989
992
  if (!Array.isArray(pipeline.parameters)) {
990
993
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
991
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
994
+ throw new ParseError(spaceTrim.spaceTrim(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 "); }));
992
995
  }
993
996
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
994
- if (!Array.isArray(pipeline.promptTemplates)) {
997
+ if (!Array.isArray(pipeline.templates)) {
995
998
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
996
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
999
+ throw new ParseError(spaceTrim.spaceTrim(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 "); }));
997
1000
  }
998
1001
  var _loop_1 = function (parameter) {
999
1002
  if (parameter.isInput && parameter.isOutput) {
@@ -1002,12 +1005,12 @@
1002
1005
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
1003
1006
  if (!parameter.isInput &&
1004
1007
  !parameter.isOutput &&
1005
- !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1008
+ !pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1006
1009
  throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
1007
1010
  }
1008
1011
  // Note: Testing that parameter is either input or result of some template
1009
1012
  if (!parameter.isInput &&
1010
- !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1013
+ !pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1011
1014
  throw new PipelineLogicError(spaceTrim.spaceTrim(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 "); }));
1012
1015
  }
1013
1016
  };
@@ -1043,7 +1046,7 @@
1043
1046
  }
1044
1047
  definedParameters.add(template.resultingParameterName);
1045
1048
  if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1046
- if (!template.expectFormat &&
1049
+ if (!template.format &&
1047
1050
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1048
1051
  throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1049
1052
  }
@@ -1095,7 +1098,7 @@
1095
1098
  };
1096
1099
  try {
1097
1100
  // Note: Checking each template individually
1098
- for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
1101
+ for (var _f = __values(pipeline.templates), _g = _f.next(); !_g.done; _g = _f.next()) {
1099
1102
  var template = _g.value;
1100
1103
  _loop_2(template);
1101
1104
  }
@@ -1131,8 +1134,7 @@
1131
1134
  }
1132
1135
  finally { if (e_3) throw e_3.error; }
1133
1136
  }
1134
- var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
1135
- // <- TODO: [🧠][🥜]
1137
+ var unresovedTemplates = __spreadArray([], __read(pipeline.templates), false);
1136
1138
  var loopLimit = LOOP_LIMIT;
1137
1139
  var _loop_3 = function () {
1138
1140
  if (loopLimit-- < 0) {
@@ -1145,14 +1147,14 @@
1145
1147
  if (currentlyResovedTemplates.length === 0) {
1146
1148
  throw new PipelineLogicError(
1147
1149
  // TODO: [🐎] DRY
1148
- spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
1150
+ spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates
1149
1151
  .map(function (_a) {
1150
1152
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1151
1153
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
1152
1154
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1153
1155
  .join(' and '));
1154
1156
  })
1155
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1157
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n\n "); }));
1156
1158
  }
1157
1159
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1158
1160
  var resultingParameterName = _a.resultingParameterName;
@@ -1252,23 +1254,23 @@
1252
1254
  * @public exported from `@promptbook/core`
1253
1255
  */
1254
1256
  function unpreparePipeline(pipeline) {
1255
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1257
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, templates = pipeline.templates;
1256
1258
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1257
1259
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1258
- promptTemplates = promptTemplates.map(function (promptTemplate) {
1259
- var dependentParameterNames = promptTemplate.dependentParameterNames;
1260
- var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
1260
+ templates = templates.map(function (template) {
1261
+ var dependentParameterNames = template.dependentParameterNames;
1262
+ var parameterNames = extractParameterNames(template.preparedContent || '');
1261
1263
  dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1262
- var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
1263
- delete promptTemplateUnprepared.preparedContent;
1264
- return promptTemplateUnprepared;
1264
+ var templateUnprepared = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames });
1265
+ delete templateUnprepared.preparedContent;
1266
+ return templateUnprepared;
1265
1267
  });
1266
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1268
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { templates: templates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1267
1269
  }
1268
1270
  /**
1269
1271
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1270
1272
  * TODO: Write tests for `preparePipeline`
1271
- * TODO: [🍙] Make some standart order of json properties
1273
+ * TODO: [🍙] Make some standard order of json properties
1272
1274
  */
1273
1275
 
1274
1276
  /**
@@ -1587,8 +1589,8 @@
1587
1589
  var BlockTypes = [
1588
1590
  'PROMPT_TEMPLATE',
1589
1591
  'SIMPLE_TEMPLATE',
1590
- 'SCRIPT',
1591
- 'PROMPT_DIALOG',
1592
+ 'SCRIPT_TEMPLATE',
1593
+ 'DIALOG_TEMPLATE',
1592
1594
  'SAMPLE',
1593
1595
  'KNOWLEDGE',
1594
1596
  'INSTRUMENT',
@@ -1792,7 +1794,7 @@
1792
1794
  });
1793
1795
  }
1794
1796
 
1795
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.9",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.9",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.9",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.9",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"}];
1797
+ 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"}];
1796
1798
 
1797
1799
  var defaultDiacriticsRemovalMap = [
1798
1800
  {
@@ -2268,7 +2270,7 @@
2268
2270
  LimitReachedError: LimitReachedError,
2269
2271
  NotFoundError: NotFoundError,
2270
2272
  NotYetImplementedError: NotYetImplementedError,
2271
- ParsingError: ParsingError,
2273
+ ParseError: ParseError,
2272
2274
  PipelineExecutionError: PipelineExecutionError,
2273
2275
  PipelineLogicError: PipelineLogicError,
2274
2276
  PipelineUrlError: PipelineUrlError,
@@ -2325,7 +2327,7 @@
2325
2327
  *
2326
2328
  * @param script from which to extract the variables
2327
2329
  * @returns the list of variable names
2328
- * @throws {ParsingError} if the script is invalid
2330
+ * @throws {ParseError} if the script is invalid
2329
2331
  * @public exported from `@promptbook/utils`
2330
2332
  */
2331
2333
  function extractVariables(script) {
@@ -2361,7 +2363,7 @@
2361
2363
  if (!(error instanceof Error)) {
2362
2364
  throw error;
2363
2365
  }
2364
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2366
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2365
2367
  }
2366
2368
  return variables;
2367
2369
  }
@@ -2372,14 +2374,14 @@
2372
2374
  /**
2373
2375
  * Parses the prompt template and returns the set of all used parameters
2374
2376
  *
2375
- * @param promptTemplate the template with used parameters
2377
+ * @param template the template with used parameters
2376
2378
  * @returns the set of parameter names
2377
- * @throws {ParsingError} if the script is invalid
2379
+ * @throws {ParseError} if the script is invalid
2378
2380
  * @public exported from `@promptbook/utils`
2379
2381
  */
2380
- function extractParameterNamesFromPromptTemplate(promptTemplate) {
2382
+ function extractParameterNamesFromTemplate(template) {
2381
2383
  var e_1, _a, e_2, _b, e_3, _c;
2382
- var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
2384
+ var title = template.title, description = template.description, blockType = template.blockType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
2383
2385
  var parameterNames = new Set();
2384
2386
  try {
2385
2387
  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()) {
@@ -2394,7 +2396,7 @@
2394
2396
  }
2395
2397
  finally { if (e_1) throw e_1.error; }
2396
2398
  }
2397
- if (blockType === 'SCRIPT') {
2399
+ if (blockType === 'SCRIPT_TEMPLATE') {
2398
2400
  try {
2399
2401
  for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
2400
2402
  var parameterName = _g.value;
@@ -2772,7 +2774,7 @@
2772
2774
  *
2773
2775
  * @param markdown any valid markdown
2774
2776
  * @returns code blocks with language and content
2775
- * @throws {ParsingError} if block is not closed properly
2777
+ * @throws {ParseError} if block is not closed properly
2776
2778
  * @public exported from `@promptbook/markdown-utils`
2777
2779
  */
2778
2780
  function extractAllBlocksFromMarkdown(markdown) {
@@ -2808,7 +2810,7 @@
2808
2810
  }
2809
2811
  else {
2810
2812
  if (language !== null) {
2811
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2813
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2812
2814
  }
2813
2815
  codeBlocks.push(currentCodeBlock);
2814
2816
  currentCodeBlock = null;
@@ -2830,7 +2832,7 @@
2830
2832
  finally { if (e_1) throw e_1.error; }
2831
2833
  }
2832
2834
  if (currentCodeBlock !== null) {
2833
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2835
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2834
2836
  }
2835
2837
  return codeBlocks;
2836
2838
  }
@@ -2842,8 +2844,8 @@
2842
2844
  * Extracts extracts exactly one valid JSON code block
2843
2845
  *
2844
2846
  * - When given string is a valid JSON as it is, it just returns it
2845
- * - When there is no JSON code block the function throws a `ParsingError`
2846
- * - When there are multiple JSON code blocks the function throws a `ParsingError`
2847
+ * - When there is no JSON code block the function throws a `ParseError`
2848
+ * - When there are multiple JSON code blocks the function throws a `ParseError`
2847
2849
  *
2848
2850
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
2849
2851
  * Note: There are multiple simmilar function:
@@ -2853,7 +2855,7 @@
2853
2855
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2854
2856
  *
2855
2857
  * @public exported from `@promptbook/markdown-utils`
2856
- * @throws {ParsingError} if there is no valid JSON block in the markdown
2858
+ * @throws {ParseError} if there is no valid JSON block in the markdown
2857
2859
  */
2858
2860
  function extractJsonBlock(markdown) {
2859
2861
  if (isValidJsonString(markdown)) {
@@ -2892,8 +2894,8 @@
2892
2894
  return false;
2893
2895
  }
2894
2896
  /*
2895
- TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2896
- > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2897
+ TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
2898
+ > if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
2897
2899
  > return false;
2898
2900
  > }
2899
2901
  */
@@ -3302,8 +3304,7 @@
3302
3304
  }
3303
3305
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
3304
3306
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
3305
- function getContextForTemplate(// <- TODO: [🧠][🥜]
3306
- template) {
3307
+ function getContextForTemplate(template) {
3307
3308
  return __awaiter(this, void 0, void 0, function () {
3308
3309
  return __generator(this, function (_a) {
3309
3310
  TODO_USE(template);
@@ -3311,8 +3312,7 @@
3311
3312
  });
3312
3313
  });
3313
3314
  }
3314
- function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
3315
- template) {
3315
+ function getKnowledgeForTemplate(template) {
3316
3316
  return __awaiter(this, void 0, void 0, function () {
3317
3317
  return __generator(this, function (_a) {
3318
3318
  // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
@@ -3324,8 +3324,7 @@
3324
3324
  });
3325
3325
  });
3326
3326
  }
3327
- function getSamplesForTemplate(// <- TODO: [🧠][🥜]
3328
- template) {
3327
+ function getSamplesForTemplate(template) {
3329
3328
  return __awaiter(this, void 0, void 0, function () {
3330
3329
  return __generator(this, function (_a) {
3331
3330
  // TODO: [♨] Implement Better - use real index and keyword search
@@ -3392,7 +3391,7 @@
3392
3391
  case 0:
3393
3392
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
3394
3393
  title = currentTemplate.title;
3395
- priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
3394
+ priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3396
3395
  if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
3397
3396
  progress_1 = {
3398
3397
  name: name,
@@ -3415,7 +3414,7 @@
3415
3414
  _h.sent();
3416
3415
  _h.label = 2;
3417
3416
  case 2:
3418
- usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3417
+ usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3419
3418
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3420
3419
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3421
3420
  throw new UnexpectedError(spaceTrim.spaceTrim(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)
@@ -3464,13 +3463,13 @@
3464
3463
  result = null;
3465
3464
  resultString = null;
3466
3465
  expectError = null;
3467
- maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
3466
+ maxAttempts = currentTemplate.blockType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3468
3467
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3469
3468
  preparedContent = (currentTemplate.preparedContent || '{content}')
3470
3469
  .split('{content}')
3471
3470
  .join(currentTemplate.content);
3472
3471
  _loop_5 = function (attempt) {
3473
- 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;
3472
+ 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;
3474
3473
  var e_5, _s, e_7, _t, e_6, _u;
3475
3474
  return __generator(this, function (_v) {
3476
3475
  switch (_v.label) {
@@ -3500,14 +3499,15 @@
3500
3499
  switch (_j) {
3501
3500
  case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3502
3501
  case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3503
- case 'SCRIPT': return [3 /*break*/, 12];
3504
- case 'PROMPT_DIALOG': return [3 /*break*/, 23];
3502
+ case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
3503
+ case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
3505
3504
  }
3506
3505
  return [3 /*break*/, 25];
3507
3506
  case 2:
3508
3507
  resultString = replaceParameters(preparedContent, parameters);
3509
3508
  return [3 /*break*/, 26];
3510
3509
  case 3:
3510
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3511
3511
  prompt = {
3512
3512
  title: currentTemplate.title,
3513
3513
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
@@ -3515,15 +3515,15 @@
3515
3515
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3516
3516
  parameters: parameters,
3517
3517
  content: preparedContent,
3518
- modelRequirements: currentTemplate.modelRequirements,
3518
+ modelRequirements: modelRequirements,
3519
3519
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3520
3520
  var name = _a.name;
3521
3521
  return name === currentTemplate.personaName;
3522
3522
  }) || {})), currentTemplate.expectations),
3523
- expectFormat: currentTemplate.expectFormat,
3523
+ format: currentTemplate.format,
3524
3524
  postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3525
3525
  }; // <- TODO: Not very good type guard
3526
- _k = currentTemplate.modelRequirements.modelVariant;
3526
+ _k = modelRequirements.modelVariant;
3527
3527
  switch (_k) {
3528
3528
  case 'CHAT': return [3 /*break*/, 4];
3529
3529
  case 'COMPLETION': return [3 /*break*/, 6];
@@ -3549,7 +3549,8 @@
3549
3549
  result = embeddingResult;
3550
3550
  resultString = embeddingResult.content.join(',');
3551
3551
  return [3 /*break*/, 11];
3552
- case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n\n "); }));
3552
+ case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
3553
+ .modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3553
3554
  case 11: return [3 /*break*/, 26];
3554
3555
  case 12:
3555
3556
  if (arrayableToArray(tools.script).length === 0) {
@@ -3628,7 +3629,7 @@
3628
3629
  priority: priority,
3629
3630
  }))];
3630
3631
  case 24:
3631
- // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
3632
+ // TODO: [🌹] When making next attempt for `DIALOG BLOCK`, preserve the previous user input
3632
3633
  resultString = _v.sent();
3633
3634
  return [3 /*break*/, 26];
3634
3635
  case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -3714,8 +3715,8 @@
3714
3715
  return [7 /*endfinally*/];
3715
3716
  case 43:
3716
3717
  // TODO: [💝] Unite object for expecting amount and format
3717
- if (currentTemplate.expectFormat) {
3718
- if (currentTemplate.expectFormat === 'JSON') {
3718
+ if (currentTemplate.format) {
3719
+ if (currentTemplate.format === 'JSON') {
3719
3720
  if (!isValidJsonString(resultString || '')) {
3720
3721
  // TODO: [🏢] Do more universally via `FormatDefinition`
3721
3722
  try {
@@ -3729,7 +3730,7 @@
3729
3730
  }
3730
3731
  }
3731
3732
  else {
3732
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3733
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3733
3734
  }
3734
3735
  }
3735
3736
  // TODO: [💝] Unite object for expecting amount and format
@@ -4005,7 +4006,7 @@
4005
4006
  var name = _a.name;
4006
4007
  return name;
4007
4008
  });
4008
- unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.promptTemplates), false);
4009
+ unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.templates), false);
4009
4010
  resolving_1 = [];
4010
4011
  loopLimit = LOOP_LIMIT;
4011
4012
  _loop_2 = function () {
@@ -4126,7 +4127,7 @@
4126
4127
  * TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
4127
4128
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
4128
4129
  * TODO: [♈] Probbably move expectations from templates to parameters
4129
- * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
4130
+ * TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
4130
4131
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
4131
4132
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
4132
4133
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
@@ -4496,7 +4497,7 @@
4496
4497
  */
4497
4498
  function clonePipeline(pipeline) {
4498
4499
  // Note: Not using spread operator (...) because @@@
4499
- 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;
4500
+ 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;
4500
4501
  return {
4501
4502
  pipelineUrl: pipelineUrl,
4502
4503
  sourceFile: sourceFile,
@@ -4504,7 +4505,7 @@
4504
4505
  promptbookVersion: promptbookVersion,
4505
4506
  description: description,
4506
4507
  parameters: parameters,
4507
- promptTemplates: promptTemplates,
4508
+ templates: templates,
4508
4509
  knowledgeSources: knowledgeSources,
4509
4510
  knowledgePieces: knowledgePieces,
4510
4511
  personas: personas,
@@ -4512,7 +4513,7 @@
4512
4513
  };
4513
4514
  }
4514
4515
  /**
4515
- * TODO: [🍙] Make some standart order of json properties
4516
+ * TODO: [🍙] Make some standard order of json properties
4516
4517
  */
4517
4518
 
4518
4519
  /**
@@ -4522,19 +4523,19 @@
4522
4523
  */
4523
4524
  function prepareTemplates(pipeline, options) {
4524
4525
  return __awaiter(this, void 0, void 0, function () {
4525
- var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
4526
+ var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
4526
4527
  var _this = this;
4527
4528
  return __generator(this, function (_b) {
4528
4529
  switch (_b.label) {
4529
4530
  case 0:
4530
4531
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
4531
- promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4532
+ templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4532
4533
  // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
4533
4534
  TODO_USE(parameters);
4534
- promptTemplatesPrepared = new Array(
4535
+ templatesPrepared = new Array(
4535
4536
  // <- TODO: [🧱] Implement in a functional (not new Class) way
4536
- promptTemplates.length);
4537
- 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 () {
4537
+ templates.length);
4538
+ 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 () {
4538
4539
  var dependentParameterNames, preparedContent, preparedTemplate;
4539
4540
  return __generator(this, function (_a) {
4540
4541
  dependentParameterNames = template.dependentParameterNames;
@@ -4547,13 +4548,13 @@
4547
4548
  ], false);
4548
4549
  }
4549
4550
  preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
4550
- promptTemplatesPrepared[index] = preparedTemplate;
4551
+ templatesPrepared[index] = preparedTemplate;
4551
4552
  return [2 /*return*/];
4552
4553
  });
4553
4554
  }); })];
4554
4555
  case 1:
4555
4556
  _b.sent();
4556
- return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
4557
+ return [2 /*return*/, { templatesPrepared: templatesPrepared }];
4557
4558
  }
4558
4559
  });
4559
4560
  });
@@ -4566,7 +4567,6 @@
4566
4567
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4567
4568
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
4568
4569
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4569
- * TODO: [🧠][🥜]
4570
4570
  */
4571
4571
 
4572
4572
  /**
@@ -4579,12 +4579,12 @@
4579
4579
  */
4580
4580
  function preparePipeline(pipeline, options) {
4581
4581
  return __awaiter(this, void 0, void 0, function () {
4582
- var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
4582
+ var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, templates,
4583
4583
  /*
4584
4584
  <- TODO: [🧠][🪑] `promptbookVersion` */
4585
4585
  knowledgeSources /*
4586
4586
  <- TODO: [🧊] `knowledgePieces` */, personas /*
4587
- <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
4587
+ <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
4588
4588
  var _this = this;
4589
4589
  return __generator(this, function (_c) {
4590
4590
  switch (_c.label) {
@@ -4593,7 +4593,7 @@
4593
4593
  return [2 /*return*/, pipeline];
4594
4594
  }
4595
4595
  llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
4596
- parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4596
+ parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4597
4597
  llmToolsWithUsage = countTotalUsage(llmTools);
4598
4598
  currentPreparation = {
4599
4599
  id: 1,
@@ -4639,7 +4639,7 @@
4639
4639
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
4640
4640
  return [4 /*yield*/, prepareTemplates({
4641
4641
  parameters: parameters,
4642
- promptTemplates: promptTemplates,
4642
+ templates: templates,
4643
4643
  knowledgePiecesCount: knowledgePiecesPrepared.length,
4644
4644
  }, {
4645
4645
  llmTools: llmToolsWithUsage,
@@ -4647,11 +4647,11 @@
4647
4647
  isVerbose: isVerbose,
4648
4648
  })];
4649
4649
  case 3:
4650
- promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
4650
+ templatesPrepared = (_c.sent()).templatesPrepared;
4651
4651
  // ----- /Templates preparation -----
4652
4652
  // Note: Count total usage
4653
4653
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
4654
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4654
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: templatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4655
4655
  }
4656
4656
  });
4657
4657
  });
@@ -4705,7 +4705,8 @@
4705
4705
  /**
4706
4706
  * BOILERPLATE command can be used in:
4707
4707
  */
4708
- usagePlaces: ['PIPELINE_HEAD'],
4708
+ isUsedInPipelineHead: true,
4709
+ isUsedInPipelineTemplate: false,
4709
4710
  /**
4710
4711
  * Description of the KNOWLEDGE command
4711
4712
  */
@@ -4731,17 +4732,17 @@
4731
4732
  var args = input.args;
4732
4733
  var sourceContent = spaceTrim__default["default"](args[0] || '');
4733
4734
  if (sourceContent === '') {
4734
- throw new ParsingError("Source is not defined");
4735
+ throw new ParseError("Source is not defined");
4735
4736
  }
4736
4737
  // TODO: !!!! Following checks should be applied every link in the `sourceContent`
4737
4738
  if (sourceContent.startsWith('http://')) {
4738
- throw new ParsingError("Source is not secure");
4739
+ throw new ParseError("Source is not secure");
4739
4740
  }
4740
4741
  if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
4741
- throw new ParsingError("Source not valid");
4742
+ throw new ParseError("Source not valid");
4742
4743
  }
4743
4744
  if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
4744
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
4745
+ throw new ParseError("Source cannot be outside of the .ptbk.md folder");
4745
4746
  }
4746
4747
  return {
4747
4748
  type: 'KNOWLEDGE',
@@ -4749,194 +4750,40 @@
4749
4750
  };
4750
4751
  },
4751
4752
  /**
4752
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4753
+ * Apply the KNOWLEDGE command to the `pipelineJson`
4754
+ *
4755
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
4753
4756
  */
4754
- applyToPipelineJson: function (personaCommand, subjects) {
4755
- var sourceContent = personaCommand.sourceContent;
4756
- var pipelineJson = subjects.pipelineJson;
4757
+ $applyToPipelineJson: function (command, $pipelineJson) {
4758
+ var sourceContent = command.sourceContent;
4757
4759
  var name = 'source-' + sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(sourceContent))).toString( /* hex */);
4758
4760
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
4759
4761
  // <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
4760
- pipelineJson.knowledgeSources.push({
4762
+ $pipelineJson.knowledgeSources.push({
4761
4763
  name: name,
4762
4764
  sourceContent: sourceContent,
4763
4765
  });
4764
4766
  },
4765
- };
4766
-
4767
- /**
4768
- * Parses the persona command
4769
- *
4770
- * @see ./PERSONA-README.md for more details
4771
- * @private within the commands folder
4772
- */
4773
- var personaCommandParser = {
4774
- /**
4775
- * Name of the command
4776
- */
4777
- name: 'PERSONA',
4778
- /**
4779
- * Aliases for the PERSONA command
4780
- */
4781
- aliasNames: ['PERSON'],
4782
- /**
4783
- * PERSONA command can be used in:
4784
- */
4785
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
4786
- /**
4787
- * Description of the PERSONA command
4788
- */
4789
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
4790
- /**
4791
- * Link to discussion
4792
- */
4793
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
4794
- /**
4795
- * Example usages of the PERSONA command
4796
- */
4797
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
4798
4767
  /**
4799
- * Parses the PERSONA command
4768
+ * Converts the KNOWLEDGE command back to string
4769
+ *
4770
+ * Note: This is used in `pipelineJsonToString` utility
4800
4771
  */
4801
- parse: function (input) {
4802
- var rawArgs = input.rawArgs;
4803
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
4804
- var personaName = (personaNameRaw || '').trim();
4805
- if (personaName === '') {
4806
- throw new ParsingError("You must set name for the persona");
4807
- }
4808
- var personaDescription = (personaDescriptionRaw || '').trim();
4809
- if (personaDescription === '') {
4810
- personaDescription = null;
4811
- }
4812
- return {
4813
- type: 'PERSONA',
4814
- personaName: personaName,
4815
- personaDescription: personaDescription,
4816
- };
4772
+ stringify: function (command) {
4773
+ keepUnused(command);
4774
+ return "!!!!!!";
4817
4775
  },
4818
4776
  /**
4819
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4777
+ * Reads the KNOWLEDGE command from the `PipelineJson`
4778
+ *
4779
+ * Note: This is used in `pipelineJsonToString` utility
4820
4780
  */
4821
- applyToPipelineJson: function (personaCommand, subjects) {
4822
- var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
4823
- var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
4824
- if (templateJson !== null) {
4825
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
4826
- throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
4827
- }
4828
- templateJson.personaName = personaName;
4829
- }
4830
- var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
4831
- if (persona === undefined) {
4832
- pipelineJson.personas.push({
4833
- name: personaName,
4834
- description: personaDescription || '',
4835
- });
4836
- return;
4837
- }
4838
- if (persona.description === personaDescription) {
4839
- return;
4840
- }
4841
- if (personaDescription === null) {
4842
- return;
4843
- }
4844
- if (persona.description === '') {
4845
- persona.description = personaDescription;
4846
- return;
4847
- }
4848
- console.warn(spaceTrim__default["default"]("\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 ")));
4849
- persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
4781
+ takeFromPipelineJson: function (pipelineJson) {
4782
+ keepUnused(pipelineJson);
4783
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4850
4784
  },
4851
4785
  };
4852
4786
 
4853
- /**
4854
- * Removes Markdown formatting tags from a string.
4855
- *
4856
- * @param {string} str - The string to remove Markdown tags from.
4857
- * @returns {string} The input string with all Markdown tags removed.
4858
- * @public exported from `@promptbook/markdown-utils`
4859
- */
4860
- function removeMarkdownFormatting(str) {
4861
- // Remove bold formatting
4862
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
4863
- // Remove italic formatting
4864
- str = str.replace(/\*(.*?)\*/g, '$1');
4865
- // Remove code formatting
4866
- str = str.replace(/`(.*?)`/g, '$1');
4867
- return str;
4868
- }
4869
-
4870
- /**
4871
- * @@@
4872
- *
4873
- * @param text @@@
4874
- * @returns @@@
4875
- * @example 'HELLO_WORLD'
4876
- * @example 'I_LOVE_PROMPTBOOK'
4877
- * @public exported from `@promptbook/utils`
4878
- */
4879
- function normalizeTo_SCREAMING_CASE(text) {
4880
- var e_1, _a;
4881
- var charType;
4882
- var lastCharType = 'OTHER';
4883
- var normalizedName = '';
4884
- try {
4885
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
4886
- var char = text_1_1.value;
4887
- var normalizedChar = void 0;
4888
- if (/^[a-z]$/.test(char)) {
4889
- charType = 'LOWERCASE';
4890
- normalizedChar = char.toUpperCase();
4891
- }
4892
- else if (/^[A-Z]$/.test(char)) {
4893
- charType = 'UPPERCASE';
4894
- normalizedChar = char;
4895
- }
4896
- else if (/^[0-9]$/.test(char)) {
4897
- charType = 'NUMBER';
4898
- normalizedChar = char;
4899
- }
4900
- else if (/^\/$/.test(char)) {
4901
- charType = 'SLASH';
4902
- normalizedChar = char;
4903
- }
4904
- else {
4905
- charType = 'OTHER';
4906
- normalizedChar = '_';
4907
- }
4908
- if (charType !== lastCharType &&
4909
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
4910
- !(lastCharType === 'NUMBER') &&
4911
- !(charType === 'NUMBER')) {
4912
- normalizedName += '_';
4913
- }
4914
- normalizedName += normalizedChar;
4915
- lastCharType = charType;
4916
- }
4917
- }
4918
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4919
- finally {
4920
- try {
4921
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
4922
- }
4923
- finally { if (e_1) throw e_1.error; }
4924
- }
4925
- normalizedName = normalizedName.replace(/_+/g, '_');
4926
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
4927
- normalizedName = normalizedName.replace(/^_/, '');
4928
- normalizedName = normalizedName.replace(/_$/, '');
4929
- return normalizedName;
4930
- }
4931
- /**
4932
- * TODO: Tests
4933
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
4934
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
4935
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
4936
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
4937
- * TODO: [🌺] Use some intermediate util splitWords
4938
- */
4939
-
4940
4787
  /**
4941
4788
  * Parses the block command
4942
4789
  *
@@ -4954,8 +4801,8 @@
4954
4801
  aliasNames: [
4955
4802
  'PROMPT_TEMPLATE',
4956
4803
  'SIMPLE_TEMPLATE',
4957
- 'SCRIPT',
4958
- 'PROMPT_DIALOG',
4804
+ 'SCRIPT_TEMPLATE',
4805
+ 'DIALOG_TEMPLATE',
4959
4806
  'SAMPLE',
4960
4807
  'EXAMPLE',
4961
4808
  'KNOWLEDGE',
@@ -4970,7 +4817,8 @@
4970
4817
  /**
4971
4818
  * BOILERPLATE command can be used in:
4972
4819
  */
4973
- usagePlaces: ['PIPELINE_TEMPLATE'],
4820
+ isUsedInPipelineHead: false,
4821
+ isUsedInPipelineTemplate: true,
4974
4822
  /**
4975
4823
  * Description of the BLOCK command
4976
4824
  */
@@ -4983,19 +4831,24 @@
4983
4831
  * Example usages of the BLOCK command
4984
4832
  */
4985
4833
  examples: [
4986
- 'Prompt template BLOCK',
4987
- 'Prompt template',
4988
- 'Simple template BLOCK',
4989
- 'Simple template',
4990
- 'Script BLOCK',
4991
- 'Script',
4992
- 'Prompt dialog BLOCK',
4993
- 'Prompt dialog',
4994
- 'Sample BLOCK',
4995
- 'Sample',
4996
- 'Example BLOCK',
4997
- 'Example',
4998
- 'Knowledge BLOCK',
4834
+ // Recommended form:
4835
+ 'PROMPT BLOCK',
4836
+ 'SIMPLE BLOCK',
4837
+ 'SCRIPT BLOCK',
4838
+ 'DIALOG BLOCK',
4839
+ // <- [🅱]
4840
+ // Long form:
4841
+ 'PROMPT TEMPLATE BLOCK',
4842
+ 'SIMPLE TEMPLATE BLOCK',
4843
+ 'SCRIPT TEMPLATE BLOCK',
4844
+ 'DIALOG TEMPLATE BLOCK',
4845
+ // <- [🅱]
4846
+ // Reversed form:
4847
+ 'BLOCK PROMPT TEMPLATE',
4848
+ 'BLOCK SIMPLE TEMPLATE',
4849
+ 'BLOCK SCRIPT TEMPLATE',
4850
+ 'BLOCK DIALOG TEMPLATE',
4851
+ // <- [🅱]
4999
4852
  // 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
5000
4853
  //---
5001
4854
  /* Note: Not implemented block types will be in examples in future -> */
@@ -5013,9 +4866,9 @@
5013
4866
  parse: function (input) {
5014
4867
  var normalized = input.normalized;
5015
4868
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
5016
- var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
4869
+ var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType.split('_TEMPLATE').join('')); });
5017
4870
  if (blockTypes.length !== 1) {
5018
- throw new ParsingError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
4871
+ throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
5019
4872
  }
5020
4873
  var blockType = blockTypes[0];
5021
4874
  return {
@@ -5023,6 +4876,94 @@
5023
4876
  blockType: blockType,
5024
4877
  };
5025
4878
  },
4879
+ /**
4880
+ * Apply the BLOCK command to the `pipelineJson`
4881
+ *
4882
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
4883
+ */
4884
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
4885
+ // TODO: !!!!!! Test multiple / no block type
4886
+ if ($templateJson.isBlockTypeSet === true) {
4887
+ throw new ParseError("Block type is already defined in the prompt template. It can be defined only once.");
4888
+ }
4889
+ $templateJson.isBlockTypeSet = true;
4890
+ // TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
4891
+ var expectResultingParameterName = function () {
4892
+ if ($templateJson.resultingParameterName) {
4893
+ return;
4894
+ }
4895
+ throw new ParseError(" Template section must end with -> {parameterName}");
4896
+ };
4897
+ if ($templateJson.content === undefined) {
4898
+ throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
4899
+ }
4900
+ if (command.blockType === 'SAMPLE') {
4901
+ expectResultingParameterName();
4902
+ var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
4903
+ if (parameter === undefined) {
4904
+ throw new ParseError("Can not find parameter {".concat($templateJson.resultingParameterName, "} to assign sample value on it"));
4905
+ }
4906
+ parameter.sampleValues = parameter.sampleValues || [];
4907
+ parameter.sampleValues.push($templateJson.content);
4908
+ // TODO: !!!!!! How to implement this?
4909
+ // continue templates;
4910
+ $templateJson.isTemplateBlock = false;
4911
+ return;
4912
+ }
4913
+ if (command.blockType === 'KNOWLEDGE') {
4914
+ knowledgeCommandParser.$applyToPipelineJson({
4915
+ type: 'KNOWLEDGE',
4916
+ sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
4917
+ }, $pipelineJson);
4918
+ // TODO: !!!!!! How to implement this?
4919
+ // continue templates;
4920
+ $templateJson.isTemplateBlock = false;
4921
+ return;
4922
+ }
4923
+ if (command.blockType === 'ACTION') {
4924
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
4925
+ // TODO: !!!!!! How to implement this?
4926
+ // continue templates;
4927
+ $templateJson.isTemplateBlock = false;
4928
+ return;
4929
+ }
4930
+ if (command.blockType === 'INSTRUMENT') {
4931
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4932
+ // TODO: !!!!!! How to implement this?
4933
+ // continue templates;
4934
+ $templateJson.isTemplateBlock = false;
4935
+ return;
4936
+ }
4937
+ expectResultingParameterName();
4938
+ $templateJson.blockType = command.blockType;
4939
+ /*
4940
+ TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
4941
+ if (command.blockType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
4942
+ templateModelRequirements.modelVariant = 'CHAT';
4943
+ }
4944
+ */
4945
+ // !!!!!!
4946
+ // isBlockTypeSet = true; //<- Note: [2]
4947
+ $templateJson.isTemplateBlock = true;
4948
+ },
4949
+ /**
4950
+ * Converts the BLOCK command back to string
4951
+ *
4952
+ * Note: This is used in `pipelineJsonToString` utility
4953
+ */
4954
+ stringify: function (command) {
4955
+ keepUnused(command);
4956
+ return "!!!!!!";
4957
+ },
4958
+ /**
4959
+ * Reads the BLOCK command from the `TemplateJson`
4960
+ *
4961
+ * Note: This is used in `pipelineJsonToString` utility
4962
+ */
4963
+ takeFromTemplateJson: function ($templateJson) {
4964
+ keepUnused($templateJson);
4965
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4966
+ },
5026
4967
  };
5027
4968
 
5028
4969
  /**
@@ -5033,7 +4974,7 @@
5033
4974
  */
5034
4975
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
5035
4976
  /**
5036
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
4977
+ * TODO: [💝] Unite object for expecting amount and format - remove format
5037
4978
  */
5038
4979
 
5039
4980
  /**
@@ -5043,7 +4984,7 @@
5043
4984
  * Note: it also works only with decimal numbers
5044
4985
  *
5045
4986
  * @returns parsed number
5046
- * @throws {ParsingError} if the value is not a number
4987
+ * @throws {ParseError} if the value is not a number
5047
4988
  *
5048
4989
  * @public exported from `@promptbook/utils`
5049
4990
  */
@@ -5079,7 +5020,7 @@
5079
5020
  var numerator = parseNumber(numerator_);
5080
5021
  var denominator = parseNumber(denominator_);
5081
5022
  if (denominator === 0) {
5082
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
5023
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
5083
5024
  }
5084
5025
  return numerator / denominator;
5085
5026
  }
@@ -5091,11 +5032,11 @@
5091
5032
  return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
5092
5033
  }
5093
5034
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
5094
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\""));
5035
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
5095
5036
  }
5096
5037
  var num = parseFloat(value);
5097
5038
  if (isNaN(num)) {
5098
- throw new ParsingError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
5039
+ throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
5099
5040
  }
5100
5041
  return num;
5101
5042
  }
@@ -5118,9 +5059,10 @@
5118
5059
  /**
5119
5060
  * BOILERPLATE command can be used in:
5120
5061
  */
5121
- usagePlaces: ['PIPELINE_TEMPLATE'],
5062
+ isUsedInPipelineHead: false,
5063
+ isUsedInPipelineTemplate: true,
5122
5064
  /**
5123
- * Description of the EXPECT command
5065
+ * Description of the FORMAT command
5124
5066
  */
5125
5067
  description: spaceTrim__default["default"]("\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 "),
5126
5068
  /**
@@ -5128,7 +5070,7 @@
5128
5070
  */
5129
5071
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
5130
5072
  /**
5131
- * Example usages of the EXPECT command
5073
+ * Example usages of the FORMAT command
5132
5074
  */
5133
5075
  examples: [
5134
5076
  'EXPECT MIN 100 Characters',
@@ -5136,22 +5078,13 @@
5136
5078
  'EXPECT EXACTLY 3 Sentences',
5137
5079
  'EXPECT EXACTLY 1 Paragraph',
5138
5080
  // <- TODO: 'EXPECT 1 Paragraph',
5139
- 'Expect JSON',
5140
5081
  ],
5141
5082
  /**
5142
- * Parses the EXPECT command
5083
+ * Parses the FORMAT command
5143
5084
  */
5144
5085
  parse: function (input) {
5145
5086
  var e_1, _a;
5146
- var args = input.args, normalized = input.normalized;
5147
- if (normalized.startsWith('EXPECT_JSON')) {
5148
- return {
5149
- type: 'EXPECT_FORMAT',
5150
- format: 'JSON',
5151
- };
5152
- // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5153
- // [🥤]
5154
- }
5087
+ var args = input.args;
5155
5088
  try {
5156
5089
  var sign = void 0;
5157
5090
  var signRaw = args.shift();
@@ -5165,15 +5098,15 @@
5165
5098
  sign = 'MAXIMUM';
5166
5099
  }
5167
5100
  else {
5168
- throw new ParsingError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
5101
+ throw new ParseError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
5169
5102
  }
5170
5103
  var amountRaw = args.shift();
5171
5104
  var amount = parseNumber(amountRaw);
5172
5105
  if (amount < 0) {
5173
- throw new ParsingError('Amount must be positive number or zero');
5106
+ throw new ParseError('Amount must be positive number or zero');
5174
5107
  }
5175
5108
  if (amount !== Math.floor(amount)) {
5176
- throw new ParsingError('Amount must be whole number');
5109
+ throw new ParseError('Amount must be whole number');
5177
5110
  }
5178
5111
  var unitRaw = args.shift();
5179
5112
  var unit = undefined;
@@ -5188,7 +5121,7 @@
5188
5121
  if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
5189
5122
  new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
5190
5123
  if (unit !== undefined) {
5191
- throw new ParsingError("Ambiguous unit \"".concat(unitRaw, "\""));
5124
+ throw new ParseError("Ambiguous unit \"".concat(unitRaw, "\""));
5192
5125
  }
5193
5126
  unit = existingUnit;
5194
5127
  }
@@ -5202,10 +5135,10 @@
5202
5135
  finally { if (e_1) throw e_1.error; }
5203
5136
  }
5204
5137
  if (unit === undefined) {
5205
- throw new ParsingError("Invalid unit \"".concat(unitRaw, "\""));
5138
+ throw new ParseError("Invalid unit \"".concat(unitRaw, "\""));
5206
5139
  }
5207
5140
  return {
5208
- type: 'EXPECT_AMOUNT',
5141
+ type: 'EXPECT',
5209
5142
  sign: sign,
5210
5143
  unit: unit,
5211
5144
  amount: amount,
@@ -5215,97 +5148,321 @@
5215
5148
  if (!(error instanceof Error)) {
5216
5149
  throw error;
5217
5150
  }
5218
- throw new ParsingError(spaceTrim__default["default"](function (block) {
5219
- return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
5151
+ throw new ParseError(spaceTrim__default["default"](function (block) {
5152
+ return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
5220
5153
  }));
5221
5154
  }
5222
5155
  },
5156
+ /**
5157
+ * Apply the FORMAT command to the `pipelineJson`
5158
+ *
5159
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5160
+ */
5161
+ $applyToTemplateJson: function (command, $templateJson) {
5162
+ // eslint-disable-next-line no-case-declarations
5163
+ var unit = command.unit.toLowerCase();
5164
+ $templateJson.expectations = $templateJson.expectations || {};
5165
+ $templateJson.expectations[unit] = $templateJson.expectations[unit] || {};
5166
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
5167
+ if ($templateJson.expectations[unit].min !== undefined) {
5168
+ throw new ParseError("Already defined minumum ".concat($templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5169
+ }
5170
+ $templateJson.expectations[unit].min = command.amount;
5171
+ } /* not else */
5172
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
5173
+ if ($templateJson.expectations[unit].max !== undefined) {
5174
+ throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5175
+ }
5176
+ $templateJson.expectations[unit].max = command.amount;
5177
+ }
5178
+ },
5179
+ /**
5180
+ * Converts the FORMAT command back to string
5181
+ *
5182
+ * Note: This is used in `pipelineJsonToString` utility
5183
+ */
5184
+ stringify: function (command) {
5185
+ keepUnused(command);
5186
+ return "!!!!!!";
5187
+ },
5188
+ /**
5189
+ * Reads the FORMAT command from the `TemplateJson`
5190
+ *
5191
+ * Note: This is used in `pipelineJsonToString` utility
5192
+ */
5193
+ takeFromTemplateJson: function ($templateJson) {
5194
+ keepUnused($templateJson);
5195
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5196
+ },
5223
5197
  };
5224
5198
 
5225
5199
  /**
5226
- * Parses the joker command
5200
+ * Parses the foreach command
5227
5201
  *
5228
- * @see ./JOKER-README.md for more details
5202
+ * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
5203
+ *
5204
+ * @see ./FOREACH-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5229
5205
  * @private within the commands folder
5230
5206
  */
5231
- var jokerCommandParser = {
5207
+ var foreachCommandParser = {
5232
5208
  /**
5233
5209
  * Name of the command
5234
5210
  */
5235
- name: 'JOKER',
5211
+ name: 'FOREACH',
5236
5212
  /**
5237
- * BOILERPLATE command can be used in:
5213
+ * Aliases for the FOREACH command
5238
5214
  */
5239
- usagePlaces: ['PIPELINE_TEMPLATE'],
5215
+ aliasNames: ['FOR', 'EACH'],
5240
5216
  /**
5241
- * Description of the JOKER command
5217
+ * FOREACH command can be used in:
5242
5218
  */
5243
- description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5219
+ isUsedInPipelineHead: false,
5220
+ isUsedInPipelineTemplate: true,
5221
+ /**
5222
+ * Description of the FOREACH command
5223
+ */
5224
+ description: "@@",
5244
5225
  /**
5245
5226
  * Link to discussion
5246
5227
  */
5247
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5228
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5248
5229
  /**
5249
- * Example usages of the JOKER command
5230
+ * Example usages of the FOREACH command
5250
5231
  */
5251
- examples: ['JOKER {documentTitle}'],
5232
+ examples: [
5233
+ 'FOREACH List Line -> `{customer}`',
5234
+ 'FOR List Line -> `{customer}`',
5235
+ 'EACH List Line -> `{customer}`',
5236
+ // <- TODO: [🍭] More
5237
+ ],
5252
5238
  /**
5253
- * Parses the JOKER command
5239
+ * Parses the FOREACH command
5254
5240
  */
5255
5241
  parse: function (input) {
5256
5242
  var args = input.args;
5257
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5258
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5259
- throw new ParsingError("Invalid joker");
5260
- }
5261
- var parameterName = parametersMatch.groups.parameterName;
5243
+ keepUnused(args);
5244
+ // <- TODO: [🍭] Implement
5262
5245
  return {
5263
- type: 'JOKER',
5264
- parameterName: parameterName,
5246
+ type: 'FOREACH',
5265
5247
  };
5266
5248
  },
5249
+ /**
5250
+ * Apply the FOREACH command to the `pipelineJson`
5251
+ *
5252
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5253
+ */
5254
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5255
+ keepUnused(command, $templateJson, $pipelineJson);
5256
+ // <- TODO: [🍭] Implement
5257
+ },
5258
+ /**
5259
+ * Converts the FOREACH command back to string
5260
+ *
5261
+ * Note: This is used in `pipelineJsonToString` utility
5262
+ */
5263
+ stringify: function (command) {
5264
+ keepUnused(command);
5265
+ return "";
5266
+ // <- TODO: [🍭] Implement
5267
+ },
5268
+ /**
5269
+ * Reads the FOREACH command from the `TemplateJson`
5270
+ *
5271
+ * Note: This is used in `pipelineJsonToString` utility
5272
+ */
5273
+ takeFromTemplateJson: function ($templateJson) {
5274
+ keepUnused($templateJson);
5275
+ return [];
5276
+ // <- TODO: [🍭] Implement
5277
+ },
5267
5278
  };
5268
-
5269
5279
  /**
5270
- * @@@
5271
- *
5272
- * @public exported from `@promptbook/core`
5280
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong syntax and logic
5273
5281
  */
5274
- var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5275
5282
 
5276
5283
  /**
5277
- * Parses the model command
5284
+ * Parses the format command
5278
5285
  *
5279
- * @see ./MODEL-README.md for more details
5286
+ * @see ./FORMAT-README.md for more details
5280
5287
  * @private within the commands folder
5281
5288
  */
5282
- var modelCommandParser = {
5289
+ var formatCommandParser = {
5283
5290
  /**
5284
5291
  * Name of the command
5285
5292
  */
5286
- name: 'MODEL',
5293
+ name: 'FORMAT',
5287
5294
  /**
5288
5295
  * BOILERPLATE command can be used in:
5289
5296
  */
5290
- usagePlaces: [
5291
- 'PIPELINE_HEAD',
5292
- // <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
5293
- 'PIPELINE_TEMPLATE',
5294
- ],
5297
+ isUsedInPipelineHead: false,
5298
+ isUsedInPipelineTemplate: true,
5295
5299
  /**
5296
- * Description of the MODEL command
5300
+ * Description of the FORMAT command
5297
5301
  */
5298
- description: "Tells which model and modelRequirements to use for the prompt template execution",
5302
+ description: spaceTrim__default["default"]("\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 "),
5299
5303
  /**
5300
5304
  * Link to discussion
5301
5305
  */
5302
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5306
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
5303
5307
  /**
5304
- * Example usages of the MODEL command
5308
+ * Example usages of the FORMAT command
5305
5309
  */
5306
- examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5310
+ examples: ['FORMAT JSON'],
5307
5311
  /**
5308
- * Parses the MODEL command
5312
+ * Parses the FORMAT command
5313
+ */
5314
+ parse: function (input) {
5315
+ var normalized = input.normalized;
5316
+ if (!normalized.startsWith('FORMAT_JSON')) {
5317
+ throw new ParseError("For now only JSON format is supported, in future we will support more formats");
5318
+ }
5319
+ return {
5320
+ type: 'FORMAT',
5321
+ format: 'JSON',
5322
+ };
5323
+ // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5324
+ // [🥤]
5325
+ },
5326
+ /**
5327
+ * Apply the FORMAT command to the `pipelineJson`
5328
+ *
5329
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5330
+ */
5331
+ $applyToTemplateJson: function (command, $templateJson) {
5332
+ if ($templateJson.format !== undefined && command.format !== $templateJson.format) {
5333
+ throw new ParseError("Format format is already defined to \"".concat($templateJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
5334
+ }
5335
+ $templateJson.format = command.format;
5336
+ },
5337
+ /**
5338
+ * Converts the FORMAT command back to string
5339
+ *
5340
+ * Note: This is used in `pipelineJsonToString` utility
5341
+ */
5342
+ stringify: function (command) {
5343
+ keepUnused(command);
5344
+ return "!!!!!!";
5345
+ },
5346
+ /**
5347
+ * Reads the FORMAT command from the `TemplateJson`
5348
+ *
5349
+ * Note: This is used in `pipelineJsonToString` utility
5350
+ */
5351
+ takeFromTemplateJson: function ($templateJson) {
5352
+ keepUnused($templateJson);
5353
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5354
+ },
5355
+ };
5356
+
5357
+ /**
5358
+ * Parses the joker command
5359
+ *
5360
+ * @see ./JOKER-README.md for more details
5361
+ * @private within the commands folder
5362
+ */
5363
+ var jokerCommandParser = {
5364
+ /**
5365
+ * Name of the command
5366
+ */
5367
+ name: 'JOKER',
5368
+ /**
5369
+ * BOILERPLATE command can be used in:
5370
+ */
5371
+ isUsedInPipelineHead: false,
5372
+ isUsedInPipelineTemplate: true,
5373
+ /**
5374
+ * Description of the JOKER command
5375
+ */
5376
+ description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5377
+ /**
5378
+ * Link to discussion
5379
+ */
5380
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5381
+ /**
5382
+ * Example usages of the JOKER command
5383
+ */
5384
+ examples: ['JOKER {documentTitle}'],
5385
+ /**
5386
+ * Parses the JOKER command
5387
+ */
5388
+ parse: function (input) {
5389
+ var args = input.args;
5390
+ var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5391
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5392
+ throw new ParseError("Invalid joker");
5393
+ }
5394
+ var parameterName = parametersMatch.groups.parameterName;
5395
+ return {
5396
+ type: 'JOKER',
5397
+ parameterName: parameterName,
5398
+ };
5399
+ },
5400
+ /**
5401
+ * Apply the JOKER command to the `pipelineJson`
5402
+ *
5403
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5404
+ */
5405
+ $applyToTemplateJson: function (command, $templateJson) {
5406
+ $templateJson.jokerParameterNames = $templateJson.jokerParameterNames || [];
5407
+ $templateJson.jokerParameterNames.push(command.parameterName);
5408
+ },
5409
+ /**
5410
+ * Converts the JOKER command back to string
5411
+ *
5412
+ * Note: This is used in `pipelineJsonToString` utility
5413
+ */
5414
+ stringify: function (command) {
5415
+ keepUnused(command);
5416
+ return "!!!!!!";
5417
+ },
5418
+ /**
5419
+ * Reads the JOKER command from the `TemplateJson`
5420
+ *
5421
+ * Note: This is used in `pipelineJsonToString` utility
5422
+ */
5423
+ takeFromTemplateJson: function ($templateJson) {
5424
+ keepUnused($templateJson);
5425
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5426
+ },
5427
+ };
5428
+
5429
+ /**
5430
+ * @@@
5431
+ *
5432
+ * @public exported from `@promptbook/core`
5433
+ */
5434
+ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5435
+
5436
+ /**
5437
+ * Parses the model command
5438
+ *
5439
+ * @see ./MODEL-README.md for more details
5440
+ * @private within the commands folder
5441
+ */
5442
+ var modelCommandParser = {
5443
+ /**
5444
+ * Name of the command
5445
+ */
5446
+ name: 'MODEL',
5447
+ /**
5448
+ * BOILERPLATE command can be used in:
5449
+ */
5450
+ isUsedInPipelineHead: true,
5451
+ isUsedInPipelineTemplate: true,
5452
+ /**
5453
+ * Description of the MODEL command
5454
+ */
5455
+ description: "Tells which model and modelRequirements to use for the prompt template execution",
5456
+ /**
5457
+ * Link to discussion
5458
+ */
5459
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5460
+ /**
5461
+ * Example usages of the MODEL command
5462
+ */
5463
+ examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5464
+ /**
5465
+ * Parses the MODEL command
5309
5466
  */
5310
5467
  parse: function (input) {
5311
5468
  var args = input.args, normalized = input.normalized;
@@ -5334,7 +5491,7 @@
5334
5491
  // <- Note: [🤖]
5335
5492
  }
5336
5493
  else {
5337
- throw new ParsingError(spaceTrim__default["default"](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 "); }));
5494
+ throw new ParseError(spaceTrim__default["default"](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 "); }));
5338
5495
  }
5339
5496
  }
5340
5497
  if (normalized.startsWith('MODEL_NAME')) {
@@ -5345,9 +5502,60 @@
5345
5502
  };
5346
5503
  }
5347
5504
  else {
5348
- throw new ParsingError(spaceTrim__default["default"](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 "); }));
5505
+ throw new ParseError(spaceTrim__default["default"](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 "); }));
5349
5506
  }
5350
5507
  },
5508
+ /**
5509
+ * Apply the MODEL command to the `pipelineJson`
5510
+ *
5511
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5512
+ */
5513
+ $applyToPipelineJson: function (command, $pipelineJson) {
5514
+ // TODO: !!!!!! Error on redefine
5515
+ $pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
5516
+ $pipelineJson.defaultModelRequirements[command.key] = command.value;
5517
+ },
5518
+ /**
5519
+ * Apply the MODEL command to the `pipelineJson`
5520
+ *
5521
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5522
+ */
5523
+ $applyToTemplateJson: function (command, $templateJson) {
5524
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5525
+ throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
5526
+ }
5527
+ // TODO: !!!!!! Error on redefine
5528
+ // TODO: Warn if setting same as default in `$pipelineJson`
5529
+ $templateJson.modelRequirements = $templateJson.modelRequirements || {};
5530
+ $templateJson.modelRequirements[command.key] = command.value;
5531
+ },
5532
+ /**
5533
+ * Converts the MODEL command back to string
5534
+ *
5535
+ * Note: This is used in `pipelineJsonToString` utility
5536
+ */
5537
+ stringify: function (command) {
5538
+ keepUnused(command);
5539
+ return "!!!!!!";
5540
+ },
5541
+ /**
5542
+ * Reads the MODEL command from the `PipelineJson`
5543
+ *
5544
+ * Note: This is used in `pipelineJsonToString` utility
5545
+ */
5546
+ takeFromPipelineJson: function (pipelineJson) {
5547
+ keepUnused(pipelineJson);
5548
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5549
+ },
5550
+ /**
5551
+ * Reads the MODEL command from the `TemplateJson`
5552
+ *
5553
+ * Note: This is used in `pipelineJsonToString` utility
5554
+ */
5555
+ takeFromTemplateJson: function ($templateJson) {
5556
+ keepUnused($templateJson);
5557
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5558
+ },
5351
5559
  };
5352
5560
 
5353
5561
  /**
@@ -5371,7 +5579,8 @@
5371
5579
  /**
5372
5580
  * BOILERPLATE command can be used in:
5373
5581
  */
5374
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
5582
+ isUsedInPipelineHead: true,
5583
+ isUsedInPipelineTemplate: true,
5375
5584
  /**
5376
5585
  * Description of the PARAMETER command
5377
5586
  */
@@ -5391,11 +5600,11 @@
5391
5600
  var normalized = input.normalized, raw = input.raw;
5392
5601
  var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
5393
5602
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5394
- throw new ParsingError("Invalid parameter");
5603
+ throw new ParseError("Invalid parameter");
5395
5604
  }
5396
5605
  var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
5397
5606
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
5398
- throw new ParsingError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5607
+ throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5399
5608
  }
5400
5609
  var isInput = normalized.startsWith('INPUT');
5401
5610
  var isOutput = normalized.startsWith('OUTPUT');
@@ -5411,8 +5620,177 @@
5411
5620
  isOutput: isOutput,
5412
5621
  };
5413
5622
  },
5623
+ /**
5624
+ * Apply the PARAMETER command to the `pipelineJson`
5625
+ *
5626
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5627
+ */
5628
+ $applyToPipelineJson: function (command, $pipelineJson) {
5629
+ keepUnused(command, $pipelineJson);
5630
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5631
+ },
5632
+ /**
5633
+ * Apply the PARAMETER command to the `pipelineJson`
5634
+ *
5635
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5636
+ */
5637
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5638
+ keepUnused(command, $templateJson, $pipelineJson);
5639
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5640
+ },
5641
+ /**
5642
+ * Converts the PARAMETER command back to string
5643
+ *
5644
+ * Note: This is used in `pipelineJsonToString` utility
5645
+ */
5646
+ stringify: function (command) {
5647
+ keepUnused(command);
5648
+ return "!!!!!!";
5649
+ },
5650
+ /**
5651
+ * Reads the PARAMETER command from the `PipelineJson`
5652
+ *
5653
+ * Note: This is used in `pipelineJsonToString` utility
5654
+ */
5655
+ takeFromPipelineJson: function (pipelineJson) {
5656
+ keepUnused(pipelineJson);
5657
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5658
+ },
5659
+ /**
5660
+ * Reads the PARAMETER command from the `TemplateJson`
5661
+ *
5662
+ * Note: This is used in `pipelineJsonToString` utility
5663
+ */
5664
+ takeFromTemplateJson: function ($templateJson) {
5665
+ keepUnused($templateJson);
5666
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5667
+ },
5414
5668
  };
5415
5669
 
5670
+ /**
5671
+ * Parses the persona command
5672
+ *
5673
+ * @see ./PERSONA-README.md for more details
5674
+ * @private within the commands folder
5675
+ */
5676
+ var personaCommandParser = {
5677
+ /**
5678
+ * Name of the command
5679
+ */
5680
+ name: 'PERSONA',
5681
+ /**
5682
+ * Aliases for the PERSONA command
5683
+ */
5684
+ aliasNames: ['PERSON'],
5685
+ /**
5686
+ * PERSONA command can be used in:
5687
+ */
5688
+ isUsedInPipelineHead: true,
5689
+ isUsedInPipelineTemplate: true,
5690
+ /**
5691
+ * Description of the PERSONA command
5692
+ */
5693
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
5694
+ /**
5695
+ * Link to discussion
5696
+ */
5697
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
5698
+ /**
5699
+ * Example usages of the PERSONA command
5700
+ */
5701
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
5702
+ /**
5703
+ * Parses the PERSONA command
5704
+ */
5705
+ parse: function (input) {
5706
+ var rawArgs = input.rawArgs;
5707
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
5708
+ var personaName = (personaNameRaw || '').trim();
5709
+ if (personaName === '') {
5710
+ throw new ParseError("You must set name for the persona");
5711
+ }
5712
+ var personaDescription = (personaDescriptionRaw || '').trim();
5713
+ if (personaDescription === '') {
5714
+ personaDescription = null;
5715
+ }
5716
+ return {
5717
+ type: 'PERSONA',
5718
+ personaName: personaName,
5719
+ personaDescription: personaDescription,
5720
+ };
5721
+ },
5722
+ /**
5723
+ * Apply the PERSONA command to the `pipelineJson`
5724
+ *
5725
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5726
+ */
5727
+ $applyToPipelineJson: function (command, $pipelineJson) {
5728
+ $applyToTemplateJson(command, null, $pipelineJson);
5729
+ },
5730
+ $applyToTemplateJson: $applyToTemplateJson,
5731
+ /**
5732
+ * Converts the PERSONA command back to string
5733
+ *
5734
+ * Note: This is used in `pipelineJsonToString` utility
5735
+ */
5736
+ stringify: function (command) {
5737
+ keepUnused(command);
5738
+ return "!!!!!!";
5739
+ },
5740
+ /**
5741
+ * Reads the PERSONA command from the `PipelineJson`
5742
+ *
5743
+ * Note: This is used in `pipelineJsonToString` utility
5744
+ */
5745
+ takeFromPipelineJson: function (pipelineJson) {
5746
+ keepUnused(pipelineJson);
5747
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5748
+ },
5749
+ /**
5750
+ * Reads the PERSONA command from the `TemplateJson`
5751
+ *
5752
+ * Note: This is used in `pipelineJsonToString` utility
5753
+ */
5754
+ takeFromTemplateJson: function ($templateJson) {
5755
+ keepUnused($templateJson);
5756
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5757
+ },
5758
+ };
5759
+ /**
5760
+ * Apply the PERSONA command to the `pipelineJson`
5761
+ *
5762
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5763
+ */
5764
+ function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
5765
+ var personaName = command.personaName, personaDescription = command.personaDescription;
5766
+ if ($templateJson !== null) {
5767
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5768
+ throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
5769
+ }
5770
+ $templateJson.personaName = personaName;
5771
+ }
5772
+ var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
5773
+ if (persona === undefined) {
5774
+ $pipelineJson.personas.push({
5775
+ name: personaName,
5776
+ description: personaDescription || '',
5777
+ });
5778
+ return;
5779
+ }
5780
+ if (persona.description === personaDescription) {
5781
+ return;
5782
+ }
5783
+ if (personaDescription === null) {
5784
+ return;
5785
+ }
5786
+ if (persona.description === '') {
5787
+ persona.description = personaDescription;
5788
+ return;
5789
+ }
5790
+ console.warn(spaceTrim__default["default"]("\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 ")));
5791
+ persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
5792
+ }
5793
+
5416
5794
  /**
5417
5795
  * @@@
5418
5796
  *
@@ -5442,7 +5820,8 @@
5442
5820
  /**
5443
5821
  * BOILERPLATE command can be used in:
5444
5822
  */
5445
- usagePlaces: ['PIPELINE_TEMPLATE'],
5823
+ isUsedInPipelineHead: false,
5824
+ isUsedInPipelineTemplate: true,
5446
5825
  /**
5447
5826
  * Description of the POSTPROCESS command
5448
5827
  */
@@ -5464,19 +5843,46 @@
5464
5843
  var args = input.args;
5465
5844
  var functionName = args.pop();
5466
5845
  if (functionName === undefined) {
5467
- throw new ParsingError("Postprocess function name is required");
5846
+ throw new ParseError("Postprocess function name is required");
5468
5847
  }
5469
5848
  if (!isValidJavascriptName(functionName)) {
5470
- throw new ParsingError("Invalid postprocess function name \"".concat(functionName, "\""));
5849
+ throw new ParseError("Invalid postprocess function name \"".concat(functionName, "\""));
5471
5850
  }
5472
5851
  if (args.length > 0) {
5473
- throw new ParsingError("Can not have more than one postprocess function");
5852
+ throw new ParseError("Can not have more than one postprocess function");
5474
5853
  }
5475
5854
  return {
5476
5855
  type: 'POSTPROCESS',
5477
5856
  functionName: functionName,
5478
5857
  };
5479
5858
  },
5859
+ /**
5860
+ * Apply the POSTPROCESS command to the `pipelineJson`
5861
+ *
5862
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5863
+ */
5864
+ $applyToTemplateJson: function (command, $templateJson) {
5865
+ $templateJson.postprocessingFunctionNames = $templateJson.postprocessingFunctionNames || [];
5866
+ $templateJson.postprocessingFunctionNames.push(command.functionName);
5867
+ },
5868
+ /**
5869
+ * Converts the POSTPROCESS command back to string
5870
+ *
5871
+ * Note: This is used in `pipelineJsonToString` utility
5872
+ */
5873
+ stringify: function (command) {
5874
+ keepUnused(command);
5875
+ return "!!!!!!";
5876
+ },
5877
+ /**
5878
+ * Reads the POSTPROCESS command from the `TemplateJson`
5879
+ *
5880
+ * Note: This is used in `pipelineJsonToString` utility
5881
+ */
5882
+ takeFromTemplateJson: function ($templateJson) {
5883
+ keepUnused($templateJson);
5884
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5885
+ },
5480
5886
  };
5481
5887
 
5482
5888
  /**
@@ -5494,7 +5900,8 @@
5494
5900
  /**
5495
5901
  * BOILERPLATE command can be used in:
5496
5902
  */
5497
- usagePlaces: ['PIPELINE_HEAD'],
5903
+ isUsedInPipelineHead: true,
5904
+ isUsedInPipelineTemplate: false,
5498
5905
  /**
5499
5906
  * Description of the PROMPTBOOK_VERSION command
5500
5907
  */
@@ -5514,19 +5921,45 @@
5514
5921
  var args = input.args;
5515
5922
  var promptbookVersion = args.pop();
5516
5923
  if (promptbookVersion === undefined) {
5517
- throw new ParsingError("Version is required");
5924
+ throw new ParseError("Version is required");
5518
5925
  }
5519
5926
  if (!isValidPromptbookVersion(promptbookVersion)) {
5520
- throw new ParsingError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5927
+ throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5521
5928
  }
5522
5929
  if (args.length > 0) {
5523
- throw new ParsingError("Can not have more than one Promptbook version");
5930
+ throw new ParseError("Can not have more than one Promptbook version");
5524
5931
  }
5525
5932
  return {
5526
5933
  type: 'PROMPTBOOK_VERSION',
5527
5934
  promptbookVersion: promptbookVersion,
5528
5935
  };
5529
5936
  },
5937
+ /**
5938
+ * Apply the PROMPTBOOK_VERSION command to the `pipelineJson`
5939
+ *
5940
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5941
+ */
5942
+ $applyToPipelineJson: function (command, $pipelineJson) {
5943
+ $pipelineJson.promptbookVersion = command.promptbookVersion;
5944
+ },
5945
+ /**
5946
+ * Converts the PROMPTBOOK_VERSION command back to string
5947
+ *
5948
+ * Note: This is used in `pipelineJsonToString` utility
5949
+ */
5950
+ stringify: function (command) {
5951
+ keepUnused(command);
5952
+ return "!!!!!!";
5953
+ },
5954
+ /**
5955
+ * Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
5956
+ *
5957
+ * Note: This is used in `pipelineJsonToString` utility
5958
+ */
5959
+ takeFromPipelineJson: function (pipelineJson) {
5960
+ keepUnused(pipelineJson);
5961
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5962
+ },
5530
5963
  };
5531
5964
 
5532
5965
  /**
@@ -5548,7 +5981,8 @@
5548
5981
  /**
5549
5982
  * BOILERPLATE command can be used in:
5550
5983
  */
5551
- usagePlaces: ['PIPELINE_HEAD'],
5984
+ isUsedInPipelineHead: true,
5985
+ isUsedInPipelineTemplate: false,
5552
5986
  /**
5553
5987
  * Description of the URL command
5554
5988
  */
@@ -5572,23 +6006,23 @@
5572
6006
  var args = input.args;
5573
6007
  var pipelineUrl = args.pop();
5574
6008
  if (pipelineUrl === undefined) {
5575
- throw new ParsingError("URL is required");
6009
+ throw new ParseError("URL is required");
5576
6010
  }
5577
6011
  // TODO: [🧠][🚲] This should be maybe tested as logic not syntax
5578
6012
  if (!isValidPipelineUrl(pipelineUrl)) {
5579
- throw new ParsingError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
6013
+ throw new ParseError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
5580
6014
  }
5581
6015
  if (args.length > 0) {
5582
- throw new ParsingError("Can not have more than one pipeline URL");
6016
+ throw new ParseError("Can not have more than one pipeline URL");
5583
6017
  }
5584
6018
  /*
5585
6019
  TODO: [🐠 Maybe more info from `isValidPipelineUrl`:
5586
6020
  if (pipelineUrl.protocol !== 'https:') {
5587
- throw new ParsingError(`Protocol must be HTTPS`);
6021
+ throw new ParseError(`Protocol must be HTTPS`);
5588
6022
  }
5589
6023
 
5590
6024
  if (pipelineUrl.hash !== '') {
5591
- throw new ParsingError(
6025
+ throw new ParseError(
5592
6026
  spaceTrim(
5593
6027
  `
5594
6028
  URL must not contain hash
@@ -5603,6 +6037,32 @@
5603
6037
  pipelineUrl: new URL(pipelineUrl),
5604
6038
  };
5605
6039
  },
6040
+ /**
6041
+ * Apply the URL command to the `pipelineJson`
6042
+ *
6043
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6044
+ */
6045
+ $applyToPipelineJson: function (command, $pipelineJson) {
6046
+ $pipelineJson.pipelineUrl = command.pipelineUrl.href;
6047
+ },
6048
+ /**
6049
+ * Converts the URL command back to string
6050
+ *
6051
+ * Note: This is used in `pipelineJsonToString` utility
6052
+ */
6053
+ stringify: function (command) {
6054
+ keepUnused(command);
6055
+ return "!!!!!!";
6056
+ },
6057
+ /**
6058
+ * Reads the URL command from the `PipelineJson`
6059
+ *
6060
+ * Note: This is used in `pipelineJsonToString` utility
6061
+ */
6062
+ takeFromPipelineJson: function (pipelineJson) {
6063
+ keepUnused(pipelineJson);
6064
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6065
+ },
5606
6066
  };
5607
6067
 
5608
6068
  /**
@@ -5619,7 +6079,8 @@
5619
6079
  /**
5620
6080
  * ACTION command can be used in:
5621
6081
  */
5622
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6082
+ isUsedInPipelineHead: true,
6083
+ isUsedInPipelineTemplate: false,
5623
6084
  /**
5624
6085
  * Description of the ACTION command
5625
6086
  */
@@ -5642,6 +6103,33 @@
5642
6103
  type: 'ACTION',
5643
6104
  };
5644
6105
  },
6106
+ /**
6107
+ * Apply the ACTION command to the `pipelineJson`
6108
+ *
6109
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6110
+ */
6111
+ $applyToPipelineJson: function (command, $pipelineJson) {
6112
+ keepUnused(command, $pipelineJson);
6113
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
6114
+ },
6115
+ /**
6116
+ * Converts the ACTION command back to string
6117
+ *
6118
+ * Note: This is used in `pipelineJsonToString` utility
6119
+ */
6120
+ stringify: function (command) {
6121
+ keepUnused(command);
6122
+ return "!!!!!!";
6123
+ },
6124
+ /**
6125
+ * Reads the ACTION command from the `PipelineJson`
6126
+ *
6127
+ * Note: This is used in `pipelineJsonToString` utility
6128
+ */
6129
+ takeFromPipelineJson: function (pipelineJson) {
6130
+ keepUnused(pipelineJson);
6131
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6132
+ },
5645
6133
  };
5646
6134
 
5647
6135
  /**
@@ -5658,7 +6146,8 @@
5658
6146
  /**
5659
6147
  * INSTRUMENT command can be used in:
5660
6148
  */
5661
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6149
+ isUsedInPipelineHead: true,
6150
+ isUsedInPipelineTemplate: false,
5662
6151
  /**
5663
6152
  * Description of the INSTRUMENT command
5664
6153
  */
@@ -5681,12 +6170,41 @@
5681
6170
  type: 'INSTRUMENT',
5682
6171
  };
5683
6172
  },
6173
+ /**
6174
+ * Apply the INSTRUMENT command to the `pipelineJson`
6175
+ *
6176
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6177
+ */
6178
+ $applyToPipelineJson: function (command, $pipelineJson) {
6179
+ keepUnused(command, $pipelineJson);
6180
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6181
+ },
6182
+ /**
6183
+ * Converts the INSTRUMENT command back to string
6184
+ *
6185
+ * Note: This is used in `pipelineJsonToString` utility
6186
+ */
6187
+ stringify: function (command) {
6188
+ keepUnused(command);
6189
+ return "!!!!!!";
6190
+ },
6191
+ /**
6192
+ * Reads the INSTRUMENT command from the `PipelineJson`
6193
+ *
6194
+ * Note: This is used in `pipelineJsonToString` utility
6195
+ */
6196
+ takeFromPipelineJson: function (pipelineJson) {
6197
+ keepUnused(pipelineJson);
6198
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6199
+ },
5684
6200
  };
5685
6201
 
5686
6202
  /**
5687
6203
  * Parses the boilerplate command
5688
6204
  *
5689
- * @see ./BOILERPLATE-README.md for more details
6205
+ * Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
6206
+ *
6207
+ * @see ./BOILERPLATE-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5690
6208
  * @private within the commands folder
5691
6209
  */
5692
6210
  var boilerplateCommandParser = {
@@ -5701,7 +6219,8 @@
5701
6219
  /**
5702
6220
  * BOILERPLATE command can be used in:
5703
6221
  */
5704
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6222
+ isUsedInPipelineHead: true,
6223
+ isUsedInPipelineTemplate: true,
5705
6224
  /**
5706
6225
  * Description of the BOILERPLATE command
5707
6226
  */
@@ -5720,20 +6239,65 @@
5720
6239
  parse: function (input) {
5721
6240
  var args = input.args;
5722
6241
  if (args.length !== 1) {
5723
- throw new ParsingError("BOILERPLATE command requires exactly one argument");
6242
+ throw new ParseError("BOILERPLATE command requires exactly one argument");
5724
6243
  }
5725
6244
  var value = args[0].toLowerCase();
5726
6245
  if (value.includes('brr')) {
5727
- throw new ParsingError("BOILERPLATE value can not contain brr");
6246
+ throw new ParseError("BOILERPLATE value can not contain brr");
5728
6247
  }
5729
6248
  return {
5730
6249
  type: 'BOILERPLATE',
5731
6250
  value: value,
5732
6251
  };
5733
6252
  },
6253
+ /**
6254
+ * Apply the BOILERPLATE command to the `pipelineJson`
6255
+ *
6256
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6257
+ */
6258
+ $applyToPipelineJson: function (command, $pipelineJson) {
6259
+ keepUnused(command, $pipelineJson);
6260
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6261
+ },
6262
+ /**
6263
+ * Apply the BOILERPLATE command to the `pipelineJson`
6264
+ *
6265
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
6266
+ */
6267
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6268
+ keepUnused(command, $templateJson, $pipelineJson);
6269
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6270
+ },
6271
+ /**
6272
+ * Converts the BOILERPLATE command back to string
6273
+ *
6274
+ * Note: This is used in `pipelineJsonToString` utility
6275
+ */
6276
+ stringify: function (command) {
6277
+ keepUnused(command);
6278
+ return "!!!!!!";
6279
+ },
6280
+ /**
6281
+ * Reads the BOILERPLATE command from the `PipelineJson`
6282
+ *
6283
+ * Note: This is used in `pipelineJsonToString` utility
6284
+ */
6285
+ takeFromPipelineJson: function (pipelineJson) {
6286
+ keepUnused(pipelineJson);
6287
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6288
+ },
6289
+ /**
6290
+ * Reads the BOILERPLATE command from the `TemplateJson`
6291
+ *
6292
+ * Note: This is used in `pipelineJsonToString` utility
6293
+ */
6294
+ takeFromTemplateJson: function ($templateJson) {
6295
+ keepUnused($templateJson);
6296
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6297
+ },
5734
6298
  };
5735
6299
  /**
5736
- * TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
6300
+ * TODO: !!!!!! Make .ptbk.md file with examples of the BOILERPLATE command and fail
5737
6301
  */
5738
6302
 
5739
6303
  /**
@@ -5744,6 +6308,7 @@
5744
6308
  var COMMANDS = [
5745
6309
  blockCommandParser,
5746
6310
  expectCommandParser,
6311
+ formatCommandParser,
5747
6312
  jokerCommandParser,
5748
6313
  modelCommandParser,
5749
6314
  parameterCommandParser,
@@ -5754,20 +6319,108 @@
5754
6319
  actionCommandParser,
5755
6320
  instrumentCommandParser,
5756
6321
  personaCommandParser,
6322
+ foreachCommandParser,
5757
6323
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
5758
6324
  ];
5759
6325
 
6326
+ /**
6327
+ * Removes Markdown formatting tags from a string.
6328
+ *
6329
+ * @param {string} str - The string to remove Markdown tags from.
6330
+ * @returns {string} The input string with all Markdown tags removed.
6331
+ * @public exported from `@promptbook/markdown-utils`
6332
+ */
6333
+ function removeMarkdownFormatting(str) {
6334
+ // Remove bold formatting
6335
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
6336
+ // Remove italic formatting
6337
+ str = str.replace(/\*(.*?)\*/g, '$1');
6338
+ // Remove code formatting
6339
+ str = str.replace(/`(.*?)`/g, '$1');
6340
+ return str;
6341
+ }
6342
+
6343
+ /**
6344
+ * @@@
6345
+ *
6346
+ * @param text @@@
6347
+ * @returns @@@
6348
+ * @example 'HELLO_WORLD'
6349
+ * @example 'I_LOVE_PROMPTBOOK'
6350
+ * @public exported from `@promptbook/utils`
6351
+ */
6352
+ function normalizeTo_SCREAMING_CASE(text) {
6353
+ var e_1, _a;
6354
+ var charType;
6355
+ var lastCharType = 'OTHER';
6356
+ var normalizedName = '';
6357
+ try {
6358
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
6359
+ var char = text_1_1.value;
6360
+ var normalizedChar = void 0;
6361
+ if (/^[a-z]$/.test(char)) {
6362
+ charType = 'LOWERCASE';
6363
+ normalizedChar = char.toUpperCase();
6364
+ }
6365
+ else if (/^[A-Z]$/.test(char)) {
6366
+ charType = 'UPPERCASE';
6367
+ normalizedChar = char;
6368
+ }
6369
+ else if (/^[0-9]$/.test(char)) {
6370
+ charType = 'NUMBER';
6371
+ normalizedChar = char;
6372
+ }
6373
+ else if (/^\/$/.test(char)) {
6374
+ charType = 'SLASH';
6375
+ normalizedChar = char;
6376
+ }
6377
+ else {
6378
+ charType = 'OTHER';
6379
+ normalizedChar = '_';
6380
+ }
6381
+ if (charType !== lastCharType &&
6382
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
6383
+ !(lastCharType === 'NUMBER') &&
6384
+ !(charType === 'NUMBER')) {
6385
+ normalizedName += '_';
6386
+ }
6387
+ normalizedName += normalizedChar;
6388
+ lastCharType = charType;
6389
+ }
6390
+ }
6391
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6392
+ finally {
6393
+ try {
6394
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
6395
+ }
6396
+ finally { if (e_1) throw e_1.error; }
6397
+ }
6398
+ normalizedName = normalizedName.replace(/_+/g, '_');
6399
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
6400
+ normalizedName = normalizedName.replace(/^_/, '');
6401
+ normalizedName = normalizedName.replace(/_$/, '');
6402
+ return normalizedName;
6403
+ }
6404
+ /**
6405
+ * TODO: Tests
6406
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
6407
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
6408
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
6409
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
6410
+ * TODO: [🌺] Use some intermediate util splitWords
6411
+ */
6412
+
5760
6413
  /**
5761
6414
  * Parses one line of ul/ol to command
5762
6415
  *
5763
6416
  * @returns parsed command object
5764
- * @throws {ParsingError} if the command is invalid
6417
+ * @throws {ParseError} if the command is invalid
5765
6418
  *
5766
6419
  * @private within the pipelineStringToJson
5767
6420
  */
5768
6421
  function parseCommand(raw, usagePlace) {
5769
6422
  if (raw.includes('\n') || raw.includes('\r')) {
5770
- throw new ParsingError('Command can not contain new line characters' /* <- TODO: [🚞] */);
6423
+ throw new ParseError('Command can not contain new line characters' /* <- TODO: [🚞] */);
5771
6424
  }
5772
6425
  var normalized = raw.trim();
5773
6426
  normalized = normalized.split('`').join('');
@@ -5804,7 +6457,7 @@
5804
6457
  .map(removeMarkdownFormatting)
5805
6458
  .map(function (item) { return item.trim(); });
5806
6459
  if (items.length === 0 || items[0] === '') {
5807
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6460
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5808
6461
  return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5809
6462
  }));
5810
6463
  }
@@ -5831,7 +6484,7 @@
5831
6484
  return command;
5832
6485
  }
5833
6486
  }
5834
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6487
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5835
6488
  return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5836
6489
  }));
5837
6490
  }
@@ -5841,6 +6494,7 @@
5841
6494
  function getSupportedCommandsMessage() {
5842
6495
  return COMMANDS.flatMap(function (_a) {
5843
6496
  var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
6497
+ // <- Note: [🦦] Its strange that this type assertion is needed
5844
6498
  return __spreadArray([
5845
6499
  "- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
5846
6500
  ], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
@@ -5854,27 +6508,34 @@
5854
6508
  var commandNameRaw = input.commandNameRaw, usagePlace = input.usagePlace, normalized = input.normalized, args = input.args, raw = input.raw, rawArgs = input.rawArgs;
5855
6509
  var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
5856
6510
  var _loop_1 = function (commandParser) {
5857
- var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6511
+ // <- Note: [🦦] Its strange that this type assertion is needed
6512
+ var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6513
+ if (just(false)) {
6514
+ keepUnused( /* for better indentation */);
6515
+ }
6516
+ else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
6517
+ return "continue";
6518
+ }
6519
+ else if (usagePlace === 'PIPELINE_TEMPLATE' && !isUsedInPipelineTemplate) {
6520
+ return "continue";
6521
+ }
5858
6522
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
5859
6523
  if (names.includes(commandName)) {
5860
6524
  try {
5861
6525
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
5862
6526
  }
5863
6527
  catch (error) {
5864
- if (!(error instanceof ParsingError)) {
6528
+ if (!(error instanceof ParseError)) {
5865
6529
  throw error;
5866
6530
  }
5867
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6531
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5868
6532
  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 ");
5869
6533
  }));
5870
6534
  }
5871
6535
  }
5872
6536
  };
5873
6537
  try {
5874
- for (var _b = __values(COMMANDS.filter(function (_a) {
5875
- var places = _a.usagePlaces;
5876
- return places.includes(usagePlace);
5877
- })), _c = _b.next(); !_c.done; _c = _b.next()) {
6538
+ for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
5878
6539
  var commandParser = _c.value;
5879
6540
  var state_1 = _loop_1(commandParser);
5880
6541
  if (typeof state_1 === "object")
@@ -5941,7 +6602,7 @@
5941
6602
  /**
5942
6603
  * Extracts exactly ONE code block from markdown.
5943
6604
  *
5944
- * - When there are multiple or no code blocks the function throws a `ParsingError`
6605
+ * - When there are multiple or no code blocks the function throws a `ParseError`
5945
6606
  *
5946
6607
  * Note: There are multiple simmilar function:
5947
6608
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
@@ -5952,12 +6613,12 @@
5952
6613
  * @param markdown any valid markdown
5953
6614
  * @returns code block with language and content
5954
6615
  * @public exported from `@promptbook/markdown-utils`
5955
- * @throws {ParsingError} if there is not exactly one code block in the markdown
6616
+ * @throws {ParseError} if there is not exactly one code block in the markdown
5956
6617
  */
5957
6618
  function extractOneBlockFromMarkdown(markdown) {
5958
6619
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
5959
6620
  if (codeBlocks.length !== 1) {
5960
- throw new ParsingError(spaceTrim__default["default"](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 "); }));
6621
+ throw new ParseError(spaceTrim__default["default"](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 "); }));
5961
6622
  }
5962
6623
  return codeBlocks[0];
5963
6624
  }
@@ -5974,13 +6635,13 @@
5974
6635
  var _a, _b;
5975
6636
  var lines = value.split('\n');
5976
6637
  if (!lines[0].startsWith('#')) {
5977
- throw new ParsingError('Markdown section must start with heading');
6638
+ throw new ParseError('Markdown section must start with heading');
5978
6639
  }
5979
6640
  var title = lines[0].replace(/^#+\s*/, '');
5980
6641
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
5981
6642
  var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
5982
6643
  if (level < 1 || level > 6) {
5983
- throw new ParsingError('Markdown section must have heading level between 1 and 6');
6644
+ throw new ParseError('Markdown section must have heading level between 1 and 6');
5984
6645
  }
5985
6646
  return { title: title, level: level, content: content };
5986
6647
  }
@@ -6136,31 +6797,32 @@
6136
6797
  *
6137
6798
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
6138
6799
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6139
- * @throws {ParsingError} if the promptbook string is not valid
6800
+ * @throws {ParseError} if the promptbook string is not valid
6140
6801
  * @public exported from `@promptbook/core`
6141
6802
  */
6142
6803
  function pipelineStringToJsonSync(pipelineString) {
6143
6804
  var e_1, _a, e_2, _b;
6144
- var pipelineJson = {
6145
- title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
6805
+ var $pipelineJson = {
6806
+ title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
6146
6807
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
6147
6808
  promptbookVersion: PROMPTBOOK_VERSION,
6148
- description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
6809
+ description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
6149
6810
  parameters: [],
6150
- promptTemplates: [],
6811
+ templates: [],
6151
6812
  knowledgeSources: [],
6152
6813
  knowledgePieces: [],
6153
6814
  personas: [],
6154
6815
  preparations: [],
6816
+ // <- TODO: [🍙] Some standard order of properties
6155
6817
  };
6156
6818
  function getPipelineIdentification() {
6157
6819
  // Note: This is a 😐 implementation of [🚞]
6158
6820
  var _ = [];
6159
- if (pipelineJson.sourceFile !== undefined) {
6160
- _.push("File: ".concat(pipelineJson.sourceFile));
6821
+ if ($pipelineJson.sourceFile !== undefined) {
6822
+ _.push("File: ".concat($pipelineJson.sourceFile));
6161
6823
  }
6162
- if (pipelineJson.pipelineUrl !== undefined) {
6163
- _.push("Url: ".concat(pipelineJson.pipelineUrl));
6824
+ if ($pipelineJson.pipelineUrl !== undefined) {
6825
+ _.push("Url: ".concat($pipelineJson.pipelineUrl));
6164
6826
  }
6165
6827
  return _.join('\n');
6166
6828
  }
@@ -6185,14 +6847,14 @@
6185
6847
  var defineParam = function (parameterCommand) {
6186
6848
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
6187
6849
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
6188
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
6850
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
6189
6851
  }
6190
- var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6852
+ var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6191
6853
  if (existingParameter &&
6192
6854
  existingParameter.description &&
6193
6855
  existingParameter.description !== parameterDescription &&
6194
6856
  parameterDescription) {
6195
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
6857
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
6196
6858
  }
6197
6859
  if (existingParameter) {
6198
6860
  if (parameterDescription) {
@@ -6200,7 +6862,7 @@
6200
6862
  }
6201
6863
  }
6202
6864
  else {
6203
- pipelineJson.parameters.push({
6865
+ $pipelineJson.parameters.push({
6204
6866
  name: parameterName,
6205
6867
  description: parameterDescription || undefined,
6206
6868
  isInput: isInput,
@@ -6210,7 +6872,7 @@
6210
6872
  };
6211
6873
  // =============================================================
6212
6874
  // Note: 3️⃣ Process pipeline head
6213
- pipelineJson.title = pipelineHead.title;
6875
+ $pipelineJson.title = pipelineHead.title;
6214
6876
  // TODO: [🎾][1] DRY description
6215
6877
  var description = pipelineHead.content;
6216
6878
  // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
@@ -6222,43 +6884,31 @@
6222
6884
  if (description === '') {
6223
6885
  description = undefined;
6224
6886
  }
6225
- pipelineJson.description = description;
6226
- var defaultModelRequirements = {};
6887
+ $pipelineJson.description = description;
6227
6888
  var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
6228
6889
  var _loop_1 = function (listItem) {
6890
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineHeadCommands`
6229
6891
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
6230
- switch (command.type) {
6231
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6232
- case 'MODEL':
6233
- defaultModelRequirements[command.key] = command.value;
6234
- break;
6235
- case 'PARAMETER':
6236
- defineParam(command);
6237
- break;
6238
- case 'PROMPTBOOK_VERSION':
6239
- pipelineJson.promptbookVersion = command.promptbookVersion;
6240
- break;
6241
- case 'URL':
6242
- pipelineJson.pipelineUrl = command.pipelineUrl.href;
6243
- break;
6244
- case 'KNOWLEDGE':
6245
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6246
- break;
6247
- case 'ACTION':
6248
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6249
- break;
6250
- case 'INSTRUMENT':
6251
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6252
- break;
6253
- case 'PERSONA':
6254
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6255
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6256
- break;
6257
- case 'BOILERPLATE':
6258
- throw new ParsingError(spaceTrim.spaceTrim(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: [🚞]
6259
- // <- [💐]
6260
- default:
6261
- throw new ParsingError(spaceTrim.spaceTrim(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
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6893
+ if (commandParser === undefined) {
6894
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4E\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6895
+ }
6896
+ if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
6897
+ throw new ParseError(spaceTrim.spaceTrim(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: [🚞]
6898
+ }
6899
+ try {
6900
+ commandParser.$applyToPipelineJson(command, $pipelineJson);
6901
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6902
+ }
6903
+ catch (error) {
6904
+ if (!(error instanceof ParseError)) {
6905
+ throw error;
6906
+ }
6907
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
6908
+ }
6909
+ if (command.type === 'PARAMETER') {
6910
+ defineParam(command);
6911
+ // <- Note: [🍣]
6262
6912
  }
6263
6913
  };
6264
6914
  try {
@@ -6277,27 +6927,7 @@
6277
6927
  var _loop_2 = function (section) {
6278
6928
  var e_3, _d;
6279
6929
  // TODO: Parse prompt template description (the content out of the codeblock and lists)
6280
- var templateModelRequirements = __assign({}, defaultModelRequirements);
6281
- var listItems_3 = extractAllListItemsFromMarkdown(section.content);
6282
- var lastLine = section.content.split('\n').pop();
6283
- var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6284
- var resultingParameterName = null;
6285
- if (resultingParameterNameMatch &&
6286
- resultingParameterNameMatch.groups !== undefined &&
6287
- resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6288
- resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6289
- }
6290
- var expectResultingParameterName = function () {
6291
- if (resultingParameterName !== null) {
6292
- return resultingParameterName;
6293
- }
6294
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(getPipelineIdentification()), "\n\n Invalid section:\n ").concat(block(
6295
- // TODO: Show code of invalid sections each time + DRY
6296
- section.content
6297
- .split('\n')
6298
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
6299
- .join('\n')), "\n "); }));
6300
- };
6930
+ var listItems_2 = extractAllListItemsFromMarkdown(section.content);
6301
6931
  var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
6302
6932
  // TODO: [🎾][1] DRY description
6303
6933
  var description_1 = section.content;
@@ -6310,176 +6940,121 @@
6310
6940
  if (description_1 === '') {
6311
6941
  description_1 = undefined;
6312
6942
  }
6313
- var templateJson = {
6314
- blockType: 'PROMPT_TEMPLATE',
6943
+ var $templateJson = {
6944
+ isBlockTypeSet: false,
6945
+ isTemplateBlock: true,
6946
+ blockType: undefined /* <- Note: [🍙] Putting here placeholder to keep `blockType` on top at final JSON */,
6315
6947
  name: titleToName(section.title),
6316
6948
  title: section.title,
6317
6949
  description: description_1,
6318
- modelRequirements: templateModelRequirements,
6319
6950
  content: content,
6951
+ // <- TODO: [🍙] Some standard order of properties
6320
6952
  };
6321
- /**
6322
- * This is nessesary because block type can be
6323
- * - Set zero times, so anticipate 'PROMPT_TEMPLATE'
6324
- * - Set one time
6325
- * - Set more times - throw error
6326
- *
6327
- * Note: [2]
6328
- */
6329
- var isBlockTypeSet = false;
6330
- var _loop_3 = function (listItem) {
6331
- var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
6332
- // TODO [🍧][♓️] List commands and before apply order them
6333
- switch (command.type) {
6334
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6335
- case 'BLOCK':
6336
- if (isBlockTypeSet) {
6337
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
6338
- }
6339
- if (command.blockType === 'SAMPLE') {
6340
- expectResultingParameterName();
6341
- var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
6342
- if (parameter === undefined) {
6343
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6344
- }
6345
- parameter.sampleValues = parameter.sampleValues || [];
6346
- parameter.sampleValues.push(content);
6347
- return "continue-templates";
6348
- }
6349
- if (command.blockType === 'KNOWLEDGE') {
6350
- knowledgeCommandParser.applyToPipelineJson({
6351
- type: 'KNOWLEDGE',
6352
- sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6353
- }, {
6354
- pipelineJson: pipelineJson,
6355
- templateJson: templateJson,
6356
- });
6357
- return "continue-templates";
6358
- }
6359
- if (command.blockType === 'ACTION') {
6360
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6361
- return "continue-templates";
6362
- }
6363
- if (command.blockType === 'INSTRUMENT') {
6364
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6365
- return "continue-templates";
6366
- }
6367
- expectResultingParameterName();
6368
- templateJson.blockType = command.blockType;
6369
- isBlockTypeSet = true; //<- Note: [2]
6370
- break;
6371
- case 'EXPECT_AMOUNT':
6372
- // eslint-disable-next-line no-case-declarations
6373
- var unit_1 = command.unit.toLowerCase();
6374
- templateJson.expectations = templateJson.expectations || {};
6375
- templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
6376
- if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6377
- if (templateJson.expectations[unit_1].min !== undefined) {
6378
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
6379
- }
6380
- templateJson.expectations[unit_1].min = command.amount;
6381
- } /* not else */
6382
- if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6383
- if (templateJson.expectations[unit_1].max !== undefined) {
6384
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
6385
- }
6386
- templateJson.expectations[unit_1].max = command.amount;
6387
- }
6388
- break;
6389
- case 'EXPECT_FORMAT':
6390
- if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
6391
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
6392
- }
6393
- templateJson.expectFormat = command.format;
6394
- break;
6395
- case 'JOKER':
6396
- templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
6397
- templateJson.jokerParameterNames.push(command.parameterName);
6398
- break;
6399
- case 'MODEL':
6400
- templateModelRequirements[command.key] = command.value;
6401
- break;
6402
- case 'PARAMETER':
6403
- // Note: This is just for detecting resulitng parameter name
6404
- defineParam(command);
6405
- break;
6406
- case 'POSTPROCESS':
6407
- templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
6408
- templateJson.postprocessingFunctionNames.push(command.functionName);
6409
- break;
6410
- case 'KNOWLEDGE':
6411
- // TODO: [👙] The knowledge is maybe relevant for just this template
6412
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6413
- break;
6414
- case 'ACTION':
6415
- // TODO: [👙] The action is maybe relevant for just this template
6416
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6417
- break;
6418
- case 'INSTRUMENT':
6419
- // TODO: [👙] The instrument is maybe relevant for just this template
6420
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6421
- break;
6422
- case 'PERSONA':
6423
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6424
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6425
- break;
6426
- case 'BOILERPLATE':
6427
- console.error(new ParsingError(spaceTrim.spaceTrim(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 "); })));
6428
- break;
6429
- // <- [💐]
6430
- default:
6431
- throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
6953
+ var lastLine = section.content.split('\n').pop();
6954
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6955
+ if (resultingParameterNameMatch &&
6956
+ resultingParameterNameMatch.groups !== undefined &&
6957
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6958
+ $templateJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6959
+ }
6960
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTemplateCommands`
6961
+ var commands = listItems_2.map(function (listItem) { return ({
6962
+ listItem: listItem,
6963
+ command: parseCommand(listItem, 'PIPELINE_TEMPLATE'),
6964
+ }); });
6965
+ // Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
6966
+ if (commands.some(function (_a) {
6967
+ var command = _a.command;
6968
+ return command.type === 'BLOCK';
6969
+ }) === false) {
6970
+ blockCommandParser.$applyToTemplateJson({ type: 'BLOCK', blockType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
6971
+ }
6972
+ var _loop_3 = function (listItem, command) {
6973
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6974
+ if (commandParser === undefined) {
6975
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4F\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
6976
+ }
6977
+ if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
6978
+ throw new ParseError(spaceTrim.spaceTrim(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: [🚞]
6979
+ }
6980
+ try {
6981
+ commandParser.$applyToTemplateJson(
6982
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6983
+ command, $templateJson, $pipelineJson);
6984
+ }
6985
+ catch (error) {
6986
+ if (!(error instanceof ParseError)) {
6987
+ throw error;
6988
+ }
6989
+ throw new ParseError(spaceTrim.spaceTrim(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: [🚞]
6990
+ }
6991
+ // TODO: !!!!!! Multiple problematic things in BLOCK command - blockCommandParser.$applyToTemplateJson
6992
+ if (command.type === 'PARAMETER') {
6993
+ defineParam(command);
6994
+ // <- Note: [🍣]
6432
6995
  }
6433
6996
  };
6434
6997
  try {
6435
- 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()) {
6436
- var listItem = listItems_2_1.value;
6437
- var state_2 = _loop_3(listItem);
6438
- switch (state_2) {
6439
- case "continue-templates": return state_2;
6440
- }
6998
+ // TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE BLOCK`
6999
+ // TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE BLOCK`
7000
+ // TODO [♓️] List commands and before apply order them
7001
+ 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()) {
7002
+ var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
7003
+ _loop_3(listItem, command);
6441
7004
  }
6442
7005
  }
6443
7006
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
6444
7007
  finally {
6445
7008
  try {
6446
- if (listItems_2_1 && !listItems_2_1.done && (_d = listItems_2.return)) _d.call(listItems_2);
7009
+ if (commands_1_1 && !commands_1_1.done && (_d = commands_1.return)) _d.call(commands_1);
6447
7010
  }
6448
7011
  finally { if (e_3) throw e_3.error; }
6449
7012
  }
6450
- // TODO: [🍧] Should be done in BLOCK command
6451
- if (templateJson.blockType === 'SCRIPT') {
7013
+ // TODO: [🍧] !!!!!! Should be done in BLOCK command
7014
+ if ($templateJson.blockType === 'SCRIPT_TEMPLATE') {
6452
7015
  if (!language) {
6453
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
7016
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
6454
7017
  }
6455
7018
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
6456
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
7019
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
6457
7020
  }
6458
- templateJson.contentLanguage = language;
7021
+ $templateJson.contentLanguage =
7022
+ language;
6459
7023
  }
6460
- // TODO: [🍧][❔] Should be done in BLOCK command
6461
- if (templateModelRequirements.modelVariant === undefined) {
6462
- templateModelRequirements.modelVariant = 'CHAT';
7024
+ $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
7025
+ /*
7026
+ // TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
7027
+ // TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
7028
+ // TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
7029
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
7030
+ throw new UnexpectedError(
7031
+ spaceTrim(
7032
+ (block) => `
7033
+ Model requirements are defined for the block type ${
7034
+ $templateJson.blockType
7035
+ } which is not a prompt template
7036
+
7037
+ This should be avoided by the \`modelCommandParser\`
7038
+
7039
+ ${block(getPipelineIdentification())}
7040
+ `,
7041
+ ),
7042
+ );
6463
7043
  }
6464
- templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
6465
- // TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
6466
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
6467
- delete templateJson.modelRequirements;
7044
+ */
7045
+ if ($templateJson.isTemplateBlock) {
7046
+ delete $templateJson.isBlockTypeSet;
7047
+ delete $templateJson.isTemplateBlock;
7048
+ // TODO: [🍙] Maybe do reorder of `$templateJson` here
7049
+ $pipelineJson.templates.push($templateJson);
6468
7050
  }
6469
- // TODO: [🍧] Make this better - for example each command parser can call and apply this
6470
- templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
6471
- // TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
6472
- pipelineJson.promptTemplates.push(templateJson);
6473
7051
  };
6474
7052
  try {
6475
7053
  // =============================================================
6476
7054
  // Note: 4️⃣ Process each template of the pipeline
6477
- templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
7055
+ /* 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()) {
6478
7056
  var section = pipelineSections_1_1.value;
6479
- var state_1 = _loop_2(section);
6480
- switch (state_1) {
6481
- case "continue-templates": continue templates;
6482
- }
7057
+ _loop_2(section);
6483
7058
  }
6484
7059
  }
6485
7060
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -6491,13 +7066,13 @@
6491
7066
  }
6492
7067
  // =============================================================
6493
7068
  // Note: 5️⃣ Cleanup of undefined values
6494
- pipelineJson.promptTemplates.forEach(function (promptTemplates) {
7069
+ $pipelineJson.templates.forEach(function (templates) {
6495
7070
  var e_4, _a;
6496
7071
  try {
6497
- for (var _b = __values(Object.entries(promptTemplates)), _c = _b.next(); !_c.done; _c = _b.next()) {
7072
+ for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
6498
7073
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
6499
7074
  if (value === undefined) {
6500
- delete promptTemplates[key];
7075
+ delete templates[key];
6501
7076
  }
6502
7077
  }
6503
7078
  }
@@ -6509,7 +7084,7 @@
6509
7084
  finally { if (e_4) throw e_4.error; }
6510
7085
  }
6511
7086
  });
6512
- pipelineJson.parameters.forEach(function (parameter) {
7087
+ $pipelineJson.parameters.forEach(function (parameter) {
6513
7088
  var e_5, _a;
6514
7089
  try {
6515
7090
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -6528,7 +7103,8 @@
6528
7103
  }
6529
7104
  });
6530
7105
  // =============================================================
6531
- return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
7106
+ // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
7107
+ return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
6532
7108
  }
6533
7109
  /**
6534
7110
  * TODO: !!!! Warn if used only sync version
@@ -6538,7 +7114,7 @@
6538
7114
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
6539
7115
  * TODO: [♈] Probbably move expectations from templates to parameters
6540
7116
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
6541
- * TODO: [🍙] Make some standart order of json properties
7117
+ * TODO: [🍙] Make some standard order of json properties
6542
7118
  */
6543
7119
 
6544
7120
  /**
@@ -6555,7 +7131,7 @@
6555
7131
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
6556
7132
  * @param options - Options and tools for the compilation
6557
7133
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6558
- * @throws {ParsingError} if the promptbook string is not valid
7134
+ * @throws {ParseError} if the promptbook string is not valid
6559
7135
  * @public exported from `@promptbook/core`
6560
7136
  */
6561
7137
  function pipelineStringToJson(pipelineString, options) {
@@ -6600,8 +7176,8 @@
6600
7176
  }
6601
7177
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
6602
7178
  if (!placeForSection) {
6603
- throw new ParsingError(
6604
- // <- [🧠] Maybe something better tha `ParsingError`
7179
+ throw new ParseError(
7180
+ // <- [🧠] Maybe something better tha `ParseError`
6605
7181
  "No place where to put the section <!--".concat(sectionName, "-->"));
6606
7182
  // <- [🚞]
6607
7183
  }
@@ -6609,6 +7185,7 @@
6609
7185
  return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
6610
7186
  }
6611
7187
  /**
7188
+ * TODO: !!!!!! Somw way how to connect this with commands
6612
7189
  * TODO: [🏛] This can be part of markdown builder
6613
7190
  */
6614
7191
 
@@ -6684,7 +7261,7 @@
6684
7261
  * @public exported from `@promptbook/utils`
6685
7262
  */
6686
7263
  function renderPromptbookMermaid(pipelineJson, options) {
6687
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
7264
+ var _a = (options || {}).linkTemplate, linkTemplate = _a === void 0 ? function () { return null; } : _a;
6688
7265
  var parameterNameToTemplateName = function (parameterName) {
6689
7266
  var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6690
7267
  if (!parameter) {
@@ -6693,13 +7270,13 @@
6693
7270
  if (parameter.isInput) {
6694
7271
  return 'input';
6695
7272
  }
6696
- var template = pipelineJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
7273
+ var template = pipelineJson.templates.find(function (template) { return template.resultingParameterName === parameterName; });
6697
7274
  if (!template) {
6698
7275
  throw new Error("Could not find template for {".concat(parameterName, "}"));
6699
7276
  }
6700
7277
  return normalizeTo_camelCase('template-' + titleToName(template.title));
6701
7278
  };
6702
- var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
7279
+ var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.templates
6703
7280
  .flatMap(function (_a) {
6704
7281
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
6705
7282
  return __spreadArray([
@@ -6717,14 +7294,14 @@
6717
7294
  var name = _a.name;
6718
7295
  return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
6719
7296
  })
6720
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.promptTemplates
6721
- .map(function (promptTemplate) {
6722
- var link = linkPromptTemplate(promptTemplate);
7297
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.templates
7298
+ .map(function (template) {
7299
+ var link = linkTemplate(template);
6723
7300
  if (link === null) {
6724
7301
  return '';
6725
7302
  }
6726
7303
  var href = link.href, title = link.title;
6727
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
7304
+ var templateName = parameterNameToTemplateName(template.resultingParameterName);
6728
7305
  return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
6729
7306
  })
6730
7307
  .filter(function (line) { return line !== ''; })
@@ -6753,8 +7330,8 @@
6753
7330
  case 1:
6754
7331
  pipelineJson = _a.sent();
6755
7332
  promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
6756
- linkPromptTemplate: function (promptTemplate) {
6757
- return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
7333
+ linkTemplate: function (template) {
7334
+ return { href: "#".concat(template.name), title: template.title };
6758
7335
  },
6759
7336
  });
6760
7337
  promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
@@ -6834,7 +7411,7 @@
6834
7411
  * TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
6835
7412
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
6836
7413
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
6837
- * TODO: [🍙] Make some standart order of json properties
7414
+ * TODO: [🍙] Make some standard order of json properties
6838
7415
  */
6839
7416
 
6840
7417
  /**
@@ -7853,7 +8430,7 @@
7853
8430
  exports.NotYetImplementedError = NotYetImplementedError;
7854
8431
  exports.PIPELINE_COLLECTION_BASE_FILENAME = PIPELINE_COLLECTION_BASE_FILENAME;
7855
8432
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
7856
- exports.ParsingError = ParsingError;
8433
+ exports.ParseError = ParseError;
7857
8434
  exports.PipelineExecutionError = PipelineExecutionError;
7858
8435
  exports.PipelineLogicError = PipelineLogicError;
7859
8436
  exports.PipelineUrlError = PipelineUrlError;