@promptbook/legacy-documents 0.72.0-9 → 0.72.0

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 (133) hide show
  1. package/README.md +4 -8
  2. package/esm/index.es.js +169 -153
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +24 -18
  5. package/esm/typings/src/_packages/node.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +18 -12
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  8. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  9. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
  10. package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
  11. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
  12. package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
  14. package/esm/typings/src/config.d.ts +21 -14
  15. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
  16. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
  17. package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
  18. package/esm/typings/src/executables/locateApp.d.ts +33 -0
  19. package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
  20. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
  21. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
  22. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
  23. package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
  24. package/esm/typings/src/execution/Executables.d.ts +18 -0
  25. package/esm/typings/src/execution/ExecutionTools.d.ts +9 -3
  26. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  27. package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
  28. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  29. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
  30. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
  31. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -11
  32. package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -13
  33. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -14
  34. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
  35. package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
  36. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  37. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -2
  38. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -2
  39. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForCli.d.ts +2 -2
  40. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
  41. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +7 -0
  42. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
  43. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  44. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  45. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  46. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  47. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  48. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
  49. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
  50. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  51. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  52. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -5
  53. package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
  54. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
  55. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
  56. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
  57. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  58. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
  59. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +15 -6
  60. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
  61. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +6 -12
  62. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
  63. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +9 -14
  64. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +23 -8
  65. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  66. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +4 -23
  67. package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
  68. package/esm/typings/src/scrapers/_common/Scraper.d.ts +2 -9
  69. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
  70. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +2 -2
  71. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +2 -2
  72. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -2
  73. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +2 -2
  74. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  75. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +2 -2
  76. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  77. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
  78. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +3 -3
  79. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -1
  80. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
  81. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
  82. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -1
  83. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
  84. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +2 -2
  85. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  86. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
  87. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +6 -3
  88. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -1
  89. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
  90. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
  91. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
  92. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  93. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
  94. package/esm/typings/src/types/Arrayable.d.ts +1 -1
  95. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
  96. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
  97. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  98. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
  99. package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
  100. package/esm/typings/src/types/Prompt.d.ts +2 -1
  101. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
  102. package/esm/typings/src/types/typeAliases.d.ts +11 -8
  103. package/esm/typings/src/utils/$Register.d.ts +1 -1
  104. package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
  105. package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
  106. package/esm/typings/src/utils/emojis.d.ts +1 -1
  107. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +4 -2
  108. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
  109. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -0
  110. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
  111. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  112. package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
  113. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  114. package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
  115. package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
  116. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
  117. package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
  118. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
  119. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  120. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  121. package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
  122. package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
  123. package/esm/typings/src/utils/sets/union.d.ts +1 -1
  124. package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
  125. package/package.json +4 -3
  126. package/umd/index.umd.js +169 -153
  127. package/umd/index.umd.js.map +1 -1
  128. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
  129. package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
  130. package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
  131. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
  132. /package/esm/typings/src/{scrapers/website/WebsiteScraper.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
  133. /package/esm/typings/src/{scrapers/website/utils/markdownConverter.test.d.ts → executables/apps/locatePandoc.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -15,7 +15,7 @@ import { unparse, parse } from 'papaparse';
15
15
  /**
16
16
  * The version of the Promptbook library
17
17
  */
18
- var PROMPTBOOK_VERSION = '0.72.0-8';
18
+ var PROMPTBOOK_VERSION = '0.72.0-34';
19
19
  // TODO: [main] !!!! List here all the versions and annotate + put into script
20
20
 
21
21
  /*! *****************************************************************************
@@ -363,18 +363,25 @@ var LOOP_LIMIT = 1000;
363
363
  * @private within the repository - too low-level in comparison with other `MAX_...`
364
364
  */
365
365
  var IMMEDIATE_TIME = 10;
366
+ /**
367
+ * Strategy for caching the intermediate results for knowledge sources
368
+ *
369
+ * @public exported from `@promptbook/core`
370
+ */
371
+ var DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
372
+ // <- TODO: [😡] Change to 'VISIBLE'
366
373
  /**
367
374
  * The maximum number of (LLM) tasks running in parallel
368
375
  *
369
376
  * @public exported from `@promptbook/core`
370
377
  */
371
- var MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
378
+ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
372
379
  /**
373
380
  * The maximum number of attempts to execute LLM task before giving up
374
381
  *
375
382
  * @public exported from `@promptbook/core`
376
383
  */
377
- var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
384
+ var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
378
385
  /**
379
386
  * Where to store the scrape cache
380
387
  *
@@ -382,7 +389,7 @@ var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
382
389
  *
383
390
  * @public exported from `@promptbook/core`
384
391
  */
385
- var SCRAPE_CACHE_DIRNAME = '/.promptbook/scrape-cache';
392
+ var DEFAULT_SCRAPE_CACHE_DIRNAME = '/.promptbook/scrape-cache';
386
393
  /**
387
394
  * Nonce which is used for replacing things in strings
388
395
  *
@@ -434,7 +441,7 @@ var DEFAULT_CSV_SETTINGS = Object.freeze({
434
441
  *
435
442
  * @public exported from `@promptbook/core`
436
443
  */
437
- var IS_VERBOSE = false;
444
+ var DEFAULT_IS_VERBOSE = false;
438
445
  /**
439
446
  * @@@
440
447
  *
@@ -508,22 +515,26 @@ var $isRunningInNode = new Function("\n try {\n return this === global
508
515
  /**
509
516
  * Normalize options for `execCommand` and `execCommands`
510
517
  *
518
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
519
+ *
511
520
  * @private internal utility of `execCommand` and `execCommands`
512
521
  */
513
- function execCommandNormalizeOptions(options) {
522
+ function $execCommandNormalizeOptions(options) {
514
523
  var _a;
515
- var _b, _c, _d;
524
+ var _b, _c, _d, _e;
516
525
  var command;
517
526
  var cwd;
518
527
  var crashOnError;
519
528
  var args = [];
520
529
  var timeout;
530
+ var isVerbose;
521
531
  if (typeof options === 'string') {
522
532
  // TODO: [1] DRY default values
523
533
  command = options;
524
534
  cwd = process.cwd();
525
535
  crashOnError = true;
526
- timeout = Infinity;
536
+ timeout = Infinity; // <- TODO: [⏳]
537
+ isVerbose = DEFAULT_IS_VERBOSE;
527
538
  }
528
539
  else {
529
540
  /*
@@ -539,6 +550,7 @@ function execCommandNormalizeOptions(options) {
539
550
  cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
540
551
  crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
541
552
  timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
553
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
542
554
  }
543
555
  // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
544
556
  var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
@@ -560,16 +572,21 @@ function execCommandNormalizeOptions(options) {
560
572
  if (['ts-node'].includes(humanReadableCommand)) {
561
573
  humanReadableCommand += " ".concat(args[1]);
562
574
  }
563
- return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout };
575
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
576
+ command = "".concat(command, ".cmd");
577
+ }
578
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
564
579
  }
565
580
  // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
566
581
 
567
582
  /**
568
583
  * Run one command in a shell
569
584
  *
585
+ *
570
586
  * Note: There are 2 similar functions in the codebase:
571
587
  * - `$execCommand` which runs a single command
572
588
  * - `$execCommands` which runs multiple commands
589
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
573
590
  *
574
591
  * @public exported from `@promptbook/node`
575
592
  */
@@ -579,7 +596,7 @@ function $execCommand(options) {
579
596
  }
580
597
  return new Promise(function (resolve, reject) {
581
598
  // eslint-disable-next-line prefer-const
582
- var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
599
+ var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
583
600
  if (timeout !== Infinity) {
584
601
  // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
585
602
  forTime(timeout).then(function () {
@@ -592,24 +609,26 @@ function $execCommand(options) {
592
609
  }
593
610
  });
594
611
  }
595
- if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
596
- command = "".concat(command, ".cmd");
612
+ if (isVerbose) {
613
+ console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
597
614
  }
598
- // !!!!!! Verbose mode - to all consoles
599
- console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
600
615
  try {
601
616
  var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
602
- commandProcess.on('message', function (message) {
603
- console.info({ message: message });
604
- });
617
+ if (isVerbose) {
618
+ commandProcess.on('message', function (message) {
619
+ console.info({ message: message });
620
+ });
621
+ }
605
622
  var output_1 = [];
606
623
  commandProcess.stdout.on('data', function (stdout) {
607
624
  output_1.push(stdout.toString());
608
- console.info(stdout.toString());
625
+ if (isVerbose) {
626
+ console.info(stdout.toString());
627
+ }
609
628
  });
610
629
  commandProcess.stderr.on('data', function (stderr) {
611
630
  output_1.push(stderr.toString());
612
- if (stderr.toString().trim()) {
631
+ if (isVerbose && stderr.toString().trim()) {
613
632
  console.warn(stderr.toString());
614
633
  }
615
634
  });
@@ -620,7 +639,9 @@ function $execCommand(options) {
620
639
  "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
621
640
  }
622
641
  else {
623
- console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
642
+ if (isVerbose) {
643
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
644
+ }
624
645
  resolve(spaceTrim(output_1.join('\n')));
625
646
  }
626
647
  }
@@ -639,7 +660,9 @@ function $execCommand(options) {
639
660
  reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
640
661
  }
641
662
  else {
642
- console.warn(error);
663
+ if (isVerbose) {
664
+ console.warn(error);
665
+ }
643
666
  resolve(spaceTrim(output_1.join('\n')));
644
667
  }
645
668
  });
@@ -1150,12 +1173,12 @@ function TODO_USE() {
1150
1173
  */
1151
1174
  function getScraperIntermediateSource(source, options) {
1152
1175
  return __awaiter(this, void 0, void 0, function () {
1153
- var sourceFilename, url, rootDirname, cacheDirname, isCacheCleaned, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
1176
+ var sourceFilename, url, rootDirname, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
1154
1177
  return __generator(this, function (_a) {
1155
1178
  switch (_a.label) {
1156
1179
  case 0:
1157
1180
  sourceFilename = source.filename, url = source.url;
1158
- rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, isCacheCleaned = options.isCacheCleaned, extension = options.extension, isVerbose = options.isVerbose;
1181
+ rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
1159
1182
  hash = SHA256(
1160
1183
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
1161
1184
  hexEncoder.parse(sourceFilename || url || 'untitled'))
@@ -1165,7 +1188,7 @@ function getScraperIntermediateSource(source, options) {
1165
1188
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
1166
1189
  name = pieces.join('-').split('--').join('-');
1167
1190
  // <- TODO: Use MAX_FILENAME_LENGTH
1168
- TODO_USE(rootDirname); // <- TODO: !!!!!!
1191
+ TODO_USE(rootDirname); // <- TODO: [😡]
1169
1192
  cacheFilename = join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
1170
1193
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
1171
1194
  .join('/') +
@@ -1185,7 +1208,7 @@ function getScraperIntermediateSource(source, options) {
1185
1208
  return __generator(this, function (_a) {
1186
1209
  switch (_a.label) {
1187
1210
  case 0:
1188
- if (!isCacheCleaned) return [3 /*break*/, 2];
1211
+ if (!(intermediateFilesStrategy === 'HIDE_AND_CLEAN')) return [3 /*break*/, 2];
1189
1212
  if (isVerbose) {
1190
1213
  console.info('legacyDocumentScraper: Clening cache');
1191
1214
  }
@@ -1209,7 +1232,7 @@ function getScraperIntermediateSource(source, options) {
1209
1232
  /**
1210
1233
  * Note: Not using `FileCacheStorage` for two reasons:
1211
1234
  * 1) Need to store more than serialized JSONs
1212
- * 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: !!!!
1235
+ * 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: [😡]
1213
1236
  * TODO: [🐱‍🐉][🧠] Make some smart crop
1214
1237
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1215
1238
  */
@@ -1274,7 +1297,6 @@ function pipelineJsonToString(pipelineJson) {
1274
1297
  pipelineString += '\n\n';
1275
1298
  pipelineString += description;
1276
1299
  }
1277
- // TODO:> const commands: Array<Command>
1278
1300
  var commands = [];
1279
1301
  if (pipelineUrl) {
1280
1302
  commands.push("PIPELINE URL ".concat(pipelineUrl));
@@ -1330,7 +1352,6 @@ function pipelineJsonToString(pipelineJson) {
1330
1352
  pipelineString += '\n\n';
1331
1353
  pipelineString += description_1;
1332
1354
  }
1333
- // TODO:> const commands: Array<Command>
1334
1355
  var commands_1 = [];
1335
1356
  var contentLanguage = 'text';
1336
1357
  if (templateType === 'PROMPT_TEMPLATE') {
@@ -2215,6 +2236,7 @@ function assertsExecutionSuccessful(executionResult) {
2215
2236
  }
2216
2237
  }
2217
2238
  /**
2239
+ * TODO: [🐚] This function should be removed OR changed OR be completely rewritten
2218
2240
  * TODO: [🧠] Can this return type be better typed than void
2219
2241
  */
2220
2242
 
@@ -2400,8 +2422,7 @@ $deepFreeze({
2400
2422
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2401
2423
  *
2402
2424
  * Note: Internal utility of `joinLlmExecutionTools` but exposed type
2403
- * @public exported from `@promptbook/types`
2404
- * TODO: !!!!!! Export as runtime class not just type
2425
+ * @public exported from `@promptbook/core`
2405
2426
  */
2406
2427
  var MultipleLlmExecutionTools = /** @class */ (function () {
2407
2428
  /**
@@ -2903,7 +2924,7 @@ function preparePersona(personaDescription, tools, options) {
2903
2924
  return __generator(this, function (_d) {
2904
2925
  switch (_d.label) {
2905
2926
  case 0:
2906
- _a = options.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
2927
+ _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
2907
2928
  if (tools === undefined || tools.llm === undefined) {
2908
2929
  throw new MissingToolsError('LLM tools are required for preparing persona');
2909
2930
  }
@@ -3069,7 +3090,7 @@ var $Register = /** @class */ (function () {
3069
3090
  this.storage = globalScope[storageName];
3070
3091
  }
3071
3092
  $Register.prototype.list = function () {
3072
- // <- TODO: ReadonlyDeep<Array<TRegistered>>
3093
+ // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
3073
3094
  return this.storage;
3074
3095
  };
3075
3096
  $Register.prototype.register = function (registered) {
@@ -3121,7 +3142,6 @@ var $scrapersRegister = new $Register('scraper_constructors');
3121
3142
  * TODO: [®] DRY Register logic
3122
3143
  */
3123
3144
 
3124
- // TODO: !!!!!! Maybe delete this function
3125
3145
  /**
3126
3146
  * Creates a message with all registered scrapers
3127
3147
  *
@@ -3229,7 +3249,6 @@ function $registeredScrapersMessage() {
3229
3249
  * @private within the repository
3230
3250
  */
3231
3251
  function sourceContentToName(sourceContent) {
3232
- // TODO: !!!!!! Better name for source than gibberish hash
3233
3252
  var hash = SHA256(hexEncoder.parse(JSON.stringify(sourceContent)))
3234
3253
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
3235
3254
  .toString( /* hex */)
@@ -3257,20 +3276,20 @@ function extensionToMimeType(value) {
3257
3276
  /**
3258
3277
  * @@@
3259
3278
  *
3260
- * @private for scraper utilities
3279
+ * @public exported from `@promptbook/core`
3261
3280
  */
3262
3281
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3263
3282
  var _a;
3264
3283
  return __awaiter(this, void 0, void 0, function () {
3265
3284
  var sourceContent, name, _b, _c, rootDirname, _d,
3266
3285
  // <- TODO: process.cwd() if running in Node.js
3267
- isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType_1;
3286
+ isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3268
3287
  return __generator(this, function (_e) {
3269
3288
  switch (_e.label) {
3270
3289
  case 0:
3271
3290
  sourceContent = knowledgeSource.sourceContent;
3272
3291
  name = knowledgeSource.name;
3273
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d;
3292
+ _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d;
3274
3293
  TODO_USE(isVerbose);
3275
3294
  if (!name) {
3276
3295
  name = sourceContentToName(sourceContent);
@@ -3286,19 +3305,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3286
3305
  filename: null,
3287
3306
  url: url,
3288
3307
  mimeType: mimeType,
3289
- asBlob: function () {
3290
- return __awaiter(this, void 0, void 0, function () {
3291
- var content;
3292
- return __generator(this, function (_a) {
3293
- switch (_a.label) {
3294
- case 0: return [4 /*yield*/, response_1.blob()];
3295
- case 1:
3296
- content = _a.sent();
3297
- return [2 /*return*/, content];
3298
- }
3299
- });
3300
- });
3301
- },
3308
+ /*
3309
+ TODO: [🥽]
3310
+ > async asBlob() {
3311
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
3312
+ > const content = await response.blob();
3313
+ > return content;
3314
+ > },
3315
+ */
3302
3316
  asJson: function () {
3303
3317
  return __awaiter(this, void 0, void 0, function () {
3304
3318
  var content;
@@ -3338,34 +3352,31 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3338
3352
  }
3339
3353
  filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
3340
3354
  fileExtension = getFileExtension(filename_1);
3341
- mimeType_1 = extensionToMimeType(fileExtension || '');
3355
+ mimeType = extensionToMimeType(fileExtension || '');
3342
3356
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3343
3357
  case 3:
3344
3358
  if (!(_e.sent())) {
3345
3359
  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 "); }));
3346
3360
  }
3347
- // TODO: !!!!!! Test security file - file is scoped to the project (maybe do this in `filesystemTools`)
3361
+ // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3348
3362
  return [2 /*return*/, {
3349
3363
  source: name,
3350
3364
  filename: filename_1,
3351
3365
  url: null,
3352
- mimeType: mimeType_1,
3353
- asBlob: function () {
3354
- return __awaiter(this, void 0, void 0, function () {
3355
- var content;
3356
- return __generator(this, function (_a) {
3357
- switch (_a.label) {
3358
- case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
3359
- case 1:
3360
- content = _a.sent();
3361
- return [2 /*return*/, new Blob([
3362
- content,
3363
- // <- TODO: !!!!!! Maybe not working
3364
- ], { type: mimeType_1 })];
3365
- }
3366
- });
3367
- });
3368
- },
3366
+ mimeType: mimeType,
3367
+ /*
3368
+ TODO: [🥽]
3369
+ > async asBlob() {
3370
+ > const content = await tools.fs!.readFile(filename);
3371
+ > return new Blob(
3372
+ > [
3373
+ > content,
3374
+ > // <- TODO: [🥽] This is NOT tested, test it
3375
+ > ],
3376
+ > { type: mimeType },
3377
+ > );
3378
+ > },
3379
+ */
3369
3380
  asJson: function () {
3370
3381
  return __awaiter(this, void 0, void 0, function () {
3371
3382
  var _a, _b;
@@ -3401,9 +3412,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3401
3412
  asJson: function () {
3402
3413
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
3403
3414
  },
3404
- asBlob: function () {
3405
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
3406
- },
3415
+ /*
3416
+ TODO: [🥽]
3417
+ > asBlob() {
3418
+ > throw new UnexpectedError(
3419
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
3420
+ > );
3421
+ > },
3422
+ */
3407
3423
  }];
3408
3424
  }
3409
3425
  });
@@ -3423,7 +3439,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
3423
3439
  return __generator(this, function (_c) {
3424
3440
  switch (_c.label) {
3425
3441
  case 0:
3426
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, rootDirname = options.rootDirname, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
3442
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, rootDirname = options.rootDirname, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
3427
3443
  knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3428
3444
  return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource, index) { return __awaiter(_this, void 0, void 0, function () {
3429
3445
  var partialPieces, sourceHandler, _a, _b, scraper, partialPiecesUnchecked, e_1_1, pieces;
@@ -3452,7 +3468,8 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
3452
3468
  case 4:
3453
3469
  partialPiecesUnchecked = _d.sent();
3454
3470
  if (partialPiecesUnchecked !== null) {
3455
- partialPieces = partialPiecesUnchecked;
3471
+ partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
3472
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3456
3473
  return [3 /*break*/, 6];
3457
3474
  }
3458
3475
  _d.label = 5;
@@ -3500,7 +3517,7 @@ TODO: [🧊] This is how it can look in future
3500
3517
  > /**
3501
3518
  > * Unprepared knowledge
3502
3519
  > * /
3503
- > readonly knowledgeSources: Array<KnowledgeSourceJson>;
3520
+ > readonly knowledgeSources: ReadonlyArray<KnowledgeSourceJson>;
3504
3521
  > };
3505
3522
  >
3506
3523
  > export async function prepareKnowledgePieces(
@@ -3558,7 +3575,7 @@ function prepareTemplates(pipeline, tools, options) {
3558
3575
  return __generator(this, function (_b) {
3559
3576
  switch (_b.label) {
3560
3577
  case 0:
3561
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3578
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
3562
3579
  templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3563
3580
  // TODO: [main] !!!!! Apply samples to each template (if missing and is for the template defined)
3564
3581
  TODO_USE(parameters);
@@ -3620,7 +3637,7 @@ function preparePipeline(pipeline, tools, options) {
3620
3637
  if (isPipelinePrepared(pipeline)) {
3621
3638
  return [2 /*return*/, pipeline];
3622
3639
  }
3623
- rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
3640
+ rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
3624
3641
  parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3625
3642
  if (tools === undefined || tools.llm === undefined) {
3626
3643
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
@@ -3678,7 +3695,9 @@ function preparePipeline(pipeline, tools, options) {
3678
3695
  // ----- /Templates preparation -----
3679
3696
  // Note: Count total usage
3680
3697
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
3681
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: templatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
3698
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: __spreadArray([], __read(templatesPrepared), false),
3699
+ // <- TODO: [🪓] Here should be no need for spreading new array, just ` templates: templatesPrepared`
3700
+ knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
3682
3701
  }
3683
3702
  });
3684
3703
  });
@@ -4649,12 +4668,11 @@ function checkExpectations(expectations, value) {
4649
4668
  */
4650
4669
  function executeAttempts(options) {
4651
4670
  return __awaiter(this, void 0, void 0, function () {
4652
- var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
4671
+ var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
4653
4672
  return __generator(this, function (_a) {
4654
4673
  switch (_a.label) {
4655
4674
  case 0:
4656
- jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
4657
- maxExecutionAttempts = settings.maxExecutionAttempts;
4675
+ jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts;
4658
4676
  $ongoingTemplateResult = {
4659
4677
  $result: null,
4660
4678
  $resultString: null,
@@ -5020,12 +5038,12 @@ function executeAttempts(options) {
5020
5038
  */
5021
5039
  function executeFormatSubvalues(options) {
5022
5040
  return __awaiter(this, void 0, void 0, function () {
5023
- var template, jokerParameterNames, parameters, priority, pipelineIdentification, settings, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
5041
+ var template, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
5024
5042
  var _this = this;
5025
5043
  return __generator(this, function (_a) {
5026
5044
  switch (_a.label) {
5027
5045
  case 0:
5028
- template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
5046
+ template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
5029
5047
  if (template.foreach === undefined) {
5030
5048
  return [2 /*return*/, /* not await */ executeAttempts(options)];
5031
5049
  }
@@ -5055,7 +5073,7 @@ function executeFormatSubvalues(options) {
5055
5073
  .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
5056
5074
  }
5057
5075
  if (formatDefinition.formatName === 'CSV') {
5058
- formatSettings = settings.csvSettings;
5076
+ formatSettings = csvSettings;
5059
5077
  // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5060
5078
  }
5061
5079
  return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
@@ -5208,13 +5226,12 @@ function getReservedParametersForTemplate(options) {
5208
5226
  */
5209
5227
  function executeTemplate(options) {
5210
5228
  return __awaiter(this, void 0, void 0, function () {
5211
- var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
5212
- var e_1, _f, _g;
5213
- return __generator(this, function (_h) {
5214
- switch (_h.label) {
5229
+ var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, _a, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _b, _c, _d, definedParameterNames, parameters, _loop_1, _e, _f, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
5230
+ var e_1, _g, _h;
5231
+ return __generator(this, function (_j) {
5232
+ switch (_j.label) {
5215
5233
  case 0:
5216
- currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
5217
- maxExecutionAttempts = settings.maxExecutionAttempts;
5234
+ currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a;
5218
5235
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
5219
5236
  title = currentTemplate.title;
5220
5237
  priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
@@ -5229,7 +5246,7 @@ function executeTemplate(options) {
5229
5246
  // <- [🍸]
5230
5247
  })];
5231
5248
  case 1:
5232
- _h.sent();
5249
+ _j.sent();
5233
5250
  usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
5234
5251
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
5235
5252
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
@@ -5240,15 +5257,15 @@ function executeTemplate(options) {
5240
5257
  .map(function (name) { return "{".concat(name, "}"); })
5241
5258
  .join(', '), "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
5242
5259
  }
5243
- _b = (_a = Object).freeze;
5244
- _c = [{}];
5260
+ _c = (_b = Object).freeze;
5261
+ _d = [{}];
5245
5262
  return [4 /*yield*/, getReservedParametersForTemplate({
5246
5263
  preparedPipeline: preparedPipeline,
5247
5264
  template: currentTemplate,
5248
5265
  pipelineIdentification: pipelineIdentification,
5249
5266
  })];
5250
5267
  case 2:
5251
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
5268
+ definedParameters = _c.apply(_b, [__assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_j.sent())])), parametersToPass])]);
5252
5269
  definedParameterNames = new Set(Object.keys(definedParameters));
5253
5270
  parameters = {};
5254
5271
  _loop_1 = function (parameterName) {
@@ -5268,15 +5285,15 @@ function executeTemplate(options) {
5268
5285
  try {
5269
5286
  // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
5270
5287
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5271
- for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
5272
- parameterName = _e.value;
5288
+ for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
5289
+ parameterName = _f.value;
5273
5290
  _loop_1(parameterName);
5274
5291
  }
5275
5292
  }
5276
5293
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
5277
5294
  finally {
5278
5295
  try {
5279
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
5296
+ if (_f && !_f.done && (_g = _e.return)) _g.call(_e);
5280
5297
  }
5281
5298
  finally { if (e_1) throw e_1.error; }
5282
5299
  }
@@ -5296,12 +5313,11 @@ function executeTemplate(options) {
5296
5313
  template: currentTemplate,
5297
5314
  preparedPipeline: preparedPipeline,
5298
5315
  tools: tools,
5299
- settings: settings,
5300
5316
  $executionReport: $executionReport,
5301
5317
  pipelineIdentification: pipelineIdentification,
5302
5318
  })];
5303
5319
  case 3:
5304
- resultString = _h.sent();
5320
+ resultString = _j.sent();
5305
5321
  return [4 /*yield*/, onProgress({
5306
5322
  name: name,
5307
5323
  title: title,
@@ -5313,12 +5329,12 @@ function executeTemplate(options) {
5313
5329
  // <- [🍸]
5314
5330
  })];
5315
5331
  case 4:
5316
- _h.sent();
5317
- return [2 /*return*/, Object.freeze((_g = {},
5318
- _g[currentTemplate.resultingParameterName] =
5332
+ _j.sent();
5333
+ return [2 /*return*/, Object.freeze((_h = {},
5334
+ _h[currentTemplate.resultingParameterName] =
5319
5335
  // <- Note: [👩‍👩‍👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
5320
5336
  resultString,
5321
- _g))];
5337
+ _h))];
5322
5338
  }
5323
5339
  });
5324
5340
  });
@@ -5377,13 +5393,12 @@ function filterJustOutputParameters(options) {
5377
5393
  */
5378
5394
  function executePipeline(options) {
5379
5395
  return __awaiter(this, void 0, void 0, function () {
5380
- var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, settings, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
5396
+ var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
5381
5397
  var e_1, _f, e_2, _g;
5382
5398
  return __generator(this, function (_h) {
5383
5399
  switch (_h.label) {
5384
5400
  case 0:
5385
- inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
5386
- maxParallelCount = settings.maxParallelCount, rootDirname = settings.rootDirname, _a = settings.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
5401
+ inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, maxParallelCount = options.maxParallelCount, rootDirname = options.rootDirname, _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
5387
5402
  preparedPipeline = options.preparedPipeline;
5388
5403
  if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
5389
5404
  return [4 /*yield*/, preparePipeline(pipeline, tools, {
@@ -5568,12 +5583,7 @@ function executePipeline(options) {
5568
5583
  return [3 /*break*/, 4];
5569
5584
  case 3:
5570
5585
  unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
5571
- work_1 = executeTemplate({
5572
- currentTemplate: currentTemplate,
5573
- preparedPipeline: preparedPipeline,
5574
- parametersToPass: parametersToPass,
5575
- tools: tools,
5576
- onProgress: function (progress) {
5586
+ work_1 = executeTemplate(__assign(__assign({}, options), { currentTemplate: currentTemplate, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
5577
5587
  if (isReturned) {
5578
5588
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
5579
5589
  .split('\n')
@@ -5583,11 +5593,7 @@ function executePipeline(options) {
5583
5593
  if (onProgress) {
5584
5594
  onProgress(progress);
5585
5595
  }
5586
- },
5587
- settings: settings,
5588
- $executionReport: executionReport,
5589
- pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
5590
- })
5596
+ }, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }) }))
5591
5597
  .then(function (newParametersToPass) {
5592
5598
  parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
5593
5599
  resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
@@ -5691,8 +5697,7 @@ function executePipeline(options) {
5691
5697
  */
5692
5698
  function createPipelineExecutor(options) {
5693
5699
  var _this = this;
5694
- var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
5695
- var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.csvSettings, csvSettings = _d === void 0 ? DEFAULT_CSV_SETTINGS : _d, _e = settings.isVerbose, isVerbose = _e === void 0 ? IS_VERBOSE : _e, _f = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _f === void 0 ? false : _f, _g = settings.rootDirname, rootDirname = _g === void 0 ? null : _g;
5700
+ var pipeline = options.pipeline, tools = options.tools, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a, _b = options.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = options.csvSettings, csvSettings = _c === void 0 ? DEFAULT_CSV_SETTINGS : _c, _d = options.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d, _e = options.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e, _f = options.rootDirname, rootDirname = _f === void 0 ? null : _f;
5696
5701
  validatePipeline(pipeline);
5697
5702
  var pipelineIdentification = (function () {
5698
5703
  // Note: This is a 😐 implementation of [🚞]
@@ -5726,14 +5731,12 @@ function createPipelineExecutor(options) {
5726
5731
  tools: tools,
5727
5732
  onProgress: onProgress,
5728
5733
  pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
5729
- settings: {
5730
- maxExecutionAttempts: maxExecutionAttempts,
5731
- maxParallelCount: maxParallelCount,
5732
- csvSettings: csvSettings,
5733
- isVerbose: isVerbose,
5734
- isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5735
- rootDirname: rootDirname,
5736
- },
5734
+ maxExecutionAttempts: maxExecutionAttempts,
5735
+ maxParallelCount: maxParallelCount,
5736
+ csvSettings: csvSettings,
5737
+ isVerbose: isVerbose,
5738
+ isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5739
+ rootDirname: rootDirname,
5737
5740
  })];
5738
5741
  });
5739
5742
  }); };
@@ -5755,7 +5758,7 @@ var markdownScraperMetadata = $deepFreeze({
5755
5758
  mimeTypes: ['text/markdown', 'text/plain'],
5756
5759
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5757
5760
  isAvilableInBrowser: true,
5758
- requiredExecutables: ['!!!!!!'],
5761
+ requiredExecutables: [],
5759
5762
  }); /* <- TODO: [🤛] */
5760
5763
  /**
5761
5764
  * Registration of known scraper metadata
@@ -5799,7 +5802,7 @@ var MarkdownScraper = /** @class */ (function () {
5799
5802
  return __generator(this, function (_k) {
5800
5803
  switch (_k.label) {
5801
5804
  case 0:
5802
- _a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ? MAX_PARALLEL_COUNT : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? IS_VERBOSE : _c;
5805
+ _a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
5803
5806
  llm = this.tools.llm;
5804
5807
  if (llm === undefined) {
5805
5808
  throw new MissingToolsError('LLM tools are required for scraping external files');
@@ -5898,7 +5901,8 @@ var MarkdownScraper = /** @class */ (function () {
5898
5901
  embeddingResult = _c.sent();
5899
5902
  index.push({
5900
5903
  modelName: embeddingResult.modelName,
5901
- position: embeddingResult.content,
5904
+ position: __spreadArray([], __read(embeddingResult.content), false),
5905
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `position: embeddingResult.content`
5902
5906
  });
5903
5907
  _c.label = 6;
5904
5908
  case 6: return [3 /*break*/, 8];
@@ -5949,7 +5953,7 @@ var documentScraperMetadata = $deepFreeze({
5949
5953
  mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
5950
5954
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
5951
5955
  isAvilableInBrowser: false,
5952
- requiredExecutables: ['!!!!!!'],
5956
+ requiredExecutables: ['Pandoc'],
5953
5957
  }); /* <- TODO: [🤛] */
5954
5958
  /**
5955
5959
  * Registration of known scraper metadata
@@ -5989,12 +5993,13 @@ var DocumentScraper = /** @class */ (function () {
5989
5993
  * Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
5990
5994
  */
5991
5995
  DocumentScraper.prototype.$convert = function (source) {
5996
+ var _a;
5992
5997
  return __awaiter(this, void 0, void 0, function () {
5993
- var _a, _b, externalProgramsPaths, _c, rootDirname, _d, cacheDirname, _e, isCacheCleaned, _f, isVerbose, extension, cacheFilehandler, command_1;
5998
+ var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, command_1;
5994
5999
  return __generator(this, function (_g) {
5995
6000
  switch (_g.label) {
5996
6001
  case 0:
5997
- _a = this.options, _b = _a.externalProgramsPaths, externalProgramsPaths = _b === void 0 ? {} : _b, _c = _a.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _a.cacheDirname, cacheDirname = _d === void 0 ? SCRAPE_CACHE_DIRNAME : _d, _e = _a.isCacheCleaned, isCacheCleaned = _e === void 0 ? false : _e, _f = _a.isVerbose, isVerbose = _f === void 0 ? IS_VERBOSE : _f;
6002
+ _b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
5998
6003
  if (!$isRunningInNode()) {
5999
6004
  throw new KnowledgeScrapeError('Scraping .docx files is only supported in Node environment');
6000
6005
  }
@@ -6002,7 +6007,7 @@ var DocumentScraper = /** @class */ (function () {
6002
6007
  throw new EnvironmentMismatchError('Can not scrape documents without filesystem tools');
6003
6008
  // <- TODO: [🧠] What is the best error type here`
6004
6009
  }
6005
- if (externalProgramsPaths.pandocPath === undefined) {
6010
+ if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.pandocPath) === undefined) {
6006
6011
  throw new MissingToolsError('Pandoc is required for scraping .docx files');
6007
6012
  }
6008
6013
  if (source.filename === null) {
@@ -6013,7 +6018,7 @@ var DocumentScraper = /** @class */ (function () {
6013
6018
  return [4 /*yield*/, getScraperIntermediateSource(source, {
6014
6019
  rootDirname: rootDirname,
6015
6020
  cacheDirname: cacheDirname,
6016
- isCacheCleaned: isCacheCleaned,
6021
+ intermediateFilesStrategy: intermediateFilesStrategy,
6017
6022
  extension: 'md',
6018
6023
  isVerbose: isVerbose,
6019
6024
  })];
@@ -6022,11 +6027,9 @@ var DocumentScraper = /** @class */ (function () {
6022
6027
  return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
6023
6028
  case 2:
6024
6029
  if (!!(_g.sent())) return [3 /*break*/, 5];
6025
- command_1 = "\"".concat(externalProgramsPaths.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
6026
- // TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
6030
+ command_1 = "\"".concat(this.tools.executables.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
6027
6031
  return [4 /*yield*/, $execCommand(command_1)];
6028
6032
  case 3:
6029
- // TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook
6030
6033
  _g.sent();
6031
6034
  return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
6032
6035
  case 4:
@@ -6071,9 +6074,14 @@ var DocumentScraper = /** @class */ (function () {
6071
6074
  asJson: function () {
6072
6075
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
6073
6076
  },
6074
- asBlob: function () {
6075
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
6076
- },
6077
+ /*
6078
+ TODO: [🥽]
6079
+ > asBlob() {
6080
+ > throw new UnexpectedError(
6081
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
6082
+ > );
6083
+ > },
6084
+ */
6077
6085
  };
6078
6086
  knowledge = this.markdownScraper.scrape(markdownSource);
6079
6087
  return [4 /*yield*/, cacheFilehandler.destroy()];
@@ -6105,7 +6113,11 @@ var legacyDocumentScraperMetadata = $deepFreeze({
6105
6113
  mimeTypes: ['application/msword', 'text/rtf'],
6106
6114
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
6107
6115
  isAvilableInBrowser: false,
6108
- requiredExecutables: ['!!!!!!'],
6116
+ requiredExecutables: [
6117
+ 'Pandoc',
6118
+ 'LibreOffice',
6119
+ // <- TODO: [🧠] Should be 'LibreOffice' here, its dependency of dependency
6120
+ ],
6109
6121
  }); /* <- TODO: [🤛] */
6110
6122
  /**
6111
6123
  * Registration of known scraper metadata
@@ -6118,7 +6130,7 @@ var legacyDocumentScraperMetadata = $deepFreeze({
6118
6130
  $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
6119
6131
 
6120
6132
  /**
6121
- * Scraper for .docx files
6133
+ * Scraper for old document files (like .doc and .rtf)
6122
6134
  *
6123
6135
  * @see `documentationUrl` for more details
6124
6136
  * @public exported from `@promptbook/legacy-documents`
@@ -6145,12 +6157,13 @@ var LegacyDocumentScraper = /** @class */ (function () {
6145
6157
  * Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
6146
6158
  */
6147
6159
  LegacyDocumentScraper.prototype.$convert = function (source) {
6160
+ var _a;
6148
6161
  return __awaiter(this, void 0, void 0, function () {
6149
- var _a, _b, externalProgramsPaths, _c, rootDirname, _d, cacheDirname, _e, isCacheCleaned, _f, isVerbose, extension, cacheFilehandler, documentSourceOutdirPathForLibreOffice_1, command_1, files_1, file;
6162
+ var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, documentSourceOutdirPathForLibreOffice_1, command_1, files_1, file;
6150
6163
  return __generator(this, function (_g) {
6151
6164
  switch (_g.label) {
6152
6165
  case 0:
6153
- _a = this.options, _b = _a.externalProgramsPaths, externalProgramsPaths = _b === void 0 ? {} : _b, _c = _a.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _a.cacheDirname, cacheDirname = _d === void 0 ? SCRAPE_CACHE_DIRNAME : _d, _e = _a.isCacheCleaned, isCacheCleaned = _e === void 0 ? false : _e, _f = _a.isVerbose, isVerbose = _f === void 0 ? IS_VERBOSE : _f;
6166
+ _b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
6154
6167
  if (!$isRunningInNode()) {
6155
6168
  throw new KnowledgeScrapeError('Scraping .doc files is only supported in Node environment');
6156
6169
  }
@@ -6158,7 +6171,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
6158
6171
  throw new EnvironmentMismatchError('Can not scrape (legacy) documents without filesystem tools');
6159
6172
  // <- TODO: [🧠] What is the best error type here`
6160
6173
  }
6161
- if (externalProgramsPaths.libreOfficePath === undefined) {
6174
+ if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.libreOfficePath) === undefined) {
6162
6175
  throw new MissingToolsError('LibreOffice is required for scraping .doc and .rtf files');
6163
6176
  }
6164
6177
  if (source.filename === null) {
@@ -6169,7 +6182,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
6169
6182
  return [4 /*yield*/, getScraperIntermediateSource(source, {
6170
6183
  rootDirname: rootDirname,
6171
6184
  cacheDirname: cacheDirname,
6172
- isCacheCleaned: isCacheCleaned,
6185
+ intermediateFilesStrategy: intermediateFilesStrategy,
6173
6186
  extension: 'docx',
6174
6187
  isVerbose: isVerbose,
6175
6188
  })];
@@ -6184,11 +6197,9 @@ var LegacyDocumentScraper = /** @class */ (function () {
6184
6197
  documentSourceOutdirPathForLibreOffice_1 = join(dirname(cacheFilehandler.filename), 'libreoffice')
6185
6198
  .split('\\')
6186
6199
  .join('/');
6187
- command_1 = "\"".concat(externalProgramsPaths.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
6188
- // TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook - this should trigger build polution error
6200
+ command_1 = "\"".concat(this.tools.executables.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
6189
6201
  return [4 /*yield*/, $execCommand(command_1)];
6190
6202
  case 3:
6191
- // TODO: !!!!!! [🕊] Make execCommand standard (?node-)util of the promptbook - this should trigger build polution error
6192
6203
  _g.sent();
6193
6204
  return [4 /*yield*/, readdir(documentSourceOutdirPathForLibreOffice_1)];
6194
6205
  case 4:
@@ -6236,9 +6247,14 @@ var LegacyDocumentScraper = /** @class */ (function () {
6236
6247
  asJson: function () {
6237
6248
  throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asJson`');
6238
6249
  },
6239
- asBlob: function () {
6240
- throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asBlob`');
6241
- },
6250
+ /*
6251
+ TODO: [🥽]
6252
+ > asBlob() {
6253
+ > throw new UnexpectedError(
6254
+ > 'Did not expect that `documentScraper` would need to get the content `asBlob`',
6255
+ > );
6256
+ > },
6257
+ */
6242
6258
  };
6243
6259
  knowledge = this.documentScraper.scrape(markdownSource);
6244
6260
  return [4 /*yield*/, cacheFilehandler.destroy()];