@promptbook/remote-server 0.84.0-20 → 0.84.0-9

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 (29) hide show
  1. package/README.md +5 -11
  2. package/esm/index.es.js +123 -268
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +0 -4
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -12
  6. package/esm/typings/src/_packages/types.index.d.ts +0 -2
  7. package/esm/typings/src/_packages/utils.index.d.ts +0 -2
  8. package/esm/typings/src/_packages/wizzard.index.d.ts +0 -4
  9. package/esm/typings/src/config.d.ts +1 -27
  10. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  11. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  12. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
  13. package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
  14. package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
  15. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  16. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
  17. package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
  18. package/package.json +16 -9
  19. package/umd/index.umd.js +123 -268
  20. package/umd/index.umd.js.map +1 -1
  21. package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
  22. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
  23. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
  24. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
  25. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
  26. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
  27. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
  28. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
  29. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -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/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';
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';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -11,7 +11,6 @@
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);
15
14
 
16
15
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
17
16
  /**
@@ -27,7 +26,7 @@
27
26
  * @generated
28
27
  * @see https://github.com/webgptorg/promptbook
29
28
  */
30
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-19';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
31
30
  /**
32
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -198,12 +197,6 @@
198
197
  * @public exported from `@promptbook/core`
199
198
  */
200
199
  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
207
200
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
208
201
  /**
209
202
  * The maximum number of iterations for a loops
@@ -237,12 +230,6 @@
237
230
  * @private within the repository - too low-level in comparison with other `MAX_...`
238
231
  */
239
232
  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;
246
233
  /**
247
234
  * Strategy for caching the intermediate results for knowledge sources
248
235
  *
@@ -262,15 +249,6 @@
262
249
  * @public exported from `@promptbook/core`
263
250
  */
264
251
  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';
274
252
  /**
275
253
  * Where to store the scrape cache
276
254
  *
@@ -879,7 +857,6 @@
879
857
  readFile: promises.readFile,
880
858
  writeFile: promises.writeFile,
881
859
  readdir: promises.readdir,
882
- mkdir: promises.mkdir,
883
860
  };
884
861
  }
885
862
  /**
@@ -1779,99 +1756,6 @@
1779
1756
 
1780
1757
  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"}];
1781
1758
 
1782
- /**
1783
- * Checks if value is valid email
1784
- *
1785
- * @public exported from `@promptbook/utils`
1786
- */
1787
- function isValidEmail(email) {
1788
- if (typeof email !== 'string') {
1789
- return false;
1790
- }
1791
- if (email.split('\n').length > 1) {
1792
- return false;
1793
- }
1794
- return /^.+@.+\..+$/.test(email);
1795
- }
1796
-
1797
- /**
1798
- * Tests if given string is valid URL.
1799
- *
1800
- * Note: This does not check if the file exists only if the path is valid
1801
- * @public exported from `@promptbook/utils`
1802
- */
1803
- function isValidFilePath(filename) {
1804
- if (typeof filename !== 'string') {
1805
- return false;
1806
- }
1807
- if (filename.split('\n').length > 1) {
1808
- return false;
1809
- }
1810
- if (filename.split(' ').length >
1811
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
1812
- return false;
1813
- }
1814
- var filenameSlashes = filename.split('\\').join('/');
1815
- // Absolute Unix path: /hello.txt
1816
- if (/^(\/)/i.test(filenameSlashes)) {
1817
- // console.log(filename, 'Absolute Unix path: /hello.txt');
1818
- return true;
1819
- }
1820
- // Absolute Windows path: /hello.txt
1821
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1822
- // console.log(filename, 'Absolute Windows path: /hello.txt');
1823
- return true;
1824
- }
1825
- // Relative path: ./hello.txt
1826
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1827
- // console.log(filename, 'Relative path: ./hello.txt');
1828
- return true;
1829
- }
1830
- // Allow paths like foo/hello
1831
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
1832
- // console.log(filename, 'Allow paths like foo/hello');
1833
- return true;
1834
- }
1835
- // Allow paths like hello.book
1836
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
1837
- // console.log(filename, 'Allow paths like hello.book');
1838
- return true;
1839
- }
1840
- return false;
1841
- }
1842
- /**
1843
- * TODO: [🍏] Implement for MacOs
1844
- */
1845
-
1846
- /**
1847
- * Tests if given string is valid URL.
1848
- *
1849
- * Note: Dataurl are considered perfectly valid.
1850
- * Note: There are two simmilar functions:
1851
- * - `isValidUrl` which tests any URL
1852
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1853
- *
1854
- * @public exported from `@promptbook/utils`
1855
- */
1856
- function isValidUrl(url) {
1857
- if (typeof url !== 'string') {
1858
- return false;
1859
- }
1860
- try {
1861
- if (url.startsWith('blob:')) {
1862
- url = url.replace(/^blob:/, '');
1863
- }
1864
- var urlObject = new URL(url /* because fail is handled */);
1865
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1866
- return false;
1867
- }
1868
- return true;
1869
- }
1870
- catch (error) {
1871
- return false;
1872
- }
1873
- }
1874
-
1875
1759
  /**
1876
1760
  * Function isValidJsonString will tell you if the string is valid JSON or not
1877
1761
  *
@@ -1906,15 +1790,6 @@
1906
1790
  if (isValidJsonString(pipelineString)) {
1907
1791
  throw new ParseError('Expected a book, but got a JSON string');
1908
1792
  }
1909
- else if (isValidUrl(pipelineString)) {
1910
- throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1911
- }
1912
- else if (isValidFilePath(pipelineString)) {
1913
- throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1914
- }
1915
- else if (isValidEmail(pipelineString)) {
1916
- throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1917
- }
1918
1793
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1919
1794
  return pipelineString;
1920
1795
  }
@@ -2558,6 +2433,35 @@
2558
2433
  return isHostnameOnPrivateNetwork(url.hostname);
2559
2434
  }
2560
2435
 
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
+
2561
2465
  /**
2562
2466
  * Tests if given string is valid pipeline URL URL.
2563
2467
  *
@@ -3057,28 +2961,12 @@
3057
2961
  /**
3058
2962
  * Asserts that the execution of a Promptbook is successful
3059
2963
  *
3060
- * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
3061
- *
3062
2964
  * @param executionResult - The partial result of the Promptbook execution
3063
2965
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
3064
2966
  * @public exported from `@promptbook/core`
3065
2967
  */
3066
2968
  function assertsExecutionSuccessful(executionResult) {
3067
- var e_1, _a;
3068
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
3069
- try {
3070
- for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
3071
- var warning = warnings_1_1.value;
3072
- console.warn(warning.message);
3073
- }
3074
- }
3075
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3076
- finally {
3077
- try {
3078
- if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
3079
- }
3080
- finally { if (e_1) throw e_1.error; }
3081
- }
2969
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
3082
2970
  if (isSuccessful === true) {
3083
2971
  return;
3084
2972
  }
@@ -6087,15 +5975,6 @@
6087
5975
  * TODO: [🐱‍🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
6088
5976
  */
6089
5977
 
6090
- /**
6091
- * @@@
6092
- *
6093
- * @private for `FileCacheStorage`
6094
- */
6095
- function nameToSubfolderPath(name) {
6096
- return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
6097
- }
6098
-
6099
5978
  /**
6100
5979
  * Convert file extension to mime type
6101
5980
  *
@@ -6152,55 +6031,53 @@
6152
6031
  */
6153
6032
 
6154
6033
  /**
6155
- * Convert mime type to file extension
6156
- *
6157
- * Note: If the mime type is invalid, `null` is returned
6158
- *
6159
- * @private within the repository
6160
- */
6161
- function mimeTypeToExtension(value) {
6162
- return mimeTypes.extension(value) || null;
6163
- }
6164
-
6165
- /**
6166
- * Removes emojis from a string and fix whitespaces
6167
- *
6168
- * @param text with emojis
6169
- * @returns text without emojis
6170
- * @public exported from `@promptbook/utils`
6171
- */
6172
- function removeEmojis(text) {
6173
- // Replace emojis (and also ZWJ sequence) with hyphens
6174
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
6175
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
6176
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
6177
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
6178
- return text;
6179
- }
6180
-
6181
- /**
6182
- * @@@
6034
+ * Tests if given string is valid URL.
6183
6035
  *
6184
- * @param value @@@
6185
- * @returns @@@
6186
- * @example @@@
6036
+ * Note: This does not check if the file exists only if the path is valid
6187
6037
  * @public exported from `@promptbook/utils`
6188
6038
  */
6189
- function titleToName(value) {
6190
- if (isValidUrl(value)) {
6191
- value = value.replace(/^https?:\/\//, '');
6192
- value = value.replace(/\.html$/, '');
6039
+ function isValidFilePath(filename) {
6040
+ if (typeof filename !== 'string') {
6041
+ return false;
6193
6042
  }
6194
- else if (isValidFilePath(value)) {
6195
- value = path.basename(value);
6196
- // Note: Keeping extension in the name
6043
+ if (filename.split('\n').length > 1) {
6044
+ return false;
6197
6045
  }
6198
- value = value.split('/').join('-');
6199
- value = removeEmojis(value);
6200
- value = normalizeToKebabCase(value);
6201
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
6202
- return value;
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;
6203
6077
  }
6078
+ /**
6079
+ * TODO: [🍏] Implement for MacOs
6080
+ */
6204
6081
 
6205
6082
  /**
6206
6083
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -6237,9 +6114,9 @@
6237
6114
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6238
6115
  var _a;
6239
6116
  return __awaiter(this, void 0, void 0, function () {
6240
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
6241
- return __generator(this, function (_h) {
6242
- switch (_h.label) {
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) {
6243
6120
  case 0:
6244
6121
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
6245
6122
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -6248,76 +6125,54 @@
6248
6125
  if (!name) {
6249
6126
  name = knowledgeSourceContentToName(knowledgeSourceContent);
6250
6127
  }
6251
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
6128
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
6252
6129
  url = knowledgeSourceContent;
6253
6130
  return [4 /*yield*/, fetch(url)];
6254
6131
  case 1:
6255
- response_1 = _h.sent();
6132
+ response_1 = _f.sent();
6256
6133
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
6257
- if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
6258
- return [2 /*return*/, {
6259
- source: name,
6260
- filename: null,
6261
- url: url,
6262
- mimeType: mimeType,
6263
- /*
6264
- TODO: [🥽]
6265
- > async asBlob() {
6266
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
6267
- > const content = await response.blob();
6268
- > return content;
6269
- > },
6270
- */
6271
- asJson: function () {
6272
- return __awaiter(this, void 0, void 0, function () {
6273
- var content;
6274
- return __generator(this, function (_a) {
6275
- switch (_a.label) {
6276
- case 0: return [4 /*yield*/, response_1.json()];
6277
- case 1:
6278
- content = _a.sent();
6279
- return [2 /*return*/, content];
6280
- }
6281
- });
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
+ }
6282
6157
  });
6283
- },
6284
- asText: function () {
6285
- return __awaiter(this, void 0, void 0, function () {
6286
- var content;
6287
- return __generator(this, function (_a) {
6288
- switch (_a.label) {
6289
- case 0: return [4 /*yield*/, response_1.text()];
6290
- case 1:
6291
- content = _a.sent();
6292
- return [2 /*return*/, content];
6293
- }
6294
- });
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
+ }
6295
6170
  });
6296
- },
6297
- }];
6298
- }
6299
- basename = url.split('/').pop() || titleToName(url);
6300
- hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
6301
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
6302
- 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));
6303
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
6171
+ });
6172
+ },
6173
+ }];
6304
6174
  case 2:
6305
- _h.sent();
6306
- _g = (_f = Buffer).from;
6307
- return [4 /*yield*/, response_1.arrayBuffer()];
6308
- case 3:
6309
- fileContent = _g.apply(_f, [_h.sent()]);
6310
- if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
6311
- 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."));
6312
- }
6313
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
6314
- case 4:
6315
- _h.sent();
6316
- // TODO: [💵] Check the file security
6317
- // TODO: [🧹][🧠] Delete the file after the scraping is done
6318
- return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6319
- case 5:
6320
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
6175
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
6321
6176
  if (tools.fs === undefined) {
6322
6177
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
6323
6178
  // <- TODO: [🧠] What is the best error type here`
@@ -6330,8 +6185,8 @@
6330
6185
  fileExtension = getFileExtension(filename_1);
6331
6186
  mimeType = extensionToMimeType(fileExtension || '');
6332
6187
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6333
- case 6:
6334
- if (!(_h.sent())) {
6188
+ case 3:
6189
+ if (!(_f.sent())) {
6335
6190
  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 "); }));
6336
6191
  }
6337
6192
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -6377,7 +6232,7 @@
6377
6232
  });
6378
6233
  },
6379
6234
  }];
6380
- case 7: return [2 /*return*/, {
6235
+ case 4: return [2 /*return*/, {
6381
6236
  source: name,
6382
6237
  filename: null,
6383
6238
  url: null,