@promptbook/pdf 0.84.0-10 โ 0.84.0-12
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 +99 -64
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +9 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- 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/esm/typings/src/wizzard/wizzard.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +103 -68
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -6,6 +6,7 @@ import { basename, join, dirname } from 'path';
|
|
|
6
6
|
import { format } from 'prettier';
|
|
7
7
|
import parserHtml from 'prettier/parser-html';
|
|
8
8
|
import { forTime } from 'waitasecond';
|
|
9
|
+
import sha256 from 'crypto-js/sha256';
|
|
9
10
|
import { lookup } from 'mime-types';
|
|
10
11
|
import { unparse, parse } from 'papaparse';
|
|
11
12
|
|
|
@@ -23,7 +24,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
23
24
|
* @generated
|
|
24
25
|
* @see https://github.com/webgptorg/promptbook
|
|
25
26
|
*/
|
|
26
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
27
28
|
/**
|
|
28
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
30
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -227,6 +228,12 @@ var SMALL_NUMBER = 0.001;
|
|
|
227
228
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
228
229
|
*/
|
|
229
230
|
var IMMEDIATE_TIME = 10;
|
|
231
|
+
/**
|
|
232
|
+
* The maximum length of the (generated) filename
|
|
233
|
+
*
|
|
234
|
+
* @public exported from `@promptbook/core`
|
|
235
|
+
*/
|
|
236
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
230
237
|
/**
|
|
231
238
|
* Strategy for caching the intermediate results for knowledge sources
|
|
232
239
|
*
|
|
@@ -246,6 +253,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
|
246
253
|
* @public exported from `@promptbook/core`
|
|
247
254
|
*/
|
|
248
255
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
256
|
+
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
257
|
+
/**
|
|
258
|
+
* Where to store the temporary downloads
|
|
259
|
+
*
|
|
260
|
+
* Note: When the folder does not exist, it is created recursively
|
|
261
|
+
*
|
|
262
|
+
* @public exported from `@promptbook/core`
|
|
263
|
+
*/
|
|
264
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
249
265
|
/**
|
|
250
266
|
* Where to store the scrape cache
|
|
251
267
|
*
|
|
@@ -940,24 +956,18 @@ function getScraperIntermediateSource(source, options) {
|
|
|
940
956
|
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"}];
|
|
941
957
|
|
|
942
958
|
/**
|
|
943
|
-
*
|
|
959
|
+
* Checks if value is valid email
|
|
944
960
|
*
|
|
945
961
|
* @public exported from `@promptbook/utils`
|
|
946
962
|
*/
|
|
947
|
-
function
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
return true;
|
|
963
|
+
function isValidEmail(email) {
|
|
964
|
+
if (typeof email !== 'string') {
|
|
965
|
+
return false;
|
|
951
966
|
}
|
|
952
|
-
|
|
953
|
-
if (!(error instanceof Error)) {
|
|
954
|
-
throw error;
|
|
955
|
-
}
|
|
956
|
-
if (error.message.includes('Unexpected token')) {
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
967
|
+
if (email.split('\n').length > 1) {
|
|
959
968
|
return false;
|
|
960
969
|
}
|
|
970
|
+
return /^.+@.+\..+$/.test(email);
|
|
961
971
|
}
|
|
962
972
|
|
|
963
973
|
/**
|
|
@@ -979,6 +989,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
979
989
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
980
990
|
*/
|
|
981
991
|
|
|
992
|
+
/**
|
|
993
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
994
|
+
*
|
|
995
|
+
* @public exported from `@promptbook/utils`
|
|
996
|
+
*/
|
|
997
|
+
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
998
|
+
try {
|
|
999
|
+
JSON.parse(value);
|
|
1000
|
+
return true;
|
|
1001
|
+
}
|
|
1002
|
+
catch (error) {
|
|
1003
|
+
if (!(error instanceof Error)) {
|
|
1004
|
+
throw error;
|
|
1005
|
+
}
|
|
1006
|
+
if (error.message.includes('Unexpected token')) {
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
982
1013
|
/**
|
|
983
1014
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
984
1015
|
* 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.
|
|
@@ -992,6 +1023,15 @@ function validatePipelineString(pipelineString) {
|
|
|
992
1023
|
if (isValidJsonString(pipelineString)) {
|
|
993
1024
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
994
1025
|
}
|
|
1026
|
+
else if (isValidUrl(pipelineString)) {
|
|
1027
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1028
|
+
}
|
|
1029
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1030
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1031
|
+
}
|
|
1032
|
+
else if (isValidEmail(pipelineString)) {
|
|
1033
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1034
|
+
}
|
|
995
1035
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
996
1036
|
return pipelineString;
|
|
997
1037
|
}
|
|
@@ -2373,12 +2413,28 @@ function deserializeError(error) {
|
|
|
2373
2413
|
/**
|
|
2374
2414
|
* Asserts that the execution of a Promptbook is successful
|
|
2375
2415
|
*
|
|
2416
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2417
|
+
*
|
|
2376
2418
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2377
2419
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2378
2420
|
* @public exported from `@promptbook/core`
|
|
2379
2421
|
*/
|
|
2380
2422
|
function assertsExecutionSuccessful(executionResult) {
|
|
2381
|
-
var
|
|
2423
|
+
var e_1, _a;
|
|
2424
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2425
|
+
try {
|
|
2426
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2427
|
+
var warning = warnings_1_1.value;
|
|
2428
|
+
console.warn(warning.message);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2432
|
+
finally {
|
|
2433
|
+
try {
|
|
2434
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2435
|
+
}
|
|
2436
|
+
finally { if (e_1) throw e_1.error; }
|
|
2437
|
+
}
|
|
2382
2438
|
if (isSuccessful === true) {
|
|
2383
2439
|
return;
|
|
2384
2440
|
}
|
|
@@ -3559,10 +3615,11 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3559
3615
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3560
3616
|
var _a;
|
|
3561
3617
|
return __awaiter(this, void 0, void 0, function () {
|
|
3562
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3563
|
-
return __generator(this, function (
|
|
3564
|
-
switch (
|
|
3618
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response, mimeType, filename, hash, rootDirname_1, filepath, _f, _g, _h, _j, _k, filename_1, fileExtension, mimeType;
|
|
3619
|
+
return __generator(this, function (_l) {
|
|
3620
|
+
switch (_l.label) {
|
|
3565
3621
|
case 0:
|
|
3622
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3566
3623
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3567
3624
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
3568
3625
|
name = knowledgeSource.name;
|
|
@@ -3570,54 +3627,32 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3570
3627
|
if (!name) {
|
|
3571
3628
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3572
3629
|
}
|
|
3573
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3630
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3574
3631
|
url = knowledgeSourceContent;
|
|
3575
3632
|
return [4 /*yield*/, fetch(url)];
|
|
3576
3633
|
case 1:
|
|
3577
|
-
|
|
3578
|
-
mimeType = ((_a =
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
/*
|
|
3585
|
-
TODO: [๐ฅฝ]
|
|
3586
|
-
> async asBlob() {
|
|
3587
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
3588
|
-
> const content = await response.blob();
|
|
3589
|
-
> return content;
|
|
3590
|
-
> },
|
|
3591
|
-
*/
|
|
3592
|
-
asJson: function () {
|
|
3593
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3594
|
-
var content;
|
|
3595
|
-
return __generator(this, function (_a) {
|
|
3596
|
-
switch (_a.label) {
|
|
3597
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
3598
|
-
case 1:
|
|
3599
|
-
content = _a.sent();
|
|
3600
|
-
return [2 /*return*/, content];
|
|
3601
|
-
}
|
|
3602
|
-
});
|
|
3603
|
-
});
|
|
3604
|
-
},
|
|
3605
|
-
asText: function () {
|
|
3606
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3607
|
-
var content;
|
|
3608
|
-
return __generator(this, function (_a) {
|
|
3609
|
-
switch (_a.label) {
|
|
3610
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
3611
|
-
case 1:
|
|
3612
|
-
content = _a.sent();
|
|
3613
|
-
return [2 /*return*/, content];
|
|
3614
|
-
}
|
|
3615
|
-
});
|
|
3616
|
-
});
|
|
3617
|
-
},
|
|
3618
|
-
}];
|
|
3634
|
+
response = _l.sent();
|
|
3635
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3636
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
3637
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3638
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3639
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), ["".concat(filename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
|
|
3640
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3619
3641
|
case 2:
|
|
3620
|
-
|
|
3642
|
+
_l.sent();
|
|
3643
|
+
_g = (_f = tools.fs).writeFile;
|
|
3644
|
+
_h = [join(rootDirname_1, filepath)];
|
|
3645
|
+
_k = (_j = Buffer).from;
|
|
3646
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
3647
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3648
|
+
case 4:
|
|
3649
|
+
_l.sent();
|
|
3650
|
+
// TODO: !!!!!!!! Check the file security
|
|
3651
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
3652
|
+
// TODO: !!!!!!!! Delete the file
|
|
3653
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3654
|
+
case 5:
|
|
3655
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3621
3656
|
if (tools.fs === undefined) {
|
|
3622
3657
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3623
3658
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -3630,8 +3665,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3630
3665
|
fileExtension = getFileExtension(filename_1);
|
|
3631
3666
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3632
3667
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3633
|
-
case
|
|
3634
|
-
if (!(
|
|
3668
|
+
case 6:
|
|
3669
|
+
if (!(_l.sent())) {
|
|
3635
3670
|
throw new NotFoundError(spaceTrim(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 "); }));
|
|
3636
3671
|
}
|
|
3637
3672
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3677,7 +3712,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3677
3712
|
});
|
|
3678
3713
|
},
|
|
3679
3714
|
}];
|
|
3680
|
-
case
|
|
3715
|
+
case 7: return [2 /*return*/, {
|
|
3681
3716
|
source: name,
|
|
3682
3717
|
filename: null,
|
|
3683
3718
|
url: null,
|