@promptbook/documents 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
|
@@ -8,6 +8,7 @@ import hexEncoder from 'crypto-js/enc-hex';
|
|
|
8
8
|
import { basename, join, dirname } from 'path';
|
|
9
9
|
import { format } from 'prettier';
|
|
10
10
|
import parserHtml from 'prettier/parser-html';
|
|
11
|
+
import sha256 from 'crypto-js/sha256';
|
|
11
12
|
import { lookup } from 'mime-types';
|
|
12
13
|
import { unparse, parse } from 'papaparse';
|
|
13
14
|
|
|
@@ -25,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
26
|
* @generated
|
|
26
27
|
* @see https://github.com/webgptorg/promptbook
|
|
27
28
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
29
30
|
/**
|
|
30
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
32
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -229,6 +230,12 @@ var SMALL_NUMBER = 0.001;
|
|
|
229
230
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
230
231
|
*/
|
|
231
232
|
var IMMEDIATE_TIME = 10;
|
|
233
|
+
/**
|
|
234
|
+
* The maximum length of the (generated) filename
|
|
235
|
+
*
|
|
236
|
+
* @public exported from `@promptbook/core`
|
|
237
|
+
*/
|
|
238
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
232
239
|
/**
|
|
233
240
|
* Strategy for caching the intermediate results for knowledge sources
|
|
234
241
|
*
|
|
@@ -248,6 +255,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
|
248
255
|
* @public exported from `@promptbook/core`
|
|
249
256
|
*/
|
|
250
257
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
258
|
+
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
259
|
+
/**
|
|
260
|
+
* Where to store the temporary downloads
|
|
261
|
+
*
|
|
262
|
+
* Note: When the folder does not exist, it is created recursively
|
|
263
|
+
*
|
|
264
|
+
* @public exported from `@promptbook/core`
|
|
265
|
+
*/
|
|
266
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
251
267
|
/**
|
|
252
268
|
* Where to store the scrape cache
|
|
253
269
|
*
|
|
@@ -1117,24 +1133,18 @@ function getScraperIntermediateSource(source, options) {
|
|
|
1117
1133
|
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"}];
|
|
1118
1134
|
|
|
1119
1135
|
/**
|
|
1120
|
-
*
|
|
1136
|
+
* Checks if value is valid email
|
|
1121
1137
|
*
|
|
1122
1138
|
* @public exported from `@promptbook/utils`
|
|
1123
1139
|
*/
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
return true;
|
|
1140
|
+
function isValidEmail(email) {
|
|
1141
|
+
if (typeof email !== 'string') {
|
|
1142
|
+
return false;
|
|
1128
1143
|
}
|
|
1129
|
-
|
|
1130
|
-
if (!(error instanceof Error)) {
|
|
1131
|
-
throw error;
|
|
1132
|
-
}
|
|
1133
|
-
if (error.message.includes('Unexpected token')) {
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1144
|
+
if (email.split('\n').length > 1) {
|
|
1136
1145
|
return false;
|
|
1137
1146
|
}
|
|
1147
|
+
return /^.+@.+\..+$/.test(email);
|
|
1138
1148
|
}
|
|
1139
1149
|
|
|
1140
1150
|
/**
|
|
@@ -1156,6 +1166,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
1156
1166
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1157
1167
|
*/
|
|
1158
1168
|
|
|
1169
|
+
/**
|
|
1170
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1171
|
+
*
|
|
1172
|
+
* @public exported from `@promptbook/utils`
|
|
1173
|
+
*/
|
|
1174
|
+
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
1175
|
+
try {
|
|
1176
|
+
JSON.parse(value);
|
|
1177
|
+
return true;
|
|
1178
|
+
}
|
|
1179
|
+
catch (error) {
|
|
1180
|
+
if (!(error instanceof Error)) {
|
|
1181
|
+
throw error;
|
|
1182
|
+
}
|
|
1183
|
+
if (error.message.includes('Unexpected token')) {
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1159
1190
|
/**
|
|
1160
1191
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1161
1192
|
* 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.
|
|
@@ -1169,6 +1200,15 @@ function validatePipelineString(pipelineString) {
|
|
|
1169
1200
|
if (isValidJsonString(pipelineString)) {
|
|
1170
1201
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1171
1202
|
}
|
|
1203
|
+
else if (isValidUrl(pipelineString)) {
|
|
1204
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1205
|
+
}
|
|
1206
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1207
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1208
|
+
}
|
|
1209
|
+
else if (isValidEmail(pipelineString)) {
|
|
1210
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1211
|
+
}
|
|
1172
1212
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1173
1213
|
return pipelineString;
|
|
1174
1214
|
}
|
|
@@ -2534,12 +2574,28 @@ function deserializeError(error) {
|
|
|
2534
2574
|
/**
|
|
2535
2575
|
* Asserts that the execution of a Promptbook is successful
|
|
2536
2576
|
*
|
|
2577
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2578
|
+
*
|
|
2537
2579
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2538
2580
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2539
2581
|
* @public exported from `@promptbook/core`
|
|
2540
2582
|
*/
|
|
2541
2583
|
function assertsExecutionSuccessful(executionResult) {
|
|
2542
|
-
var
|
|
2584
|
+
var e_1, _a;
|
|
2585
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2586
|
+
try {
|
|
2587
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2588
|
+
var warning = warnings_1_1.value;
|
|
2589
|
+
console.warn(warning.message);
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2593
|
+
finally {
|
|
2594
|
+
try {
|
|
2595
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2596
|
+
}
|
|
2597
|
+
finally { if (e_1) throw e_1.error; }
|
|
2598
|
+
}
|
|
2543
2599
|
if (isSuccessful === true) {
|
|
2544
2600
|
return;
|
|
2545
2601
|
}
|
|
@@ -3710,10 +3766,11 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3710
3766
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3711
3767
|
var _a;
|
|
3712
3768
|
return __awaiter(this, void 0, void 0, function () {
|
|
3713
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3714
|
-
return __generator(this, function (
|
|
3715
|
-
switch (
|
|
3769
|
+
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;
|
|
3770
|
+
return __generator(this, function (_l) {
|
|
3771
|
+
switch (_l.label) {
|
|
3716
3772
|
case 0:
|
|
3773
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3717
3774
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3718
3775
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
3719
3776
|
name = knowledgeSource.name;
|
|
@@ -3721,54 +3778,32 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3721
3778
|
if (!name) {
|
|
3722
3779
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3723
3780
|
}
|
|
3724
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3781
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3725
3782
|
url = knowledgeSourceContent;
|
|
3726
3783
|
return [4 /*yield*/, fetch(url)];
|
|
3727
3784
|
case 1:
|
|
3728
|
-
|
|
3729
|
-
mimeType = ((_a =
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
/*
|
|
3736
|
-
TODO: [๐ฅฝ]
|
|
3737
|
-
> async asBlob() {
|
|
3738
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
3739
|
-
> const content = await response.blob();
|
|
3740
|
-
> return content;
|
|
3741
|
-
> },
|
|
3742
|
-
*/
|
|
3743
|
-
asJson: function () {
|
|
3744
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3745
|
-
var content;
|
|
3746
|
-
return __generator(this, function (_a) {
|
|
3747
|
-
switch (_a.label) {
|
|
3748
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
3749
|
-
case 1:
|
|
3750
|
-
content = _a.sent();
|
|
3751
|
-
return [2 /*return*/, content];
|
|
3752
|
-
}
|
|
3753
|
-
});
|
|
3754
|
-
});
|
|
3755
|
-
},
|
|
3756
|
-
asText: function () {
|
|
3757
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3758
|
-
var content;
|
|
3759
|
-
return __generator(this, function (_a) {
|
|
3760
|
-
switch (_a.label) {
|
|
3761
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
3762
|
-
case 1:
|
|
3763
|
-
content = _a.sent();
|
|
3764
|
-
return [2 /*return*/, content];
|
|
3765
|
-
}
|
|
3766
|
-
});
|
|
3767
|
-
});
|
|
3768
|
-
},
|
|
3769
|
-
}];
|
|
3785
|
+
response = _l.sent();
|
|
3786
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3787
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
3788
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3789
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3790
|
+
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));
|
|
3791
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3770
3792
|
case 2:
|
|
3771
|
-
|
|
3793
|
+
_l.sent();
|
|
3794
|
+
_g = (_f = tools.fs).writeFile;
|
|
3795
|
+
_h = [join(rootDirname_1, filepath)];
|
|
3796
|
+
_k = (_j = Buffer).from;
|
|
3797
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
3798
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3799
|
+
case 4:
|
|
3800
|
+
_l.sent();
|
|
3801
|
+
// TODO: !!!!!!!! Check the file security
|
|
3802
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
3803
|
+
// TODO: !!!!!!!! Delete the file
|
|
3804
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3805
|
+
case 5:
|
|
3806
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3772
3807
|
if (tools.fs === undefined) {
|
|
3773
3808
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3774
3809
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -3781,8 +3816,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3781
3816
|
fileExtension = getFileExtension(filename_1);
|
|
3782
3817
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3783
3818
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3784
|
-
case
|
|
3785
|
-
if (!(
|
|
3819
|
+
case 6:
|
|
3820
|
+
if (!(_l.sent())) {
|
|
3786
3821
|
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 "); }));
|
|
3787
3822
|
}
|
|
3788
3823
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3828,7 +3863,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3828
3863
|
});
|
|
3829
3864
|
},
|
|
3830
3865
|
}];
|
|
3831
|
-
case
|
|
3866
|
+
case 7: return [2 /*return*/, {
|
|
3832
3867
|
source: name,
|
|
3833
3868
|
filename: null,
|
|
3834
3869
|
url: null,
|