@promptbook/markdown-utils 0.81.0-9 → 0.81.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 (93) hide show
  1. package/README.md +25 -8
  2. package/esm/index.es.js +141 -59
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +38 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -4
  6. package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/node.index.d.ts +0 -2
  8. package/esm/typings/src/_packages/templates.index.d.ts +2 -2
  9. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  10. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  11. package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
  12. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  13. package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
  14. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
  15. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  16. package/esm/typings/src/commands/index.d.ts +1 -1
  17. package/esm/typings/src/config.d.ts +3 -3
  18. package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
  19. package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
  20. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  21. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
  22. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
  23. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
  24. package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
  25. package/esm/typings/src/formfactors/index.d.ts +31 -9
  26. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
  27. package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
  28. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
  29. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  30. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
  32. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
  35. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
  36. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
  37. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
  38. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
  39. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  40. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
  41. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
  42. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
  43. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
  44. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
  45. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
  46. package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
  47. package/esm/typings/src/personas/preparePersona.d.ts +4 -4
  48. package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
  49. package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
  50. package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
  51. package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
  52. package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
  53. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
  54. package/esm/typings/src/prepare/preparePipeline.d.ts +2 -0
  55. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
  56. package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
  57. package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
  58. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
  59. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
  60. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
  61. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  62. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
  63. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  64. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
  65. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  66. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
  67. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
  68. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  69. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  70. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
  71. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
  72. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  73. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
  74. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
  75. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
  76. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  77. package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
  78. package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
  79. package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
  80. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
  81. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
  82. package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
  83. package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
  84. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
  85. package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
  86. package/esm/typings/src/wizzard/wizzard.d.ts +51 -7
  87. package/package.json +1 -1
  88. package/umd/index.umd.js +141 -59
  89. package/umd/index.umd.js.map +1 -1
  90. package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
  91. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
  92. /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
  93. /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-24';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -358,7 +358,27 @@ function extractJsonBlock(markdown) {
358
358
  * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
359
359
  */
360
360
 
361
- 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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou 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}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou 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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"}];
361
+ 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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece 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}],tasks:[{taskType:"PROMPT_TASK",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- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",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}],tasks:[{taskType:"PROMPT_TASK",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"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou 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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
362
+
363
+ /**
364
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
365
+ * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
366
+ *
367
+ * @param {string} pipelineString the candidate for a pipeline string
368
+ * @returns {PipelineString} the same string as input, but validated as valid
369
+ * @throws {ParseError} if the string is not a valid pipeline string
370
+ * @public exported from `@promptbook/core`
371
+ */
372
+ function validatePipelineString(pipelineString) {
373
+ if (isValidJsonString(pipelineString)) {
374
+ throw new ParseError('Expected a book, but got a JSON string');
375
+ }
376
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
377
+ return pipelineString;
378
+ }
379
+ /**
380
+ * TODO: [🧠][🈴] Where is the best location for this file
381
+ */
362
382
 
363
383
  /**
364
384
  * Prettify the html code
@@ -417,7 +437,7 @@ function pipelineJsonToString(pipelineJson) {
417
437
  if (bookVersion !== "undefined") {
418
438
  commands.push("BOOK VERSION ".concat(bookVersion));
419
439
  }
420
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
440
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
421
441
  pipelineString = prettifyMarkdown(pipelineString);
422
442
  try {
423
443
  for (var _g = __values(parameters.filter(function (_a) {
@@ -565,12 +585,12 @@ function pipelineJsonToString(pipelineJson) {
565
585
  pipelineString += '```' + contentLanguage;
566
586
  pipelineString += '\n';
567
587
  pipelineString += spaceTrim(content);
568
- // <- TODO: [main] !!! Escape
588
+ // <- TODO: [main] !!3 Escape
569
589
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
570
590
  pipelineString += '\n';
571
591
  pipelineString += '```';
572
592
  pipelineString += '\n\n';
573
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
593
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
574
594
  }
575
595
  }
576
596
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -580,7 +600,7 @@ function pipelineJsonToString(pipelineJson) {
580
600
  }
581
601
  finally { if (e_3) throw e_3.error; }
582
602
  }
583
- return pipelineString;
603
+ return validatePipelineString(pipelineString);
584
604
  }
585
605
  /**
586
606
  * @private internal utility of `pipelineJsonToString`
@@ -652,7 +672,7 @@ var ADMIN_GITHUB_NAME = 'hejny';
652
672
  *
653
673
  * @public exported from `@promptbook/core`
654
674
  */
655
- var DEFAULT_TITLE = "Untitled";
675
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
656
676
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
657
677
  /**
658
678
  * The maximum number of iterations for a loops
@@ -804,7 +824,7 @@ function $deepFreeze(objectValue) {
804
824
  /**
805
825
  * Make error report URL for the given error
806
826
  *
807
- * @private !!!!!!
827
+ * @private private within the repository
808
828
  */
809
829
  function getErrorReportUrl(error) {
810
830
  var report = {
@@ -925,7 +945,7 @@ function checkSerializableAsJson(options) {
925
945
  if (!(error instanceof Error)) {
926
946
  throw error;
927
947
  }
928
- throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
948
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
929
949
  }
930
950
  /*
931
951
  TODO: [0] Is there some more elegant way to check circular references?
@@ -955,7 +975,7 @@ function checkSerializableAsJson(options) {
955
975
  }
956
976
  /**
957
977
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
958
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
978
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
959
979
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
960
980
  */
961
981
 
@@ -967,7 +987,6 @@ function checkSerializableAsJson(options) {
967
987
  function deepClone(objectValue) {
968
988
  return JSON.parse(JSON.stringify(objectValue));
969
989
  /*
970
- !!!!!!!!
971
990
  TODO: [🧠] Is there a better implementation?
972
991
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
973
992
  > for (const propertyName of propertyNames) {
@@ -1133,7 +1152,7 @@ function isValidPromptbookVersion(version) {
1133
1152
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1134
1153
  return false;
1135
1154
  }
1136
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1155
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1137
1156
  return true;
1138
1157
  }
1139
1158
 
@@ -1233,9 +1252,6 @@ function isValidPipelineUrl(url) {
1233
1252
  if (!url.startsWith('https://')) {
1234
1253
  return false;
1235
1254
  }
1236
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1237
- return false;
1238
- }
1239
1255
  if (url.includes('#')) {
1240
1256
  // TODO: [🐠]
1241
1257
  return false;
@@ -1266,11 +1282,11 @@ function isValidPipelineUrl(url) {
1266
1282
  */
1267
1283
  function validatePipeline(pipeline) {
1268
1284
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1269
- validatePipelineCore(pipeline);
1285
+ validatePipeline_InnerFunction(pipeline);
1270
1286
  }
1271
1287
  else {
1272
1288
  try {
1273
- validatePipelineCore(pipeline);
1289
+ validatePipeline_InnerFunction(pipeline);
1274
1290
  }
1275
1291
  catch (error) {
1276
1292
  if (!(error instanceof PipelineLogicError)) {
@@ -1284,7 +1300,7 @@ function validatePipeline(pipeline) {
1284
1300
  /**
1285
1301
  * @private internal function for `validatePipeline`
1286
1302
  */
1287
- function validatePipelineCore(pipeline) {
1303
+ function validatePipeline_InnerFunction(pipeline) {
1288
1304
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1289
1305
  var e_1, _a, e_2, _b, e_3, _c;
1290
1306
  var pipelineIdentification = (function () {
@@ -1508,11 +1524,11 @@ function validatePipelineCore(pipeline) {
1508
1524
  _loop_3();
1509
1525
  }
1510
1526
  // Note: Check that formfactor is corresponding to the pipeline interface
1511
- // TODO: !!!!!! Implement this
1527
+ // TODO: !!6 Implement this
1512
1528
  // pipeline.formfactorName
1513
1529
  }
1514
1530
  /**
1515
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
1531
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
1516
1532
  * TODO: [🧠] Work with promptbookVersion
1517
1533
  * TODO: Use here some json-schema, Zod or something similar and change it to:
1518
1534
  * > /**
@@ -1524,11 +1540,11 @@ function validatePipelineCore(pipeline) {
1524
1540
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
1525
1541
  */
1526
1542
  /**
1527
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
1528
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
1529
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
1530
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1531
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
1543
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
1544
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
1545
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
1546
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1547
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
1532
1548
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
1533
1549
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
1534
1550
  */
@@ -1664,7 +1680,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1664
1680
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1665
1681
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1666
1682
  var existing = this.collection.get(pipeline.pipelineUrl);
1667
- throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1683
+ throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1668
1684
  }
1669
1685
  // Note: [🧠] Overwrite existing pipeline with the same URL
1670
1686
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -2000,11 +2016,16 @@ function assertsExecutionSuccessful(executionResult) {
2000
2016
  /**
2001
2017
  * Determine if the pipeline is fully prepared
2002
2018
  *
2019
+ * @see https://github.com/webgptorg/promptbook/discussions/196
2020
+ *
2003
2021
  * @public exported from `@promptbook/core`
2004
2022
  */
2005
2023
  function isPipelinePrepared(pipeline) {
2006
2024
  // Note: Ignoring `pipeline.preparations` @@@
2007
2025
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2026
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2027
+ return false;
2028
+ }
2008
2029
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2009
2030
  return false;
2010
2031
  }
@@ -2020,7 +2041,7 @@ function isPipelinePrepared(pipeline) {
2020
2041
  return true;
2021
2042
  }
2022
2043
  /**
2023
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
2044
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2024
2045
  * TODO: [🐠] Maybe base this on `makeValidator`
2025
2046
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2026
2047
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -2785,10 +2806,10 @@ function preparePersona(personaDescription, tools, options) {
2785
2806
  });
2786
2807
  }
2787
2808
  /**
2788
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
2789
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
2790
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
2791
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
2809
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
2810
+ * TODO: [🏢] Check validity of `modelName` in pipeline
2811
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
2812
+ * TODO: [🏢] Check validity of `temperature` in pipeline
2792
2813
  */
2793
2814
 
2794
2815
  /**
@@ -3483,21 +3504,44 @@ function isValidFilePath(filename) {
3483
3504
  if (typeof filename !== 'string') {
3484
3505
  return false;
3485
3506
  }
3507
+ if (filename.split('\n').length > 1) {
3508
+ return false;
3509
+ }
3510
+ if (filename.split(' ').length >
3511
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
3512
+ return false;
3513
+ }
3486
3514
  var filenameSlashes = filename.split('\\').join('/');
3487
3515
  // Absolute Unix path: /hello.txt
3488
3516
  if (/^(\/)/i.test(filenameSlashes)) {
3517
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
3489
3518
  return true;
3490
3519
  }
3491
3520
  // Absolute Windows path: /hello.txt
3492
3521
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
3522
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
3493
3523
  return true;
3494
3524
  }
3495
3525
  // Relative path: ./hello.txt
3496
3526
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
3527
+ // console.log(filename, 'Relative path: ./hello.txt');
3528
+ return true;
3529
+ }
3530
+ // Allow paths like foo/hello
3531
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
3532
+ // console.log(filename, 'Allow paths like foo/hello');
3533
+ return true;
3534
+ }
3535
+ // Allow paths like hello.book
3536
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
3537
+ // console.log(filename, 'Allow paths like hello.book');
3497
3538
  return true;
3498
3539
  }
3499
3540
  return false;
3500
3541
  }
3542
+ /**
3543
+ * TODO: [🍏] Implement for MacOs
3544
+ */
3501
3545
 
3502
3546
  /**
3503
3547
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -3522,6 +3566,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
3522
3566
  }
3523
3567
  });
3524
3568
  }); };
3569
+ /**
3570
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3571
+ */
3525
3572
 
3526
3573
  /**
3527
3574
  * @@@
@@ -3589,7 +3636,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3589
3636
  },
3590
3637
  }];
3591
3638
  case 2:
3592
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3639
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3593
3640
  if (tools.fs === undefined) {
3594
3641
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3595
3642
  // <- TODO: [🧠] What is the best error type here`
@@ -3604,7 +3651,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3604
3651
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3605
3652
  case 3:
3606
3653
  if (!(_f.sent())) {
3607
- throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3654
+ throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
3608
3655
  }
3609
3656
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3610
3657
  return [2 /*return*/, {
@@ -3717,7 +3764,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
3717
3764
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
3718
3765
  return [2 /*return*/, "break"];
3719
3766
  }
3720
- console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n \n The source:\n > ").concat(block(knowledgeSource.sourceContent
3767
+ console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.sourceContent
3721
3768
  .split('\n')
3722
3769
  .map(function (line) { return "> ".concat(line); })
3723
3770
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3755,7 +3802,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
3755
3802
  return [7 /*endfinally*/];
3756
3803
  case 9:
3757
3804
  if (partialPieces === null) {
3758
- throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
3805
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
3759
3806
  .split('\n')
3760
3807
  .map(function (line) { return "> ".concat(line); })
3761
3808
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3846,7 +3893,7 @@ function prepareTasks(pipeline, tools, options) {
3846
3893
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3847
3894
  * TODO: [🧠] Add context to each task (if missing)
3848
3895
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3849
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
3896
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
3850
3897
  * TODO: Write tests for `preparePipeline`
3851
3898
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3852
3899
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -3856,6 +3903,8 @@ function prepareTasks(pipeline, tools, options) {
3856
3903
  /**
3857
3904
  * Prepare pipeline from string (markdown) format to JSON format
3858
3905
  *
3906
+ * @see https://github.com/webgptorg/promptbook/discussions/196
3907
+ *
3859
3908
  * Note: This function does not validate logic of the pipeline
3860
3909
  * Note: This function acts as part of compilation process
3861
3910
  * Note: When the pipeline is already prepared, it returns the same pipeline
@@ -3868,16 +3917,17 @@ function preparePipeline(pipeline, tools, options) {
3868
3917
  <- TODO: [🧠][🪑] `promptbookVersion` */
3869
3918
  knowledgeSources /*
3870
3919
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3871
- <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
3920
+ <- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
3921
+ var _d;
3872
3922
  var _this = this;
3873
- return __generator(this, function (_c) {
3874
- switch (_c.label) {
3923
+ return __generator(this, function (_e) {
3924
+ switch (_e.label) {
3875
3925
  case 0:
3876
3926
  if (isPipelinePrepared(pipeline)) {
3877
3927
  return [2 /*return*/, pipeline];
3878
3928
  }
3879
3929
  rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
3880
- parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3930
+ parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
3881
3931
  if (tools === undefined || tools.llm === undefined) {
3882
3932
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
3883
3933
  }
@@ -3895,6 +3945,33 @@ function preparePipeline(pipeline, tools, options) {
3895
3945
  // <- TODO: [🧊]
3896
3946
  currentPreparation,
3897
3947
  ];
3948
+ title = pipeline.title;
3949
+ if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
3950
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
3951
+ _c = createPipelineExecutor;
3952
+ _d = {};
3953
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
3954
+ case 1:
3955
+ prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
3956
+ _d.tools = tools,
3957
+ _d)]);
3958
+ return [4 /*yield*/, prepareTitleExecutor({
3959
+ book: sources.map(function (_a) {
3960
+ var content = _a.content;
3961
+ return content;
3962
+ }).join('\n\n'),
3963
+ })];
3964
+ case 2:
3965
+ result = _e.sent();
3966
+ assertsExecutionSuccessful(result);
3967
+ outputParameters = result.outputParameters;
3968
+ titleRaw = outputParameters.title;
3969
+ if (isVerbose) {
3970
+ console.info("The title is \"".concat(titleRaw, "\""));
3971
+ }
3972
+ title = titleRaw || DEFAULT_BOOK_TITLE;
3973
+ _e.label = 3;
3974
+ case 3:
3898
3975
  preparedPersonas = new Array(personas.length);
3899
3976
  return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
3900
3977
  var modelRequirements, preparedPersona;
@@ -3913,12 +3990,12 @@ function preparePipeline(pipeline, tools, options) {
3913
3990
  }
3914
3991
  });
3915
3992
  }); })];
3916
- case 1:
3917
- _c.sent();
3993
+ case 4:
3994
+ _e.sent();
3918
3995
  knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3919
3996
  return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
3920
- case 2:
3921
- partialknowledgePiecesPrepared = _c.sent();
3997
+ case 5:
3998
+ partialknowledgePiecesPrepared = _e.sent();
3922
3999
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3923
4000
  return [4 /*yield*/, prepareTasks({
3924
4001
  parameters: parameters,
@@ -3929,8 +4006,8 @@ function preparePipeline(pipeline, tools, options) {
3929
4006
  maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
3930
4007
  isVerbose: isVerbose,
3931
4008
  })];
3932
- case 3:
3933
- tasksPrepared = (_c.sent()).tasksPrepared;
4009
+ case 6:
4010
+ tasksPrepared = (_e.sent()).tasksPrepared;
3934
4011
  // ----- /Tasks preparation -----
3935
4012
  // TODO: [😂] Use here all `AsyncHighLevelAbstraction`
3936
4013
  // Note: Count total usage
@@ -3941,7 +4018,7 @@ function preparePipeline(pipeline, tools, options) {
3941
4018
  order: ORDER_OF_PIPELINE_JSON,
3942
4019
  value: __assign(__assign({}, pipeline), {
3943
4020
  // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
3944
- knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
4021
+ title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
3945
4022
  // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
3946
4023
  personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
3947
4024
  })];
@@ -4012,7 +4089,7 @@ function extractVariablesFromScript(script) {
4012
4089
  if (!(error instanceof Error)) {
4013
4090
  throw error;
4014
4091
  }
4015
- throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
4092
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
4016
4093
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
4017
4094
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
4018
4095
  }
@@ -4550,6 +4627,8 @@ function templateParameters(template, parameters) {
4550
4627
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4551
4628
  }
4552
4629
  parameterValue = valueToString(parameterValue);
4630
+ // Escape curly braces in parameter values to prevent prompt-injection
4631
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4553
4632
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4554
4633
  parameterValue = parameterValue
4555
4634
  .split('\n')
@@ -4909,7 +4988,7 @@ function executeAttempts(options) {
4909
4988
  promptTitle: task.title,
4910
4989
  promptMessage: templateParameters(task.description || '', parameters),
4911
4990
  defaultValue: templateParameters(preparedContent, parameters),
4912
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4991
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
4913
4992
  placeholder: undefined,
4914
4993
  priority: priority,
4915
4994
  }))];
@@ -5899,6 +5978,7 @@ var markdownScraperMetadata = $deepFreeze({
5899
5978
  mimeTypes: ['text/markdown', 'text/plain'],
5900
5979
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5901
5980
  isAvilableInBrowser: true,
5981
+ // <- Note: [🌏] This is the only scraper which makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
5902
5982
  requiredExecutables: [],
5903
5983
  }); /* <- Note: [🤛] */
5904
5984
  /**
@@ -5907,6 +5987,7 @@ var markdownScraperMetadata = $deepFreeze({
5907
5987
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
5908
5988
  *
5909
5989
  * @public exported from `@promptbook/core`
5990
+ * @public exported from `@promptbook/wizzard`
5910
5991
  * @public exported from `@promptbook/cli`
5911
5992
  */
5912
5993
  $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -5992,12 +6073,12 @@ var MarkdownScraper = /** @class */ (function () {
5992
6073
  outputParameters = result.outputParameters;
5993
6074
  knowledgePiecesRaw = outputParameters.knowledgePieces;
5994
6075
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
5995
- // <- TODO: [main] !! Smarter split and filter out empty pieces
6076
+ // <- TODO: [main] Smarter split and filter out empty pieces
5996
6077
  if (isVerbose) {
5997
6078
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
5998
6079
  }
5999
6080
  return [4 /*yield*/, Promise.all(
6000
- // TODO: [🪂] !! Do not send all at once but in chunks
6081
+ // TODO: [🪂] Do not send all at once but in chunks
6001
6082
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
6002
6083
  var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
6003
6084
  return __generator(this, function (_c) {
@@ -6102,6 +6183,7 @@ var createMarkdownScraper = Object.assign(function (tools, options) {
6102
6183
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6103
6184
  *
6104
6185
  * @public exported from `@promptbook/markdown-utils`
6186
+ * @public exported from `@promptbook/wizzard`
6105
6187
  * @public exported from `@promptbook/cli`
6106
6188
  */
6107
6189
  var _MarkdownScraperRegistration = $scrapersRegister.register(createMarkdownScraper);
@@ -6111,13 +6193,13 @@ var _MarkdownScraperRegistration = $scrapersRegister.register(createMarkdownScra
6111
6193
  */
6112
6194
 
6113
6195
  /**
6114
- * Removes HTML or Markdown comments from a string.
6196
+ * Removes Markdown (or HTML) comments
6115
6197
  *
6116
6198
  * @param {string} content - The string to remove comments from.
6117
6199
  * @returns {string} The input string with all comments removed.
6118
6200
  * @public exported from `@promptbook/markdown-utils`
6119
6201
  */
6120
- function removeContentComments(content) {
6202
+ function removeMarkdownComments(content) {
6121
6203
  return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
6122
6204
  }
6123
6205
 
@@ -6136,7 +6218,7 @@ function addAutoGeneratedSection(content, options) {
6136
6218
  return content.replace(sectionRegex, contentToInsert);
6137
6219
  }
6138
6220
  // Note: Following is the case when the section is not found in the file so we add it there
6139
- var placeForSection = removeContentComments(content).match(/^##.*$/im);
6221
+ var placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
6140
6222
  if (placeForSection !== null) {
6141
6223
  var _a = __read(placeForSection, 1), heading_1 = _a[0];
6142
6224
  return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
@@ -6316,7 +6398,7 @@ function splitMarkdownIntoSections(markdown) {
6316
6398
  return;
6317
6399
  }
6318
6400
  if (!section.startsWith('#')) {
6319
- section = "# ".concat(DEFAULT_TITLE, "\n\n").concat(section);
6401
+ section = "# ".concat(DEFAULT_BOOK_TITLE, "\n\n").concat(section);
6320
6402
  }
6321
6403
  sections.push(section);
6322
6404
  buffer = [];
@@ -6371,7 +6453,7 @@ function splitMarkdownIntoSections(markdown) {
6371
6453
  /**
6372
6454
  * Normalizes the markdown by flattening the structure
6373
6455
  *
6374
- * - It always have h1 - if there is no h1 in the markdown, it will be added "# Untitled"
6456
+ * - It always have h1 - if there is no h1 in the markdown, it will be added `DEFAULT_BOOK_TITLE`
6375
6457
  * - All other headings are normalized to h2
6376
6458
  *
6377
6459
  * @public exported from `@promptbook/markdown-utils`
@@ -6380,7 +6462,7 @@ function flattenMarkdown(markdown) {
6380
6462
  var e_1, _a;
6381
6463
  var sections = splitMarkdownIntoSections(markdown);
6382
6464
  if (sections.length === 0) {
6383
- return "# ".concat(DEFAULT_TITLE);
6465
+ return "# ".concat(DEFAULT_BOOK_TITLE);
6384
6466
  }
6385
6467
  var flattenedMarkdown = '';
6386
6468
  var parsedSections = sections.map(parseMarkdownSection);
@@ -6391,7 +6473,7 @@ function flattenMarkdown(markdown) {
6391
6473
  }
6392
6474
  else {
6393
6475
  parsedSections.unshift(firstSection);
6394
- flattenedMarkdown += "# ".concat(DEFAULT_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
6476
+ flattenedMarkdown += "# ".concat(DEFAULT_BOOK_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
6395
6477
  }
6396
6478
  try {
6397
6479
  for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
@@ -6434,5 +6516,5 @@ function removeMarkdownFormatting(str) {
6434
6516
  return str;
6435
6517
  }
6436
6518
 
6437
- export { BOOK_LANGUAGE_VERSION, MarkdownScraper, PROMPTBOOK_ENGINE_VERSION, _MarkdownScraperRegistration, addAutoGeneratedSection, createMarkdownChart, createMarkdownScraper, createMarkdownTable, escapeMarkdownBlock, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractBlock, extractJsonBlock, extractOneBlockFromMarkdown, flattenMarkdown, parseMarkdownSection, removeContentComments, removeMarkdownFormatting, splitMarkdownIntoSections };
6519
+ export { BOOK_LANGUAGE_VERSION, MarkdownScraper, PROMPTBOOK_ENGINE_VERSION, _MarkdownScraperRegistration, addAutoGeneratedSection, createMarkdownChart, createMarkdownScraper, createMarkdownTable, escapeMarkdownBlock, extractAllBlocksFromMarkdown, extractAllListItemsFromMarkdown, extractBlock, extractJsonBlock, extractOneBlockFromMarkdown, flattenMarkdown, parseMarkdownSection, removeMarkdownComments, removeMarkdownFormatting, splitMarkdownIntoSections };
6438
6520
  //# sourceMappingURL=index.es.js.map