@promptbook/cli 0.71.0-12 → 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.
Files changed (30) hide show
  1. package/README.md +1 -0
  2. package/esm/index.es.js +98 -80
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/node.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  6. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -2
  7. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
  8. package/esm/typings/src/execution/ExecutionTools.d.ts +12 -2
  9. package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
  10. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
  11. package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
  12. package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
  13. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
  14. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
  15. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +1 -0
  16. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +2 -4
  17. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
  18. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
  19. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
  20. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +3 -1
  21. package/esm/typings/src/utils/files/{$isDirectoryExisting.d.ts → isDirectoryExisting.d.ts} +3 -4
  22. package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
  23. package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
  24. package/package.json +1 -1
  25. package/umd/index.umd.js +97 -79
  26. package/umd/index.umd.js.map +1 -1
  27. package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
  28. /package/esm/typings/src/utils/files/{$isDirectoryExisting.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
  29. /package/esm/typings/src/utils/files/{$isFileExisting.test.d.ts → isFileExisting.test.d.ts} +0 -0
  30. /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → listAllFiles.test.d.ts} +0 -0
package/README.md CHANGED
@@ -61,6 +61,7 @@ Then just use it:
61
61
  ```typescript
62
62
  import { createPipelineExecutor, assertsExecutionSuccessful } from '@promptbook/core';
63
63
  import { $provideExecutionToolsForNode } from '@promptbook/node';
64
+ import { $provideFilesystemForNode } from '@promptbook/node';
64
65
  import { getPipelineCollection } from './promptbook-collection'; // <- Importing from pre-built library
65
66
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
66
67
  import { OpenAiExecutionTools } from '@promptbook/openai';
package/esm/index.es.js CHANGED
@@ -2,7 +2,7 @@ import commander from 'commander';
2
2
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
3
  import colors from 'colors';
4
4
  import { forTime } from 'waitasecond';
5
- import { stat, access, constants, readFile, readdir, writeFile, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
5
+ import { readFile, stat, access, constants, readdir, writeFile, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
6
6
  import { join, basename, dirname } from 'path';
7
7
  import { format } from 'prettier';
8
8
  import parserHtml from 'prettier/parser-html';
@@ -26,7 +26,7 @@ import { Converter } from 'showdown';
26
26
  /**
27
27
  * The version of the Promptbook library
28
28
  */
29
- var PROMPTBOOK_VERSION = '0.71.0-11';
29
+ var PROMPTBOOK_VERSION = '0.71.0-13';
30
30
  // TODO: [main] !!!! List here all the versions and annotate + put into script
31
31
 
32
32
  /*! *****************************************************************************
@@ -5094,30 +5094,45 @@ function sourceContentToName(sourceContent) {
5094
5094
  */
5095
5095
 
5096
5096
  /**
5097
- * Checks if the file exists
5097
+ * Convert file extension to mime type
5098
5098
  *
5099
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
5099
+ * @private within the repository
5100
+ */
5101
+ function extensionToMimeType(value) {
5102
+ return lookup(value) || 'application/octet-stream';
5103
+ }
5104
+
5105
+ /**
5106
+ * Get the file extension from a file name
5100
5107
  *
5101
5108
  * @private within the repository
5102
5109
  */
5103
- function $isFileExisting(filename) {
5110
+ function getFileExtension(value) {
5111
+ var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
5112
+ return match ? match[1].toLowerCase() : null;
5113
+ }
5114
+
5115
+ /**
5116
+ * Checks if the file exists
5117
+ *
5118
+ * @private within the repository
5119
+ */
5120
+ function isFileExisting(filename, fs) {
5104
5121
  return __awaiter(this, void 0, void 0, function () {
5105
5122
  var isReadAccessAllowed, isFile;
5106
5123
  return __generator(this, function (_a) {
5107
5124
  switch (_a.label) {
5108
- case 0:
5109
- if (!$isRunningInNode()) {
5110
- throw new EnvironmentMismatchError('Function `$isFileExisting` works only in Node environment.js');
5111
- }
5112
- return [4 /*yield*/, access(filename, constants.R_OK)
5113
- .then(function () { return true; })
5114
- .catch(function () { return false; })];
5125
+ case 0: return [4 /*yield*/, fs
5126
+ .access(filename, fs.constants.R_OK)
5127
+ .then(function () { return true; })
5128
+ .catch(function () { return false; })];
5115
5129
  case 1:
5116
5130
  isReadAccessAllowed = _a.sent();
5117
5131
  if (!isReadAccessAllowed) {
5118
5132
  return [2 /*return*/, false];
5119
5133
  }
5120
- return [4 /*yield*/, stat(filename)
5134
+ return [4 /*yield*/, fs
5135
+ .stat(filename)
5121
5136
  .then(function (fileStat) { return fileStat.isFile(); })
5122
5137
  .catch(function () { return false; })];
5123
5138
  case 2:
@@ -5128,30 +5143,11 @@ function $isFileExisting(filename) {
5128
5143
  });
5129
5144
  }
5130
5145
  /**
5131
- * Note: [🟢 !!!!!! After fix makeKnowledgeSourceHandler] Code in this file should never be published outside of `@promptbook/node` and `@promptbook/cli`
5146
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
5132
5147
  * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
5133
5148
  * TODO: [🖇] What about symlinks?
5134
5149
  */
5135
5150
 
5136
- /**
5137
- * Convert file extension to mime type
5138
- *
5139
- * @private within the repository
5140
- */
5141
- function extensionToMimeType(value) {
5142
- return lookup(value) || 'application/octet-stream';
5143
- }
5144
-
5145
- /**
5146
- * Get the file extension from a file name
5147
- *
5148
- * @private within the repository
5149
- */
5150
- function getFileExtension(value) {
5151
- var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
5152
- return match ? match[1].toLowerCase() : null;
5153
- }
5154
-
5155
5151
  /**
5156
5152
  * Tests if given string is valid URL.
5157
5153
  *
@@ -5183,7 +5179,7 @@ function isValidFilePath(filename) {
5183
5179
  *
5184
5180
  * @private for scraper utilities
5185
5181
  */
5186
- function makeKnowledgeSourceHandler(knowledgeSource, options) {
5182
+ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5187
5183
  var _a;
5188
5184
  return __awaiter(this, void 0, void 0, function () {
5189
5185
  var sourceContent, name, _b, _c, rootDirname, _d,
@@ -5252,8 +5248,9 @@ function makeKnowledgeSourceHandler(knowledgeSource, options) {
5252
5248
  }];
5253
5249
  case 2:
5254
5250
  if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
5255
- if (!$isRunningInNode()) {
5256
- throw new EnvironmentMismatchError('Importing knowledge source file works only in Node.js environment');
5251
+ if (tools.fs === undefined) {
5252
+ throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
5253
+ // <- TODO: [🧠] What is the best error type here`
5257
5254
  }
5258
5255
  if (rootDirname === null) {
5259
5256
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
@@ -5262,7 +5259,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, options) {
5262
5259
  filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
5263
5260
  fileExtension = getFileExtension(filename_1);
5264
5261
  mimeType_1 = extensionToMimeType(fileExtension || '');
5265
- return [4 /*yield*/, $isFileExisting(filename_1)];
5262
+ return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5266
5263
  case 3:
5267
5264
  if (!(_e.sent())) {
5268
5265
  throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
@@ -5278,7 +5275,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, options) {
5278
5275
  var content;
5279
5276
  return __generator(this, function (_a) {
5280
5277
  switch (_a.label) {
5281
- case 0: return [4 /*yield*/, readFile(filename_1)];
5278
+ case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
5282
5279
  case 1:
5283
5280
  content = _a.sent();
5284
5281
  return [2 /*return*/, new Blob([
@@ -5332,9 +5329,6 @@ function makeKnowledgeSourceHandler(knowledgeSource, options) {
5332
5329
  });
5333
5330
  });
5334
5331
  }
5335
- /**
5336
- * TODO: !!!!!!! Maybe constrain to @promptbook/node bundle
5337
- */
5338
5332
 
5339
5333
  /**
5340
5334
  * Prepares the knowle
@@ -5358,7 +5352,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5358
5352
  switch (_d.label) {
5359
5353
  case 0:
5360
5354
  partialPieces = null;
5361
- return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, { rootDirname: rootDirname, isVerbose: isVerbose })];
5355
+ return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname: rootDirname, isVerbose: isVerbose })];
5362
5356
  case 1:
5363
5357
  sourceHandler = _d.sent();
5364
5358
  _d.label = 2;
@@ -8590,6 +8584,29 @@ function $provideLlmToolsFromEnv(options) {
8590
8584
  * TODO: [🍂] Maybe make llm = $provideLlmToolsFromEnv() without problem with bundle contaminated by only `@promptbook/node` and `@promptbook/cli` stuff
8591
8585
  */
8592
8586
 
8587
+ /**
8588
+ * @@@
8589
+ *
8590
+ * @public exported from `@promptbook/node`
8591
+ */
8592
+ function $provideFilesystemForNode(options) {
8593
+ if (!$isRunningInNode()) {
8594
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8595
+ }
8596
+ var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
8597
+ TODO_USE(isVerbose);
8598
+ return {
8599
+ stat: stat,
8600
+ access: access,
8601
+ constants: constants,
8602
+ readFile: readFile,
8603
+ readdir: readdir,
8604
+ };
8605
+ }
8606
+ /**
8607
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8608
+ */
8609
+
8593
8610
  /**
8594
8611
  * !!!!!!
8595
8612
  *
@@ -9112,7 +9129,8 @@ function $provideExecutionToolsForNode(options) {
9112
9129
  }
9113
9130
  llm = $provideLlmToolsFromEnv(options);
9114
9131
  _a = {
9115
- llm: llm
9132
+ llm: llm,
9133
+ fs: $provideFilesystemForNode()
9116
9134
  };
9117
9135
  return [4 /*yield*/, $provideScrapersForNode({ llm: llm }, options)];
9118
9136
  case 1:
@@ -9131,28 +9149,24 @@ function $provideExecutionToolsForNode(options) {
9131
9149
  /**
9132
9150
  * Checks if the directory exists
9133
9151
  *
9134
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
9135
- *
9136
9152
  * @private within the repository
9137
9153
  */
9138
- function $isDirectoryExisting(directoryPath) {
9154
+ function isDirectoryExisting(directoryPath, fs) {
9139
9155
  return __awaiter(this, void 0, void 0, function () {
9140
9156
  var isReadAccessAllowed, isDirectory;
9141
9157
  return __generator(this, function (_a) {
9142
9158
  switch (_a.label) {
9143
- case 0:
9144
- if (!$isRunningInNode()) {
9145
- throw new EnvironmentMismatchError('Function `$isDirectoryExisting` works only in Node environment.js');
9146
- }
9147
- return [4 /*yield*/, access(directoryPath, constants.R_OK)
9148
- .then(function () { return true; })
9149
- .catch(function () { return false; })];
9159
+ case 0: return [4 /*yield*/, fs
9160
+ .access(directoryPath, fs.constants.R_OK)
9161
+ .then(function () { return true; })
9162
+ .catch(function () { return false; })];
9150
9163
  case 1:
9151
9164
  isReadAccessAllowed = _a.sent();
9152
9165
  if (!isReadAccessAllowed) {
9153
9166
  return [2 /*return*/, false];
9154
9167
  }
9155
- return [4 /*yield*/, stat(directoryPath)
9168
+ return [4 /*yield*/, fs
9169
+ .stat(directoryPath)
9156
9170
  .then(function (fileStat) { return fileStat.isDirectory(); })
9157
9171
  .catch(function () { return false; })];
9158
9172
  case 2:
@@ -9163,7 +9177,7 @@ function $isDirectoryExisting(directoryPath) {
9163
9177
  });
9164
9178
  }
9165
9179
  /**
9166
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9180
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
9167
9181
  * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
9168
9182
  * TODO: [🧠][📂] "directory" vs "folder"
9169
9183
  * TODO: [🖇] What about symlinks?
@@ -9172,30 +9186,24 @@ function $isDirectoryExisting(directoryPath) {
9172
9186
  /**
9173
9187
  * Reads all files in the directory
9174
9188
  *
9175
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
9176
- *
9177
9189
  * @param path
9178
9190
  * @param isRecursive
9179
9191
  * @returns List of all files in the directory
9180
9192
  * @private internal function of `createCollectionFromDirectory`
9181
9193
  */
9182
- function $listAllFiles(path, isRecursive) {
9194
+ function listAllFiles(path, isRecursive, fs) {
9183
9195
  return __awaiter(this, void 0, void 0, function () {
9184
9196
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
9185
9197
  var e_1, _g;
9186
9198
  return __generator(this, function (_h) {
9187
9199
  switch (_h.label) {
9188
- case 0:
9189
- if (!$isRunningInNode()) {
9190
- throw new EnvironmentMismatchError('Function `$listAllFiles` works only in Node environment.js');
9191
- }
9192
- return [4 /*yield*/, $isDirectoryExisting(path)];
9200
+ case 0: return [4 /*yield*/, isDirectoryExisting(path, fs)];
9193
9201
  case 1:
9194
9202
  if (!(_h.sent())) {
9195
9203
  throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
9196
9204
  // <- TODO: Use some custom error class
9197
9205
  }
9198
- return [4 /*yield*/, readdir(path, {
9206
+ return [4 /*yield*/, fs.readdir(path, {
9199
9207
  withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
9200
9208
  })];
9201
9209
  case 2:
@@ -9219,7 +9227,7 @@ function $listAllFiles(path, isRecursive) {
9219
9227
  _d = (_c = fileNames.push).apply;
9220
9228
  _e = [fileNames];
9221
9229
  _f = [[]];
9222
- return [4 /*yield*/, $listAllFiles(subPath, isRecursive)];
9230
+ return [4 /*yield*/, listAllFiles(subPath, isRecursive, fs)];
9223
9231
  case 5:
9224
9232
  _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent()).map(function (filename) { return filename; })]), false]))]));
9225
9233
  _h.label = 6;
@@ -9244,7 +9252,7 @@ function $listAllFiles(path, isRecursive) {
9244
9252
  }
9245
9253
  /**
9246
9254
  * TODO: [😶] Unite floder listing
9247
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9255
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
9248
9256
  * TODO: [🖇] What about symlinks?
9249
9257
  */
9250
9258
 
@@ -9353,17 +9361,18 @@ function createCollectionFromDirectory(path, tools, options) {
9353
9361
  return __generator(this, function (_f) {
9354
9362
  switch (_f.label) {
9355
9363
  case 0:
9356
- if (!$isRunningInNode()) {
9357
- throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
9358
- }
9359
9364
  if (!(tools === undefined)) return [3 /*break*/, 2];
9360
9365
  return [4 /*yield*/, $provideExecutionToolsForNode()];
9361
9366
  case 1:
9362
9367
  tools = _f.sent();
9363
9368
  _f.label = 2;
9364
9369
  case 2:
9370
+ if (tools === undefined || tools.fs === undefined) {
9371
+ throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
9372
+ // <- TODO: [🧠] What is the best error type here`
9373
+ }
9365
9374
  makedLibraryFilePath = join(path, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
9366
- return [4 /*yield*/, $isFileExisting(makedLibraryFilePath)];
9375
+ return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
9367
9376
  case 3:
9368
9377
  if (!(_f.sent())) {
9369
9378
  console.info(colors.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.")));
@@ -9383,7 +9392,7 @@ function createCollectionFromDirectory(path, tools, options) {
9383
9392
  if (isVerbose) {
9384
9393
  console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
9385
9394
  }
9386
- return [4 /*yield*/, $listAllFiles(path, isRecursive)];
9395
+ return [4 /*yield*/, listAllFiles(path, isRecursive, tools.fs)];
9387
9396
  case 1:
9388
9397
  fileNames = _b.sent();
9389
9398
  // Note: First load all .ptbk.json and then .ptbk.md files
@@ -9531,8 +9540,8 @@ function createCollectionFromDirectory(path, tools, options) {
9531
9540
  });
9532
9541
  }
9533
9542
  /**
9534
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9535
9543
  * TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
9544
+ * TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
9536
9545
  */
9537
9546
 
9538
9547
  /**
@@ -9675,7 +9684,8 @@ function nameToSubfolderPath(name) {
9675
9684
  * @public exported from `@promptbook/node`
9676
9685
  */
9677
9686
  var FileCacheStorage = /** @class */ (function () {
9678
- function FileCacheStorage(options) {
9687
+ function FileCacheStorage(tools, options) {
9688
+ this.tools = tools;
9679
9689
  this.options = options;
9680
9690
  if (!$isRunningInNode()) {
9681
9691
  throw new EnvironmentMismatchError("FileCacheStorage works only in Node.js environment");
@@ -9701,7 +9711,7 @@ var FileCacheStorage = /** @class */ (function () {
9701
9711
  switch (_a.label) {
9702
9712
  case 0:
9703
9713
  filename = this.getFilenameForKey(key);
9704
- return [4 /*yield*/, $isFileExisting(filename)];
9714
+ return [4 /*yield*/, isFileExisting(filename, this.tools.fs)];
9705
9715
  case 1:
9706
9716
  if (!(_a.sent())) {
9707
9717
  return [2 /*return*/, null];
@@ -9956,7 +9966,7 @@ function $provideLlmToolsForCli(options) {
9956
9966
  return cacheLlmTools(countTotalUsage(
9957
9967
  // <- Note: for example here we don`t want the [🌯]
9958
9968
  $provideLlmToolsFromEnv()), {
9959
- storage: new FileCacheStorage({ rootFolderPath: join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
9969
+ storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, { rootFolderPath: join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
9960
9970
  isReloaded: isCacheReloaded,
9961
9971
  });
9962
9972
  }
@@ -12743,6 +12753,7 @@ function getScraperIntermediateSource(source, options) {
12743
12753
  * 1) Need to store more than serialized JSONs
12744
12754
  * 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: !!!!
12745
12755
  * TODO: [🐱‍🐉][🧠] Make some smart crop
12756
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
12746
12757
  */
12747
12758
 
12748
12759
  /**
@@ -13000,6 +13011,10 @@ var DocumentScraper = /** @class */ (function () {
13000
13011
  if (!$isRunningInNode()) {
13001
13012
  throw new KnowledgeScrapeError('Scraping .docx files is only supported in Node environment');
13002
13013
  }
13014
+ if (this.tools.fs === undefined) {
13015
+ throw new EnvironmentMismatchError('Can not scrape documents without filesystem tools');
13016
+ // <- TODO: [🧠] What is the best error type here`
13017
+ }
13003
13018
  if (externalProgramsPaths.pandocPath === undefined) {
13004
13019
  throw new MissingToolsError('Pandoc is required for scraping .docx files');
13005
13020
  }
@@ -13017,7 +13032,7 @@ var DocumentScraper = /** @class */ (function () {
13017
13032
  })];
13018
13033
  case 1:
13019
13034
  cacheFilehandler = _g.sent();
13020
- return [4 /*yield*/, $isFileExisting(cacheFilehandler.filename)];
13035
+ return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
13021
13036
  case 2:
13022
13037
  if (!!(_g.sent())) return [3 /*break*/, 5];
13023
13038
  command_1 = "\"".concat(externalProgramsPaths.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
@@ -13026,7 +13041,7 @@ var DocumentScraper = /** @class */ (function () {
13026
13041
  case 3:
13027
13042
  // TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
13028
13043
  _g.sent();
13029
- return [4 /*yield*/, $isFileExisting(cacheFilehandler.filename)];
13044
+ return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
13030
13045
  case 4:
13031
13046
  // Note: [0]
13032
13047
  if (!(_g.sent())) {
@@ -13152,6 +13167,10 @@ var LegacyDocumentScraper = /** @class */ (function () {
13152
13167
  if (!$isRunningInNode()) {
13153
13168
  throw new KnowledgeScrapeError('Scraping .doc files is only supported in Node environment');
13154
13169
  }
13170
+ if (this.tools.fs === undefined) {
13171
+ throw new EnvironmentMismatchError('Can not scrape (legacy) documents without filesystem tools');
13172
+ // <- TODO: [🧠] What is the best error type here`
13173
+ }
13155
13174
  if (externalProgramsPaths.libreOfficePath === undefined) {
13156
13175
  throw new MissingToolsError('LibreOffice is required for scraping .doc and .rtf files');
13157
13176
  }
@@ -13172,7 +13191,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
13172
13191
  if (isVerbose) {
13173
13192
  console.info("documentScraper: Converting .".concat(extension, " -> .docx"));
13174
13193
  }
13175
- return [4 /*yield*/, $isFileExisting(cacheFilehandler.filename)];
13194
+ return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
13176
13195
  case 2:
13177
13196
  if (!!(_g.sent())) return [3 /*break*/, 8];
13178
13197
  documentSourceOutdirPathForLibreOffice_1 = join(dirname(cacheFilehandler.filename), 'libreoffice')
@@ -13197,7 +13216,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
13197
13216
  return [4 /*yield*/, rmdir(documentSourceOutdirPathForLibreOffice_1)];
13198
13217
  case 6:
13199
13218
  _g.sent();
13200
- return [4 /*yield*/, $isFileExisting(cacheFilehandler.filename)];
13219
+ return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
13201
13220
  case 7:
13202
13221
  if (!(_g.sent())) {
13203
13222
  throw new UnexpectedError(spaceTrim$1(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 "); }));
@@ -13277,7 +13296,6 @@ var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacy
13277
13296
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
13278
13297
  */
13279
13298
 
13280
- // <- TODO: !!!!!!! Are theese changed to import type { ... } from ... correctly
13281
13299
  /**
13282
13300
  * @@@
13283
13301
  *