@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.
- package/README.md +1 -0
- package/esm/index.es.js +123 -83
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +8 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
- package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
- package/esm/typings/src/constants.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +5 -0
- package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
- package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +123 -83
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -269,6 +269,7 @@ Or you can install them separately:
|
|
|
269
269
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
270
270
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
271
271
|
- **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
|
|
272
|
+
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/markitdown)** - Integration of [Markitdown by Microsoft](https://github.com/microsoft/markitdown)
|
|
272
273
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
273
274
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
274
275
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
package/esm/index.es.js
CHANGED
|
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
22
22
|
* @generated
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -360,6 +360,99 @@ function extractJsonBlock(markdown) {
|
|
|
360
360
|
|
|
361
361
|
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"}];
|
|
362
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Checks if value is valid email
|
|
365
|
+
*
|
|
366
|
+
* @public exported from `@promptbook/utils`
|
|
367
|
+
*/
|
|
368
|
+
function isValidEmail(email) {
|
|
369
|
+
if (typeof email !== 'string') {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
if (email.split('\n').length > 1) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
return /^.+@.+\..+$/.test(email);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Tests if given string is valid URL.
|
|
380
|
+
*
|
|
381
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
382
|
+
* @public exported from `@promptbook/utils`
|
|
383
|
+
*/
|
|
384
|
+
function isValidFilePath(filename) {
|
|
385
|
+
if (typeof filename !== 'string') {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (filename.split('\n').length > 1) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (filename.split(' ').length >
|
|
392
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
396
|
+
// Absolute Unix path: /hello.txt
|
|
397
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
398
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
// Absolute Windows path: /hello.txt
|
|
402
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
403
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
// Relative path: ./hello.txt
|
|
407
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
408
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
// Allow paths like foo/hello
|
|
412
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
413
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
// Allow paths like hello.book
|
|
417
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
418
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* TODO: [🍏] Implement for MacOs
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Tests if given string is valid URL.
|
|
429
|
+
*
|
|
430
|
+
* Note: Dataurl are considered perfectly valid.
|
|
431
|
+
* Note: There are two simmilar functions:
|
|
432
|
+
* - `isValidUrl` which tests any URL
|
|
433
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
434
|
+
*
|
|
435
|
+
* @public exported from `@promptbook/utils`
|
|
436
|
+
*/
|
|
437
|
+
function isValidUrl(url) {
|
|
438
|
+
if (typeof url !== 'string') {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
if (url.startsWith('blob:')) {
|
|
443
|
+
url = url.replace(/^blob:/, '');
|
|
444
|
+
}
|
|
445
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
446
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
363
456
|
/**
|
|
364
457
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
365
458
|
* 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.
|
|
@@ -373,6 +466,15 @@ function validatePipelineString(pipelineString) {
|
|
|
373
466
|
if (isValidJsonString(pipelineString)) {
|
|
374
467
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
375
468
|
}
|
|
469
|
+
else if (isValidUrl(pipelineString)) {
|
|
470
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
471
|
+
}
|
|
472
|
+
else if (isValidFilePath(pipelineString)) {
|
|
473
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
474
|
+
}
|
|
475
|
+
else if (isValidEmail(pipelineString)) {
|
|
476
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
477
|
+
}
|
|
376
478
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
377
479
|
return pipelineString;
|
|
378
480
|
}
|
|
@@ -660,7 +762,7 @@ var NAME = "Promptbook";
|
|
|
660
762
|
*
|
|
661
763
|
* @public exported from `@promptbook/core`
|
|
662
764
|
*/
|
|
663
|
-
var ADMIN_EMAIL = '
|
|
765
|
+
var ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
664
766
|
/**
|
|
665
767
|
* Name of the responsible person for the Promptbook on GitHub
|
|
666
768
|
*
|
|
@@ -1061,7 +1163,7 @@ var ORDER_OF_PIPELINE_JSON = [
|
|
|
1061
1163
|
*
|
|
1062
1164
|
* @private within the repository
|
|
1063
1165
|
*/
|
|
1064
|
-
var REPLACING_NONCE = '
|
|
1166
|
+
var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
1065
1167
|
/**
|
|
1066
1168
|
* @@@
|
|
1067
1169
|
*
|
|
@@ -1207,35 +1309,6 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
1207
1309
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1208
1310
|
}
|
|
1209
1311
|
|
|
1210
|
-
/**
|
|
1211
|
-
* Tests if given string is valid URL.
|
|
1212
|
-
*
|
|
1213
|
-
* Note: Dataurl are considered perfectly valid.
|
|
1214
|
-
* Note: There are two simmilar functions:
|
|
1215
|
-
* - `isValidUrl` which tests any URL
|
|
1216
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1217
|
-
*
|
|
1218
|
-
* @public exported from `@promptbook/utils`
|
|
1219
|
-
*/
|
|
1220
|
-
function isValidUrl(url) {
|
|
1221
|
-
if (typeof url !== 'string') {
|
|
1222
|
-
return false;
|
|
1223
|
-
}
|
|
1224
|
-
try {
|
|
1225
|
-
if (url.startsWith('blob:')) {
|
|
1226
|
-
url = url.replace(/^blob:/, '');
|
|
1227
|
-
}
|
|
1228
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
1229
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1230
|
-
return false;
|
|
1231
|
-
}
|
|
1232
|
-
return true;
|
|
1233
|
-
}
|
|
1234
|
-
catch (error) {
|
|
1235
|
-
return false;
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1312
|
/**
|
|
1240
1313
|
* Tests if given string is valid pipeline URL URL.
|
|
1241
1314
|
*
|
|
@@ -1904,7 +1977,7 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
1904
1977
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1905
1978
|
__extends(NotYetImplementedError, _super);
|
|
1906
1979
|
function NotYetImplementedError(message) {
|
|
1907
|
-
var _this = _super.call(this, spaceTrim$1(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
|
|
1980
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
1908
1981
|
_this.name = 'NotYetImplementedError';
|
|
1909
1982
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1910
1983
|
return _this;
|
|
@@ -1990,12 +2063,28 @@ function deserializeError(error) {
|
|
|
1990
2063
|
/**
|
|
1991
2064
|
* Asserts that the execution of a Promptbook is successful
|
|
1992
2065
|
*
|
|
2066
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2067
|
+
*
|
|
1993
2068
|
* @param executionResult - The partial result of the Promptbook execution
|
|
1994
2069
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1995
2070
|
* @public exported from `@promptbook/core`
|
|
1996
2071
|
*/
|
|
1997
2072
|
function assertsExecutionSuccessful(executionResult) {
|
|
1998
|
-
var
|
|
2073
|
+
var e_1, _a;
|
|
2074
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2075
|
+
try {
|
|
2076
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2077
|
+
var warning = warnings_1_1.value;
|
|
2078
|
+
console.warn(warning.message);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2082
|
+
finally {
|
|
2083
|
+
try {
|
|
2084
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2085
|
+
}
|
|
2086
|
+
finally { if (e_1) throw e_1.error; }
|
|
2087
|
+
}
|
|
1999
2088
|
if (isSuccessful === true) {
|
|
2000
2089
|
return;
|
|
2001
2090
|
}
|
|
@@ -3500,55 +3589,6 @@ function isFileExisting(filename, fs) {
|
|
|
3500
3589
|
* TODO: [🖇] What about symlinks?
|
|
3501
3590
|
*/
|
|
3502
3591
|
|
|
3503
|
-
/**
|
|
3504
|
-
* Tests if given string is valid URL.
|
|
3505
|
-
*
|
|
3506
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
3507
|
-
* @public exported from `@promptbook/utils`
|
|
3508
|
-
*/
|
|
3509
|
-
function isValidFilePath(filename) {
|
|
3510
|
-
if (typeof filename !== 'string') {
|
|
3511
|
-
return false;
|
|
3512
|
-
}
|
|
3513
|
-
if (filename.split('\n').length > 1) {
|
|
3514
|
-
return false;
|
|
3515
|
-
}
|
|
3516
|
-
if (filename.split(' ').length >
|
|
3517
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
3518
|
-
return false;
|
|
3519
|
-
}
|
|
3520
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
3521
|
-
// Absolute Unix path: /hello.txt
|
|
3522
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
3523
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
3524
|
-
return true;
|
|
3525
|
-
}
|
|
3526
|
-
// Absolute Windows path: /hello.txt
|
|
3527
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
3528
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
3529
|
-
return true;
|
|
3530
|
-
}
|
|
3531
|
-
// Relative path: ./hello.txt
|
|
3532
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
3533
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
3534
|
-
return true;
|
|
3535
|
-
}
|
|
3536
|
-
// Allow paths like foo/hello
|
|
3537
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
3538
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
3539
|
-
return true;
|
|
3540
|
-
}
|
|
3541
|
-
// Allow paths like hello.book
|
|
3542
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
3543
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
3544
|
-
return true;
|
|
3545
|
-
}
|
|
3546
|
-
return false;
|
|
3547
|
-
}
|
|
3548
|
-
/**
|
|
3549
|
-
* TODO: [🍏] Implement for MacOs
|
|
3550
|
-
*/
|
|
3551
|
-
|
|
3552
3592
|
/**
|
|
3553
3593
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3554
3594
|
*
|