@promptbook/legacy-documents 0.80.0 → 0.81.0-12

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 (70) hide show
  1. package/README.md +8 -1
  2. package/esm/index.es.js +180 -23
  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 +12 -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 +19 -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 +10 -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/scripting/javascript/utils/preserve.d.ts +1 -0
  45. package/esm/typings/src/types/typeAliases.d.ts +8 -0
  46. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
  47. package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
  48. package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
  49. package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
  50. package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
  51. package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
  52. package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
  53. package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
  54. package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
  55. package/esm/typings/src/utils/validators/filePath/isPathRoot.d.ts +12 -0
  56. package/esm/typings/src/utils/validators/filePath/isPathRoot.test.d.ts +4 -0
  57. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
  58. package/esm/typings/src/version.d.ts +7 -0
  59. package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
  60. package/esm/typings/src/wizzard/wizzard.d.ts +51 -0
  61. package/package.json +2 -2
  62. package/umd/index.umd.js +180 -23
  63. package/umd/index.umd.js.map +1 -1
  64. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
  65. package/esm/typings/src/utils/formatNumber.d.ts +0 -6
  66. /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
  67. /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
  68. /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
  69. /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
  70. /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/legacy-documents`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -229,6 +233,7 @@ Or you can install them separately:
229
233
 
230
234
  - ⭐ **[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
231
235
  - **[promptbook](https://www.npmjs.com/package/promptbook)** - Same as `ptbk`
236
+ - ⭐🧙‍♂️ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizzard to just run the books in node without any struggle
232
237
  - **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
233
238
  - **[@promptbook/node](https://www.npmjs.com/package/@promptbook/node)** - Core of the library for Node.js environment
234
239
  - **[@promptbook/browser](https://www.npmjs.com/package/@promptbook/browser)** - Core of the library for browser environment
@@ -249,8 +254,10 @@ Or you can install them separately:
249
254
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
250
255
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
251
256
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
257
+ - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
258
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
252
259
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
253
- - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
260
+ - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
254
261
 
255
262
 
256
263
 
package/esm/index.es.js CHANGED
@@ -15,15 +15,17 @@ import { unparse, parse } from 'papaparse';
15
15
  /**
16
16
  * The version of the Book language
17
17
  *
18
+ * @generated
18
19
  * @see https://github.com/webgptorg/book
19
20
  */
20
21
  var BOOK_LANGUAGE_VERSION = '1.0.0';
21
22
  /**
22
23
  * The version of the Promptbook engine
23
24
  *
25
+ * @generated
24
26
  * @see https://github.com/webgptorg/promptbook
25
27
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-11';
27
29
  /**
28
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -195,6 +197,26 @@ var ADMIN_GITHUB_NAME = 'hejny';
195
197
  * @private within the repository - too low-level in comparison with other `MAX_...`
196
198
  */
197
199
  var LOOP_LIMIT = 1000;
200
+ /**
201
+ * Strings to represent various values in the context of parameter values
202
+ *
203
+ * @public exported from `@promptbook/utils`
204
+ */
205
+ var VALUE_STRINGS = {
206
+ empty: '(nothing; empty string)',
207
+ null: '(no value; null)',
208
+ undefined: '(unknown value; undefined)',
209
+ nan: '(not a number; NaN)',
210
+ infinity: '(infinity; ∞)',
211
+ negativeInfinity: '(negative infinity; -∞)',
212
+ unserializable: '(unserializable value)',
213
+ };
214
+ /**
215
+ * Small number limit
216
+ *
217
+ * @public exported from `@promptbook/utils`
218
+ */
219
+ var SMALL_NUMBER = 0.001;
198
220
  /**
199
221
  * Short time interval to prevent race conditions in milliseconds
200
222
  *
@@ -923,21 +945,44 @@ function isValidFilePath(filename) {
923
945
  if (typeof filename !== 'string') {
924
946
  return false;
925
947
  }
948
+ if (filename.split('\n').length > 1) {
949
+ return false;
950
+ }
951
+ if (filename.split(' ').length >
952
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
953
+ return false;
954
+ }
926
955
  var filenameSlashes = filename.split('\\').join('/');
927
956
  // Absolute Unix path: /hello.txt
928
957
  if (/^(\/)/i.test(filenameSlashes)) {
958
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
929
959
  return true;
930
960
  }
931
961
  // Absolute Windows path: /hello.txt
932
962
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
963
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
933
964
  return true;
934
965
  }
935
966
  // Relative path: ./hello.txt
936
967
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
968
+ // console.log(filename, 'Relative path: ./hello.txt');
969
+ return true;
970
+ }
971
+ // Allow paths like foo/hello
972
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
973
+ // console.log(filename, 'Allow paths like foo/hello');
974
+ return true;
975
+ }
976
+ // Allow paths like hello.book
977
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
978
+ // console.log(filename, 'Allow paths like hello.book');
937
979
  return true;
938
980
  }
939
981
  return false;
940
982
  }
983
+ /**
984
+ * TODO: [🍏] Implement for MacOs
985
+ */
941
986
 
942
987
  /**
943
988
  * Tests if given string is valid URL.
@@ -1063,7 +1108,7 @@ function getScraperIntermediateSource(source, options) {
1063
1108
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1064
1109
  */
1065
1110
 
1066
- 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"}];
1111
+ 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"}];
1067
1112
 
1068
1113
  /**
1069
1114
  * Prettify the html code
@@ -1455,7 +1500,7 @@ function checkSerializableAsJson(options) {
1455
1500
  if (!(error instanceof Error)) {
1456
1501
  throw error;
1457
1502
  }
1458
- throw new UnexpectedError(spaceTrim$1(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 "); }));
1503
+ throw new UnexpectedError(spaceTrim$1(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 "); }));
1459
1504
  }
1460
1505
  /*
1461
1506
  TODO: [0] Is there some more elegant way to check circular references?
@@ -1553,6 +1598,7 @@ function exportJson(options) {
1553
1598
  * @public exported from `@promptbook/core`
1554
1599
  */
1555
1600
  var ORDER_OF_PIPELINE_JSON = [
1601
+ // Note: [🍙] In this order will be pipeline serialized
1556
1602
  'title',
1557
1603
  'pipelineUrl',
1558
1604
  'bookVersion',
@@ -1564,6 +1610,7 @@ var ORDER_OF_PIPELINE_JSON = [
1564
1610
  'preparations',
1565
1611
  'knowledgeSources',
1566
1612
  'knowledgePieces',
1613
+ 'sources', // <- TODO: [🧠] Where should the `sources` be
1567
1614
  ];
1568
1615
  /**
1569
1616
  * Nonce which is used for replacing things in strings
@@ -1751,9 +1798,6 @@ function isValidPipelineUrl(url) {
1751
1798
  if (!url.startsWith('https://')) {
1752
1799
  return false;
1753
1800
  }
1754
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1755
- return false;
1756
- }
1757
1801
  if (url.includes('#')) {
1758
1802
  // TODO: [🐠]
1759
1803
  return false;
@@ -2499,6 +2543,81 @@ function isPipelinePrepared(pipeline) {
2499
2543
  * - [♨] Are tasks prepared
2500
2544
  */
2501
2545
 
2546
+ /**
2547
+ * Format either small or big number
2548
+ *
2549
+ * @public exported from `@promptbook/utils`
2550
+ */
2551
+ function numberToString(value) {
2552
+ if (value === 0) {
2553
+ return '0';
2554
+ }
2555
+ else if (Number.isNaN(value)) {
2556
+ return VALUE_STRINGS.nan;
2557
+ }
2558
+ else if (value === Infinity) {
2559
+ return VALUE_STRINGS.infinity;
2560
+ }
2561
+ else if (value === -Infinity) {
2562
+ return VALUE_STRINGS.negativeInfinity;
2563
+ }
2564
+ for (var exponent = 0; exponent < 15; exponent++) {
2565
+ var factor = Math.pow(10, exponent);
2566
+ var valueRounded = Math.round(value * factor) / factor;
2567
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2568
+ return valueRounded.toFixed(exponent);
2569
+ }
2570
+ }
2571
+ return value.toString();
2572
+ }
2573
+
2574
+ /**
2575
+ * Function `valueToString` will convert the given value to string
2576
+ * This is useful and used in the `templateParameters` function
2577
+ *
2578
+ * Note: This function is not just calling `toString` method
2579
+ * It's more complex and can handle this conversion specifically for LLM models
2580
+ * See `VALUE_STRINGS`
2581
+ *
2582
+ * Note: There are 2 similar functions
2583
+ * - `valueToString` converts value to string for LLM models as human-readable string
2584
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2585
+ *
2586
+ * @public exported from `@promptbook/utils`
2587
+ */
2588
+ function valueToString(value) {
2589
+ try {
2590
+ if (value === '') {
2591
+ return VALUE_STRINGS.empty;
2592
+ }
2593
+ else if (value === null) {
2594
+ return VALUE_STRINGS.null;
2595
+ }
2596
+ else if (value === undefined) {
2597
+ return VALUE_STRINGS.undefined;
2598
+ }
2599
+ else if (typeof value === 'string') {
2600
+ return value;
2601
+ }
2602
+ else if (typeof value === 'number') {
2603
+ return numberToString(value);
2604
+ }
2605
+ else if (value instanceof Date) {
2606
+ return value.toISOString();
2607
+ }
2608
+ else {
2609
+ return JSON.stringify(value);
2610
+ }
2611
+ }
2612
+ catch (error) {
2613
+ if (!(error instanceof Error)) {
2614
+ throw error;
2615
+ }
2616
+ console.error(error);
2617
+ return VALUE_STRINGS.unserializable;
2618
+ }
2619
+ }
2620
+
2502
2621
  /**
2503
2622
  * Serializes an error into a [🚉] JSON-serializable object
2504
2623
  *
@@ -3499,6 +3618,33 @@ function extensionToMimeType(value) {
3499
3618
  return lookup(value) || 'application/octet-stream';
3500
3619
  }
3501
3620
 
3621
+ /**
3622
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3623
+ *
3624
+ * @private as default `fetch` function used in Promptbook scrapers
3625
+ */
3626
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
3627
+ var error_1;
3628
+ return __generator(this, function (_a) {
3629
+ switch (_a.label) {
3630
+ case 0:
3631
+ _a.trys.push([0, 2, , 3]);
3632
+ return [4 /*yield*/, fetch(url, init)];
3633
+ case 1: return [2 /*return*/, _a.sent()];
3634
+ case 2:
3635
+ error_1 = _a.sent();
3636
+ if (!(error_1 instanceof Error)) {
3637
+ throw error_1;
3638
+ }
3639
+ throw new KnowledgeScrapeError(spaceTrim$1(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
3640
+ case 3: return [2 /*return*/];
3641
+ }
3642
+ });
3643
+ }); };
3644
+ /**
3645
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3646
+ */
3647
+
3502
3648
  /**
3503
3649
  * @@@
3504
3650
  *
@@ -3507,13 +3653,14 @@ function extensionToMimeType(value) {
3507
3653
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3508
3654
  var _a;
3509
3655
  return __awaiter(this, void 0, void 0, function () {
3510
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3511
- return __generator(this, function (_e) {
3512
- switch (_e.label) {
3656
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3657
+ return __generator(this, function (_f) {
3658
+ switch (_f.label) {
3513
3659
  case 0:
3660
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3514
3661
  sourceContent = knowledgeSource.sourceContent;
3515
3662
  name = knowledgeSource.name;
3516
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
3663
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
3517
3664
  if (!name) {
3518
3665
  name = sourceContentToName(sourceContent);
3519
3666
  }
@@ -3521,7 +3668,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3521
3668
  url = sourceContent;
3522
3669
  return [4 /*yield*/, fetch(url)];
3523
3670
  case 1:
3524
- response_1 = _e.sent();
3671
+ response_1 = _f.sent();
3525
3672
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3526
3673
  return [2 /*return*/, {
3527
3674
  source: name,
@@ -3564,7 +3711,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3564
3711
  },
3565
3712
  }];
3566
3713
  case 2:
3567
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3714
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3568
3715
  if (tools.fs === undefined) {
3569
3716
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3570
3717
  // <- TODO: [🧠] What is the best error type here`
@@ -3578,8 +3725,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3578
3725
  mimeType = extensionToMimeType(fileExtension || '');
3579
3726
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3580
3727
  case 3:
3581
- if (!(_e.sent())) {
3582
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3728
+ if (!(_f.sent())) {
3729
+ throw new NotFoundError(spaceTrim$1(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 "); }));
3583
3730
  }
3584
3731
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3585
3732
  return [2 /*return*/, {
@@ -3987,7 +4134,7 @@ function extractVariablesFromScript(script) {
3987
4134
  if (!(error instanceof Error)) {
3988
4135
  throw error;
3989
4136
  }
3990
- throw new ParseError(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)
4137
+ throw new ParseError(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)
3991
4138
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
3992
4139
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
3993
4140
  }
@@ -4609,13 +4756,16 @@ function extractJsonBlock(markdown) {
4609
4756
  /**
4610
4757
  * Replaces parameters in template with values from parameters object
4611
4758
  *
4759
+ * Note: This function is not places strings into string,
4760
+ * It's more complex and can handle this operation specifically for LLM models
4761
+ *
4612
4762
  * @param template the template with parameters in {curly} braces
4613
4763
  * @param parameters the object with parameters
4614
4764
  * @returns the template with replaced parameters
4615
4765
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4616
4766
  * @public exported from `@promptbook/utils`
4617
4767
  */
4618
- function replaceParameters(template, parameters) {
4768
+ function templateParameters(template, parameters) {
4619
4769
  var e_1, _a;
4620
4770
  try {
4621
4771
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -4641,7 +4791,7 @@ function replaceParameters(template, parameters) {
4641
4791
  var loopLimit = LOOP_LIMIT;
4642
4792
  var _loop_1 = function () {
4643
4793
  if (loopLimit-- < 0) {
4644
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
4794
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4645
4795
  }
4646
4796
  var precol = match.groups.precol;
4647
4797
  var parameterName = match.groups.parameterName;
@@ -4658,7 +4808,7 @@ function replaceParameters(template, parameters) {
4658
4808
  if (parameterValue === undefined) {
4659
4809
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4660
4810
  }
4661
- parameterValue = parameterValue.toString();
4811
+ parameterValue = valueToString(parameterValue);
4662
4812
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4663
4813
  parameterValue = parameterValue
4664
4814
  .split('\n')
@@ -4893,7 +5043,7 @@ function executeAttempts(options) {
4893
5043
  }
4894
5044
  return [3 /*break*/, 24];
4895
5045
  case 2:
4896
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
5046
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
4897
5047
  return [3 /*break*/, 25];
4898
5048
  case 3:
4899
5049
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -5016,8 +5166,8 @@ function executeAttempts(options) {
5016
5166
  _j = $ongoingTaskResult;
5017
5167
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
5018
5168
  promptTitle: task.title,
5019
- promptMessage: replaceParameters(task.description || '', parameters),
5020
- defaultValue: replaceParameters(preparedContent, parameters),
5169
+ promptMessage: templateParameters(task.description || '', parameters),
5170
+ defaultValue: templateParameters(preparedContent, parameters),
5021
5171
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
5022
5172
  placeholder: undefined,
5023
5173
  priority: priority,
@@ -5141,7 +5291,7 @@ function executeAttempts(options) {
5141
5291
  if (!isJokerAttempt &&
5142
5292
  task.taskType === 'PROMPT_TASK' &&
5143
5293
  $ongoingTaskResult.$prompt
5144
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
5294
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
5145
5295
  // In that case we don’t want to make a report about it because it’s not a llm execution error
5146
5296
  ) {
5147
5297
  // TODO: [🧠] Maybe put other taskTypes into report
@@ -5718,7 +5868,10 @@ function executePipeline(options) {
5718
5868
  finally { if (e_2) throw e_2.error; }
5719
5869
  return [7 /*endfinally*/];
5720
5870
  case 19:
5721
- parametersToPass = inputParameters;
5871
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
5872
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
5873
+ return [key, valueToString(value)];
5874
+ }));
5722
5875
  _g.label = 20;
5723
5876
  case 20:
5724
5877
  _g.trys.push([20, 25, , 28]);
@@ -5973,6 +6126,7 @@ var markdownScraperMetadata = $deepFreeze({
5973
6126
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
5974
6127
  *
5975
6128
  * @public exported from `@promptbook/core`
6129
+ * @public exported from `@promptbook/wizzard`
5976
6130
  * @public exported from `@promptbook/cli`
5977
6131
  */
5978
6132
  $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -6170,6 +6324,7 @@ var documentScraperMetadata = $deepFreeze({
6170
6324
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6171
6325
  *
6172
6326
  * @public exported from `@promptbook/core`
6327
+ * @public exported from `@promptbook/wizzard`
6173
6328
  * @public exported from `@promptbook/cli`
6174
6329
  */
6175
6330
  $scrapersMetadataRegister.register(documentScraperMetadata);
@@ -6337,6 +6492,7 @@ var legacyDocumentScraperMetadata = $deepFreeze({
6337
6492
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6338
6493
  *
6339
6494
  * @public exported from `@promptbook/core`
6495
+ * @public exported from `@promptbook/wizzard`
6340
6496
  * @public exported from `@promptbook/cli`
6341
6497
  */
6342
6498
  $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
@@ -6507,6 +6663,7 @@ var createLegacyDocumentScraper = Object.assign(function (tools, options) {
6507
6663
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
6508
6664
  *
6509
6665
  * @public exported from `@promptbook/legacy-documents`
6666
+ * @public exported from `@promptbook/wizzard`
6510
6667
  * @public exported from `@promptbook/cli`
6511
6668
  */
6512
6669
  var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacyDocumentScraper);