@promptbook/node 0.83.0 → 0.84.0-10
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 +5 -0
- package/esm/index.es.js +244 -231
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +8 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/editable.index.d.ts +8 -2
- package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
- package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
- package/esm/typings/src/constants.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +4 -0
- package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -0
- package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
- package/esm/typings/src/utils/editable/{utils → edit-pipeline-string}/removePipelineCommand.d.ts +1 -1
- package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
- package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +3 -0
- package/package.json +3 -3
- package/umd/index.umd.js +247 -233
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/utils/editable/{utils/removePipelineCommand.test.d.ts → edit-pipeline-string/addPipelineCommand.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/node`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -269,6 +273,7 @@ Or you can install them separately:
|
|
|
269
273
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
270
274
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
271
275
|
- **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
|
|
276
|
+
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/markitdown)** - Integration of [Markitdown by Microsoft](https://github.com/microsoft/markitdown)
|
|
272
277
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
273
278
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
274
279
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
package/esm/index.es.js
CHANGED
|
@@ -9,8 +9,7 @@ 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 {
|
|
13
|
-
import { promisify } from 'util';
|
|
12
|
+
import { spawn } from 'child_process';
|
|
14
13
|
import * as dotenv from 'dotenv';
|
|
15
14
|
import sha256 from 'crypto-js/sha256';
|
|
16
15
|
|
|
@@ -28,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
27
|
* @generated
|
|
29
28
|
* @see https://github.com/webgptorg/promptbook
|
|
30
29
|
*/
|
|
31
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-9';
|
|
32
31
|
/**
|
|
33
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -186,7 +185,7 @@ var NAME = "Promptbook";
|
|
|
186
185
|
*
|
|
187
186
|
* @public exported from `@promptbook/core`
|
|
188
187
|
*/
|
|
189
|
-
var ADMIN_EMAIL = '
|
|
188
|
+
var ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
190
189
|
/**
|
|
191
190
|
* Name of the responsible person for the Promptbook on GitHub
|
|
192
191
|
*
|
|
@@ -917,7 +916,7 @@ var ORDER_OF_PIPELINE_JSON = [
|
|
|
917
916
|
*
|
|
918
917
|
* @private within the repository
|
|
919
918
|
*/
|
|
920
|
-
var REPLACING_NONCE = '
|
|
919
|
+
var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
921
920
|
/**
|
|
922
921
|
* @@@
|
|
923
922
|
*
|
|
@@ -1760,7 +1759,7 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
1760
1759
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1761
1760
|
__extends(NotYetImplementedError, _super);
|
|
1762
1761
|
function NotYetImplementedError(message) {
|
|
1763
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on
|
|
1762
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
|
|
1764
1763
|
_this.name = 'NotYetImplementedError';
|
|
1765
1764
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1766
1765
|
return _this;
|
|
@@ -8619,6 +8618,55 @@ var HIGH_LEVEL_ABSTRACTIONS = [
|
|
|
8619
8618
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
8620
8619
|
// <- TODO: [🏥] DRY
|
|
8621
8620
|
|
|
8621
|
+
/**
|
|
8622
|
+
* Removes Markdown (or HTML) comments
|
|
8623
|
+
*
|
|
8624
|
+
* @param {string} content - The string to remove comments from.
|
|
8625
|
+
* @returns {string} The input string with all comments removed.
|
|
8626
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
8627
|
+
*/
|
|
8628
|
+
function removeMarkdownComments(content) {
|
|
8629
|
+
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
8630
|
+
}
|
|
8631
|
+
|
|
8632
|
+
/**
|
|
8633
|
+
* @@@
|
|
8634
|
+
*
|
|
8635
|
+
* @public exported from `@promptbook/editable`
|
|
8636
|
+
*/
|
|
8637
|
+
function isFlatPipeline(pipelineString) {
|
|
8638
|
+
pipelineString = removeMarkdownComments(pipelineString);
|
|
8639
|
+
pipelineString = spaceTrim(pipelineString);
|
|
8640
|
+
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
8641
|
+
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
8642
|
+
// TODO: Also (double)check
|
|
8643
|
+
// > const usedCommands
|
|
8644
|
+
// > const isBlocksUsed
|
|
8645
|
+
// > const returnStatementCount
|
|
8646
|
+
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
8647
|
+
return isFlat;
|
|
8648
|
+
}
|
|
8649
|
+
|
|
8650
|
+
/**
|
|
8651
|
+
* @@@
|
|
8652
|
+
*
|
|
8653
|
+
* @public exported from `@promptbook/editable`
|
|
8654
|
+
*/
|
|
8655
|
+
function deflatePipeline(pipelineString) {
|
|
8656
|
+
if (!isFlatPipeline(pipelineString)) {
|
|
8657
|
+
return pipelineString;
|
|
8658
|
+
}
|
|
8659
|
+
var pipelineStringLines = pipelineString.split('\n');
|
|
8660
|
+
var returnStatement = pipelineStringLines.pop();
|
|
8661
|
+
var prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
8662
|
+
pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
|
|
8663
|
+
// <- TODO: Maybe use book` notation
|
|
8664
|
+
return pipelineString;
|
|
8665
|
+
}
|
|
8666
|
+
/**
|
|
8667
|
+
* TODO: Unit test
|
|
8668
|
+
*/
|
|
8669
|
+
|
|
8622
8670
|
/**
|
|
8623
8671
|
* Utility function to extract all list items from markdown
|
|
8624
8672
|
*
|
|
@@ -8834,17 +8882,6 @@ function flattenMarkdown(markdown) {
|
|
|
8834
8882
|
* NOW we are working just with markdown string and its good enough
|
|
8835
8883
|
*/
|
|
8836
8884
|
|
|
8837
|
-
/**
|
|
8838
|
-
* Removes Markdown (or HTML) comments
|
|
8839
|
-
*
|
|
8840
|
-
* @param {string} content - The string to remove comments from.
|
|
8841
|
-
* @returns {string} The input string with all comments removed.
|
|
8842
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
8843
|
-
*/
|
|
8844
|
-
function removeMarkdownComments(content) {
|
|
8845
|
-
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
8846
|
-
}
|
|
8847
|
-
|
|
8848
8885
|
/**
|
|
8849
8886
|
* @@@
|
|
8850
8887
|
*
|
|
@@ -8929,26 +8966,9 @@ function parsePipeline(pipelineString) {
|
|
|
8929
8966
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
8930
8967
|
pipelineString = spaceTrim$1(pipelineString);
|
|
8931
8968
|
// <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
8969
|
+
pipelineString = deflatePipeline(pipelineString);
|
|
8932
8970
|
// ==============
|
|
8933
|
-
// Note: 1️⃣◽2️⃣
|
|
8934
|
-
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
8935
|
-
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
8936
|
-
// TODO: Also (double)check
|
|
8937
|
-
// > const usedCommands
|
|
8938
|
-
// > const isBlocksUsed
|
|
8939
|
-
// > const returnStatementCount
|
|
8940
|
-
var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
8941
|
-
// console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
|
|
8942
|
-
if (isFlatPipeline) {
|
|
8943
|
-
var pipelineStringLines = pipelineString.split('\n');
|
|
8944
|
-
var returnStatement_1 = pipelineStringLines.pop();
|
|
8945
|
-
var prompt_1 = spaceTrim$1(pipelineStringLines.join('\n'));
|
|
8946
|
-
pipelineString = validatePipelineString(spaceTrim$1(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
|
|
8947
|
-
// <- TODO: Maybe use book` notation
|
|
8948
|
-
// console.log(pipelineString);
|
|
8949
|
-
}
|
|
8950
|
-
// ==============
|
|
8951
|
-
// Note: 1️⃣◽3️⃣ Parse the markdown
|
|
8971
|
+
// Note: 1️⃣◽2️⃣ Parse the markdown
|
|
8952
8972
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8953
8973
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8954
8974
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
@@ -9406,30 +9426,187 @@ function compilePipeline(pipelineString, tools, options) {
|
|
|
9406
9426
|
*/
|
|
9407
9427
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
9408
9428
|
|
|
9409
|
-
|
|
9410
|
-
|
|
9429
|
+
/**
|
|
9430
|
+
* Normalize options for `execCommand` and `execCommands`
|
|
9431
|
+
*
|
|
9432
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
9433
|
+
*
|
|
9434
|
+
* @private internal utility of `execCommand` and `execCommands`
|
|
9435
|
+
*/
|
|
9436
|
+
function $execCommandNormalizeOptions(options) {
|
|
9437
|
+
var _a;
|
|
9438
|
+
var _b, _c, _d, _e;
|
|
9439
|
+
var command;
|
|
9440
|
+
var cwd;
|
|
9441
|
+
var crashOnError;
|
|
9442
|
+
var args = [];
|
|
9443
|
+
var timeout;
|
|
9444
|
+
var isVerbose;
|
|
9445
|
+
if (typeof options === 'string') {
|
|
9446
|
+
// TODO: [1] DRY default values
|
|
9447
|
+
command = options;
|
|
9448
|
+
cwd = process.cwd();
|
|
9449
|
+
crashOnError = true;
|
|
9450
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
9451
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
9452
|
+
}
|
|
9453
|
+
else {
|
|
9454
|
+
/*
|
|
9455
|
+
TODO:
|
|
9456
|
+
if ((options as any).commands !== undefined) {
|
|
9457
|
+
commands = (options as any).commands;
|
|
9458
|
+
} else {
|
|
9459
|
+
commands = [(options as any).command];
|
|
9460
|
+
}
|
|
9461
|
+
*/
|
|
9462
|
+
// TODO: [1] DRY default values
|
|
9463
|
+
command = options.command;
|
|
9464
|
+
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
9465
|
+
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
9466
|
+
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
9467
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
9468
|
+
}
|
|
9469
|
+
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
9470
|
+
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
9471
|
+
.map(function (_a) {
|
|
9472
|
+
var _b = __read(_a, 1), match = _b[0];
|
|
9473
|
+
return match;
|
|
9474
|
+
})
|
|
9475
|
+
.filter(function (arg) { return arg !== ''; });
|
|
9476
|
+
if (_.length > 1) {
|
|
9477
|
+
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
9478
|
+
}
|
|
9479
|
+
if (options.args) {
|
|
9480
|
+
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
9481
|
+
}
|
|
9482
|
+
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
9483
|
+
if (['ts-node'].includes(humanReadableCommand)) {
|
|
9484
|
+
humanReadableCommand += " ".concat(args[1]);
|
|
9485
|
+
}
|
|
9486
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
9487
|
+
command = "".concat(command, ".cmd");
|
|
9488
|
+
}
|
|
9489
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
9490
|
+
}
|
|
9491
|
+
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
9492
|
+
|
|
9493
|
+
/**
|
|
9494
|
+
* Run one command in a shell
|
|
9495
|
+
*
|
|
9496
|
+
*
|
|
9497
|
+
* Note: There are 2 similar functions in the codebase:
|
|
9498
|
+
* - `$execCommand` which runs a single command
|
|
9499
|
+
* - `$execCommands` which runs multiple commands
|
|
9500
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
9501
|
+
*
|
|
9502
|
+
* @public exported from `@promptbook/node`
|
|
9503
|
+
*/
|
|
9504
|
+
function $execCommand(options) {
|
|
9505
|
+
if (!$isRunningInNode()) {
|
|
9506
|
+
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
9507
|
+
}
|
|
9508
|
+
return new Promise(function (resolve, reject) {
|
|
9509
|
+
// eslint-disable-next-line prefer-const
|
|
9510
|
+
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;
|
|
9511
|
+
if (timeout !== Infinity) {
|
|
9512
|
+
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
9513
|
+
forTime(timeout).then(function () {
|
|
9514
|
+
if (crashOnError) {
|
|
9515
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
9516
|
+
}
|
|
9517
|
+
else {
|
|
9518
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
9519
|
+
resolve('Command exceeded time limit');
|
|
9520
|
+
}
|
|
9521
|
+
});
|
|
9522
|
+
}
|
|
9523
|
+
if (isVerbose) {
|
|
9524
|
+
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
9525
|
+
}
|
|
9526
|
+
try {
|
|
9527
|
+
var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
|
|
9528
|
+
if (isVerbose) {
|
|
9529
|
+
commandProcess.on('message', function (message) {
|
|
9530
|
+
console.info({ message: message });
|
|
9531
|
+
});
|
|
9532
|
+
}
|
|
9533
|
+
var output_1 = [];
|
|
9534
|
+
commandProcess.stdout.on('data', function (stdout) {
|
|
9535
|
+
output_1.push(stdout.toString());
|
|
9536
|
+
if (isVerbose) {
|
|
9537
|
+
console.info(stdout.toString());
|
|
9538
|
+
}
|
|
9539
|
+
});
|
|
9540
|
+
commandProcess.stderr.on('data', function (stderr) {
|
|
9541
|
+
output_1.push(stderr.toString());
|
|
9542
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
9543
|
+
console.warn(stderr.toString());
|
|
9544
|
+
}
|
|
9545
|
+
});
|
|
9546
|
+
var finishWithCode = function (code) {
|
|
9547
|
+
if (code !== 0) {
|
|
9548
|
+
if (crashOnError) {
|
|
9549
|
+
reject(new Error(output_1.join('\n').trim() ||
|
|
9550
|
+
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
9551
|
+
}
|
|
9552
|
+
else {
|
|
9553
|
+
if (isVerbose) {
|
|
9554
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
9555
|
+
}
|
|
9556
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
9557
|
+
}
|
|
9558
|
+
}
|
|
9559
|
+
else {
|
|
9560
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
9561
|
+
}
|
|
9562
|
+
};
|
|
9563
|
+
commandProcess.on('close', finishWithCode);
|
|
9564
|
+
commandProcess.on('exit', finishWithCode);
|
|
9565
|
+
commandProcess.on('disconnect', function () {
|
|
9566
|
+
// Note: Unexpected disconnection should always result in rejection
|
|
9567
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
9568
|
+
});
|
|
9569
|
+
commandProcess.on('error', function (error) {
|
|
9570
|
+
if (crashOnError) {
|
|
9571
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
9572
|
+
}
|
|
9573
|
+
else {
|
|
9574
|
+
if (isVerbose) {
|
|
9575
|
+
console.warn(error);
|
|
9576
|
+
}
|
|
9577
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
9578
|
+
}
|
|
9579
|
+
});
|
|
9580
|
+
}
|
|
9581
|
+
catch (error) {
|
|
9582
|
+
// Note: Unexpected error in sync code should always result in rejection
|
|
9583
|
+
reject(error);
|
|
9584
|
+
}
|
|
9585
|
+
});
|
|
9586
|
+
}
|
|
9587
|
+
/**
|
|
9588
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9589
|
+
*/
|
|
9590
|
+
|
|
9411
9591
|
/**
|
|
9412
9592
|
* @@@
|
|
9413
9593
|
*
|
|
9414
9594
|
* @private within the repository
|
|
9415
9595
|
*/
|
|
9416
9596
|
function locateAppOnLinux(_a) {
|
|
9417
|
-
var
|
|
9597
|
+
var linuxWhich = _a.linuxWhich;
|
|
9418
9598
|
return __awaiter(this, void 0, void 0, function () {
|
|
9419
|
-
var
|
|
9420
|
-
return __generator(this, function (
|
|
9421
|
-
switch (
|
|
9599
|
+
var result, error_1;
|
|
9600
|
+
return __generator(this, function (_b) {
|
|
9601
|
+
switch (_b.label) {
|
|
9422
9602
|
case 0:
|
|
9423
|
-
|
|
9424
|
-
return [4 /*yield*/,
|
|
9603
|
+
_b.trys.push([0, 2, , 3]);
|
|
9604
|
+
return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
|
|
9425
9605
|
case 1:
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
return [2 /*return*/, stdout.trim()];
|
|
9429
|
-
}
|
|
9430
|
-
throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
|
|
9606
|
+
result = _b.sent();
|
|
9607
|
+
return [2 /*return*/, result.trim()];
|
|
9431
9608
|
case 2:
|
|
9432
|
-
error_1 =
|
|
9609
|
+
error_1 = _b.sent();
|
|
9433
9610
|
if (!(error_1 instanceof Error)) {
|
|
9434
9611
|
throw error_1;
|
|
9435
9612
|
}
|
|
@@ -9499,43 +9676,41 @@ function isExecutable(path, fs) {
|
|
|
9499
9676
|
// @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
|
|
9500
9677
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9501
9678
|
var userhome = require('userhome');
|
|
9502
|
-
// Note: We want to use the `exec` as async function
|
|
9503
|
-
var exec = promisify(exec$2);
|
|
9504
9679
|
/**
|
|
9505
9680
|
* @@@
|
|
9506
9681
|
*
|
|
9507
9682
|
* @private within the repository
|
|
9508
9683
|
*/
|
|
9509
9684
|
function locateAppOnMacOs(_a) {
|
|
9510
|
-
var
|
|
9685
|
+
var macOsName = _a.macOsName;
|
|
9511
9686
|
return __awaiter(this, void 0, void 0, function () {
|
|
9512
|
-
var toExec, regPath, altPath,
|
|
9513
|
-
return __generator(this, function (
|
|
9514
|
-
switch (
|
|
9687
|
+
var toExec, regPath, altPath, result, error_1;
|
|
9688
|
+
return __generator(this, function (_b) {
|
|
9689
|
+
switch (_b.label) {
|
|
9515
9690
|
case 0:
|
|
9516
|
-
|
|
9691
|
+
_b.trys.push([0, 6, , 7]);
|
|
9517
9692
|
toExec = "/Contents/MacOS/".concat(macOsName);
|
|
9518
9693
|
regPath = "/Applications/".concat(macOsName, ".app") + toExec;
|
|
9519
9694
|
altPath = userhome(regPath.slice(1));
|
|
9520
9695
|
return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
|
|
9521
9696
|
case 1:
|
|
9522
|
-
if (!
|
|
9697
|
+
if (!_b.sent()) return [3 /*break*/, 2];
|
|
9523
9698
|
return [2 /*return*/, regPath];
|
|
9524
9699
|
case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
|
|
9525
9700
|
case 3:
|
|
9526
|
-
if (
|
|
9701
|
+
if (_b.sent()) {
|
|
9527
9702
|
return [2 /*return*/, altPath];
|
|
9528
9703
|
}
|
|
9529
|
-
|
|
9530
|
-
case 4: return [4 /*yield*/,
|
|
9704
|
+
_b.label = 4;
|
|
9705
|
+
case 4: return [4 /*yield*/, $execCommand({
|
|
9706
|
+
crashOnError: true,
|
|
9707
|
+
command: "mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"),
|
|
9708
|
+
})];
|
|
9531
9709
|
case 5:
|
|
9532
|
-
|
|
9533
|
-
|
|
9534
|
-
return [2 /*return*/, stdout.trim() + toExec];
|
|
9535
|
-
}
|
|
9536
|
-
throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
|
|
9710
|
+
result = _b.sent();
|
|
9711
|
+
return [2 /*return*/, result.trim() + toExec];
|
|
9537
9712
|
case 6:
|
|
9538
|
-
error_1 =
|
|
9713
|
+
error_1 = _b.sent();
|
|
9539
9714
|
if (!(error_1 instanceof Error)) {
|
|
9540
9715
|
throw error_1;
|
|
9541
9716
|
}
|
|
@@ -9636,7 +9811,7 @@ function locateApp(options) {
|
|
|
9636
9811
|
}
|
|
9637
9812
|
else if (process.platform === 'darwin') {
|
|
9638
9813
|
if (macOsName) {
|
|
9639
|
-
return locateAppOnMacOs({
|
|
9814
|
+
return locateAppOnMacOs({ macOsName: macOsName });
|
|
9640
9815
|
}
|
|
9641
9816
|
else {
|
|
9642
9817
|
throw new Error("".concat(appName, " is not available on macOS."));
|
|
@@ -9644,7 +9819,7 @@ function locateApp(options) {
|
|
|
9644
9819
|
}
|
|
9645
9820
|
else {
|
|
9646
9821
|
if (linuxWhich) {
|
|
9647
|
-
return locateAppOnLinux({
|
|
9822
|
+
return locateAppOnLinux({ linuxWhich: linuxWhich });
|
|
9648
9823
|
}
|
|
9649
9824
|
else {
|
|
9650
9825
|
throw new Error("".concat(appName, " is not available on Linux."));
|
|
@@ -11190,168 +11365,6 @@ var FileCacheStorage = /** @class */ (function () {
|
|
|
11190
11365
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
11191
11366
|
*/
|
|
11192
11367
|
|
|
11193
|
-
/**
|
|
11194
|
-
* Normalize options for `execCommand` and `execCommands`
|
|
11195
|
-
*
|
|
11196
|
-
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
11197
|
-
*
|
|
11198
|
-
* @private internal utility of `execCommand` and `execCommands`
|
|
11199
|
-
*/
|
|
11200
|
-
function $execCommandNormalizeOptions(options) {
|
|
11201
|
-
var _a;
|
|
11202
|
-
var _b, _c, _d, _e;
|
|
11203
|
-
var command;
|
|
11204
|
-
var cwd;
|
|
11205
|
-
var crashOnError;
|
|
11206
|
-
var args = [];
|
|
11207
|
-
var timeout;
|
|
11208
|
-
var isVerbose;
|
|
11209
|
-
if (typeof options === 'string') {
|
|
11210
|
-
// TODO: [1] DRY default values
|
|
11211
|
-
command = options;
|
|
11212
|
-
cwd = process.cwd();
|
|
11213
|
-
crashOnError = true;
|
|
11214
|
-
timeout = Infinity; // <- TODO: [⏳]
|
|
11215
|
-
isVerbose = DEFAULT_IS_VERBOSE;
|
|
11216
|
-
}
|
|
11217
|
-
else {
|
|
11218
|
-
/*
|
|
11219
|
-
TODO:
|
|
11220
|
-
if ((options as any).commands !== undefined) {
|
|
11221
|
-
commands = (options as any).commands;
|
|
11222
|
-
} else {
|
|
11223
|
-
commands = [(options as any).command];
|
|
11224
|
-
}
|
|
11225
|
-
*/
|
|
11226
|
-
// TODO: [1] DRY default values
|
|
11227
|
-
command = options.command;
|
|
11228
|
-
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
11229
|
-
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
11230
|
-
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
11231
|
-
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
11232
|
-
}
|
|
11233
|
-
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
11234
|
-
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
11235
|
-
.map(function (_a) {
|
|
11236
|
-
var _b = __read(_a, 1), match = _b[0];
|
|
11237
|
-
return match;
|
|
11238
|
-
})
|
|
11239
|
-
.filter(function (arg) { return arg !== ''; });
|
|
11240
|
-
if (_.length > 1) {
|
|
11241
|
-
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
11242
|
-
}
|
|
11243
|
-
if (options.args) {
|
|
11244
|
-
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
11245
|
-
}
|
|
11246
|
-
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
11247
|
-
if (['ts-node'].includes(humanReadableCommand)) {
|
|
11248
|
-
humanReadableCommand += " ".concat(args[1]);
|
|
11249
|
-
}
|
|
11250
|
-
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
11251
|
-
command = "".concat(command, ".cmd");
|
|
11252
|
-
}
|
|
11253
|
-
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
11254
|
-
}
|
|
11255
|
-
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
11256
|
-
|
|
11257
|
-
/**
|
|
11258
|
-
* Run one command in a shell
|
|
11259
|
-
*
|
|
11260
|
-
*
|
|
11261
|
-
* Note: There are 2 similar functions in the codebase:
|
|
11262
|
-
* - `$execCommand` which runs a single command
|
|
11263
|
-
* - `$execCommands` which runs multiple commands
|
|
11264
|
-
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
11265
|
-
*
|
|
11266
|
-
* @public exported from `@promptbook/node`
|
|
11267
|
-
*/
|
|
11268
|
-
function $execCommand(options) {
|
|
11269
|
-
if (!$isRunningInNode()) {
|
|
11270
|
-
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
11271
|
-
}
|
|
11272
|
-
return new Promise(function (resolve, reject) {
|
|
11273
|
-
// eslint-disable-next-line prefer-const
|
|
11274
|
-
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;
|
|
11275
|
-
if (timeout !== Infinity) {
|
|
11276
|
-
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
11277
|
-
forTime(timeout).then(function () {
|
|
11278
|
-
if (crashOnError) {
|
|
11279
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
11280
|
-
}
|
|
11281
|
-
else {
|
|
11282
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
11283
|
-
resolve('Command exceeded time limit');
|
|
11284
|
-
}
|
|
11285
|
-
});
|
|
11286
|
-
}
|
|
11287
|
-
if (isVerbose) {
|
|
11288
|
-
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
11289
|
-
}
|
|
11290
|
-
try {
|
|
11291
|
-
var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
|
|
11292
|
-
if (isVerbose) {
|
|
11293
|
-
commandProcess.on('message', function (message) {
|
|
11294
|
-
console.info({ message: message });
|
|
11295
|
-
});
|
|
11296
|
-
}
|
|
11297
|
-
var output_1 = [];
|
|
11298
|
-
commandProcess.stdout.on('data', function (stdout) {
|
|
11299
|
-
output_1.push(stdout.toString());
|
|
11300
|
-
if (isVerbose) {
|
|
11301
|
-
console.info(stdout.toString());
|
|
11302
|
-
}
|
|
11303
|
-
});
|
|
11304
|
-
commandProcess.stderr.on('data', function (stderr) {
|
|
11305
|
-
output_1.push(stderr.toString());
|
|
11306
|
-
if (isVerbose && stderr.toString().trim()) {
|
|
11307
|
-
console.warn(stderr.toString());
|
|
11308
|
-
}
|
|
11309
|
-
});
|
|
11310
|
-
var finishWithCode = function (code) {
|
|
11311
|
-
if (code !== 0) {
|
|
11312
|
-
if (crashOnError) {
|
|
11313
|
-
reject(new Error(output_1.join('\n').trim() ||
|
|
11314
|
-
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
11315
|
-
}
|
|
11316
|
-
else {
|
|
11317
|
-
if (isVerbose) {
|
|
11318
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
11319
|
-
}
|
|
11320
|
-
resolve(spaceTrim$1(output_1.join('\n')));
|
|
11321
|
-
}
|
|
11322
|
-
}
|
|
11323
|
-
else {
|
|
11324
|
-
resolve(spaceTrim$1(output_1.join('\n')));
|
|
11325
|
-
}
|
|
11326
|
-
};
|
|
11327
|
-
commandProcess.on('close', finishWithCode);
|
|
11328
|
-
commandProcess.on('exit', finishWithCode);
|
|
11329
|
-
commandProcess.on('disconnect', function () {
|
|
11330
|
-
// Note: Unexpected disconnection should always result in rejection
|
|
11331
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
11332
|
-
});
|
|
11333
|
-
commandProcess.on('error', function (error) {
|
|
11334
|
-
if (crashOnError) {
|
|
11335
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
11336
|
-
}
|
|
11337
|
-
else {
|
|
11338
|
-
if (isVerbose) {
|
|
11339
|
-
console.warn(error);
|
|
11340
|
-
}
|
|
11341
|
-
resolve(spaceTrim$1(output_1.join('\n')));
|
|
11342
|
-
}
|
|
11343
|
-
});
|
|
11344
|
-
}
|
|
11345
|
-
catch (error) {
|
|
11346
|
-
// Note: Unexpected error in sync code should always result in rejection
|
|
11347
|
-
reject(error);
|
|
11348
|
-
}
|
|
11349
|
-
});
|
|
11350
|
-
}
|
|
11351
|
-
/**
|
|
11352
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
11353
|
-
*/
|
|
11354
|
-
|
|
11355
11368
|
/**
|
|
11356
11369
|
* Run multiple commands in a shell in sequence
|
|
11357
11370
|
*
|