@promptbook/remote-server 0.84.0-12 → 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.
@@ -12,6 +12,8 @@ import { LOGO_LIGHT_SRC } from '../config';
12
12
  import { LOGO_DARK_SRC } from '../config';
13
13
  import { DEFAULT_BOOK_TITLE } from '../config';
14
14
  import { DEFAULT_TASK_TITLE } from '../config';
15
+ import { DEFAULT_PROMPT_TASK_TITLE } from '../config';
16
+ import { DEFAULT_BOOK_OUTPUT_PARAMETER_NAME } from '../config';
15
17
  import { MAX_FILENAME_LENGTH } from '../config';
16
18
  import { DEFAULT_INTERMEDIATE_FILES_STRATEGY } from '../config';
17
19
  import { DEFAULT_MAX_PARALLEL_COUNT } from '../config';
@@ -139,6 +141,8 @@ export { LOGO_LIGHT_SRC };
139
141
  export { LOGO_DARK_SRC };
140
142
  export { DEFAULT_BOOK_TITLE };
141
143
  export { DEFAULT_TASK_TITLE };
144
+ export { DEFAULT_PROMPT_TASK_TITLE };
145
+ export { DEFAULT_BOOK_OUTPUT_PARAMETER_NAME };
142
146
  export { MAX_FILENAME_LENGTH };
143
147
  export { DEFAULT_INTERMEDIATE_FILES_STRATEGY };
144
148
  export { DEFAULT_MAX_PARALLEL_COUNT };
@@ -65,6 +65,18 @@ export declare const DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
65
65
  * @public exported from `@promptbook/core`
66
66
  */
67
67
  export declare const DEFAULT_TASK_TITLE = "Task";
68
+ /**
69
+ * When the title of the prompt task is not provided, the default title is used
70
+ *
71
+ * @public exported from `@promptbook/core`
72
+ */
73
+ export declare const DEFAULT_PROMPT_TASK_TITLE = "Prompt";
74
+ /**
75
+ * When the pipeline is flat and no name of return parameter is provided, this name is used
76
+ *
77
+ * @public exported from `@promptbook/core`
78
+ */
79
+ export declare const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = "result";
68
80
  /**
69
81
  * Warning message for the generated sections and files files
70
82
  *
@@ -0,0 +1,10 @@
1
+ import type { string_file_extension } from '../../types/typeAliases';
2
+ import type { string_mime_type } from '../../types/typeAliases';
3
+ /**
4
+ * Convert mime type to file extension
5
+ *
6
+ * Note: If the mime type is invalid, `null` is returned
7
+ *
8
+ * @private within the repository
9
+ */
10
+ export declare function mimeTypeToExtension(value: string_mime_type): string_file_extension | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.84.0-12",
3
+ "version": "0.84.0-14",
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-12"
57
+ "@promptbook/core": "0.84.0-14"
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-11';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-13';
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,57 @@
6185
6145
  * TODO: [🖇] What about symlinks?
6186
6146
  */
6187
6147
 
6148
+ /**
6149
+ * Convert mime type to file extension
6150
+ *
6151
+ * Note: If the mime type is invalid, `null` is returned
6152
+ *
6153
+ * @private within the repository
6154
+ */
6155
+ function mimeTypeToExtension(value) {
6156
+ return mimeTypes.extension(value) || null;
6157
+ }
6158
+
6159
+ /**
6160
+ * Removes emojis from a string and fix whitespaces
6161
+ *
6162
+ * @param text with emojis
6163
+ * @returns text without emojis
6164
+ * @public exported from `@promptbook/utils`
6165
+ */
6166
+ function removeEmojis(text) {
6167
+ // Replace emojis (and also ZWJ sequence) with hyphens
6168
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
6169
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
6170
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
6171
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
6172
+ return text;
6173
+ }
6174
+
6175
+ /**
6176
+ * @@@
6177
+ *
6178
+ * @param value @@@
6179
+ * @returns @@@
6180
+ * @example @@@
6181
+ * @public exported from `@promptbook/utils`
6182
+ */
6183
+ function titleToName(value) {
6184
+ if (isValidUrl(value)) {
6185
+ value = value.replace(/^https?:\/\//, '');
6186
+ value = value.replace(/\.html$/, '');
6187
+ }
6188
+ else if (isValidFilePath(value)) {
6189
+ value = path.basename(value);
6190
+ // Note: Keeping extension in the name
6191
+ }
6192
+ value = value.split('/').join('-');
6193
+ value = removeEmojis(value);
6194
+ value = normalizeToKebabCase(value);
6195
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
6196
+ return value;
6197
+ }
6198
+
6188
6199
  /**
6189
6200
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
6190
6201
  *
@@ -6220,7 +6231,7 @@
6220
6231
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6221
6232
  var _a;
6222
6233
  return __awaiter(this, void 0, void 0, function () {
6223
- 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;
6234
+ 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
6235
  return __generator(this, function (_l) {
6225
6236
  switch (_l.label) {
6226
6237
  case 0:
@@ -6236,25 +6247,67 @@
6236
6247
  url = knowledgeSourceContent;
6237
6248
  return [4 /*yield*/, fetch(url)];
6238
6249
  case 1:
6239
- response = _l.sent();
6240
- mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
6241
- filename = url.split('/').pop() || titleToName(url);
6250
+ response_1 = _l.sent();
6251
+ mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
6252
+ if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
6253
+ return [2 /*return*/, {
6254
+ source: name,
6255
+ filename: null,
6256
+ url: url,
6257
+ mimeType: mimeType,
6258
+ /*
6259
+ TODO: [🥽]
6260
+ > async asBlob() {
6261
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
6262
+ > const content = await response.blob();
6263
+ > return content;
6264
+ > },
6265
+ */
6266
+ asJson: function () {
6267
+ return __awaiter(this, void 0, void 0, function () {
6268
+ var content;
6269
+ return __generator(this, function (_a) {
6270
+ switch (_a.label) {
6271
+ case 0: return [4 /*yield*/, response_1.json()];
6272
+ case 1:
6273
+ content = _a.sent();
6274
+ return [2 /*return*/, content];
6275
+ }
6276
+ });
6277
+ });
6278
+ },
6279
+ asText: function () {
6280
+ return __awaiter(this, void 0, void 0, function () {
6281
+ var content;
6282
+ return __generator(this, function (_a) {
6283
+ switch (_a.label) {
6284
+ case 0: return [4 /*yield*/, response_1.text()];
6285
+ case 1:
6286
+ content = _a.sent();
6287
+ return [2 /*return*/, content];
6288
+ }
6289
+ });
6290
+ });
6291
+ },
6292
+ }];
6293
+ }
6294
+ basename = url.split('/').pop() || titleToName(url);
6242
6295
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
6243
6296
  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(filename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
6297
+ 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), ".").concat(mimeTypeToExtension(mimeType))], false));
6245
6298
  return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
6246
6299
  case 2:
6247
6300
  _l.sent();
6248
6301
  _g = (_f = tools.fs).writeFile;
6249
6302
  _h = [path.join(rootDirname_1, filepath)];
6250
6303
  _k = (_j = Buffer).from;
6251
- return [4 /*yield*/, response.arrayBuffer()];
6304
+ return [4 /*yield*/, response_1.arrayBuffer()];
6252
6305
  case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
6253
6306
  case 4:
6254
6307
  _l.sent();
6255
- // TODO: !!!!!!!! Check the file security
6308
+ // TODO: [💵] Check the file security
6256
6309
  // TODO: !!!!!!!! Check the file size (if it is not too big)
6257
- // TODO: !!!!!!!! Delete the file
6310
+ // TODO: !!!!!!!! Delete the file after the scraping is done
6258
6311
  return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6259
6312
  case 5:
6260
6313
  if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];