@promptbook/pdf 0.84.0-11 โ 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 +46 -51
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/config.d.ts +9 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/wizzard/wizzard.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +50 -55
- 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
|
*
|
|
@@ -3599,10 +3615,11 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3599
3615
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3600
3616
|
var _a;
|
|
3601
3617
|
return __awaiter(this, void 0, void 0, function () {
|
|
3602
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3603
|
-
return __generator(this, function (
|
|
3604
|
-
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) {
|
|
3605
3621
|
case 0:
|
|
3622
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3606
3623
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3607
3624
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
3608
3625
|
name = knowledgeSource.name;
|
|
@@ -3610,54 +3627,32 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3610
3627
|
if (!name) {
|
|
3611
3628
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3612
3629
|
}
|
|
3613
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3630
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3614
3631
|
url = knowledgeSourceContent;
|
|
3615
3632
|
return [4 /*yield*/, fetch(url)];
|
|
3616
3633
|
case 1:
|
|
3617
|
-
|
|
3618
|
-
mimeType = ((_a =
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
/*
|
|
3625
|
-
TODO: [๐ฅฝ]
|
|
3626
|
-
> async asBlob() {
|
|
3627
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
3628
|
-
> const content = await response.blob();
|
|
3629
|
-
> return content;
|
|
3630
|
-
> },
|
|
3631
|
-
*/
|
|
3632
|
-
asJson: function () {
|
|
3633
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3634
|
-
var content;
|
|
3635
|
-
return __generator(this, function (_a) {
|
|
3636
|
-
switch (_a.label) {
|
|
3637
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
3638
|
-
case 1:
|
|
3639
|
-
content = _a.sent();
|
|
3640
|
-
return [2 /*return*/, content];
|
|
3641
|
-
}
|
|
3642
|
-
});
|
|
3643
|
-
});
|
|
3644
|
-
},
|
|
3645
|
-
asText: function () {
|
|
3646
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3647
|
-
var content;
|
|
3648
|
-
return __generator(this, function (_a) {
|
|
3649
|
-
switch (_a.label) {
|
|
3650
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
3651
|
-
case 1:
|
|
3652
|
-
content = _a.sent();
|
|
3653
|
-
return [2 /*return*/, content];
|
|
3654
|
-
}
|
|
3655
|
-
});
|
|
3656
|
-
});
|
|
3657
|
-
},
|
|
3658
|
-
}];
|
|
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 })];
|
|
3659
3641
|
case 2:
|
|
3660
|
-
|
|
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];
|
|
3661
3656
|
if (tools.fs === undefined) {
|
|
3662
3657
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3663
3658
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -3670,8 +3665,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3670
3665
|
fileExtension = getFileExtension(filename_1);
|
|
3671
3666
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3672
3667
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3673
|
-
case
|
|
3674
|
-
if (!(
|
|
3668
|
+
case 6:
|
|
3669
|
+
if (!(_l.sent())) {
|
|
3675
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 "); }));
|
|
3676
3671
|
}
|
|
3677
3672
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3717,7 +3712,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3717
3712
|
});
|
|
3718
3713
|
},
|
|
3719
3714
|
}];
|
|
3720
|
-
case
|
|
3715
|
+
case 7: return [2 /*return*/, {
|
|
3721
3716
|
source: name,
|
|
3722
3717
|
filename: null,
|
|
3723
3718
|
url: null,
|