@promptbook/cli 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 +1220 -643
  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 +1220 -643
  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
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.67.9';
42
+ var PROMPTBOOK_VERSION = '0.68.0-0';
43
43
  // TODO: !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -667,7 +667,7 @@
667
667
  */
668
668
  function pipelineJsonToString(pipelineJson) {
669
669
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
670
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
670
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
671
671
  var pipelineString = "# ".concat(title);
672
672
  if (description) {
673
673
  pipelineString += '\n\n';
@@ -687,7 +687,7 @@
687
687
  return isInput;
688
688
  })), _h = _g.next(); !_h.done; _h = _g.next()) {
689
689
  var parameter = _h.value;
690
- commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
690
+ commands.push("INPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
691
691
  }
692
692
  }
693
693
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -703,7 +703,7 @@
703
703
  return isOutput;
704
704
  })), _k = _j.next(); !_k.done; _k = _j.next()) {
705
705
  var parameter = _k.value;
706
- commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
706
+ commands.push("OUTPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
707
707
  }
708
708
  }
709
709
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -716,13 +716,13 @@
716
716
  pipelineString += '\n\n';
717
717
  pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
718
718
  try {
719
- for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
720
- var promptTemplate = promptTemplates_1_1.value;
719
+ for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
720
+ var template = templates_1_1.value;
721
721
  var
722
722
  /* Note: Not using:> name, */
723
- title_1 = promptTemplate.title, description_1 = promptTemplate.description,
723
+ title_1 = template.title, description_1 = template.description,
724
724
  /* Note: dependentParameterNames, */
725
- jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
725
+ jokers = template.jokerParameterNames, blockType = template.blockType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
726
726
  pipelineString += '\n\n';
727
727
  pipelineString += "## ".concat(title_1);
728
728
  if (description_1) {
@@ -733,7 +733,7 @@
733
733
  var commands_1 = [];
734
734
  var contentLanguage = 'text';
735
735
  if (blockType === 'PROMPT_TEMPLATE') {
736
- var modelRequirements = promptTemplate.modelRequirements;
736
+ var modelRequirements = template.modelRequirements;
737
737
  var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
738
738
  commands_1.push("EXECUTE PROMPT TEMPLATE");
739
739
  if (modelVariant) {
@@ -747,17 +747,17 @@
747
747
  commands_1.push("SIMPLE TEMPLATE");
748
748
  // Note: Nothing special here
749
749
  }
750
- else if (blockType === 'SCRIPT') {
750
+ else if (blockType === 'SCRIPT_TEMPLATE') {
751
751
  commands_1.push("EXECUTE SCRIPT");
752
- if (promptTemplate.contentLanguage) {
753
- contentLanguage = promptTemplate.contentLanguage;
752
+ if (template.contentLanguage) {
753
+ contentLanguage = template.contentLanguage;
754
754
  }
755
755
  else {
756
756
  contentLanguage = '';
757
757
  }
758
758
  }
759
- else if (blockType === 'PROMPT_DIALOG') {
760
- commands_1.push("PROMPT DIALOG");
759
+ else if (blockType === 'DIALOG_TEMPLATE') {
760
+ commands_1.push("DIALOG BLOCK");
761
761
  // Note: Nothing special here
762
762
  } // <- }else if([🅱]
763
763
  if (jokers) {
@@ -815,10 +815,10 @@
815
815
  finally { if (e_6) throw e_6.error; }
816
816
  }
817
817
  } /* not else */
818
- if (expectFormat) {
819
- if (expectFormat === 'JSON') {
818
+ if (format) {
819
+ if (format === 'JSON') {
820
820
  // TODO: @deprecated remove
821
- commands_1.push("EXPECT JSON");
821
+ commands_1.push("FORMAT JSON");
822
822
  }
823
823
  } /* not else */
824
824
  pipelineString += '\n\n';
@@ -832,13 +832,13 @@
832
832
  pipelineString += '\n';
833
833
  pipelineString += '```';
834
834
  pipelineString += '\n\n';
835
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
835
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use templateParameterJsonToString
836
836
  }
837
837
  }
838
838
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
839
839
  finally {
840
840
  try {
841
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
841
+ if (templates_1_1 && !templates_1_1.done && (_c = templates_1.return)) _c.call(templates_1);
842
842
  }
843
843
  finally { if (e_3) throw e_3.error; }
844
844
  }
@@ -847,8 +847,8 @@
847
847
  /**
848
848
  * @private internal utility of `pipelineJsonToString`
849
849
  */
850
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
851
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
850
+ function templateParameterJsonToString(templateParameterJson) {
851
+ var name = templateParameterJson.name, description = templateParameterJson.description;
852
852
  var parameterString = "{".concat(name, "}");
853
853
  if (description) {
854
854
  parameterString = "".concat(parameterString, " ").concat(description);
@@ -856,7 +856,7 @@
856
856
  return parameterString;
857
857
  }
858
858
  /**
859
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
859
+ * TODO: !!!!!! Implement new features and commands into `templateParameterJsonToString`
860
860
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
861
861
  * TODO: [🏛] Maybe make some markdown builder
862
862
  * TODO: [🏛] Escape all
@@ -1059,23 +1059,26 @@
1059
1059
  });
1060
1060
  }
1061
1061
 
1062
- 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"}];
1062
+ 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"}];
1063
1063
 
1064
1064
  /**
1065
1065
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1066
1066
  *
1067
1067
  * @public exported from `@promptbook/core`
1068
1068
  */
1069
- var ParsingError = /** @class */ (function (_super) {
1070
- __extends(ParsingError, _super);
1071
- function ParsingError(message) {
1069
+ var ParseError = /** @class */ (function (_super) {
1070
+ __extends(ParseError, _super);
1071
+ function ParseError(message) {
1072
1072
  var _this = _super.call(this, message) || this;
1073
- _this.name = 'ParsingError';
1074
- Object.setPrototypeOf(_this, ParsingError.prototype);
1073
+ _this.name = 'ParseError';
1074
+ Object.setPrototypeOf(_this, ParseError.prototype);
1075
1075
  return _this;
1076
1076
  }
1077
- return ParsingError;
1077
+ return ParseError;
1078
1078
  }(Error));
1079
+ /**
1080
+ * TODO: Maybe split `ParseError` and `ApplyError`
1081
+ */
1079
1082
 
1080
1083
  /**
1081
1084
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
@@ -1287,12 +1290,12 @@
1287
1290
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1288
1291
  if (!Array.isArray(pipeline.parameters)) {
1289
1292
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1290
- 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 "); }));
1293
+ 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 "); }));
1291
1294
  }
1292
1295
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1293
- if (!Array.isArray(pipeline.promptTemplates)) {
1296
+ if (!Array.isArray(pipeline.templates)) {
1294
1297
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1295
- 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 "); }));
1298
+ 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 "); }));
1296
1299
  }
1297
1300
  var _loop_1 = function (parameter) {
1298
1301
  if (parameter.isInput && parameter.isOutput) {
@@ -1301,12 +1304,12 @@
1301
1304
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
1302
1305
  if (!parameter.isInput &&
1303
1306
  !parameter.isOutput &&
1304
- !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1307
+ !pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1305
1308
  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 "); }));
1306
1309
  }
1307
1310
  // Note: Testing that parameter is either input or result of some template
1308
1311
  if (!parameter.isInput &&
1309
- !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1312
+ !pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1310
1313
  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 "); }));
1311
1314
  }
1312
1315
  };
@@ -1342,7 +1345,7 @@
1342
1345
  }
1343
1346
  definedParameters.add(template.resultingParameterName);
1344
1347
  if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1345
- if (!template.expectFormat &&
1348
+ if (!template.format &&
1346
1349
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1347
1350
  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 "); }));
1348
1351
  }
@@ -1394,7 +1397,7 @@
1394
1397
  };
1395
1398
  try {
1396
1399
  // Note: Checking each template individually
1397
- for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
1400
+ for (var _f = __values(pipeline.templates), _g = _f.next(); !_g.done; _g = _f.next()) {
1398
1401
  var template = _g.value;
1399
1402
  _loop_2(template);
1400
1403
  }
@@ -1430,8 +1433,7 @@
1430
1433
  }
1431
1434
  finally { if (e_3) throw e_3.error; }
1432
1435
  }
1433
- var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
1434
- // <- TODO: [🧠][🥜]
1436
+ var unresovedTemplates = __spreadArray([], __read(pipeline.templates), false);
1435
1437
  var loopLimit = LOOP_LIMIT;
1436
1438
  var _loop_3 = function () {
1437
1439
  if (loopLimit-- < 0) {
@@ -1444,14 +1446,14 @@
1444
1446
  if (currentlyResovedTemplates.length === 0) {
1445
1447
  throw new PipelineLogicError(
1446
1448
  // TODO: [🐎] DRY
1447
- 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
1449
+ 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
1448
1450
  .map(function (_a) {
1449
1451
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1450
1452
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
1451
1453
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1452
1454
  .join(' and '));
1453
1455
  })
1454
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1456
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n\n "); }));
1455
1457
  }
1456
1458
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1457
1459
  var resultingParameterName = _a.resultingParameterName;
@@ -1551,23 +1553,23 @@
1551
1553
  * @public exported from `@promptbook/core`
1552
1554
  */
1553
1555
  function unpreparePipeline(pipeline) {
1554
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1556
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, templates = pipeline.templates;
1555
1557
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1556
1558
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1557
- promptTemplates = promptTemplates.map(function (promptTemplate) {
1558
- var dependentParameterNames = promptTemplate.dependentParameterNames;
1559
- var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
1559
+ templates = templates.map(function (template) {
1560
+ var dependentParameterNames = template.dependentParameterNames;
1561
+ var parameterNames = extractParameterNames(template.preparedContent || '');
1560
1562
  dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1561
- var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
1562
- delete promptTemplateUnprepared.preparedContent;
1563
- return promptTemplateUnprepared;
1563
+ var templateUnprepared = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames });
1564
+ delete templateUnprepared.preparedContent;
1565
+ return templateUnprepared;
1564
1566
  });
1565
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1567
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { templates: templates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1566
1568
  }
1567
1569
  /**
1568
1570
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1569
1571
  * TODO: Write tests for `preparePipeline`
1570
- * TODO: [🍙] Make some standart order of json properties
1572
+ * TODO: [🍙] Make some standard order of json properties
1571
1573
  */
1572
1574
 
1573
1575
  /**
@@ -2133,7 +2135,7 @@
2133
2135
  LimitReachedError: LimitReachedError,
2134
2136
  NotFoundError: NotFoundError,
2135
2137
  NotYetImplementedError: NotYetImplementedError,
2136
- ParsingError: ParsingError,
2138
+ ParseError: ParseError,
2137
2139
  PipelineExecutionError: PipelineExecutionError,
2138
2140
  PipelineLogicError: PipelineLogicError,
2139
2141
  PipelineUrlError: PipelineUrlError,
@@ -2190,7 +2192,7 @@
2190
2192
  *
2191
2193
  * @param script from which to extract the variables
2192
2194
  * @returns the list of variable names
2193
- * @throws {ParsingError} if the script is invalid
2195
+ * @throws {ParseError} if the script is invalid
2194
2196
  * @public exported from `@promptbook/utils`
2195
2197
  */
2196
2198
  function extractVariables(script) {
@@ -2226,7 +2228,7 @@
2226
2228
  if (!(error instanceof Error)) {
2227
2229
  throw error;
2228
2230
  }
2229
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2231
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
2230
2232
  }
2231
2233
  return variables;
2232
2234
  }
@@ -2237,14 +2239,14 @@
2237
2239
  /**
2238
2240
  * Parses the prompt template and returns the set of all used parameters
2239
2241
  *
2240
- * @param promptTemplate the template with used parameters
2242
+ * @param template the template with used parameters
2241
2243
  * @returns the set of parameter names
2242
- * @throws {ParsingError} if the script is invalid
2244
+ * @throws {ParseError} if the script is invalid
2243
2245
  * @public exported from `@promptbook/utils`
2244
2246
  */
2245
- function extractParameterNamesFromPromptTemplate(promptTemplate) {
2247
+ function extractParameterNamesFromTemplate(template) {
2246
2248
  var e_1, _a, e_2, _b, e_3, _c;
2247
- var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
2249
+ var title = template.title, description = template.description, blockType = template.blockType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
2248
2250
  var parameterNames = new Set();
2249
2251
  try {
2250
2252
  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()) {
@@ -2259,7 +2261,7 @@
2259
2261
  }
2260
2262
  finally { if (e_1) throw e_1.error; }
2261
2263
  }
2262
- if (blockType === 'SCRIPT') {
2264
+ if (blockType === 'SCRIPT_TEMPLATE') {
2263
2265
  try {
2264
2266
  for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
2265
2267
  var parameterName = _g.value;
@@ -2637,7 +2639,7 @@
2637
2639
  *
2638
2640
  * @param markdown any valid markdown
2639
2641
  * @returns code blocks with language and content
2640
- * @throws {ParsingError} if block is not closed properly
2642
+ * @throws {ParseError} if block is not closed properly
2641
2643
  * @public exported from `@promptbook/markdown-utils`
2642
2644
  */
2643
2645
  function extractAllBlocksFromMarkdown(markdown) {
@@ -2673,7 +2675,7 @@
2673
2675
  }
2674
2676
  else {
2675
2677
  if (language !== null) {
2676
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2678
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2677
2679
  }
2678
2680
  codeBlocks.push(currentCodeBlock);
2679
2681
  currentCodeBlock = null;
@@ -2695,7 +2697,7 @@
2695
2697
  finally { if (e_1) throw e_1.error; }
2696
2698
  }
2697
2699
  if (currentCodeBlock !== null) {
2698
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2700
+ throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2699
2701
  }
2700
2702
  return codeBlocks;
2701
2703
  }
@@ -2707,8 +2709,8 @@
2707
2709
  * Extracts extracts exactly one valid JSON code block
2708
2710
  *
2709
2711
  * - When given string is a valid JSON as it is, it just returns it
2710
- * - When there is no JSON code block the function throws a `ParsingError`
2711
- * - When there are multiple JSON code blocks the function throws a `ParsingError`
2712
+ * - When there is no JSON code block the function throws a `ParseError`
2713
+ * - When there are multiple JSON code blocks the function throws a `ParseError`
2712
2714
  *
2713
2715
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
2714
2716
  * Note: There are multiple simmilar function:
@@ -2718,7 +2720,7 @@
2718
2720
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2719
2721
  *
2720
2722
  * @public exported from `@promptbook/markdown-utils`
2721
- * @throws {ParsingError} if there is no valid JSON block in the markdown
2723
+ * @throws {ParseError} if there is no valid JSON block in the markdown
2722
2724
  */
2723
2725
  function extractJsonBlock(markdown) {
2724
2726
  if (isValidJsonString(markdown)) {
@@ -2757,8 +2759,8 @@
2757
2759
  return false;
2758
2760
  }
2759
2761
  /*
2760
- TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2761
- > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2762
+ TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
2763
+ > if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
2762
2764
  > return false;
2763
2765
  > }
2764
2766
  */
@@ -3145,8 +3147,7 @@
3145
3147
  }
3146
3148
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
3147
3149
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
3148
- function getContextForTemplate(// <- TODO: [🧠][🥜]
3149
- template) {
3150
+ function getContextForTemplate(template) {
3150
3151
  return __awaiter(this, void 0, void 0, function () {
3151
3152
  return __generator(this, function (_a) {
3152
3153
  TODO_USE(template);
@@ -3154,8 +3155,7 @@
3154
3155
  });
3155
3156
  });
3156
3157
  }
3157
- function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
3158
- template) {
3158
+ function getKnowledgeForTemplate(template) {
3159
3159
  return __awaiter(this, void 0, void 0, function () {
3160
3160
  return __generator(this, function (_a) {
3161
3161
  // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
@@ -3167,8 +3167,7 @@
3167
3167
  });
3168
3168
  });
3169
3169
  }
3170
- function getSamplesForTemplate(// <- TODO: [🧠][🥜]
3171
- template) {
3170
+ function getSamplesForTemplate(template) {
3172
3171
  return __awaiter(this, void 0, void 0, function () {
3173
3172
  return __generator(this, function (_a) {
3174
3173
  // TODO: [♨] Implement Better - use real index and keyword search
@@ -3235,7 +3234,7 @@
3235
3234
  case 0:
3236
3235
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
3237
3236
  title = currentTemplate.title;
3238
- priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
3237
+ priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3239
3238
  if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
3240
3239
  progress_1 = {
3241
3240
  name: name,
@@ -3258,7 +3257,7 @@
3258
3257
  _h.sent();
3259
3258
  _h.label = 2;
3260
3259
  case 2:
3261
- usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3260
+ usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3262
3261
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3263
3262
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3264
3263
  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)
@@ -3307,13 +3306,13 @@
3307
3306
  result = null;
3308
3307
  resultString = null;
3309
3308
  expectError = null;
3310
- maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
3309
+ maxAttempts = currentTemplate.blockType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3311
3310
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3312
3311
  preparedContent = (currentTemplate.preparedContent || '{content}')
3313
3312
  .split('{content}')
3314
3313
  .join(currentTemplate.content);
3315
3314
  _loop_5 = function (attempt) {
3316
- 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;
3315
+ 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;
3317
3316
  var e_5, _s, e_7, _t, e_6, _u;
3318
3317
  return __generator(this, function (_v) {
3319
3318
  switch (_v.label) {
@@ -3343,14 +3342,15 @@
3343
3342
  switch (_j) {
3344
3343
  case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3345
3344
  case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3346
- case 'SCRIPT': return [3 /*break*/, 12];
3347
- case 'PROMPT_DIALOG': return [3 /*break*/, 23];
3345
+ case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
3346
+ case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
3348
3347
  }
3349
3348
  return [3 /*break*/, 25];
3350
3349
  case 2:
3351
3350
  resultString = replaceParameters(preparedContent, parameters);
3352
3351
  return [3 /*break*/, 26];
3353
3352
  case 3:
3353
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3354
3354
  prompt = {
3355
3355
  title: currentTemplate.title,
3356
3356
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
@@ -3358,15 +3358,15 @@
3358
3358
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3359
3359
  parameters: parameters,
3360
3360
  content: preparedContent,
3361
- modelRequirements: currentTemplate.modelRequirements,
3361
+ modelRequirements: modelRequirements,
3362
3362
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3363
3363
  var name = _a.name;
3364
3364
  return name === currentTemplate.personaName;
3365
3365
  }) || {})), currentTemplate.expectations),
3366
- expectFormat: currentTemplate.expectFormat,
3366
+ format: currentTemplate.format,
3367
3367
  postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3368
3368
  }; // <- TODO: Not very good type guard
3369
- _k = currentTemplate.modelRequirements.modelVariant;
3369
+ _k = modelRequirements.modelVariant;
3370
3370
  switch (_k) {
3371
3371
  case 'CHAT': return [3 /*break*/, 4];
3372
3372
  case 'COMPLETION': return [3 /*break*/, 6];
@@ -3392,7 +3392,8 @@
3392
3392
  result = embeddingResult;
3393
3393
  resultString = embeddingResult.content.join(',');
3394
3394
  return [3 /*break*/, 11];
3395
- 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 "); }));
3395
+ case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
3396
+ .modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3396
3397
  case 11: return [3 /*break*/, 26];
3397
3398
  case 12:
3398
3399
  if (arrayableToArray(tools.script).length === 0) {
@@ -3471,7 +3472,7 @@
3471
3472
  priority: priority,
3472
3473
  }))];
3473
3474
  case 24:
3474
- // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
3475
+ // TODO: [🌹] When making next attempt for `DIALOG BLOCK`, preserve the previous user input
3475
3476
  resultString = _v.sent();
3476
3477
  return [3 /*break*/, 26];
3477
3478
  case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -3557,8 +3558,8 @@
3557
3558
  return [7 /*endfinally*/];
3558
3559
  case 43:
3559
3560
  // TODO: [💝] Unite object for expecting amount and format
3560
- if (currentTemplate.expectFormat) {
3561
- if (currentTemplate.expectFormat === 'JSON') {
3561
+ if (currentTemplate.format) {
3562
+ if (currentTemplate.format === 'JSON') {
3562
3563
  if (!isValidJsonString(resultString || '')) {
3563
3564
  // TODO: [🏢] Do more universally via `FormatDefinition`
3564
3565
  try {
@@ -3572,7 +3573,7 @@
3572
3573
  }
3573
3574
  }
3574
3575
  else {
3575
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3576
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3576
3577
  }
3577
3578
  }
3578
3579
  // TODO: [💝] Unite object for expecting amount and format
@@ -3848,7 +3849,7 @@
3848
3849
  var name = _a.name;
3849
3850
  return name;
3850
3851
  });
3851
- unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.promptTemplates), false);
3852
+ unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.templates), false);
3852
3853
  resolving_1 = [];
3853
3854
  loopLimit = LOOP_LIMIT;
3854
3855
  _loop_2 = function () {
@@ -3969,7 +3970,7 @@
3969
3970
  * TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
3970
3971
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
3971
3972
  * TODO: [♈] Probbably move expectations from templates to parameters
3972
- * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
3973
+ * TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
3973
3974
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
3974
3975
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
3975
3976
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
@@ -4339,7 +4340,7 @@
4339
4340
  */
4340
4341
  function clonePipeline(pipeline) {
4341
4342
  // Note: Not using spread operator (...) because @@@
4342
- 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;
4343
+ 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;
4343
4344
  return {
4344
4345
  pipelineUrl: pipelineUrl,
4345
4346
  sourceFile: sourceFile,
@@ -4347,7 +4348,7 @@
4347
4348
  promptbookVersion: promptbookVersion,
4348
4349
  description: description,
4349
4350
  parameters: parameters,
4350
- promptTemplates: promptTemplates,
4351
+ templates: templates,
4351
4352
  knowledgeSources: knowledgeSources,
4352
4353
  knowledgePieces: knowledgePieces,
4353
4354
  personas: personas,
@@ -4355,7 +4356,7 @@
4355
4356
  };
4356
4357
  }
4357
4358
  /**
4358
- * TODO: [🍙] Make some standart order of json properties
4359
+ * TODO: [🍙] Make some standard order of json properties
4359
4360
  */
4360
4361
 
4361
4362
  /**
@@ -4365,19 +4366,19 @@
4365
4366
  */
4366
4367
  function prepareTemplates(pipeline, options) {
4367
4368
  return __awaiter(this, void 0, void 0, function () {
4368
- var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
4369
+ var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
4369
4370
  var _this = this;
4370
4371
  return __generator(this, function (_b) {
4371
4372
  switch (_b.label) {
4372
4373
  case 0:
4373
4374
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
4374
- promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4375
+ templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
4375
4376
  // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
4376
4377
  TODO_USE(parameters);
4377
- promptTemplatesPrepared = new Array(
4378
+ templatesPrepared = new Array(
4378
4379
  // <- TODO: [🧱] Implement in a functional (not new Class) way
4379
- promptTemplates.length);
4380
- 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 () {
4380
+ templates.length);
4381
+ 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 () {
4381
4382
  var dependentParameterNames, preparedContent, preparedTemplate;
4382
4383
  return __generator(this, function (_a) {
4383
4384
  dependentParameterNames = template.dependentParameterNames;
@@ -4390,13 +4391,13 @@
4390
4391
  ], false);
4391
4392
  }
4392
4393
  preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
4393
- promptTemplatesPrepared[index] = preparedTemplate;
4394
+ templatesPrepared[index] = preparedTemplate;
4394
4395
  return [2 /*return*/];
4395
4396
  });
4396
4397
  }); })];
4397
4398
  case 1:
4398
4399
  _b.sent();
4399
- return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
4400
+ return [2 /*return*/, { templatesPrepared: templatesPrepared }];
4400
4401
  }
4401
4402
  });
4402
4403
  });
@@ -4409,7 +4410,6 @@
4409
4410
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4410
4411
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
4411
4412
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4412
- * TODO: [🧠][🥜]
4413
4413
  */
4414
4414
 
4415
4415
  /**
@@ -4422,12 +4422,12 @@
4422
4422
  */
4423
4423
  function preparePipeline(pipeline, options) {
4424
4424
  return __awaiter(this, void 0, void 0, function () {
4425
- var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
4425
+ var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, templates,
4426
4426
  /*
4427
4427
  <- TODO: [🧠][🪑] `promptbookVersion` */
4428
4428
  knowledgeSources /*
4429
4429
  <- TODO: [🧊] `knowledgePieces` */, personas /*
4430
- <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
4430
+ <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
4431
4431
  var _this = this;
4432
4432
  return __generator(this, function (_c) {
4433
4433
  switch (_c.label) {
@@ -4436,7 +4436,7 @@
4436
4436
  return [2 /*return*/, pipeline];
4437
4437
  }
4438
4438
  llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
4439
- parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4439
+ parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4440
4440
  llmToolsWithUsage = countTotalUsage(llmTools);
4441
4441
  currentPreparation = {
4442
4442
  id: 1,
@@ -4482,7 +4482,7 @@
4482
4482
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
4483
4483
  return [4 /*yield*/, prepareTemplates({
4484
4484
  parameters: parameters,
4485
- promptTemplates: promptTemplates,
4485
+ templates: templates,
4486
4486
  knowledgePiecesCount: knowledgePiecesPrepared.length,
4487
4487
  }, {
4488
4488
  llmTools: llmToolsWithUsage,
@@ -4490,11 +4490,11 @@
4490
4490
  isVerbose: isVerbose,
4491
4491
  })];
4492
4492
  case 3:
4493
- promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
4493
+ templatesPrepared = (_c.sent()).templatesPrepared;
4494
4494
  // ----- /Templates preparation -----
4495
4495
  // Note: Count total usage
4496
4496
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
4497
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4497
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: templatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4498
4498
  }
4499
4499
  });
4500
4500
  });
@@ -4548,7 +4548,8 @@
4548
4548
  /**
4549
4549
  * BOILERPLATE command can be used in:
4550
4550
  */
4551
- usagePlaces: ['PIPELINE_HEAD'],
4551
+ isUsedInPipelineHead: true,
4552
+ isUsedInPipelineTemplate: false,
4552
4553
  /**
4553
4554
  * Description of the KNOWLEDGE command
4554
4555
  */
@@ -4574,17 +4575,17 @@
4574
4575
  var args = input.args;
4575
4576
  var sourceContent = spaceTrim__default["default"](args[0] || '');
4576
4577
  if (sourceContent === '') {
4577
- throw new ParsingError("Source is not defined");
4578
+ throw new ParseError("Source is not defined");
4578
4579
  }
4579
4580
  // TODO: !!!! Following checks should be applied every link in the `sourceContent`
4580
4581
  if (sourceContent.startsWith('http://')) {
4581
- throw new ParsingError("Source is not secure");
4582
+ throw new ParseError("Source is not secure");
4582
4583
  }
4583
4584
  if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
4584
- throw new ParsingError("Source not valid");
4585
+ throw new ParseError("Source not valid");
4585
4586
  }
4586
4587
  if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
4587
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
4588
+ throw new ParseError("Source cannot be outside of the .ptbk.md folder");
4588
4589
  }
4589
4590
  return {
4590
4591
  type: 'KNOWLEDGE',
@@ -4592,194 +4593,40 @@
4592
4593
  };
4593
4594
  },
4594
4595
  /**
4595
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4596
+ * Apply the KNOWLEDGE command to the `pipelineJson`
4597
+ *
4598
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
4596
4599
  */
4597
- applyToPipelineJson: function (personaCommand, subjects) {
4598
- var sourceContent = personaCommand.sourceContent;
4599
- var pipelineJson = subjects.pipelineJson;
4600
+ $applyToPipelineJson: function (command, $pipelineJson) {
4601
+ var sourceContent = command.sourceContent;
4600
4602
  var name = 'source-' + sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(sourceContent))).toString( /* hex */);
4601
4603
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
4602
4604
  // <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
4603
- pipelineJson.knowledgeSources.push({
4605
+ $pipelineJson.knowledgeSources.push({
4604
4606
  name: name,
4605
4607
  sourceContent: sourceContent,
4606
4608
  });
4607
4609
  },
4608
- };
4609
-
4610
- /**
4611
- * Parses the persona command
4612
- *
4613
- * @see ./PERSONA-README.md for more details
4614
- * @private within the commands folder
4615
- */
4616
- var personaCommandParser = {
4617
- /**
4618
- * Name of the command
4619
- */
4620
- name: 'PERSONA',
4621
- /**
4622
- * Aliases for the PERSONA command
4623
- */
4624
- aliasNames: ['PERSON'],
4625
- /**
4626
- * PERSONA command can be used in:
4627
- */
4628
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
4629
- /**
4630
- * Description of the PERSONA command
4631
- */
4632
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
4633
- /**
4634
- * Link to discussion
4635
- */
4636
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
4637
- /**
4638
- * Example usages of the PERSONA command
4639
- */
4640
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
4641
4610
  /**
4642
- * Parses the PERSONA command
4611
+ * Converts the KNOWLEDGE command back to string
4612
+ *
4613
+ * Note: This is used in `pipelineJsonToString` utility
4643
4614
  */
4644
- parse: function (input) {
4645
- var rawArgs = input.rawArgs;
4646
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
4647
- var personaName = (personaNameRaw || '').trim();
4648
- if (personaName === '') {
4649
- throw new ParsingError("You must set name for the persona");
4650
- }
4651
- var personaDescription = (personaDescriptionRaw || '').trim();
4652
- if (personaDescription === '') {
4653
- personaDescription = null;
4654
- }
4655
- return {
4656
- type: 'PERSONA',
4657
- personaName: personaName,
4658
- personaDescription: personaDescription,
4659
- };
4615
+ stringify: function (command) {
4616
+ keepUnused(command);
4617
+ return "!!!!!!";
4660
4618
  },
4661
4619
  /**
4662
- * Note: Prototype of [🍧] (remove this comment after full implementation)
4620
+ * Reads the KNOWLEDGE command from the `PipelineJson`
4621
+ *
4622
+ * Note: This is used in `pipelineJsonToString` utility
4663
4623
  */
4664
- applyToPipelineJson: function (personaCommand, subjects) {
4665
- var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
4666
- var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
4667
- if (templateJson !== null) {
4668
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
4669
- throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
4670
- }
4671
- templateJson.personaName = personaName;
4672
- }
4673
- var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
4674
- if (persona === undefined) {
4675
- pipelineJson.personas.push({
4676
- name: personaName,
4677
- description: personaDescription || '',
4678
- });
4679
- return;
4680
- }
4681
- if (persona.description === personaDescription) {
4682
- return;
4683
- }
4684
- if (personaDescription === null) {
4685
- return;
4686
- }
4687
- if (persona.description === '') {
4688
- persona.description = personaDescription;
4689
- return;
4690
- }
4691
- 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 ")));
4692
- persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
4624
+ takeFromPipelineJson: function (pipelineJson) {
4625
+ keepUnused(pipelineJson);
4626
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4693
4627
  },
4694
4628
  };
4695
4629
 
4696
- /**
4697
- * Removes Markdown formatting tags from a string.
4698
- *
4699
- * @param {string} str - The string to remove Markdown tags from.
4700
- * @returns {string} The input string with all Markdown tags removed.
4701
- * @public exported from `@promptbook/markdown-utils`
4702
- */
4703
- function removeMarkdownFormatting(str) {
4704
- // Remove bold formatting
4705
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
4706
- // Remove italic formatting
4707
- str = str.replace(/\*(.*?)\*/g, '$1');
4708
- // Remove code formatting
4709
- str = str.replace(/`(.*?)`/g, '$1');
4710
- return str;
4711
- }
4712
-
4713
- /**
4714
- * @@@
4715
- *
4716
- * @param text @@@
4717
- * @returns @@@
4718
- * @example 'HELLO_WORLD'
4719
- * @example 'I_LOVE_PROMPTBOOK'
4720
- * @public exported from `@promptbook/utils`
4721
- */
4722
- function normalizeTo_SCREAMING_CASE(text) {
4723
- var e_1, _a;
4724
- var charType;
4725
- var lastCharType = 'OTHER';
4726
- var normalizedName = '';
4727
- try {
4728
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
4729
- var char = text_1_1.value;
4730
- var normalizedChar = void 0;
4731
- if (/^[a-z]$/.test(char)) {
4732
- charType = 'LOWERCASE';
4733
- normalizedChar = char.toUpperCase();
4734
- }
4735
- else if (/^[A-Z]$/.test(char)) {
4736
- charType = 'UPPERCASE';
4737
- normalizedChar = char;
4738
- }
4739
- else if (/^[0-9]$/.test(char)) {
4740
- charType = 'NUMBER';
4741
- normalizedChar = char;
4742
- }
4743
- else if (/^\/$/.test(char)) {
4744
- charType = 'SLASH';
4745
- normalizedChar = char;
4746
- }
4747
- else {
4748
- charType = 'OTHER';
4749
- normalizedChar = '_';
4750
- }
4751
- if (charType !== lastCharType &&
4752
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
4753
- !(lastCharType === 'NUMBER') &&
4754
- !(charType === 'NUMBER')) {
4755
- normalizedName += '_';
4756
- }
4757
- normalizedName += normalizedChar;
4758
- lastCharType = charType;
4759
- }
4760
- }
4761
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4762
- finally {
4763
- try {
4764
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
4765
- }
4766
- finally { if (e_1) throw e_1.error; }
4767
- }
4768
- normalizedName = normalizedName.replace(/_+/g, '_');
4769
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
4770
- normalizedName = normalizedName.replace(/^_/, '');
4771
- normalizedName = normalizedName.replace(/_$/, '');
4772
- return normalizedName;
4773
- }
4774
- /**
4775
- * TODO: Tests
4776
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
4777
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
4778
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
4779
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
4780
- * TODO: [🌺] Use some intermediate util splitWords
4781
- */
4782
-
4783
4630
  /**
4784
4631
  * Block type describes the way how the block is blockd
4785
4632
  *
@@ -4789,8 +4636,8 @@
4789
4636
  var BlockTypes = [
4790
4637
  'PROMPT_TEMPLATE',
4791
4638
  'SIMPLE_TEMPLATE',
4792
- 'SCRIPT',
4793
- 'PROMPT_DIALOG',
4639
+ 'SCRIPT_TEMPLATE',
4640
+ 'DIALOG_TEMPLATE',
4794
4641
  'SAMPLE',
4795
4642
  'KNOWLEDGE',
4796
4643
  'INSTRUMENT',
@@ -4815,8 +4662,8 @@
4815
4662
  aliasNames: [
4816
4663
  'PROMPT_TEMPLATE',
4817
4664
  'SIMPLE_TEMPLATE',
4818
- 'SCRIPT',
4819
- 'PROMPT_DIALOG',
4665
+ 'SCRIPT_TEMPLATE',
4666
+ 'DIALOG_TEMPLATE',
4820
4667
  'SAMPLE',
4821
4668
  'EXAMPLE',
4822
4669
  'KNOWLEDGE',
@@ -4831,7 +4678,8 @@
4831
4678
  /**
4832
4679
  * BOILERPLATE command can be used in:
4833
4680
  */
4834
- usagePlaces: ['PIPELINE_TEMPLATE'],
4681
+ isUsedInPipelineHead: false,
4682
+ isUsedInPipelineTemplate: true,
4835
4683
  /**
4836
4684
  * Description of the BLOCK command
4837
4685
  */
@@ -4844,19 +4692,24 @@
4844
4692
  * Example usages of the BLOCK command
4845
4693
  */
4846
4694
  examples: [
4847
- 'Prompt template BLOCK',
4848
- 'Prompt template',
4849
- 'Simple template BLOCK',
4850
- 'Simple template',
4851
- 'Script BLOCK',
4852
- 'Script',
4853
- 'Prompt dialog BLOCK',
4854
- 'Prompt dialog',
4855
- 'Sample BLOCK',
4856
- 'Sample',
4857
- 'Example BLOCK',
4858
- 'Example',
4859
- 'Knowledge BLOCK',
4695
+ // Recommended form:
4696
+ 'PROMPT BLOCK',
4697
+ 'SIMPLE BLOCK',
4698
+ 'SCRIPT BLOCK',
4699
+ 'DIALOG BLOCK',
4700
+ // <- [🅱]
4701
+ // Long form:
4702
+ 'PROMPT TEMPLATE BLOCK',
4703
+ 'SIMPLE TEMPLATE BLOCK',
4704
+ 'SCRIPT TEMPLATE BLOCK',
4705
+ 'DIALOG TEMPLATE BLOCK',
4706
+ // <- [🅱]
4707
+ // Reversed form:
4708
+ 'BLOCK PROMPT TEMPLATE',
4709
+ 'BLOCK SIMPLE TEMPLATE',
4710
+ 'BLOCK SCRIPT TEMPLATE',
4711
+ 'BLOCK DIALOG TEMPLATE',
4712
+ // <- [🅱]
4860
4713
  // 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
4861
4714
  //---
4862
4715
  /* Note: Not implemented block types will be in examples in future -> */
@@ -4874,9 +4727,9 @@
4874
4727
  parse: function (input) {
4875
4728
  var normalized = input.normalized;
4876
4729
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
4877
- var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
4730
+ var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType.split('_TEMPLATE').join('')); });
4878
4731
  if (blockTypes.length !== 1) {
4879
- 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 "); }));
4732
+ 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 "); }));
4880
4733
  }
4881
4734
  var blockType = blockTypes[0];
4882
4735
  return {
@@ -4884,6 +4737,94 @@
4884
4737
  blockType: blockType,
4885
4738
  };
4886
4739
  },
4740
+ /**
4741
+ * Apply the BLOCK command to the `pipelineJson`
4742
+ *
4743
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
4744
+ */
4745
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
4746
+ // TODO: !!!!!! Test multiple / no block type
4747
+ if ($templateJson.isBlockTypeSet === true) {
4748
+ throw new ParseError("Block type is already defined in the prompt template. It can be defined only once.");
4749
+ }
4750
+ $templateJson.isBlockTypeSet = true;
4751
+ // TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
4752
+ var expectResultingParameterName = function () {
4753
+ if ($templateJson.resultingParameterName) {
4754
+ return;
4755
+ }
4756
+ throw new ParseError(" Template section must end with -> {parameterName}");
4757
+ };
4758
+ if ($templateJson.content === undefined) {
4759
+ throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
4760
+ }
4761
+ if (command.blockType === 'SAMPLE') {
4762
+ expectResultingParameterName();
4763
+ var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
4764
+ if (parameter === undefined) {
4765
+ throw new ParseError("Can not find parameter {".concat($templateJson.resultingParameterName, "} to assign sample value on it"));
4766
+ }
4767
+ parameter.sampleValues = parameter.sampleValues || [];
4768
+ parameter.sampleValues.push($templateJson.content);
4769
+ // TODO: !!!!!! How to implement this?
4770
+ // continue templates;
4771
+ $templateJson.isTemplateBlock = false;
4772
+ return;
4773
+ }
4774
+ if (command.blockType === 'KNOWLEDGE') {
4775
+ knowledgeCommandParser.$applyToPipelineJson({
4776
+ type: 'KNOWLEDGE',
4777
+ sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
4778
+ }, $pipelineJson);
4779
+ // TODO: !!!!!! How to implement this?
4780
+ // continue templates;
4781
+ $templateJson.isTemplateBlock = false;
4782
+ return;
4783
+ }
4784
+ if (command.blockType === 'ACTION') {
4785
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
4786
+ // TODO: !!!!!! How to implement this?
4787
+ // continue templates;
4788
+ $templateJson.isTemplateBlock = false;
4789
+ return;
4790
+ }
4791
+ if (command.blockType === 'INSTRUMENT') {
4792
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4793
+ // TODO: !!!!!! How to implement this?
4794
+ // continue templates;
4795
+ $templateJson.isTemplateBlock = false;
4796
+ return;
4797
+ }
4798
+ expectResultingParameterName();
4799
+ $templateJson.blockType = command.blockType;
4800
+ /*
4801
+ TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
4802
+ if (command.blockType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
4803
+ templateModelRequirements.modelVariant = 'CHAT';
4804
+ }
4805
+ */
4806
+ // !!!!!!
4807
+ // isBlockTypeSet = true; //<- Note: [2]
4808
+ $templateJson.isTemplateBlock = true;
4809
+ },
4810
+ /**
4811
+ * Converts the BLOCK command back to string
4812
+ *
4813
+ * Note: This is used in `pipelineJsonToString` utility
4814
+ */
4815
+ stringify: function (command) {
4816
+ keepUnused(command);
4817
+ return "!!!!!!";
4818
+ },
4819
+ /**
4820
+ * Reads the BLOCK command from the `TemplateJson`
4821
+ *
4822
+ * Note: This is used in `pipelineJsonToString` utility
4823
+ */
4824
+ takeFromTemplateJson: function ($templateJson) {
4825
+ keepUnused($templateJson);
4826
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
4827
+ },
4887
4828
  };
4888
4829
 
4889
4830
  /**
@@ -4894,7 +4835,7 @@
4894
4835
  */
4895
4836
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
4896
4837
  /**
4897
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
4838
+ * TODO: [💝] Unite object for expecting amount and format - remove format
4898
4839
  */
4899
4840
 
4900
4841
  /**
@@ -4904,7 +4845,7 @@
4904
4845
  * Note: it also works only with decimal numbers
4905
4846
  *
4906
4847
  * @returns parsed number
4907
- * @throws {ParsingError} if the value is not a number
4848
+ * @throws {ParseError} if the value is not a number
4908
4849
  *
4909
4850
  * @public exported from `@promptbook/utils`
4910
4851
  */
@@ -4940,7 +4881,7 @@
4940
4881
  var numerator = parseNumber(numerator_);
4941
4882
  var denominator = parseNumber(denominator_);
4942
4883
  if (denominator === 0) {
4943
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
4884
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
4944
4885
  }
4945
4886
  return numerator / denominator;
4946
4887
  }
@@ -4952,11 +4893,11 @@
4952
4893
  return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
4953
4894
  }
4954
4895
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
4955
- throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\""));
4896
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
4956
4897
  }
4957
4898
  var num = parseFloat(value);
4958
4899
  if (isNaN(num)) {
4959
- throw new ParsingError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
4900
+ throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
4960
4901
  }
4961
4902
  return num;
4962
4903
  }
@@ -4979,9 +4920,10 @@
4979
4920
  /**
4980
4921
  * BOILERPLATE command can be used in:
4981
4922
  */
4982
- usagePlaces: ['PIPELINE_TEMPLATE'],
4923
+ isUsedInPipelineHead: false,
4924
+ isUsedInPipelineTemplate: true,
4983
4925
  /**
4984
- * Description of the EXPECT command
4926
+ * Description of the FORMAT command
4985
4927
  */
4986
4928
  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 "),
4987
4929
  /**
@@ -4989,7 +4931,7 @@
4989
4931
  */
4990
4932
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
4991
4933
  /**
4992
- * Example usages of the EXPECT command
4934
+ * Example usages of the FORMAT command
4993
4935
  */
4994
4936
  examples: [
4995
4937
  'EXPECT MIN 100 Characters',
@@ -4997,22 +4939,13 @@
4997
4939
  'EXPECT EXACTLY 3 Sentences',
4998
4940
  'EXPECT EXACTLY 1 Paragraph',
4999
4941
  // <- TODO: 'EXPECT 1 Paragraph',
5000
- 'Expect JSON',
5001
4942
  ],
5002
4943
  /**
5003
- * Parses the EXPECT command
4944
+ * Parses the FORMAT command
5004
4945
  */
5005
4946
  parse: function (input) {
5006
4947
  var e_1, _a;
5007
- var args = input.args, normalized = input.normalized;
5008
- if (normalized.startsWith('EXPECT_JSON')) {
5009
- return {
5010
- type: 'EXPECT_FORMAT',
5011
- format: 'JSON',
5012
- };
5013
- // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5014
- // [🥤]
5015
- }
4948
+ var args = input.args;
5016
4949
  try {
5017
4950
  var sign = void 0;
5018
4951
  var signRaw = args.shift();
@@ -5026,15 +4959,15 @@
5026
4959
  sign = 'MAXIMUM';
5027
4960
  }
5028
4961
  else {
5029
- throw new ParsingError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
4962
+ throw new ParseError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
5030
4963
  }
5031
4964
  var amountRaw = args.shift();
5032
4965
  var amount = parseNumber(amountRaw);
5033
4966
  if (amount < 0) {
5034
- throw new ParsingError('Amount must be positive number or zero');
4967
+ throw new ParseError('Amount must be positive number or zero');
5035
4968
  }
5036
4969
  if (amount !== Math.floor(amount)) {
5037
- throw new ParsingError('Amount must be whole number');
4970
+ throw new ParseError('Amount must be whole number');
5038
4971
  }
5039
4972
  var unitRaw = args.shift();
5040
4973
  var unit = undefined;
@@ -5049,7 +4982,7 @@
5049
4982
  if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
5050
4983
  new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
5051
4984
  if (unit !== undefined) {
5052
- throw new ParsingError("Ambiguous unit \"".concat(unitRaw, "\""));
4985
+ throw new ParseError("Ambiguous unit \"".concat(unitRaw, "\""));
5053
4986
  }
5054
4987
  unit = existingUnit;
5055
4988
  }
@@ -5063,10 +4996,10 @@
5063
4996
  finally { if (e_1) throw e_1.error; }
5064
4997
  }
5065
4998
  if (unit === undefined) {
5066
- throw new ParsingError("Invalid unit \"".concat(unitRaw, "\""));
4999
+ throw new ParseError("Invalid unit \"".concat(unitRaw, "\""));
5067
5000
  }
5068
5001
  return {
5069
- type: 'EXPECT_AMOUNT',
5002
+ type: 'EXPECT',
5070
5003
  sign: sign,
5071
5004
  unit: unit,
5072
5005
  amount: amount,
@@ -5076,100 +5009,324 @@
5076
5009
  if (!(error instanceof Error)) {
5077
5010
  throw error;
5078
5011
  }
5079
- throw new ParsingError(spaceTrim__default["default"](function (block) {
5080
- return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
5012
+ throw new ParseError(spaceTrim__default["default"](function (block) {
5013
+ return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
5081
5014
  }));
5082
5015
  }
5083
5016
  },
5017
+ /**
5018
+ * Apply the FORMAT command to the `pipelineJson`
5019
+ *
5020
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5021
+ */
5022
+ $applyToTemplateJson: function (command, $templateJson) {
5023
+ // eslint-disable-next-line no-case-declarations
5024
+ var unit = command.unit.toLowerCase();
5025
+ $templateJson.expectations = $templateJson.expectations || {};
5026
+ $templateJson.expectations[unit] = $templateJson.expectations[unit] || {};
5027
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
5028
+ if ($templateJson.expectations[unit].min !== undefined) {
5029
+ throw new ParseError("Already defined minumum ".concat($templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5030
+ }
5031
+ $templateJson.expectations[unit].min = command.amount;
5032
+ } /* not else */
5033
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
5034
+ if ($templateJson.expectations[unit].max !== undefined) {
5035
+ throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5036
+ }
5037
+ $templateJson.expectations[unit].max = command.amount;
5038
+ }
5039
+ },
5040
+ /**
5041
+ * Converts the FORMAT command back to string
5042
+ *
5043
+ * Note: This is used in `pipelineJsonToString` utility
5044
+ */
5045
+ stringify: function (command) {
5046
+ keepUnused(command);
5047
+ return "!!!!!!";
5048
+ },
5049
+ /**
5050
+ * Reads the FORMAT command from the `TemplateJson`
5051
+ *
5052
+ * Note: This is used in `pipelineJsonToString` utility
5053
+ */
5054
+ takeFromTemplateJson: function ($templateJson) {
5055
+ keepUnused($templateJson);
5056
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5057
+ },
5084
5058
  };
5085
5059
 
5086
5060
  /**
5087
- * Parses the joker command
5061
+ * Parses the foreach command
5088
5062
  *
5089
- * @see ./JOKER-README.md for more details
5063
+ * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
5064
+ *
5065
+ * @see ./FOREACH-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5090
5066
  * @private within the commands folder
5091
5067
  */
5092
- var jokerCommandParser = {
5068
+ var foreachCommandParser = {
5093
5069
  /**
5094
5070
  * Name of the command
5095
5071
  */
5096
- name: 'JOKER',
5072
+ name: 'FOREACH',
5097
5073
  /**
5098
- * BOILERPLATE command can be used in:
5074
+ * Aliases for the FOREACH command
5099
5075
  */
5100
- usagePlaces: ['PIPELINE_TEMPLATE'],
5076
+ aliasNames: ['FOR', 'EACH'],
5101
5077
  /**
5102
- * Description of the JOKER command
5078
+ * FOREACH command can be used in:
5103
5079
  */
5104
- description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5080
+ isUsedInPipelineHead: false,
5081
+ isUsedInPipelineTemplate: true,
5082
+ /**
5083
+ * Description of the FOREACH command
5084
+ */
5085
+ description: "@@",
5105
5086
  /**
5106
5087
  * Link to discussion
5107
5088
  */
5108
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5089
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5109
5090
  /**
5110
- * Example usages of the JOKER command
5091
+ * Example usages of the FOREACH command
5111
5092
  */
5112
- examples: ['JOKER {documentTitle}'],
5093
+ examples: [
5094
+ 'FOREACH List Line -> `{customer}`',
5095
+ 'FOR List Line -> `{customer}`',
5096
+ 'EACH List Line -> `{customer}`',
5097
+ // <- TODO: [🍭] More
5098
+ ],
5113
5099
  /**
5114
- * Parses the JOKER command
5100
+ * Parses the FOREACH command
5115
5101
  */
5116
5102
  parse: function (input) {
5117
5103
  var args = input.args;
5118
- var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5119
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5120
- throw new ParsingError("Invalid joker");
5121
- }
5122
- var parameterName = parametersMatch.groups.parameterName;
5104
+ keepUnused(args);
5105
+ // <- TODO: [🍭] Implement
5123
5106
  return {
5124
- type: 'JOKER',
5125
- parameterName: parameterName,
5107
+ type: 'FOREACH',
5126
5108
  };
5127
5109
  },
5110
+ /**
5111
+ * Apply the FOREACH command to the `pipelineJson`
5112
+ *
5113
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5114
+ */
5115
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5116
+ keepUnused(command, $templateJson, $pipelineJson);
5117
+ // <- TODO: [🍭] Implement
5118
+ },
5119
+ /**
5120
+ * Converts the FOREACH command back to string
5121
+ *
5122
+ * Note: This is used in `pipelineJsonToString` utility
5123
+ */
5124
+ stringify: function (command) {
5125
+ keepUnused(command);
5126
+ return "";
5127
+ // <- TODO: [🍭] Implement
5128
+ },
5129
+ /**
5130
+ * Reads the FOREACH command from the `TemplateJson`
5131
+ *
5132
+ * Note: This is used in `pipelineJsonToString` utility
5133
+ */
5134
+ takeFromTemplateJson: function ($templateJson) {
5135
+ keepUnused($templateJson);
5136
+ return [];
5137
+ // <- TODO: [🍭] Implement
5138
+ },
5128
5139
  };
5129
-
5130
5140
  /**
5131
- * @@@
5132
- *
5133
- * @public exported from `@promptbook/core`
5141
+ * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong syntax and logic
5134
5142
  */
5135
- var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5136
5143
 
5137
5144
  /**
5138
- * Parses the model command
5145
+ * Parses the format command
5139
5146
  *
5140
- * @see ./MODEL-README.md for more details
5147
+ * @see ./FORMAT-README.md for more details
5141
5148
  * @private within the commands folder
5142
5149
  */
5143
- var modelCommandParser = {
5150
+ var formatCommandParser = {
5144
5151
  /**
5145
5152
  * Name of the command
5146
5153
  */
5147
- name: 'MODEL',
5154
+ name: 'FORMAT',
5148
5155
  /**
5149
5156
  * BOILERPLATE command can be used in:
5150
5157
  */
5151
- usagePlaces: [
5152
- 'PIPELINE_HEAD',
5153
- // <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
5154
- 'PIPELINE_TEMPLATE',
5155
- ],
5158
+ isUsedInPipelineHead: false,
5159
+ isUsedInPipelineTemplate: true,
5156
5160
  /**
5157
- * Description of the MODEL command
5161
+ * Description of the FORMAT command
5158
5162
  */
5159
- description: "Tells which model and modelRequirements to use for the prompt template execution",
5163
+ 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 "),
5160
5164
  /**
5161
5165
  * Link to discussion
5162
5166
  */
5163
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5167
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
5164
5168
  /**
5165
- * Example usages of the MODEL command
5169
+ * Example usages of the FORMAT command
5166
5170
  */
5167
- examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5171
+ examples: ['FORMAT JSON'],
5168
5172
  /**
5169
- * Parses the MODEL command
5173
+ * Parses the FORMAT command
5170
5174
  */
5171
5175
  parse: function (input) {
5172
- var args = input.args, normalized = input.normalized;
5176
+ var normalized = input.normalized;
5177
+ if (!normalized.startsWith('FORMAT_JSON')) {
5178
+ throw new ParseError("For now only JSON format is supported, in future we will support more formats");
5179
+ }
5180
+ return {
5181
+ type: 'FORMAT',
5182
+ format: 'JSON',
5183
+ };
5184
+ // <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
5185
+ // [🥤]
5186
+ },
5187
+ /**
5188
+ * Apply the FORMAT command to the `pipelineJson`
5189
+ *
5190
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5191
+ */
5192
+ $applyToTemplateJson: function (command, $templateJson) {
5193
+ if ($templateJson.format !== undefined && command.format !== $templateJson.format) {
5194
+ throw new ParseError("Format format is already defined to \"".concat($templateJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
5195
+ }
5196
+ $templateJson.format = command.format;
5197
+ },
5198
+ /**
5199
+ * Converts the FORMAT command back to string
5200
+ *
5201
+ * Note: This is used in `pipelineJsonToString` utility
5202
+ */
5203
+ stringify: function (command) {
5204
+ keepUnused(command);
5205
+ return "!!!!!!";
5206
+ },
5207
+ /**
5208
+ * Reads the FORMAT command from the `TemplateJson`
5209
+ *
5210
+ * Note: This is used in `pipelineJsonToString` utility
5211
+ */
5212
+ takeFromTemplateJson: function ($templateJson) {
5213
+ keepUnused($templateJson);
5214
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5215
+ },
5216
+ };
5217
+
5218
+ /**
5219
+ * Parses the joker command
5220
+ *
5221
+ * @see ./JOKER-README.md for more details
5222
+ * @private within the commands folder
5223
+ */
5224
+ var jokerCommandParser = {
5225
+ /**
5226
+ * Name of the command
5227
+ */
5228
+ name: 'JOKER',
5229
+ /**
5230
+ * BOILERPLATE command can be used in:
5231
+ */
5232
+ isUsedInPipelineHead: false,
5233
+ isUsedInPipelineTemplate: true,
5234
+ /**
5235
+ * Description of the JOKER command
5236
+ */
5237
+ description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
5238
+ /**
5239
+ * Link to discussion
5240
+ */
5241
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
5242
+ /**
5243
+ * Example usages of the JOKER command
5244
+ */
5245
+ examples: ['JOKER {documentTitle}'],
5246
+ /**
5247
+ * Parses the JOKER command
5248
+ */
5249
+ parse: function (input) {
5250
+ var args = input.args;
5251
+ var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
5252
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5253
+ throw new ParseError("Invalid joker");
5254
+ }
5255
+ var parameterName = parametersMatch.groups.parameterName;
5256
+ return {
5257
+ type: 'JOKER',
5258
+ parameterName: parameterName,
5259
+ };
5260
+ },
5261
+ /**
5262
+ * Apply the JOKER command to the `pipelineJson`
5263
+ *
5264
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5265
+ */
5266
+ $applyToTemplateJson: function (command, $templateJson) {
5267
+ $templateJson.jokerParameterNames = $templateJson.jokerParameterNames || [];
5268
+ $templateJson.jokerParameterNames.push(command.parameterName);
5269
+ },
5270
+ /**
5271
+ * Converts the JOKER command back to string
5272
+ *
5273
+ * Note: This is used in `pipelineJsonToString` utility
5274
+ */
5275
+ stringify: function (command) {
5276
+ keepUnused(command);
5277
+ return "!!!!!!";
5278
+ },
5279
+ /**
5280
+ * Reads the JOKER command from the `TemplateJson`
5281
+ *
5282
+ * Note: This is used in `pipelineJsonToString` utility
5283
+ */
5284
+ takeFromTemplateJson: function ($templateJson) {
5285
+ keepUnused($templateJson);
5286
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5287
+ },
5288
+ };
5289
+
5290
+ /**
5291
+ * @@@
5292
+ *
5293
+ * @public exported from `@promptbook/core`
5294
+ */
5295
+ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
5296
+
5297
+ /**
5298
+ * Parses the model command
5299
+ *
5300
+ * @see ./MODEL-README.md for more details
5301
+ * @private within the commands folder
5302
+ */
5303
+ var modelCommandParser = {
5304
+ /**
5305
+ * Name of the command
5306
+ */
5307
+ name: 'MODEL',
5308
+ /**
5309
+ * BOILERPLATE command can be used in:
5310
+ */
5311
+ isUsedInPipelineHead: true,
5312
+ isUsedInPipelineTemplate: true,
5313
+ /**
5314
+ * Description of the MODEL command
5315
+ */
5316
+ description: "Tells which model and modelRequirements to use for the prompt template execution",
5317
+ /**
5318
+ * Link to discussion
5319
+ */
5320
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
5321
+ /**
5322
+ * Example usages of the MODEL command
5323
+ */
5324
+ examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
5325
+ /**
5326
+ * Parses the MODEL command
5327
+ */
5328
+ parse: function (input) {
5329
+ var args = input.args, normalized = input.normalized;
5173
5330
  // TODO: Make this more elegant and dynamically
5174
5331
  if (normalized.startsWith('MODEL_VARIANT')) {
5175
5332
  if (normalized === 'MODEL_VARIANT_CHAT') {
@@ -5195,7 +5352,7 @@
5195
5352
  // <- Note: [🤖]
5196
5353
  }
5197
5354
  else {
5198
- 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 "); }));
5355
+ 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 "); }));
5199
5356
  }
5200
5357
  }
5201
5358
  if (normalized.startsWith('MODEL_NAME')) {
@@ -5206,9 +5363,60 @@
5206
5363
  };
5207
5364
  }
5208
5365
  else {
5209
- 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 "); }));
5366
+ 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 "); }));
5210
5367
  }
5211
5368
  },
5369
+ /**
5370
+ * Apply the MODEL command to the `pipelineJson`
5371
+ *
5372
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5373
+ */
5374
+ $applyToPipelineJson: function (command, $pipelineJson) {
5375
+ // TODO: !!!!!! Error on redefine
5376
+ $pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
5377
+ $pipelineJson.defaultModelRequirements[command.key] = command.value;
5378
+ },
5379
+ /**
5380
+ * Apply the MODEL command to the `pipelineJson`
5381
+ *
5382
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5383
+ */
5384
+ $applyToTemplateJson: function (command, $templateJson) {
5385
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5386
+ throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
5387
+ }
5388
+ // TODO: !!!!!! Error on redefine
5389
+ // TODO: Warn if setting same as default in `$pipelineJson`
5390
+ $templateJson.modelRequirements = $templateJson.modelRequirements || {};
5391
+ $templateJson.modelRequirements[command.key] = command.value;
5392
+ },
5393
+ /**
5394
+ * Converts the MODEL command back to string
5395
+ *
5396
+ * Note: This is used in `pipelineJsonToString` utility
5397
+ */
5398
+ stringify: function (command) {
5399
+ keepUnused(command);
5400
+ return "!!!!!!";
5401
+ },
5402
+ /**
5403
+ * Reads the MODEL command from the `PipelineJson`
5404
+ *
5405
+ * Note: This is used in `pipelineJsonToString` utility
5406
+ */
5407
+ takeFromPipelineJson: function (pipelineJson) {
5408
+ keepUnused(pipelineJson);
5409
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5410
+ },
5411
+ /**
5412
+ * Reads the MODEL command from the `TemplateJson`
5413
+ *
5414
+ * Note: This is used in `pipelineJsonToString` utility
5415
+ */
5416
+ takeFromTemplateJson: function ($templateJson) {
5417
+ keepUnused($templateJson);
5418
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5419
+ },
5212
5420
  };
5213
5421
 
5214
5422
  /**
@@ -5232,7 +5440,8 @@
5232
5440
  /**
5233
5441
  * BOILERPLATE command can be used in:
5234
5442
  */
5235
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
5443
+ isUsedInPipelineHead: true,
5444
+ isUsedInPipelineTemplate: true,
5236
5445
  /**
5237
5446
  * Description of the PARAMETER command
5238
5447
  */
@@ -5252,11 +5461,11 @@
5252
5461
  var normalized = input.normalized, raw = input.raw;
5253
5462
  var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
5254
5463
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
5255
- throw new ParsingError("Invalid parameter");
5464
+ throw new ParseError("Invalid parameter");
5256
5465
  }
5257
5466
  var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
5258
5467
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
5259
- throw new ParsingError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5468
+ throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
5260
5469
  }
5261
5470
  var isInput = normalized.startsWith('INPUT');
5262
5471
  var isOutput = normalized.startsWith('OUTPUT');
@@ -5272,8 +5481,177 @@
5272
5481
  isOutput: isOutput,
5273
5482
  };
5274
5483
  },
5484
+ /**
5485
+ * Apply the PARAMETER command to the `pipelineJson`
5486
+ *
5487
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5488
+ */
5489
+ $applyToPipelineJson: function (command, $pipelineJson) {
5490
+ keepUnused(command, $pipelineJson);
5491
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5492
+ },
5493
+ /**
5494
+ * Apply the PARAMETER command to the `pipelineJson`
5495
+ *
5496
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5497
+ */
5498
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5499
+ keepUnused(command, $templateJson, $pipelineJson);
5500
+ // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
5501
+ },
5502
+ /**
5503
+ * Converts the PARAMETER command back to string
5504
+ *
5505
+ * Note: This is used in `pipelineJsonToString` utility
5506
+ */
5507
+ stringify: function (command) {
5508
+ keepUnused(command);
5509
+ return "!!!!!!";
5510
+ },
5511
+ /**
5512
+ * Reads the PARAMETER command from the `PipelineJson`
5513
+ *
5514
+ * Note: This is used in `pipelineJsonToString` utility
5515
+ */
5516
+ takeFromPipelineJson: function (pipelineJson) {
5517
+ keepUnused(pipelineJson);
5518
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5519
+ },
5520
+ /**
5521
+ * Reads the PARAMETER command from the `TemplateJson`
5522
+ *
5523
+ * Note: This is used in `pipelineJsonToString` utility
5524
+ */
5525
+ takeFromTemplateJson: function ($templateJson) {
5526
+ keepUnused($templateJson);
5527
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5528
+ },
5275
5529
  };
5276
5530
 
5531
+ /**
5532
+ * Parses the persona command
5533
+ *
5534
+ * @see ./PERSONA-README.md for more details
5535
+ * @private within the commands folder
5536
+ */
5537
+ var personaCommandParser = {
5538
+ /**
5539
+ * Name of the command
5540
+ */
5541
+ name: 'PERSONA',
5542
+ /**
5543
+ * Aliases for the PERSONA command
5544
+ */
5545
+ aliasNames: ['PERSON'],
5546
+ /**
5547
+ * PERSONA command can be used in:
5548
+ */
5549
+ isUsedInPipelineHead: true,
5550
+ isUsedInPipelineTemplate: true,
5551
+ /**
5552
+ * Description of the PERSONA command
5553
+ */
5554
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
5555
+ /**
5556
+ * Link to discussion
5557
+ */
5558
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
5559
+ /**
5560
+ * Example usages of the PERSONA command
5561
+ */
5562
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
5563
+ /**
5564
+ * Parses the PERSONA command
5565
+ */
5566
+ parse: function (input) {
5567
+ var rawArgs = input.rawArgs;
5568
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
5569
+ var personaName = (personaNameRaw || '').trim();
5570
+ if (personaName === '') {
5571
+ throw new ParseError("You must set name for the persona");
5572
+ }
5573
+ var personaDescription = (personaDescriptionRaw || '').trim();
5574
+ if (personaDescription === '') {
5575
+ personaDescription = null;
5576
+ }
5577
+ return {
5578
+ type: 'PERSONA',
5579
+ personaName: personaName,
5580
+ personaDescription: personaDescription,
5581
+ };
5582
+ },
5583
+ /**
5584
+ * Apply the PERSONA command to the `pipelineJson`
5585
+ *
5586
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5587
+ */
5588
+ $applyToPipelineJson: function (command, $pipelineJson) {
5589
+ $applyToTemplateJson(command, null, $pipelineJson);
5590
+ },
5591
+ $applyToTemplateJson: $applyToTemplateJson,
5592
+ /**
5593
+ * Converts the PERSONA command back to string
5594
+ *
5595
+ * Note: This is used in `pipelineJsonToString` utility
5596
+ */
5597
+ stringify: function (command) {
5598
+ keepUnused(command);
5599
+ return "!!!!!!";
5600
+ },
5601
+ /**
5602
+ * Reads the PERSONA command from the `PipelineJson`
5603
+ *
5604
+ * Note: This is used in `pipelineJsonToString` utility
5605
+ */
5606
+ takeFromPipelineJson: function (pipelineJson) {
5607
+ keepUnused(pipelineJson);
5608
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5609
+ },
5610
+ /**
5611
+ * Reads the PERSONA command from the `TemplateJson`
5612
+ *
5613
+ * Note: This is used in `pipelineJsonToString` utility
5614
+ */
5615
+ takeFromTemplateJson: function ($templateJson) {
5616
+ keepUnused($templateJson);
5617
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5618
+ },
5619
+ };
5620
+ /**
5621
+ * Apply the PERSONA command to the `pipelineJson`
5622
+ *
5623
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5624
+ */
5625
+ function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
5626
+ var personaName = command.personaName, personaDescription = command.personaDescription;
5627
+ if ($templateJson !== null) {
5628
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
5629
+ throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
5630
+ }
5631
+ $templateJson.personaName = personaName;
5632
+ }
5633
+ var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
5634
+ if (persona === undefined) {
5635
+ $pipelineJson.personas.push({
5636
+ name: personaName,
5637
+ description: personaDescription || '',
5638
+ });
5639
+ return;
5640
+ }
5641
+ if (persona.description === personaDescription) {
5642
+ return;
5643
+ }
5644
+ if (personaDescription === null) {
5645
+ return;
5646
+ }
5647
+ if (persona.description === '') {
5648
+ persona.description = personaDescription;
5649
+ return;
5650
+ }
5651
+ 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 ")));
5652
+ persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
5653
+ }
5654
+
5277
5655
  /**
5278
5656
  * @@@
5279
5657
  *
@@ -5303,7 +5681,8 @@
5303
5681
  /**
5304
5682
  * BOILERPLATE command can be used in:
5305
5683
  */
5306
- usagePlaces: ['PIPELINE_TEMPLATE'],
5684
+ isUsedInPipelineHead: false,
5685
+ isUsedInPipelineTemplate: true,
5307
5686
  /**
5308
5687
  * Description of the POSTPROCESS command
5309
5688
  */
@@ -5325,19 +5704,46 @@
5325
5704
  var args = input.args;
5326
5705
  var functionName = args.pop();
5327
5706
  if (functionName === undefined) {
5328
- throw new ParsingError("Postprocess function name is required");
5707
+ throw new ParseError("Postprocess function name is required");
5329
5708
  }
5330
5709
  if (!isValidJavascriptName(functionName)) {
5331
- throw new ParsingError("Invalid postprocess function name \"".concat(functionName, "\""));
5710
+ throw new ParseError("Invalid postprocess function name \"".concat(functionName, "\""));
5332
5711
  }
5333
5712
  if (args.length > 0) {
5334
- throw new ParsingError("Can not have more than one postprocess function");
5713
+ throw new ParseError("Can not have more than one postprocess function");
5335
5714
  }
5336
5715
  return {
5337
5716
  type: 'POSTPROCESS',
5338
5717
  functionName: functionName,
5339
5718
  };
5340
5719
  },
5720
+ /**
5721
+ * Apply the POSTPROCESS command to the `pipelineJson`
5722
+ *
5723
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
5724
+ */
5725
+ $applyToTemplateJson: function (command, $templateJson) {
5726
+ $templateJson.postprocessingFunctionNames = $templateJson.postprocessingFunctionNames || [];
5727
+ $templateJson.postprocessingFunctionNames.push(command.functionName);
5728
+ },
5729
+ /**
5730
+ * Converts the POSTPROCESS command back to string
5731
+ *
5732
+ * Note: This is used in `pipelineJsonToString` utility
5733
+ */
5734
+ stringify: function (command) {
5735
+ keepUnused(command);
5736
+ return "!!!!!!";
5737
+ },
5738
+ /**
5739
+ * Reads the POSTPROCESS command from the `TemplateJson`
5740
+ *
5741
+ * Note: This is used in `pipelineJsonToString` utility
5742
+ */
5743
+ takeFromTemplateJson: function ($templateJson) {
5744
+ keepUnused($templateJson);
5745
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5746
+ },
5341
5747
  };
5342
5748
 
5343
5749
  /**
@@ -5355,7 +5761,8 @@
5355
5761
  /**
5356
5762
  * BOILERPLATE command can be used in:
5357
5763
  */
5358
- usagePlaces: ['PIPELINE_HEAD'],
5764
+ isUsedInPipelineHead: true,
5765
+ isUsedInPipelineTemplate: false,
5359
5766
  /**
5360
5767
  * Description of the PROMPTBOOK_VERSION command
5361
5768
  */
@@ -5375,19 +5782,45 @@
5375
5782
  var args = input.args;
5376
5783
  var promptbookVersion = args.pop();
5377
5784
  if (promptbookVersion === undefined) {
5378
- throw new ParsingError("Version is required");
5785
+ throw new ParseError("Version is required");
5379
5786
  }
5380
5787
  if (!isValidPromptbookVersion(promptbookVersion)) {
5381
- throw new ParsingError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5788
+ throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
5382
5789
  }
5383
5790
  if (args.length > 0) {
5384
- throw new ParsingError("Can not have more than one Promptbook version");
5791
+ throw new ParseError("Can not have more than one Promptbook version");
5385
5792
  }
5386
5793
  return {
5387
5794
  type: 'PROMPTBOOK_VERSION',
5388
5795
  promptbookVersion: promptbookVersion,
5389
5796
  };
5390
5797
  },
5798
+ /**
5799
+ * Apply the PROMPTBOOK_VERSION command to the `pipelineJson`
5800
+ *
5801
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5802
+ */
5803
+ $applyToPipelineJson: function (command, $pipelineJson) {
5804
+ $pipelineJson.promptbookVersion = command.promptbookVersion;
5805
+ },
5806
+ /**
5807
+ * Converts the PROMPTBOOK_VERSION command back to string
5808
+ *
5809
+ * Note: This is used in `pipelineJsonToString` utility
5810
+ */
5811
+ stringify: function (command) {
5812
+ keepUnused(command);
5813
+ return "!!!!!!";
5814
+ },
5815
+ /**
5816
+ * Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
5817
+ *
5818
+ * Note: This is used in `pipelineJsonToString` utility
5819
+ */
5820
+ takeFromPipelineJson: function (pipelineJson) {
5821
+ keepUnused(pipelineJson);
5822
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5823
+ },
5391
5824
  };
5392
5825
 
5393
5826
  /**
@@ -5409,7 +5842,8 @@
5409
5842
  /**
5410
5843
  * BOILERPLATE command can be used in:
5411
5844
  */
5412
- usagePlaces: ['PIPELINE_HEAD'],
5845
+ isUsedInPipelineHead: true,
5846
+ isUsedInPipelineTemplate: false,
5413
5847
  /**
5414
5848
  * Description of the URL command
5415
5849
  */
@@ -5433,23 +5867,23 @@
5433
5867
  var args = input.args;
5434
5868
  var pipelineUrl = args.pop();
5435
5869
  if (pipelineUrl === undefined) {
5436
- throw new ParsingError("URL is required");
5870
+ throw new ParseError("URL is required");
5437
5871
  }
5438
5872
  // TODO: [🧠][🚲] This should be maybe tested as logic not syntax
5439
5873
  if (!isValidPipelineUrl(pipelineUrl)) {
5440
- throw new ParsingError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
5874
+ throw new ParseError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
5441
5875
  }
5442
5876
  if (args.length > 0) {
5443
- throw new ParsingError("Can not have more than one pipeline URL");
5877
+ throw new ParseError("Can not have more than one pipeline URL");
5444
5878
  }
5445
5879
  /*
5446
5880
  TODO: [🐠 Maybe more info from `isValidPipelineUrl`:
5447
5881
  if (pipelineUrl.protocol !== 'https:') {
5448
- throw new ParsingError(`Protocol must be HTTPS`);
5882
+ throw new ParseError(`Protocol must be HTTPS`);
5449
5883
  }
5450
5884
 
5451
5885
  if (pipelineUrl.hash !== '') {
5452
- throw new ParsingError(
5886
+ throw new ParseError(
5453
5887
  spaceTrim(
5454
5888
  `
5455
5889
  URL must not contain hash
@@ -5464,6 +5898,32 @@
5464
5898
  pipelineUrl: new URL(pipelineUrl),
5465
5899
  };
5466
5900
  },
5901
+ /**
5902
+ * Apply the URL command to the `pipelineJson`
5903
+ *
5904
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5905
+ */
5906
+ $applyToPipelineJson: function (command, $pipelineJson) {
5907
+ $pipelineJson.pipelineUrl = command.pipelineUrl.href;
5908
+ },
5909
+ /**
5910
+ * Converts the URL command back to string
5911
+ *
5912
+ * Note: This is used in `pipelineJsonToString` utility
5913
+ */
5914
+ stringify: function (command) {
5915
+ keepUnused(command);
5916
+ return "!!!!!!";
5917
+ },
5918
+ /**
5919
+ * Reads the URL command from the `PipelineJson`
5920
+ *
5921
+ * Note: This is used in `pipelineJsonToString` utility
5922
+ */
5923
+ takeFromPipelineJson: function (pipelineJson) {
5924
+ keepUnused(pipelineJson);
5925
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5926
+ },
5467
5927
  };
5468
5928
 
5469
5929
  /**
@@ -5480,7 +5940,8 @@
5480
5940
  /**
5481
5941
  * ACTION command can be used in:
5482
5942
  */
5483
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
5943
+ isUsedInPipelineHead: true,
5944
+ isUsedInPipelineTemplate: false,
5484
5945
  /**
5485
5946
  * Description of the ACTION command
5486
5947
  */
@@ -5503,6 +5964,33 @@
5503
5964
  type: 'ACTION',
5504
5965
  };
5505
5966
  },
5967
+ /**
5968
+ * Apply the ACTION command to the `pipelineJson`
5969
+ *
5970
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
5971
+ */
5972
+ $applyToPipelineJson: function (command, $pipelineJson) {
5973
+ keepUnused(command, $pipelineJson);
5974
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
5975
+ },
5976
+ /**
5977
+ * Converts the ACTION command back to string
5978
+ *
5979
+ * Note: This is used in `pipelineJsonToString` utility
5980
+ */
5981
+ stringify: function (command) {
5982
+ keepUnused(command);
5983
+ return "!!!!!!";
5984
+ },
5985
+ /**
5986
+ * Reads the ACTION command from the `PipelineJson`
5987
+ *
5988
+ * Note: This is used in `pipelineJsonToString` utility
5989
+ */
5990
+ takeFromPipelineJson: function (pipelineJson) {
5991
+ keepUnused(pipelineJson);
5992
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
5993
+ },
5506
5994
  };
5507
5995
 
5508
5996
  /**
@@ -5519,7 +6007,8 @@
5519
6007
  /**
5520
6008
  * INSTRUMENT command can be used in:
5521
6009
  */
5522
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6010
+ isUsedInPipelineHead: true,
6011
+ isUsedInPipelineTemplate: false,
5523
6012
  /**
5524
6013
  * Description of the INSTRUMENT command
5525
6014
  */
@@ -5542,12 +6031,41 @@
5542
6031
  type: 'INSTRUMENT',
5543
6032
  };
5544
6033
  },
6034
+ /**
6035
+ * Apply the INSTRUMENT command to the `pipelineJson`
6036
+ *
6037
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6038
+ */
6039
+ $applyToPipelineJson: function (command, $pipelineJson) {
6040
+ keepUnused(command, $pipelineJson);
6041
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6042
+ },
6043
+ /**
6044
+ * Converts the INSTRUMENT command back to string
6045
+ *
6046
+ * Note: This is used in `pipelineJsonToString` utility
6047
+ */
6048
+ stringify: function (command) {
6049
+ keepUnused(command);
6050
+ return "!!!!!!";
6051
+ },
6052
+ /**
6053
+ * Reads the INSTRUMENT command from the `PipelineJson`
6054
+ *
6055
+ * Note: This is used in `pipelineJsonToString` utility
6056
+ */
6057
+ takeFromPipelineJson: function (pipelineJson) {
6058
+ keepUnused(pipelineJson);
6059
+ throw new NotYetImplementedError("Not implemented yet !!!!!!");
6060
+ },
5545
6061
  };
5546
6062
 
5547
6063
  /**
5548
6064
  * Parses the boilerplate command
5549
6065
  *
5550
- * @see ./BOILERPLATE-README.md for more details
6066
+ * Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
6067
+ *
6068
+ * @see ./BOILERPLATE-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
5551
6069
  * @private within the commands folder
5552
6070
  */
5553
6071
  var boilerplateCommandParser = {
@@ -5562,7 +6080,8 @@
5562
6080
  /**
5563
6081
  * BOILERPLATE command can be used in:
5564
6082
  */
5565
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
6083
+ isUsedInPipelineHead: true,
6084
+ isUsedInPipelineTemplate: true,
5566
6085
  /**
5567
6086
  * Description of the BOILERPLATE command
5568
6087
  */
@@ -5581,20 +6100,65 @@
5581
6100
  parse: function (input) {
5582
6101
  var args = input.args;
5583
6102
  if (args.length !== 1) {
5584
- throw new ParsingError("BOILERPLATE command requires exactly one argument");
6103
+ throw new ParseError("BOILERPLATE command requires exactly one argument");
5585
6104
  }
5586
6105
  var value = args[0].toLowerCase();
5587
6106
  if (value.includes('brr')) {
5588
- throw new ParsingError("BOILERPLATE value can not contain brr");
6107
+ throw new ParseError("BOILERPLATE value can not contain brr");
5589
6108
  }
5590
6109
  return {
5591
6110
  type: 'BOILERPLATE',
5592
6111
  value: value,
5593
6112
  };
5594
6113
  },
6114
+ /**
6115
+ * Apply the BOILERPLATE command to the `pipelineJson`
6116
+ *
6117
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6118
+ */
6119
+ $applyToPipelineJson: function (command, $pipelineJson) {
6120
+ keepUnused(command, $pipelineJson);
6121
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6122
+ },
6123
+ /**
6124
+ * Apply the BOILERPLATE command to the `pipelineJson`
6125
+ *
6126
+ * Note: `$` is used to indicate that this function mutates given `templateJson`
6127
+ */
6128
+ $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6129
+ keepUnused(command, $templateJson, $pipelineJson);
6130
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6131
+ },
6132
+ /**
6133
+ * Converts the BOILERPLATE command back to string
6134
+ *
6135
+ * Note: This is used in `pipelineJsonToString` utility
6136
+ */
6137
+ stringify: function (command) {
6138
+ keepUnused(command);
6139
+ return "!!!!!!";
6140
+ },
6141
+ /**
6142
+ * Reads the BOILERPLATE command from the `PipelineJson`
6143
+ *
6144
+ * Note: This is used in `pipelineJsonToString` utility
6145
+ */
6146
+ takeFromPipelineJson: function (pipelineJson) {
6147
+ keepUnused(pipelineJson);
6148
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6149
+ },
6150
+ /**
6151
+ * Reads the BOILERPLATE command from the `TemplateJson`
6152
+ *
6153
+ * Note: This is used in `pipelineJsonToString` utility
6154
+ */
6155
+ takeFromTemplateJson: function ($templateJson) {
6156
+ keepUnused($templateJson);
6157
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
6158
+ },
5595
6159
  };
5596
6160
  /**
5597
- * TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
6161
+ * TODO: !!!!!! Make .ptbk.md file with examples of the BOILERPLATE command and fail
5598
6162
  */
5599
6163
 
5600
6164
  /**
@@ -5605,6 +6169,7 @@
5605
6169
  var COMMANDS = [
5606
6170
  blockCommandParser,
5607
6171
  expectCommandParser,
6172
+ formatCommandParser,
5608
6173
  jokerCommandParser,
5609
6174
  modelCommandParser,
5610
6175
  parameterCommandParser,
@@ -5615,20 +6180,108 @@
5615
6180
  actionCommandParser,
5616
6181
  instrumentCommandParser,
5617
6182
  personaCommandParser,
6183
+ foreachCommandParser,
5618
6184
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
5619
6185
  ];
5620
6186
 
6187
+ /**
6188
+ * Removes Markdown formatting tags from a string.
6189
+ *
6190
+ * @param {string} str - The string to remove Markdown tags from.
6191
+ * @returns {string} The input string with all Markdown tags removed.
6192
+ * @public exported from `@promptbook/markdown-utils`
6193
+ */
6194
+ function removeMarkdownFormatting(str) {
6195
+ // Remove bold formatting
6196
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
6197
+ // Remove italic formatting
6198
+ str = str.replace(/\*(.*?)\*/g, '$1');
6199
+ // Remove code formatting
6200
+ str = str.replace(/`(.*?)`/g, '$1');
6201
+ return str;
6202
+ }
6203
+
6204
+ /**
6205
+ * @@@
6206
+ *
6207
+ * @param text @@@
6208
+ * @returns @@@
6209
+ * @example 'HELLO_WORLD'
6210
+ * @example 'I_LOVE_PROMPTBOOK'
6211
+ * @public exported from `@promptbook/utils`
6212
+ */
6213
+ function normalizeTo_SCREAMING_CASE(text) {
6214
+ var e_1, _a;
6215
+ var charType;
6216
+ var lastCharType = 'OTHER';
6217
+ var normalizedName = '';
6218
+ try {
6219
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
6220
+ var char = text_1_1.value;
6221
+ var normalizedChar = void 0;
6222
+ if (/^[a-z]$/.test(char)) {
6223
+ charType = 'LOWERCASE';
6224
+ normalizedChar = char.toUpperCase();
6225
+ }
6226
+ else if (/^[A-Z]$/.test(char)) {
6227
+ charType = 'UPPERCASE';
6228
+ normalizedChar = char;
6229
+ }
6230
+ else if (/^[0-9]$/.test(char)) {
6231
+ charType = 'NUMBER';
6232
+ normalizedChar = char;
6233
+ }
6234
+ else if (/^\/$/.test(char)) {
6235
+ charType = 'SLASH';
6236
+ normalizedChar = char;
6237
+ }
6238
+ else {
6239
+ charType = 'OTHER';
6240
+ normalizedChar = '_';
6241
+ }
6242
+ if (charType !== lastCharType &&
6243
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
6244
+ !(lastCharType === 'NUMBER') &&
6245
+ !(charType === 'NUMBER')) {
6246
+ normalizedName += '_';
6247
+ }
6248
+ normalizedName += normalizedChar;
6249
+ lastCharType = charType;
6250
+ }
6251
+ }
6252
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6253
+ finally {
6254
+ try {
6255
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
6256
+ }
6257
+ finally { if (e_1) throw e_1.error; }
6258
+ }
6259
+ normalizedName = normalizedName.replace(/_+/g, '_');
6260
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
6261
+ normalizedName = normalizedName.replace(/^_/, '');
6262
+ normalizedName = normalizedName.replace(/_$/, '');
6263
+ return normalizedName;
6264
+ }
6265
+ /**
6266
+ * TODO: Tests
6267
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
6268
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
6269
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
6270
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
6271
+ * TODO: [🌺] Use some intermediate util splitWords
6272
+ */
6273
+
5621
6274
  /**
5622
6275
  * Parses one line of ul/ol to command
5623
6276
  *
5624
6277
  * @returns parsed command object
5625
- * @throws {ParsingError} if the command is invalid
6278
+ * @throws {ParseError} if the command is invalid
5626
6279
  *
5627
6280
  * @private within the pipelineStringToJson
5628
6281
  */
5629
6282
  function parseCommand(raw, usagePlace) {
5630
6283
  if (raw.includes('\n') || raw.includes('\r')) {
5631
- throw new ParsingError('Command can not contain new line characters' /* <- TODO: [🚞] */);
6284
+ throw new ParseError('Command can not contain new line characters' /* <- TODO: [🚞] */);
5632
6285
  }
5633
6286
  var normalized = raw.trim();
5634
6287
  normalized = normalized.split('`').join('');
@@ -5665,7 +6318,7 @@
5665
6318
  .map(removeMarkdownFormatting)
5666
6319
  .map(function (item) { return item.trim(); });
5667
6320
  if (items.length === 0 || items[0] === '') {
5668
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6321
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5669
6322
  return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5670
6323
  }));
5671
6324
  }
@@ -5692,7 +6345,7 @@
5692
6345
  return command;
5693
6346
  }
5694
6347
  }
5695
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6348
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5696
6349
  return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5697
6350
  }));
5698
6351
  }
@@ -5702,6 +6355,7 @@
5702
6355
  function getSupportedCommandsMessage() {
5703
6356
  return COMMANDS.flatMap(function (_a) {
5704
6357
  var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
6358
+ // <- Note: [🦦] Its strange that this type assertion is needed
5705
6359
  return __spreadArray([
5706
6360
  "- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
5707
6361
  ], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
@@ -5715,27 +6369,34 @@
5715
6369
  var commandNameRaw = input.commandNameRaw, usagePlace = input.usagePlace, normalized = input.normalized, args = input.args, raw = input.raw, rawArgs = input.rawArgs;
5716
6370
  var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
5717
6371
  var _loop_1 = function (commandParser) {
5718
- var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6372
+ // <- Note: [🦦] Its strange that this type assertion is needed
6373
+ var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
6374
+ if (just(false)) {
6375
+ keepUnused( /* for better indentation */);
6376
+ }
6377
+ else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
6378
+ return "continue";
6379
+ }
6380
+ else if (usagePlace === 'PIPELINE_TEMPLATE' && !isUsedInPipelineTemplate) {
6381
+ return "continue";
6382
+ }
5719
6383
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
5720
6384
  if (names.includes(commandName)) {
5721
6385
  try {
5722
6386
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
5723
6387
  }
5724
6388
  catch (error) {
5725
- if (!(error instanceof ParsingError)) {
6389
+ if (!(error instanceof ParseError)) {
5726
6390
  throw error;
5727
6391
  }
5728
- throw new ParsingError(spaceTrim.spaceTrim(function (block) {
6392
+ throw new ParseError(spaceTrim.spaceTrim(function (block) {
5729
6393
  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 ");
5730
6394
  }));
5731
6395
  }
5732
6396
  }
5733
6397
  };
5734
6398
  try {
5735
- for (var _b = __values(COMMANDS.filter(function (_a) {
5736
- var places = _a.usagePlaces;
5737
- return places.includes(usagePlace);
5738
- })), _c = _b.next(); !_c.done; _c = _b.next()) {
6399
+ for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
5739
6400
  var commandParser = _c.value;
5740
6401
  var state_1 = _loop_1(commandParser);
5741
6402
  if (typeof state_1 === "object")
@@ -5802,7 +6463,7 @@
5802
6463
  /**
5803
6464
  * Extracts exactly ONE code block from markdown.
5804
6465
  *
5805
- * - When there are multiple or no code blocks the function throws a `ParsingError`
6466
+ * - When there are multiple or no code blocks the function throws a `ParseError`
5806
6467
  *
5807
6468
  * Note: There are multiple simmilar function:
5808
6469
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
@@ -5813,12 +6474,12 @@
5813
6474
  * @param markdown any valid markdown
5814
6475
  * @returns code block with language and content
5815
6476
  * @public exported from `@promptbook/markdown-utils`
5816
- * @throws {ParsingError} if there is not exactly one code block in the markdown
6477
+ * @throws {ParseError} if there is not exactly one code block in the markdown
5817
6478
  */
5818
6479
  function extractOneBlockFromMarkdown(markdown) {
5819
6480
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
5820
6481
  if (codeBlocks.length !== 1) {
5821
- 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 "); }));
6482
+ 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 "); }));
5822
6483
  }
5823
6484
  return codeBlocks[0];
5824
6485
  }
@@ -5835,13 +6496,13 @@
5835
6496
  var _a, _b;
5836
6497
  var lines = value.split('\n');
5837
6498
  if (!lines[0].startsWith('#')) {
5838
- throw new ParsingError('Markdown section must start with heading');
6499
+ throw new ParseError('Markdown section must start with heading');
5839
6500
  }
5840
6501
  var title = lines[0].replace(/^#+\s*/, '');
5841
6502
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
5842
6503
  var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
5843
6504
  if (level < 1 || level > 6) {
5844
- throw new ParsingError('Markdown section must have heading level between 1 and 6');
6505
+ throw new ParseError('Markdown section must have heading level between 1 and 6');
5845
6506
  }
5846
6507
  return { title: title, level: level, content: content };
5847
6508
  }
@@ -5997,31 +6658,32 @@
5997
6658
  *
5998
6659
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
5999
6660
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6000
- * @throws {ParsingError} if the promptbook string is not valid
6661
+ * @throws {ParseError} if the promptbook string is not valid
6001
6662
  * @public exported from `@promptbook/core`
6002
6663
  */
6003
6664
  function pipelineStringToJsonSync(pipelineString) {
6004
6665
  var e_1, _a, e_2, _b;
6005
- var pipelineJson = {
6006
- title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
6666
+ var $pipelineJson = {
6667
+ title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
6007
6668
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
6008
6669
  promptbookVersion: PROMPTBOOK_VERSION,
6009
- description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
6670
+ description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
6010
6671
  parameters: [],
6011
- promptTemplates: [],
6672
+ templates: [],
6012
6673
  knowledgeSources: [],
6013
6674
  knowledgePieces: [],
6014
6675
  personas: [],
6015
6676
  preparations: [],
6677
+ // <- TODO: [🍙] Some standard order of properties
6016
6678
  };
6017
6679
  function getPipelineIdentification() {
6018
6680
  // Note: This is a 😐 implementation of [🚞]
6019
6681
  var _ = [];
6020
- if (pipelineJson.sourceFile !== undefined) {
6021
- _.push("File: ".concat(pipelineJson.sourceFile));
6682
+ if ($pipelineJson.sourceFile !== undefined) {
6683
+ _.push("File: ".concat($pipelineJson.sourceFile));
6022
6684
  }
6023
- if (pipelineJson.pipelineUrl !== undefined) {
6024
- _.push("Url: ".concat(pipelineJson.pipelineUrl));
6685
+ if ($pipelineJson.pipelineUrl !== undefined) {
6686
+ _.push("Url: ".concat($pipelineJson.pipelineUrl));
6025
6687
  }
6026
6688
  return _.join('\n');
6027
6689
  }
@@ -6046,14 +6708,14 @@
6046
6708
  var defineParam = function (parameterCommand) {
6047
6709
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
6048
6710
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
6049
- 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: [🚞] */);
6711
+ 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: [🚞] */);
6050
6712
  }
6051
- var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6713
+ var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
6052
6714
  if (existingParameter &&
6053
6715
  existingParameter.description &&
6054
6716
  existingParameter.description !== parameterDescription &&
6055
6717
  parameterDescription) {
6056
- 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 "); }));
6718
+ 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 "); }));
6057
6719
  }
6058
6720
  if (existingParameter) {
6059
6721
  if (parameterDescription) {
@@ -6061,7 +6723,7 @@
6061
6723
  }
6062
6724
  }
6063
6725
  else {
6064
- pipelineJson.parameters.push({
6726
+ $pipelineJson.parameters.push({
6065
6727
  name: parameterName,
6066
6728
  description: parameterDescription || undefined,
6067
6729
  isInput: isInput,
@@ -6071,7 +6733,7 @@
6071
6733
  };
6072
6734
  // =============================================================
6073
6735
  // Note: 3️⃣ Process pipeline head
6074
- pipelineJson.title = pipelineHead.title;
6736
+ $pipelineJson.title = pipelineHead.title;
6075
6737
  // TODO: [🎾][1] DRY description
6076
6738
  var description = pipelineHead.content;
6077
6739
  // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
@@ -6083,43 +6745,31 @@
6083
6745
  if (description === '') {
6084
6746
  description = undefined;
6085
6747
  }
6086
- pipelineJson.description = description;
6087
- var defaultModelRequirements = {};
6748
+ $pipelineJson.description = description;
6088
6749
  var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
6089
6750
  var _loop_1 = function (listItem) {
6751
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineHeadCommands`
6090
6752
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
6091
- switch (command.type) {
6092
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6093
- case 'MODEL':
6094
- defaultModelRequirements[command.key] = command.value;
6095
- break;
6096
- case 'PARAMETER':
6097
- defineParam(command);
6098
- break;
6099
- case 'PROMPTBOOK_VERSION':
6100
- pipelineJson.promptbookVersion = command.promptbookVersion;
6101
- break;
6102
- case 'URL':
6103
- pipelineJson.pipelineUrl = command.pipelineUrl.href;
6104
- break;
6105
- case 'KNOWLEDGE':
6106
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6107
- break;
6108
- case 'ACTION':
6109
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6110
- break;
6111
- case 'INSTRUMENT':
6112
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6113
- break;
6114
- case 'PERSONA':
6115
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6116
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6117
- break;
6118
- case 'BOILERPLATE':
6119
- 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: [🚞]
6120
- // <- [💐]
6121
- default:
6122
- 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: [🚞]
6753
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6754
+ if (commandParser === undefined) {
6755
+ 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 "); }));
6756
+ }
6757
+ if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
6758
+ 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: [🚞]
6759
+ }
6760
+ try {
6761
+ commandParser.$applyToPipelineJson(command, $pipelineJson);
6762
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6763
+ }
6764
+ catch (error) {
6765
+ if (!(error instanceof ParseError)) {
6766
+ throw error;
6767
+ }
6768
+ 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: [🚞]
6769
+ }
6770
+ if (command.type === 'PARAMETER') {
6771
+ defineParam(command);
6772
+ // <- Note: [🍣]
6123
6773
  }
6124
6774
  };
6125
6775
  try {
@@ -6138,27 +6788,7 @@
6138
6788
  var _loop_2 = function (section) {
6139
6789
  var e_3, _d;
6140
6790
  // TODO: Parse prompt template description (the content out of the codeblock and lists)
6141
- var templateModelRequirements = __assign({}, defaultModelRequirements);
6142
- var listItems_3 = extractAllListItemsFromMarkdown(section.content);
6143
- var lastLine = section.content.split('\n').pop();
6144
- var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6145
- var resultingParameterName = null;
6146
- if (resultingParameterNameMatch &&
6147
- resultingParameterNameMatch.groups !== undefined &&
6148
- resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6149
- resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6150
- }
6151
- var expectResultingParameterName = function () {
6152
- if (resultingParameterName !== null) {
6153
- return resultingParameterName;
6154
- }
6155
- 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(
6156
- // TODO: Show code of invalid sections each time + DRY
6157
- section.content
6158
- .split('\n')
6159
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
6160
- .join('\n')), "\n "); }));
6161
- };
6791
+ var listItems_2 = extractAllListItemsFromMarkdown(section.content);
6162
6792
  var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
6163
6793
  // TODO: [🎾][1] DRY description
6164
6794
  var description_1 = section.content;
@@ -6171,176 +6801,121 @@
6171
6801
  if (description_1 === '') {
6172
6802
  description_1 = undefined;
6173
6803
  }
6174
- var templateJson = {
6175
- blockType: 'PROMPT_TEMPLATE',
6804
+ var $templateJson = {
6805
+ isBlockTypeSet: false,
6806
+ isTemplateBlock: true,
6807
+ blockType: undefined /* <- Note: [🍙] Putting here placeholder to keep `blockType` on top at final JSON */,
6176
6808
  name: titleToName(section.title),
6177
6809
  title: section.title,
6178
6810
  description: description_1,
6179
- modelRequirements: templateModelRequirements,
6180
6811
  content: content,
6812
+ // <- TODO: [🍙] Some standard order of properties
6181
6813
  };
6182
- /**
6183
- * This is nessesary because block type can be
6184
- * - Set zero times, so anticipate 'PROMPT_TEMPLATE'
6185
- * - Set one time
6186
- * - Set more times - throw error
6187
- *
6188
- * Note: [2]
6189
- */
6190
- var isBlockTypeSet = false;
6191
- var _loop_3 = function (listItem) {
6192
- var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
6193
- // TODO [🍧][♓️] List commands and before apply order them
6194
- switch (command.type) {
6195
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6196
- case 'BLOCK':
6197
- if (isBlockTypeSet) {
6198
- 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 "); }));
6199
- }
6200
- if (command.blockType === 'SAMPLE') {
6201
- expectResultingParameterName();
6202
- var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
6203
- if (parameter === undefined) {
6204
- 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 "); }));
6205
- }
6206
- parameter.sampleValues = parameter.sampleValues || [];
6207
- parameter.sampleValues.push(content);
6208
- return "continue-templates";
6209
- }
6210
- if (command.blockType === 'KNOWLEDGE') {
6211
- knowledgeCommandParser.applyToPipelineJson({
6212
- type: 'KNOWLEDGE',
6213
- sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6214
- }, {
6215
- pipelineJson: pipelineJson,
6216
- templateJson: templateJson,
6217
- });
6218
- return "continue-templates";
6219
- }
6220
- if (command.blockType === 'ACTION') {
6221
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6222
- return "continue-templates";
6223
- }
6224
- if (command.blockType === 'INSTRUMENT') {
6225
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6226
- return "continue-templates";
6227
- }
6228
- expectResultingParameterName();
6229
- templateJson.blockType = command.blockType;
6230
- isBlockTypeSet = true; //<- Note: [2]
6231
- break;
6232
- case 'EXPECT_AMOUNT':
6233
- // eslint-disable-next-line no-case-declarations
6234
- var unit_1 = command.unit.toLowerCase();
6235
- templateJson.expectations = templateJson.expectations || {};
6236
- templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
6237
- if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6238
- if (templateJson.expectations[unit_1].min !== undefined) {
6239
- 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 "); }));
6240
- }
6241
- templateJson.expectations[unit_1].min = command.amount;
6242
- } /* not else */
6243
- if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6244
- if (templateJson.expectations[unit_1].max !== undefined) {
6245
- 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 "); }));
6246
- }
6247
- templateJson.expectations[unit_1].max = command.amount;
6248
- }
6249
- break;
6250
- case 'EXPECT_FORMAT':
6251
- if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
6252
- 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 "); }));
6253
- }
6254
- templateJson.expectFormat = command.format;
6255
- break;
6256
- case 'JOKER':
6257
- templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
6258
- templateJson.jokerParameterNames.push(command.parameterName);
6259
- break;
6260
- case 'MODEL':
6261
- templateModelRequirements[command.key] = command.value;
6262
- break;
6263
- case 'PARAMETER':
6264
- // Note: This is just for detecting resulitng parameter name
6265
- defineParam(command);
6266
- break;
6267
- case 'POSTPROCESS':
6268
- templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
6269
- templateJson.postprocessingFunctionNames.push(command.functionName);
6270
- break;
6271
- case 'KNOWLEDGE':
6272
- // TODO: [👙] The knowledge is maybe relevant for just this template
6273
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6274
- break;
6275
- case 'ACTION':
6276
- // TODO: [👙] The action is maybe relevant for just this template
6277
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6278
- break;
6279
- case 'INSTRUMENT':
6280
- // TODO: [👙] The instrument is maybe relevant for just this template
6281
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6282
- break;
6283
- case 'PERSONA':
6284
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6285
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6286
- break;
6287
- case 'BOILERPLATE':
6288
- 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 "); })));
6289
- break;
6290
- // <- [💐]
6291
- default:
6292
- 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 "); }));
6814
+ var lastLine = section.content.split('\n').pop();
6815
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
6816
+ if (resultingParameterNameMatch &&
6817
+ resultingParameterNameMatch.groups !== undefined &&
6818
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
6819
+ $templateJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
6820
+ }
6821
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTemplateCommands`
6822
+ var commands = listItems_2.map(function (listItem) { return ({
6823
+ listItem: listItem,
6824
+ command: parseCommand(listItem, 'PIPELINE_TEMPLATE'),
6825
+ }); });
6826
+ // Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
6827
+ if (commands.some(function (_a) {
6828
+ var command = _a.command;
6829
+ return command.type === 'BLOCK';
6830
+ }) === false) {
6831
+ blockCommandParser.$applyToTemplateJson({ type: 'BLOCK', blockType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
6832
+ }
6833
+ var _loop_3 = function (listItem, command) {
6834
+ var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
6835
+ if (commandParser === undefined) {
6836
+ 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 "); }));
6837
+ }
6838
+ if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
6839
+ 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: [🚞]
6840
+ }
6841
+ try {
6842
+ commandParser.$applyToTemplateJson(
6843
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
6844
+ command, $templateJson, $pipelineJson);
6845
+ }
6846
+ catch (error) {
6847
+ if (!(error instanceof ParseError)) {
6848
+ throw error;
6849
+ }
6850
+ 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: [🚞]
6851
+ }
6852
+ // TODO: !!!!!! Multiple problematic things in BLOCK command - blockCommandParser.$applyToTemplateJson
6853
+ if (command.type === 'PARAMETER') {
6854
+ defineParam(command);
6855
+ // <- Note: [🍣]
6293
6856
  }
6294
6857
  };
6295
6858
  try {
6296
- 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()) {
6297
- var listItem = listItems_2_1.value;
6298
- var state_2 = _loop_3(listItem);
6299
- switch (state_2) {
6300
- case "continue-templates": return state_2;
6301
- }
6859
+ // TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE BLOCK`
6860
+ // TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE BLOCK`
6861
+ // TODO [♓️] List commands and before apply order them
6862
+ 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()) {
6863
+ var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
6864
+ _loop_3(listItem, command);
6302
6865
  }
6303
6866
  }
6304
6867
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
6305
6868
  finally {
6306
6869
  try {
6307
- if (listItems_2_1 && !listItems_2_1.done && (_d = listItems_2.return)) _d.call(listItems_2);
6870
+ if (commands_1_1 && !commands_1_1.done && (_d = commands_1.return)) _d.call(commands_1);
6308
6871
  }
6309
6872
  finally { if (e_3) throw e_3.error; }
6310
6873
  }
6311
- // TODO: [🍧] Should be done in BLOCK command
6312
- if (templateJson.blockType === 'SCRIPT') {
6874
+ // TODO: [🍧] !!!!!! Should be done in BLOCK command
6875
+ if ($templateJson.blockType === 'SCRIPT_TEMPLATE') {
6313
6876
  if (!language) {
6314
- 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 "); }));
6877
+ 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 "); }));
6315
6878
  }
6316
6879
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
6317
- 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 "); }));
6880
+ 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 "); }));
6318
6881
  }
6319
- templateJson.contentLanguage = language;
6882
+ $templateJson.contentLanguage =
6883
+ language;
6320
6884
  }
6321
- // TODO: [🍧][❔] Should be done in BLOCK command
6322
- if (templateModelRequirements.modelVariant === undefined) {
6323
- templateModelRequirements.modelVariant = 'CHAT';
6885
+ $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
6886
+ /*
6887
+ // TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
6888
+ // TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
6889
+ // TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
6890
+ if ($templateJson.blockType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
6891
+ throw new UnexpectedError(
6892
+ spaceTrim(
6893
+ (block) => `
6894
+ Model requirements are defined for the block type ${
6895
+ $templateJson.blockType
6896
+ } which is not a prompt template
6897
+
6898
+ This should be avoided by the \`modelCommandParser\`
6899
+
6900
+ ${block(getPipelineIdentification())}
6901
+ `,
6902
+ ),
6903
+ );
6324
6904
  }
6325
- templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
6326
- // TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
6327
- if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
6328
- delete templateJson.modelRequirements;
6905
+ */
6906
+ if ($templateJson.isTemplateBlock) {
6907
+ delete $templateJson.isBlockTypeSet;
6908
+ delete $templateJson.isTemplateBlock;
6909
+ // TODO: [🍙] Maybe do reorder of `$templateJson` here
6910
+ $pipelineJson.templates.push($templateJson);
6329
6911
  }
6330
- // TODO: [🍧] Make this better - for example each command parser can call and apply this
6331
- templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
6332
- // TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
6333
- pipelineJson.promptTemplates.push(templateJson);
6334
6912
  };
6335
6913
  try {
6336
6914
  // =============================================================
6337
6915
  // Note: 4️⃣ Process each template of the pipeline
6338
- templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
6916
+ /* 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()) {
6339
6917
  var section = pipelineSections_1_1.value;
6340
- var state_1 = _loop_2(section);
6341
- switch (state_1) {
6342
- case "continue-templates": continue templates;
6343
- }
6918
+ _loop_2(section);
6344
6919
  }
6345
6920
  }
6346
6921
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -6352,13 +6927,13 @@
6352
6927
  }
6353
6928
  // =============================================================
6354
6929
  // Note: 5️⃣ Cleanup of undefined values
6355
- pipelineJson.promptTemplates.forEach(function (promptTemplates) {
6930
+ $pipelineJson.templates.forEach(function (templates) {
6356
6931
  var e_4, _a;
6357
6932
  try {
6358
- for (var _b = __values(Object.entries(promptTemplates)), _c = _b.next(); !_c.done; _c = _b.next()) {
6933
+ for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
6359
6934
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
6360
6935
  if (value === undefined) {
6361
- delete promptTemplates[key];
6936
+ delete templates[key];
6362
6937
  }
6363
6938
  }
6364
6939
  }
@@ -6370,7 +6945,7 @@
6370
6945
  finally { if (e_4) throw e_4.error; }
6371
6946
  }
6372
6947
  });
6373
- pipelineJson.parameters.forEach(function (parameter) {
6948
+ $pipelineJson.parameters.forEach(function (parameter) {
6374
6949
  var e_5, _a;
6375
6950
  try {
6376
6951
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -6389,7 +6964,8 @@
6389
6964
  }
6390
6965
  });
6391
6966
  // =============================================================
6392
- return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
6967
+ // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
6968
+ return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
6393
6969
  }
6394
6970
  /**
6395
6971
  * TODO: !!!! Warn if used only sync version
@@ -6399,7 +6975,7 @@
6399
6975
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
6400
6976
  * TODO: [♈] Probbably move expectations from templates to parameters
6401
6977
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
6402
- * TODO: [🍙] Make some standart order of json properties
6978
+ * TODO: [🍙] Make some standard order of json properties
6403
6979
  */
6404
6980
 
6405
6981
  /**
@@ -6416,7 +6992,7 @@
6416
6992
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
6417
6993
  * @param options - Options and tools for the compilation
6418
6994
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
6419
- * @throws {ParsingError} if the promptbook string is not valid
6995
+ * @throws {ParseError} if the promptbook string is not valid
6420
6996
  * @public exported from `@promptbook/core`
6421
6997
  */
6422
6998
  function pipelineStringToJson(pipelineString, options) {
@@ -6925,7 +7501,7 @@
6925
7501
  * TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
6926
7502
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
6927
7503
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
6928
- * TODO: [🍙] Make some standart order of json properties
7504
+ * TODO: [🍙] Make some standard order of json properties
6929
7505
  */
6930
7506
 
6931
7507
  /**
@@ -7760,8 +8336,8 @@
7760
8336
  }
7761
8337
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
7762
8338
  if (!placeForSection) {
7763
- throw new ParsingError(
7764
- // <- [🧠] Maybe something better tha `ParsingError`
8339
+ throw new ParseError(
8340
+ // <- [🧠] Maybe something better tha `ParseError`
7765
8341
  "No place where to put the section <!--".concat(sectionName, "-->"));
7766
8342
  // <- [🚞]
7767
8343
  }
@@ -7769,6 +8345,7 @@
7769
8345
  return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
7770
8346
  }
7771
8347
  /**
8348
+ * TODO: !!!!!! Somw way how to connect this with commands
7772
8349
  * TODO: [🏛] This can be part of markdown builder
7773
8350
  */
7774
8351
 
@@ -7844,7 +8421,7 @@
7844
8421
  * @public exported from `@promptbook/utils`
7845
8422
  */
7846
8423
  function renderPromptbookMermaid(pipelineJson, options) {
7847
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
8424
+ var _a = (options || {}).linkTemplate, linkTemplate = _a === void 0 ? function () { return null; } : _a;
7848
8425
  var parameterNameToTemplateName = function (parameterName) {
7849
8426
  var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
7850
8427
  if (!parameter) {
@@ -7853,13 +8430,13 @@
7853
8430
  if (parameter.isInput) {
7854
8431
  return 'input';
7855
8432
  }
7856
- var template = pipelineJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
8433
+ var template = pipelineJson.templates.find(function (template) { return template.resultingParameterName === parameterName; });
7857
8434
  if (!template) {
7858
8435
  throw new Error("Could not find template for {".concat(parameterName, "}"));
7859
8436
  }
7860
8437
  return normalizeTo_camelCase('template-' + titleToName(template.title));
7861
8438
  };
7862
- 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
8439
+ 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
7863
8440
  .flatMap(function (_a) {
7864
8441
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
7865
8442
  return __spreadArray([
@@ -7877,14 +8454,14 @@
7877
8454
  var name = _a.name;
7878
8455
  return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
7879
8456
  })
7880
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.promptTemplates
7881
- .map(function (promptTemplate) {
7882
- var link = linkPromptTemplate(promptTemplate);
8457
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.templates
8458
+ .map(function (template) {
8459
+ var link = linkTemplate(template);
7883
8460
  if (link === null) {
7884
8461
  return '';
7885
8462
  }
7886
8463
  var href = link.href, title = link.title;
7887
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
8464
+ var templateName = parameterNameToTemplateName(template.resultingParameterName);
7888
8465
  return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
7889
8466
  })
7890
8467
  .filter(function (line) { return line !== ''; })
@@ -7913,8 +8490,8 @@
7913
8490
  case 1:
7914
8491
  pipelineJson = _a.sent();
7915
8492
  promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
7916
- linkPromptTemplate: function (promptTemplate) {
7917
- return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
8493
+ linkTemplate: function (template) {
8494
+ return { href: "#".concat(template.name), title: template.title };
7918
8495
  },
7919
8496
  });
7920
8497
  promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
@@ -9661,14 +10238,14 @@
9661
10238
  */
9662
10239
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
9663
10240
  return __awaiter(this, void 0, void 0, function () {
9664
- var content, parameters, modelRequirements, expectFormat, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
10241
+ var content, parameters, modelRequirements, format, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
9665
10242
  return __generator(this, function (_a) {
9666
10243
  switch (_a.label) {
9667
10244
  case 0:
9668
10245
  if (this.options.isVerbose) {
9669
10246
  console.info('💬 OpenAI callChatModel call', { prompt: prompt });
9670
10247
  }
9671
- content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
10248
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, format = prompt.format;
9672
10249
  return [4 /*yield*/, this.getClient()];
9673
10250
  case 1:
9674
10251
  client = _a.sent();
@@ -9685,7 +10262,7 @@
9685
10262
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
9686
10263
  // <- Note: [🧆]
9687
10264
  };
9688
- if (expectFormat === 'JSON') {
10265
+ if (format === 'JSON') {
9689
10266
  modelSettings.response_format = {
9690
10267
  type: 'json_object',
9691
10268
  };