@promptbook/node 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 +89 -47
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +89 -47
- package/umd/index.umd.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.84.0-
|
|
3
|
+
"version": "0.84.0-13",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [🐊]",
|
|
6
6
|
"private": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
55
55
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.84.0-
|
|
57
|
+
"@promptbook/core": "0.84.0-13"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* @generated
|
|
46
46
|
* @see https://github.com/webgptorg/promptbook
|
|
47
47
|
*/
|
|
48
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
48
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-12';
|
|
49
49
|
/**
|
|
50
50
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
51
51
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -5340,22 +5340,6 @@
|
|
|
5340
5340
|
* TODO: [®] DRY Register logic
|
|
5341
5341
|
*/
|
|
5342
5342
|
|
|
5343
|
-
/**
|
|
5344
|
-
* Removes emojis from a string and fix whitespaces
|
|
5345
|
-
*
|
|
5346
|
-
* @param text with emojis
|
|
5347
|
-
* @returns text without emojis
|
|
5348
|
-
* @public exported from `@promptbook/utils`
|
|
5349
|
-
*/
|
|
5350
|
-
function removeEmojis(text) {
|
|
5351
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
5352
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
5353
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
5354
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
5355
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
5356
|
-
return text;
|
|
5357
|
-
}
|
|
5358
|
-
|
|
5359
5343
|
/**
|
|
5360
5344
|
* @@@
|
|
5361
5345
|
*
|
|
@@ -5418,30 +5402,6 @@
|
|
|
5418
5402
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5419
5403
|
*/
|
|
5420
5404
|
|
|
5421
|
-
/**
|
|
5422
|
-
* @@@
|
|
5423
|
-
*
|
|
5424
|
-
* @param value @@@
|
|
5425
|
-
* @returns @@@
|
|
5426
|
-
* @example @@@
|
|
5427
|
-
* @public exported from `@promptbook/utils`
|
|
5428
|
-
*/
|
|
5429
|
-
function titleToName(value) {
|
|
5430
|
-
if (isValidUrl(value)) {
|
|
5431
|
-
value = value.replace(/^https?:\/\//, '');
|
|
5432
|
-
value = value.replace(/\.html$/, '');
|
|
5433
|
-
}
|
|
5434
|
-
else if (isValidFilePath(value)) {
|
|
5435
|
-
value = path.basename(value);
|
|
5436
|
-
// Note: Keeping extension in the name
|
|
5437
|
-
}
|
|
5438
|
-
value = value.split('/').join('-');
|
|
5439
|
-
value = removeEmojis(value);
|
|
5440
|
-
value = normalizeToKebabCase(value);
|
|
5441
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
5442
|
-
return value;
|
|
5443
|
-
}
|
|
5444
|
-
|
|
5445
5405
|
/**
|
|
5446
5406
|
* Creates unique name for the source
|
|
5447
5407
|
*
|
|
@@ -5527,6 +5487,46 @@
|
|
|
5527
5487
|
* TODO: [🖇] What about symlinks?
|
|
5528
5488
|
*/
|
|
5529
5489
|
|
|
5490
|
+
/**
|
|
5491
|
+
* Removes emojis from a string and fix whitespaces
|
|
5492
|
+
*
|
|
5493
|
+
* @param text with emojis
|
|
5494
|
+
* @returns text without emojis
|
|
5495
|
+
* @public exported from `@promptbook/utils`
|
|
5496
|
+
*/
|
|
5497
|
+
function removeEmojis(text) {
|
|
5498
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
5499
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
5500
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
5501
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
5502
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
5503
|
+
return text;
|
|
5504
|
+
}
|
|
5505
|
+
|
|
5506
|
+
/**
|
|
5507
|
+
* @@@
|
|
5508
|
+
*
|
|
5509
|
+
* @param value @@@
|
|
5510
|
+
* @returns @@@
|
|
5511
|
+
* @example @@@
|
|
5512
|
+
* @public exported from `@promptbook/utils`
|
|
5513
|
+
*/
|
|
5514
|
+
function titleToName(value) {
|
|
5515
|
+
if (isValidUrl(value)) {
|
|
5516
|
+
value = value.replace(/^https?:\/\//, '');
|
|
5517
|
+
value = value.replace(/\.html$/, '');
|
|
5518
|
+
}
|
|
5519
|
+
else if (isValidFilePath(value)) {
|
|
5520
|
+
value = path.basename(value);
|
|
5521
|
+
// Note: Keeping extension in the name
|
|
5522
|
+
}
|
|
5523
|
+
value = value.split('/').join('-');
|
|
5524
|
+
value = removeEmojis(value);
|
|
5525
|
+
value = normalizeToKebabCase(value);
|
|
5526
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
5527
|
+
return value;
|
|
5528
|
+
}
|
|
5529
|
+
|
|
5530
5530
|
/**
|
|
5531
5531
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5532
5532
|
*
|
|
@@ -5562,7 +5562,7 @@
|
|
|
5562
5562
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5563
5563
|
var _a;
|
|
5564
5564
|
return __awaiter(this, void 0, void 0, function () {
|
|
5565
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
5565
|
+
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;
|
|
5566
5566
|
return __generator(this, function (_l) {
|
|
5567
5567
|
switch (_l.label) {
|
|
5568
5568
|
case 0:
|
|
@@ -5578,19 +5578,61 @@
|
|
|
5578
5578
|
url = knowledgeSourceContent;
|
|
5579
5579
|
return [4 /*yield*/, fetch(url)];
|
|
5580
5580
|
case 1:
|
|
5581
|
-
|
|
5582
|
-
mimeType = ((_a =
|
|
5583
|
-
|
|
5581
|
+
response_1 = _l.sent();
|
|
5582
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5583
|
+
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
5584
|
+
return [2 /*return*/, {
|
|
5585
|
+
source: name,
|
|
5586
|
+
filename: null,
|
|
5587
|
+
url: url,
|
|
5588
|
+
mimeType: mimeType,
|
|
5589
|
+
/*
|
|
5590
|
+
TODO: [🥽]
|
|
5591
|
+
> async asBlob() {
|
|
5592
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
5593
|
+
> const content = await response.blob();
|
|
5594
|
+
> return content;
|
|
5595
|
+
> },
|
|
5596
|
+
*/
|
|
5597
|
+
asJson: function () {
|
|
5598
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5599
|
+
var content;
|
|
5600
|
+
return __generator(this, function (_a) {
|
|
5601
|
+
switch (_a.label) {
|
|
5602
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
5603
|
+
case 1:
|
|
5604
|
+
content = _a.sent();
|
|
5605
|
+
return [2 /*return*/, content];
|
|
5606
|
+
}
|
|
5607
|
+
});
|
|
5608
|
+
});
|
|
5609
|
+
},
|
|
5610
|
+
asText: function () {
|
|
5611
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5612
|
+
var content;
|
|
5613
|
+
return __generator(this, function (_a) {
|
|
5614
|
+
switch (_a.label) {
|
|
5615
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
5616
|
+
case 1:
|
|
5617
|
+
content = _a.sent();
|
|
5618
|
+
return [2 /*return*/, content];
|
|
5619
|
+
}
|
|
5620
|
+
});
|
|
5621
|
+
});
|
|
5622
|
+
},
|
|
5623
|
+
}];
|
|
5624
|
+
}
|
|
5625
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
5584
5626
|
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
5585
5627
|
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
5586
|
-
filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(
|
|
5628
|
+
filepath = path.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));
|
|
5587
5629
|
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
5588
5630
|
case 2:
|
|
5589
5631
|
_l.sent();
|
|
5590
5632
|
_g = (_f = tools.fs).writeFile;
|
|
5591
5633
|
_h = [path.join(rootDirname_1, filepath)];
|
|
5592
5634
|
_k = (_j = Buffer).from;
|
|
5593
|
-
return [4 /*yield*/,
|
|
5635
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
5594
5636
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
5595
5637
|
case 4:
|
|
5596
5638
|
_l.sent();
|