@promptbook/remote-server 0.84.0-20 → 0.84.0-9
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 +5 -11
- package/esm/index.es.js +123 -268
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +0 -4
- package/esm/typings/src/_packages/core.index.d.ts +2 -12
- package/esm/typings/src/_packages/types.index.d.ts +0 -2
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +0 -4
- package/esm/typings/src/config.d.ts +1 -27
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
- package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
- package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
- package/package.json +16 -9
- package/umd/index.umd.js +123 -268
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten -->
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# ❄ Promptbook
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## ❄ New Features
|
|
18
18
|
|
|
19
|
-
- 💫 Support of [`o3-mini` model by OpenAI](https://openai.com/index/openai-o3-mini/)
|
|
20
|
-
- 🐋 **Support of [DeepSeek models](https://www.npmjs.com/package/@promptbook/deepseek)**
|
|
21
19
|
- 💙 Working [the **Book** language v1.0.0](https://github.com/webgptorg/book)
|
|
22
20
|
- 🖤 Run books from CLI - `npx ptbk run path/to/your/book`
|
|
23
|
-
- 📚 Support of `.docx`, `.doc` and `.pdf` documents
|
|
21
|
+
- 📚 Support of `.docx`, `.doc` and `.pdf` documents
|
|
22
|
+
- ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
|
|
@@ -264,9 +263,8 @@ Or you can install them separately:
|
|
|
264
263
|
- **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
|
|
265
264
|
- **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
|
|
266
265
|
- **[@promptbook/google](https://www.npmjs.com/package/@promptbook/google)** - Integration with Google's Gemini API
|
|
267
|
-
- **[@promptbook/deepseek](https://www.npmjs.com/package/@promptbook/deepseek)** - Integration with [DeepSeek API](https://www.deepseek.com/)
|
|
268
266
|
- **[@promptbook/azure-openai](https://www.npmjs.com/package/@promptbook/azure-openai)** - Execution tools for Azure OpenAI API
|
|
269
|
-
|
|
267
|
+
- **[@promptbook/langtail](https://www.npmjs.com/package/@promptbook/langtail)** - Execution tools for Langtail API, wrapper around Langtail SDK
|
|
270
268
|
- **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
|
|
271
269
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
272
270
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
@@ -436,10 +434,6 @@ See [TODO.md](./TODO.md)
|
|
|
436
434
|
|
|
437
435
|
|
|
438
436
|
|
|
439
|
-
## 🤝 Partners
|
|
440
|
-
|
|
441
|
-
[](https://technologickainkubace.org/en/about-technology-incubation/about-the-project/)
|
|
442
|
-
|
|
443
437
|
## 🖋️ Contributing
|
|
444
438
|
|
|
445
439
|
I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can [☕ buy me a coffee](https://www.buymeacoffee.com/hejny) or [donate via cryptocurrencies](https://github.com/hejny/hejny/blob/main/documents/crypto.md).
|
package/esm/index.es.js
CHANGED
|
@@ -4,15 +4,14 @@ import { Server } from 'socket.io';
|
|
|
4
4
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
5
5
|
import { spawn } from 'child_process';
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
|
-
import { stat, access, constants, readFile, writeFile, readdir
|
|
8
|
-
import { join
|
|
7
|
+
import { stat, access, constants, readFile, writeFile, readdir } from 'fs/promises';
|
|
8
|
+
import { join } from 'path';
|
|
9
9
|
import { format } from 'prettier';
|
|
10
10
|
import parserHtml from 'prettier/parser-html';
|
|
11
11
|
import { unparse, parse } from 'papaparse';
|
|
12
|
-
import hexEncoder from 'crypto-js/enc-hex';
|
|
13
|
-
import sha256 from 'crypto-js/sha256';
|
|
14
12
|
import { SHA256 } from 'crypto-js';
|
|
15
|
-
import
|
|
13
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
14
|
+
import { lookup } from 'mime-types';
|
|
16
15
|
|
|
17
16
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
18
17
|
/**
|
|
@@ -28,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
27
|
* @generated
|
|
29
28
|
* @see https://github.com/webgptorg/promptbook
|
|
30
29
|
*/
|
|
31
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
|
|
32
31
|
/**
|
|
33
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -199,12 +198,6 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
199
198
|
* @public exported from `@promptbook/core`
|
|
200
199
|
*/
|
|
201
200
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
202
|
-
/**
|
|
203
|
-
* Maximum file size limit
|
|
204
|
-
*
|
|
205
|
-
* @public exported from `@promptbook/core`
|
|
206
|
-
*/
|
|
207
|
-
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
208
201
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
209
202
|
/**
|
|
210
203
|
* The maximum number of iterations for a loops
|
|
@@ -238,12 +231,6 @@ var SMALL_NUMBER = 0.001;
|
|
|
238
231
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
239
232
|
*/
|
|
240
233
|
var IMMEDIATE_TIME = 10;
|
|
241
|
-
/**
|
|
242
|
-
* The maximum length of the (generated) filename
|
|
243
|
-
*
|
|
244
|
-
* @public exported from `@promptbook/core`
|
|
245
|
-
*/
|
|
246
|
-
var MAX_FILENAME_LENGTH = 30;
|
|
247
234
|
/**
|
|
248
235
|
* Strategy for caching the intermediate results for knowledge sources
|
|
249
236
|
*
|
|
@@ -263,15 +250,6 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
263
250
|
* @public exported from `@promptbook/core`
|
|
264
251
|
*/
|
|
265
252
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
266
|
-
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
267
|
-
/**
|
|
268
|
-
* Where to store the temporary downloads
|
|
269
|
-
*
|
|
270
|
-
* Note: When the folder does not exist, it is created recursively
|
|
271
|
-
*
|
|
272
|
-
* @public exported from `@promptbook/core`
|
|
273
|
-
*/
|
|
274
|
-
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
275
253
|
/**
|
|
276
254
|
* Where to store the scrape cache
|
|
277
255
|
*
|
|
@@ -880,7 +858,6 @@ function $provideFilesystemForNode(options) {
|
|
|
880
858
|
readFile: readFile,
|
|
881
859
|
writeFile: writeFile,
|
|
882
860
|
readdir: readdir,
|
|
883
|
-
mkdir: mkdir,
|
|
884
861
|
};
|
|
885
862
|
}
|
|
886
863
|
/**
|
|
@@ -1780,99 +1757,6 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
1780
1757
|
|
|
1781
1758
|
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"}];
|
|
1782
1759
|
|
|
1783
|
-
/**
|
|
1784
|
-
* Checks if value is valid email
|
|
1785
|
-
*
|
|
1786
|
-
* @public exported from `@promptbook/utils`
|
|
1787
|
-
*/
|
|
1788
|
-
function isValidEmail(email) {
|
|
1789
|
-
if (typeof email !== 'string') {
|
|
1790
|
-
return false;
|
|
1791
|
-
}
|
|
1792
|
-
if (email.split('\n').length > 1) {
|
|
1793
|
-
return false;
|
|
1794
|
-
}
|
|
1795
|
-
return /^.+@.+\..+$/.test(email);
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
/**
|
|
1799
|
-
* Tests if given string is valid URL.
|
|
1800
|
-
*
|
|
1801
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
1802
|
-
* @public exported from `@promptbook/utils`
|
|
1803
|
-
*/
|
|
1804
|
-
function isValidFilePath(filename) {
|
|
1805
|
-
if (typeof filename !== 'string') {
|
|
1806
|
-
return false;
|
|
1807
|
-
}
|
|
1808
|
-
if (filename.split('\n').length > 1) {
|
|
1809
|
-
return false;
|
|
1810
|
-
}
|
|
1811
|
-
if (filename.split(' ').length >
|
|
1812
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
1813
|
-
return false;
|
|
1814
|
-
}
|
|
1815
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
1816
|
-
// Absolute Unix path: /hello.txt
|
|
1817
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1818
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
1819
|
-
return true;
|
|
1820
|
-
}
|
|
1821
|
-
// Absolute Windows path: /hello.txt
|
|
1822
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1823
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
1824
|
-
return true;
|
|
1825
|
-
}
|
|
1826
|
-
// Relative path: ./hello.txt
|
|
1827
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1828
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
1829
|
-
return true;
|
|
1830
|
-
}
|
|
1831
|
-
// Allow paths like foo/hello
|
|
1832
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
1833
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
1834
|
-
return true;
|
|
1835
|
-
}
|
|
1836
|
-
// Allow paths like hello.book
|
|
1837
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
1838
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
1839
|
-
return true;
|
|
1840
|
-
}
|
|
1841
|
-
return false;
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* TODO: [🍏] Implement for MacOs
|
|
1845
|
-
*/
|
|
1846
|
-
|
|
1847
|
-
/**
|
|
1848
|
-
* Tests if given string is valid URL.
|
|
1849
|
-
*
|
|
1850
|
-
* Note: Dataurl are considered perfectly valid.
|
|
1851
|
-
* Note: There are two simmilar functions:
|
|
1852
|
-
* - `isValidUrl` which tests any URL
|
|
1853
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1854
|
-
*
|
|
1855
|
-
* @public exported from `@promptbook/utils`
|
|
1856
|
-
*/
|
|
1857
|
-
function isValidUrl(url) {
|
|
1858
|
-
if (typeof url !== 'string') {
|
|
1859
|
-
return false;
|
|
1860
|
-
}
|
|
1861
|
-
try {
|
|
1862
|
-
if (url.startsWith('blob:')) {
|
|
1863
|
-
url = url.replace(/^blob:/, '');
|
|
1864
|
-
}
|
|
1865
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
1866
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1867
|
-
return false;
|
|
1868
|
-
}
|
|
1869
|
-
return true;
|
|
1870
|
-
}
|
|
1871
|
-
catch (error) {
|
|
1872
|
-
return false;
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
1760
|
/**
|
|
1877
1761
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1878
1762
|
*
|
|
@@ -1907,15 +1791,6 @@ function validatePipelineString(pipelineString) {
|
|
|
1907
1791
|
if (isValidJsonString(pipelineString)) {
|
|
1908
1792
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1909
1793
|
}
|
|
1910
|
-
else if (isValidUrl(pipelineString)) {
|
|
1911
|
-
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1912
|
-
}
|
|
1913
|
-
else if (isValidFilePath(pipelineString)) {
|
|
1914
|
-
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1915
|
-
}
|
|
1916
|
-
else if (isValidEmail(pipelineString)) {
|
|
1917
|
-
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1918
|
-
}
|
|
1919
1794
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1920
1795
|
return pipelineString;
|
|
1921
1796
|
}
|
|
@@ -2559,6 +2434,35 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
2559
2434
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
2560
2435
|
}
|
|
2561
2436
|
|
|
2437
|
+
/**
|
|
2438
|
+
* Tests if given string is valid URL.
|
|
2439
|
+
*
|
|
2440
|
+
* Note: Dataurl are considered perfectly valid.
|
|
2441
|
+
* Note: There are two simmilar functions:
|
|
2442
|
+
* - `isValidUrl` which tests any URL
|
|
2443
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
2444
|
+
*
|
|
2445
|
+
* @public exported from `@promptbook/utils`
|
|
2446
|
+
*/
|
|
2447
|
+
function isValidUrl(url) {
|
|
2448
|
+
if (typeof url !== 'string') {
|
|
2449
|
+
return false;
|
|
2450
|
+
}
|
|
2451
|
+
try {
|
|
2452
|
+
if (url.startsWith('blob:')) {
|
|
2453
|
+
url = url.replace(/^blob:/, '');
|
|
2454
|
+
}
|
|
2455
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
2456
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
2457
|
+
return false;
|
|
2458
|
+
}
|
|
2459
|
+
return true;
|
|
2460
|
+
}
|
|
2461
|
+
catch (error) {
|
|
2462
|
+
return false;
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2562
2466
|
/**
|
|
2563
2467
|
* Tests if given string is valid pipeline URL URL.
|
|
2564
2468
|
*
|
|
@@ -3058,28 +2962,12 @@ function deserializeError(error) {
|
|
|
3058
2962
|
/**
|
|
3059
2963
|
* Asserts that the execution of a Promptbook is successful
|
|
3060
2964
|
*
|
|
3061
|
-
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
3062
|
-
*
|
|
3063
2965
|
* @param executionResult - The partial result of the Promptbook execution
|
|
3064
2966
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
3065
2967
|
* @public exported from `@promptbook/core`
|
|
3066
2968
|
*/
|
|
3067
2969
|
function assertsExecutionSuccessful(executionResult) {
|
|
3068
|
-
var
|
|
3069
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
3070
|
-
try {
|
|
3071
|
-
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
3072
|
-
var warning = warnings_1_1.value;
|
|
3073
|
-
console.warn(warning.message);
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3077
|
-
finally {
|
|
3078
|
-
try {
|
|
3079
|
-
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
3080
|
-
}
|
|
3081
|
-
finally { if (e_1) throw e_1.error; }
|
|
3082
|
-
}
|
|
2970
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
3083
2971
|
if (isSuccessful === true) {
|
|
3084
2972
|
return;
|
|
3085
2973
|
}
|
|
@@ -6088,15 +5976,6 @@ function knowledgeSourceContentToName(knowledgeSourceContent) {
|
|
|
6088
5976
|
* TODO: [🐱🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
|
|
6089
5977
|
*/
|
|
6090
5978
|
|
|
6091
|
-
/**
|
|
6092
|
-
* @@@
|
|
6093
|
-
*
|
|
6094
|
-
* @private for `FileCacheStorage`
|
|
6095
|
-
*/
|
|
6096
|
-
function nameToSubfolderPath(name) {
|
|
6097
|
-
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
6098
|
-
}
|
|
6099
|
-
|
|
6100
5979
|
/**
|
|
6101
5980
|
* Convert file extension to mime type
|
|
6102
5981
|
*
|
|
@@ -6153,55 +6032,53 @@ function isFileExisting(filename, fs) {
|
|
|
6153
6032
|
*/
|
|
6154
6033
|
|
|
6155
6034
|
/**
|
|
6156
|
-
*
|
|
6157
|
-
*
|
|
6158
|
-
* Note: If the mime type is invalid, `null` is returned
|
|
6159
|
-
*
|
|
6160
|
-
* @private within the repository
|
|
6161
|
-
*/
|
|
6162
|
-
function mimeTypeToExtension(value) {
|
|
6163
|
-
return extension(value) || null;
|
|
6164
|
-
}
|
|
6165
|
-
|
|
6166
|
-
/**
|
|
6167
|
-
* Removes emojis from a string and fix whitespaces
|
|
6168
|
-
*
|
|
6169
|
-
* @param text with emojis
|
|
6170
|
-
* @returns text without emojis
|
|
6171
|
-
* @public exported from `@promptbook/utils`
|
|
6172
|
-
*/
|
|
6173
|
-
function removeEmojis(text) {
|
|
6174
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
6175
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
6176
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
6177
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
6178
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
6179
|
-
return text;
|
|
6180
|
-
}
|
|
6181
|
-
|
|
6182
|
-
/**
|
|
6183
|
-
* @@@
|
|
6035
|
+
* Tests if given string is valid URL.
|
|
6184
6036
|
*
|
|
6185
|
-
*
|
|
6186
|
-
* @returns @@@
|
|
6187
|
-
* @example @@@
|
|
6037
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
6188
6038
|
* @public exported from `@promptbook/utils`
|
|
6189
6039
|
*/
|
|
6190
|
-
function
|
|
6191
|
-
if (
|
|
6192
|
-
|
|
6193
|
-
value = value.replace(/\.html$/, '');
|
|
6040
|
+
function isValidFilePath(filename) {
|
|
6041
|
+
if (typeof filename !== 'string') {
|
|
6042
|
+
return false;
|
|
6194
6043
|
}
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
// Note: Keeping extension in the name
|
|
6044
|
+
if (filename.split('\n').length > 1) {
|
|
6045
|
+
return false;
|
|
6198
6046
|
}
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6047
|
+
if (filename.split(' ').length >
|
|
6048
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
6049
|
+
return false;
|
|
6050
|
+
}
|
|
6051
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
6052
|
+
// Absolute Unix path: /hello.txt
|
|
6053
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
6054
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
6055
|
+
return true;
|
|
6056
|
+
}
|
|
6057
|
+
// Absolute Windows path: /hello.txt
|
|
6058
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
6059
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
6060
|
+
return true;
|
|
6061
|
+
}
|
|
6062
|
+
// Relative path: ./hello.txt
|
|
6063
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
6064
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
6065
|
+
return true;
|
|
6066
|
+
}
|
|
6067
|
+
// Allow paths like foo/hello
|
|
6068
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
6069
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
6070
|
+
return true;
|
|
6071
|
+
}
|
|
6072
|
+
// Allow paths like hello.book
|
|
6073
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
6074
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
6075
|
+
return true;
|
|
6076
|
+
}
|
|
6077
|
+
return false;
|
|
6204
6078
|
}
|
|
6079
|
+
/**
|
|
6080
|
+
* TODO: [🍏] Implement for MacOs
|
|
6081
|
+
*/
|
|
6205
6082
|
|
|
6206
6083
|
/**
|
|
6207
6084
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -6238,9 +6115,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
6238
6115
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
6239
6116
|
var _a;
|
|
6240
6117
|
return __awaiter(this, void 0, void 0, function () {
|
|
6241
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType,
|
|
6242
|
-
return __generator(this, function (
|
|
6243
|
-
switch (
|
|
6118
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
6119
|
+
return __generator(this, function (_f) {
|
|
6120
|
+
switch (_f.label) {
|
|
6244
6121
|
case 0:
|
|
6245
6122
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
6246
6123
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -6249,76 +6126,54 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6249
6126
|
if (!name) {
|
|
6250
6127
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
6251
6128
|
}
|
|
6252
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
6129
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
|
|
6253
6130
|
url = knowledgeSourceContent;
|
|
6254
6131
|
return [4 /*yield*/, fetch(url)];
|
|
6255
6132
|
case 1:
|
|
6256
|
-
response_1 =
|
|
6133
|
+
response_1 = _f.sent();
|
|
6257
6134
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
}
|
|
6282
|
-
});
|
|
6135
|
+
return [2 /*return*/, {
|
|
6136
|
+
source: name,
|
|
6137
|
+
filename: null,
|
|
6138
|
+
url: url,
|
|
6139
|
+
mimeType: mimeType,
|
|
6140
|
+
/*
|
|
6141
|
+
TODO: [🥽]
|
|
6142
|
+
> async asBlob() {
|
|
6143
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
6144
|
+
> const content = await response.blob();
|
|
6145
|
+
> return content;
|
|
6146
|
+
> },
|
|
6147
|
+
*/
|
|
6148
|
+
asJson: function () {
|
|
6149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6150
|
+
var content;
|
|
6151
|
+
return __generator(this, function (_a) {
|
|
6152
|
+
switch (_a.label) {
|
|
6153
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
6154
|
+
case 1:
|
|
6155
|
+
content = _a.sent();
|
|
6156
|
+
return [2 /*return*/, content];
|
|
6157
|
+
}
|
|
6283
6158
|
});
|
|
6284
|
-
}
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
}
|
|
6159
|
+
});
|
|
6160
|
+
},
|
|
6161
|
+
asText: function () {
|
|
6162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6163
|
+
var content;
|
|
6164
|
+
return __generator(this, function (_a) {
|
|
6165
|
+
switch (_a.label) {
|
|
6166
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
6167
|
+
case 1:
|
|
6168
|
+
content = _a.sent();
|
|
6169
|
+
return [2 /*return*/, content];
|
|
6170
|
+
}
|
|
6296
6171
|
});
|
|
6297
|
-
}
|
|
6298
|
-
}
|
|
6299
|
-
|
|
6300
|
-
basename = url.split('/').pop() || titleToName(url);
|
|
6301
|
-
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
6302
|
-
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6303
|
-
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
|
|
6304
|
-
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
6172
|
+
});
|
|
6173
|
+
},
|
|
6174
|
+
}];
|
|
6305
6175
|
case 2:
|
|
6306
|
-
|
|
6307
|
-
_g = (_f = Buffer).from;
|
|
6308
|
-
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
6309
|
-
case 3:
|
|
6310
|
-
fileContent = _g.apply(_f, [_h.sent()]);
|
|
6311
|
-
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
6312
|
-
throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
|
|
6313
|
-
}
|
|
6314
|
-
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
6315
|
-
case 4:
|
|
6316
|
-
_h.sent();
|
|
6317
|
-
// TODO: [💵] Check the file security
|
|
6318
|
-
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
6319
|
-
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6320
|
-
case 5:
|
|
6321
|
-
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
6176
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
|
|
6322
6177
|
if (tools.fs === undefined) {
|
|
6323
6178
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
6324
6179
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -6331,8 +6186,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6331
6186
|
fileExtension = getFileExtension(filename_1);
|
|
6332
6187
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
6333
6188
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6334
|
-
case
|
|
6335
|
-
if (!(
|
|
6189
|
+
case 3:
|
|
6190
|
+
if (!(_f.sent())) {
|
|
6336
6191
|
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
6337
6192
|
}
|
|
6338
6193
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -6378,7 +6233,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6378
6233
|
});
|
|
6379
6234
|
},
|
|
6380
6235
|
}];
|
|
6381
|
-
case
|
|
6236
|
+
case 4: return [2 /*return*/, {
|
|
6382
6237
|
source: name,
|
|
6383
6238
|
filename: null,
|
|
6384
6239
|
url: null,
|