@promptbook/legacy-documents 0.84.0-9 → 0.84.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 (43) hide show
  1. package/README.md +21 -9
  2. package/esm/index.es.js +165 -64
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -2
  6. package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  9. package/esm/typings/src/_packages/wizzard.index.d.ts +4 -0
  10. package/esm/typings/src/cli/cli-commands/about.d.ts +4 -1
  11. package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -1
  12. package/esm/typings/src/cli/cli-commands/list-models.d.ts +3 -1
  13. package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
  14. package/esm/typings/src/cli/cli-commands/make.d.ts +3 -1
  15. package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -1
  16. package/esm/typings/src/cli/cli-commands/run.d.ts +3 -1
  17. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
  18. package/esm/typings/src/cli/cli-commands/test-command.d.ts +3 -1
  19. package/esm/typings/src/config.d.ts +27 -1
  20. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  21. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  22. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
  23. package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +9 -0
  24. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
  25. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
  26. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
  27. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
  28. package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
  29. package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
  30. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +5 -2
  32. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
  33. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
  34. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +3 -0
  35. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +3 -0
  36. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +3 -0
  37. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +3 -0
  38. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
  39. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
  40. package/esm/typings/src/wizzard/wizzard.d.ts +7 -1
  41. package/package.json +9 -16
  42. package/umd/index.umd.js +168 -67
  43. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten -->
2
2
 
3
- # Promptbook
3
+ # Promptbook
4
4
 
5
5
 
6
6
 
@@ -14,19 +14,16 @@
14
14
 
15
15
 
16
16
 
17
- ## New Features
17
+ ## 🌟 New Features
18
18
 
19
+ - 💫 Support of [`o3-mini` model by OpenAI](https://openai.com/index/openai-o3-mini/)
20
+ - 🐋 **Support of [DeepSeek models](https://www.npmjs.com/package/@promptbook/deepseek)**
19
21
  - 💙 Working [the **Book** language v1.0.0](https://github.com/webgptorg/book)
20
22
  - 🖤 Run books from CLI - `npx ptbk run path/to/your/book`
21
- - 📚 Support of `.docx`, `.doc` and `.pdf` documents
22
- - ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
23
+ - 📚 Support of `.docx`, `.doc` and `.pdf` documents as knowledge
23
24
 
24
25
 
25
26
 
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
-
30
27
  ## 📦 Package `@promptbook/legacy-documents`
31
28
 
32
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -265,8 +262,9 @@ Or you can install them separately:
265
262
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
266
263
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
267
264
  - **[@promptbook/google](https://www.npmjs.com/package/@promptbook/google)** - Integration with Google's Gemini API
265
+ - **[@promptbook/deepseek](https://www.npmjs.com/package/@promptbook/deepseek)** - Integration with [DeepSeek API](https://www.deepseek.com/)
268
266
  - **[@promptbook/azure-openai](https://www.npmjs.com/package/@promptbook/azure-openai)** - Execution tools for Azure OpenAI API
269
- - **[@promptbook/langtail](https://www.npmjs.com/package/@promptbook/langtail)** - Execution tools for Langtail API, wrapper around Langtail SDK
267
+
270
268
  - **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
271
269
  - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
272
270
  - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
@@ -436,6 +434,20 @@ See [TODO.md](./TODO.md)
436
434
 
437
435
 
438
436
 
437
+ ## 🤝 Partners
438
+
439
+ <div style="display: flex; align-items: center; gap: 20px;">
440
+
441
+ <a href="https://promptbook.studio/">
442
+ <img src="./other/design/promptbook-studio-logo.png" alt="Partner 3" height="100">
443
+ </a>
444
+
445
+ <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
446
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
447
+ </a>
448
+
449
+ </div>
450
+
439
451
  ## 🖋️ Contributing
440
452
 
441
453
  I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can [☕ buy me a coffee](https://www.buymeacoffee.com/hejny) or [donate via cryptocurrencies](https://github.com/hejny/hejny/blob/main/documents/crypto.md).
package/esm/index.es.js CHANGED
@@ -8,7 +8,8 @@ import { SHA256 } from 'crypto-js';
8
8
  import hexEncoder from 'crypto-js/enc-hex';
9
9
  import { format } from 'prettier';
10
10
  import parserHtml from 'prettier/parser-html';
11
- import { lookup } from 'mime-types';
11
+ import sha256 from 'crypto-js/sha256';
12
+ import { lookup, extension } from 'mime-types';
12
13
  import { unparse, parse } from 'papaparse';
13
14
 
14
15
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -25,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
25
26
  * @generated
26
27
  * @see https://github.com/webgptorg/promptbook
27
28
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
29
30
  /**
30
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -196,6 +197,12 @@ var ADMIN_GITHUB_NAME = 'hejny';
196
197
  * @public exported from `@promptbook/core`
197
198
  */
198
199
  var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
200
+ /**
201
+ * Maximum file size limit
202
+ *
203
+ * @public exported from `@promptbook/core`
204
+ */
205
+ var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
199
206
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
200
207
  /**
201
208
  * The maximum number of iterations for a loops
@@ -229,6 +236,12 @@ var SMALL_NUMBER = 0.001;
229
236
  * @private within the repository - too low-level in comparison with other `MAX_...`
230
237
  */
231
238
  var IMMEDIATE_TIME = 10;
239
+ /**
240
+ * The maximum length of the (generated) filename
241
+ *
242
+ * @public exported from `@promptbook/core`
243
+ */
244
+ var MAX_FILENAME_LENGTH = 30;
232
245
  /**
233
246
  * Strategy for caching the intermediate results for knowledge sources
234
247
  *
@@ -248,6 +261,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
248
261
  * @public exported from `@promptbook/core`
249
262
  */
250
263
  var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
264
+ // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
265
+ /**
266
+ * Where to store the temporary downloads
267
+ *
268
+ * Note: When the folder does not exist, it is created recursively
269
+ *
270
+ * @public exported from `@promptbook/core`
271
+ */
272
+ var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
251
273
  /**
252
274
  * Where to store the scrape cache
253
275
  *
@@ -384,6 +406,9 @@ var UnexpectedError = /** @class */ (function (_super) {
384
406
  * @public exported from `@promptbook/utils`
385
407
  */
386
408
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
409
+ /**
410
+ * TODO: [☑]
411
+ */
387
412
 
388
413
  /**
389
414
  * Normalize options for `execCommand` and `execCommands`
@@ -1117,24 +1142,18 @@ function getScraperIntermediateSource(source, options) {
1117
1142
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
1118
1143
 
1119
1144
  /**
1120
- * Function isValidJsonString will tell you if the string is valid JSON or not
1145
+ * Checks if value is valid email
1121
1146
  *
1122
1147
  * @public exported from `@promptbook/utils`
1123
1148
  */
1124
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
1125
- try {
1126
- JSON.parse(value);
1127
- return true;
1149
+ function isValidEmail(email) {
1150
+ if (typeof email !== 'string') {
1151
+ return false;
1128
1152
  }
1129
- catch (error) {
1130
- if (!(error instanceof Error)) {
1131
- throw error;
1132
- }
1133
- if (error.message.includes('Unexpected token')) {
1134
- return false;
1135
- }
1153
+ if (email.split('\n').length > 1) {
1136
1154
  return false;
1137
1155
  }
1156
+ return /^.+@.+\..+$/.test(email);
1138
1157
  }
1139
1158
 
1140
1159
  /**
@@ -1156,6 +1175,27 @@ var ParseError = /** @class */ (function (_super) {
1156
1175
  * TODO: Maybe split `ParseError` and `ApplyError`
1157
1176
  */
1158
1177
 
1178
+ /**
1179
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1180
+ *
1181
+ * @public exported from `@promptbook/utils`
1182
+ */
1183
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1184
+ try {
1185
+ JSON.parse(value);
1186
+ return true;
1187
+ }
1188
+ catch (error) {
1189
+ if (!(error instanceof Error)) {
1190
+ throw error;
1191
+ }
1192
+ if (error.message.includes('Unexpected token')) {
1193
+ return false;
1194
+ }
1195
+ return false;
1196
+ }
1197
+ }
1198
+
1159
1199
  /**
1160
1200
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1161
1201
  * 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.
@@ -1169,6 +1209,15 @@ function validatePipelineString(pipelineString) {
1169
1209
  if (isValidJsonString(pipelineString)) {
1170
1210
  throw new ParseError('Expected a book, but got a JSON string');
1171
1211
  }
1212
+ else if (isValidUrl(pipelineString)) {
1213
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1214
+ }
1215
+ else if (isValidFilePath(pipelineString)) {
1216
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1217
+ }
1218
+ else if (isValidEmail(pipelineString)) {
1219
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1220
+ }
1172
1221
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1173
1222
  return pipelineString;
1174
1223
  }
@@ -2534,12 +2583,28 @@ function deserializeError(error) {
2534
2583
  /**
2535
2584
  * Asserts that the execution of a Promptbook is successful
2536
2585
  *
2586
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2587
+ *
2537
2588
  * @param executionResult - The partial result of the Promptbook execution
2538
2589
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2539
2590
  * @public exported from `@promptbook/core`
2540
2591
  */
2541
2592
  function assertsExecutionSuccessful(executionResult) {
2542
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2593
+ var e_1, _a;
2594
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2595
+ try {
2596
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2597
+ var warning = warnings_1_1.value;
2598
+ console.warn(warning.message);
2599
+ }
2600
+ }
2601
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2602
+ finally {
2603
+ try {
2604
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2605
+ }
2606
+ finally { if (e_1) throw e_1.error; }
2607
+ }
2543
2608
  if (isSuccessful === true) {
2544
2609
  return;
2545
2610
  }
@@ -3176,7 +3241,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
3176
3241
  if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
3177
3242
  throw error_1;
3178
3243
  }
3179
- errors.push(error_1);
3244
+ errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
3180
3245
  return [3 /*break*/, 13];
3181
3246
  case 13:
3182
3247
  _b = _a.next();
@@ -3203,7 +3268,10 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
3203
3268
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3204
3269
  // 3) ...
3205
3270
  spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
3206
- .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
3271
+ .map(function (_a, i) {
3272
+ var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
3273
+ return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
3274
+ })
3207
3275
  .join('\n')), "\n\n "); }));
3208
3276
  }
3209
3277
  else if (this.llmExecutionTools.length === 0) {
@@ -3675,6 +3743,17 @@ function extensionToMimeType(value) {
3675
3743
  return lookup(value) || 'application/octet-stream';
3676
3744
  }
3677
3745
 
3746
+ /**
3747
+ * Convert mime type to file extension
3748
+ *
3749
+ * Note: If the mime type is invalid, `null` is returned
3750
+ *
3751
+ * @private within the repository
3752
+ */
3753
+ function mimeTypeToExtension(value) {
3754
+ return extension(value) || null;
3755
+ }
3756
+
3678
3757
  /**
3679
3758
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3680
3759
  *
@@ -3710,9 +3789,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
3710
3789
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3711
3790
  var _a;
3712
3791
  return __awaiter(this, void 0, void 0, function () {
3713
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3714
- return __generator(this, function (_f) {
3715
- switch (_f.label) {
3792
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
3793
+ return __generator(this, function (_h) {
3794
+ switch (_h.label) {
3716
3795
  case 0:
3717
3796
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3718
3797
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -3721,54 +3800,76 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3721
3800
  if (!name) {
3722
3801
  name = knowledgeSourceContentToName(knowledgeSourceContent);
3723
3802
  }
3724
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
3803
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
3725
3804
  url = knowledgeSourceContent;
3726
3805
  return [4 /*yield*/, fetch(url)];
3727
3806
  case 1:
3728
- response_1 = _f.sent();
3807
+ response_1 = _h.sent();
3729
3808
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3730
- return [2 /*return*/, {
3731
- source: name,
3732
- filename: null,
3733
- url: url,
3734
- mimeType: mimeType,
3735
- /*
3736
- TODO: [🥽]
3737
- > async asBlob() {
3738
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
3739
- > const content = await response.blob();
3740
- > return content;
3741
- > },
3742
- */
3743
- asJson: function () {
3744
- return __awaiter(this, void 0, void 0, function () {
3745
- var content;
3746
- return __generator(this, function (_a) {
3747
- switch (_a.label) {
3748
- case 0: return [4 /*yield*/, response_1.json()];
3749
- case 1:
3750
- content = _a.sent();
3751
- return [2 /*return*/, content];
3752
- }
3809
+ if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
3810
+ return [2 /*return*/, {
3811
+ source: name,
3812
+ filename: null,
3813
+ url: url,
3814
+ mimeType: mimeType,
3815
+ /*
3816
+ TODO: [🥽]
3817
+ > async asBlob() {
3818
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
3819
+ > const content = await response.blob();
3820
+ > return content;
3821
+ > },
3822
+ */
3823
+ asJson: function () {
3824
+ return __awaiter(this, void 0, void 0, function () {
3825
+ var content;
3826
+ return __generator(this, function (_a) {
3827
+ switch (_a.label) {
3828
+ case 0: return [4 /*yield*/, response_1.json()];
3829
+ case 1:
3830
+ content = _a.sent();
3831
+ return [2 /*return*/, content];
3832
+ }
3833
+ });
3753
3834
  });
3754
- });
3755
- },
3756
- asText: function () {
3757
- return __awaiter(this, void 0, void 0, function () {
3758
- var content;
3759
- return __generator(this, function (_a) {
3760
- switch (_a.label) {
3761
- case 0: return [4 /*yield*/, response_1.text()];
3762
- case 1:
3763
- content = _a.sent();
3764
- return [2 /*return*/, content];
3765
- }
3835
+ },
3836
+ asText: function () {
3837
+ return __awaiter(this, void 0, void 0, function () {
3838
+ var content;
3839
+ return __generator(this, function (_a) {
3840
+ switch (_a.label) {
3841
+ case 0: return [4 /*yield*/, response_1.text()];
3842
+ case 1:
3843
+ content = _a.sent();
3844
+ return [2 /*return*/, content];
3845
+ }
3846
+ });
3766
3847
  });
3767
- });
3768
- },
3769
- }];
3848
+ },
3849
+ }];
3850
+ }
3851
+ basename = url.split('/').pop() || titleToName(url);
3852
+ hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
3853
+ rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3854
+ filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
3855
+ return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
3770
3856
  case 2:
3771
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
3857
+ _h.sent();
3858
+ _g = (_f = Buffer).from;
3859
+ return [4 /*yield*/, response_1.arrayBuffer()];
3860
+ case 3:
3861
+ fileContent = _g.apply(_f, [_h.sent()]);
3862
+ if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3863
+ throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
3864
+ }
3865
+ return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
3866
+ case 4:
3867
+ _h.sent();
3868
+ // TODO: [💵] Check the file security
3869
+ // TODO: [🧹][🧠] Delete the file after the scraping is done
3870
+ return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
3871
+ case 5:
3872
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
3772
3873
  if (tools.fs === undefined) {
3773
3874
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3774
3875
  // <- TODO: [🧠] What is the best error type here`
@@ -3781,8 +3882,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3781
3882
  fileExtension = getFileExtension(filename_1);
3782
3883
  mimeType = extensionToMimeType(fileExtension || '');
3783
3884
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3784
- case 3:
3785
- if (!(_f.sent())) {
3885
+ case 6:
3886
+ if (!(_h.sent())) {
3786
3887
  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(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
3787
3888
  }
3788
3889
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -3828,7 +3929,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3828
3929
  });
3829
3930
  },
3830
3931
  }];
3831
- case 4: return [2 /*return*/, {
3932
+ case 7: return [2 /*return*/, {
3832
3933
  source: name,
3833
3934
  filename: null,
3834
3935
  url: null,