@promptbook/node 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.
- package/README.md +4 -8
- package/esm/index.es.js +466 -162
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +24 -18
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -12
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
- package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
- package/esm/typings/src/config.d.ts +21 -14
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
- package/esm/typings/src/executables/locateApp.d.ts +33 -0
- package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
- package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/esm/typings/src/execution/Executables.d.ts +18 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +9 -3
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -11
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -13
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -14
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
- package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -2
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForCli.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -5
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +15 -6
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +6 -12
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +9 -14
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +23 -8
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +4 -23
- package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +2 -9
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +2 -2
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +3 -3
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +2 -2
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +6 -3
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
- package/esm/typings/src/types/Arrayable.d.ts +1 -1
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/Prompt.d.ts +2 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +11 -8
- package/esm/typings/src/utils/$Register.d.ts +1 -1
- package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
- package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
- package/esm/typings/src/utils/emojis.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +4 -2
- package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -0
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
- package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
- package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
- package/esm/typings/src/utils/sets/union.d.ts +1 -1
- package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
- package/package.json +4 -3
- package/umd/index.umd.js +467 -163
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
- package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
- package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
- /package/esm/typings/src/{scrapers/website/WebsiteScraper.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
- /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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
|
-
import { stat, access, constants, readFile,
|
|
2
|
+
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink } from 'fs/promises';
|
|
3
3
|
import { join, basename, dirname } from 'path';
|
|
4
4
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
@@ -9,15 +9,16 @@ import { unparse, parse } from 'papaparse';
|
|
|
9
9
|
import { SHA256 } from 'crypto-js';
|
|
10
10
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
11
11
|
import { lookup } from 'mime-types';
|
|
12
|
+
import { exec as exec$2, spawn } from 'child_process';
|
|
13
|
+
import { promisify } from 'util';
|
|
12
14
|
import * as dotenv from 'dotenv';
|
|
13
15
|
import sha256 from 'crypto-js/sha256';
|
|
14
|
-
import { spawn } from 'child_process';
|
|
15
16
|
|
|
16
17
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
17
18
|
/**
|
|
18
19
|
* The version of the Promptbook library
|
|
19
20
|
*/
|
|
20
|
-
var PROMPTBOOK_VERSION = '0.72.0-
|
|
21
|
+
var PROMPTBOOK_VERSION = '0.72.0-34';
|
|
21
22
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
22
23
|
|
|
23
24
|
/*! *****************************************************************************
|
|
@@ -366,29 +367,30 @@ var LOOP_LIMIT = 1000;
|
|
|
366
367
|
*/
|
|
367
368
|
var IMMEDIATE_TIME = 10;
|
|
368
369
|
/**
|
|
369
|
-
* The maximum
|
|
370
|
+
* The maximum length of the (generated) filename
|
|
370
371
|
*
|
|
371
372
|
* @public exported from `@promptbook/core`
|
|
372
373
|
*/
|
|
373
|
-
var
|
|
374
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
375
|
+
// <- TODO: [😡] Change to 'VISIBLE'
|
|
374
376
|
/**
|
|
375
|
-
* The maximum number of
|
|
377
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
376
378
|
*
|
|
377
379
|
* @public exported from `@promptbook/core`
|
|
378
380
|
*/
|
|
379
|
-
var
|
|
381
|
+
var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
380
382
|
/**
|
|
381
|
-
* The maximum
|
|
383
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
382
384
|
*
|
|
383
385
|
* @public exported from `@promptbook/core`
|
|
384
386
|
*/
|
|
385
|
-
var
|
|
387
|
+
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
386
388
|
/**
|
|
387
389
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
388
390
|
*
|
|
389
391
|
* @public exported from `@promptbook/core`
|
|
390
392
|
*/
|
|
391
|
-
var
|
|
393
|
+
var DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
392
394
|
/**
|
|
393
395
|
* Nonce which is used for replacing things in strings
|
|
394
396
|
*
|
|
@@ -440,13 +442,13 @@ var DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
440
442
|
*
|
|
441
443
|
* @public exported from `@promptbook/core`
|
|
442
444
|
*/
|
|
443
|
-
var
|
|
445
|
+
var DEFAULT_IS_VERBOSE = false;
|
|
444
446
|
/**
|
|
445
447
|
* @@@
|
|
446
448
|
*
|
|
447
449
|
* @public exported from `@promptbook/core`
|
|
448
450
|
*/
|
|
449
|
-
var
|
|
451
|
+
var DEFAULT_IS_AUTO_INSTALLED = false;
|
|
450
452
|
/**
|
|
451
453
|
* @@@
|
|
452
454
|
*
|
|
@@ -518,7 +520,6 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
518
520
|
pipelineString += '\n\n';
|
|
519
521
|
pipelineString += description;
|
|
520
522
|
}
|
|
521
|
-
// TODO:> const commands: Array<Command>
|
|
522
523
|
var commands = [];
|
|
523
524
|
if (pipelineUrl) {
|
|
524
525
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
@@ -574,7 +575,6 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
574
575
|
pipelineString += '\n\n';
|
|
575
576
|
pipelineString += description_1;
|
|
576
577
|
}
|
|
577
|
-
// TODO:> const commands: Array<Command>
|
|
578
578
|
var commands_1 = [];
|
|
579
579
|
var contentLanguage = 'text';
|
|
580
580
|
if (templateType === 'PROMPT_TEMPLATE') {
|
|
@@ -873,8 +873,7 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
873
873
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
874
874
|
*
|
|
875
875
|
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
876
|
-
* @public exported from `@promptbook/
|
|
877
|
-
* TODO: !!!!!! Export as runtime class not just type
|
|
876
|
+
* @public exported from `@promptbook/core`
|
|
878
877
|
*/
|
|
879
878
|
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
880
879
|
/**
|
|
@@ -2126,6 +2125,7 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2126
2125
|
}
|
|
2127
2126
|
}
|
|
2128
2127
|
/**
|
|
2128
|
+
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2129
2129
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2130
2130
|
*/
|
|
2131
2131
|
|
|
@@ -3432,12 +3432,11 @@ function checkExpectations(expectations, value) {
|
|
|
3432
3432
|
*/
|
|
3433
3433
|
function executeAttempts(options) {
|
|
3434
3434
|
return __awaiter(this, void 0, void 0, function () {
|
|
3435
|
-
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools,
|
|
3435
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
|
|
3436
3436
|
return __generator(this, function (_a) {
|
|
3437
3437
|
switch (_a.label) {
|
|
3438
3438
|
case 0:
|
|
3439
|
-
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools,
|
|
3440
|
-
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3439
|
+
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;
|
|
3441
3440
|
$ongoingTemplateResult = {
|
|
3442
3441
|
$result: null,
|
|
3443
3442
|
$resultString: null,
|
|
@@ -3803,12 +3802,12 @@ function executeAttempts(options) {
|
|
|
3803
3802
|
*/
|
|
3804
3803
|
function executeFormatSubvalues(options) {
|
|
3805
3804
|
return __awaiter(this, void 0, void 0, function () {
|
|
3806
|
-
var template, jokerParameterNames, parameters, priority,
|
|
3805
|
+
var template, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
3807
3806
|
var _this = this;
|
|
3808
3807
|
return __generator(this, function (_a) {
|
|
3809
3808
|
switch (_a.label) {
|
|
3810
3809
|
case 0:
|
|
3811
|
-
template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority,
|
|
3810
|
+
template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
|
|
3812
3811
|
if (template.foreach === undefined) {
|
|
3813
3812
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
3814
3813
|
}
|
|
@@ -3838,7 +3837,7 @@ function executeFormatSubvalues(options) {
|
|
|
3838
3837
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3839
3838
|
}
|
|
3840
3839
|
if (formatDefinition.formatName === 'CSV') {
|
|
3841
|
-
formatSettings =
|
|
3840
|
+
formatSettings = csvSettings;
|
|
3842
3841
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3843
3842
|
}
|
|
3844
3843
|
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -3991,13 +3990,12 @@ function getReservedParametersForTemplate(options) {
|
|
|
3991
3990
|
*/
|
|
3992
3991
|
function executeTemplate(options) {
|
|
3993
3992
|
return __awaiter(this, void 0, void 0, function () {
|
|
3994
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress,
|
|
3995
|
-
var e_1,
|
|
3996
|
-
return __generator(this, function (
|
|
3997
|
-
switch (
|
|
3993
|
+
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;
|
|
3994
|
+
var e_1, _g, _h;
|
|
3995
|
+
return __generator(this, function (_j) {
|
|
3996
|
+
switch (_j.label) {
|
|
3998
3997
|
case 0:
|
|
3999
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress,
|
|
4000
|
-
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3998
|
+
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;
|
|
4001
3999
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
4002
4000
|
title = currentTemplate.title;
|
|
4003
4001
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -4012,7 +4010,7 @@ function executeTemplate(options) {
|
|
|
4012
4010
|
// <- [🍸]
|
|
4013
4011
|
})];
|
|
4014
4012
|
case 1:
|
|
4015
|
-
|
|
4013
|
+
_j.sent();
|
|
4016
4014
|
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
4017
4015
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
4018
4016
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -4023,15 +4021,15 @@ function executeTemplate(options) {
|
|
|
4023
4021
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
4024
4022
|
.join(', '), "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4025
4023
|
}
|
|
4026
|
-
|
|
4027
|
-
|
|
4024
|
+
_c = (_b = Object).freeze;
|
|
4025
|
+
_d = [{}];
|
|
4028
4026
|
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
4029
4027
|
preparedPipeline: preparedPipeline,
|
|
4030
4028
|
template: currentTemplate,
|
|
4031
4029
|
pipelineIdentification: pipelineIdentification,
|
|
4032
4030
|
})];
|
|
4033
4031
|
case 2:
|
|
4034
|
-
definedParameters =
|
|
4032
|
+
definedParameters = _c.apply(_b, [__assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_j.sent())])), parametersToPass])]);
|
|
4035
4033
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
4036
4034
|
parameters = {};
|
|
4037
4035
|
_loop_1 = function (parameterName) {
|
|
@@ -4051,15 +4049,15 @@ function executeTemplate(options) {
|
|
|
4051
4049
|
try {
|
|
4052
4050
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
4053
4051
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
4054
|
-
for (
|
|
4055
|
-
parameterName =
|
|
4052
|
+
for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4053
|
+
parameterName = _f.value;
|
|
4056
4054
|
_loop_1(parameterName);
|
|
4057
4055
|
}
|
|
4058
4056
|
}
|
|
4059
4057
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4060
4058
|
finally {
|
|
4061
4059
|
try {
|
|
4062
|
-
if (
|
|
4060
|
+
if (_f && !_f.done && (_g = _e.return)) _g.call(_e);
|
|
4063
4061
|
}
|
|
4064
4062
|
finally { if (e_1) throw e_1.error; }
|
|
4065
4063
|
}
|
|
@@ -4079,12 +4077,11 @@ function executeTemplate(options) {
|
|
|
4079
4077
|
template: currentTemplate,
|
|
4080
4078
|
preparedPipeline: preparedPipeline,
|
|
4081
4079
|
tools: tools,
|
|
4082
|
-
settings: settings,
|
|
4083
4080
|
$executionReport: $executionReport,
|
|
4084
4081
|
pipelineIdentification: pipelineIdentification,
|
|
4085
4082
|
})];
|
|
4086
4083
|
case 3:
|
|
4087
|
-
resultString =
|
|
4084
|
+
resultString = _j.sent();
|
|
4088
4085
|
return [4 /*yield*/, onProgress({
|
|
4089
4086
|
name: name,
|
|
4090
4087
|
title: title,
|
|
@@ -4096,12 +4093,12 @@ function executeTemplate(options) {
|
|
|
4096
4093
|
// <- [🍸]
|
|
4097
4094
|
})];
|
|
4098
4095
|
case 4:
|
|
4099
|
-
|
|
4100
|
-
return [2 /*return*/, Object.freeze((
|
|
4101
|
-
|
|
4096
|
+
_j.sent();
|
|
4097
|
+
return [2 /*return*/, Object.freeze((_h = {},
|
|
4098
|
+
_h[currentTemplate.resultingParameterName] =
|
|
4102
4099
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4103
4100
|
resultString,
|
|
4104
|
-
|
|
4101
|
+
_h))];
|
|
4105
4102
|
}
|
|
4106
4103
|
});
|
|
4107
4104
|
});
|
|
@@ -4160,13 +4157,12 @@ function filterJustOutputParameters(options) {
|
|
|
4160
4157
|
*/
|
|
4161
4158
|
function executePipeline(options) {
|
|
4162
4159
|
return __awaiter(this, void 0, void 0, function () {
|
|
4163
|
-
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification,
|
|
4160
|
+
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;
|
|
4164
4161
|
var e_1, _f, e_2, _g;
|
|
4165
4162
|
return __generator(this, function (_h) {
|
|
4166
4163
|
switch (_h.label) {
|
|
4167
4164
|
case 0:
|
|
4168
|
-
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification,
|
|
4169
|
-
maxParallelCount = settings.maxParallelCount, rootDirname = settings.rootDirname, _a = settings.isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
4165
|
+
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;
|
|
4170
4166
|
preparedPipeline = options.preparedPipeline;
|
|
4171
4167
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
4172
4168
|
return [4 /*yield*/, preparePipeline(pipeline, tools, {
|
|
@@ -4351,12 +4347,7 @@ function executePipeline(options) {
|
|
|
4351
4347
|
return [3 /*break*/, 4];
|
|
4352
4348
|
case 3:
|
|
4353
4349
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
4354
|
-
work_1 = executeTemplate({
|
|
4355
|
-
currentTemplate: currentTemplate,
|
|
4356
|
-
preparedPipeline: preparedPipeline,
|
|
4357
|
-
parametersToPass: parametersToPass,
|
|
4358
|
-
tools: tools,
|
|
4359
|
-
onProgress: function (progress) {
|
|
4350
|
+
work_1 = executeTemplate(__assign(__assign({}, options), { currentTemplate: currentTemplate, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
4360
4351
|
if (isReturned) {
|
|
4361
4352
|
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)
|
|
4362
4353
|
.split('\n')
|
|
@@ -4366,11 +4357,7 @@ function executePipeline(options) {
|
|
|
4366
4357
|
if (onProgress) {
|
|
4367
4358
|
onProgress(progress);
|
|
4368
4359
|
}
|
|
4369
|
-
},
|
|
4370
|
-
settings: settings,
|
|
4371
|
-
$executionReport: executionReport,
|
|
4372
|
-
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4373
|
-
})
|
|
4360
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }) }))
|
|
4374
4361
|
.then(function (newParametersToPass) {
|
|
4375
4362
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
4376
4363
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
|
|
@@ -4474,8 +4461,7 @@ function executePipeline(options) {
|
|
|
4474
4461
|
*/
|
|
4475
4462
|
function createPipelineExecutor(options) {
|
|
4476
4463
|
var _this = this;
|
|
4477
|
-
var pipeline = options.pipeline, tools = options.tools, _a = options.
|
|
4478
|
-
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;
|
|
4464
|
+
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;
|
|
4479
4465
|
validatePipeline(pipeline);
|
|
4480
4466
|
var pipelineIdentification = (function () {
|
|
4481
4467
|
// Note: This is a 😐 implementation of [🚞]
|
|
@@ -4509,14 +4495,12 @@ function createPipelineExecutor(options) {
|
|
|
4509
4495
|
tools: tools,
|
|
4510
4496
|
onProgress: onProgress,
|
|
4511
4497
|
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
rootDirname: rootDirname,
|
|
4519
|
-
},
|
|
4498
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4499
|
+
maxParallelCount: maxParallelCount,
|
|
4500
|
+
csvSettings: csvSettings,
|
|
4501
|
+
isVerbose: isVerbose,
|
|
4502
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4503
|
+
rootDirname: rootDirname,
|
|
4520
4504
|
})];
|
|
4521
4505
|
});
|
|
4522
4506
|
}); };
|
|
@@ -4539,7 +4523,7 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
4539
4523
|
return __generator(this, function (_d) {
|
|
4540
4524
|
switch (_d.label) {
|
|
4541
4525
|
case 0:
|
|
4542
|
-
_a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
4526
|
+
_a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
4543
4527
|
if (tools === undefined || tools.llm === undefined) {
|
|
4544
4528
|
throw new MissingToolsError('LLM tools are required for preparing persona');
|
|
4545
4529
|
}
|
|
@@ -4721,7 +4705,7 @@ var $Register = /** @class */ (function () {
|
|
|
4721
4705
|
this.storage = globalScope[storageName];
|
|
4722
4706
|
}
|
|
4723
4707
|
$Register.prototype.list = function () {
|
|
4724
|
-
// <- TODO: ReadonlyDeep<
|
|
4708
|
+
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
4725
4709
|
return this.storage;
|
|
4726
4710
|
};
|
|
4727
4711
|
$Register.prototype.register = function (registered) {
|
|
@@ -4773,7 +4757,6 @@ var $scrapersRegister = new $Register('scraper_constructors');
|
|
|
4773
4757
|
* TODO: [®] DRY Register logic
|
|
4774
4758
|
*/
|
|
4775
4759
|
|
|
4776
|
-
// TODO: !!!!!! Maybe delete this function
|
|
4777
4760
|
/**
|
|
4778
4761
|
* Creates a message with all registered scrapers
|
|
4779
4762
|
*
|
|
@@ -4940,7 +4923,6 @@ function normalizeToKebabCase(text) {
|
|
|
4940
4923
|
* @private within the repository
|
|
4941
4924
|
*/
|
|
4942
4925
|
function sourceContentToName(sourceContent) {
|
|
4943
|
-
// TODO: !!!!!! Better name for source than gibberish hash
|
|
4944
4926
|
var hash = SHA256(hexEncoder.parse(JSON.stringify(sourceContent)))
|
|
4945
4927
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
4946
4928
|
.toString( /* hex */)
|
|
@@ -5040,20 +5022,20 @@ function isValidFilePath(filename) {
|
|
|
5040
5022
|
/**
|
|
5041
5023
|
* @@@
|
|
5042
5024
|
*
|
|
5043
|
-
* @
|
|
5025
|
+
* @public exported from `@promptbook/core`
|
|
5044
5026
|
*/
|
|
5045
5027
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5046
5028
|
var _a;
|
|
5047
5029
|
return __awaiter(this, void 0, void 0, function () {
|
|
5048
5030
|
var sourceContent, name, _b, _c, rootDirname, _d,
|
|
5049
5031
|
// <- TODO: process.cwd() if running in Node.js
|
|
5050
|
-
isVerbose, url, response_1, mimeType, filename_1, fileExtension,
|
|
5032
|
+
isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5051
5033
|
return __generator(this, function (_e) {
|
|
5052
5034
|
switch (_e.label) {
|
|
5053
5035
|
case 0:
|
|
5054
5036
|
sourceContent = knowledgeSource.sourceContent;
|
|
5055
5037
|
name = knowledgeSource.name;
|
|
5056
|
-
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ?
|
|
5038
|
+
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d;
|
|
5057
5039
|
TODO_USE(isVerbose);
|
|
5058
5040
|
if (!name) {
|
|
5059
5041
|
name = sourceContentToName(sourceContent);
|
|
@@ -5069,19 +5051,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5069
5051
|
filename: null,
|
|
5070
5052
|
url: url,
|
|
5071
5053
|
mimeType: mimeType,
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
return [2 /*return*/, content];
|
|
5081
|
-
}
|
|
5082
|
-
});
|
|
5083
|
-
});
|
|
5084
|
-
},
|
|
5054
|
+
/*
|
|
5055
|
+
TODO: [🥽]
|
|
5056
|
+
> async asBlob() {
|
|
5057
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
5058
|
+
> const content = await response.blob();
|
|
5059
|
+
> return content;
|
|
5060
|
+
> },
|
|
5061
|
+
*/
|
|
5085
5062
|
asJson: function () {
|
|
5086
5063
|
return __awaiter(this, void 0, void 0, function () {
|
|
5087
5064
|
var content;
|
|
@@ -5121,34 +5098,31 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5121
5098
|
}
|
|
5122
5099
|
filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
|
|
5123
5100
|
fileExtension = getFileExtension(filename_1);
|
|
5124
|
-
|
|
5101
|
+
mimeType = extensionToMimeType(fileExtension || '');
|
|
5125
5102
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5126
5103
|
case 3:
|
|
5127
5104
|
if (!(_e.sent())) {
|
|
5128
5105
|
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 "); }));
|
|
5129
5106
|
}
|
|
5130
|
-
// TODO:
|
|
5107
|
+
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
5131
5108
|
return [2 /*return*/, {
|
|
5132
5109
|
source: name,
|
|
5133
5110
|
filename: filename_1,
|
|
5134
5111
|
url: null,
|
|
5135
|
-
mimeType:
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
});
|
|
5150
|
-
});
|
|
5151
|
-
},
|
|
5112
|
+
mimeType: mimeType,
|
|
5113
|
+
/*
|
|
5114
|
+
TODO: [🥽]
|
|
5115
|
+
> async asBlob() {
|
|
5116
|
+
> const content = await tools.fs!.readFile(filename);
|
|
5117
|
+
> return new Blob(
|
|
5118
|
+
> [
|
|
5119
|
+
> content,
|
|
5120
|
+
> // <- TODO: [🥽] This is NOT tested, test it
|
|
5121
|
+
> ],
|
|
5122
|
+
> { type: mimeType },
|
|
5123
|
+
> );
|
|
5124
|
+
> },
|
|
5125
|
+
*/
|
|
5152
5126
|
asJson: function () {
|
|
5153
5127
|
return __awaiter(this, void 0, void 0, function () {
|
|
5154
5128
|
var _a, _b;
|
|
@@ -5184,9 +5158,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5184
5158
|
asJson: function () {
|
|
5185
5159
|
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
5186
5160
|
},
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5161
|
+
/*
|
|
5162
|
+
TODO: [🥽]
|
|
5163
|
+
> asBlob() {
|
|
5164
|
+
> throw new UnexpectedError(
|
|
5165
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
5166
|
+
> );
|
|
5167
|
+
> },
|
|
5168
|
+
*/
|
|
5190
5169
|
}];
|
|
5191
5170
|
}
|
|
5192
5171
|
});
|
|
@@ -5206,7 +5185,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5206
5185
|
return __generator(this, function (_c) {
|
|
5207
5186
|
switch (_c.label) {
|
|
5208
5187
|
case 0:
|
|
5209
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
5188
|
+
_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;
|
|
5210
5189
|
knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
5211
5190
|
return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
5212
5191
|
var partialPieces, sourceHandler, _a, _b, scraper, partialPiecesUnchecked, e_1_1, pieces;
|
|
@@ -5235,7 +5214,8 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5235
5214
|
case 4:
|
|
5236
5215
|
partialPiecesUnchecked = _d.sent();
|
|
5237
5216
|
if (partialPiecesUnchecked !== null) {
|
|
5238
|
-
partialPieces = partialPiecesUnchecked;
|
|
5217
|
+
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
5218
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
5239
5219
|
return [3 /*break*/, 6];
|
|
5240
5220
|
}
|
|
5241
5221
|
_d.label = 5;
|
|
@@ -5283,7 +5263,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
5283
5263
|
> /**
|
|
5284
5264
|
> * Unprepared knowledge
|
|
5285
5265
|
> * /
|
|
5286
|
-
> readonly knowledgeSources:
|
|
5266
|
+
> readonly knowledgeSources: ReadonlyArray<KnowledgeSourceJson>;
|
|
5287
5267
|
> };
|
|
5288
5268
|
>
|
|
5289
5269
|
> export async function prepareKnowledgePieces(
|
|
@@ -5341,7 +5321,7 @@ function prepareTemplates(pipeline, tools, options) {
|
|
|
5341
5321
|
return __generator(this, function (_b) {
|
|
5342
5322
|
switch (_b.label) {
|
|
5343
5323
|
case 0:
|
|
5344
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
5324
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
5345
5325
|
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
5346
5326
|
// TODO: [main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
5347
5327
|
TODO_USE(parameters);
|
|
@@ -5403,7 +5383,7 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5403
5383
|
if (isPipelinePrepared(pipeline)) {
|
|
5404
5384
|
return [2 /*return*/, pipeline];
|
|
5405
5385
|
}
|
|
5406
|
-
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ?
|
|
5386
|
+
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;
|
|
5407
5387
|
parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
5408
5388
|
if (tools === undefined || tools.llm === undefined) {
|
|
5409
5389
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
@@ -5461,7 +5441,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5461
5441
|
// ----- /Templates preparation -----
|
|
5462
5442
|
// Note: Count total usage
|
|
5463
5443
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
5464
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates:
|
|
5444
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: __spreadArray([], __read(templatesPrepared), false),
|
|
5445
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` templates: templatesPrepared`
|
|
5446
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
|
|
5465
5447
|
}
|
|
5466
5448
|
});
|
|
5467
5449
|
});
|
|
@@ -5508,6 +5490,7 @@ var knowledgeCommandParser = {
|
|
|
5508
5490
|
'KNOWLEDGE ./hejny-cv.md',
|
|
5509
5491
|
'KNOWLEDGE ./hejny-cv.pdf',
|
|
5510
5492
|
'KNOWLEDGE ./hejny-cv.docx',
|
|
5493
|
+
// <- TODO: [😿] Allow ONLY files scoped in the (sub)directory NOT ../ and test it
|
|
5511
5494
|
],
|
|
5512
5495
|
/**
|
|
5513
5496
|
* Parses the KNOWLEDGE command
|
|
@@ -8225,6 +8208,327 @@ function pipelineStringToJson(pipelineString, tools, options) {
|
|
|
8225
8208
|
*/
|
|
8226
8209
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
8227
8210
|
|
|
8211
|
+
// Note: We want to use the `exec` as async function
|
|
8212
|
+
var exec$1 = promisify(exec$2);
|
|
8213
|
+
/**
|
|
8214
|
+
* @@@
|
|
8215
|
+
*
|
|
8216
|
+
* @private within the repository
|
|
8217
|
+
*/
|
|
8218
|
+
function locateAppOnLinux(_a) {
|
|
8219
|
+
var appName = _a.appName, linuxWhich = _a.linuxWhich;
|
|
8220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8221
|
+
var _b, stderr, stdout, error_1;
|
|
8222
|
+
return __generator(this, function (_c) {
|
|
8223
|
+
switch (_c.label) {
|
|
8224
|
+
case 0:
|
|
8225
|
+
_c.trys.push([0, 2, , 3]);
|
|
8226
|
+
return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
|
|
8227
|
+
case 1:
|
|
8228
|
+
_b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
|
|
8229
|
+
if (!stderr && stdout) {
|
|
8230
|
+
return [2 /*return*/, stdout.trim()];
|
|
8231
|
+
}
|
|
8232
|
+
throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
|
|
8233
|
+
case 2:
|
|
8234
|
+
error_1 = _c.sent();
|
|
8235
|
+
if (!(error_1 instanceof Error)) {
|
|
8236
|
+
throw error_1;
|
|
8237
|
+
}
|
|
8238
|
+
return [2 /*return*/, null];
|
|
8239
|
+
case 3: return [2 /*return*/];
|
|
8240
|
+
}
|
|
8241
|
+
});
|
|
8242
|
+
});
|
|
8243
|
+
}
|
|
8244
|
+
/**
|
|
8245
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node`
|
|
8246
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8247
|
+
*/
|
|
8248
|
+
|
|
8249
|
+
/**
|
|
8250
|
+
* @@@
|
|
8251
|
+
*
|
|
8252
|
+
* @public exported from `@promptbook/node`
|
|
8253
|
+
*/
|
|
8254
|
+
function $provideFilesystemForNode(options) {
|
|
8255
|
+
if (!$isRunningInNode()) {
|
|
8256
|
+
throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
|
|
8257
|
+
}
|
|
8258
|
+
var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
|
|
8259
|
+
TODO_USE(isVerbose);
|
|
8260
|
+
return {
|
|
8261
|
+
stat: stat,
|
|
8262
|
+
access: access,
|
|
8263
|
+
constants: constants,
|
|
8264
|
+
readFile: readFile,
|
|
8265
|
+
writeFile: writeFile,
|
|
8266
|
+
readdir: readdir,
|
|
8267
|
+
};
|
|
8268
|
+
}
|
|
8269
|
+
/**
|
|
8270
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8271
|
+
*/
|
|
8272
|
+
|
|
8273
|
+
/**
|
|
8274
|
+
* Checks if the file is executable
|
|
8275
|
+
*
|
|
8276
|
+
* @private within the repository
|
|
8277
|
+
*/
|
|
8278
|
+
function isExecutable(path, fs) {
|
|
8279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8280
|
+
return __generator(this, function (_a) {
|
|
8281
|
+
switch (_a.label) {
|
|
8282
|
+
case 0:
|
|
8283
|
+
_a.trys.push([0, 2, , 3]);
|
|
8284
|
+
return [4 /*yield*/, fs.access(path, fs.constants.X_OK)];
|
|
8285
|
+
case 1:
|
|
8286
|
+
_a.sent();
|
|
8287
|
+
return [2 /*return*/, true];
|
|
8288
|
+
case 2:
|
|
8289
|
+
_a.sent();
|
|
8290
|
+
return [2 /*return*/, false];
|
|
8291
|
+
case 3: return [2 /*return*/];
|
|
8292
|
+
}
|
|
8293
|
+
});
|
|
8294
|
+
});
|
|
8295
|
+
}
|
|
8296
|
+
/**
|
|
8297
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
8298
|
+
* TODO: [🖇] What about symlinks?
|
|
8299
|
+
*/
|
|
8300
|
+
|
|
8301
|
+
// Note: Module `userhome` has no types available, so it is imported using `require`
|
|
8302
|
+
// @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
|
|
8303
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8304
|
+
var userhome = require('userhome');
|
|
8305
|
+
// Note: We want to use the `exec` as async function
|
|
8306
|
+
var exec = promisify(exec$2);
|
|
8307
|
+
/**
|
|
8308
|
+
* @@@
|
|
8309
|
+
*
|
|
8310
|
+
* @private within the repository
|
|
8311
|
+
*/
|
|
8312
|
+
function locateAppOnMacOs(_a) {
|
|
8313
|
+
var appName = _a.appName, macOsName = _a.macOsName;
|
|
8314
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8315
|
+
var toExec, regPath, altPath, _b, stderr, stdout, error_1;
|
|
8316
|
+
return __generator(this, function (_c) {
|
|
8317
|
+
switch (_c.label) {
|
|
8318
|
+
case 0:
|
|
8319
|
+
_c.trys.push([0, 6, , 7]);
|
|
8320
|
+
toExec = "/Contents/MacOS/".concat(macOsName);
|
|
8321
|
+
regPath = "/Applications/".concat(macOsName, ".app") + toExec;
|
|
8322
|
+
altPath = userhome(regPath.slice(1));
|
|
8323
|
+
return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
|
|
8324
|
+
case 1:
|
|
8325
|
+
if (!_c.sent()) return [3 /*break*/, 2];
|
|
8326
|
+
return [2 /*return*/, regPath];
|
|
8327
|
+
case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
|
|
8328
|
+
case 3:
|
|
8329
|
+
if (_c.sent()) {
|
|
8330
|
+
return [2 /*return*/, altPath];
|
|
8331
|
+
}
|
|
8332
|
+
_c.label = 4;
|
|
8333
|
+
case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
|
|
8334
|
+
case 5:
|
|
8335
|
+
_b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
|
|
8336
|
+
if (!stderr && stdout) {
|
|
8337
|
+
return [2 /*return*/, stdout.trim() + toExec];
|
|
8338
|
+
}
|
|
8339
|
+
throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
|
|
8340
|
+
case 6:
|
|
8341
|
+
error_1 = _c.sent();
|
|
8342
|
+
if (!(error_1 instanceof Error)) {
|
|
8343
|
+
throw error_1;
|
|
8344
|
+
}
|
|
8345
|
+
return [2 /*return*/, null];
|
|
8346
|
+
case 7: return [2 /*return*/];
|
|
8347
|
+
}
|
|
8348
|
+
});
|
|
8349
|
+
});
|
|
8350
|
+
}
|
|
8351
|
+
/**
|
|
8352
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node`
|
|
8353
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8354
|
+
*/
|
|
8355
|
+
|
|
8356
|
+
/**
|
|
8357
|
+
* @@@
|
|
8358
|
+
*
|
|
8359
|
+
* @private within the repository
|
|
8360
|
+
*/
|
|
8361
|
+
function locateAppOnWindows(_a) {
|
|
8362
|
+
var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
|
|
8363
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8364
|
+
var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
|
|
8365
|
+
var e_1, _b;
|
|
8366
|
+
return __generator(this, function (_c) {
|
|
8367
|
+
switch (_c.label) {
|
|
8368
|
+
case 0:
|
|
8369
|
+
_c.trys.push([0, 9, , 10]);
|
|
8370
|
+
prefixes = [
|
|
8371
|
+
process.env.LOCALAPPDATA,
|
|
8372
|
+
join(process.env.LOCALAPPDATA || '', 'Programs'),
|
|
8373
|
+
process.env.PROGRAMFILES,
|
|
8374
|
+
process.env['PROGRAMFILES(X86)'],
|
|
8375
|
+
];
|
|
8376
|
+
_c.label = 1;
|
|
8377
|
+
case 1:
|
|
8378
|
+
_c.trys.push([1, 6, 7, 8]);
|
|
8379
|
+
prefixes_1 = __values(prefixes), prefixes_1_1 = prefixes_1.next();
|
|
8380
|
+
_c.label = 2;
|
|
8381
|
+
case 2:
|
|
8382
|
+
if (!!prefixes_1_1.done) return [3 /*break*/, 5];
|
|
8383
|
+
prefix = prefixes_1_1.value;
|
|
8384
|
+
path = prefix + windowsSuffix;
|
|
8385
|
+
return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
|
|
8386
|
+
case 3:
|
|
8387
|
+
if (_c.sent()) {
|
|
8388
|
+
return [2 /*return*/, path];
|
|
8389
|
+
}
|
|
8390
|
+
_c.label = 4;
|
|
8391
|
+
case 4:
|
|
8392
|
+
prefixes_1_1 = prefixes_1.next();
|
|
8393
|
+
return [3 /*break*/, 2];
|
|
8394
|
+
case 5: return [3 /*break*/, 8];
|
|
8395
|
+
case 6:
|
|
8396
|
+
e_1_1 = _c.sent();
|
|
8397
|
+
e_1 = { error: e_1_1 };
|
|
8398
|
+
return [3 /*break*/, 8];
|
|
8399
|
+
case 7:
|
|
8400
|
+
try {
|
|
8401
|
+
if (prefixes_1_1 && !prefixes_1_1.done && (_b = prefixes_1.return)) _b.call(prefixes_1);
|
|
8402
|
+
}
|
|
8403
|
+
finally { if (e_1) throw e_1.error; }
|
|
8404
|
+
return [7 /*endfinally*/];
|
|
8405
|
+
case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
|
|
8406
|
+
case 9:
|
|
8407
|
+
error_1 = _c.sent();
|
|
8408
|
+
if (!(error_1 instanceof Error)) {
|
|
8409
|
+
throw error_1;
|
|
8410
|
+
}
|
|
8411
|
+
return [2 /*return*/, null];
|
|
8412
|
+
case 10: return [2 /*return*/];
|
|
8413
|
+
}
|
|
8414
|
+
});
|
|
8415
|
+
});
|
|
8416
|
+
}
|
|
8417
|
+
/**
|
|
8418
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node`
|
|
8419
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8420
|
+
*/
|
|
8421
|
+
|
|
8422
|
+
/**
|
|
8423
|
+
* Locates an application on the system
|
|
8424
|
+
*
|
|
8425
|
+
* @private within the repository
|
|
8426
|
+
*/
|
|
8427
|
+
function locateApp(options) {
|
|
8428
|
+
if (!$isRunningInNode()) {
|
|
8429
|
+
throw new EnvironmentMismatchError('Locating apps works only in Node.js environment');
|
|
8430
|
+
}
|
|
8431
|
+
var appName = options.appName, linuxWhich = options.linuxWhich, windowsSuffix = options.windowsSuffix, macOsName = options.macOsName;
|
|
8432
|
+
if (process.platform === 'win32') {
|
|
8433
|
+
if (windowsSuffix) {
|
|
8434
|
+
return locateAppOnWindows({ appName: appName, windowsSuffix: windowsSuffix });
|
|
8435
|
+
}
|
|
8436
|
+
else {
|
|
8437
|
+
throw new Error("".concat(appName, " is not available on Windows."));
|
|
8438
|
+
}
|
|
8439
|
+
}
|
|
8440
|
+
else if (process.platform === 'darwin') {
|
|
8441
|
+
if (macOsName) {
|
|
8442
|
+
return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
|
|
8443
|
+
}
|
|
8444
|
+
else {
|
|
8445
|
+
throw new Error("".concat(appName, " is not available on macOS."));
|
|
8446
|
+
}
|
|
8447
|
+
}
|
|
8448
|
+
else {
|
|
8449
|
+
if (linuxWhich) {
|
|
8450
|
+
return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
|
|
8451
|
+
}
|
|
8452
|
+
else {
|
|
8453
|
+
throw new Error("".concat(appName, " is not available on Linux."));
|
|
8454
|
+
}
|
|
8455
|
+
}
|
|
8456
|
+
}
|
|
8457
|
+
/**
|
|
8458
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node`
|
|
8459
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8460
|
+
*/
|
|
8461
|
+
|
|
8462
|
+
/**
|
|
8463
|
+
* @@@
|
|
8464
|
+
*
|
|
8465
|
+
* @private within the repository
|
|
8466
|
+
*/
|
|
8467
|
+
function locateLibreoffice() {
|
|
8468
|
+
return locateApp({
|
|
8469
|
+
appName: 'Libreoffice',
|
|
8470
|
+
linuxWhich: 'libreoffice',
|
|
8471
|
+
windowsSuffix: '\\LibreOffice\\program\\soffice.exe',
|
|
8472
|
+
macOsName: 'LibreOffice',
|
|
8473
|
+
});
|
|
8474
|
+
}
|
|
8475
|
+
/**
|
|
8476
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/legacy-documents`
|
|
8477
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8478
|
+
*/
|
|
8479
|
+
|
|
8480
|
+
/**
|
|
8481
|
+
* @@@
|
|
8482
|
+
*
|
|
8483
|
+
* @private within the repository
|
|
8484
|
+
*/
|
|
8485
|
+
function locatePandoc() {
|
|
8486
|
+
return locateApp({
|
|
8487
|
+
appName: 'Pandoc',
|
|
8488
|
+
linuxWhich: 'pandoc',
|
|
8489
|
+
windowsSuffix: '\\Pandoc\\pandoc.exe',
|
|
8490
|
+
macOsName: 'Pandoc',
|
|
8491
|
+
});
|
|
8492
|
+
}
|
|
8493
|
+
/**
|
|
8494
|
+
* TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/documents`
|
|
8495
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8496
|
+
*/
|
|
8497
|
+
|
|
8498
|
+
/**
|
|
8499
|
+
* @@@
|
|
8500
|
+
*
|
|
8501
|
+
* @public exported from `@promptbook/node`
|
|
8502
|
+
*/
|
|
8503
|
+
function $provideExecutablesForNode(options) {
|
|
8504
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8505
|
+
var _a, _b, isAutoInstalled, _c, isVerbose;
|
|
8506
|
+
var _d;
|
|
8507
|
+
return __generator(this, function (_e) {
|
|
8508
|
+
switch (_e.label) {
|
|
8509
|
+
case 0:
|
|
8510
|
+
if (!$isRunningInNode()) {
|
|
8511
|
+
throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
|
|
8512
|
+
}
|
|
8513
|
+
_a = options || {}, _b = _a.isAutoInstalled, isAutoInstalled = _b === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
|
|
8514
|
+
TODO_USE(isAutoInstalled); // <- TODO: [🔱][🧠] Auto-install the executables
|
|
8515
|
+
TODO_USE(isVerbose);
|
|
8516
|
+
_d = {};
|
|
8517
|
+
return [4 /*yield*/, locatePandoc()];
|
|
8518
|
+
case 1:
|
|
8519
|
+
_d.pandocPath = (_e.sent()) || undefined;
|
|
8520
|
+
return [4 /*yield*/, locateLibreoffice()];
|
|
8521
|
+
case 2: return [2 /*return*/, (_d.libreOfficePath = (_e.sent()) || undefined,
|
|
8522
|
+
_d)];
|
|
8523
|
+
}
|
|
8524
|
+
});
|
|
8525
|
+
});
|
|
8526
|
+
}
|
|
8527
|
+
/**
|
|
8528
|
+
* TODO: [🧠] Allow to override the executables without need to call `locatePandoc` / `locateLibreoffice` in case of provided
|
|
8529
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8530
|
+
*/
|
|
8531
|
+
|
|
8228
8532
|
/**
|
|
8229
8533
|
* @@@
|
|
8230
8534
|
*
|
|
@@ -8394,7 +8698,7 @@ function $registeredLlmToolsMessage() {
|
|
|
8394
8698
|
*/
|
|
8395
8699
|
function createLlmToolsFromConfiguration(configuration, options) {
|
|
8396
8700
|
if (options === void 0) { options = {}; }
|
|
8397
|
-
var _a = options.isVerbose, isVerbose = _a === void 0 ?
|
|
8701
|
+
var _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a, userId = options.userId;
|
|
8398
8702
|
var llmTools = configuration.map(function (llmConfiguration) {
|
|
8399
8703
|
var registeredItem = $llmToolsRegister
|
|
8400
8704
|
.list()
|
|
@@ -8405,7 +8709,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
8405
8709
|
if (registeredItem === undefined) {
|
|
8406
8710
|
throw new Error(spaceTrim$1(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
|
|
8407
8711
|
}
|
|
8408
|
-
return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
|
|
8712
|
+
return registeredItem(__assign({ isVerbose: isVerbose, userId: userId }, llmConfiguration.options));
|
|
8409
8713
|
});
|
|
8410
8714
|
return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
|
|
8411
8715
|
}
|
|
@@ -8458,29 +8762,6 @@ function $provideLlmToolsFromEnv(options) {
|
|
|
8458
8762
|
/**
|
|
8459
8763
|
* @@@
|
|
8460
8764
|
*
|
|
8461
|
-
* @public exported from `@promptbook/node`
|
|
8462
|
-
*/
|
|
8463
|
-
function $provideFilesystemForNode(options) {
|
|
8464
|
-
if (!$isRunningInNode()) {
|
|
8465
|
-
throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
|
|
8466
|
-
}
|
|
8467
|
-
var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? IS_VERBOSE : _a;
|
|
8468
|
-
TODO_USE(isVerbose);
|
|
8469
|
-
return {
|
|
8470
|
-
stat: stat,
|
|
8471
|
-
access: access,
|
|
8472
|
-
constants: constants,
|
|
8473
|
-
readFile: readFile,
|
|
8474
|
-
readdir: readdir,
|
|
8475
|
-
};
|
|
8476
|
-
}
|
|
8477
|
-
/**
|
|
8478
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
8479
|
-
*/
|
|
8480
|
-
|
|
8481
|
-
/**
|
|
8482
|
-
* !!!!!!
|
|
8483
|
-
*
|
|
8484
8765
|
* 1) @@@
|
|
8485
8766
|
* 2) @@@
|
|
8486
8767
|
*
|
|
@@ -8496,7 +8777,7 @@ function $provideScrapersForNode(tools, options) {
|
|
|
8496
8777
|
if (!$isRunningInNode()) {
|
|
8497
8778
|
throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
|
|
8498
8779
|
}
|
|
8499
|
-
_a = options || {}, _b = _a.isAutoInstalled, isAutoInstalled = _b === void 0 ?
|
|
8780
|
+
_a = options || {}, _b = _a.isAutoInstalled, isAutoInstalled = _b === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
|
|
8500
8781
|
TODO_USE(isAutoInstalled);
|
|
8501
8782
|
TODO_USE(isVerbose);
|
|
8502
8783
|
scrapers = [];
|
|
@@ -8990,7 +9271,7 @@ var JavascriptExecutionTools = JavascriptEvalExecutionTools;
|
|
|
8990
9271
|
*/
|
|
8991
9272
|
function $provideExecutionToolsForNode(options) {
|
|
8992
9273
|
return __awaiter(this, void 0, void 0, function () {
|
|
8993
|
-
var fs, llm, tools;
|
|
9274
|
+
var fs, llm, executables, tools;
|
|
8994
9275
|
var _a;
|
|
8995
9276
|
return __generator(this, function (_b) {
|
|
8996
9277
|
switch (_b.label) {
|
|
@@ -9000,12 +9281,16 @@ function $provideExecutionToolsForNode(options) {
|
|
|
9000
9281
|
}
|
|
9001
9282
|
fs = $provideFilesystemForNode();
|
|
9002
9283
|
llm = $provideLlmToolsFromEnv(options);
|
|
9284
|
+
return [4 /*yield*/, $provideExecutablesForNode(options)];
|
|
9285
|
+
case 1:
|
|
9286
|
+
executables = _b.sent();
|
|
9003
9287
|
_a = {
|
|
9004
9288
|
llm: llm,
|
|
9005
|
-
fs: fs
|
|
9289
|
+
fs: fs,
|
|
9290
|
+
executables: executables
|
|
9006
9291
|
};
|
|
9007
|
-
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm }, options)];
|
|
9008
|
-
case
|
|
9292
|
+
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, options)];
|
|
9293
|
+
case 2:
|
|
9009
9294
|
tools = (_a.scrapers = _b.sent(),
|
|
9010
9295
|
_a.script = [new JavascriptExecutionTools(options)],
|
|
9011
9296
|
_a);
|
|
@@ -9243,7 +9528,9 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
9243
9528
|
throw new EnvironmentMismatchError('Can not create collection without filesystem tools');
|
|
9244
9529
|
// <- TODO: [🧠] What is the best error type here`
|
|
9245
9530
|
}
|
|
9246
|
-
makedLibraryFilePath = join(path, "".concat(
|
|
9531
|
+
makedLibraryFilePath = join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
|
|
9532
|
+
// <- TODO: [🦒] Allow to override (pass different value into the function)
|
|
9533
|
+
, ".json"));
|
|
9247
9534
|
return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
|
|
9248
9535
|
case 3:
|
|
9249
9536
|
if (!(_f.sent())) {
|
|
@@ -9254,7 +9541,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
9254
9541
|
// TODO: !! Implement;
|
|
9255
9542
|
// TODO: [🌗]
|
|
9256
9543
|
}
|
|
9257
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ?
|
|
9544
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
9258
9545
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
9259
9546
|
var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
9260
9547
|
var e_1, _a;
|
|
@@ -9588,22 +9875,26 @@ var FileCacheStorage = /** @class */ (function () {
|
|
|
9588
9875
|
/**
|
|
9589
9876
|
* Normalize options for `execCommand` and `execCommands`
|
|
9590
9877
|
*
|
|
9878
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
9879
|
+
*
|
|
9591
9880
|
* @private internal utility of `execCommand` and `execCommands`
|
|
9592
9881
|
*/
|
|
9593
|
-
function execCommandNormalizeOptions(options) {
|
|
9882
|
+
function $execCommandNormalizeOptions(options) {
|
|
9594
9883
|
var _a;
|
|
9595
|
-
var _b, _c, _d;
|
|
9884
|
+
var _b, _c, _d, _e;
|
|
9596
9885
|
var command;
|
|
9597
9886
|
var cwd;
|
|
9598
9887
|
var crashOnError;
|
|
9599
9888
|
var args = [];
|
|
9600
9889
|
var timeout;
|
|
9890
|
+
var isVerbose;
|
|
9601
9891
|
if (typeof options === 'string') {
|
|
9602
9892
|
// TODO: [1] DRY default values
|
|
9603
9893
|
command = options;
|
|
9604
9894
|
cwd = process.cwd();
|
|
9605
9895
|
crashOnError = true;
|
|
9606
|
-
timeout = Infinity;
|
|
9896
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
9897
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
9607
9898
|
}
|
|
9608
9899
|
else {
|
|
9609
9900
|
/*
|
|
@@ -9619,6 +9910,7 @@ function execCommandNormalizeOptions(options) {
|
|
|
9619
9910
|
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
9620
9911
|
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
9621
9912
|
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
9913
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
9622
9914
|
}
|
|
9623
9915
|
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
9624
9916
|
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
@@ -9640,16 +9932,21 @@ function execCommandNormalizeOptions(options) {
|
|
|
9640
9932
|
if (['ts-node'].includes(humanReadableCommand)) {
|
|
9641
9933
|
humanReadableCommand += " ".concat(args[1]);
|
|
9642
9934
|
}
|
|
9643
|
-
|
|
9935
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
9936
|
+
command = "".concat(command, ".cmd");
|
|
9937
|
+
}
|
|
9938
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
9644
9939
|
}
|
|
9645
9940
|
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
9646
9941
|
|
|
9647
9942
|
/**
|
|
9648
9943
|
* Run one command in a shell
|
|
9649
9944
|
*
|
|
9945
|
+
*
|
|
9650
9946
|
* Note: There are 2 similar functions in the codebase:
|
|
9651
9947
|
* - `$execCommand` which runs a single command
|
|
9652
9948
|
* - `$execCommands` which runs multiple commands
|
|
9949
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
9653
9950
|
*
|
|
9654
9951
|
* @public exported from `@promptbook/node`
|
|
9655
9952
|
*/
|
|
@@ -9659,7 +9956,7 @@ function $execCommand(options) {
|
|
|
9659
9956
|
}
|
|
9660
9957
|
return new Promise(function (resolve, reject) {
|
|
9661
9958
|
// eslint-disable-next-line prefer-const
|
|
9662
|
-
var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
|
|
9959
|
+
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;
|
|
9663
9960
|
if (timeout !== Infinity) {
|
|
9664
9961
|
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
9665
9962
|
forTime(timeout).then(function () {
|
|
@@ -9672,24 +9969,26 @@ function $execCommand(options) {
|
|
|
9672
9969
|
}
|
|
9673
9970
|
});
|
|
9674
9971
|
}
|
|
9675
|
-
if (
|
|
9676
|
-
|
|
9972
|
+
if (isVerbose) {
|
|
9973
|
+
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
9677
9974
|
}
|
|
9678
|
-
// !!!!!! Verbose mode - to all consoles
|
|
9679
|
-
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
9680
9975
|
try {
|
|
9681
9976
|
var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9977
|
+
if (isVerbose) {
|
|
9978
|
+
commandProcess.on('message', function (message) {
|
|
9979
|
+
console.info({ message: message });
|
|
9980
|
+
});
|
|
9981
|
+
}
|
|
9685
9982
|
var output_1 = [];
|
|
9686
9983
|
commandProcess.stdout.on('data', function (stdout) {
|
|
9687
9984
|
output_1.push(stdout.toString());
|
|
9688
|
-
|
|
9985
|
+
if (isVerbose) {
|
|
9986
|
+
console.info(stdout.toString());
|
|
9987
|
+
}
|
|
9689
9988
|
});
|
|
9690
9989
|
commandProcess.stderr.on('data', function (stderr) {
|
|
9691
9990
|
output_1.push(stderr.toString());
|
|
9692
|
-
if (stderr.toString().trim()) {
|
|
9991
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
9693
9992
|
console.warn(stderr.toString());
|
|
9694
9993
|
}
|
|
9695
9994
|
});
|
|
@@ -9700,7 +9999,9 @@ function $execCommand(options) {
|
|
|
9700
9999
|
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
9701
10000
|
}
|
|
9702
10001
|
else {
|
|
9703
|
-
|
|
10002
|
+
if (isVerbose) {
|
|
10003
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
10004
|
+
}
|
|
9704
10005
|
resolve(spaceTrim(output_1.join('\n')));
|
|
9705
10006
|
}
|
|
9706
10007
|
}
|
|
@@ -9719,7 +10020,9 @@ function $execCommand(options) {
|
|
|
9719
10020
|
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
9720
10021
|
}
|
|
9721
10022
|
else {
|
|
9722
|
-
|
|
10023
|
+
if (isVerbose) {
|
|
10024
|
+
console.warn(error);
|
|
10025
|
+
}
|
|
9723
10026
|
resolve(spaceTrim(output_1.join('\n')));
|
|
9724
10027
|
}
|
|
9725
10028
|
});
|
|
@@ -9740,6 +10043,7 @@ function $execCommand(options) {
|
|
|
9740
10043
|
* Note: There are 2 similar functions in the codebase:
|
|
9741
10044
|
* - `$execCommand` which runs a single command
|
|
9742
10045
|
* - `$execCommands` which runs multiple commands
|
|
10046
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a commands in a shell
|
|
9743
10047
|
*
|
|
9744
10048
|
* @public exported from `@promptbook/node`
|
|
9745
10049
|
*/
|
|
@@ -9784,5 +10088,5 @@ function $execCommands(_a) {
|
|
|
9784
10088
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9785
10089
|
*/
|
|
9786
10090
|
|
|
9787
|
-
export { $execCommand, $execCommands, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, FileCacheStorage, PROMPTBOOK_VERSION, createCollectionFromDirectory };
|
|
10091
|
+
export { $execCommand, $execCommands, $provideExecutablesForNode, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, FileCacheStorage, PROMPTBOOK_VERSION, createCollectionFromDirectory };
|
|
9788
10092
|
//# sourceMappingURL=index.es.js.map
|