@promptbook/pdf 0.74.0-8 → 0.75.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 (57) hide show
  1. package/README.md +2 -11
  2. package/esm/index.es.js +92 -52
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +3 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +25 -1
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
  9. package/esm/typings/src/cli/main.d.ts +4 -1
  10. package/esm/typings/src/cli/promptbookCli.d.ts +1 -1
  11. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  12. package/esm/typings/src/collection/collectionToJson.test.d.ts +1 -1
  13. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
  14. package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +1 -1
  15. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
  16. package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +11 -0
  17. package/esm/typings/src/commands/FORMFACTOR/formfactorCommand.test.d.ts +1 -0
  18. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +11 -0
  19. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  20. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +2 -0
  21. package/esm/typings/src/commands/index.d.ts +1 -1
  22. package/esm/typings/src/config.d.ts +7 -0
  23. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +3 -3
  24. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
  25. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -2
  26. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
  27. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +7 -7
  28. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  29. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +1 -1
  30. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +14 -0
  31. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +34 -0
  32. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +5 -0
  33. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +5 -0
  34. package/esm/typings/src/formfactors/chat/ChatFormfactorDefinition.d.ts +15 -0
  35. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +14 -0
  36. package/esm/typings/src/formfactors/index.d.ts +39 -0
  37. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +14 -0
  38. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +14 -0
  39. package/esm/typings/src/pipeline/pipeline-interface/PipelineInterface.d.ts +22 -0
  40. package/esm/typings/src/pipeline/pipeline-interface/constants.d.ts +9 -0
  41. package/esm/typings/src/pipeline/pipeline-interface/getPipelineInterface.d.ts +11 -0
  42. package/esm/typings/src/pipeline/pipeline-interface/isPipelineImplementingInterface.d.ts +25 -0
  43. package/esm/typings/src/pipeline/pipeline-interface/isPipelineInterfacesEqual.d.ts +11 -0
  44. package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
  45. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +1 -1
  46. package/esm/typings/src/storage/{memory/utils → utils}/PrefixStorage.d.ts +1 -1
  47. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +11 -4
  48. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  49. package/esm/typings/src/types/Prompt.d.ts +1 -1
  50. package/esm/typings/src/types/typeAliases.d.ts +2 -2
  51. package/esm/typings/src/utils/expectation-counters/constants.d.ts +15 -0
  52. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
  53. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
  54. package/package.json +2 -2
  55. package/umd/index.umd.js +92 -52
  56. package/umd/index.umd.js.map +1 -1
  57. /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/umd/index.umd.js CHANGED
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.75.0-0';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  */
@@ -175,7 +175,7 @@
175
175
  function TODO_USE() {
176
176
  }
177
177
 
178
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"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",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"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",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"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",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:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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"}];
178
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"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.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"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.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"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.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",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:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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.book.md"}];
179
179
 
180
180
  /**
181
181
  * Prettify the html code
@@ -223,13 +223,13 @@
223
223
  /**
224
224
  * Converts promptbook in JSON format to string format
225
225
  *
226
- * @param pipelineJson Promptbook in JSON format (.ptbk.json)
227
- * @returns Promptbook in string format (.ptbk.md)
226
+ * @param pipelineJson Promptbook in JSON format (.book.json)
227
+ * @returns Promptbook in string format (.book.md)
228
228
  * @public exported from `@promptbook/core`
229
229
  */
230
230
  function pipelineJsonToString(pipelineJson) {
231
231
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
232
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
232
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
233
233
  var pipelineString = "# ".concat(title);
234
234
  if (description) {
235
235
  pipelineString += '\n\n';
@@ -239,8 +239,10 @@
239
239
  if (pipelineUrl) {
240
240
  commands.push("PIPELINE URL ".concat(pipelineUrl));
241
241
  }
242
- commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
243
- // TODO: [main] !!! This increase size of the bundle and is probbably not necessary
242
+ if (bookVersion !== "undefined") {
243
+ commands.push("BOOK VERSION ".concat(bookVersion));
244
+ }
245
+ // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
244
246
  pipelineString = prettifyMarkdown(pipelineString);
245
247
  try {
246
248
  for (var _g = __values(parameters.filter(function (_a) {
@@ -420,7 +422,7 @@
420
422
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
421
423
  * TODO: [🏛] Maybe make some markdown builder
422
424
  * TODO: [🏛] Escape all
423
- * TODO: [🧠] Should be in generated .ptbk.md file GENERATOR_WARNING
425
+ * TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
424
426
  */
425
427
 
426
428
  /**
@@ -724,6 +726,7 @@
724
726
  // Note: In normal situations, we check the pipeline logic:
725
727
  true);
726
728
  /**
729
+ * TODO: Extract `constants.ts` from `config.ts`
727
730
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
728
731
  */
729
732
 
@@ -900,7 +903,7 @@
900
903
  if (!url.startsWith('https://')) {
901
904
  return false;
902
905
  }
903
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.ptbk.md') || url.endsWith('.ptbk'))) {
906
+ if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
904
907
  return false;
905
908
  }
906
909
  if (url.includes('#')) {
@@ -969,9 +972,9 @@
969
972
  // <- Note: [🚲]
970
973
  throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
971
974
  }
972
- if (pipeline.promptbookVersion !== undefined && !isValidPromptbookVersion(pipeline.promptbookVersion)) {
975
+ if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
973
976
  // <- Note: [🚲]
974
- throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
977
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
975
978
  }
976
979
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
977
980
  if (!Array.isArray(pipeline.parameters)) {
@@ -985,18 +988,18 @@
985
988
  }
986
989
  var _loop_1 = function (parameter) {
987
990
  if (parameter.isInput && parameter.isOutput) {
988
- throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
991
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Parameter `{".concat(parameter.name, "}` can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
989
992
  }
990
993
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
991
994
  if (!parameter.isInput &&
992
995
  !parameter.isOutput &&
993
996
  !pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
994
- 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 "); }));
997
+ 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 "); }));
995
998
  }
996
999
  // Note: Testing that parameter is either input or result of some template
997
1000
  if (!parameter.isInput &&
998
1001
  !pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
999
- 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 1) Remove declaration of {").concat(parameter.name, "}\n 2) Add template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
1002
+ 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 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add template that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1000
1003
  }
1001
1004
  };
1002
1005
  try {
@@ -1024,7 +1027,7 @@
1024
1027
  var _loop_2 = function (template) {
1025
1028
  var e_4, _h, e_5, _j;
1026
1029
  if (definedParameters.has(template.resultingParameterName)) {
1027
- throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1030
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(template.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1028
1031
  }
1029
1032
  if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
1030
1033
  throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -1037,7 +1040,7 @@
1037
1040
  }
1038
1041
  var _loop_4 = function (joker) {
1039
1042
  if (!template.dependentParameterNames.includes(joker)) {
1040
- throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1043
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1041
1044
  }
1042
1045
  };
1043
1046
  try {
@@ -1132,14 +1135,24 @@
1132
1135
  if (currentlyResovedTemplates.length === 0) {
1133
1136
  throw new PipelineLogicError(
1134
1137
  // TODO: [🐎] DRY
1135
- 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
1138
+ 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
1136
1139
  .map(function (_a) {
1137
1140
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1138
- return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
1139
- .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1141
+ return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
1142
+ .map(function (dependentParameterName) { return "`{".concat(dependentParameterName, "}`"); })
1140
1143
  .join(' and '));
1141
1144
  })
1142
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n\n "); }));
1145
+ .join('\n')), "\n\n **Resolved:**\n ").concat(block(resovedParameters
1146
+ .filter(function (name) {
1147
+ return !RESERVED_PARAMETER_NAMES.includes(name);
1148
+ })
1149
+ .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
1150
+ .join('\n')), "\n\n\n **Reserved (which are available):**\n ").concat(block(resovedParameters
1151
+ .filter(function (name) {
1152
+ return RESERVED_PARAMETER_NAMES.includes(name);
1153
+ })
1154
+ .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
1155
+ .join('\n')), "\n\n\n "); }));
1143
1156
  }
1144
1157
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1145
1158
  var resultingParameterName = _a.resultingParameterName;
@@ -1150,6 +1163,7 @@
1150
1163
  while (unresovedTemplates.length > 0) {
1151
1164
  _loop_3();
1152
1165
  }
1166
+ // TODO: !!!!!! Test that pipeline interface implements declared formfactor interface
1153
1167
  }
1154
1168
  /**
1155
1169
  * TODO: !! [🧞‍♀️] Do not allow joker + foreach
@@ -2489,8 +2503,8 @@
2489
2503
  else if (errors.length > 1) {
2490
2504
  throw new PipelineExecutionError(
2491
2505
  // TODO: Tell which execution tools failed like
2492
- // 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
2493
- // 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
2506
+ // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2507
+ // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2494
2508
  // 3) ...
2495
2509
  spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2496
2510
  .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
@@ -2604,7 +2618,7 @@
2604
2618
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2605
2619
  _b = createPipelineExecutor;
2606
2620
  _c = {};
2607
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
2621
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
2608
2622
  case 1:
2609
2623
  preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
2610
2624
  _c.tools = tools,
@@ -3276,13 +3290,14 @@
3276
3290
  */
3277
3291
  function clonePipeline(pipeline) {
3278
3292
  // Note: Not using spread operator (...) because @@@
3279
- 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;
3293
+ var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
3280
3294
  return {
3281
3295
  pipelineUrl: pipelineUrl,
3282
3296
  sourceFile: sourceFile,
3283
3297
  title: title,
3284
- promptbookVersion: promptbookVersion,
3298
+ bookVersion: bookVersion,
3285
3299
  description: description,
3300
+ formfactorName: formfactorName,
3286
3301
  parameters: parameters,
3287
3302
  templates: templates,
3288
3303
  knowledgeSources: knowledgeSources,
@@ -4147,11 +4162,11 @@
4147
4162
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
4148
4163
  var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
4149
4164
  if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
4150
- throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
4165
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
4151
4166
  }
4152
4167
  else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
4153
4168
  // TODO: [🍵]
4154
- throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
4169
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
4155
4170
  }
4156
4171
  }
4157
4172
  }
@@ -4178,11 +4193,11 @@
4178
4193
  throw new PipelineExecutionError('Parameter is already opened or not closed');
4179
4194
  }
4180
4195
  if (parameters[parameterName] === undefined) {
4181
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
4196
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4182
4197
  }
4183
4198
  var parameterValue = parameters[parameterName];
4184
4199
  if (parameterValue === undefined) {
4185
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
4200
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4186
4201
  }
4187
4202
  parameterValue = parameterValue.toString();
4188
4203
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
@@ -4226,30 +4241,45 @@
4226
4241
  return text.length;
4227
4242
  }
4228
4243
 
4244
+ /**
4245
+ * Number of characters per standard line with 11pt Arial font size.
4246
+ *
4247
+ * @public exported from `@promptbook/utils`
4248
+ */
4249
+ var CHARACTERS_PER_STANDARD_LINE = 63;
4250
+ /**
4251
+ * Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
4252
+ *
4253
+ * @public exported from `@promptbook/utils`
4254
+ */
4255
+ var LINES_PER_STANDARD_PAGE = 44;
4256
+ /**
4257
+ * TODO: [🧠] Should be this `constants.ts` or `config.ts`?
4258
+ */
4259
+
4229
4260
  /**
4230
4261
  * Counts number of lines in the text
4231
4262
  *
4263
+ * Note: This does not check only for the presence of newlines, but also for the length of the standard line.
4264
+ *
4232
4265
  * @public exported from `@promptbook/utils`
4233
4266
  */
4234
4267
  function countLines(text) {
4235
- if (text === '') {
4236
- return 0;
4237
- }
4238
- return text.split('\n').length;
4268
+ text = text.replace('\r\n', '\n');
4269
+ text = text.replace('\r', '\n');
4270
+ var lines = text.split('\n');
4271
+ return lines.reduce(function (count, line) { return count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE); }, 0);
4239
4272
  }
4240
4273
 
4241
4274
  /**
4242
4275
  * Counts number of pages in the text
4243
4276
  *
4277
+ * Note: This does not check only for the count of newlines, but also for the length of the standard line and length of the standard page.
4278
+ *
4244
4279
  * @public exported from `@promptbook/utils`
4245
4280
  */
4246
4281
  function countPages(text) {
4247
- if (text === '') {
4248
- return 0;
4249
- }
4250
- var pagesByLinesCount = Math.ceil(countLines(text) / 44);
4251
- var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
4252
- return Math.max(pagesByLinesCount, pagesByCharactersCount);
4282
+ return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4253
4283
  }
4254
4284
 
4255
4285
  /**
@@ -4529,7 +4559,7 @@
4529
4559
  promptTitle: template.title,
4530
4560
  promptMessage: replaceParameters(template.description || '', parameters),
4531
4561
  defaultValue: replaceParameters(preparedContent, parameters),
4532
- // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
4562
+ // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4533
4563
  placeholder: undefined,
4534
4564
  priority: priority,
4535
4565
  }))];
@@ -4957,7 +4987,7 @@
4957
4987
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
4958
4988
  // Houston, we have a problem
4959
4989
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
4960
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4990
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4961
4991
  }
4962
4992
  };
4963
4993
  try {
@@ -5036,7 +5066,7 @@
5036
5066
  var _loop_1 = function (parameter) {
5037
5067
  if (parametersToPass[parameter.name] === undefined) {
5038
5068
  // [4]
5039
- $warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
5069
+ $warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
5040
5070
  return "continue";
5041
5071
  }
5042
5072
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -5095,7 +5125,7 @@
5095
5125
  pipelineUrl: preparedPipeline.pipelineUrl,
5096
5126
  title: preparedPipeline.title,
5097
5127
  promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
5098
- promptbookRequestedVersion: preparedPipeline.promptbookVersion,
5128
+ promptbookRequestedVersion: preparedPipeline.bookVersion,
5099
5129
  description: preparedPipeline.description,
5100
5130
  promptExecutions: [],
5101
5131
  };
@@ -5123,7 +5153,7 @@
5123
5153
  case 6: return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
5124
5154
  isSuccessful: false,
5125
5155
  errors: __spreadArray([
5126
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
5156
+ new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
5127
5157
  ], __read(errors), false).map(serializeError),
5128
5158
  warnings: [],
5129
5159
  executionReport: executionReport,
@@ -5171,7 +5201,7 @@
5171
5201
  case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
5172
5202
  isSuccessful: false,
5173
5203
  errors: __spreadArray([
5174
- new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
5204
+ new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
5175
5205
  ], __read(errors), false).map(serializeError),
5176
5206
  warnings: warnings.map(serializeError),
5177
5207
  executionReport: executionReport,
@@ -5245,14 +5275,24 @@
5245
5275
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
5246
5276
  throw new UnexpectedError(
5247
5277
  // TODO: [🐎] DRY
5248
- spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
5278
+ spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTemplates_1
5249
5279
  .map(function (_a) {
5250
5280
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
5251
- return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
5252
- .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
5281
+ return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
5282
+ .map(function (dependentParameterName) { return "`{".concat(dependentParameterName, "}`"); })
5253
5283
  .join(' and '));
5254
5284
  })
5255
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
5285
+ .join('\n')), "\n\n **Resolved:**\n ").concat(block(resovedParameterNames_1
5286
+ .filter(function (name) {
5287
+ return !RESERVED_PARAMETER_NAMES.includes(name);
5288
+ })
5289
+ .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
5290
+ .join('\n')), "\n\n **Reserved (which are available):**\n ").concat(block(resovedParameterNames_1
5291
+ .filter(function (name) {
5292
+ return RESERVED_PARAMETER_NAMES.includes(name);
5293
+ })
5294
+ .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
5295
+ .join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
5256
5296
  case 1:
5257
5297
  if (!!currentTemplate) return [3 /*break*/, 3];
5258
5298
  /* [🤹‍♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -5491,7 +5531,7 @@
5491
5531
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
5492
5532
  _d = createPipelineExecutor;
5493
5533
  _g = {};
5494
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
5534
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md')];
5495
5535
  case 1:
5496
5536
  prepareKnowledgeFromMarkdownExecutor = _d.apply(void 0, [(_g.pipeline = _k.sent(),
5497
5537
  _g.tools = {
@@ -5500,7 +5540,7 @@
5500
5540
  _g)]);
5501
5541
  _e = createPipelineExecutor;
5502
5542
  _h = {};
5503
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
5543
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.book.md')];
5504
5544
  case 2:
5505
5545
  prepareTitleExecutor = _e.apply(void 0, [(_h.pipeline = _k.sent(),
5506
5546
  _h.tools = {
@@ -5509,7 +5549,7 @@
5509
5549
  _h)]);
5510
5550
  _f = createPipelineExecutor;
5511
5551
  _j = {};
5512
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
5552
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md')];
5513
5553
  case 3:
5514
5554
  prepareKeywordsExecutor = _f.apply(void 0, [(_j.pipeline = _k.sent(),
5515
5555
  _j.tools = {