@promptbook/pdf 0.81.0-9 → 0.82.0-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 (108) hide show
  1. package/README.md +25 -4
  2. package/esm/index.es.js +184 -93
  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/remote-client.index.d.ts +7 -3
  9. package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
  10. package/esm/typings/src/_packages/templates.index.d.ts +2 -2
  11. package/esm/typings/src/_packages/types.index.d.ts +32 -30
  12. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  13. package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
  14. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  15. package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
  16. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
  17. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  18. package/esm/typings/src/commands/index.d.ts +1 -1
  19. package/esm/typings/src/config.d.ts +3 -3
  20. package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
  21. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +18 -0
  22. package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
  23. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  24. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
  25. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
  26. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
  27. package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
  28. package/esm/typings/src/formfactors/index.d.ts +31 -9
  29. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
  30. package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
  31. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
  32. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
  35. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
  39. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
  40. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
  41. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
  42. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
  43. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  44. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
  45. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
  46. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
  47. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
  48. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
  49. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  50. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
  51. package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
  52. package/esm/typings/src/personas/preparePersona.d.ts +4 -4
  53. package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
  54. package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
  55. package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
  56. package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
  57. package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
  58. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
  59. package/esm/typings/src/prepare/preparePipeline.d.ts +4 -2
  60. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +14 -0
  61. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
  62. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Error.d.ts +1 -1
  63. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Request.d.ts +4 -4
  64. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Response.d.ts +1 -1
  65. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Progress.d.ts +1 -1
  66. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Request.d.ts +5 -5
  67. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Response.d.ts +1 -1
  68. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteLlmExecutionToolsOptions.d.ts +7 -7
  69. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteServerOptions.d.ts +10 -10
  70. package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
  71. package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
  72. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
  73. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
  74. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
  75. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  76. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
  77. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  78. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
  79. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  80. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
  81. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
  82. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  83. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  84. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
  85. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
  86. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  87. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
  88. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
  89. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
  90. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  91. package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
  92. package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
  93. package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
  94. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
  95. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
  96. package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
  97. package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
  98. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
  99. package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
  100. package/esm/typings/src/wizzard/wizzard.d.ts +51 -7
  101. package/package.json +2 -2
  102. package/umd/index.umd.js +184 -93
  103. package/umd/index.umd.js.map +1 -1
  104. package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
  105. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
  106. /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
  107. /package/esm/typings/src/{llm-providers/remote → remote-server}/startRemoteServer.d.ts +0 -0
  108. /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -24,7 +24,7 @@
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -178,7 +178,67 @@
178
178
  function TODO_USE() {
179
179
  }
180
180
 
181
- 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"}];
181
+ 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- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\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- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\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 task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon",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 task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
182
+
183
+ /**
184
+ * Function isValidJsonString will tell you if the string is valid JSON or not
185
+ *
186
+ * @public exported from `@promptbook/utils`
187
+ */
188
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
189
+ try {
190
+ JSON.parse(value);
191
+ return true;
192
+ }
193
+ catch (error) {
194
+ if (!(error instanceof Error)) {
195
+ throw error;
196
+ }
197
+ if (error.message.includes('Unexpected token')) {
198
+ return false;
199
+ }
200
+ return false;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
206
+ *
207
+ * @public exported from `@promptbook/core`
208
+ */
209
+ var ParseError = /** @class */ (function (_super) {
210
+ __extends(ParseError, _super);
211
+ function ParseError(message) {
212
+ var _this = _super.call(this, message) || this;
213
+ _this.name = 'ParseError';
214
+ Object.setPrototypeOf(_this, ParseError.prototype);
215
+ return _this;
216
+ }
217
+ return ParseError;
218
+ }(Error));
219
+ /**
220
+ * TODO: Maybe split `ParseError` and `ApplyError`
221
+ */
222
+
223
+ /**
224
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
225
+ * 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.
226
+ *
227
+ * @param {string} pipelineString the candidate for a pipeline string
228
+ * @returns {PipelineString} the same string as input, but validated as valid
229
+ * @throws {ParseError} if the string is not a valid pipeline string
230
+ * @public exported from `@promptbook/core`
231
+ */
232
+ function validatePipelineString(pipelineString) {
233
+ if (isValidJsonString(pipelineString)) {
234
+ throw new ParseError('Expected a book, but got a JSON string');
235
+ }
236
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
237
+ return pipelineString;
238
+ }
239
+ /**
240
+ * TODO: [🧠][🈴] Where is the best location for this file
241
+ */
182
242
 
183
243
  /**
184
244
  * Prettify the html code
@@ -246,7 +306,7 @@
246
306
  if (bookVersion !== "undefined") {
247
307
  commands.push("BOOK VERSION ".concat(bookVersion));
248
308
  }
249
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
309
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
250
310
  pipelineString = prettifyMarkdown(pipelineString);
251
311
  try {
252
312
  for (var _g = __values(parameters.filter(function (_a) {
@@ -394,12 +454,12 @@
394
454
  pipelineString += '```' + contentLanguage;
395
455
  pipelineString += '\n';
396
456
  pipelineString += spaceTrim__default["default"](content);
397
- // <- TODO: [main] !!! Escape
457
+ // <- TODO: [main] !!3 Escape
398
458
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
399
459
  pipelineString += '\n';
400
460
  pipelineString += '```';
401
461
  pipelineString += '\n\n';
402
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
462
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
403
463
  }
404
464
  }
405
465
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -409,7 +469,7 @@
409
469
  }
410
470
  finally { if (e_3) throw e_3.error; }
411
471
  }
412
- return pipelineString;
472
+ return validatePipelineString(pipelineString);
413
473
  }
414
474
  /**
415
475
  * @private internal utility of `pipelineJsonToString`
@@ -470,6 +530,12 @@
470
530
  * @public exported from `@promptbook/core`
471
531
  */
472
532
  var ADMIN_GITHUB_NAME = 'hejny';
533
+ /**
534
+ * When the title is not provided, the default title is used
535
+ *
536
+ * @public exported from `@promptbook/core`
537
+ */
538
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
473
539
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
474
540
  /**
475
541
  * The maximum number of iterations for a loops
@@ -621,7 +687,7 @@
621
687
  /**
622
688
  * Make error report URL for the given error
623
689
  *
624
- * @private !!!!!!
690
+ * @private private within the repository
625
691
  */
626
692
  function getErrorReportUrl(error) {
627
693
  var report = {
@@ -742,7 +808,7 @@
742
808
  if (!(error instanceof Error)) {
743
809
  throw error;
744
810
  }
745
- throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
811
+ throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
746
812
  }
747
813
  /*
748
814
  TODO: [0] Is there some more elegant way to check circular references?
@@ -772,7 +838,7 @@
772
838
  }
773
839
  /**
774
840
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
775
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
841
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
776
842
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
777
843
  */
778
844
 
@@ -784,7 +850,6 @@
784
850
  function deepClone(objectValue) {
785
851
  return JSON.parse(JSON.stringify(objectValue));
786
852
  /*
787
- !!!!!!!!
788
853
  TODO: [🧠] Is there a better implementation?
789
854
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
790
855
  > for (const propertyName of propertyNames) {
@@ -896,25 +961,6 @@
896
961
  * Note: [💞] Ignore a discrepancy between file name and entity name
897
962
  */
898
963
 
899
- /**
900
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
901
- *
902
- * @public exported from `@promptbook/core`
903
- */
904
- var ParseError = /** @class */ (function (_super) {
905
- __extends(ParseError, _super);
906
- function ParseError(message) {
907
- var _this = _super.call(this, message) || this;
908
- _this.name = 'ParseError';
909
- Object.setPrototypeOf(_this, ParseError.prototype);
910
- return _this;
911
- }
912
- return ParseError;
913
- }(Error));
914
- /**
915
- * TODO: Maybe split `ParseError` and `ApplyError`
916
- */
917
-
918
964
  /**
919
965
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
920
966
  *
@@ -969,7 +1015,7 @@
969
1015
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
970
1016
  return false;
971
1017
  }
972
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1018
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
973
1019
  return true;
974
1020
  }
975
1021
 
@@ -1069,9 +1115,6 @@
1069
1115
  if (!url.startsWith('https://')) {
1070
1116
  return false;
1071
1117
  }
1072
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1073
- return false;
1074
- }
1075
1118
  if (url.includes('#')) {
1076
1119
  // TODO: [🐠]
1077
1120
  return false;
@@ -1102,11 +1145,11 @@
1102
1145
  */
1103
1146
  function validatePipeline(pipeline) {
1104
1147
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1105
- validatePipelineCore(pipeline);
1148
+ validatePipeline_InnerFunction(pipeline);
1106
1149
  }
1107
1150
  else {
1108
1151
  try {
1109
- validatePipelineCore(pipeline);
1152
+ validatePipeline_InnerFunction(pipeline);
1110
1153
  }
1111
1154
  catch (error) {
1112
1155
  if (!(error instanceof PipelineLogicError)) {
@@ -1120,7 +1163,7 @@
1120
1163
  /**
1121
1164
  * @private internal function for `validatePipeline`
1122
1165
  */
1123
- function validatePipelineCore(pipeline) {
1166
+ function validatePipeline_InnerFunction(pipeline) {
1124
1167
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1125
1168
  var e_1, _a, e_2, _b, e_3, _c;
1126
1169
  var pipelineIdentification = (function () {
@@ -1344,11 +1387,11 @@
1344
1387
  _loop_3();
1345
1388
  }
1346
1389
  // Note: Check that formfactor is corresponding to the pipeline interface
1347
- // TODO: !!!!!! Implement this
1390
+ // TODO: !!6 Implement this
1348
1391
  // pipeline.formfactorName
1349
1392
  }
1350
1393
  /**
1351
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
1394
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
1352
1395
  * TODO: [🧠] Work with promptbookVersion
1353
1396
  * TODO: Use here some json-schema, Zod or something similar and change it to:
1354
1397
  * > /**
@@ -1360,11 +1403,11 @@
1360
1403
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
1361
1404
  */
1362
1405
  /**
1363
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
1364
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
1365
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
1366
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1367
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
1406
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
1407
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
1408
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
1409
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1410
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
1368
1411
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
1369
1412
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
1370
1413
  */
@@ -1500,7 +1543,7 @@
1500
1543
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1501
1544
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1502
1545
  var existing = this.collection.get(pipeline.pipelineUrl);
1503
- throw new PipelineUrlError(spaceTrim.spaceTrim("\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 ")));
1546
+ throw new PipelineUrlError(spaceTrim.spaceTrim("\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 ")));
1504
1547
  }
1505
1548
  // Note: [🧠] Overwrite existing pipeline with the same URL
1506
1549
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1820,11 +1863,16 @@
1820
1863
  /**
1821
1864
  * Determine if the pipeline is fully prepared
1822
1865
  *
1866
+ * @see https://github.com/webgptorg/promptbook/discussions/196
1867
+ *
1823
1868
  * @public exported from `@promptbook/core`
1824
1869
  */
1825
1870
  function isPipelinePrepared(pipeline) {
1826
1871
  // Note: Ignoring `pipeline.preparations` @@@
1827
1872
  // Note: Ignoring `pipeline.knowledgePieces` @@@
1873
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
1874
+ return false;
1875
+ }
1828
1876
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
1829
1877
  return false;
1830
1878
  }
@@ -1840,7 +1888,7 @@
1840
1888
  return true;
1841
1889
  }
1842
1890
  /**
1843
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
1891
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
1844
1892
  * TODO: [🐠] Maybe base this on `makeValidator`
1845
1893
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
1846
1894
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -2605,10 +2653,10 @@
2605
2653
  });
2606
2654
  }
2607
2655
  /**
2608
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
2609
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
2610
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
2611
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
2656
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
2657
+ * TODO: [🏢] Check validity of `modelName` in pipeline
2658
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
2659
+ * TODO: [🏢] Check validity of `temperature` in pipeline
2612
2660
  */
2613
2661
 
2614
2662
  /**
@@ -3303,21 +3351,44 @@
3303
3351
  if (typeof filename !== 'string') {
3304
3352
  return false;
3305
3353
  }
3354
+ if (filename.split('\n').length > 1) {
3355
+ return false;
3356
+ }
3357
+ if (filename.split(' ').length >
3358
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
3359
+ return false;
3360
+ }
3306
3361
  var filenameSlashes = filename.split('\\').join('/');
3307
3362
  // Absolute Unix path: /hello.txt
3308
3363
  if (/^(\/)/i.test(filenameSlashes)) {
3364
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
3309
3365
  return true;
3310
3366
  }
3311
3367
  // Absolute Windows path: /hello.txt
3312
3368
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
3369
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
3313
3370
  return true;
3314
3371
  }
3315
3372
  // Relative path: ./hello.txt
3316
3373
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
3374
+ // console.log(filename, 'Relative path: ./hello.txt');
3375
+ return true;
3376
+ }
3377
+ // Allow paths like foo/hello
3378
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
3379
+ // console.log(filename, 'Allow paths like foo/hello');
3380
+ return true;
3381
+ }
3382
+ // Allow paths like hello.book
3383
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
3384
+ // console.log(filename, 'Allow paths like hello.book');
3317
3385
  return true;
3318
3386
  }
3319
3387
  return false;
3320
3388
  }
3389
+ /**
3390
+ * TODO: [🍏] Implement for MacOs
3391
+ */
3321
3392
 
3322
3393
  /**
3323
3394
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -3342,6 +3413,9 @@
3342
3413
  }
3343
3414
  });
3344
3415
  }); };
3416
+ /**
3417
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3418
+ */
3345
3419
 
3346
3420
  /**
3347
3421
  * @@@
@@ -3409,7 +3483,7 @@
3409
3483
  },
3410
3484
  }];
3411
3485
  case 2:
3412
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3486
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3413
3487
  if (tools.fs === undefined) {
3414
3488
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3415
3489
  // <- TODO: [🧠] What is the best error type here`
@@ -3424,7 +3498,7 @@
3424
3498
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3425
3499
  case 3:
3426
3500
  if (!(_f.sent())) {
3427
- throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3501
+ throw new NotFoundError(spaceTrim__default["default"](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 "); }));
3428
3502
  }
3429
3503
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3430
3504
  return [2 /*return*/, {
@@ -3537,7 +3611,7 @@
3537
3611
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
3538
3612
  return [2 /*return*/, "break"];
3539
3613
  }
3540
- console.warn(spaceTrim__default["default"](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
3614
+ console.warn(spaceTrim__default["default"](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
3541
3615
  .split('\n')
3542
3616
  .map(function (line) { return "> ".concat(line); })
3543
3617
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3575,7 +3649,7 @@
3575
3649
  return [7 /*endfinally*/];
3576
3650
  case 9:
3577
3651
  if (partialPieces === null) {
3578
- throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
3652
+ throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
3579
3653
  .split('\n')
3580
3654
  .map(function (line) { return "> ".concat(line); })
3581
3655
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3666,7 +3740,7 @@
3666
3740
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3667
3741
  * TODO: [🧠] Add context to each task (if missing)
3668
3742
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3669
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
3743
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
3670
3744
  * TODO: Write tests for `preparePipeline`
3671
3745
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3672
3746
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -3674,7 +3748,9 @@
3674
3748
  */
3675
3749
 
3676
3750
  /**
3677
- * Prepare pipeline from string (markdown) format to JSON format
3751
+ * Prepare pipeline locally
3752
+ *
3753
+ * @see https://github.com/webgptorg/promptbook/discussions/196
3678
3754
  *
3679
3755
  * Note: This function does not validate logic of the pipeline
3680
3756
  * Note: This function acts as part of compilation process
@@ -3688,16 +3764,17 @@
3688
3764
  <- TODO: [🧠][🪑] `promptbookVersion` */
3689
3765
  knowledgeSources /*
3690
3766
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3691
- <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
3767
+ <- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
3768
+ var _d;
3692
3769
  var _this = this;
3693
- return __generator(this, function (_c) {
3694
- switch (_c.label) {
3770
+ return __generator(this, function (_e) {
3771
+ switch (_e.label) {
3695
3772
  case 0:
3696
3773
  if (isPipelinePrepared(pipeline)) {
3697
3774
  return [2 /*return*/, pipeline];
3698
3775
  }
3699
3776
  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;
3700
- parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3777
+ parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
3701
3778
  if (tools === undefined || tools.llm === undefined) {
3702
3779
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
3703
3780
  }
@@ -3715,6 +3792,33 @@
3715
3792
  // <- TODO: [🧊]
3716
3793
  currentPreparation,
3717
3794
  ];
3795
+ title = pipeline.title;
3796
+ if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
3797
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
3798
+ _c = createPipelineExecutor;
3799
+ _d = {};
3800
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
3801
+ case 1:
3802
+ prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
3803
+ _d.tools = tools,
3804
+ _d)]);
3805
+ return [4 /*yield*/, prepareTitleExecutor({
3806
+ book: sources.map(function (_a) {
3807
+ var content = _a.content;
3808
+ return content;
3809
+ }).join('\n\n'),
3810
+ })];
3811
+ case 2:
3812
+ result = _e.sent();
3813
+ assertsExecutionSuccessful(result);
3814
+ outputParameters = result.outputParameters;
3815
+ titleRaw = outputParameters.title;
3816
+ if (isVerbose) {
3817
+ console.info("The title is \"".concat(titleRaw, "\""));
3818
+ }
3819
+ title = titleRaw || DEFAULT_BOOK_TITLE;
3820
+ _e.label = 3;
3821
+ case 3:
3718
3822
  preparedPersonas = new Array(personas.length);
3719
3823
  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 () {
3720
3824
  var modelRequirements, preparedPersona;
@@ -3733,12 +3837,12 @@
3733
3837
  }
3734
3838
  });
3735
3839
  }); })];
3736
- case 1:
3737
- _c.sent();
3840
+ case 4:
3841
+ _e.sent();
3738
3842
  knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3739
3843
  return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
3740
- case 2:
3741
- partialknowledgePiecesPrepared = _c.sent();
3844
+ case 5:
3845
+ partialknowledgePiecesPrepared = _e.sent();
3742
3846
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3743
3847
  return [4 /*yield*/, prepareTasks({
3744
3848
  parameters: parameters,
@@ -3749,8 +3853,8 @@
3749
3853
  maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
3750
3854
  isVerbose: isVerbose,
3751
3855
  })];
3752
- case 3:
3753
- tasksPrepared = (_c.sent()).tasksPrepared;
3856
+ case 6:
3857
+ tasksPrepared = (_e.sent()).tasksPrepared;
3754
3858
  // ----- /Tasks preparation -----
3755
3859
  // TODO: [😂] Use here all `AsyncHighLevelAbstraction`
3756
3860
  // Note: Count total usage
@@ -3761,7 +3865,7 @@
3761
3865
  order: ORDER_OF_PIPELINE_JSON,
3762
3866
  value: __assign(__assign({}, pipeline), {
3763
3867
  // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
3764
- knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
3868
+ title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
3765
3869
  // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
3766
3870
  personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
3767
3871
  })];
@@ -3770,7 +3874,7 @@
3770
3874
  });
3771
3875
  }
3772
3876
  /**
3773
- * TODO: Write tests for `preparePipeline`
3877
+ * TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
3774
3878
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3775
3879
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3776
3880
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
@@ -3832,7 +3936,7 @@
3832
3936
  if (!(error instanceof Error)) {
3833
3937
  throw error;
3834
3938
  }
3835
- throw new ParseError(spaceTrim.spaceTrim(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)
3939
+ throw new ParseError(spaceTrim.spaceTrim(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)
3836
3940
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
3837
3941
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
3838
3942
  }
@@ -4112,27 +4216,6 @@
4112
4216
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4113
4217
  */
4114
4218
 
4115
- /**
4116
- * Function isValidJsonString will tell you if the string is valid JSON or not
4117
- *
4118
- * @public exported from `@promptbook/utils`
4119
- */
4120
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
4121
- try {
4122
- JSON.parse(value);
4123
- return true;
4124
- }
4125
- catch (error) {
4126
- if (!(error instanceof Error)) {
4127
- throw error;
4128
- }
4129
- if (error.message.includes('Unexpected token')) {
4130
- return false;
4131
- }
4132
- return false;
4133
- }
4134
- }
4135
-
4136
4219
  /**
4137
4220
  * Definition for JSON format
4138
4221
  *
@@ -4507,6 +4590,8 @@
4507
4590
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4508
4591
  }
4509
4592
  parameterValue = valueToString(parameterValue);
4593
+ // Escape curly braces in parameter values to prevent prompt-injection
4594
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4510
4595
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4511
4596
  parameterValue = parameterValue
4512
4597
  .split('\n')
@@ -4866,7 +4951,7 @@
4866
4951
  promptTitle: task.title,
4867
4952
  promptMessage: templateParameters(task.description || '', parameters),
4868
4953
  defaultValue: templateParameters(preparedContent, parameters),
4869
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4954
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
4870
4955
  placeholder: undefined,
4871
4956
  priority: priority,
4872
4957
  }))];
@@ -5856,6 +5941,7 @@
5856
5941
  mimeTypes: ['text/markdown', 'text/plain'],
5857
5942
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5858
5943
  isAvilableInBrowser: true,
5944
+ // <- 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
5859
5945
  requiredExecutables: [],
5860
5946
  }); /* <- Note: [🤛] */
5861
5947
  /**
@@ -5864,6 +5950,7 @@
5864
5950
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
5865
5951
  *
5866
5952
  * @public exported from `@promptbook/core`
5953
+ * @public exported from `@promptbook/wizzard`
5867
5954
  * @public exported from `@promptbook/cli`
5868
5955
  */
5869
5956
  $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -5949,12 +6036,12 @@
5949
6036
  outputParameters = result.outputParameters;
5950
6037
  knowledgePiecesRaw = outputParameters.knowledgePieces;
5951
6038
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
5952
- // <- TODO: [main] !! Smarter split and filter out empty pieces
6039
+ // <- TODO: [main] Smarter split and filter out empty pieces
5953
6040
  if (isVerbose) {
5954
6041
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
5955
6042
  }
5956
6043
  return [4 /*yield*/, Promise.all(
5957
- // TODO: [🪂] !! Do not send all at once but in chunks
6044
+ // TODO: [🪂] Do not send all at once but in chunks
5958
6045
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
5959
6046
  var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
5960
6047
  return __generator(this, function (_c) {
@@ -6052,7 +6139,8 @@
6052
6139
  className: 'PdfScraper',
6053
6140
  mimeTypes: ['application/pdf'],
6054
6141
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6055
- isAvilableInBrowser: true,
6142
+ isAvilableInBrowser: false,
6143
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
6056
6144
  requiredExecutables: [],
6057
6145
  }); /* <- Note: [🤛] */
6058
6146
  /**
@@ -6061,6 +6149,7 @@
6061
6149
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6062
6150
  *
6063
6151
  * @public exported from `@promptbook/core`
6152
+ * @public exported from `@promptbook/wizzard`
6064
6153
  * @public exported from `@promptbook/cli`
6065
6154
  */
6066
6155
  $scrapersMetadataRegister.register(pdfScraperMetadata);
@@ -6125,6 +6214,7 @@
6125
6214
  * TODO: [👣] Converted pdf documents can act as cached items - there is no need to run conversion each time
6126
6215
  * TODO: [🪂] Do it in parallel 11:11
6127
6216
  * Note: No need to aggregate usage here, it is done by intercepting the llmTools
6217
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6128
6218
  */
6129
6219
 
6130
6220
  /**
@@ -6145,6 +6235,7 @@
6145
6235
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6146
6236
  *
6147
6237
  * @public exported from `@promptbook/pdf`
6238
+ * @public exported from `@promptbook/wizzard`
6148
6239
  * @public exported from `@promptbook/cli`
6149
6240
  */
6150
6241
  var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);