@promptbook/remote-server 0.84.0-13 → 0.84.0-14

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
@@ -12,7 +12,7 @@ import { unparse, parse } from 'papaparse';
12
12
  import hexEncoder from 'crypto-js/enc-hex';
13
13
  import sha256 from 'crypto-js/sha256';
14
14
  import { SHA256 } from 'crypto-js';
15
- import { lookup } from 'mime-types';
15
+ import { lookup, extension } from 'mime-types';
16
16
 
17
17
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
18
18
  /**
@@ -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-12';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-13';
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
@@ -6146,6 +6146,17 @@ function isFileExisting(filename, fs) {
6146
6146
  * TODO: [🖇] What about symlinks?
6147
6147
  */
6148
6148
 
6149
+ /**
6150
+ * Convert mime type to file extension
6151
+ *
6152
+ * Note: If the mime type is invalid, `null` is returned
6153
+ *
6154
+ * @private within the repository
6155
+ */
6156
+ function mimeTypeToExtension(value) {
6157
+ return extension(value) || null;
6158
+ }
6159
+
6149
6160
  /**
6150
6161
  * Removes emojis from a string and fix whitespaces
6151
6162
  *
@@ -6239,7 +6250,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6239
6250
  case 1:
6240
6251
  response_1 = _l.sent();
6241
6252
  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')) {
6253
+ if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
6243
6254
  return [2 /*return*/, {
6244
6255
  source: name,
6245
6256
  filename: null,
@@ -6284,7 +6295,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6284
6295
  basename = url.split('/').pop() || titleToName(url);
6285
6296
  hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
6286
6297
  rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
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));
6298
+ filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
6288
6299
  return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
6289
6300
  case 2:
6290
6301
  _l.sent();
@@ -6295,9 +6306,9 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6295
6306
  case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
6296
6307
  case 4:
6297
6308
  _l.sent();
6298
- // TODO: !!!!!!!! Check the file security
6309
+ // TODO: [💵] Check the file security
6299
6310
  // TODO: !!!!!!!! Check the file size (if it is not too big)
6300
- // TODO: !!!!!!!! Delete the file
6311
+ // TODO: !!!!!!!! Delete the file after the scraping is done
6301
6312
  return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6302
6313
  case 5:
6303
6314
  if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];