@promptbook/node 0.84.0-10 → 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.
- package/esm/index.es.js +128 -88
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
- package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
- package/package.json +2 -2
- package/umd/index.umd.js +128 -88
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -317,22 +317,94 @@ true);
|
|
|
317
317
|
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"}];
|
|
318
318
|
|
|
319
319
|
/**
|
|
320
|
-
*
|
|
320
|
+
* Checks if value is valid email
|
|
321
321
|
*
|
|
322
322
|
* @public exported from `@promptbook/utils`
|
|
323
323
|
*/
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
function isValidEmail(email) {
|
|
325
|
+
if (typeof email !== 'string') {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if (email.split('\n').length > 1) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return /^.+@.+\..+$/.test(email);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Tests if given string is valid URL.
|
|
336
|
+
*
|
|
337
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
338
|
+
* @public exported from `@promptbook/utils`
|
|
339
|
+
*/
|
|
340
|
+
function isValidFilePath(filename) {
|
|
341
|
+
if (typeof filename !== 'string') {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (filename.split('\n').length > 1) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
if (filename.split(' ').length >
|
|
348
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
352
|
+
// Absolute Unix path: /hello.txt
|
|
353
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
354
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
327
355
|
return true;
|
|
328
356
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
357
|
+
// Absolute Windows path: /hello.txt
|
|
358
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
359
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
// Relative path: ./hello.txt
|
|
363
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
364
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
// Allow paths like foo/hello
|
|
368
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
369
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
// Allow paths like hello.book
|
|
373
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
374
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* TODO: [🍏] Implement for MacOs
|
|
381
|
+
*/
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Tests if given string is valid URL.
|
|
385
|
+
*
|
|
386
|
+
* Note: Dataurl are considered perfectly valid.
|
|
387
|
+
* Note: There are two simmilar functions:
|
|
388
|
+
* - `isValidUrl` which tests any URL
|
|
389
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
390
|
+
*
|
|
391
|
+
* @public exported from `@promptbook/utils`
|
|
392
|
+
*/
|
|
393
|
+
function isValidUrl(url) {
|
|
394
|
+
if (typeof url !== 'string') {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
try {
|
|
398
|
+
if (url.startsWith('blob:')) {
|
|
399
|
+
url = url.replace(/^blob:/, '');
|
|
332
400
|
}
|
|
333
|
-
|
|
401
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
402
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
334
403
|
return false;
|
|
335
404
|
}
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
336
408
|
return false;
|
|
337
409
|
}
|
|
338
410
|
}
|
|
@@ -356,6 +428,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
356
428
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
357
429
|
*/
|
|
358
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
433
|
+
*
|
|
434
|
+
* @public exported from `@promptbook/utils`
|
|
435
|
+
*/
|
|
436
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
437
|
+
try {
|
|
438
|
+
JSON.parse(value);
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
if (!(error instanceof Error)) {
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
if (error.message.includes('Unexpected token')) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
359
452
|
/**
|
|
360
453
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
361
454
|
* 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.
|
|
@@ -369,6 +462,15 @@ function validatePipelineString(pipelineString) {
|
|
|
369
462
|
if (isValidJsonString(pipelineString)) {
|
|
370
463
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
371
464
|
}
|
|
465
|
+
else if (isValidUrl(pipelineString)) {
|
|
466
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
467
|
+
}
|
|
468
|
+
else if (isValidFilePath(pipelineString)) {
|
|
469
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
470
|
+
}
|
|
471
|
+
else if (isValidEmail(pipelineString)) {
|
|
472
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
473
|
+
}
|
|
372
474
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
373
475
|
return pipelineString;
|
|
374
476
|
}
|
|
@@ -1062,35 +1164,6 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
1062
1164
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1063
1165
|
}
|
|
1064
1166
|
|
|
1065
|
-
/**
|
|
1066
|
-
* Tests if given string is valid URL.
|
|
1067
|
-
*
|
|
1068
|
-
* Note: Dataurl are considered perfectly valid.
|
|
1069
|
-
* Note: There are two simmilar functions:
|
|
1070
|
-
* - `isValidUrl` which tests any URL
|
|
1071
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1072
|
-
*
|
|
1073
|
-
* @public exported from `@promptbook/utils`
|
|
1074
|
-
*/
|
|
1075
|
-
function isValidUrl(url) {
|
|
1076
|
-
if (typeof url !== 'string') {
|
|
1077
|
-
return false;
|
|
1078
|
-
}
|
|
1079
|
-
try {
|
|
1080
|
-
if (url.startsWith('blob:')) {
|
|
1081
|
-
url = url.replace(/^blob:/, '');
|
|
1082
|
-
}
|
|
1083
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
1084
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1085
|
-
return false;
|
|
1086
|
-
}
|
|
1087
|
-
return true;
|
|
1088
|
-
}
|
|
1089
|
-
catch (error) {
|
|
1090
|
-
return false;
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
1167
|
/**
|
|
1095
1168
|
* Tests if given string is valid pipeline URL URL.
|
|
1096
1169
|
*
|
|
@@ -1845,12 +1918,28 @@ function deserializeError(error) {
|
|
|
1845
1918
|
/**
|
|
1846
1919
|
* Asserts that the execution of a Promptbook is successful
|
|
1847
1920
|
*
|
|
1921
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
1922
|
+
*
|
|
1848
1923
|
* @param executionResult - The partial result of the Promptbook execution
|
|
1849
1924
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1850
1925
|
* @public exported from `@promptbook/core`
|
|
1851
1926
|
*/
|
|
1852
1927
|
function assertsExecutionSuccessful(executionResult) {
|
|
1853
|
-
var
|
|
1928
|
+
var e_1, _a;
|
|
1929
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
1930
|
+
try {
|
|
1931
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
1932
|
+
var warning = warnings_1_1.value;
|
|
1933
|
+
console.warn(warning.message);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1937
|
+
finally {
|
|
1938
|
+
try {
|
|
1939
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
1940
|
+
}
|
|
1941
|
+
finally { if (e_1) throw e_1.error; }
|
|
1942
|
+
}
|
|
1854
1943
|
if (isSuccessful === true) {
|
|
1855
1944
|
return;
|
|
1856
1945
|
}
|
|
@@ -5362,55 +5451,6 @@ function isFileExisting(filename, fs) {
|
|
|
5362
5451
|
* TODO: [🖇] What about symlinks?
|
|
5363
5452
|
*/
|
|
5364
5453
|
|
|
5365
|
-
/**
|
|
5366
|
-
* Tests if given string is valid URL.
|
|
5367
|
-
*
|
|
5368
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
5369
|
-
* @public exported from `@promptbook/utils`
|
|
5370
|
-
*/
|
|
5371
|
-
function isValidFilePath(filename) {
|
|
5372
|
-
if (typeof filename !== 'string') {
|
|
5373
|
-
return false;
|
|
5374
|
-
}
|
|
5375
|
-
if (filename.split('\n').length > 1) {
|
|
5376
|
-
return false;
|
|
5377
|
-
}
|
|
5378
|
-
if (filename.split(' ').length >
|
|
5379
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
5380
|
-
return false;
|
|
5381
|
-
}
|
|
5382
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
5383
|
-
// Absolute Unix path: /hello.txt
|
|
5384
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5385
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
5386
|
-
return true;
|
|
5387
|
-
}
|
|
5388
|
-
// Absolute Windows path: /hello.txt
|
|
5389
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5390
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
5391
|
-
return true;
|
|
5392
|
-
}
|
|
5393
|
-
// Relative path: ./hello.txt
|
|
5394
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5395
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
5396
|
-
return true;
|
|
5397
|
-
}
|
|
5398
|
-
// Allow paths like foo/hello
|
|
5399
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
5400
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
5401
|
-
return true;
|
|
5402
|
-
}
|
|
5403
|
-
// Allow paths like hello.book
|
|
5404
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
5405
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
5406
|
-
return true;
|
|
5407
|
-
}
|
|
5408
|
-
return false;
|
|
5409
|
-
}
|
|
5410
|
-
/**
|
|
5411
|
-
* TODO: [🍏] Implement for MacOs
|
|
5412
|
-
*/
|
|
5413
|
-
|
|
5414
5454
|
/**
|
|
5415
5455
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5416
5456
|
*
|