@promptbook/node 0.80.0 → 0.81.0-11

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 (64) hide show
  1. package/README.md +7 -0
  2. package/esm/index.es.js +180 -32
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +15 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -6
  6. package/esm/typings/src/_packages/editable.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/templates.index.d.ts +4 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +10 -2
  10. package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
  11. package/esm/typings/src/config.d.ts +26 -0
  12. package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
  13. package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
  14. package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
  15. package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
  16. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
  17. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
  18. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
  19. package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
  20. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
  21. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
  22. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
  23. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
  24. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  25. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
  26. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
  27. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
  28. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
  29. package/esm/typings/src/other/templates/getBookTemplate.d.ts +21 -0
  30. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
  31. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
  32. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  33. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
  34. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  35. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
  36. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  37. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
  38. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  39. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
  40. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  41. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -0
  42. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  43. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
  44. package/esm/typings/src/types/typeAliases.d.ts +8 -0
  45. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
  46. package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
  47. package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
  48. package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
  49. package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
  50. package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
  51. package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
  52. package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
  53. package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
  54. package/esm/typings/src/version.d.ts +7 -0
  55. package/esm/typings/src/wizzard/wizzard.d.ts +51 -0
  56. package/package.json +2 -2
  57. package/umd/index.umd.js +180 -32
  58. package/umd/index.umd.js.map +1 -1
  59. package/esm/typings/src/utils/formatNumber.d.ts +0 -6
  60. /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
  61. /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
  62. /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
  63. /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
  64. /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/node`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -231,6 +235,7 @@ Or you can install them separately:
231
235
 
232
236
  - ⭐ **[ptbk](https://www.npmjs.com/package/ptbk)** - Bundle of all packages, when you want to install everything and you don't care about the size
233
237
  - **[promptbook](https://www.npmjs.com/package/promptbook)** - Same as `ptbk`
238
+ - ⭐🧙‍♂️ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizzard to just run the books in node without any struggle
234
239
  - **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
235
240
  - **[@promptbook/node](https://www.npmjs.com/package/@promptbook/node)** - Core of the library for Node.js environment
236
241
  - **[@promptbook/browser](https://www.npmjs.com/package/@promptbook/browser)** - Core of the library for browser environment
@@ -251,6 +256,8 @@ Or you can install them separately:
251
256
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
252
257
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
253
258
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
259
+ - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
260
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
254
261
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
255
262
  - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
256
263
 
package/esm/index.es.js CHANGED
@@ -18,15 +18,17 @@ import sha256 from 'crypto-js/sha256';
18
18
  /**
19
19
  * The version of the Book language
20
20
  *
21
+ * @generated
21
22
  * @see https://github.com/webgptorg/book
22
23
  */
23
24
  var BOOK_LANGUAGE_VERSION = '1.0.0';
24
25
  /**
25
26
  * The version of the Promptbook engine
26
27
  *
28
+ * @generated
27
29
  * @see https://github.com/webgptorg/promptbook
28
30
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-10';
30
32
  /**
31
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -204,6 +206,26 @@ var DEFAULT_TITLE = "Untitled";
204
206
  * @private within the repository - too low-level in comparison with other `MAX_...`
205
207
  */
206
208
  var LOOP_LIMIT = 1000;
209
+ /**
210
+ * Strings to represent various values in the context of parameter values
211
+ *
212
+ * @public exported from `@promptbook/utils`
213
+ */
214
+ var VALUE_STRINGS = {
215
+ empty: '(nothing; empty string)',
216
+ null: '(no value; null)',
217
+ undefined: '(unknown value; undefined)',
218
+ nan: '(not a number; NaN)',
219
+ infinity: '(infinity; ∞)',
220
+ negativeInfinity: '(negative infinity; -∞)',
221
+ unserializable: '(unserializable value)',
222
+ };
223
+ /**
224
+ * Small number limit
225
+ *
226
+ * @public exported from `@promptbook/utils`
227
+ */
228
+ var SMALL_NUMBER = 0.001;
207
229
  /**
208
230
  * Short time interval to prevent race conditions in milliseconds
209
231
  *
@@ -559,6 +581,7 @@ function exportJson(options) {
559
581
  * @public exported from `@promptbook/core`
560
582
  */
561
583
  var ORDER_OF_PIPELINE_JSON = [
584
+ // Note: [🍙] In this order will be pipeline serialized
562
585
  'title',
563
586
  'pipelineUrl',
564
587
  'bookVersion',
@@ -570,6 +593,7 @@ var ORDER_OF_PIPELINE_JSON = [
570
593
  'preparations',
571
594
  'knowledgeSources',
572
595
  'knowledgePieces',
596
+ 'sources', // <- TODO: [🧠] Where should the `sources` be
573
597
  ];
574
598
  /**
575
599
  * Nonce which is used for replacing things in strings
@@ -1228,7 +1252,7 @@ function joinLlmExecutionTools() {
1228
1252
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1229
1253
  */
1230
1254
 
1231
- 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:[],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:[],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:[],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:[],sourceFile:"./books/prepare-persona.book.md"}];
1255
+ 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"}];
1232
1256
 
1233
1257
  /**
1234
1258
  * Prettify the html code
@@ -1653,9 +1677,6 @@ function isValidPipelineUrl(url) {
1653
1677
  if (!url.startsWith('https://')) {
1654
1678
  return false;
1655
1679
  }
1656
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1657
- return false;
1658
- }
1659
1680
  if (url.includes('#')) {
1660
1681
  // TODO: [🐠]
1661
1682
  return false;
@@ -2417,6 +2438,81 @@ function isPipelinePrepared(pipeline) {
2417
2438
  * - [♨] Are tasks prepared
2418
2439
  */
2419
2440
 
2441
+ /**
2442
+ * Format either small or big number
2443
+ *
2444
+ * @public exported from `@promptbook/utils`
2445
+ */
2446
+ function numberToString(value) {
2447
+ if (value === 0) {
2448
+ return '0';
2449
+ }
2450
+ else if (Number.isNaN(value)) {
2451
+ return VALUE_STRINGS.nan;
2452
+ }
2453
+ else if (value === Infinity) {
2454
+ return VALUE_STRINGS.infinity;
2455
+ }
2456
+ else if (value === -Infinity) {
2457
+ return VALUE_STRINGS.negativeInfinity;
2458
+ }
2459
+ for (var exponent = 0; exponent < 15; exponent++) {
2460
+ var factor = Math.pow(10, exponent);
2461
+ var valueRounded = Math.round(value * factor) / factor;
2462
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2463
+ return valueRounded.toFixed(exponent);
2464
+ }
2465
+ }
2466
+ return value.toString();
2467
+ }
2468
+
2469
+ /**
2470
+ * Function `valueToString` will convert the given value to string
2471
+ * This is useful and used in the `templateParameters` function
2472
+ *
2473
+ * Note: This function is not just calling `toString` method
2474
+ * It's more complex and can handle this conversion specifically for LLM models
2475
+ * See `VALUE_STRINGS`
2476
+ *
2477
+ * Note: There are 2 similar functions
2478
+ * - `valueToString` converts value to string for LLM models as human-readable string
2479
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2480
+ *
2481
+ * @public exported from `@promptbook/utils`
2482
+ */
2483
+ function valueToString(value) {
2484
+ try {
2485
+ if (value === '') {
2486
+ return VALUE_STRINGS.empty;
2487
+ }
2488
+ else if (value === null) {
2489
+ return VALUE_STRINGS.null;
2490
+ }
2491
+ else if (value === undefined) {
2492
+ return VALUE_STRINGS.undefined;
2493
+ }
2494
+ else if (typeof value === 'string') {
2495
+ return value;
2496
+ }
2497
+ else if (typeof value === 'number') {
2498
+ return numberToString(value);
2499
+ }
2500
+ else if (value instanceof Date) {
2501
+ return value.toISOString();
2502
+ }
2503
+ else {
2504
+ return JSON.stringify(value);
2505
+ }
2506
+ }
2507
+ catch (error) {
2508
+ if (!(error instanceof Error)) {
2509
+ throw error;
2510
+ }
2511
+ console.error(error);
2512
+ return VALUE_STRINGS.unserializable;
2513
+ }
2514
+ }
2515
+
2420
2516
  /**
2421
2517
  * Serializes an error into a [🚉] JSON-serializable object
2422
2518
  *
@@ -3129,13 +3225,16 @@ function arrayableToArray(input) {
3129
3225
  /**
3130
3226
  * Replaces parameters in template with values from parameters object
3131
3227
  *
3228
+ * Note: This function is not places strings into string,
3229
+ * It's more complex and can handle this operation specifically for LLM models
3230
+ *
3132
3231
  * @param template the template with parameters in {curly} braces
3133
3232
  * @param parameters the object with parameters
3134
3233
  * @returns the template with replaced parameters
3135
3234
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
3136
3235
  * @public exported from `@promptbook/utils`
3137
3236
  */
3138
- function replaceParameters(template, parameters) {
3237
+ function templateParameters(template, parameters) {
3139
3238
  var e_1, _a;
3140
3239
  try {
3141
3240
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -3161,7 +3260,7 @@ function replaceParameters(template, parameters) {
3161
3260
  var loopLimit = LOOP_LIMIT;
3162
3261
  var _loop_1 = function () {
3163
3262
  if (loopLimit-- < 0) {
3164
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
3263
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
3165
3264
  }
3166
3265
  var precol = match.groups.precol;
3167
3266
  var parameterName = match.groups.parameterName;
@@ -3178,7 +3277,7 @@ function replaceParameters(template, parameters) {
3178
3277
  if (parameterValue === undefined) {
3179
3278
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
3180
3279
  }
3181
- parameterValue = parameterValue.toString();
3280
+ parameterValue = valueToString(parameterValue);
3182
3281
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
3183
3282
  parameterValue = parameterValue
3184
3283
  .split('\n')
@@ -3674,7 +3773,7 @@ function executeAttempts(options) {
3674
3773
  }
3675
3774
  return [3 /*break*/, 24];
3676
3775
  case 2:
3677
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
3776
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
3678
3777
  return [3 /*break*/, 25];
3679
3778
  case 3:
3680
3779
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -3797,8 +3896,8 @@ function executeAttempts(options) {
3797
3896
  _j = $ongoingTaskResult;
3798
3897
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3799
3898
  promptTitle: task.title,
3800
- promptMessage: replaceParameters(task.description || '', parameters),
3801
- defaultValue: replaceParameters(preparedContent, parameters),
3899
+ promptMessage: templateParameters(task.description || '', parameters),
3900
+ defaultValue: templateParameters(preparedContent, parameters),
3802
3901
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
3803
3902
  placeholder: undefined,
3804
3903
  priority: priority,
@@ -3922,7 +4021,7 @@ function executeAttempts(options) {
3922
4021
  if (!isJokerAttempt &&
3923
4022
  task.taskType === 'PROMPT_TASK' &&
3924
4023
  $ongoingTaskResult.$prompt
3925
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
4024
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
3926
4025
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3927
4026
  ) {
3928
4027
  // TODO: [🧠] Maybe put other taskTypes into report
@@ -4499,7 +4598,10 @@ function executePipeline(options) {
4499
4598
  finally { if (e_2) throw e_2.error; }
4500
4599
  return [7 /*endfinally*/];
4501
4600
  case 19:
4502
- parametersToPass = inputParameters;
4601
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
4602
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
4603
+ return [key, valueToString(value)];
4604
+ }));
4503
4605
  _g.label = 20;
4504
4606
  case 20:
4505
4607
  _g.trys.push([20, 25, , 28]);
@@ -5249,6 +5351,30 @@ function isValidFilePath(filename) {
5249
5351
  return false;
5250
5352
  }
5251
5353
 
5354
+ /**
5355
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5356
+ *
5357
+ * @private as default `fetch` function used in Promptbook scrapers
5358
+ */
5359
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
5360
+ var error_1;
5361
+ return __generator(this, function (_a) {
5362
+ switch (_a.label) {
5363
+ case 0:
5364
+ _a.trys.push([0, 2, , 3]);
5365
+ return [4 /*yield*/, fetch(url, init)];
5366
+ case 1: return [2 /*return*/, _a.sent()];
5367
+ case 2:
5368
+ error_1 = _a.sent();
5369
+ if (!(error_1 instanceof Error)) {
5370
+ throw error_1;
5371
+ }
5372
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
5373
+ case 3: return [2 /*return*/];
5374
+ }
5375
+ });
5376
+ }); };
5377
+
5252
5378
  /**
5253
5379
  * @@@
5254
5380
  *
@@ -5257,13 +5383,14 @@ function isValidFilePath(filename) {
5257
5383
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5258
5384
  var _a;
5259
5385
  return __awaiter(this, void 0, void 0, function () {
5260
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5261
- return __generator(this, function (_e) {
5262
- switch (_e.label) {
5386
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5387
+ return __generator(this, function (_f) {
5388
+ switch (_f.label) {
5263
5389
  case 0:
5390
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5264
5391
  sourceContent = knowledgeSource.sourceContent;
5265
5392
  name = knowledgeSource.name;
5266
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
5393
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
5267
5394
  if (!name) {
5268
5395
  name = sourceContentToName(sourceContent);
5269
5396
  }
@@ -5271,7 +5398,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5271
5398
  url = sourceContent;
5272
5399
  return [4 /*yield*/, fetch(url)];
5273
5400
  case 1:
5274
- response_1 = _e.sent();
5401
+ response_1 = _f.sent();
5275
5402
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5276
5403
  return [2 /*return*/, {
5277
5404
  source: name,
@@ -5328,7 +5455,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5328
5455
  mimeType = extensionToMimeType(fileExtension || '');
5329
5456
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5330
5457
  case 3:
5331
- if (!(_e.sent())) {
5458
+ if (!(_f.sent())) {
5332
5459
  throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5333
5460
  }
5334
5461
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -8631,6 +8758,14 @@ function precompilePipeline(pipelineString) {
8631
8758
  knowledgePieces: [],
8632
8759
  personas: [],
8633
8760
  preparations: [],
8761
+ sources: [
8762
+ {
8763
+ type: 'BOOK',
8764
+ path: null,
8765
+ // <- TODO: !!!!!! Pass here path of the file
8766
+ content: pipelineString,
8767
+ },
8768
+ ],
8634
8769
  };
8635
8770
  function getPipelineIdentification() {
8636
8771
  // Note: This is a 😐 implementation of [🚞]
@@ -8645,6 +8780,8 @@ function precompilePipeline(pipelineString) {
8645
8780
  }
8646
8781
  // =============================================================
8647
8782
  // Note: 1️⃣ Parsing of the markdown into object
8783
+ // ==============
8784
+ // Note: 1️⃣◽1️⃣ Remove #!shebang and comments
8648
8785
  if (pipelineString.startsWith('#!')) {
8649
8786
  var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
8650
8787
  if (!(shebangLine_1 || '').includes('ptbk')) {
@@ -8653,10 +8790,21 @@ function precompilePipeline(pipelineString) {
8653
8790
  pipelineString = restLines.join('\n');
8654
8791
  }
8655
8792
  pipelineString = removeContentComments(pipelineString);
8793
+ // ==============
8794
+ // Note: 1️⃣◽2️⃣ Process flat pipeline
8795
+ // TODO: !!!!!!
8796
+ // const isMarkdownBeginningWithHeadline =
8797
+ // const isMarkdown
8798
+ // const isMarkdown
8799
+ // const isMarkdown
8800
+ // ==============
8801
+ // Note: 1️⃣◽3️⃣ Parse the markdown
8656
8802
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
8657
8803
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
8658
8804
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
8659
8805
  var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
8806
+ // ==============
8807
+ // Note: 1️⃣◽4️⃣ Check markdown structure
8660
8808
  if (pipelineHead === undefined) {
8661
8809
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8662
8810
  }
@@ -9038,7 +9186,6 @@ function precompilePipeline(pipelineString) {
9038
9186
  $pipelineJson.formfactorName = 'GENERIC';
9039
9187
  }
9040
9188
  // =============================================================
9041
- // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
9042
9189
  return exportJson({
9043
9190
  name: 'pipelineJson',
9044
9191
  message: "Result of `precompilePipeline`",
@@ -9694,8 +9841,11 @@ function $provideLlmToolsFromEnv(options) {
9694
9841
  }
9695
9842
  var configuration = $provideLlmToolsConfigurationFromEnv();
9696
9843
  if (configuration.length === 0) {
9844
+ if ($llmToolsMetadataRegister.list().length === 0) {
9845
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n No LLM tools registered, this is probably a bug in the Promptbook library\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
9846
+ }
9697
9847
  // TODO: [🥃]
9698
- throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
9848
+ throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
9699
9849
  }
9700
9850
  return createLlmToolsFromConfiguration(configuration, options);
9701
9851
  }
@@ -10461,7 +10611,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
10461
10611
  */
10462
10612
  function createCollectionFromDirectory(path, tools, options) {
10463
10613
  return __awaiter(this, void 0, void 0, function () {
10464
- var makedLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
10614
+ var madeLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
10465
10615
  var _this = this;
10466
10616
  return __generator(this, function (_f) {
10467
10617
  switch (_f.label) {
@@ -10476,16 +10626,14 @@ function createCollectionFromDirectory(path, tools, options) {
10476
10626
  throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
10477
10627
  // <- TODO: [🧠] What is the best error type here`
10478
10628
  }
10479
- makedLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
10629
+ madeLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
10480
10630
  // <- TODO: [🦒] Allow to override (pass different value into the function)
10481
10631
  , ".json"));
10482
- return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
10632
+ return [4 /*yield*/, isFileExisting(madeLibraryFilePath, tools.fs)];
10483
10633
  case 3:
10484
- if (!(_f.sent())) {
10485
- console.info(colors.yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
10486
- }
10634
+ if (!(_f.sent())) ;
10487
10635
  else {
10488
- colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
10636
+ colors.green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(madeLibraryFilePath));
10489
10637
  // TODO: !! Implement;
10490
10638
  // TODO: [🌗]
10491
10639
  }
@@ -10505,10 +10653,10 @@ function createCollectionFromDirectory(path, tools, options) {
10505
10653
  // Note: First load all .book.json and then .book.md files
10506
10654
  // .book.json can be prepared so it is faster to load
10507
10655
  fileNames.sort(function (a, b) {
10508
- if (a.endsWith('.book.json') && b.endsWith('.book.md')) {
10656
+ if (a.endsWith('.json') && b.endsWith('.md')) {
10509
10657
  return -1;
10510
10658
  }
10511
- if (a.endsWith('.book.md') && b.endsWith('.book.json')) {
10659
+ if (a.endsWith('.md') && b.endsWith('.json')) {
10512
10660
  return 1;
10513
10661
  }
10514
10662
  return 0;
@@ -10557,7 +10705,7 @@ function createCollectionFromDirectory(path, tools, options) {
10557
10705
  // TODO: [👠] DRY
10558
10706
  if (pipeline.pipelineUrl === undefined) {
10559
10707
  if (isVerbose) {
10560
- console.info(colors.red("Can not load pipeline from ".concat(fileName
10708
+ console.info(colors.yellow("Can not load pipeline from ".concat(fileName
10561
10709
  .split('\\')
10562
10710
  .join('/'), " because of missing URL")));
10563
10711
  }
@@ -10691,7 +10839,7 @@ function isSerializableAsJson(value) {
10691
10839
  * Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
10692
10840
  * Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
10693
10841
  *
10694
- * @public exported from `@promptbook/core`
10842
+ * @public exported from `@promptbook/editable`
10695
10843
  */
10696
10844
  function stringifyPipelineJson(pipeline) {
10697
10845
  if (!isSerializableAsJson(pipeline)) {