@promptbook/node 0.74.0-8 → 0.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +3 -15
  2. package/esm/index.es.js +80 -59
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +5 -1
  5. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  6. package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
  7. package/esm/typings/src/cli/main.d.ts +4 -1
  8. package/esm/typings/src/cli/promptbookCli.d.ts +1 -1
  9. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  10. package/esm/typings/src/collection/collectionToJson.test.d.ts +1 -1
  11. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -1
  12. package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +1 -1
  13. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
  14. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  15. package/esm/typings/src/config.d.ts +6 -0
  16. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +3 -3
  17. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
  18. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -2
  19. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
  20. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +7 -7
  21. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  22. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +1 -1
  23. package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
  24. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +1 -1
  25. package/esm/typings/src/storage/{memory/utils → utils}/PrefixStorage.d.ts +1 -1
  26. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -4
  27. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
  28. package/esm/typings/src/types/Prompt.d.ts +1 -1
  29. package/esm/typings/src/types/typeAliases.d.ts +2 -2
  30. package/esm/typings/src/utils/expectation-counters/config.d.ts +12 -0
  31. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
  32. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
  33. package/package.json +2 -2
  34. package/umd/index.umd.js +80 -59
  35. package/umd/index.umd.js.map +1 -1
  36. /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/README.md CHANGED
@@ -18,16 +18,13 @@ Build responsible, controlled and transparent applications on top of LLM models!
18
18
 
19
19
  ## ✨ New Features
20
20
 
21
- - 💙 Working on [the **Book** language v1](https://github.com/webgptorg/book)
21
+ - 💙 Working [the **Book** language v1.0.0](https://github.com/webgptorg/book)
22
+ - 🖤 Run books from CLI - `npx ptbk run path/to/your/book`
22
23
  - 📚 Support of `.docx`, `.doc` and `.pdf` documents
23
24
  - ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
24
25
 
25
26
 
26
27
 
27
- <blockquote style="color: #ff8811">
28
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
29
- </blockquote>
30
-
31
28
  ## 📦 Package `@promptbook/node`
32
29
 
33
30
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -152,7 +149,7 @@ Following is the documentation and blueprint of the Book language.
152
149
 
153
150
  File is designed to be easy to read and write. It is strict subset of markdown. It is designed to be understandable by both humans and machines and without specific knowledge of the language.
154
151
 
155
- It has file with `.ptbk.md` or `.book` extension with `UTF-8` non BOM encoding.
152
+ It has file with `.book.md` or `.book` extension with `UTF-8` non BOM encoding.
156
153
 
157
154
  As it is source code, it can leverage all the features of version control systems like git and does not suffer from the problems of binary formats, proprietary formats, or no-code solutions.
158
155
 
@@ -245,11 +242,6 @@ Or you can install them separately:
245
242
 
246
243
  ## 📚 Dictionary
247
244
 
248
-
249
-
250
-
251
-
252
-
253
245
  ### 📚 Dictionary
254
246
 
255
247
  The following glossary is used to clarify certain concepts:
@@ -265,8 +257,6 @@ The following glossary is used to clarify certain concepts:
265
257
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
266
258
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
267
259
 
268
-
269
-
270
260
  _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
271
261
 
272
262
  #### Promptbook core
@@ -327,8 +317,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
327
317
  - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
328
318
  - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
329
319
 
330
-
331
-
332
320
  ### Terms specific to Promptbook TypeScript implementation
333
321
 
334
322
  - Anonymous mode
package/esm/index.es.js CHANGED
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  *
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.74.0-13';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  */
@@ -363,6 +363,13 @@ function $asDeeplyFrozenSerializableJson(name, objectValue) {
363
363
  * TODO: [🧠] Is there a way how to meaningfully test this utility
364
364
  */
365
365
 
366
+ // <- TODO: [🐊] Pick the best claim
367
+ /**
368
+ * When the title is not provided, the default title is used
369
+ *
370
+ * @public exported from `@promptbook/core`
371
+ */
372
+ var DEFAULT_TITLE = "Untitled";
366
373
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
367
374
  /**
368
375
  * The maximum number of iterations for a loops
@@ -512,13 +519,13 @@ function capitalize(word) {
512
519
  /**
513
520
  * Converts promptbook in JSON format to string format
514
521
  *
515
- * @param pipelineJson Promptbook in JSON format (.ptbk.json)
516
- * @returns Promptbook in string format (.ptbk.md)
522
+ * @param pipelineJson Promptbook in JSON format (.book.json)
523
+ * @returns Promptbook in string format (.book.md)
517
524
  * @public exported from `@promptbook/core`
518
525
  */
519
526
  function pipelineJsonToString(pipelineJson) {
520
527
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
521
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
528
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
522
529
  var pipelineString = "# ".concat(title);
523
530
  if (description) {
524
531
  pipelineString += '\n\n';
@@ -528,8 +535,10 @@ function pipelineJsonToString(pipelineJson) {
528
535
  if (pipelineUrl) {
529
536
  commands.push("PIPELINE URL ".concat(pipelineUrl));
530
537
  }
531
- commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
532
- // TODO: [main] !!! This increase size of the bundle and is probbably not necessary
538
+ if (bookVersion !== "undefined") {
539
+ commands.push("BOOK VERSION ".concat(bookVersion));
540
+ }
541
+ // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
533
542
  pipelineString = prettifyMarkdown(pipelineString);
534
543
  try {
535
544
  for (var _g = __values(parameters.filter(function (_a) {
@@ -709,7 +718,7 @@ function templateParameterJsonToString(templateParameterJson) {
709
718
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
710
719
  * TODO: [🏛] Maybe make some markdown builder
711
720
  * TODO: [🏛] Escape all
712
- * TODO: [🧠] Should be in generated .ptbk.md file GENERATOR_WARNING
721
+ * TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
713
722
  */
714
723
 
715
724
  /**
@@ -1347,7 +1356,7 @@ function joinLlmExecutionTools() {
1347
1356
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1348
1357
  */
1349
1358
 
1350
- 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"}];
1359
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.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.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.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.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.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.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.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.book.md"}];
1351
1360
 
1352
1361
  /**
1353
1362
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1522,7 +1531,7 @@ function isValidPipelineUrl(url) {
1522
1531
  if (!url.startsWith('https://')) {
1523
1532
  return false;
1524
1533
  }
1525
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.ptbk.md') || url.endsWith('.ptbk'))) {
1534
+ if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1526
1535
  return false;
1527
1536
  }
1528
1537
  if (url.includes('#')) {
@@ -1591,9 +1600,9 @@ function validatePipelineCore(pipeline) {
1591
1600
  // <- Note: [🚲]
1592
1601
  throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1593
1602
  }
1594
- if (pipeline.promptbookVersion !== undefined && !isValidPromptbookVersion(pipeline.promptbookVersion)) {
1603
+ if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
1595
1604
  // <- Note: [🚲]
1596
- throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1605
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1597
1606
  }
1598
1607
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1599
1608
  if (!Array.isArray(pipeline.parameters)) {
@@ -2986,30 +2995,42 @@ function countCharacters(text) {
2986
2995
  return text.length;
2987
2996
  }
2988
2997
 
2998
+ /**
2999
+ * Number of characters per standard line with 11pt Arial font size.
3000
+ *
3001
+ * @public exported from `@promptbook/utils`
3002
+ */
3003
+ var CHARACTERS_PER_STANDARD_LINE = 63;
3004
+ /**
3005
+ * Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
3006
+ *
3007
+ * @public exported from `@promptbook/utils`
3008
+ */
3009
+ var LINES_PER_STANDARD_PAGE = 44;
3010
+
2989
3011
  /**
2990
3012
  * Counts number of lines in the text
2991
3013
  *
3014
+ * Note: This does not check only for the presence of newlines, but also for the length of the standard line.
3015
+ *
2992
3016
  * @public exported from `@promptbook/utils`
2993
3017
  */
2994
3018
  function countLines(text) {
2995
- if (text === '') {
2996
- return 0;
2997
- }
2998
- return text.split('\n').length;
3019
+ text = text.replace('\r\n', '\n');
3020
+ text = text.replace('\r', '\n');
3021
+ var lines = text.split('\n');
3022
+ return lines.reduce(function (count, line) { return count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE); }, 0);
2999
3023
  }
3000
3024
 
3001
3025
  /**
3002
3026
  * Counts number of pages in the text
3003
3027
  *
3028
+ * 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.
3029
+ *
3004
3030
  * @public exported from `@promptbook/utils`
3005
3031
  */
3006
3032
  function countPages(text) {
3007
- if (text === '') {
3008
- return 0;
3009
- }
3010
- var pagesByLinesCount = Math.ceil(countLines(text) / 44);
3011
- var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
3012
- return Math.max(pagesByLinesCount, pagesByCharactersCount);
3033
+ return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
3013
3034
  }
3014
3035
 
3015
3036
  /**
@@ -3550,7 +3571,7 @@ function executeAttempts(options) {
3550
3571
  promptTitle: template.title,
3551
3572
  promptMessage: replaceParameters(template.description || '', parameters),
3552
3573
  defaultValue: replaceParameters(preparedContent, parameters),
3553
- // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
3574
+ // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
3554
3575
  placeholder: undefined,
3555
3576
  priority: priority,
3556
3577
  }))];
@@ -4116,7 +4137,7 @@ function executePipeline(options) {
4116
4137
  pipelineUrl: preparedPipeline.pipelineUrl,
4117
4138
  title: preparedPipeline.title,
4118
4139
  promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
4119
- promptbookRequestedVersion: preparedPipeline.promptbookVersion,
4140
+ promptbookRequestedVersion: preparedPipeline.bookVersion,
4120
4141
  description: preparedPipeline.description,
4121
4142
  promptExecutions: [],
4122
4143
  };
@@ -4465,7 +4486,7 @@ function preparePersona(personaDescription, tools, options) {
4465
4486
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
4466
4487
  _b = createPipelineExecutor;
4467
4488
  _c = {};
4468
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
4489
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book.md')];
4469
4490
  case 1:
4470
4491
  preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
4471
4492
  _c.tools = tools,
@@ -5222,12 +5243,12 @@ TODO: [🧊] This is how it can look in future
5222
5243
  */
5223
5244
  function clonePipeline(pipeline) {
5224
5245
  // Note: Not using spread operator (...) because @@@
5225
- 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;
5246
+ var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
5226
5247
  return {
5227
5248
  pipelineUrl: pipelineUrl,
5228
5249
  sourceFile: sourceFile,
5229
5250
  title: title,
5230
- promptbookVersion: promptbookVersion,
5251
+ bookVersion: bookVersion,
5231
5252
  description: description,
5232
5253
  parameters: parameters,
5233
5254
  templates: templates,
@@ -5439,7 +5460,7 @@ var knowledgeCommandParser = {
5439
5460
  throw new ParseError("Source not valid");
5440
5461
  }
5441
5462
  if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
5442
- throw new ParseError("Source cannot be outside of the .ptbk.md folder");
5463
+ throw new ParseError("Source cannot be outside of the .book.md folder");
5443
5464
  }
5444
5465
  return {
5445
5466
  type: 'KNOWLEDGE',
@@ -6089,7 +6110,7 @@ function validateParameterName(parameterName) {
6089
6110
  /**
6090
6111
  * Parses the foreach command
6091
6112
  *
6092
- * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
6113
+ * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
6093
6114
  *
6094
6115
  * @see `documentationUrl` for more details
6095
6116
  * @private within the commands folder
@@ -6239,7 +6260,7 @@ var foreachCommandParser = {
6239
6260
  },
6240
6261
  };
6241
6262
  /**
6242
- * TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
6263
+ * TODO: [🍭] Make .book.md file with examples of the FOREACH with wrong parsing and logic
6243
6264
  */
6244
6265
 
6245
6266
  /**
@@ -6873,7 +6894,7 @@ var bookVersionCommandParser = {
6873
6894
  /**
6874
6895
  * Description of the BOOK_VERSION command
6875
6896
  */
6876
- description: "Which version of the Book language is the .ptbk.md using",
6897
+ description: "Which version of the Book language is the .book.md using",
6877
6898
  /**
6878
6899
  * Link to documentation
6879
6900
  */
@@ -6887,19 +6908,19 @@ var bookVersionCommandParser = {
6887
6908
  */
6888
6909
  parse: function (input) {
6889
6910
  var args = input.args;
6890
- var promptbookVersion = args.pop();
6891
- if (promptbookVersion === undefined) {
6911
+ var bookVersion = args.pop();
6912
+ if (bookVersion === undefined) {
6892
6913
  throw new ParseError("Version is required");
6893
6914
  }
6894
- if (!isValidPromptbookVersion(promptbookVersion)) {
6895
- throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
6915
+ if (!isValidPromptbookVersion(bookVersion)) {
6916
+ throw new ParseError("Invalid Promptbook version \"".concat(bookVersion, "\""));
6896
6917
  }
6897
6918
  if (args.length > 0 && !(((args.length === 1 && args[0]) || '').toUpperCase() === 'VERSION')) {
6898
6919
  throw new ParseError("Can not have more than one Promptbook version");
6899
6920
  }
6900
6921
  return {
6901
6922
  type: 'BOOK_VERSION',
6902
- promptbookVersion: promptbookVersion,
6923
+ bookVersion: bookVersion,
6903
6924
  };
6904
6925
  },
6905
6926
  /**
@@ -6909,7 +6930,7 @@ var bookVersionCommandParser = {
6909
6930
  */
6910
6931
  $applyToPipelineJson: function (command, $pipelineJson) {
6911
6932
  // TODO: Warn if the version is overridden
6912
- $pipelineJson.promptbookVersion = command.promptbookVersion;
6933
+ $pipelineJson.bookVersion = command.bookVersion;
6913
6934
  },
6914
6935
  /**
6915
6936
  * Converts the BOOK_VERSION command back to string
@@ -6962,9 +6983,9 @@ var urlCommandParser = {
6962
6983
  * Example usages of the URL command
6963
6984
  */
6964
6985
  examples: [
6965
- 'PIPELINE URL https://promptbook.studio/library/write-cv.ptbk.md',
6966
- 'URL https://promptbook.studio/library/write-cv.ptbk.md',
6967
- 'https://promptbook.studio/library/write-cv.ptbk.md',
6986
+ 'PIPELINE URL https://promptbook.studio/library/write-cv.book.md',
6987
+ 'URL https://promptbook.studio/library/write-cv.book.md',
6988
+ 'https://promptbook.studio/library/write-cv.book.md',
6968
6989
  ],
6969
6990
  /**
6970
6991
  * Parses the URL command
@@ -7165,7 +7186,7 @@ var instrumentCommandParser = {
7165
7186
  /**
7166
7187
  * Parses the boilerplate command
7167
7188
  *
7168
- * Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
7189
+ * Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.book.md` file
7169
7190
  *
7170
7191
  * @see `documentationUrl` for more details
7171
7192
  * @private within the commands folder
@@ -7219,7 +7240,7 @@ var boilerplateCommandParser = {
7219
7240
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7220
7241
  */
7221
7242
  $applyToPipelineJson: function (command, $pipelineJson) {
7222
- throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7243
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
7223
7244
  },
7224
7245
  /**
7225
7246
  * Apply the BOILERPLATE command to the `pipelineJson`
@@ -7227,7 +7248,7 @@ var boilerplateCommandParser = {
7227
7248
  * Note: `$` is used to indicate that this function mutates given `templateJson`
7228
7249
  */
7229
7250
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
7230
- throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7251
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
7231
7252
  },
7232
7253
  /**
7233
7254
  * Converts the BOILERPLATE command back to string
@@ -7243,7 +7264,7 @@ var boilerplateCommandParser = {
7243
7264
  * Note: This is used in `pipelineJsonToString` utility
7244
7265
  */
7245
7266
  takeFromPipelineJson: function (pipelineJson) {
7246
- throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7267
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
7247
7268
  },
7248
7269
  /**
7249
7270
  * Reads the BOILERPLATE command from the `TemplateJson`
@@ -7251,7 +7272,7 @@ var boilerplateCommandParser = {
7251
7272
  * Note: This is used in `pipelineJsonToString` utility
7252
7273
  */
7253
7274
  takeFromTemplateJson: function ($templateJson) {
7254
- throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7275
+ throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
7255
7276
  },
7256
7277
  };
7257
7278
 
@@ -7580,7 +7601,7 @@ function splitMarkdownIntoSections(markdown) {
7580
7601
  return;
7581
7602
  }
7582
7603
  if (!section.startsWith('#')) {
7583
- section = "# Untitled\n\n".concat(section);
7604
+ section = "# ".concat(DEFAULT_TITLE, "\n\n").concat(section);
7584
7605
  }
7585
7606
  sections.push(section);
7586
7607
  buffer = [];
@@ -7644,7 +7665,7 @@ function flattenMarkdown(markdown) {
7644
7665
  var e_1, _a;
7645
7666
  var sections = splitMarkdownIntoSections(markdown);
7646
7667
  if (sections.length === 0) {
7647
- return '# Untitled';
7668
+ return "# ".concat(DEFAULT_TITLE);
7648
7669
  }
7649
7670
  var flattenedMarkdown = '';
7650
7671
  var parsedSections = sections.map(parseMarkdownSection);
@@ -7655,7 +7676,7 @@ function flattenMarkdown(markdown) {
7655
7676
  }
7656
7677
  else {
7657
7678
  parsedSections.unshift(firstSection);
7658
- flattenedMarkdown += "# Untitled" + "\n\n"; // <- [🧠] Maybe 3 new lines?
7679
+ flattenedMarkdown += "# ".concat(DEFAULT_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
7659
7680
  }
7660
7681
  try {
7661
7682
  for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
@@ -7727,8 +7748,8 @@ function titleToName(value) {
7727
7748
  * Note: This function does not validate logic of the pipeline only the parsing
7728
7749
  * Note: This function acts as compilation process
7729
7750
  *
7730
- * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
7731
- * @returns {Promptbook} compiled in JSON format (.ptbk.json)
7751
+ * @param pipelineString {Promptbook} in string markdown format (.book.md)
7752
+ * @returns {Promptbook} compiled in JSON format (.book.json)
7732
7753
  * @throws {ParseError} if the promptbook string is not valid
7733
7754
  * @public exported from `@promptbook/core`
7734
7755
  */
@@ -7737,7 +7758,7 @@ function pipelineStringToJsonSync(pipelineString) {
7737
7758
  var $pipelineJson = {
7738
7759
  title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
7739
7760
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
7740
- promptbookVersion: undefined /* <- Note: By default no explicit version */,
7761
+ bookVersion: undefined /* <- Note: By default no explicit version */,
7741
7762
  description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
7742
7763
  parameters: [],
7743
7764
  templates: [],
@@ -8120,10 +8141,10 @@ function pipelineStringToJsonSync(pipelineString) {
8120
8141
  * Note: This function does not validate logic of the pipeline only the parsing
8121
8142
  * Note: This function acts as compilation process
8122
8143
  *
8123
- * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
8144
+ * @param pipelineString {Promptbook} in string markdown format (.book.md)
8124
8145
  * @param tools - Tools for the preparation and scraping - if not provided together with `llm`, the preparation will be skipped
8125
8146
  * @param options - Options and tools for the compilation
8126
- * @returns {Promptbook} compiled in JSON format (.ptbk.json)
8147
+ * @returns {Promptbook} compiled in JSON format (.book.json)
8127
8148
  * @throws {ParseError} if the promptbook string is not valid
8128
8149
  * @public exported from `@promptbook/core`
8129
8150
  */
@@ -9504,13 +9525,13 @@ function createCollectionFromDirectory(path, tools, options) {
9504
9525
  return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
9505
9526
  case 1:
9506
9527
  fileNames = _b.sent();
9507
- // Note: First load all .ptbk.json and then .ptbk.md files
9508
- // .ptbk.json can be prepared so it is faster to load
9528
+ // Note: First load all .book.json and then .book.md files
9529
+ // .book.json can be prepared so it is faster to load
9509
9530
  fileNames.sort(function (a, b) {
9510
- if (a.endsWith('.ptbk.json') && b.endsWith('.ptbk.md')) {
9531
+ if (a.endsWith('.book.json') && b.endsWith('.book.md')) {
9511
9532
  return -1;
9512
9533
  }
9513
- if (a.endsWith('.ptbk.md') && b.endsWith('.ptbk.json')) {
9534
+ if (a.endsWith('.book.md') && b.endsWith('.book.json')) {
9514
9535
  return 1;
9515
9536
  }
9516
9537
  return 0;
@@ -9527,7 +9548,7 @@ function createCollectionFromDirectory(path, tools, options) {
9527
9548
  case 1:
9528
9549
  _e.trys.push([1, 8, , 9]);
9529
9550
  pipeline = null;
9530
- if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 4];
9551
+ if (!fileName.endsWith('.book.md')) return [3 /*break*/, 4];
9531
9552
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
9532
9553
  case 2:
9533
9554
  pipelineString = (_e.sent());
@@ -9539,7 +9560,7 @@ function createCollectionFromDirectory(path, tools, options) {
9539
9560
  pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
9540
9561
  return [3 /*break*/, 7];
9541
9562
  case 4:
9542
- if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 6];
9563
+ if (!fileName.endsWith('.book.json')) return [3 /*break*/, 6];
9543
9564
  _d = (_c = JSON).parse;
9544
9565
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
9545
9566
  case 5:
@@ -9707,7 +9728,7 @@ function stringifyPipelineJson(pipeline) {
9707
9728
  return pipelineJsonStringified;
9708
9729
  }
9709
9730
  /**
9710
- * TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.ptbk.md
9731
+ * TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.book.md
9711
9732
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
9712
9733
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
9713
9734
  * TODO: [🍙] Make some standard order of json properties