@promptbook/legacy-documents 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 -92
  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 -92
  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
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -190,6 +190,12 @@
190
190
  * @public exported from `@promptbook/core`
191
191
  */
192
192
  var ADMIN_GITHUB_NAME = 'hejny';
193
+ /**
194
+ * When the title is not provided, the default title is used
195
+ *
196
+ * @public exported from `@promptbook/core`
197
+ */
198
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
193
199
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
194
200
  /**
195
201
  * The maximum number of iterations for a loops
@@ -339,7 +345,7 @@
339
345
  /**
340
346
  * Make error report URL for the given error
341
347
  *
342
- * @private !!!!!!
348
+ * @private private within the repository
343
349
  */
344
350
  function getErrorReportUrl(error) {
345
351
  var report = {
@@ -945,21 +951,44 @@
945
951
  if (typeof filename !== 'string') {
946
952
  return false;
947
953
  }
954
+ if (filename.split('\n').length > 1) {
955
+ return false;
956
+ }
957
+ if (filename.split(' ').length >
958
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
959
+ return false;
960
+ }
948
961
  var filenameSlashes = filename.split('\\').join('/');
949
962
  // Absolute Unix path: /hello.txt
950
963
  if (/^(\/)/i.test(filenameSlashes)) {
964
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
951
965
  return true;
952
966
  }
953
967
  // Absolute Windows path: /hello.txt
954
968
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
969
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
955
970
  return true;
956
971
  }
957
972
  // Relative path: ./hello.txt
958
973
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
974
+ // console.log(filename, 'Relative path: ./hello.txt');
975
+ return true;
976
+ }
977
+ // Allow paths like foo/hello
978
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
979
+ // console.log(filename, 'Allow paths like foo/hello');
980
+ return true;
981
+ }
982
+ // Allow paths like hello.book
983
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
984
+ // console.log(filename, 'Allow paths like hello.book');
959
985
  return true;
960
986
  }
961
987
  return false;
962
988
  }
989
+ /**
990
+ * TODO: [🍏] Implement for MacOs
991
+ */
963
992
 
964
993
  /**
965
994
  * Tests if given string is valid URL.
@@ -1085,7 +1114,67 @@
1085
1114
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1086
1115
  */
1087
1116
 
1088
- 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"}];
1117
+ 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"}];
1118
+
1119
+ /**
1120
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1121
+ *
1122
+ * @public exported from `@promptbook/utils`
1123
+ */
1124
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1125
+ try {
1126
+ JSON.parse(value);
1127
+ return true;
1128
+ }
1129
+ catch (error) {
1130
+ if (!(error instanceof Error)) {
1131
+ throw error;
1132
+ }
1133
+ if (error.message.includes('Unexpected token')) {
1134
+ return false;
1135
+ }
1136
+ return false;
1137
+ }
1138
+ }
1139
+
1140
+ /**
1141
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1142
+ *
1143
+ * @public exported from `@promptbook/core`
1144
+ */
1145
+ var ParseError = /** @class */ (function (_super) {
1146
+ __extends(ParseError, _super);
1147
+ function ParseError(message) {
1148
+ var _this = _super.call(this, message) || this;
1149
+ _this.name = 'ParseError';
1150
+ Object.setPrototypeOf(_this, ParseError.prototype);
1151
+ return _this;
1152
+ }
1153
+ return ParseError;
1154
+ }(Error));
1155
+ /**
1156
+ * TODO: Maybe split `ParseError` and `ApplyError`
1157
+ */
1158
+
1159
+ /**
1160
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1161
+ * 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.
1162
+ *
1163
+ * @param {string} pipelineString the candidate for a pipeline string
1164
+ * @returns {PipelineString} the same string as input, but validated as valid
1165
+ * @throws {ParseError} if the string is not a valid pipeline string
1166
+ * @public exported from `@promptbook/core`
1167
+ */
1168
+ function validatePipelineString(pipelineString) {
1169
+ if (isValidJsonString(pipelineString)) {
1170
+ throw new ParseError('Expected a book, but got a JSON string');
1171
+ }
1172
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1173
+ return pipelineString;
1174
+ }
1175
+ /**
1176
+ * TODO: [🧠][🈴] Where is the best location for this file
1177
+ */
1089
1178
 
1090
1179
  /**
1091
1180
  * Prettify the html code
@@ -1153,7 +1242,7 @@
1153
1242
  if (bookVersion !== "undefined") {
1154
1243
  commands.push("BOOK VERSION ".concat(bookVersion));
1155
1244
  }
1156
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
1245
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
1157
1246
  pipelineString = prettifyMarkdown(pipelineString);
1158
1247
  try {
1159
1248
  for (var _g = __values(parameters.filter(function (_a) {
@@ -1301,12 +1390,12 @@
1301
1390
  pipelineString += '```' + contentLanguage;
1302
1391
  pipelineString += '\n';
1303
1392
  pipelineString += spaceTrim__default["default"](content);
1304
- // <- TODO: [main] !!! Escape
1393
+ // <- TODO: [main] !!3 Escape
1305
1394
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1306
1395
  pipelineString += '\n';
1307
1396
  pipelineString += '```';
1308
1397
  pipelineString += '\n\n';
1309
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
1398
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
1310
1399
  }
1311
1400
  }
1312
1401
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -1316,7 +1405,7 @@
1316
1405
  }
1317
1406
  finally { if (e_3) throw e_3.error; }
1318
1407
  }
1319
- return pipelineString;
1408
+ return validatePipelineString(pipelineString);
1320
1409
  }
1321
1410
  /**
1322
1411
  * @private internal utility of `pipelineJsonToString`
@@ -1477,7 +1566,7 @@
1477
1566
  if (!(error instanceof Error)) {
1478
1567
  throw error;
1479
1568
  }
1480
- 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 "); }));
1569
+ 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 "); }));
1481
1570
  }
1482
1571
  /*
1483
1572
  TODO: [0] Is there some more elegant way to check circular references?
@@ -1507,7 +1596,7 @@
1507
1596
  }
1508
1597
  /**
1509
1598
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
1510
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1599
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
1511
1600
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1512
1601
  */
1513
1602
 
@@ -1519,7 +1608,6 @@
1519
1608
  function deepClone(objectValue) {
1520
1609
  return JSON.parse(JSON.stringify(objectValue));
1521
1610
  /*
1522
- !!!!!!!!
1523
1611
  TODO: [🧠] Is there a better implementation?
1524
1612
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
1525
1613
  > for (const propertyName of propertyNames) {
@@ -1631,25 +1719,6 @@
1631
1719
  * Note: [💞] Ignore a discrepancy between file name and entity name
1632
1720
  */
1633
1721
 
1634
- /**
1635
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1636
- *
1637
- * @public exported from `@promptbook/core`
1638
- */
1639
- var ParseError = /** @class */ (function (_super) {
1640
- __extends(ParseError, _super);
1641
- function ParseError(message) {
1642
- var _this = _super.call(this, message) || this;
1643
- _this.name = 'ParseError';
1644
- Object.setPrototypeOf(_this, ParseError.prototype);
1645
- return _this;
1646
- }
1647
- return ParseError;
1648
- }(Error));
1649
- /**
1650
- * TODO: Maybe split `ParseError` and `ApplyError`
1651
- */
1652
-
1653
1722
  /**
1654
1723
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1655
1724
  *
@@ -1704,7 +1773,7 @@
1704
1773
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1705
1774
  return false;
1706
1775
  }
1707
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1776
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1708
1777
  return true;
1709
1778
  }
1710
1779
 
@@ -1775,9 +1844,6 @@
1775
1844
  if (!url.startsWith('https://')) {
1776
1845
  return false;
1777
1846
  }
1778
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1779
- return false;
1780
- }
1781
1847
  if (url.includes('#')) {
1782
1848
  // TODO: [🐠]
1783
1849
  return false;
@@ -1808,11 +1874,11 @@
1808
1874
  */
1809
1875
  function validatePipeline(pipeline) {
1810
1876
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1811
- validatePipelineCore(pipeline);
1877
+ validatePipeline_InnerFunction(pipeline);
1812
1878
  }
1813
1879
  else {
1814
1880
  try {
1815
- validatePipelineCore(pipeline);
1881
+ validatePipeline_InnerFunction(pipeline);
1816
1882
  }
1817
1883
  catch (error) {
1818
1884
  if (!(error instanceof PipelineLogicError)) {
@@ -1826,7 +1892,7 @@
1826
1892
  /**
1827
1893
  * @private internal function for `validatePipeline`
1828
1894
  */
1829
- function validatePipelineCore(pipeline) {
1895
+ function validatePipeline_InnerFunction(pipeline) {
1830
1896
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1831
1897
  var e_1, _a, e_2, _b, e_3, _c;
1832
1898
  var pipelineIdentification = (function () {
@@ -2050,11 +2116,11 @@
2050
2116
  _loop_3();
2051
2117
  }
2052
2118
  // Note: Check that formfactor is corresponding to the pipeline interface
2053
- // TODO: !!!!!! Implement this
2119
+ // TODO: !!6 Implement this
2054
2120
  // pipeline.formfactorName
2055
2121
  }
2056
2122
  /**
2057
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
2123
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
2058
2124
  * TODO: [🧠] Work with promptbookVersion
2059
2125
  * TODO: Use here some json-schema, Zod or something similar and change it to:
2060
2126
  * > /**
@@ -2066,11 +2132,11 @@
2066
2132
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
2067
2133
  */
2068
2134
  /**
2069
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
2070
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
2071
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
2072
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
2073
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
2135
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
2136
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
2137
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
2138
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
2139
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
2074
2140
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
2075
2141
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2076
2142
  */
@@ -2206,7 +2272,7 @@
2206
2272
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
2207
2273
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
2208
2274
  var existing = this.collection.get(pipeline.pipelineUrl);
2209
- 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 ")));
2275
+ 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 ")));
2210
2276
  }
2211
2277
  // Note: [🧠] Overwrite existing pipeline with the same URL
2212
2278
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -2494,11 +2560,16 @@
2494
2560
  /**
2495
2561
  * Determine if the pipeline is fully prepared
2496
2562
  *
2563
+ * @see https://github.com/webgptorg/promptbook/discussions/196
2564
+ *
2497
2565
  * @public exported from `@promptbook/core`
2498
2566
  */
2499
2567
  function isPipelinePrepared(pipeline) {
2500
2568
  // Note: Ignoring `pipeline.preparations` @@@
2501
2569
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2570
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2571
+ return false;
2572
+ }
2502
2573
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2503
2574
  return false;
2504
2575
  }
@@ -2514,7 +2585,7 @@
2514
2585
  return true;
2515
2586
  }
2516
2587
  /**
2517
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
2588
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2518
2589
  * TODO: [🐠] Maybe base this on `makeValidator`
2519
2590
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2520
2591
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -3279,10 +3350,10 @@
3279
3350
  });
3280
3351
  }
3281
3352
  /**
3282
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
3283
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
3284
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
3285
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
3353
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
3354
+ * TODO: [🏢] Check validity of `modelName` in pipeline
3355
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
3356
+ * TODO: [🏢] Check validity of `temperature` in pipeline
3286
3357
  */
3287
3358
 
3288
3359
  /**
@@ -3621,6 +3692,9 @@
3621
3692
  }
3622
3693
  });
3623
3694
  }); };
3695
+ /**
3696
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3697
+ */
3624
3698
 
3625
3699
  /**
3626
3700
  * @@@
@@ -3688,7 +3762,7 @@
3688
3762
  },
3689
3763
  }];
3690
3764
  case 2:
3691
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3765
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3692
3766
  if (tools.fs === undefined) {
3693
3767
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3694
3768
  // <- TODO: [🧠] What is the best error type here`
@@ -3703,7 +3777,7 @@
3703
3777
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3704
3778
  case 3:
3705
3779
  if (!(_f.sent())) {
3706
- 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 "); }));
3780
+ 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 "); }));
3707
3781
  }
3708
3782
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3709
3783
  return [2 /*return*/, {
@@ -3816,7 +3890,7 @@
3816
3890
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
3817
3891
  return [2 /*return*/, "break"];
3818
3892
  }
3819
- 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
3893
+ 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
3820
3894
  .split('\n')
3821
3895
  .map(function (line) { return "> ".concat(line); })
3822
3896
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3854,7 +3928,7 @@
3854
3928
  return [7 /*endfinally*/];
3855
3929
  case 9:
3856
3930
  if (partialPieces === null) {
3857
- throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
3931
+ throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
3858
3932
  .split('\n')
3859
3933
  .map(function (line) { return "> ".concat(line); })
3860
3934
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -3945,7 +4019,7 @@
3945
4019
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3946
4020
  * TODO: [🧠] Add context to each task (if missing)
3947
4021
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3948
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
4022
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
3949
4023
  * TODO: Write tests for `preparePipeline`
3950
4024
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3951
4025
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -3953,7 +4027,9 @@
3953
4027
  */
3954
4028
 
3955
4029
  /**
3956
- * Prepare pipeline from string (markdown) format to JSON format
4030
+ * Prepare pipeline locally
4031
+ *
4032
+ * @see https://github.com/webgptorg/promptbook/discussions/196
3957
4033
  *
3958
4034
  * Note: This function does not validate logic of the pipeline
3959
4035
  * Note: This function acts as part of compilation process
@@ -3967,16 +4043,17 @@
3967
4043
  <- TODO: [🧠][🪑] `promptbookVersion` */
3968
4044
  knowledgeSources /*
3969
4045
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3970
- <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
4046
+ <- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
4047
+ var _d;
3971
4048
  var _this = this;
3972
- return __generator(this, function (_c) {
3973
- switch (_c.label) {
4049
+ return __generator(this, function (_e) {
4050
+ switch (_e.label) {
3974
4051
  case 0:
3975
4052
  if (isPipelinePrepared(pipeline)) {
3976
4053
  return [2 /*return*/, pipeline];
3977
4054
  }
3978
4055
  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;
3979
- parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
4056
+ parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
3980
4057
  if (tools === undefined || tools.llm === undefined) {
3981
4058
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
3982
4059
  }
@@ -3994,6 +4071,33 @@
3994
4071
  // <- TODO: [🧊]
3995
4072
  currentPreparation,
3996
4073
  ];
4074
+ title = pipeline.title;
4075
+ if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
4076
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
4077
+ _c = createPipelineExecutor;
4078
+ _d = {};
4079
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
4080
+ case 1:
4081
+ prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
4082
+ _d.tools = tools,
4083
+ _d)]);
4084
+ return [4 /*yield*/, prepareTitleExecutor({
4085
+ book: sources.map(function (_a) {
4086
+ var content = _a.content;
4087
+ return content;
4088
+ }).join('\n\n'),
4089
+ })];
4090
+ case 2:
4091
+ result = _e.sent();
4092
+ assertsExecutionSuccessful(result);
4093
+ outputParameters = result.outputParameters;
4094
+ titleRaw = outputParameters.title;
4095
+ if (isVerbose) {
4096
+ console.info("The title is \"".concat(titleRaw, "\""));
4097
+ }
4098
+ title = titleRaw || DEFAULT_BOOK_TITLE;
4099
+ _e.label = 3;
4100
+ case 3:
3997
4101
  preparedPersonas = new Array(personas.length);
3998
4102
  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 () {
3999
4103
  var modelRequirements, preparedPersona;
@@ -4012,12 +4116,12 @@
4012
4116
  }
4013
4117
  });
4014
4118
  }); })];
4015
- case 1:
4016
- _c.sent();
4119
+ case 4:
4120
+ _e.sent();
4017
4121
  knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
4018
4122
  return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
4019
- case 2:
4020
- partialknowledgePiecesPrepared = _c.sent();
4123
+ case 5:
4124
+ partialknowledgePiecesPrepared = _e.sent();
4021
4125
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
4022
4126
  return [4 /*yield*/, prepareTasks({
4023
4127
  parameters: parameters,
@@ -4028,8 +4132,8 @@
4028
4132
  maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
4029
4133
  isVerbose: isVerbose,
4030
4134
  })];
4031
- case 3:
4032
- tasksPrepared = (_c.sent()).tasksPrepared;
4135
+ case 6:
4136
+ tasksPrepared = (_e.sent()).tasksPrepared;
4033
4137
  // ----- /Tasks preparation -----
4034
4138
  // TODO: [😂] Use here all `AsyncHighLevelAbstraction`
4035
4139
  // Note: Count total usage
@@ -4040,7 +4144,7 @@
4040
4144
  order: ORDER_OF_PIPELINE_JSON,
4041
4145
  value: __assign(__assign({}, pipeline), {
4042
4146
  // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
4043
- knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
4147
+ title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
4044
4148
  // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
4045
4149
  personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
4046
4150
  })];
@@ -4049,7 +4153,7 @@
4049
4153
  });
4050
4154
  }
4051
4155
  /**
4052
- * TODO: Write tests for `preparePipeline`
4156
+ * TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
4053
4157
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
4054
4158
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
4055
4159
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
@@ -4111,7 +4215,7 @@
4111
4215
  if (!(error instanceof Error)) {
4112
4216
  throw error;
4113
4217
  }
4114
- 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)
4218
+ 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)
4115
4219
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
4116
4220
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
4117
4221
  }
@@ -4391,27 +4495,6 @@
4391
4495
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4392
4496
  */
4393
4497
 
4394
- /**
4395
- * Function isValidJsonString will tell you if the string is valid JSON or not
4396
- *
4397
- * @public exported from `@promptbook/utils`
4398
- */
4399
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
4400
- try {
4401
- JSON.parse(value);
4402
- return true;
4403
- }
4404
- catch (error) {
4405
- if (!(error instanceof Error)) {
4406
- throw error;
4407
- }
4408
- if (error.message.includes('Unexpected token')) {
4409
- return false;
4410
- }
4411
- return false;
4412
- }
4413
- }
4414
-
4415
4498
  /**
4416
4499
  * Definition for JSON format
4417
4500
  *
@@ -4786,6 +4869,8 @@
4786
4869
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4787
4870
  }
4788
4871
  parameterValue = valueToString(parameterValue);
4872
+ // Escape curly braces in parameter values to prevent prompt-injection
4873
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4789
4874
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4790
4875
  parameterValue = parameterValue
4791
4876
  .split('\n')
@@ -5145,7 +5230,7 @@
5145
5230
  promptTitle: task.title,
5146
5231
  promptMessage: templateParameters(task.description || '', parameters),
5147
5232
  defaultValue: templateParameters(preparedContent, parameters),
5148
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
5233
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
5149
5234
  placeholder: undefined,
5150
5235
  priority: priority,
5151
5236
  }))];
@@ -6095,6 +6180,7 @@
6095
6180
  mimeTypes: ['text/markdown', 'text/plain'],
6096
6181
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6097
6182
  isAvilableInBrowser: true,
6183
+ // <- 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
6098
6184
  requiredExecutables: [],
6099
6185
  }); /* <- Note: [🤛] */
6100
6186
  /**
@@ -6103,6 +6189,7 @@
6103
6189
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6104
6190
  *
6105
6191
  * @public exported from `@promptbook/core`
6192
+ * @public exported from `@promptbook/wizzard`
6106
6193
  * @public exported from `@promptbook/cli`
6107
6194
  */
6108
6195
  $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -6188,12 +6275,12 @@
6188
6275
  outputParameters = result.outputParameters;
6189
6276
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6190
6277
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
6191
- // <- TODO: [main] !! Smarter split and filter out empty pieces
6278
+ // <- TODO: [main] Smarter split and filter out empty pieces
6192
6279
  if (isVerbose) {
6193
6280
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
6194
6281
  }
6195
6282
  return [4 /*yield*/, Promise.all(
6196
- // TODO: [🪂] !! Do not send all at once but in chunks
6283
+ // TODO: [🪂] Do not send all at once but in chunks
6197
6284
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
6198
6285
  var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
6199
6286
  return __generator(this, function (_c) {
@@ -6292,6 +6379,7 @@
6292
6379
  mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
6293
6380
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6294
6381
  isAvilableInBrowser: false,
6382
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
6295
6383
  requiredExecutables: ['Pandoc'],
6296
6384
  }); /* <- Note: [🤛] */
6297
6385
  /**
@@ -6300,6 +6388,7 @@
6300
6388
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6301
6389
  *
6302
6390
  * @public exported from `@promptbook/core`
6391
+ * @public exported from `@promptbook/wizzard`
6303
6392
  * @public exported from `@promptbook/cli`
6304
6393
  */
6305
6394
  $scrapersMetadataRegister.register(documentScraperMetadata);
@@ -6455,6 +6544,7 @@
6455
6544
  mimeTypes: ['application/msword', 'text/rtf'],
6456
6545
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6457
6546
  isAvilableInBrowser: false,
6547
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
6458
6548
  requiredExecutables: [
6459
6549
  'Pandoc',
6460
6550
  'LibreOffice',
@@ -6467,6 +6557,7 @@
6467
6557
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6468
6558
  *
6469
6559
  * @public exported from `@promptbook/core`
6560
+ * @public exported from `@promptbook/wizzard`
6470
6561
  * @public exported from `@promptbook/cli`
6471
6562
  */
6472
6563
  $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
@@ -6637,6 +6728,7 @@
6637
6728
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6638
6729
  *
6639
6730
  * @public exported from `@promptbook/legacy-documents`
6731
+ * @public exported from `@promptbook/wizzard`
6640
6732
  * @public exported from `@promptbook/cli`
6641
6733
  */
6642
6734
  var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacyDocumentScraper);