@promptbook/node 0.71.0-19 → 0.71.0-21

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/esm/index.es.js CHANGED
@@ -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.71.0-18';
21
+ var PROMPTBOOK_VERSION = '0.71.0-20';
21
22
  // TODO: [main] !!!! List here all the versions and annotate + put into script
22
23
 
23
24
  /*! *****************************************************************************
@@ -4729,7 +4730,6 @@ var $scrapersRegister = new $Register('scraper_constructors');
4729
4730
  * TODO: [®] DRY Register logic
4730
4731
  */
4731
4732
 
4732
- // TODO: !!!!!!last - Maybe delete this function
4733
4733
  /**
4734
4734
  * Creates a message with all registered scrapers
4735
4735
  *
@@ -8183,6 +8183,301 @@ function pipelineStringToJson(pipelineString, tools, options) {
8183
8183
  */
8184
8184
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
8185
8185
 
8186
+ // Note: We want to use the `exec` as async function
8187
+ var exec$1 = promisify(exec$2);
8188
+ /**
8189
+ * @@@
8190
+ *
8191
+ * @private within the repository
8192
+ */
8193
+ function locateAppOnLinux(_a) {
8194
+ var appName = _a.appName, linuxWhich = _a.linuxWhich;
8195
+ return __awaiter(this, void 0, void 0, function () {
8196
+ var _b, stderr, stdout;
8197
+ return __generator(this, function (_c) {
8198
+ switch (_c.label) {
8199
+ case 0: return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8200
+ case 1:
8201
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8202
+ if (!stderr && stdout) {
8203
+ return [2 /*return*/, stdout.trim()];
8204
+ }
8205
+ throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
8206
+ }
8207
+ });
8208
+ });
8209
+ }
8210
+ /**
8211
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8212
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8213
+ */
8214
+
8215
+ /**
8216
+ * @@@
8217
+ *
8218
+ * @public exported from `@promptbook/node`
8219
+ */
8220
+ function $provideFilesystemForNode(options) {
8221
+ if (!$isRunningInNode()) {
8222
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8223
+ }
8224
+ var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8225
+ TODO_USE(isVerbose);
8226
+ return {
8227
+ stat: stat,
8228
+ access: access,
8229
+ constants: constants,
8230
+ readFile: readFile,
8231
+ readdir: readdir,
8232
+ };
8233
+ }
8234
+ /**
8235
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8236
+ */
8237
+
8238
+ /**
8239
+ * Checks if the file is executable
8240
+ *
8241
+ * @private within the repository
8242
+ */
8243
+ function isExecutable(path, fs) {
8244
+ return __awaiter(this, void 0, void 0, function () {
8245
+ return __generator(this, function (_a) {
8246
+ switch (_a.label) {
8247
+ case 0:
8248
+ _a.trys.push([0, 2, , 3]);
8249
+ return [4 /*yield*/, fs.access(path, fs.constants.X_OK)];
8250
+ case 1:
8251
+ _a.sent();
8252
+ return [2 /*return*/, true];
8253
+ case 2:
8254
+ _a.sent();
8255
+ return [2 /*return*/, false];
8256
+ case 3: return [2 /*return*/];
8257
+ }
8258
+ });
8259
+ });
8260
+ }
8261
+ /**
8262
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
8263
+ * TODO: [🖇] What about symlinks?
8264
+ */
8265
+
8266
+ // Note: Module `userhome` has no types available, so it is imported using `require`
8267
+ // @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
8268
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8269
+ var userhome = require('userhome');
8270
+ // Note: We want to use the `exec` as async function
8271
+ var exec = promisify(exec$2);
8272
+ /**
8273
+ * @@@
8274
+ *
8275
+ * @private within the repository
8276
+ */
8277
+ function locateAppOnMacOs(_a) {
8278
+ var appName = _a.appName, macOsName = _a.macOsName;
8279
+ return __awaiter(this, void 0, void 0, function () {
8280
+ var toExec, regPath, altPath, _b, stderr, stdout;
8281
+ return __generator(this, function (_c) {
8282
+ switch (_c.label) {
8283
+ case 0:
8284
+ toExec = "/Contents/MacOS/".concat(macOsName);
8285
+ regPath = "/Applications/".concat(macOsName, ".app") + toExec;
8286
+ altPath = userhome(regPath.slice(1));
8287
+ return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
8288
+ case 1:
8289
+ if (!_c.sent()) return [3 /*break*/, 2];
8290
+ return [2 /*return*/, regPath];
8291
+ case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
8292
+ case 3:
8293
+ if (_c.sent()) {
8294
+ return [2 /*return*/, altPath];
8295
+ }
8296
+ _c.label = 4;
8297
+ case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
8298
+ case 5:
8299
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8300
+ if (!stderr && stdout) {
8301
+ return [2 /*return*/, stdout.trim() + toExec];
8302
+ }
8303
+ throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
8304
+ }
8305
+ });
8306
+ });
8307
+ }
8308
+ /**
8309
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8310
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8311
+ */
8312
+
8313
+ /**
8314
+ * @@@
8315
+ *
8316
+ * @private within the repository
8317
+ */
8318
+ function locateAppOnWindows(_a) {
8319
+ var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
8320
+ return __awaiter(this, void 0, void 0, function () {
8321
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1;
8322
+ var e_1, _b;
8323
+ return __generator(this, function (_c) {
8324
+ switch (_c.label) {
8325
+ case 0:
8326
+ prefixes = [
8327
+ process.env.LOCALAPPDATA,
8328
+ join(process.env.LOCALAPPDATA || '', 'Programs'),
8329
+ process.env.PROGRAMFILES,
8330
+ process.env['PROGRAMFILES(X86)'],
8331
+ ];
8332
+ _c.label = 1;
8333
+ case 1:
8334
+ _c.trys.push([1, 6, 7, 8]);
8335
+ prefixes_1 = __values(prefixes), prefixes_1_1 = prefixes_1.next();
8336
+ _c.label = 2;
8337
+ case 2:
8338
+ if (!!prefixes_1_1.done) return [3 /*break*/, 5];
8339
+ prefix = prefixes_1_1.value;
8340
+ path = prefix + windowsSuffix;
8341
+ return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
8342
+ case 3:
8343
+ if (_c.sent()) {
8344
+ return [2 /*return*/, path];
8345
+ }
8346
+ _c.label = 4;
8347
+ case 4:
8348
+ prefixes_1_1 = prefixes_1.next();
8349
+ return [3 /*break*/, 2];
8350
+ case 5: return [3 /*break*/, 8];
8351
+ case 6:
8352
+ e_1_1 = _c.sent();
8353
+ e_1 = { error: e_1_1 };
8354
+ return [3 /*break*/, 8];
8355
+ case 7:
8356
+ try {
8357
+ if (prefixes_1_1 && !prefixes_1_1.done && (_b = prefixes_1.return)) _b.call(prefixes_1);
8358
+ }
8359
+ finally { if (e_1) throw e_1.error; }
8360
+ return [7 /*endfinally*/];
8361
+ case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
8362
+ }
8363
+ });
8364
+ });
8365
+ }
8366
+ /**
8367
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8368
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8369
+ */
8370
+
8371
+ /**
8372
+ * Locates an application on the system
8373
+ *
8374
+ * @private within the repository
8375
+ */
8376
+ function locateApp(options) {
8377
+ if (!$isRunningInNode()) {
8378
+ throw new EnvironmentMismatchError('Locating apps works only in Node.js environment');
8379
+ }
8380
+ var appName = options.appName, linuxWhich = options.linuxWhich, windowsSuffix = options.windowsSuffix, macOsName = options.macOsName;
8381
+ if (process.platform === 'win32') {
8382
+ if (windowsSuffix) {
8383
+ return locateAppOnWindows({ appName: appName, windowsSuffix: windowsSuffix });
8384
+ }
8385
+ else {
8386
+ throw new Error("".concat(appName, " is not available on Windows."));
8387
+ }
8388
+ }
8389
+ else if (process.platform === 'darwin') {
8390
+ if (macOsName) {
8391
+ return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
8392
+ }
8393
+ else {
8394
+ throw new Error("".concat(appName, " is not available on macOS."));
8395
+ }
8396
+ }
8397
+ else {
8398
+ if (linuxWhich) {
8399
+ return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
8400
+ }
8401
+ else {
8402
+ throw new Error("".concat(appName, " is not available on Linux."));
8403
+ }
8404
+ }
8405
+ }
8406
+ /**
8407
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8408
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8409
+ */
8410
+
8411
+ /**
8412
+ * @@@
8413
+ *
8414
+ * @private within the repository
8415
+ */
8416
+ function locateLibreoffice() {
8417
+ return locateApp({
8418
+ appName: 'Libreoffice',
8419
+ linuxWhich: 'libreoffice',
8420
+ windowsSuffix: '\\LibreOffice\\program\\soffice.exe',
8421
+ macOsName: 'LibreOffice',
8422
+ });
8423
+ }
8424
+ /**
8425
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/legacy-documents`
8426
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8427
+ */
8428
+
8429
+ /**
8430
+ * @@@
8431
+ *
8432
+ * @private within the repository
8433
+ */
8434
+ function locatePandoc() {
8435
+ return locateApp({
8436
+ appName: 'Pandoc',
8437
+ linuxWhich: 'pandoc',
8438
+ windowsSuffix: '\\Pandoc\\pandoc.exe',
8439
+ macOsName: 'Pandoc',
8440
+ });
8441
+ }
8442
+ /**
8443
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/documents`
8444
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8445
+ */
8446
+
8447
+ /**
8448
+ * @@@
8449
+ *
8450
+ * @public exported from `@promptbook/node`
8451
+ */
8452
+ function $provideExecutablesForNode(options) {
8453
+ return __awaiter(this, void 0, void 0, function () {
8454
+ var _a, _b, isAutoInstalled, _c, isVerbose;
8455
+ var _d;
8456
+ return __generator(this, function (_e) {
8457
+ switch (_e.label) {
8458
+ case 0:
8459
+ if (!$isRunningInNode()) {
8460
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8461
+ }
8462
+ _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;
8463
+ TODO_USE(isAutoInstalled); // <- TODO: [🔱][🧠] Auto-install the executables
8464
+ TODO_USE(isVerbose);
8465
+ _d = {};
8466
+ return [4 /*yield*/, locatePandoc()];
8467
+ case 1:
8468
+ _d.pandocPath = _e.sent();
8469
+ return [4 /*yield*/, locateLibreoffice()];
8470
+ case 2: return [2 /*return*/, (_d.libreOfficePath = _e.sent(),
8471
+ _d)];
8472
+ }
8473
+ });
8474
+ });
8475
+ }
8476
+ /**
8477
+ * TODO: [🧠] Allow to override the executables without need to call `locatePandoc` / `locateLibreoffice` in case of provided
8478
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8479
+ */
8480
+
8186
8481
  /**
8187
8482
  * @@@
8188
8483
  *
@@ -8413,57 +8708,6 @@ function $provideLlmToolsFromEnv(options) {
8413
8708
  * TODO: [®] DRY Register logic
8414
8709
  */
8415
8710
 
8416
- /**
8417
- * @@@
8418
- *
8419
- * @public exported from `@promptbook/node`
8420
- */
8421
- function $provideExecutablesForNode(options) {
8422
- return __awaiter(this, void 0, void 0, function () {
8423
- var _a, _b, isAutoInstalled, _c, isVerbose;
8424
- return __generator(this, function (_d) {
8425
- if (!$isRunningInNode()) {
8426
- throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8427
- }
8428
- _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;
8429
- TODO_USE(isAutoInstalled);
8430
- TODO_USE(isVerbose);
8431
- return [2 /*return*/, {
8432
- // TODO: !!!!!! use `locate-app` library here
8433
- pandocPath: 'C:/Users/me/AppData/Local/Pandoc/pandoc.exe',
8434
- libreOfficePath: 'C:/Program Files/LibreOffice/program/swriter.exe',
8435
- }];
8436
- });
8437
- });
8438
- }
8439
- /**
8440
- * TODO: [🧠] THis should be maybe in different folder
8441
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8442
- */
8443
-
8444
- /**
8445
- * @@@
8446
- *
8447
- * @public exported from `@promptbook/node`
8448
- */
8449
- function $provideFilesystemForNode(options) {
8450
- if (!$isRunningInNode()) {
8451
- throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8452
- }
8453
- var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8454
- TODO_USE(isVerbose);
8455
- return {
8456
- stat: stat,
8457
- access: access,
8458
- constants: constants,
8459
- readFile: readFile,
8460
- readdir: readdir,
8461
- };
8462
- }
8463
- /**
8464
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8465
- */
8466
-
8467
8711
  /**
8468
8712
  * @@@
8469
8713
  *