@promptbook/documents 0.84.0-12 → 0.84.0-13
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 +49 -7
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +49 -7
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-12';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3766,7 +3766,7 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3766
3766
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3767
3767
|
var _a;
|
|
3768
3768
|
return __awaiter(this, void 0, void 0, function () {
|
|
3769
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3769
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, _f, _g, _h, _j, _k, filename_1, fileExtension, mimeType;
|
|
3770
3770
|
return __generator(this, function (_l) {
|
|
3771
3771
|
switch (_l.label) {
|
|
3772
3772
|
case 0:
|
|
@@ -3782,19 +3782,61 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3782
3782
|
url = knowledgeSourceContent;
|
|
3783
3783
|
return [4 /*yield*/, fetch(url)];
|
|
3784
3784
|
case 1:
|
|
3785
|
-
|
|
3786
|
-
mimeType = ((_a =
|
|
3787
|
-
|
|
3785
|
+
response_1 = _l.sent();
|
|
3786
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3787
|
+
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
3788
|
+
return [2 /*return*/, {
|
|
3789
|
+
source: name,
|
|
3790
|
+
filename: null,
|
|
3791
|
+
url: url,
|
|
3792
|
+
mimeType: mimeType,
|
|
3793
|
+
/*
|
|
3794
|
+
TODO: [🥽]
|
|
3795
|
+
> async asBlob() {
|
|
3796
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3797
|
+
> const content = await response.blob();
|
|
3798
|
+
> return content;
|
|
3799
|
+
> },
|
|
3800
|
+
*/
|
|
3801
|
+
asJson: function () {
|
|
3802
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3803
|
+
var content;
|
|
3804
|
+
return __generator(this, function (_a) {
|
|
3805
|
+
switch (_a.label) {
|
|
3806
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3807
|
+
case 1:
|
|
3808
|
+
content = _a.sent();
|
|
3809
|
+
return [2 /*return*/, content];
|
|
3810
|
+
}
|
|
3811
|
+
});
|
|
3812
|
+
});
|
|
3813
|
+
},
|
|
3814
|
+
asText: function () {
|
|
3815
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3816
|
+
var content;
|
|
3817
|
+
return __generator(this, function (_a) {
|
|
3818
|
+
switch (_a.label) {
|
|
3819
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3820
|
+
case 1:
|
|
3821
|
+
content = _a.sent();
|
|
3822
|
+
return [2 /*return*/, content];
|
|
3823
|
+
}
|
|
3824
|
+
});
|
|
3825
|
+
});
|
|
3826
|
+
},
|
|
3827
|
+
}];
|
|
3828
|
+
}
|
|
3829
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3788
3830
|
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3789
3831
|
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(
|
|
3832
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
|
|
3791
3833
|
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3792
3834
|
case 2:
|
|
3793
3835
|
_l.sent();
|
|
3794
3836
|
_g = (_f = tools.fs).writeFile;
|
|
3795
3837
|
_h = [join(rootDirname_1, filepath)];
|
|
3796
3838
|
_k = (_j = Buffer).from;
|
|
3797
|
-
return [4 /*yield*/,
|
|
3839
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3798
3840
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3799
3841
|
case 4:
|
|
3800
3842
|
_l.sent();
|