@promptbook/markdown-utils 0.84.0-0 → 0.84.0-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +1 -0
  2. package/esm/index.es.js +123 -83
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +8 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
  7. package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  9. package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
  10. package/esm/typings/src/constants.d.ts +1 -1
  11. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
  12. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
  13. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
  14. package/esm/typings/src/pipeline/book-notation.d.ts +5 -0
  15. package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
  16. package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
  17. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
  18. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
  19. package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
  20. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
  21. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
  22. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
  23. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
  24. package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
  25. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
  26. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
  27. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +123 -83
  30. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -24,7 +24,7 @@
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -362,6 +362,99 @@
362
362
 
363
363
  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"}];
364
364
 
365
+ /**
366
+ * Checks if value is valid email
367
+ *
368
+ * @public exported from `@promptbook/utils`
369
+ */
370
+ function isValidEmail(email) {
371
+ if (typeof email !== 'string') {
372
+ return false;
373
+ }
374
+ if (email.split('\n').length > 1) {
375
+ return false;
376
+ }
377
+ return /^.+@.+\..+$/.test(email);
378
+ }
379
+
380
+ /**
381
+ * Tests if given string is valid URL.
382
+ *
383
+ * Note: This does not check if the file exists only if the path is valid
384
+ * @public exported from `@promptbook/utils`
385
+ */
386
+ function isValidFilePath(filename) {
387
+ if (typeof filename !== 'string') {
388
+ return false;
389
+ }
390
+ if (filename.split('\n').length > 1) {
391
+ return false;
392
+ }
393
+ if (filename.split(' ').length >
394
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
395
+ return false;
396
+ }
397
+ var filenameSlashes = filename.split('\\').join('/');
398
+ // Absolute Unix path: /hello.txt
399
+ if (/^(\/)/i.test(filenameSlashes)) {
400
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
401
+ return true;
402
+ }
403
+ // Absolute Windows path: /hello.txt
404
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
405
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
406
+ return true;
407
+ }
408
+ // Relative path: ./hello.txt
409
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
410
+ // console.log(filename, 'Relative path: ./hello.txt');
411
+ return true;
412
+ }
413
+ // Allow paths like foo/hello
414
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
415
+ // console.log(filename, 'Allow paths like foo/hello');
416
+ return true;
417
+ }
418
+ // Allow paths like hello.book
419
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
420
+ // console.log(filename, 'Allow paths like hello.book');
421
+ return true;
422
+ }
423
+ return false;
424
+ }
425
+ /**
426
+ * TODO: [🍏] Implement for MacOs
427
+ */
428
+
429
+ /**
430
+ * Tests if given string is valid URL.
431
+ *
432
+ * Note: Dataurl are considered perfectly valid.
433
+ * Note: There are two simmilar functions:
434
+ * - `isValidUrl` which tests any URL
435
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
436
+ *
437
+ * @public exported from `@promptbook/utils`
438
+ */
439
+ function isValidUrl(url) {
440
+ if (typeof url !== 'string') {
441
+ return false;
442
+ }
443
+ try {
444
+ if (url.startsWith('blob:')) {
445
+ url = url.replace(/^blob:/, '');
446
+ }
447
+ var urlObject = new URL(url /* because fail is handled */);
448
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
449
+ return false;
450
+ }
451
+ return true;
452
+ }
453
+ catch (error) {
454
+ return false;
455
+ }
456
+ }
457
+
365
458
  /**
366
459
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
367
460
  * 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.
@@ -375,6 +468,15 @@
375
468
  if (isValidJsonString(pipelineString)) {
376
469
  throw new ParseError('Expected a book, but got a JSON string');
377
470
  }
471
+ else if (isValidUrl(pipelineString)) {
472
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
473
+ }
474
+ else if (isValidFilePath(pipelineString)) {
475
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
476
+ }
477
+ else if (isValidEmail(pipelineString)) {
478
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
479
+ }
378
480
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
379
481
  return pipelineString;
380
482
  }
@@ -662,7 +764,7 @@
662
764
  *
663
765
  * @public exported from `@promptbook/core`
664
766
  */
665
- var ADMIN_EMAIL = 'me@pavolhejny.com';
767
+ var ADMIN_EMAIL = 'pavol@ptbk.io';
666
768
  /**
667
769
  * Name of the responsible person for the Promptbook on GitHub
668
770
  *
@@ -1063,7 +1165,7 @@
1063
1165
  *
1064
1166
  * @private within the repository
1065
1167
  */
1066
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
1168
+ var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1067
1169
  /**
1068
1170
  * @@@
1069
1171
  *
@@ -1209,35 +1311,6 @@
1209
1311
  return isHostnameOnPrivateNetwork(url.hostname);
1210
1312
  }
1211
1313
 
1212
- /**
1213
- * Tests if given string is valid URL.
1214
- *
1215
- * Note: Dataurl are considered perfectly valid.
1216
- * Note: There are two simmilar functions:
1217
- * - `isValidUrl` which tests any URL
1218
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1219
- *
1220
- * @public exported from `@promptbook/utils`
1221
- */
1222
- function isValidUrl(url) {
1223
- if (typeof url !== 'string') {
1224
- return false;
1225
- }
1226
- try {
1227
- if (url.startsWith('blob:')) {
1228
- url = url.replace(/^blob:/, '');
1229
- }
1230
- var urlObject = new URL(url /* because fail is handled */);
1231
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1232
- return false;
1233
- }
1234
- return true;
1235
- }
1236
- catch (error) {
1237
- return false;
1238
- }
1239
- }
1240
-
1241
1314
  /**
1242
1315
  * Tests if given string is valid pipeline URL URL.
1243
1316
  *
@@ -1906,7 +1979,7 @@
1906
1979
  var NotYetImplementedError = /** @class */ (function (_super) {
1907
1980
  __extends(NotYetImplementedError, _super);
1908
1981
  function NotYetImplementedError(message) {
1909
- var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
1982
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
1910
1983
  _this.name = 'NotYetImplementedError';
1911
1984
  Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
1912
1985
  return _this;
@@ -1992,12 +2065,28 @@
1992
2065
  /**
1993
2066
  * Asserts that the execution of a Promptbook is successful
1994
2067
  *
2068
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2069
+ *
1995
2070
  * @param executionResult - The partial result of the Promptbook execution
1996
2071
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
1997
2072
  * @public exported from `@promptbook/core`
1998
2073
  */
1999
2074
  function assertsExecutionSuccessful(executionResult) {
2000
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2075
+ var e_1, _a;
2076
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2077
+ try {
2078
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2079
+ var warning = warnings_1_1.value;
2080
+ console.warn(warning.message);
2081
+ }
2082
+ }
2083
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2084
+ finally {
2085
+ try {
2086
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2087
+ }
2088
+ finally { if (e_1) throw e_1.error; }
2089
+ }
2001
2090
  if (isSuccessful === true) {
2002
2091
  return;
2003
2092
  }
@@ -3502,55 +3591,6 @@
3502
3591
  * TODO: [🖇] What about symlinks?
3503
3592
  */
3504
3593
 
3505
- /**
3506
- * Tests if given string is valid URL.
3507
- *
3508
- * Note: This does not check if the file exists only if the path is valid
3509
- * @public exported from `@promptbook/utils`
3510
- */
3511
- function isValidFilePath(filename) {
3512
- if (typeof filename !== 'string') {
3513
- return false;
3514
- }
3515
- if (filename.split('\n').length > 1) {
3516
- return false;
3517
- }
3518
- if (filename.split(' ').length >
3519
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
3520
- return false;
3521
- }
3522
- var filenameSlashes = filename.split('\\').join('/');
3523
- // Absolute Unix path: /hello.txt
3524
- if (/^(\/)/i.test(filenameSlashes)) {
3525
- // console.log(filename, 'Absolute Unix path: /hello.txt');
3526
- return true;
3527
- }
3528
- // Absolute Windows path: /hello.txt
3529
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
3530
- // console.log(filename, 'Absolute Windows path: /hello.txt');
3531
- return true;
3532
- }
3533
- // Relative path: ./hello.txt
3534
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
3535
- // console.log(filename, 'Relative path: ./hello.txt');
3536
- return true;
3537
- }
3538
- // Allow paths like foo/hello
3539
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
3540
- // console.log(filename, 'Allow paths like foo/hello');
3541
- return true;
3542
- }
3543
- // Allow paths like hello.book
3544
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
3545
- // console.log(filename, 'Allow paths like hello.book');
3546
- return true;
3547
- }
3548
- return false;
3549
- }
3550
- /**
3551
- * TODO: [🍏] Implement for MacOs
3552
- */
3553
-
3554
3594
  /**
3555
3595
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3556
3596
  *