@promptbook/remote-server 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 +283 -127
  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 +283 -127
  43. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('http'), require('socket.io'), require('spacetrim'), require('child_process'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'http', 'socket.io', 'spacetrim', 'child_process', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'crypto-js/enc-hex', 'mime-types'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.http, global.socket_io, global.spaceTrim, global.child_process, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.hexEncoder, global.mimeTypes));
5
- })(this, (function (exports, colors, http, socket_io, spaceTrim, child_process, waitasecond, promises, path, prettier, parserHtml, papaparse, cryptoJs, hexEncoder, mimeTypes) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('http'), require('socket.io'), require('spacetrim'), require('child_process'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'http', 'socket.io', 'spacetrim', 'child_process', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.http, global.socket_io, global.spaceTrim, global.child_process, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes));
5
+ })(this, (function (exports, colors, http, socket_io, spaceTrim, child_process, waitasecond, promises, path, prettier, parserHtml, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -11,6 +11,7 @@
11
11
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
12
12
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
13
13
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
14
+ var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
14
15
 
15
16
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
16
17
  /**
@@ -26,7 +27,7 @@
26
27
  * @generated
27
28
  * @see https://github.com/webgptorg/promptbook
28
29
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
30
31
  /**
31
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -197,6 +198,12 @@
197
198
  * @public exported from `@promptbook/core`
198
199
  */
199
200
  var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
201
+ /**
202
+ * Maximum file size limit
203
+ *
204
+ * @public exported from `@promptbook/core`
205
+ */
206
+ var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
200
207
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
201
208
  /**
202
209
  * The maximum number of iterations for a loops
@@ -230,6 +237,12 @@
230
237
  * @private within the repository - too low-level in comparison with other `MAX_...`
231
238
  */
232
239
  var IMMEDIATE_TIME = 10;
240
+ /**
241
+ * The maximum length of the (generated) filename
242
+ *
243
+ * @public exported from `@promptbook/core`
244
+ */
245
+ var MAX_FILENAME_LENGTH = 30;
233
246
  /**
234
247
  * Strategy for caching the intermediate results for knowledge sources
235
248
  *
@@ -249,6 +262,15 @@
249
262
  * @public exported from `@promptbook/core`
250
263
  */
251
264
  var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
265
+ // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
266
+ /**
267
+ * Where to store the temporary downloads
268
+ *
269
+ * Note: When the folder does not exist, it is created recursively
270
+ *
271
+ * @public exported from `@promptbook/core`
272
+ */
273
+ var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
252
274
  /**
253
275
  * Where to store the scrape cache
254
276
  *
@@ -644,6 +666,9 @@
644
666
  * @public exported from `@promptbook/utils`
645
667
  */
646
668
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
669
+ /**
670
+ * TODO: [☑]
671
+ */
647
672
 
648
673
  /**
649
674
  * Normalize options for `execCommand` and `execCommands`
@@ -857,6 +882,7 @@
857
882
  readFile: promises.readFile,
858
883
  writeFile: promises.writeFile,
859
884
  readdir: promises.readdir,
885
+ mkdir: promises.mkdir,
860
886
  };
861
887
  }
862
888
  /**
@@ -1311,7 +1337,7 @@
1311
1337
  if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
1312
1338
  throw error_1;
1313
1339
  }
1314
- errors.push(error_1);
1340
+ errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
1315
1341
  return [3 /*break*/, 13];
1316
1342
  case 13:
1317
1343
  _b = _a.next();
@@ -1338,7 +1364,10 @@
1338
1364
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
1339
1365
  // 3) ...
1340
1366
  spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
1341
- .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
1367
+ .map(function (_a, i) {
1368
+ var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
1369
+ return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
1370
+ })
1342
1371
  .join('\n')), "\n\n "); }));
1343
1372
  }
1344
1373
  else if (this.llmExecutionTools.length === 0) {
@@ -1651,10 +1680,11 @@
1651
1680
  // <- Note: [🗨]
1652
1681
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
1653
1682
  });
1683
+ var usedEnvMessage = "Unknown `.env` file" ;
1654
1684
  if (metadata.length === 0) {
1655
- return "No LLM providers are available.";
1685
+ return spaceTrim__default["default"](function (block) { return "\n No LLM providers are available.\n\n ".concat(block(usedEnvMessage), "\n "); });
1656
1686
  }
1657
- return spaceTrim__default["default"](function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
1687
+ return spaceTrim__default["default"](function (block) { return "\n\n ".concat(block(usedEnvMessage), "\n\n Relevant environment variables:\n ").concat(block(Object.keys(env)
1658
1688
  .filter(function (envVariableName) {
1659
1689
  return metadata.some(function (_a) {
1660
1690
  var envVariables = _a.envVariables;
@@ -1756,6 +1786,99 @@
1756
1786
 
1757
1787
  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"}];
1758
1788
 
1789
+ /**
1790
+ * Checks if value is valid email
1791
+ *
1792
+ * @public exported from `@promptbook/utils`
1793
+ */
1794
+ function isValidEmail(email) {
1795
+ if (typeof email !== 'string') {
1796
+ return false;
1797
+ }
1798
+ if (email.split('\n').length > 1) {
1799
+ return false;
1800
+ }
1801
+ return /^.+@.+\..+$/.test(email);
1802
+ }
1803
+
1804
+ /**
1805
+ * Tests if given string is valid URL.
1806
+ *
1807
+ * Note: This does not check if the file exists only if the path is valid
1808
+ * @public exported from `@promptbook/utils`
1809
+ */
1810
+ function isValidFilePath(filename) {
1811
+ if (typeof filename !== 'string') {
1812
+ return false;
1813
+ }
1814
+ if (filename.split('\n').length > 1) {
1815
+ return false;
1816
+ }
1817
+ if (filename.split(' ').length >
1818
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
1819
+ return false;
1820
+ }
1821
+ var filenameSlashes = filename.split('\\').join('/');
1822
+ // Absolute Unix path: /hello.txt
1823
+ if (/^(\/)/i.test(filenameSlashes)) {
1824
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
1825
+ return true;
1826
+ }
1827
+ // Absolute Windows path: /hello.txt
1828
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1829
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
1830
+ return true;
1831
+ }
1832
+ // Relative path: ./hello.txt
1833
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1834
+ // console.log(filename, 'Relative path: ./hello.txt');
1835
+ return true;
1836
+ }
1837
+ // Allow paths like foo/hello
1838
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
1839
+ // console.log(filename, 'Allow paths like foo/hello');
1840
+ return true;
1841
+ }
1842
+ // Allow paths like hello.book
1843
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
1844
+ // console.log(filename, 'Allow paths like hello.book');
1845
+ return true;
1846
+ }
1847
+ return false;
1848
+ }
1849
+ /**
1850
+ * TODO: [🍏] Implement for MacOs
1851
+ */
1852
+
1853
+ /**
1854
+ * Tests if given string is valid URL.
1855
+ *
1856
+ * Note: Dataurl are considered perfectly valid.
1857
+ * Note: There are two simmilar functions:
1858
+ * - `isValidUrl` which tests any URL
1859
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1860
+ *
1861
+ * @public exported from `@promptbook/utils`
1862
+ */
1863
+ function isValidUrl(url) {
1864
+ if (typeof url !== 'string') {
1865
+ return false;
1866
+ }
1867
+ try {
1868
+ if (url.startsWith('blob:')) {
1869
+ url = url.replace(/^blob:/, '');
1870
+ }
1871
+ var urlObject = new URL(url /* because fail is handled */);
1872
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1873
+ return false;
1874
+ }
1875
+ return true;
1876
+ }
1877
+ catch (error) {
1878
+ return false;
1879
+ }
1880
+ }
1881
+
1759
1882
  /**
1760
1883
  * Function isValidJsonString will tell you if the string is valid JSON or not
1761
1884
  *
@@ -1790,6 +1913,15 @@
1790
1913
  if (isValidJsonString(pipelineString)) {
1791
1914
  throw new ParseError('Expected a book, but got a JSON string');
1792
1915
  }
1916
+ else if (isValidUrl(pipelineString)) {
1917
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1918
+ }
1919
+ else if (isValidFilePath(pipelineString)) {
1920
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1921
+ }
1922
+ else if (isValidEmail(pipelineString)) {
1923
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1924
+ }
1793
1925
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1794
1926
  return pipelineString;
1795
1927
  }
@@ -2433,35 +2565,6 @@
2433
2565
  return isHostnameOnPrivateNetwork(url.hostname);
2434
2566
  }
2435
2567
 
2436
- /**
2437
- * Tests if given string is valid URL.
2438
- *
2439
- * Note: Dataurl are considered perfectly valid.
2440
- * Note: There are two simmilar functions:
2441
- * - `isValidUrl` which tests any URL
2442
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
2443
- *
2444
- * @public exported from `@promptbook/utils`
2445
- */
2446
- function isValidUrl(url) {
2447
- if (typeof url !== 'string') {
2448
- return false;
2449
- }
2450
- try {
2451
- if (url.startsWith('blob:')) {
2452
- url = url.replace(/^blob:/, '');
2453
- }
2454
- var urlObject = new URL(url /* because fail is handled */);
2455
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
2456
- return false;
2457
- }
2458
- return true;
2459
- }
2460
- catch (error) {
2461
- return false;
2462
- }
2463
- }
2464
-
2465
2568
  /**
2466
2569
  * Tests if given string is valid pipeline URL URL.
2467
2570
  *
@@ -2961,12 +3064,28 @@
2961
3064
  /**
2962
3065
  * Asserts that the execution of a Promptbook is successful
2963
3066
  *
3067
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
3068
+ *
2964
3069
  * @param executionResult - The partial result of the Promptbook execution
2965
3070
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2966
3071
  * @public exported from `@promptbook/core`
2967
3072
  */
2968
3073
  function assertsExecutionSuccessful(executionResult) {
2969
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
3074
+ var e_1, _a;
3075
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
3076
+ try {
3077
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
3078
+ var warning = warnings_1_1.value;
3079
+ console.warn(warning.message);
3080
+ }
3081
+ }
3082
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3083
+ finally {
3084
+ try {
3085
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
3086
+ }
3087
+ finally { if (e_1) throw e_1.error; }
3088
+ }
2970
3089
  if (isSuccessful === true) {
2971
3090
  return;
2972
3091
  }
@@ -5975,6 +6094,15 @@
5975
6094
  * TODO: [🐱‍🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
5976
6095
  */
5977
6096
 
6097
+ /**
6098
+ * @@@
6099
+ *
6100
+ * @private for `FileCacheStorage`
6101
+ */
6102
+ function nameToSubfolderPath(name) {
6103
+ return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
6104
+ }
6105
+
5978
6106
  /**
5979
6107
  * Convert file extension to mime type
5980
6108
  *
@@ -6031,53 +6159,55 @@
6031
6159
  */
6032
6160
 
6033
6161
  /**
6034
- * Tests if given string is valid URL.
6162
+ * Convert mime type to file extension
6035
6163
  *
6036
- * Note: This does not check if the file exists only if the path is valid
6164
+ * Note: If the mime type is invalid, `null` is returned
6165
+ *
6166
+ * @private within the repository
6167
+ */
6168
+ function mimeTypeToExtension(value) {
6169
+ return mimeTypes.extension(value) || null;
6170
+ }
6171
+
6172
+ /**
6173
+ * Removes emojis from a string and fix whitespaces
6174
+ *
6175
+ * @param text with emojis
6176
+ * @returns text without emojis
6037
6177
  * @public exported from `@promptbook/utils`
6038
6178
  */
6039
- function isValidFilePath(filename) {
6040
- if (typeof filename !== 'string') {
6041
- return false;
6042
- }
6043
- if (filename.split('\n').length > 1) {
6044
- return false;
6045
- }
6046
- if (filename.split(' ').length >
6047
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
6048
- return false;
6049
- }
6050
- var filenameSlashes = filename.split('\\').join('/');
6051
- // Absolute Unix path: /hello.txt
6052
- if (/^(\/)/i.test(filenameSlashes)) {
6053
- // console.log(filename, 'Absolute Unix path: /hello.txt');
6054
- return true;
6055
- }
6056
- // Absolute Windows path: /hello.txt
6057
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
6058
- // console.log(filename, 'Absolute Windows path: /hello.txt');
6059
- return true;
6060
- }
6061
- // Relative path: ./hello.txt
6062
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
6063
- // console.log(filename, 'Relative path: ./hello.txt');
6064
- return true;
6065
- }
6066
- // Allow paths like foo/hello
6067
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
6068
- // console.log(filename, 'Allow paths like foo/hello');
6069
- return true;
6070
- }
6071
- // Allow paths like hello.book
6072
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
6073
- // console.log(filename, 'Allow paths like hello.book');
6074
- return true;
6075
- }
6076
- return false;
6179
+ function removeEmojis(text) {
6180
+ // Replace emojis (and also ZWJ sequence) with hyphens
6181
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
6182
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
6183
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
6184
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
6185
+ return text;
6077
6186
  }
6187
+
6078
6188
  /**
6079
- * TODO: [🍏] Implement for MacOs
6189
+ * @@@
6190
+ *
6191
+ * @param value @@@
6192
+ * @returns @@@
6193
+ * @example @@@
6194
+ * @public exported from `@promptbook/utils`
6080
6195
  */
6196
+ function titleToName(value) {
6197
+ if (isValidUrl(value)) {
6198
+ value = value.replace(/^https?:\/\//, '');
6199
+ value = value.replace(/\.html$/, '');
6200
+ }
6201
+ else if (isValidFilePath(value)) {
6202
+ value = path.basename(value);
6203
+ // Note: Keeping extension in the name
6204
+ }
6205
+ value = value.split('/').join('-');
6206
+ value = removeEmojis(value);
6207
+ value = normalizeToKebabCase(value);
6208
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
6209
+ return value;
6210
+ }
6081
6211
 
6082
6212
  /**
6083
6213
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -6114,9 +6244,9 @@
6114
6244
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6115
6245
  var _a;
6116
6246
  return __awaiter(this, void 0, void 0, function () {
6117
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
6118
- return __generator(this, function (_f) {
6119
- switch (_f.label) {
6247
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
6248
+ return __generator(this, function (_h) {
6249
+ switch (_h.label) {
6120
6250
  case 0:
6121
6251
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
6122
6252
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -6125,54 +6255,76 @@
6125
6255
  if (!name) {
6126
6256
  name = knowledgeSourceContentToName(knowledgeSourceContent);
6127
6257
  }
6128
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
6258
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
6129
6259
  url = knowledgeSourceContent;
6130
6260
  return [4 /*yield*/, fetch(url)];
6131
6261
  case 1:
6132
- response_1 = _f.sent();
6262
+ response_1 = _h.sent();
6133
6263
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
6134
- return [2 /*return*/, {
6135
- source: name,
6136
- filename: null,
6137
- url: url,
6138
- mimeType: mimeType,
6139
- /*
6140
- TODO: [🥽]
6141
- > async asBlob() {
6142
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
6143
- > const content = await response.blob();
6144
- > return content;
6145
- > },
6146
- */
6147
- asJson: function () {
6148
- return __awaiter(this, void 0, void 0, function () {
6149
- var content;
6150
- return __generator(this, function (_a) {
6151
- switch (_a.label) {
6152
- case 0: return [4 /*yield*/, response_1.json()];
6153
- case 1:
6154
- content = _a.sent();
6155
- return [2 /*return*/, content];
6156
- }
6264
+ if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
6265
+ return [2 /*return*/, {
6266
+ source: name,
6267
+ filename: null,
6268
+ url: url,
6269
+ mimeType: mimeType,
6270
+ /*
6271
+ TODO: [🥽]
6272
+ > async asBlob() {
6273
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
6274
+ > const content = await response.blob();
6275
+ > return content;
6276
+ > },
6277
+ */
6278
+ asJson: function () {
6279
+ return __awaiter(this, void 0, void 0, function () {
6280
+ var content;
6281
+ return __generator(this, function (_a) {
6282
+ switch (_a.label) {
6283
+ case 0: return [4 /*yield*/, response_1.json()];
6284
+ case 1:
6285
+ content = _a.sent();
6286
+ return [2 /*return*/, content];
6287
+ }
6288
+ });
6157
6289
  });
6158
- });
6159
- },
6160
- asText: function () {
6161
- return __awaiter(this, void 0, void 0, function () {
6162
- var content;
6163
- return __generator(this, function (_a) {
6164
- switch (_a.label) {
6165
- case 0: return [4 /*yield*/, response_1.text()];
6166
- case 1:
6167
- content = _a.sent();
6168
- return [2 /*return*/, content];
6169
- }
6290
+ },
6291
+ asText: function () {
6292
+ return __awaiter(this, void 0, void 0, function () {
6293
+ var content;
6294
+ return __generator(this, function (_a) {
6295
+ switch (_a.label) {
6296
+ case 0: return [4 /*yield*/, response_1.text()];
6297
+ case 1:
6298
+ content = _a.sent();
6299
+ return [2 /*return*/, content];
6300
+ }
6301
+ });
6170
6302
  });
6171
- });
6172
- },
6173
- }];
6303
+ },
6304
+ }];
6305
+ }
6306
+ basename = url.split('/').pop() || titleToName(url);
6307
+ hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
6308
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
6309
+ filepath = path.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));
6310
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
6174
6311
  case 2:
6175
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
6312
+ _h.sent();
6313
+ _g = (_f = Buffer).from;
6314
+ return [4 /*yield*/, response_1.arrayBuffer()];
6315
+ case 3:
6316
+ fileContent = _g.apply(_f, [_h.sent()]);
6317
+ if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
6318
+ 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."));
6319
+ }
6320
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
6321
+ case 4:
6322
+ _h.sent();
6323
+ // TODO: [💵] Check the file security
6324
+ // TODO: [🧹][🧠] Delete the file after the scraping is done
6325
+ return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6326
+ case 5:
6327
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
6176
6328
  if (tools.fs === undefined) {
6177
6329
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
6178
6330
  // <- TODO: [🧠] What is the best error type here`
@@ -6185,8 +6337,8 @@
6185
6337
  fileExtension = getFileExtension(filename_1);
6186
6338
  mimeType = extensionToMimeType(fileExtension || '');
6187
6339
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6188
- case 3:
6189
- if (!(_f.sent())) {
6340
+ case 6:
6341
+ if (!(_h.sent())) {
6190
6342
  throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
6191
6343
  }
6192
6344
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -6232,7 +6384,7 @@
6232
6384
  });
6233
6385
  },
6234
6386
  }];
6235
- case 4: return [2 /*return*/, {
6387
+ case 7: return [2 /*return*/, {
6236
6388
  source: name,
6237
6389
  filename: null,
6238
6390
  url: null,
@@ -6602,6 +6754,10 @@
6602
6754
  return [4 /*yield*/, scraperFactory(tools, options || {})];
6603
6755
  case 3:
6604
6756
  scraper = _g.sent();
6757
+ if (scraper.metadata.packageName === '@promptbook/boilerplate' ||
6758
+ scraper.metadata.mimeTypes.some(function (mimeType) { return mimeType.includes('DISABLED'); })) {
6759
+ return [3 /*break*/, 4];
6760
+ }
6605
6761
  scrapers.push(scraper);
6606
6762
  _g.label = 4;
6607
6763
  case 4: