@promptbook/remote-server 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/remote-server",
|
|
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/remote-server.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
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-12';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -5998,22 +5998,6 @@
|
|
|
5998
5998
|
* TODO: [®] DRY Register logic
|
|
5999
5999
|
*/
|
|
6000
6000
|
|
|
6001
|
-
/**
|
|
6002
|
-
* Removes emojis from a string and fix whitespaces
|
|
6003
|
-
*
|
|
6004
|
-
* @param text with emojis
|
|
6005
|
-
* @returns text without emojis
|
|
6006
|
-
* @public exported from `@promptbook/utils`
|
|
6007
|
-
*/
|
|
6008
|
-
function removeEmojis(text) {
|
|
6009
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
6010
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
6011
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
6012
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
6013
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
6014
|
-
return text;
|
|
6015
|
-
}
|
|
6016
|
-
|
|
6017
6001
|
/**
|
|
6018
6002
|
* @@@
|
|
6019
6003
|
*
|
|
@@ -6076,30 +6060,6 @@
|
|
|
6076
6060
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6077
6061
|
*/
|
|
6078
6062
|
|
|
6079
|
-
/**
|
|
6080
|
-
* @@@
|
|
6081
|
-
*
|
|
6082
|
-
* @param value @@@
|
|
6083
|
-
* @returns @@@
|
|
6084
|
-
* @example @@@
|
|
6085
|
-
* @public exported from `@promptbook/utils`
|
|
6086
|
-
*/
|
|
6087
|
-
function titleToName(value) {
|
|
6088
|
-
if (isValidUrl(value)) {
|
|
6089
|
-
value = value.replace(/^https?:\/\//, '');
|
|
6090
|
-
value = value.replace(/\.html$/, '');
|
|
6091
|
-
}
|
|
6092
|
-
else if (isValidFilePath(value)) {
|
|
6093
|
-
value = path.basename(value);
|
|
6094
|
-
// Note: Keeping extension in the name
|
|
6095
|
-
}
|
|
6096
|
-
value = value.split('/').join('-');
|
|
6097
|
-
value = removeEmojis(value);
|
|
6098
|
-
value = normalizeToKebabCase(value);
|
|
6099
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
6100
|
-
return value;
|
|
6101
|
-
}
|
|
6102
|
-
|
|
6103
6063
|
/**
|
|
6104
6064
|
* Creates unique name for the source
|
|
6105
6065
|
*
|
|
@@ -6185,6 +6145,46 @@
|
|
|
6185
6145
|
* TODO: [🖇] What about symlinks?
|
|
6186
6146
|
*/
|
|
6187
6147
|
|
|
6148
|
+
/**
|
|
6149
|
+
* Removes emojis from a string and fix whitespaces
|
|
6150
|
+
*
|
|
6151
|
+
* @param text with emojis
|
|
6152
|
+
* @returns text without emojis
|
|
6153
|
+
* @public exported from `@promptbook/utils`
|
|
6154
|
+
*/
|
|
6155
|
+
function removeEmojis(text) {
|
|
6156
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
6157
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
6158
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
6159
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
6160
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
6161
|
+
return text;
|
|
6162
|
+
}
|
|
6163
|
+
|
|
6164
|
+
/**
|
|
6165
|
+
* @@@
|
|
6166
|
+
*
|
|
6167
|
+
* @param value @@@
|
|
6168
|
+
* @returns @@@
|
|
6169
|
+
* @example @@@
|
|
6170
|
+
* @public exported from `@promptbook/utils`
|
|
6171
|
+
*/
|
|
6172
|
+
function titleToName(value) {
|
|
6173
|
+
if (isValidUrl(value)) {
|
|
6174
|
+
value = value.replace(/^https?:\/\//, '');
|
|
6175
|
+
value = value.replace(/\.html$/, '');
|
|
6176
|
+
}
|
|
6177
|
+
else if (isValidFilePath(value)) {
|
|
6178
|
+
value = path.basename(value);
|
|
6179
|
+
// Note: Keeping extension in the name
|
|
6180
|
+
}
|
|
6181
|
+
value = value.split('/').join('-');
|
|
6182
|
+
value = removeEmojis(value);
|
|
6183
|
+
value = normalizeToKebabCase(value);
|
|
6184
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
6185
|
+
return value;
|
|
6186
|
+
}
|
|
6187
|
+
|
|
6188
6188
|
/**
|
|
6189
6189
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
6190
6190
|
*
|
|
@@ -6220,7 +6220,7 @@
|
|
|
6220
6220
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
6221
6221
|
var _a;
|
|
6222
6222
|
return __awaiter(this, void 0, void 0, function () {
|
|
6223
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
6223
|
+
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;
|
|
6224
6224
|
return __generator(this, function (_l) {
|
|
6225
6225
|
switch (_l.label) {
|
|
6226
6226
|
case 0:
|
|
@@ -6236,19 +6236,61 @@
|
|
|
6236
6236
|
url = knowledgeSourceContent;
|
|
6237
6237
|
return [4 /*yield*/, fetch(url)];
|
|
6238
6238
|
case 1:
|
|
6239
|
-
|
|
6240
|
-
mimeType = ((_a =
|
|
6241
|
-
|
|
6239
|
+
response_1 = _l.sent();
|
|
6240
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6241
|
+
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
6242
|
+
return [2 /*return*/, {
|
|
6243
|
+
source: name,
|
|
6244
|
+
filename: null,
|
|
6245
|
+
url: url,
|
|
6246
|
+
mimeType: mimeType,
|
|
6247
|
+
/*
|
|
6248
|
+
TODO: [🥽]
|
|
6249
|
+
> async asBlob() {
|
|
6250
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
6251
|
+
> const content = await response.blob();
|
|
6252
|
+
> return content;
|
|
6253
|
+
> },
|
|
6254
|
+
*/
|
|
6255
|
+
asJson: function () {
|
|
6256
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6257
|
+
var content;
|
|
6258
|
+
return __generator(this, function (_a) {
|
|
6259
|
+
switch (_a.label) {
|
|
6260
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
6261
|
+
case 1:
|
|
6262
|
+
content = _a.sent();
|
|
6263
|
+
return [2 /*return*/, content];
|
|
6264
|
+
}
|
|
6265
|
+
});
|
|
6266
|
+
});
|
|
6267
|
+
},
|
|
6268
|
+
asText: function () {
|
|
6269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6270
|
+
var content;
|
|
6271
|
+
return __generator(this, function (_a) {
|
|
6272
|
+
switch (_a.label) {
|
|
6273
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
6274
|
+
case 1:
|
|
6275
|
+
content = _a.sent();
|
|
6276
|
+
return [2 /*return*/, content];
|
|
6277
|
+
}
|
|
6278
|
+
});
|
|
6279
|
+
});
|
|
6280
|
+
},
|
|
6281
|
+
}];
|
|
6282
|
+
}
|
|
6283
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
6242
6284
|
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
6243
6285
|
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6244
|
-
filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(
|
|
6286
|
+
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));
|
|
6245
6287
|
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
6246
6288
|
case 2:
|
|
6247
6289
|
_l.sent();
|
|
6248
6290
|
_g = (_f = tools.fs).writeFile;
|
|
6249
6291
|
_h = [path.join(rootDirname_1, filepath)];
|
|
6250
6292
|
_k = (_j = Buffer).from;
|
|
6251
|
-
return [4 /*yield*/,
|
|
6293
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
6252
6294
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6253
6295
|
case 4:
|
|
6254
6296
|
_l.sent();
|