@promptbook/cli 0.71.0-13 → 0.71.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/README.md +1 -0
- package/esm/index.es.js +98 -80
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
- package/esm/typings/src/execution/ExecutionTools.d.ts +12 -2
- package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
- package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +2 -4
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +3 -1
- package/esm/typings/src/utils/files/{$isDirectoryExisting.d.ts → isDirectoryExisting.d.ts} +3 -4
- package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
- package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
- package/package.json +1 -1
- package/umd/index.umd.js +97 -79
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
- /package/esm/typings/src/utils/files/{$isDirectoryExisting.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
- /package/esm/typings/src/utils/files/{$isFileExisting.test.d.ts → isFileExisting.test.d.ts} +0 -0
- /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → listAllFiles.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.71.0-
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.71.0-13';
|
|
43
43
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -5107,30 +5107,45 @@
|
|
|
5107
5107
|
*/
|
|
5108
5108
|
|
|
5109
5109
|
/**
|
|
5110
|
-
*
|
|
5110
|
+
* Convert file extension to mime type
|
|
5111
5111
|
*
|
|
5112
|
-
*
|
|
5112
|
+
* @private within the repository
|
|
5113
|
+
*/
|
|
5114
|
+
function extensionToMimeType(value) {
|
|
5115
|
+
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5118
|
+
/**
|
|
5119
|
+
* Get the file extension from a file name
|
|
5113
5120
|
*
|
|
5114
5121
|
* @private within the repository
|
|
5115
5122
|
*/
|
|
5116
|
-
function
|
|
5123
|
+
function getFileExtension(value) {
|
|
5124
|
+
var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
|
|
5125
|
+
return match ? match[1].toLowerCase() : null;
|
|
5126
|
+
}
|
|
5127
|
+
|
|
5128
|
+
/**
|
|
5129
|
+
* Checks if the file exists
|
|
5130
|
+
*
|
|
5131
|
+
* @private within the repository
|
|
5132
|
+
*/
|
|
5133
|
+
function isFileExisting(filename, fs) {
|
|
5117
5134
|
return __awaiter(this, void 0, void 0, function () {
|
|
5118
5135
|
var isReadAccessAllowed, isFile;
|
|
5119
5136
|
return __generator(this, function (_a) {
|
|
5120
5137
|
switch (_a.label) {
|
|
5121
|
-
case 0:
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
return [4 /*yield*/, promises.access(filename, promises.constants.R_OK)
|
|
5126
|
-
.then(function () { return true; })
|
|
5127
|
-
.catch(function () { return false; })];
|
|
5138
|
+
case 0: return [4 /*yield*/, fs
|
|
5139
|
+
.access(filename, fs.constants.R_OK)
|
|
5140
|
+
.then(function () { return true; })
|
|
5141
|
+
.catch(function () { return false; })];
|
|
5128
5142
|
case 1:
|
|
5129
5143
|
isReadAccessAllowed = _a.sent();
|
|
5130
5144
|
if (!isReadAccessAllowed) {
|
|
5131
5145
|
return [2 /*return*/, false];
|
|
5132
5146
|
}
|
|
5133
|
-
return [4 /*yield*/,
|
|
5147
|
+
return [4 /*yield*/, fs
|
|
5148
|
+
.stat(filename)
|
|
5134
5149
|
.then(function (fileStat) { return fileStat.isFile(); })
|
|
5135
5150
|
.catch(function () { return false; })];
|
|
5136
5151
|
case 2:
|
|
@@ -5141,30 +5156,11 @@
|
|
|
5141
5156
|
});
|
|
5142
5157
|
}
|
|
5143
5158
|
/**
|
|
5144
|
-
* Note: [
|
|
5159
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
5145
5160
|
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
5146
5161
|
* TODO: [🖇] What about symlinks?
|
|
5147
5162
|
*/
|
|
5148
5163
|
|
|
5149
|
-
/**
|
|
5150
|
-
* Convert file extension to mime type
|
|
5151
|
-
*
|
|
5152
|
-
* @private within the repository
|
|
5153
|
-
*/
|
|
5154
|
-
function extensionToMimeType(value) {
|
|
5155
|
-
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
5156
|
-
}
|
|
5157
|
-
|
|
5158
|
-
/**
|
|
5159
|
-
* Get the file extension from a file name
|
|
5160
|
-
*
|
|
5161
|
-
* @private within the repository
|
|
5162
|
-
*/
|
|
5163
|
-
function getFileExtension(value) {
|
|
5164
|
-
var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
|
|
5165
|
-
return match ? match[1].toLowerCase() : null;
|
|
5166
|
-
}
|
|
5167
|
-
|
|
5168
5164
|
/**
|
|
5169
5165
|
* Tests if given string is valid URL.
|
|
5170
5166
|
*
|
|
@@ -5196,7 +5192,7 @@
|
|
|
5196
5192
|
*
|
|
5197
5193
|
* @private for scraper utilities
|
|
5198
5194
|
*/
|
|
5199
|
-
function makeKnowledgeSourceHandler(knowledgeSource, options) {
|
|
5195
|
+
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5200
5196
|
var _a;
|
|
5201
5197
|
return __awaiter(this, void 0, void 0, function () {
|
|
5202
5198
|
var sourceContent, name, _b, _c, rootDirname, _d,
|
|
@@ -5265,8 +5261,9 @@
|
|
|
5265
5261
|
}];
|
|
5266
5262
|
case 2:
|
|
5267
5263
|
if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
|
|
5268
|
-
if (
|
|
5269
|
-
throw new EnvironmentMismatchError('
|
|
5264
|
+
if (tools.fs === undefined) {
|
|
5265
|
+
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
5266
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
5270
5267
|
}
|
|
5271
5268
|
if (rootDirname === null) {
|
|
5272
5269
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
@@ -5275,7 +5272,7 @@
|
|
|
5275
5272
|
filename_1 = path.join(rootDirname, sourceContent).split('\\').join('/');
|
|
5276
5273
|
fileExtension = getFileExtension(filename_1);
|
|
5277
5274
|
mimeType_1 = extensionToMimeType(fileExtension || '');
|
|
5278
|
-
return [4 /*yield*/,
|
|
5275
|
+
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5279
5276
|
case 3:
|
|
5280
5277
|
if (!(_e.sent())) {
|
|
5281
5278
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
@@ -5291,7 +5288,7 @@
|
|
|
5291
5288
|
var content;
|
|
5292
5289
|
return __generator(this, function (_a) {
|
|
5293
5290
|
switch (_a.label) {
|
|
5294
|
-
case 0: return [4 /*yield*/,
|
|
5291
|
+
case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
|
|
5295
5292
|
case 1:
|
|
5296
5293
|
content = _a.sent();
|
|
5297
5294
|
return [2 /*return*/, new Blob([
|
|
@@ -5345,9 +5342,6 @@
|
|
|
5345
5342
|
});
|
|
5346
5343
|
});
|
|
5347
5344
|
}
|
|
5348
|
-
/**
|
|
5349
|
-
* TODO: !!!!!!! Maybe constrain to @promptbook/node bundle
|
|
5350
|
-
*/
|
|
5351
5345
|
|
|
5352
5346
|
/**
|
|
5353
5347
|
* Prepares the knowle
|
|
@@ -5371,7 +5365,7 @@
|
|
|
5371
5365
|
switch (_d.label) {
|
|
5372
5366
|
case 0:
|
|
5373
5367
|
partialPieces = null;
|
|
5374
|
-
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
5368
|
+
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
5375
5369
|
case 1:
|
|
5376
5370
|
sourceHandler = _d.sent();
|
|
5377
5371
|
_d.label = 2;
|
|
@@ -8603,6 +8597,29 @@
|
|
|
8603
8597
|
* TODO: [🍂] Maybe make llm = $provideLlmToolsFromEnv() without problem with bundle contaminated by only `@promptbook/node` and `@promptbook/cli` stuff
|
|
8604
8598
|
*/
|
|
8605
8599
|
|
|
8600
|
+
/**
|
|
8601
|
+
* @@@
|
|
8602
|
+
*
|
|
8603
|
+
* @public exported from `@promptbook/node`
|
|
8604
|
+
*/
|
|
8605
|
+
function $provideFilesystemForNode(options) {
|
|
8606
|
+
if (!$isRunningInNode()) {
|
|
8607
|
+
throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
|
|
8608
|
+
}
|
|
8609
|
+
var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
8610
|
+
TODO_USE(isVerbose);
|
|
8611
|
+
return {
|
|
8612
|
+
stat: promises.stat,
|
|
8613
|
+
access: promises.access,
|
|
8614
|
+
constants: promises.constants,
|
|
8615
|
+
readFile: promises.readFile,
|
|
8616
|
+
readdir: promises.readdir,
|
|
8617
|
+
};
|
|
8618
|
+
}
|
|
8619
|
+
/**
|
|
8620
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8621
|
+
*/
|
|
8622
|
+
|
|
8606
8623
|
/**
|
|
8607
8624
|
* !!!!!!
|
|
8608
8625
|
*
|
|
@@ -9125,7 +9142,8 @@
|
|
|
9125
9142
|
}
|
|
9126
9143
|
llm = $provideLlmToolsFromEnv(options);
|
|
9127
9144
|
_a = {
|
|
9128
|
-
llm: llm
|
|
9145
|
+
llm: llm,
|
|
9146
|
+
fs: $provideFilesystemForNode()
|
|
9129
9147
|
};
|
|
9130
9148
|
return [4 /*yield*/, $provideScrapersForNode({ llm: llm }, options)];
|
|
9131
9149
|
case 1:
|
|
@@ -9144,28 +9162,24 @@
|
|
|
9144
9162
|
/**
|
|
9145
9163
|
* Checks if the directory exists
|
|
9146
9164
|
*
|
|
9147
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
9148
|
-
*
|
|
9149
9165
|
* @private within the repository
|
|
9150
9166
|
*/
|
|
9151
|
-
function
|
|
9167
|
+
function isDirectoryExisting(directoryPath, fs) {
|
|
9152
9168
|
return __awaiter(this, void 0, void 0, function () {
|
|
9153
9169
|
var isReadAccessAllowed, isDirectory;
|
|
9154
9170
|
return __generator(this, function (_a) {
|
|
9155
9171
|
switch (_a.label) {
|
|
9156
|
-
case 0:
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
return [4 /*yield*/, promises.access(directoryPath, promises.constants.R_OK)
|
|
9161
|
-
.then(function () { return true; })
|
|
9162
|
-
.catch(function () { return false; })];
|
|
9172
|
+
case 0: return [4 /*yield*/, fs
|
|
9173
|
+
.access(directoryPath, fs.constants.R_OK)
|
|
9174
|
+
.then(function () { return true; })
|
|
9175
|
+
.catch(function () { return false; })];
|
|
9163
9176
|
case 1:
|
|
9164
9177
|
isReadAccessAllowed = _a.sent();
|
|
9165
9178
|
if (!isReadAccessAllowed) {
|
|
9166
9179
|
return [2 /*return*/, false];
|
|
9167
9180
|
}
|
|
9168
|
-
return [4 /*yield*/,
|
|
9181
|
+
return [4 /*yield*/, fs
|
|
9182
|
+
.stat(directoryPath)
|
|
9169
9183
|
.then(function (fileStat) { return fileStat.isDirectory(); })
|
|
9170
9184
|
.catch(function () { return false; })];
|
|
9171
9185
|
case 2:
|
|
@@ -9176,7 +9190,7 @@
|
|
|
9176
9190
|
});
|
|
9177
9191
|
}
|
|
9178
9192
|
/**
|
|
9179
|
-
* Note: [
|
|
9193
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
9180
9194
|
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
9181
9195
|
* TODO: [🧠][📂] "directory" vs "folder"
|
|
9182
9196
|
* TODO: [🖇] What about symlinks?
|
|
@@ -9185,30 +9199,24 @@
|
|
|
9185
9199
|
/**
|
|
9186
9200
|
* Reads all files in the directory
|
|
9187
9201
|
*
|
|
9188
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
9189
|
-
*
|
|
9190
9202
|
* @param path
|
|
9191
9203
|
* @param isRecursive
|
|
9192
9204
|
* @returns List of all files in the directory
|
|
9193
9205
|
* @private internal function of `createCollectionFromDirectory`
|
|
9194
9206
|
*/
|
|
9195
|
-
function
|
|
9207
|
+
function listAllFiles(path$1, isRecursive, fs) {
|
|
9196
9208
|
return __awaiter(this, void 0, void 0, function () {
|
|
9197
9209
|
var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
|
|
9198
9210
|
var e_1, _g;
|
|
9199
9211
|
return __generator(this, function (_h) {
|
|
9200
9212
|
switch (_h.label) {
|
|
9201
|
-
case 0:
|
|
9202
|
-
if (!$isRunningInNode()) {
|
|
9203
|
-
throw new EnvironmentMismatchError('Function `$listAllFiles` works only in Node environment.js');
|
|
9204
|
-
}
|
|
9205
|
-
return [4 /*yield*/, $isDirectoryExisting(path$1)];
|
|
9213
|
+
case 0: return [4 /*yield*/, isDirectoryExisting(path$1, fs)];
|
|
9206
9214
|
case 1:
|
|
9207
9215
|
if (!(_h.sent())) {
|
|
9208
9216
|
throw new Error("Directory \"".concat(path$1, "\" does not exist or is not readable"));
|
|
9209
9217
|
// <- TODO: Use some custom error class
|
|
9210
9218
|
}
|
|
9211
|
-
return [4 /*yield*/,
|
|
9219
|
+
return [4 /*yield*/, fs.readdir(path$1, {
|
|
9212
9220
|
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
9213
9221
|
})];
|
|
9214
9222
|
case 2:
|
|
@@ -9232,7 +9240,7 @@
|
|
|
9232
9240
|
_d = (_c = fileNames.push).apply;
|
|
9233
9241
|
_e = [fileNames];
|
|
9234
9242
|
_f = [[]];
|
|
9235
|
-
return [4 /*yield*/,
|
|
9243
|
+
return [4 /*yield*/, listAllFiles(subPath, isRecursive, fs)];
|
|
9236
9244
|
case 5:
|
|
9237
9245
|
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent()).map(function (filename) { return filename; })]), false]))]));
|
|
9238
9246
|
_h.label = 6;
|
|
@@ -9257,7 +9265,7 @@
|
|
|
9257
9265
|
}
|
|
9258
9266
|
/**
|
|
9259
9267
|
* TODO: [😶] Unite floder listing
|
|
9260
|
-
* Note: [
|
|
9268
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
9261
9269
|
* TODO: [🖇] What about symlinks?
|
|
9262
9270
|
*/
|
|
9263
9271
|
|
|
@@ -9366,17 +9374,18 @@
|
|
|
9366
9374
|
return __generator(this, function (_f) {
|
|
9367
9375
|
switch (_f.label) {
|
|
9368
9376
|
case 0:
|
|
9369
|
-
if (!$isRunningInNode()) {
|
|
9370
|
-
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
9371
|
-
}
|
|
9372
9377
|
if (!(tools === undefined)) return [3 /*break*/, 2];
|
|
9373
9378
|
return [4 /*yield*/, $provideExecutionToolsForNode()];
|
|
9374
9379
|
case 1:
|
|
9375
9380
|
tools = _f.sent();
|
|
9376
9381
|
_f.label = 2;
|
|
9377
9382
|
case 2:
|
|
9383
|
+
if (tools === undefined || tools.fs === undefined) {
|
|
9384
|
+
throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
|
|
9385
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
9386
|
+
}
|
|
9378
9387
|
makedLibraryFilePath = path.join(path$1, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
|
|
9379
|
-
return [4 /*yield*/,
|
|
9388
|
+
return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
|
|
9380
9389
|
case 3:
|
|
9381
9390
|
if (!(_f.sent())) {
|
|
9382
9391
|
console.info(colors__default["default"].yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
|
|
@@ -9396,7 +9405,7 @@
|
|
|
9396
9405
|
if (isVerbose) {
|
|
9397
9406
|
console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
|
|
9398
9407
|
}
|
|
9399
|
-
return [4 /*yield*/,
|
|
9408
|
+
return [4 /*yield*/, listAllFiles(path$1, isRecursive, tools.fs)];
|
|
9400
9409
|
case 1:
|
|
9401
9410
|
fileNames = _b.sent();
|
|
9402
9411
|
// Note: First load all .ptbk.json and then .ptbk.md files
|
|
@@ -9544,8 +9553,8 @@
|
|
|
9544
9553
|
});
|
|
9545
9554
|
}
|
|
9546
9555
|
/**
|
|
9547
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9548
9556
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
9557
|
+
* TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
|
|
9549
9558
|
*/
|
|
9550
9559
|
|
|
9551
9560
|
/**
|
|
@@ -9688,7 +9697,8 @@
|
|
|
9688
9697
|
* @public exported from `@promptbook/node`
|
|
9689
9698
|
*/
|
|
9690
9699
|
var FileCacheStorage = /** @class */ (function () {
|
|
9691
|
-
function FileCacheStorage(options) {
|
|
9700
|
+
function FileCacheStorage(tools, options) {
|
|
9701
|
+
this.tools = tools;
|
|
9692
9702
|
this.options = options;
|
|
9693
9703
|
if (!$isRunningInNode()) {
|
|
9694
9704
|
throw new EnvironmentMismatchError("FileCacheStorage works only in Node.js environment");
|
|
@@ -9714,7 +9724,7 @@
|
|
|
9714
9724
|
switch (_a.label) {
|
|
9715
9725
|
case 0:
|
|
9716
9726
|
filename = this.getFilenameForKey(key);
|
|
9717
|
-
return [4 /*yield*/,
|
|
9727
|
+
return [4 /*yield*/, isFileExisting(filename, this.tools.fs)];
|
|
9718
9728
|
case 1:
|
|
9719
9729
|
if (!(_a.sent())) {
|
|
9720
9730
|
return [2 /*return*/, null];
|
|
@@ -9969,7 +9979,7 @@
|
|
|
9969
9979
|
return cacheLlmTools(countTotalUsage(
|
|
9970
9980
|
// <- Note: for example here we don`t want the [🌯]
|
|
9971
9981
|
$provideLlmToolsFromEnv()), {
|
|
9972
|
-
storage: new FileCacheStorage({ rootFolderPath: path.join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
|
|
9982
|
+
storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, { rootFolderPath: path.join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
|
|
9973
9983
|
isReloaded: isCacheReloaded,
|
|
9974
9984
|
});
|
|
9975
9985
|
}
|
|
@@ -12756,6 +12766,7 @@
|
|
|
12756
12766
|
* 1) Need to store more than serialized JSONs
|
|
12757
12767
|
* 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: !!!!
|
|
12758
12768
|
* TODO: [🐱🐉][🧠] Make some smart crop
|
|
12769
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
12759
12770
|
*/
|
|
12760
12771
|
|
|
12761
12772
|
/**
|
|
@@ -13013,6 +13024,10 @@
|
|
|
13013
13024
|
if (!$isRunningInNode()) {
|
|
13014
13025
|
throw new KnowledgeScrapeError('Scraping .docx files is only supported in Node environment');
|
|
13015
13026
|
}
|
|
13027
|
+
if (this.tools.fs === undefined) {
|
|
13028
|
+
throw new EnvironmentMismatchError('Can not scrape documents without filesystem tools');
|
|
13029
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
13030
|
+
}
|
|
13016
13031
|
if (externalProgramsPaths.pandocPath === undefined) {
|
|
13017
13032
|
throw new MissingToolsError('Pandoc is required for scraping .docx files');
|
|
13018
13033
|
}
|
|
@@ -13030,7 +13045,7 @@
|
|
|
13030
13045
|
})];
|
|
13031
13046
|
case 1:
|
|
13032
13047
|
cacheFilehandler = _g.sent();
|
|
13033
|
-
return [4 /*yield*/,
|
|
13048
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
13034
13049
|
case 2:
|
|
13035
13050
|
if (!!(_g.sent())) return [3 /*break*/, 5];
|
|
13036
13051
|
command_1 = "\"".concat(externalProgramsPaths.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
|
|
@@ -13039,7 +13054,7 @@
|
|
|
13039
13054
|
case 3:
|
|
13040
13055
|
// TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
|
|
13041
13056
|
_g.sent();
|
|
13042
|
-
return [4 /*yield*/,
|
|
13057
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
13043
13058
|
case 4:
|
|
13044
13059
|
// Note: [0]
|
|
13045
13060
|
if (!(_g.sent())) {
|
|
@@ -13165,6 +13180,10 @@
|
|
|
13165
13180
|
if (!$isRunningInNode()) {
|
|
13166
13181
|
throw new KnowledgeScrapeError('Scraping .doc files is only supported in Node environment');
|
|
13167
13182
|
}
|
|
13183
|
+
if (this.tools.fs === undefined) {
|
|
13184
|
+
throw new EnvironmentMismatchError('Can not scrape (legacy) documents without filesystem tools');
|
|
13185
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
13186
|
+
}
|
|
13168
13187
|
if (externalProgramsPaths.libreOfficePath === undefined) {
|
|
13169
13188
|
throw new MissingToolsError('LibreOffice is required for scraping .doc and .rtf files');
|
|
13170
13189
|
}
|
|
@@ -13185,7 +13204,7 @@
|
|
|
13185
13204
|
if (isVerbose) {
|
|
13186
13205
|
console.info("documentScraper: Converting .".concat(extension, " -> .docx"));
|
|
13187
13206
|
}
|
|
13188
|
-
return [4 /*yield*/,
|
|
13207
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
13189
13208
|
case 2:
|
|
13190
13209
|
if (!!(_g.sent())) return [3 /*break*/, 8];
|
|
13191
13210
|
documentSourceOutdirPathForLibreOffice_1 = path.join(path.dirname(cacheFilehandler.filename), 'libreoffice')
|
|
@@ -13210,7 +13229,7 @@
|
|
|
13210
13229
|
return [4 /*yield*/, promises.rmdir(documentSourceOutdirPathForLibreOffice_1)];
|
|
13211
13230
|
case 6:
|
|
13212
13231
|
_g.sent();
|
|
13213
|
-
return [4 /*yield*/,
|
|
13232
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
13214
13233
|
case 7:
|
|
13215
13234
|
if (!(_g.sent())) {
|
|
13216
13235
|
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n File that was supposed to be created by LibreOffice does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
@@ -13290,7 +13309,6 @@
|
|
|
13290
13309
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
13291
13310
|
*/
|
|
13292
13311
|
|
|
13293
|
-
// <- TODO: !!!!!!! Are theese changed to import type { ... } from ... correctly
|
|
13294
13312
|
/**
|
|
13295
13313
|
* @@@
|
|
13296
13314
|
*
|