@promptbook/markdown-utils 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 +120 -80
- 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 +1 -1
- package/umd/index.umd.js +120 -80
- package/umd/index.umd.js.map +1 -1
|
@@ -8,6 +8,7 @@ import { serializeError } from '../errors/utils/serializeError';
|
|
|
8
8
|
import { forEachAsync } from '../execution/utils/forEachAsync';
|
|
9
9
|
import { isValidJsonString } from '../formats/json/utils/isValidJsonString';
|
|
10
10
|
import { prompt } from '../pipeline/prompt-notation';
|
|
11
|
+
import { promptTemplate } from '../pipeline/prompt-notation';
|
|
11
12
|
import { $getCurrentDate } from '../utils/$getCurrentDate';
|
|
12
13
|
import { $isRunningInBrowser } from '../utils/environment/$isRunningInBrowser';
|
|
13
14
|
import { $isRunningInJest } from '../utils/environment/$isRunningInJest';
|
|
@@ -89,6 +90,7 @@ export { serializeError };
|
|
|
89
90
|
export { forEachAsync };
|
|
90
91
|
export { isValidJsonString };
|
|
91
92
|
export { prompt };
|
|
93
|
+
export { promptTemplate };
|
|
92
94
|
export { $getCurrentDate };
|
|
93
95
|
export { $isRunningInBrowser };
|
|
94
96
|
export { $isRunningInJest };
|
|
@@ -2,11 +2,13 @@ import type { PipelineExecutorResult } from './PipelineExecutorResult';
|
|
|
2
2
|
/**
|
|
3
3
|
* Asserts that the execution of a Promptbook is successful
|
|
4
4
|
*
|
|
5
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
6
|
+
*
|
|
5
7
|
* @param executionResult - The partial result of the Promptbook execution
|
|
6
8
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
7
9
|
* @public exported from `@promptbook/core`
|
|
8
10
|
*/
|
|
9
|
-
export declare function assertsExecutionSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors'>): void;
|
|
11
|
+
export declare function assertsExecutionSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors' | 'warnings'>): void;
|
|
10
12
|
/**
|
|
11
13
|
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
12
14
|
* TODO: [🧠] Can this return type be better typed than void
|
|
@@ -2,9 +2,10 @@ import type { PipelineString } from './PipelineString';
|
|
|
2
2
|
/**
|
|
3
3
|
* Tag function for notating a pipeline with a book\`...\ notation as template literal
|
|
4
4
|
*
|
|
5
|
-
* Note: There are
|
|
5
|
+
* Note: There are 3 similar functions:
|
|
6
6
|
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
7
|
-
*
|
|
7
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
8
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
8
9
|
*
|
|
9
10
|
* @param strings @@@
|
|
10
11
|
* @param values @@@
|
|
@@ -2,16 +2,29 @@ import type { string_prompt } from '../types/typeAliases';
|
|
|
2
2
|
/**
|
|
3
3
|
* Tag function for notating a prompt as template literal
|
|
4
4
|
*
|
|
5
|
-
* Note: There are
|
|
5
|
+
* Note: There are 3 similar functions:
|
|
6
6
|
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
7
|
-
*
|
|
7
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
8
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
8
9
|
*
|
|
9
|
-
* @param strings
|
|
10
|
-
* @param values
|
|
11
|
-
* @returns the
|
|
10
|
+
* @param strings
|
|
11
|
+
* @param values
|
|
12
|
+
* @returns the prompt string
|
|
12
13
|
* @public exported from `@promptbook/utils`
|
|
13
14
|
*/
|
|
14
15
|
export declare function prompt(strings: TemplateStringsArray, ...values: Array<string>): string_prompt;
|
|
16
|
+
/**
|
|
17
|
+
* Tag function for notating a prompt as template literal
|
|
18
|
+
*
|
|
19
|
+
* Note: There are 3 similar functions:
|
|
20
|
+
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
21
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
22
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
23
|
+
*
|
|
24
|
+
* @alias prompt
|
|
25
|
+
* @public exported from `@promptbook/utils`
|
|
26
|
+
*/
|
|
27
|
+
export declare const promptTemplate: typeof prompt;
|
|
15
28
|
/**
|
|
16
29
|
* TODO: [🧠][🈴] Where is the best location for this file
|
|
17
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
package/package.json
CHANGED
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.84.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
|
}
|
|
@@ -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
|
*
|
|
@@ -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
|
|
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
|
*
|