@promptbook/cli 0.84.0-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 +1 -0
- package/esm/index.es.js +611 -208
- 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/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/package.json +3 -2
- package/umd/index.umd.js +617 -209
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('path'), require('fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('mime-types'), require('child_process'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'path', 'fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'mime-types', 'child_process', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.mimeTypes, global.child_process, global.
|
|
5
|
-
})(this, (function (exports, colors, commander, spaceTrim, waitasecond, path, promises, hexEncoder, sha256, dotenv, prettier, parserHtml, papaparse, cryptoJs, mimeTypes, child_process,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('path'), require('fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('mime-types'), require('child_process'), require('glob-promise'), require('prompts'), require('moment'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('@mozilla/readability'), require('jsdom'), require('showdown')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'path', 'fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'mime-types', 'child_process', 'glob-promise', 'prompts', 'moment', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai', '@mozilla/readability', 'jsdom', 'showdown'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.mimeTypes, global.child_process, global.glob, global.prompts, global.moment, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI, global.readability, global.jsdom, global.showdown));
|
|
5
|
+
})(this, (function (exports, colors, commander, spaceTrim, waitasecond, path, promises, hexEncoder, sha256, dotenv, prettier, parserHtml, papaparse, cryptoJs, mimeTypes, child_process, glob, prompts, moment, socket_ioClient, Anthropic, openai, OpenAI, readability, jsdom, showdown) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @generated
|
|
52
52
|
* @see https://github.com/webgptorg/promptbook
|
|
53
53
|
*/
|
|
54
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
54
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-9';
|
|
55
55
|
/**
|
|
56
56
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
57
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -215,7 +215,7 @@
|
|
|
215
215
|
*
|
|
216
216
|
* @public exported from `@promptbook/core`
|
|
217
217
|
*/
|
|
218
|
-
var ADMIN_EMAIL = '
|
|
218
|
+
var ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
219
219
|
/**
|
|
220
220
|
* Name of the responsible person for the Promptbook on GitHub
|
|
221
221
|
*
|
|
@@ -825,7 +825,7 @@
|
|
|
825
825
|
*
|
|
826
826
|
* @private within the repository
|
|
827
827
|
*/
|
|
828
|
-
var REPLACING_NONCE = '
|
|
828
|
+
var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
829
829
|
/**
|
|
830
830
|
* @@@
|
|
831
831
|
*
|
|
@@ -1928,7 +1928,7 @@
|
|
|
1928
1928
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1929
1929
|
__extends(NotYetImplementedError, _super);
|
|
1930
1930
|
function NotYetImplementedError(message) {
|
|
1931
|
-
var _this = _super.call(this, spaceTrim.spaceTrim(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
|
|
1931
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(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;
|
|
1932
1932
|
_this.name = 'NotYetImplementedError';
|
|
1933
1933
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1934
1934
|
return _this;
|
|
@@ -10405,30 +10405,187 @@
|
|
|
10405
10405
|
* TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
|
|
10406
10406
|
*/
|
|
10407
10407
|
|
|
10408
|
-
|
|
10409
|
-
|
|
10408
|
+
/**
|
|
10409
|
+
* Normalize options for `execCommand` and `execCommands`
|
|
10410
|
+
*
|
|
10411
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
10412
|
+
*
|
|
10413
|
+
* @private internal utility of `execCommand` and `execCommands`
|
|
10414
|
+
*/
|
|
10415
|
+
function $execCommandNormalizeOptions(options) {
|
|
10416
|
+
var _a;
|
|
10417
|
+
var _b, _c, _d, _e;
|
|
10418
|
+
var command;
|
|
10419
|
+
var cwd;
|
|
10420
|
+
var crashOnError;
|
|
10421
|
+
var args = [];
|
|
10422
|
+
var timeout;
|
|
10423
|
+
var isVerbose;
|
|
10424
|
+
if (typeof options === 'string') {
|
|
10425
|
+
// TODO: [1] DRY default values
|
|
10426
|
+
command = options;
|
|
10427
|
+
cwd = process.cwd();
|
|
10428
|
+
crashOnError = true;
|
|
10429
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
10430
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
10431
|
+
}
|
|
10432
|
+
else {
|
|
10433
|
+
/*
|
|
10434
|
+
TODO:
|
|
10435
|
+
if ((options as any).commands !== undefined) {
|
|
10436
|
+
commands = (options as any).commands;
|
|
10437
|
+
} else {
|
|
10438
|
+
commands = [(options as any).command];
|
|
10439
|
+
}
|
|
10440
|
+
*/
|
|
10441
|
+
// TODO: [1] DRY default values
|
|
10442
|
+
command = options.command;
|
|
10443
|
+
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
10444
|
+
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
10445
|
+
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
10446
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
10447
|
+
}
|
|
10448
|
+
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
10449
|
+
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
10450
|
+
.map(function (_a) {
|
|
10451
|
+
var _b = __read(_a, 1), match = _b[0];
|
|
10452
|
+
return match;
|
|
10453
|
+
})
|
|
10454
|
+
.filter(function (arg) { return arg !== ''; });
|
|
10455
|
+
if (_.length > 1) {
|
|
10456
|
+
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
10457
|
+
}
|
|
10458
|
+
if (options.args) {
|
|
10459
|
+
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
10460
|
+
}
|
|
10461
|
+
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
10462
|
+
if (['ts-node'].includes(humanReadableCommand)) {
|
|
10463
|
+
humanReadableCommand += " ".concat(args[1]);
|
|
10464
|
+
}
|
|
10465
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
10466
|
+
command = "".concat(command, ".cmd");
|
|
10467
|
+
}
|
|
10468
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
10469
|
+
}
|
|
10470
|
+
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
10471
|
+
|
|
10472
|
+
/**
|
|
10473
|
+
* Run one command in a shell
|
|
10474
|
+
*
|
|
10475
|
+
*
|
|
10476
|
+
* Note: There are 2 similar functions in the codebase:
|
|
10477
|
+
* - `$execCommand` which runs a single command
|
|
10478
|
+
* - `$execCommands` which runs multiple commands
|
|
10479
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
10480
|
+
*
|
|
10481
|
+
* @public exported from `@promptbook/node`
|
|
10482
|
+
*/
|
|
10483
|
+
function $execCommand(options) {
|
|
10484
|
+
if (!$isRunningInNode()) {
|
|
10485
|
+
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
10486
|
+
}
|
|
10487
|
+
return new Promise(function (resolve, reject) {
|
|
10488
|
+
// eslint-disable-next-line prefer-const
|
|
10489
|
+
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;
|
|
10490
|
+
if (timeout !== Infinity) {
|
|
10491
|
+
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
10492
|
+
waitasecond.forTime(timeout).then(function () {
|
|
10493
|
+
if (crashOnError) {
|
|
10494
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
10495
|
+
}
|
|
10496
|
+
else {
|
|
10497
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
10498
|
+
resolve('Command exceeded time limit');
|
|
10499
|
+
}
|
|
10500
|
+
});
|
|
10501
|
+
}
|
|
10502
|
+
if (isVerbose) {
|
|
10503
|
+
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
10504
|
+
}
|
|
10505
|
+
try {
|
|
10506
|
+
var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
10507
|
+
if (isVerbose) {
|
|
10508
|
+
commandProcess.on('message', function (message) {
|
|
10509
|
+
console.info({ message: message });
|
|
10510
|
+
});
|
|
10511
|
+
}
|
|
10512
|
+
var output_1 = [];
|
|
10513
|
+
commandProcess.stdout.on('data', function (stdout) {
|
|
10514
|
+
output_1.push(stdout.toString());
|
|
10515
|
+
if (isVerbose) {
|
|
10516
|
+
console.info(stdout.toString());
|
|
10517
|
+
}
|
|
10518
|
+
});
|
|
10519
|
+
commandProcess.stderr.on('data', function (stderr) {
|
|
10520
|
+
output_1.push(stderr.toString());
|
|
10521
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
10522
|
+
console.warn(stderr.toString());
|
|
10523
|
+
}
|
|
10524
|
+
});
|
|
10525
|
+
var finishWithCode = function (code) {
|
|
10526
|
+
if (code !== 0) {
|
|
10527
|
+
if (crashOnError) {
|
|
10528
|
+
reject(new Error(output_1.join('\n').trim() ||
|
|
10529
|
+
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
10530
|
+
}
|
|
10531
|
+
else {
|
|
10532
|
+
if (isVerbose) {
|
|
10533
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
10534
|
+
}
|
|
10535
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10536
|
+
}
|
|
10537
|
+
}
|
|
10538
|
+
else {
|
|
10539
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10540
|
+
}
|
|
10541
|
+
};
|
|
10542
|
+
commandProcess.on('close', finishWithCode);
|
|
10543
|
+
commandProcess.on('exit', finishWithCode);
|
|
10544
|
+
commandProcess.on('disconnect', function () {
|
|
10545
|
+
// Note: Unexpected disconnection should always result in rejection
|
|
10546
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
10547
|
+
});
|
|
10548
|
+
commandProcess.on('error', function (error) {
|
|
10549
|
+
if (crashOnError) {
|
|
10550
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
10551
|
+
}
|
|
10552
|
+
else {
|
|
10553
|
+
if (isVerbose) {
|
|
10554
|
+
console.warn(error);
|
|
10555
|
+
}
|
|
10556
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10557
|
+
}
|
|
10558
|
+
});
|
|
10559
|
+
}
|
|
10560
|
+
catch (error) {
|
|
10561
|
+
// Note: Unexpected error in sync code should always result in rejection
|
|
10562
|
+
reject(error);
|
|
10563
|
+
}
|
|
10564
|
+
});
|
|
10565
|
+
}
|
|
10566
|
+
/**
|
|
10567
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
10568
|
+
*/
|
|
10569
|
+
|
|
10410
10570
|
/**
|
|
10411
10571
|
* @@@
|
|
10412
10572
|
*
|
|
10413
10573
|
* @private within the repository
|
|
10414
10574
|
*/
|
|
10415
10575
|
function locateAppOnLinux(_a) {
|
|
10416
|
-
var
|
|
10576
|
+
var linuxWhich = _a.linuxWhich;
|
|
10417
10577
|
return __awaiter(this, void 0, void 0, function () {
|
|
10418
|
-
var
|
|
10419
|
-
return __generator(this, function (
|
|
10420
|
-
switch (
|
|
10578
|
+
var result, error_1;
|
|
10579
|
+
return __generator(this, function (_b) {
|
|
10580
|
+
switch (_b.label) {
|
|
10421
10581
|
case 0:
|
|
10422
|
-
|
|
10423
|
-
return [4 /*yield*/,
|
|
10582
|
+
_b.trys.push([0, 2, , 3]);
|
|
10583
|
+
return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
|
|
10424
10584
|
case 1:
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
return [2 /*return*/, stdout.trim()];
|
|
10428
|
-
}
|
|
10429
|
-
throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
|
|
10585
|
+
result = _b.sent();
|
|
10586
|
+
return [2 /*return*/, result.trim()];
|
|
10430
10587
|
case 2:
|
|
10431
|
-
error_1 =
|
|
10588
|
+
error_1 = _b.sent();
|
|
10432
10589
|
if (!(error_1 instanceof Error)) {
|
|
10433
10590
|
throw error_1;
|
|
10434
10591
|
}
|
|
@@ -10475,43 +10632,41 @@
|
|
|
10475
10632
|
// @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
|
|
10476
10633
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10477
10634
|
var userhome = require('userhome');
|
|
10478
|
-
// Note: We want to use the `exec` as async function
|
|
10479
|
-
var exec = util.promisify(child_process.exec);
|
|
10480
10635
|
/**
|
|
10481
10636
|
* @@@
|
|
10482
10637
|
*
|
|
10483
10638
|
* @private within the repository
|
|
10484
10639
|
*/
|
|
10485
10640
|
function locateAppOnMacOs(_a) {
|
|
10486
|
-
var
|
|
10641
|
+
var macOsName = _a.macOsName;
|
|
10487
10642
|
return __awaiter(this, void 0, void 0, function () {
|
|
10488
|
-
var toExec, regPath, altPath,
|
|
10489
|
-
return __generator(this, function (
|
|
10490
|
-
switch (
|
|
10643
|
+
var toExec, regPath, altPath, result, error_1;
|
|
10644
|
+
return __generator(this, function (_b) {
|
|
10645
|
+
switch (_b.label) {
|
|
10491
10646
|
case 0:
|
|
10492
|
-
|
|
10647
|
+
_b.trys.push([0, 6, , 7]);
|
|
10493
10648
|
toExec = "/Contents/MacOS/".concat(macOsName);
|
|
10494
10649
|
regPath = "/Applications/".concat(macOsName, ".app") + toExec;
|
|
10495
10650
|
altPath = userhome(regPath.slice(1));
|
|
10496
10651
|
return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
|
|
10497
10652
|
case 1:
|
|
10498
|
-
if (!
|
|
10653
|
+
if (!_b.sent()) return [3 /*break*/, 2];
|
|
10499
10654
|
return [2 /*return*/, regPath];
|
|
10500
10655
|
case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
|
|
10501
10656
|
case 3:
|
|
10502
|
-
if (
|
|
10657
|
+
if (_b.sent()) {
|
|
10503
10658
|
return [2 /*return*/, altPath];
|
|
10504
10659
|
}
|
|
10505
|
-
|
|
10506
|
-
case 4: return [4 /*yield*/,
|
|
10660
|
+
_b.label = 4;
|
|
10661
|
+
case 4: return [4 /*yield*/, $execCommand({
|
|
10662
|
+
crashOnError: true,
|
|
10663
|
+
command: "mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"),
|
|
10664
|
+
})];
|
|
10507
10665
|
case 5:
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
return [2 /*return*/, stdout.trim() + toExec];
|
|
10511
|
-
}
|
|
10512
|
-
throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
|
|
10666
|
+
result = _b.sent();
|
|
10667
|
+
return [2 /*return*/, result.trim() + toExec];
|
|
10513
10668
|
case 6:
|
|
10514
|
-
error_1 =
|
|
10669
|
+
error_1 = _b.sent();
|
|
10515
10670
|
if (!(error_1 instanceof Error)) {
|
|
10516
10671
|
throw error_1;
|
|
10517
10672
|
}
|
|
@@ -10612,7 +10767,7 @@
|
|
|
10612
10767
|
}
|
|
10613
10768
|
else if (process.platform === 'darwin') {
|
|
10614
10769
|
if (macOsName) {
|
|
10615
|
-
return locateAppOnMacOs({
|
|
10770
|
+
return locateAppOnMacOs({ macOsName: macOsName });
|
|
10616
10771
|
}
|
|
10617
10772
|
else {
|
|
10618
10773
|
throw new Error("".concat(appName, " is not available on macOS."));
|
|
@@ -10620,7 +10775,7 @@
|
|
|
10620
10775
|
}
|
|
10621
10776
|
else {
|
|
10622
10777
|
if (linuxWhich) {
|
|
10623
|
-
return locateAppOnLinux({
|
|
10778
|
+
return locateAppOnLinux({ linuxWhich: linuxWhich });
|
|
10624
10779
|
}
|
|
10625
10780
|
else {
|
|
10626
10781
|
throw new Error("".concat(appName, " is not available on Linux."));
|
|
@@ -15827,173 +15982,11 @@
|
|
|
15827
15982
|
*/
|
|
15828
15983
|
|
|
15829
15984
|
/**
|
|
15830
|
-
*
|
|
15831
|
-
*
|
|
15832
|
-
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
15833
|
-
*
|
|
15834
|
-
* @private internal utility of `execCommand` and `execCommands`
|
|
15835
|
-
*/
|
|
15836
|
-
function $execCommandNormalizeOptions(options) {
|
|
15837
|
-
var _a;
|
|
15838
|
-
var _b, _c, _d, _e;
|
|
15839
|
-
var command;
|
|
15840
|
-
var cwd;
|
|
15841
|
-
var crashOnError;
|
|
15842
|
-
var args = [];
|
|
15843
|
-
var timeout;
|
|
15844
|
-
var isVerbose;
|
|
15845
|
-
if (typeof options === 'string') {
|
|
15846
|
-
// TODO: [1] DRY default values
|
|
15847
|
-
command = options;
|
|
15848
|
-
cwd = process.cwd();
|
|
15849
|
-
crashOnError = true;
|
|
15850
|
-
timeout = Infinity; // <- TODO: [⏳]
|
|
15851
|
-
isVerbose = DEFAULT_IS_VERBOSE;
|
|
15852
|
-
}
|
|
15853
|
-
else {
|
|
15854
|
-
/*
|
|
15855
|
-
TODO:
|
|
15856
|
-
if ((options as any).commands !== undefined) {
|
|
15857
|
-
commands = (options as any).commands;
|
|
15858
|
-
} else {
|
|
15859
|
-
commands = [(options as any).command];
|
|
15860
|
-
}
|
|
15861
|
-
*/
|
|
15862
|
-
// TODO: [1] DRY default values
|
|
15863
|
-
command = options.command;
|
|
15864
|
-
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
15865
|
-
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
15866
|
-
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
15867
|
-
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
15868
|
-
}
|
|
15869
|
-
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
15870
|
-
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
15871
|
-
.map(function (_a) {
|
|
15872
|
-
var _b = __read(_a, 1), match = _b[0];
|
|
15873
|
-
return match;
|
|
15874
|
-
})
|
|
15875
|
-
.filter(function (arg) { return arg !== ''; });
|
|
15876
|
-
if (_.length > 1) {
|
|
15877
|
-
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
15878
|
-
}
|
|
15879
|
-
if (options.args) {
|
|
15880
|
-
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
15881
|
-
}
|
|
15882
|
-
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
15883
|
-
if (['ts-node'].includes(humanReadableCommand)) {
|
|
15884
|
-
humanReadableCommand += " ".concat(args[1]);
|
|
15885
|
-
}
|
|
15886
|
-
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
15887
|
-
command = "".concat(command, ".cmd");
|
|
15888
|
-
}
|
|
15889
|
-
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
15890
|
-
}
|
|
15891
|
-
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
15892
|
-
|
|
15893
|
-
/**
|
|
15894
|
-
* Run one command in a shell
|
|
15895
|
-
*
|
|
15985
|
+
* Create a filename for intermediate cache for scrapers
|
|
15896
15986
|
*
|
|
15897
|
-
* Note:
|
|
15898
|
-
* - `$execCommand` which runs a single command
|
|
15899
|
-
* - `$execCommands` which runs multiple commands
|
|
15900
|
-
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
15987
|
+
* Note: It also checks if directory exists and creates it if not
|
|
15901
15988
|
*
|
|
15902
|
-
* @
|
|
15903
|
-
*/
|
|
15904
|
-
function $execCommand(options) {
|
|
15905
|
-
if (!$isRunningInNode()) {
|
|
15906
|
-
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
15907
|
-
}
|
|
15908
|
-
return new Promise(function (resolve, reject) {
|
|
15909
|
-
// eslint-disable-next-line prefer-const
|
|
15910
|
-
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;
|
|
15911
|
-
if (timeout !== Infinity) {
|
|
15912
|
-
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
15913
|
-
waitasecond.forTime(timeout).then(function () {
|
|
15914
|
-
if (crashOnError) {
|
|
15915
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
15916
|
-
}
|
|
15917
|
-
else {
|
|
15918
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
15919
|
-
resolve('Command exceeded time limit');
|
|
15920
|
-
}
|
|
15921
|
-
});
|
|
15922
|
-
}
|
|
15923
|
-
if (isVerbose) {
|
|
15924
|
-
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
15925
|
-
}
|
|
15926
|
-
try {
|
|
15927
|
-
var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
15928
|
-
if (isVerbose) {
|
|
15929
|
-
commandProcess.on('message', function (message) {
|
|
15930
|
-
console.info({ message: message });
|
|
15931
|
-
});
|
|
15932
|
-
}
|
|
15933
|
-
var output_1 = [];
|
|
15934
|
-
commandProcess.stdout.on('data', function (stdout) {
|
|
15935
|
-
output_1.push(stdout.toString());
|
|
15936
|
-
if (isVerbose) {
|
|
15937
|
-
console.info(stdout.toString());
|
|
15938
|
-
}
|
|
15939
|
-
});
|
|
15940
|
-
commandProcess.stderr.on('data', function (stderr) {
|
|
15941
|
-
output_1.push(stderr.toString());
|
|
15942
|
-
if (isVerbose && stderr.toString().trim()) {
|
|
15943
|
-
console.warn(stderr.toString());
|
|
15944
|
-
}
|
|
15945
|
-
});
|
|
15946
|
-
var finishWithCode = function (code) {
|
|
15947
|
-
if (code !== 0) {
|
|
15948
|
-
if (crashOnError) {
|
|
15949
|
-
reject(new Error(output_1.join('\n').trim() ||
|
|
15950
|
-
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
15951
|
-
}
|
|
15952
|
-
else {
|
|
15953
|
-
if (isVerbose) {
|
|
15954
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
15955
|
-
}
|
|
15956
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15957
|
-
}
|
|
15958
|
-
}
|
|
15959
|
-
else {
|
|
15960
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15961
|
-
}
|
|
15962
|
-
};
|
|
15963
|
-
commandProcess.on('close', finishWithCode);
|
|
15964
|
-
commandProcess.on('exit', finishWithCode);
|
|
15965
|
-
commandProcess.on('disconnect', function () {
|
|
15966
|
-
// Note: Unexpected disconnection should always result in rejection
|
|
15967
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
15968
|
-
});
|
|
15969
|
-
commandProcess.on('error', function (error) {
|
|
15970
|
-
if (crashOnError) {
|
|
15971
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
15972
|
-
}
|
|
15973
|
-
else {
|
|
15974
|
-
if (isVerbose) {
|
|
15975
|
-
console.warn(error);
|
|
15976
|
-
}
|
|
15977
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15978
|
-
}
|
|
15979
|
-
});
|
|
15980
|
-
}
|
|
15981
|
-
catch (error) {
|
|
15982
|
-
// Note: Unexpected error in sync code should always result in rejection
|
|
15983
|
-
reject(error);
|
|
15984
|
-
}
|
|
15985
|
-
});
|
|
15986
|
-
}
|
|
15987
|
-
/**
|
|
15988
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
15989
|
-
*/
|
|
15990
|
-
|
|
15991
|
-
/**
|
|
15992
|
-
* Create a filename for intermediate cache for scrapers
|
|
15993
|
-
*
|
|
15994
|
-
* Note: It also checks if directory exists and creates it if not
|
|
15995
|
-
*
|
|
15996
|
-
* @private as internal utility for scrapers
|
|
15989
|
+
* @private as internal utility for scrapers
|
|
15997
15990
|
*/
|
|
15998
15991
|
function getScraperIntermediateSource(source, options) {
|
|
15999
15992
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -16258,6 +16251,207 @@
|
|
|
16258
16251
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
16259
16252
|
*/
|
|
16260
16253
|
|
|
16254
|
+
/**
|
|
16255
|
+
* Metadata of the scraper
|
|
16256
|
+
*
|
|
16257
|
+
* @private within the scraper directory
|
|
16258
|
+
*/
|
|
16259
|
+
var boilerplateScraperMetadata = $deepFreeze({
|
|
16260
|
+
title: 'Boilerplate scraper',
|
|
16261
|
+
packageName: '@promptbook/boilerplate',
|
|
16262
|
+
className: 'BoilerplateScraper',
|
|
16263
|
+
mimeTypes: [
|
|
16264
|
+
'@@@/@@@',
|
|
16265
|
+
// <- TODO: @@@ Add compatible mime types with Boilerplate scraper
|
|
16266
|
+
],
|
|
16267
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@@',
|
|
16268
|
+
isAvilableInBrowser: false,
|
|
16269
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16270
|
+
requiredExecutables: [
|
|
16271
|
+
/* @@@ 'Pandoc' */
|
|
16272
|
+
],
|
|
16273
|
+
}); /* <- Note: [🤛] */
|
|
16274
|
+
/**
|
|
16275
|
+
* Registration of known scraper metadata
|
|
16276
|
+
*
|
|
16277
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16278
|
+
*
|
|
16279
|
+
* @public exported from `@promptbook/core`
|
|
16280
|
+
* @public exported from `@promptbook/wizzard`
|
|
16281
|
+
* @public exported from `@promptbook/cli`
|
|
16282
|
+
*/
|
|
16283
|
+
var _BoilerplateScraperMetadataRegistration = $scrapersMetadataRegister.register(boilerplateScraperMetadata);
|
|
16284
|
+
/**
|
|
16285
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16286
|
+
*/
|
|
16287
|
+
|
|
16288
|
+
/**
|
|
16289
|
+
* Scraper of @@@ files
|
|
16290
|
+
*
|
|
16291
|
+
* @see `documentationUrl` for more details
|
|
16292
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16293
|
+
*/
|
|
16294
|
+
var BoilerplateScraper = /** @class */ (function () {
|
|
16295
|
+
function BoilerplateScraper(tools, options) {
|
|
16296
|
+
this.tools = tools;
|
|
16297
|
+
this.options = options;
|
|
16298
|
+
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
16299
|
+
}
|
|
16300
|
+
Object.defineProperty(BoilerplateScraper.prototype, "metadata", {
|
|
16301
|
+
/**
|
|
16302
|
+
* Metadata of the scraper which includes title, mime types, etc.
|
|
16303
|
+
*/
|
|
16304
|
+
get: function () {
|
|
16305
|
+
return boilerplateScraperMetadata;
|
|
16306
|
+
},
|
|
16307
|
+
enumerable: false,
|
|
16308
|
+
configurable: true
|
|
16309
|
+
});
|
|
16310
|
+
/**
|
|
16311
|
+
* Convert the `.@@@` to `.md` file and returns intermediate source
|
|
16312
|
+
*
|
|
16313
|
+
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
16314
|
+
*/
|
|
16315
|
+
BoilerplateScraper.prototype.$convert = function (source) {
|
|
16316
|
+
var _a;
|
|
16317
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16318
|
+
var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, command_1;
|
|
16319
|
+
return __generator(this, function (_g) {
|
|
16320
|
+
switch (_g.label) {
|
|
16321
|
+
case 0:
|
|
16322
|
+
_b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
|
|
16323
|
+
// TODO: @@@ Preserve or delete
|
|
16324
|
+
if (!$isRunningInNode()) {
|
|
16325
|
+
throw new KnowledgeScrapeError('BoilerplateScraper is only supported in Node environment');
|
|
16326
|
+
}
|
|
16327
|
+
// TODO: @@@ Preserve or delete
|
|
16328
|
+
if (this.tools.fs === undefined) {
|
|
16329
|
+
throw new EnvironmentMismatchError('Can not scrape boilerplates without filesystem tools');
|
|
16330
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
16331
|
+
}
|
|
16332
|
+
// TODO: @@@ Preserve, delete or modify
|
|
16333
|
+
if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.pandocPath) === undefined) {
|
|
16334
|
+
throw new MissingToolsError('Pandoc is required for scraping .docx files');
|
|
16335
|
+
}
|
|
16336
|
+
// TODO: @@@ Preserve, delete or modify
|
|
16337
|
+
if (source.filename === null) {
|
|
16338
|
+
// TODO: [🧠] Maybe save file as temporary
|
|
16339
|
+
throw new KnowledgeScrapeError('When parsing .@@@ file, it must be real file in the file system');
|
|
16340
|
+
}
|
|
16341
|
+
extension = getFileExtension(source.filename);
|
|
16342
|
+
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
16343
|
+
rootDirname: rootDirname,
|
|
16344
|
+
cacheDirname: cacheDirname,
|
|
16345
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
16346
|
+
extension: 'md',
|
|
16347
|
+
isVerbose: isVerbose,
|
|
16348
|
+
})];
|
|
16349
|
+
case 1:
|
|
16350
|
+
cacheFilehandler = _g.sent();
|
|
16351
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
16352
|
+
case 2:
|
|
16353
|
+
if (!!(_g.sent())) return [3 /*break*/, 5];
|
|
16354
|
+
command_1 = "\"".concat(this.tools.executables.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
|
|
16355
|
+
return [4 /*yield*/, $execCommand(command_1)];
|
|
16356
|
+
case 3:
|
|
16357
|
+
_g.sent();
|
|
16358
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
16359
|
+
case 4:
|
|
16360
|
+
// Note: [0]
|
|
16361
|
+
if (!(_g.sent())) {
|
|
16362
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
16363
|
+
}
|
|
16364
|
+
_g.label = 5;
|
|
16365
|
+
case 5: return [2 /*return*/, cacheFilehandler];
|
|
16366
|
+
}
|
|
16367
|
+
});
|
|
16368
|
+
});
|
|
16369
|
+
};
|
|
16370
|
+
/**
|
|
16371
|
+
* Scrapes the docx file and returns the knowledge pieces or `null` if it can't scrape it
|
|
16372
|
+
*/
|
|
16373
|
+
BoilerplateScraper.prototype.scrape = function (source) {
|
|
16374
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16375
|
+
var cacheFilehandler, markdownSource, knowledge;
|
|
16376
|
+
return __generator(this, function (_a) {
|
|
16377
|
+
switch (_a.label) {
|
|
16378
|
+
case 0: return [4 /*yield*/, this.$convert(source)];
|
|
16379
|
+
case 1:
|
|
16380
|
+
cacheFilehandler = _a.sent();
|
|
16381
|
+
markdownSource = {
|
|
16382
|
+
source: source.source,
|
|
16383
|
+
filename: cacheFilehandler.filename,
|
|
16384
|
+
url: null,
|
|
16385
|
+
mimeType: 'text/markdown',
|
|
16386
|
+
asText: function () {
|
|
16387
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16388
|
+
return __generator(this, function (_a) {
|
|
16389
|
+
switch (_a.label) {
|
|
16390
|
+
case 0: return [4 /*yield*/, promises.readFile(cacheFilehandler.filename, 'utf-8')];
|
|
16391
|
+
case 1:
|
|
16392
|
+
// Note: [0] In $convert we check that the file exists
|
|
16393
|
+
return [2 /*return*/, _a.sent()];
|
|
16394
|
+
}
|
|
16395
|
+
});
|
|
16396
|
+
});
|
|
16397
|
+
},
|
|
16398
|
+
asJson: function () {
|
|
16399
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
16400
|
+
},
|
|
16401
|
+
/*
|
|
16402
|
+
TODO: [🥽]
|
|
16403
|
+
> asBlob() {
|
|
16404
|
+
> throw new UnexpectedError(
|
|
16405
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
16406
|
+
> );
|
|
16407
|
+
> },
|
|
16408
|
+
*/
|
|
16409
|
+
};
|
|
16410
|
+
knowledge = this.markdownScraper.scrape(markdownSource);
|
|
16411
|
+
return [4 /*yield*/, cacheFilehandler.destroy()];
|
|
16412
|
+
case 2:
|
|
16413
|
+
_a.sent();
|
|
16414
|
+
return [2 /*return*/, knowledge];
|
|
16415
|
+
}
|
|
16416
|
+
});
|
|
16417
|
+
});
|
|
16418
|
+
};
|
|
16419
|
+
return BoilerplateScraper;
|
|
16420
|
+
}());
|
|
16421
|
+
/**
|
|
16422
|
+
* TODO: [👣] Converted documents can act as cached items - there is no need to run conversion each time
|
|
16423
|
+
* TODO: [🪂] Do it in parallel
|
|
16424
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
16425
|
+
* @@@ Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
16426
|
+
*/
|
|
16427
|
+
|
|
16428
|
+
/**
|
|
16429
|
+
* Constructor of `BoilerplateScraper`
|
|
16430
|
+
*
|
|
16431
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16432
|
+
*/
|
|
16433
|
+
var createBoilerplateScraper = Object.assign(function (tools, options) {
|
|
16434
|
+
return new BoilerplateScraper(tools, options);
|
|
16435
|
+
}, boilerplateScraperMetadata); /* <- Note: [🤛] */
|
|
16436
|
+
/**
|
|
16437
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
16438
|
+
*/
|
|
16439
|
+
|
|
16440
|
+
/**
|
|
16441
|
+
* Registration of known scraper
|
|
16442
|
+
*
|
|
16443
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16444
|
+
*
|
|
16445
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16446
|
+
* @public exported from `@promptbook/wizzard`
|
|
16447
|
+
* @public exported from `@promptbook/cli`
|
|
16448
|
+
*/
|
|
16449
|
+
var _BoilerplateScraperRegistration = $scrapersRegister.register(createBoilerplateScraper);
|
|
16450
|
+
/**
|
|
16451
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
16452
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16453
|
+
*/
|
|
16454
|
+
|
|
16261
16455
|
/**
|
|
16262
16456
|
* Metadata of the scraper
|
|
16263
16457
|
*
|
|
@@ -16357,7 +16551,7 @@
|
|
|
16357
16551
|
case 4:
|
|
16358
16552
|
// Note: [0]
|
|
16359
16553
|
if (!(_g.sent())) {
|
|
16360
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n
|
|
16554
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
16361
16555
|
}
|
|
16362
16556
|
_g.label = 5;
|
|
16363
16557
|
case 5: return [2 /*return*/, cacheFilehandler];
|
|
@@ -16532,7 +16726,7 @@
|
|
|
16532
16726
|
case 4:
|
|
16533
16727
|
files_1 = _g.sent();
|
|
16534
16728
|
if (files_1.length !== 1) {
|
|
16535
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n
|
|
16729
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
|
|
16536
16730
|
}
|
|
16537
16731
|
file = files_1[0];
|
|
16538
16732
|
return [4 /*yield*/, promises.rename(path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
|
|
@@ -16682,6 +16876,216 @@
|
|
|
16682
16876
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16683
16877
|
*/
|
|
16684
16878
|
|
|
16879
|
+
/**
|
|
16880
|
+
* Metadata of the scraper
|
|
16881
|
+
*
|
|
16882
|
+
* @private within the scraper directory
|
|
16883
|
+
*/
|
|
16884
|
+
var markitdownScraperMetadata = $deepFreeze({
|
|
16885
|
+
title: 'Markitdown scraper',
|
|
16886
|
+
packageName: '@promptbook/markitdown',
|
|
16887
|
+
className: 'MarkitdownScraper',
|
|
16888
|
+
mimeTypes: [
|
|
16889
|
+
'application/pdf',
|
|
16890
|
+
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
16891
|
+
// 'text/html',
|
|
16892
|
+
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16893
|
+
],
|
|
16894
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16895
|
+
isAvilableInBrowser: false,
|
|
16896
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16897
|
+
requiredExecutables: [],
|
|
16898
|
+
}); /* <- Note: [🤛] */
|
|
16899
|
+
/**
|
|
16900
|
+
* Registration of known scraper metadata
|
|
16901
|
+
*
|
|
16902
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16903
|
+
*
|
|
16904
|
+
* @public exported from `@promptbook/core`
|
|
16905
|
+
* @public exported from `@promptbook/wizzard`
|
|
16906
|
+
* @public exported from `@promptbook/cli`
|
|
16907
|
+
*/
|
|
16908
|
+
var _MarkitdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markitdownScraperMetadata);
|
|
16909
|
+
/**
|
|
16910
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16911
|
+
*/
|
|
16912
|
+
|
|
16913
|
+
/**
|
|
16914
|
+
* Integration of Markitdown by Microsoft into Promptbook
|
|
16915
|
+
*
|
|
16916
|
+
* @see https://github.com/microsoft/markitdown
|
|
16917
|
+
* @see `documentationUrl` for more details
|
|
16918
|
+
* @public exported from `@promptbook/markitdown`
|
|
16919
|
+
* @public exported from `@promptbook/pdf`
|
|
16920
|
+
*/
|
|
16921
|
+
var MarkitdownScraper = /** @class */ (function () {
|
|
16922
|
+
function MarkitdownScraper(tools, options) {
|
|
16923
|
+
this.tools = tools;
|
|
16924
|
+
this.options = options;
|
|
16925
|
+
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
16926
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16927
|
+
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
16928
|
+
// <- TODO: !!! Use Markitdown directly not through this package
|
|
16929
|
+
// <- Note: !!!!!!!
|
|
16930
|
+
this.markitdown = new MarkItDown();
|
|
16931
|
+
}
|
|
16932
|
+
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
16933
|
+
/**
|
|
16934
|
+
* Metadata of the scraper which includes title, mime types, etc.
|
|
16935
|
+
*/
|
|
16936
|
+
get: function () {
|
|
16937
|
+
return markitdownScraperMetadata;
|
|
16938
|
+
},
|
|
16939
|
+
enumerable: false,
|
|
16940
|
+
configurable: true
|
|
16941
|
+
});
|
|
16942
|
+
/**
|
|
16943
|
+
* Convert the documents to `.md` file and returns intermediate source
|
|
16944
|
+
*
|
|
16945
|
+
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
16946
|
+
*/
|
|
16947
|
+
MarkitdownScraper.prototype.$convert = function (source) {
|
|
16948
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16949
|
+
var _a, _b, rootDirname, _c, cacheDirname, _d, intermediateFilesStrategy, _e, isVerbose, cacheFilehandler, src, result;
|
|
16950
|
+
return __generator(this, function (_f) {
|
|
16951
|
+
switch (_f.label) {
|
|
16952
|
+
case 0:
|
|
16953
|
+
_a = this.options, _b = _a.rootDirname, rootDirname = _b === void 0 ? process.cwd() : _b, _c = _a.cacheDirname, cacheDirname = _c === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _c, _d = _a.intermediateFilesStrategy, intermediateFilesStrategy = _d === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _d, _e = _a.isVerbose, isVerbose = _e === void 0 ? DEFAULT_IS_VERBOSE : _e;
|
|
16954
|
+
if (!$isRunningInNode()) {
|
|
16955
|
+
throw new KnowledgeScrapeError('MarkitdownScraper is only supported in Node environment');
|
|
16956
|
+
}
|
|
16957
|
+
if (this.tools.fs === undefined) {
|
|
16958
|
+
throw new EnvironmentMismatchError('Can not scrape boilerplates without filesystem tools');
|
|
16959
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
16960
|
+
}
|
|
16961
|
+
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
16962
|
+
rootDirname: rootDirname,
|
|
16963
|
+
cacheDirname: cacheDirname,
|
|
16964
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
16965
|
+
extension: 'md',
|
|
16966
|
+
isVerbose: isVerbose,
|
|
16967
|
+
})];
|
|
16968
|
+
case 1:
|
|
16969
|
+
cacheFilehandler = _f.sent();
|
|
16970
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
16971
|
+
case 2:
|
|
16972
|
+
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
16973
|
+
src = source.filename || source.url || null;
|
|
16974
|
+
console.log('!!!', { src: src, source: source, cacheFilehandler: cacheFilehandler });
|
|
16975
|
+
if (src === null) {
|
|
16976
|
+
throw new UnexpectedError('Source has no filename or url');
|
|
16977
|
+
}
|
|
16978
|
+
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
16979
|
+
// TODO: !!!!!! Pass when sacraping Youtube
|
|
16980
|
+
// enableYoutubeTranscript: true,
|
|
16981
|
+
// youtubeTranscriptLanguage: 'en',
|
|
16982
|
+
})];
|
|
16983
|
+
case 3:
|
|
16984
|
+
result = _f.sent();
|
|
16985
|
+
if (result === null || result === undefined) {
|
|
16986
|
+
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
16987
|
+
// <- TODO: !!! Make MarkitdownError
|
|
16988
|
+
}
|
|
16989
|
+
console.log('!!!', { result: result, cacheFilehandler: cacheFilehandler });
|
|
16990
|
+
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
16991
|
+
case 4:
|
|
16992
|
+
_f.sent();
|
|
16993
|
+
_f.label = 5;
|
|
16994
|
+
case 5: return [2 /*return*/, cacheFilehandler];
|
|
16995
|
+
}
|
|
16996
|
+
});
|
|
16997
|
+
});
|
|
16998
|
+
};
|
|
16999
|
+
/**
|
|
17000
|
+
* Scrapes the docx file and returns the knowledge pieces or `null` if it can't scrape it
|
|
17001
|
+
*/
|
|
17002
|
+
MarkitdownScraper.prototype.scrape = function (source) {
|
|
17003
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17004
|
+
var cacheFilehandler, markdownSource, knowledge;
|
|
17005
|
+
return __generator(this, function (_a) {
|
|
17006
|
+
switch (_a.label) {
|
|
17007
|
+
case 0: return [4 /*yield*/, this.$convert(source)];
|
|
17008
|
+
case 1:
|
|
17009
|
+
cacheFilehandler = _a.sent();
|
|
17010
|
+
markdownSource = {
|
|
17011
|
+
source: source.source,
|
|
17012
|
+
filename: cacheFilehandler.filename,
|
|
17013
|
+
url: null,
|
|
17014
|
+
mimeType: 'text/markdown',
|
|
17015
|
+
asText: function () {
|
|
17016
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17017
|
+
return __generator(this, function (_a) {
|
|
17018
|
+
switch (_a.label) {
|
|
17019
|
+
case 0: return [4 /*yield*/, promises.readFile(cacheFilehandler.filename, 'utf-8')];
|
|
17020
|
+
case 1:
|
|
17021
|
+
// Note: [0] In $convert we check that the file exists
|
|
17022
|
+
return [2 /*return*/, _a.sent()];
|
|
17023
|
+
}
|
|
17024
|
+
});
|
|
17025
|
+
});
|
|
17026
|
+
},
|
|
17027
|
+
asJson: function () {
|
|
17028
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
17029
|
+
},
|
|
17030
|
+
/*
|
|
17031
|
+
TODO: [🥽]
|
|
17032
|
+
> asBlob() {
|
|
17033
|
+
> throw new UnexpectedError(
|
|
17034
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
17035
|
+
> );
|
|
17036
|
+
> },
|
|
17037
|
+
*/
|
|
17038
|
+
};
|
|
17039
|
+
knowledge = this.markdownScraper.scrape(markdownSource);
|
|
17040
|
+
return [4 /*yield*/, cacheFilehandler.destroy()];
|
|
17041
|
+
case 2:
|
|
17042
|
+
_a.sent();
|
|
17043
|
+
return [2 /*return*/, knowledge];
|
|
17044
|
+
}
|
|
17045
|
+
});
|
|
17046
|
+
});
|
|
17047
|
+
};
|
|
17048
|
+
return MarkitdownScraper;
|
|
17049
|
+
}());
|
|
17050
|
+
/**
|
|
17051
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17052
|
+
* TODO: [👣] Converted documents can act as cached items - there is no need to run conversion each time
|
|
17053
|
+
* TODO: [🪂] Do it in parallel
|
|
17054
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
17055
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
17056
|
+
*/
|
|
17057
|
+
|
|
17058
|
+
/**
|
|
17059
|
+
* Constructor of `MarkitdownScraper`
|
|
17060
|
+
*
|
|
17061
|
+
* @public exported from `@promptbook/markitdown`
|
|
17062
|
+
* @public exported from `@promptbook/pdf`
|
|
17063
|
+
*/
|
|
17064
|
+
var createMarkitdownScraper = Object.assign(function (tools, options) {
|
|
17065
|
+
return new MarkitdownScraper(tools, options);
|
|
17066
|
+
}, markitdownScraperMetadata); /* <- Note: [🤛] */
|
|
17067
|
+
/**
|
|
17068
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17069
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
17070
|
+
*/
|
|
17071
|
+
|
|
17072
|
+
/**
|
|
17073
|
+
* Registration of known scraper
|
|
17074
|
+
*
|
|
17075
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
17076
|
+
*
|
|
17077
|
+
* @public exported from `@promptbook/markitdown`
|
|
17078
|
+
* @public exported from `@promptbook/pdf`
|
|
17079
|
+
* @public exported from `@promptbook/wizzard`
|
|
17080
|
+
* @public exported from `@promptbook/cli`
|
|
17081
|
+
*/
|
|
17082
|
+
var _MarkitdownScraperRegistration = $scrapersRegister.register(createMarkitdownScraper);
|
|
17083
|
+
/**
|
|
17084
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17085
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
17086
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
17087
|
+
*/
|
|
17088
|
+
|
|
16685
17089
|
/**
|
|
16686
17090
|
* Metadata of the scraper
|
|
16687
17091
|
*
|
|
@@ -16691,7 +17095,7 @@
|
|
|
16691
17095
|
title: 'Pdf scraper',
|
|
16692
17096
|
packageName: '@promptbook/pdf',
|
|
16693
17097
|
className: 'PdfScraper',
|
|
16694
|
-
mimeTypes: ['application/pdf'],
|
|
17098
|
+
mimeTypes: ['application/pdf-DISABLED'],
|
|
16695
17099
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16696
17100
|
isAvilableInBrowser: false,
|
|
16697
17101
|
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
@@ -17008,6 +17412,8 @@
|
|
|
17008
17412
|
exports._AnthropicClaudeRegistration = _AnthropicClaudeRegistration;
|
|
17009
17413
|
exports._AzureOpenAiMetadataRegistration = _AzureOpenAiMetadataRegistration;
|
|
17010
17414
|
exports._AzureOpenAiRegistration = _AzureOpenAiRegistration;
|
|
17415
|
+
exports._BoilerplateScraperMetadataRegistration = _BoilerplateScraperMetadataRegistration;
|
|
17416
|
+
exports._BoilerplateScraperRegistration = _BoilerplateScraperRegistration;
|
|
17011
17417
|
exports._CLI = _CLI;
|
|
17012
17418
|
exports._DocumentScraperMetadataRegistration = _DocumentScraperMetadataRegistration;
|
|
17013
17419
|
exports._DocumentScraperRegistration = _DocumentScraperRegistration;
|
|
@@ -17017,6 +17423,8 @@
|
|
|
17017
17423
|
exports._LegacyDocumentScraperRegistration = _LegacyDocumentScraperRegistration;
|
|
17018
17424
|
exports._MarkdownScraperMetadataRegistration = _MarkdownScraperMetadataRegistration;
|
|
17019
17425
|
exports._MarkdownScraperRegistration = _MarkdownScraperRegistration;
|
|
17426
|
+
exports._MarkitdownScraperMetadataRegistration = _MarkitdownScraperMetadataRegistration;
|
|
17427
|
+
exports._MarkitdownScraperRegistration = _MarkitdownScraperRegistration;
|
|
17020
17428
|
exports._OpenAiAssistantMetadataRegistration = _OpenAiAssistantMetadataRegistration;
|
|
17021
17429
|
exports._OpenAiAssistantRegistration = _OpenAiAssistantRegistration;
|
|
17022
17430
|
exports._OpenAiMetadataRegistration = _OpenAiMetadataRegistration;
|