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