@promptbook/remote-server 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 +2 -2
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-server",
|
|
3
|
-
"version": "0.84.0-
|
|
3
|
+
"version": "0.84.0-11",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [🐊]",
|
|
6
6
|
"private": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
55
55
|
"typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.84.0-
|
|
57
|
+
"@promptbook/core": "0.84.0-11"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1756,6 +1756,99 @@
|
|
|
1756
1756
|
|
|
1757
1757
|
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
1758
1758
|
|
|
1759
|
+
/**
|
|
1760
|
+
* Checks if value is valid email
|
|
1761
|
+
*
|
|
1762
|
+
* @public exported from `@promptbook/utils`
|
|
1763
|
+
*/
|
|
1764
|
+
function isValidEmail(email) {
|
|
1765
|
+
if (typeof email !== 'string') {
|
|
1766
|
+
return false;
|
|
1767
|
+
}
|
|
1768
|
+
if (email.split('\n').length > 1) {
|
|
1769
|
+
return false;
|
|
1770
|
+
}
|
|
1771
|
+
return /^.+@.+\..+$/.test(email);
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
/**
|
|
1775
|
+
* Tests if given string is valid URL.
|
|
1776
|
+
*
|
|
1777
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
1778
|
+
* @public exported from `@promptbook/utils`
|
|
1779
|
+
*/
|
|
1780
|
+
function isValidFilePath(filename) {
|
|
1781
|
+
if (typeof filename !== 'string') {
|
|
1782
|
+
return false;
|
|
1783
|
+
}
|
|
1784
|
+
if (filename.split('\n').length > 1) {
|
|
1785
|
+
return false;
|
|
1786
|
+
}
|
|
1787
|
+
if (filename.split(' ').length >
|
|
1788
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
1789
|
+
return false;
|
|
1790
|
+
}
|
|
1791
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
1792
|
+
// Absolute Unix path: /hello.txt
|
|
1793
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1794
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
1795
|
+
return true;
|
|
1796
|
+
}
|
|
1797
|
+
// Absolute Windows path: /hello.txt
|
|
1798
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1799
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
1800
|
+
return true;
|
|
1801
|
+
}
|
|
1802
|
+
// Relative path: ./hello.txt
|
|
1803
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1804
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
1805
|
+
return true;
|
|
1806
|
+
}
|
|
1807
|
+
// Allow paths like foo/hello
|
|
1808
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
1809
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
1810
|
+
return true;
|
|
1811
|
+
}
|
|
1812
|
+
// Allow paths like hello.book
|
|
1813
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
1814
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
1815
|
+
return true;
|
|
1816
|
+
}
|
|
1817
|
+
return false;
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* TODO: [🍏] Implement for MacOs
|
|
1821
|
+
*/
|
|
1822
|
+
|
|
1823
|
+
/**
|
|
1824
|
+
* Tests if given string is valid URL.
|
|
1825
|
+
*
|
|
1826
|
+
* Note: Dataurl are considered perfectly valid.
|
|
1827
|
+
* Note: There are two simmilar functions:
|
|
1828
|
+
* - `isValidUrl` which tests any URL
|
|
1829
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1830
|
+
*
|
|
1831
|
+
* @public exported from `@promptbook/utils`
|
|
1832
|
+
*/
|
|
1833
|
+
function isValidUrl(url) {
|
|
1834
|
+
if (typeof url !== 'string') {
|
|
1835
|
+
return false;
|
|
1836
|
+
}
|
|
1837
|
+
try {
|
|
1838
|
+
if (url.startsWith('blob:')) {
|
|
1839
|
+
url = url.replace(/^blob:/, '');
|
|
1840
|
+
}
|
|
1841
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
1842
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
return true;
|
|
1846
|
+
}
|
|
1847
|
+
catch (error) {
|
|
1848
|
+
return false;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1759
1852
|
/**
|
|
1760
1853
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1761
1854
|
*
|
|
@@ -1790,6 +1883,15 @@
|
|
|
1790
1883
|
if (isValidJsonString(pipelineString)) {
|
|
1791
1884
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1792
1885
|
}
|
|
1886
|
+
else if (isValidUrl(pipelineString)) {
|
|
1887
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1888
|
+
}
|
|
1889
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1890
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1891
|
+
}
|
|
1892
|
+
else if (isValidEmail(pipelineString)) {
|
|
1893
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1894
|
+
}
|
|
1793
1895
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1794
1896
|
return pipelineString;
|
|
1795
1897
|
}
|
|
@@ -2433,35 +2535,6 @@
|
|
|
2433
2535
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
2434
2536
|
}
|
|
2435
2537
|
|
|
2436
|
-
/**
|
|
2437
|
-
* Tests if given string is valid URL.
|
|
2438
|
-
*
|
|
2439
|
-
* Note: Dataurl are considered perfectly valid.
|
|
2440
|
-
* Note: There are two simmilar functions:
|
|
2441
|
-
* - `isValidUrl` which tests any URL
|
|
2442
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
2443
|
-
*
|
|
2444
|
-
* @public exported from `@promptbook/utils`
|
|
2445
|
-
*/
|
|
2446
|
-
function isValidUrl(url) {
|
|
2447
|
-
if (typeof url !== 'string') {
|
|
2448
|
-
return false;
|
|
2449
|
-
}
|
|
2450
|
-
try {
|
|
2451
|
-
if (url.startsWith('blob:')) {
|
|
2452
|
-
url = url.replace(/^blob:/, '');
|
|
2453
|
-
}
|
|
2454
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
2455
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
2456
|
-
return false;
|
|
2457
|
-
}
|
|
2458
|
-
return true;
|
|
2459
|
-
}
|
|
2460
|
-
catch (error) {
|
|
2461
|
-
return false;
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
2538
|
/**
|
|
2466
2539
|
* Tests if given string is valid pipeline URL URL.
|
|
2467
2540
|
*
|
|
@@ -2961,12 +3034,28 @@
|
|
|
2961
3034
|
/**
|
|
2962
3035
|
* Asserts that the execution of a Promptbook is successful
|
|
2963
3036
|
*
|
|
3037
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
3038
|
+
*
|
|
2964
3039
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2965
3040
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2966
3041
|
* @public exported from `@promptbook/core`
|
|
2967
3042
|
*/
|
|
2968
3043
|
function assertsExecutionSuccessful(executionResult) {
|
|
2969
|
-
var
|
|
3044
|
+
var e_1, _a;
|
|
3045
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
3046
|
+
try {
|
|
3047
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
3048
|
+
var warning = warnings_1_1.value;
|
|
3049
|
+
console.warn(warning.message);
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3053
|
+
finally {
|
|
3054
|
+
try {
|
|
3055
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
3056
|
+
}
|
|
3057
|
+
finally { if (e_1) throw e_1.error; }
|
|
3058
|
+
}
|
|
2970
3059
|
if (isSuccessful === true) {
|
|
2971
3060
|
return;
|
|
2972
3061
|
}
|
|
@@ -6030,55 +6119,6 @@
|
|
|
6030
6119
|
* TODO: [🖇] What about symlinks?
|
|
6031
6120
|
*/
|
|
6032
6121
|
|
|
6033
|
-
/**
|
|
6034
|
-
* Tests if given string is valid URL.
|
|
6035
|
-
*
|
|
6036
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
6037
|
-
* @public exported from `@promptbook/utils`
|
|
6038
|
-
*/
|
|
6039
|
-
function isValidFilePath(filename) {
|
|
6040
|
-
if (typeof filename !== 'string') {
|
|
6041
|
-
return false;
|
|
6042
|
-
}
|
|
6043
|
-
if (filename.split('\n').length > 1) {
|
|
6044
|
-
return false;
|
|
6045
|
-
}
|
|
6046
|
-
if (filename.split(' ').length >
|
|
6047
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
6048
|
-
return false;
|
|
6049
|
-
}
|
|
6050
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
6051
|
-
// Absolute Unix path: /hello.txt
|
|
6052
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
6053
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
6054
|
-
return true;
|
|
6055
|
-
}
|
|
6056
|
-
// Absolute Windows path: /hello.txt
|
|
6057
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
6058
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
6059
|
-
return true;
|
|
6060
|
-
}
|
|
6061
|
-
// Relative path: ./hello.txt
|
|
6062
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
6063
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
6064
|
-
return true;
|
|
6065
|
-
}
|
|
6066
|
-
// Allow paths like foo/hello
|
|
6067
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
6068
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
6069
|
-
return true;
|
|
6070
|
-
}
|
|
6071
|
-
// Allow paths like hello.book
|
|
6072
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
6073
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
6074
|
-
return true;
|
|
6075
|
-
}
|
|
6076
|
-
return false;
|
|
6077
|
-
}
|
|
6078
|
-
/**
|
|
6079
|
-
* TODO: [🍏] Implement for MacOs
|
|
6080
|
-
*/
|
|
6081
|
-
|
|
6082
6122
|
/**
|
|
6083
6123
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
6084
6124
|
*
|