@promptbook/website-crawler 0.84.0-21 → 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 -21
- package/esm/index.es.js +64 -162
- 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/cli/cli-commands/about.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -3
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -3
- 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 +67 -165
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +0 -13
- 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,20 +434,6 @@ See [TODO.md](./TODO.md)
|
|
|
436
434
|
|
|
437
435
|
|
|
438
436
|
|
|
439
|
-
## 🤝 Partners
|
|
440
|
-
|
|
441
|
-
<div style="display: flex; align-items: center; gap: 20px;">
|
|
442
|
-
|
|
443
|
-
<a href="https://promptbook.studio/">
|
|
444
|
-
<img src="./other/design/promptbook-studio-logo.png" alt="Partner 3" height="100">
|
|
445
|
-
</a>
|
|
446
|
-
|
|
447
|
-
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
448
|
-
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
|
|
449
|
-
</a>
|
|
450
|
-
|
|
451
|
-
</div>
|
|
452
|
-
|
|
453
437
|
## 🖋️ Contributing
|
|
454
438
|
|
|
455
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
|
@@ -8,8 +8,7 @@ import { basename, join, dirname } from 'path';
|
|
|
8
8
|
import { format } from 'prettier';
|
|
9
9
|
import parserHtml from 'prettier/parser-html';
|
|
10
10
|
import { forTime } from 'waitasecond';
|
|
11
|
-
import
|
|
12
|
-
import { lookup, extension } from 'mime-types';
|
|
11
|
+
import { lookup } from 'mime-types';
|
|
13
12
|
import { unparse, parse } from 'papaparse';
|
|
14
13
|
import { Converter } from 'showdown';
|
|
15
14
|
|
|
@@ -27,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
26
|
* @generated
|
|
28
27
|
* @see https://github.com/webgptorg/promptbook
|
|
29
28
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
|
|
31
30
|
/**
|
|
32
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -236,12 +235,6 @@ var ADMIN_GITHUB_NAME = 'hejny';
|
|
|
236
235
|
* @public exported from `@promptbook/core`
|
|
237
236
|
*/
|
|
238
237
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
239
|
-
/**
|
|
240
|
-
* Maximum file size limit
|
|
241
|
-
*
|
|
242
|
-
* @public exported from `@promptbook/core`
|
|
243
|
-
*/
|
|
244
|
-
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
245
238
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
246
239
|
/**
|
|
247
240
|
* The maximum number of iterations for a loops
|
|
@@ -275,12 +268,6 @@ var SMALL_NUMBER = 0.001;
|
|
|
275
268
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
276
269
|
*/
|
|
277
270
|
var IMMEDIATE_TIME = 10;
|
|
278
|
-
/**
|
|
279
|
-
* The maximum length of the (generated) filename
|
|
280
|
-
*
|
|
281
|
-
* @public exported from `@promptbook/core`
|
|
282
|
-
*/
|
|
283
|
-
var MAX_FILENAME_LENGTH = 30;
|
|
284
271
|
/**
|
|
285
272
|
* Strategy for caching the intermediate results for knowledge sources
|
|
286
273
|
*
|
|
@@ -300,15 +287,6 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
300
287
|
* @public exported from `@promptbook/core`
|
|
301
288
|
*/
|
|
302
289
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
303
|
-
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
304
|
-
/**
|
|
305
|
-
* Where to store the temporary downloads
|
|
306
|
-
*
|
|
307
|
-
* Note: When the folder does not exist, it is created recursively
|
|
308
|
-
*
|
|
309
|
-
* @public exported from `@promptbook/core`
|
|
310
|
-
*/
|
|
311
|
-
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
312
290
|
/**
|
|
313
291
|
* Where to store the scrape cache
|
|
314
292
|
*
|
|
@@ -1141,18 +1119,24 @@ function getScraperIntermediateSource(source, options) {
|
|
|
1141
1119
|
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"}];
|
|
1142
1120
|
|
|
1143
1121
|
/**
|
|
1144
|
-
*
|
|
1122
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1145
1123
|
*
|
|
1146
1124
|
* @public exported from `@promptbook/utils`
|
|
1147
1125
|
*/
|
|
1148
|
-
function
|
|
1149
|
-
|
|
1150
|
-
|
|
1126
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1127
|
+
try {
|
|
1128
|
+
JSON.parse(value);
|
|
1129
|
+
return true;
|
|
1151
1130
|
}
|
|
1152
|
-
|
|
1131
|
+
catch (error) {
|
|
1132
|
+
if (!(error instanceof Error)) {
|
|
1133
|
+
throw error;
|
|
1134
|
+
}
|
|
1135
|
+
if (error.message.includes('Unexpected token')) {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1153
1138
|
return false;
|
|
1154
1139
|
}
|
|
1155
|
-
return /^.+@.+\..+$/.test(email);
|
|
1156
1140
|
}
|
|
1157
1141
|
|
|
1158
1142
|
/**
|
|
@@ -1174,27 +1158,6 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
1174
1158
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1175
1159
|
*/
|
|
1176
1160
|
|
|
1177
|
-
/**
|
|
1178
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1179
|
-
*
|
|
1180
|
-
* @public exported from `@promptbook/utils`
|
|
1181
|
-
*/
|
|
1182
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1183
|
-
try {
|
|
1184
|
-
JSON.parse(value);
|
|
1185
|
-
return true;
|
|
1186
|
-
}
|
|
1187
|
-
catch (error) {
|
|
1188
|
-
if (!(error instanceof Error)) {
|
|
1189
|
-
throw error;
|
|
1190
|
-
}
|
|
1191
|
-
if (error.message.includes('Unexpected token')) {
|
|
1192
|
-
return false;
|
|
1193
|
-
}
|
|
1194
|
-
return false;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
1161
|
/**
|
|
1199
1162
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1200
1163
|
* 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.
|
|
@@ -1208,15 +1171,6 @@ function validatePipelineString(pipelineString) {
|
|
|
1208
1171
|
if (isValidJsonString(pipelineString)) {
|
|
1209
1172
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1210
1173
|
}
|
|
1211
|
-
else if (isValidUrl(pipelineString)) {
|
|
1212
|
-
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1213
|
-
}
|
|
1214
|
-
else if (isValidFilePath(pipelineString)) {
|
|
1215
|
-
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1216
|
-
}
|
|
1217
|
-
else if (isValidEmail(pipelineString)) {
|
|
1218
|
-
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1219
|
-
}
|
|
1220
1174
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1221
1175
|
return pipelineString;
|
|
1222
1176
|
}
|
|
@@ -2544,28 +2498,12 @@ function deserializeError(error) {
|
|
|
2544
2498
|
/**
|
|
2545
2499
|
* Asserts that the execution of a Promptbook is successful
|
|
2546
2500
|
*
|
|
2547
|
-
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2548
|
-
*
|
|
2549
2501
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2550
2502
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2551
2503
|
* @public exported from `@promptbook/core`
|
|
2552
2504
|
*/
|
|
2553
2505
|
function assertsExecutionSuccessful(executionResult) {
|
|
2554
|
-
var
|
|
2555
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2556
|
-
try {
|
|
2557
|
-
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2558
|
-
var warning = warnings_1_1.value;
|
|
2559
|
-
console.warn(warning.message);
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2563
|
-
finally {
|
|
2564
|
-
try {
|
|
2565
|
-
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2566
|
-
}
|
|
2567
|
-
finally { if (e_1) throw e_1.error; }
|
|
2568
|
-
}
|
|
2506
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
2569
2507
|
if (isSuccessful === true) {
|
|
2570
2508
|
return;
|
|
2571
2509
|
}
|
|
@@ -3202,7 +3140,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3202
3140
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3203
3141
|
throw error_1;
|
|
3204
3142
|
}
|
|
3205
|
-
errors.push(
|
|
3143
|
+
errors.push(error_1);
|
|
3206
3144
|
return [3 /*break*/, 13];
|
|
3207
3145
|
case 13:
|
|
3208
3146
|
_b = _a.next();
|
|
@@ -3229,10 +3167,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3229
3167
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3230
3168
|
// 3) ...
|
|
3231
3169
|
spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3232
|
-
.map(function (
|
|
3233
|
-
var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
|
|
3234
|
-
return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
|
|
3235
|
-
})
|
|
3170
|
+
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
3236
3171
|
.join('\n')), "\n\n "); }));
|
|
3237
3172
|
}
|
|
3238
3173
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3599,17 +3534,6 @@ function isFileExisting(filename, fs) {
|
|
|
3599
3534
|
* TODO: [🖇] What about symlinks?
|
|
3600
3535
|
*/
|
|
3601
3536
|
|
|
3602
|
-
/**
|
|
3603
|
-
* Convert mime type to file extension
|
|
3604
|
-
*
|
|
3605
|
-
* Note: If the mime type is invalid, `null` is returned
|
|
3606
|
-
*
|
|
3607
|
-
* @private within the repository
|
|
3608
|
-
*/
|
|
3609
|
-
function mimeTypeToExtension(value) {
|
|
3610
|
-
return extension(value) || null;
|
|
3611
|
-
}
|
|
3612
|
-
|
|
3613
3537
|
/**
|
|
3614
3538
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3615
3539
|
*
|
|
@@ -3645,9 +3569,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3645
3569
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3646
3570
|
var _a;
|
|
3647
3571
|
return __awaiter(this, void 0, void 0, function () {
|
|
3648
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType,
|
|
3649
|
-
return __generator(this, function (
|
|
3650
|
-
switch (
|
|
3572
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3573
|
+
return __generator(this, function (_f) {
|
|
3574
|
+
switch (_f.label) {
|
|
3651
3575
|
case 0:
|
|
3652
3576
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3653
3577
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3656,76 +3580,54 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3656
3580
|
if (!name) {
|
|
3657
3581
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3658
3582
|
}
|
|
3659
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3583
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
|
|
3660
3584
|
url = knowledgeSourceContent;
|
|
3661
3585
|
return [4 /*yield*/, fetch(url)];
|
|
3662
3586
|
case 1:
|
|
3663
|
-
response_1 =
|
|
3587
|
+
response_1 = _f.sent();
|
|
3664
3588
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
}
|
|
3689
|
-
});
|
|
3589
|
+
return [2 /*return*/, {
|
|
3590
|
+
source: name,
|
|
3591
|
+
filename: null,
|
|
3592
|
+
url: url,
|
|
3593
|
+
mimeType: mimeType,
|
|
3594
|
+
/*
|
|
3595
|
+
TODO: [🥽]
|
|
3596
|
+
> async asBlob() {
|
|
3597
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3598
|
+
> const content = await response.blob();
|
|
3599
|
+
> return content;
|
|
3600
|
+
> },
|
|
3601
|
+
*/
|
|
3602
|
+
asJson: function () {
|
|
3603
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3604
|
+
var content;
|
|
3605
|
+
return __generator(this, function (_a) {
|
|
3606
|
+
switch (_a.label) {
|
|
3607
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3608
|
+
case 1:
|
|
3609
|
+
content = _a.sent();
|
|
3610
|
+
return [2 /*return*/, content];
|
|
3611
|
+
}
|
|
3690
3612
|
});
|
|
3691
|
-
}
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
}
|
|
3613
|
+
});
|
|
3614
|
+
},
|
|
3615
|
+
asText: function () {
|
|
3616
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3617
|
+
var content;
|
|
3618
|
+
return __generator(this, function (_a) {
|
|
3619
|
+
switch (_a.label) {
|
|
3620
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3621
|
+
case 1:
|
|
3622
|
+
content = _a.sent();
|
|
3623
|
+
return [2 /*return*/, content];
|
|
3624
|
+
}
|
|
3703
3625
|
});
|
|
3704
|
-
}
|
|
3705
|
-
}
|
|
3706
|
-
|
|
3707
|
-
basename = url.split('/').pop() || titleToName(url);
|
|
3708
|
-
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3709
|
-
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3710
|
-
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));
|
|
3711
|
-
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3626
|
+
});
|
|
3627
|
+
},
|
|
3628
|
+
}];
|
|
3712
3629
|
case 2:
|
|
3713
|
-
|
|
3714
|
-
_g = (_f = Buffer).from;
|
|
3715
|
-
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3716
|
-
case 3:
|
|
3717
|
-
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3718
|
-
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3719
|
-
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."));
|
|
3720
|
-
}
|
|
3721
|
-
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
3722
|
-
case 4:
|
|
3723
|
-
_h.sent();
|
|
3724
|
-
// TODO: [💵] Check the file security
|
|
3725
|
-
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3726
|
-
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3727
|
-
case 5:
|
|
3728
|
-
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3630
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
|
|
3729
3631
|
if (tools.fs === undefined) {
|
|
3730
3632
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3731
3633
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3738,8 +3640,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3738
3640
|
fileExtension = getFileExtension(filename_1);
|
|
3739
3641
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3740
3642
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3741
|
-
case
|
|
3742
|
-
if (!(
|
|
3643
|
+
case 3:
|
|
3644
|
+
if (!(_f.sent())) {
|
|
3743
3645
|
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 "); }));
|
|
3744
3646
|
}
|
|
3745
3647
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3785,7 +3687,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3785
3687
|
});
|
|
3786
3688
|
},
|
|
3787
3689
|
}];
|
|
3788
|
-
case
|
|
3690
|
+
case 4: return [2 /*return*/, {
|
|
3789
3691
|
source: name,
|
|
3790
3692
|
filename: null,
|
|
3791
3693
|
url: null,
|