@promptbook/cli 0.72.0-15 → 0.72.0-23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/esm/index.es.js +355 -296
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/cli.index.d.ts +0 -4
  4. package/esm/typings/src/_packages/core.index.d.ts +0 -2
  5. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  7. package/esm/typings/src/{scrapers/_common/register → executables}/$provideExecutablesForNode.d.ts +3 -3
  8. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
  9. package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
  10. package/esm/typings/src/executables/locateApp.d.ts +33 -0
  11. package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
  12. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
  13. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
  14. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
  15. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
  16. package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -4
  17. package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
  18. package/package.json +1 -4
  19. package/umd/index.umd.js +356 -297
  20. package/umd/index.umd.js.map +1 -1
  21. package/esm/typings/src/_packages/website-crawler.index.d.ts +0 -8
  22. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +0 -50
  23. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +0 -20
  24. package/esm/typings/src/scrapers/website/playground/website-scraper-playground.d.ts +0 -5
  25. package/esm/typings/src/scrapers/website/register-constructor.d.ts +0 -13
  26. package/esm/typings/src/scrapers/website/register-metadata.d.ts +0 -24
  27. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +0 -7
  28. /package/esm/typings/src/{scrapers/website/WebsiteScraper.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
  29. /package/esm/typings/src/{scrapers/website/utils/createShowdownConverter.test.d.ts → executables/apps/locatePandoc.test.d.ts} +0 -0
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('commander'), require('spacetrim'), require('colors'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('dotenv'), require('crypto-js/sha256'), require('glob-promise'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('child_process'), require('@mozilla/readability'), require('jsdom'), require('showdown')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'commander', 'spacetrim', 'colors', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'dotenv', 'crypto-js/sha256', 'glob-promise', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai', 'child_process', '@mozilla/readability', 'jsdom', 'showdown'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.commander, global.spaceTrim, global.colors, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.dotenv, global.sha256, global.glob, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI, global.child_process, global.readability, global.jsdom, global.showdown));
5
- })(this, (function (exports, commander, spaceTrim, colors, waitasecond, promises, path, prettier, parserHtml, papaparse, cryptoJs, hexEncoder, mimeTypes, dotenv, sha256, glob, socket_ioClient, Anthropic, openai, OpenAI, child_process, readability, jsdom, showdown) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('commander'), require('spacetrim'), require('colors'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('child_process'), require('util'), require('dotenv'), require('crypto-js/sha256'), require('glob-promise'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'commander', 'spacetrim', 'colors', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'child_process', 'util', 'dotenv', 'crypto-js/sha256', 'glob-promise', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.commander, global.spaceTrim, global.colors, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.child_process, global.util, global.dotenv, global.sha256, global.glob, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI));
5
+ })(this, (function (exports, commander, spaceTrim, colors, waitasecond, promises, path, prettier, parserHtml, papaparse, cryptoJs, hexEncoder, mimeTypes, child_process, util, dotenv, sha256, glob, socket_ioClient, Anthropic, openai, OpenAI) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.72.0-14';
42
+ var PROMPTBOOK_VERSION = '0.72.0-22';
43
43
  // TODO: [main] !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -4940,7 +4940,6 @@
4940
4940
  * TODO: [®] DRY Register logic
4941
4941
  */
4942
4942
 
4943
- // TODO: !!!!!!last - Maybe delete this function
4944
4943
  /**
4945
4944
  * Creates a message with all registered scrapers
4946
4945
  *
@@ -5213,7 +5212,7 @@
5213
5212
  return __awaiter(this, void 0, void 0, function () {
5214
5213
  var sourceContent, name, _b, _c, rootDirname, _d,
5215
5214
  // <- TODO: process.cwd() if running in Node.js
5216
- isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType_1;
5215
+ isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5217
5216
  return __generator(this, function (_e) {
5218
5217
  switch (_e.label) {
5219
5218
  case 0:
@@ -5235,19 +5234,14 @@
5235
5234
  filename: null,
5236
5235
  url: url,
5237
5236
  mimeType: mimeType,
5238
- asBlob: function () {
5239
- return __awaiter(this, void 0, void 0, function () {
5240
- var content;
5241
- return __generator(this, function (_a) {
5242
- switch (_a.label) {
5243
- case 0: return [4 /*yield*/, response_1.blob()];
5244
- case 1:
5245
- content = _a.sent();
5246
- return [2 /*return*/, content];
5247
- }
5248
- });
5249
- });
5250
- },
5237
+ /*
5238
+ TODO: [🥽]
5239
+ > async asBlob() {
5240
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5241
+ > const content = await response.blob();
5242
+ > return content;
5243
+ > },
5244
+ */
5251
5245
  asJson: function () {
5252
5246
  return __awaiter(this, void 0, void 0, function () {
5253
5247
  var content;
@@ -5287,34 +5281,31 @@
5287
5281
  }
5288
5282
  filename_1 = path.join(rootDirname, sourceContent).split('\\').join('/');
5289
5283
  fileExtension = getFileExtension(filename_1);
5290
- mimeType_1 = extensionToMimeType(fileExtension || '');
5284
+ mimeType = extensionToMimeType(fileExtension || '');
5291
5285
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5292
5286
  case 3:
5293
5287
  if (!(_e.sent())) {
5294
5288
  throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5295
5289
  }
5296
- // TODO: !!!!!! Test security file - file is scoped to the project (maybe do this in `filesystemTools`)
5290
+ // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5297
5291
  return [2 /*return*/, {
5298
5292
  source: name,
5299
5293
  filename: filename_1,
5300
5294
  url: null,
5301
- mimeType: mimeType_1,
5302
- asBlob: function () {
5303
- return __awaiter(this, void 0, void 0, function () {
5304
- var content;
5305
- return __generator(this, function (_a) {
5306
- switch (_a.label) {
5307
- case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
5308
- case 1:
5309
- content = _a.sent();
5310
- return [2 /*return*/, new Blob([
5311
- content,
5312
- // <- TODO: !!!!!! Test that this is working
5313
- ], { type: mimeType_1 })];
5314
- }
5315
- });
5316
- });
5317
- },
5295
+ mimeType: mimeType,
5296
+ /*
5297
+ TODO: [🥽]
5298
+ > async asBlob() {
5299
+ > const content = await tools.fs!.readFile(filename);
5300
+ > return new Blob(
5301
+ > [
5302
+ > content,
5303
+ > // <- TODO: [🥽] This is NOT tested, test it
5304
+ > ],
5305
+ > { type: mimeType },
5306
+ > );
5307
+ > },
5308
+ */
5318
5309
  asJson: function () {
5319
5310
  return __awaiter(this, void 0, void 0, function () {
5320
5311
  var _a, _b;
@@ -5350,9 +5341,14 @@
5350
5341
  asJson: function () {
5351
5342
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
5352
5343
  },
5353
- asBlob: function () {
5354
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
5355
- },
5344
+ /*
5345
+ TODO: [🥽]
5346
+ > asBlob() {
5347
+ > throw new UnexpectedError(
5348
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
5349
+ > );
5350
+ > },
5351
+ */
5356
5352
  }];
5357
5353
  }
5358
5354
  });
@@ -5677,6 +5673,7 @@
5677
5673
  'KNOWLEDGE ./hejny-cv.md',
5678
5674
  'KNOWLEDGE ./hejny-cv.pdf',
5679
5675
  'KNOWLEDGE ./hejny-cv.docx',
5676
+ // <- TODO: [😿] Allow ONLY files scoped in the (sub)directory NOT ../ and test it
5680
5677
  ],
5681
5678
  /**
5682
5679
  * Parses the KNOWLEDGE command
@@ -8385,6 +8382,301 @@
8385
8382
  * TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
8386
8383
  */
8387
8384
 
8385
+ // Note: We want to use the `exec` as async function
8386
+ var exec$1 = util.promisify(child_process.exec);
8387
+ /**
8388
+ * @@@
8389
+ *
8390
+ * @private within the repository
8391
+ */
8392
+ function locateAppOnLinux(_a) {
8393
+ var appName = _a.appName, linuxWhich = _a.linuxWhich;
8394
+ return __awaiter(this, void 0, void 0, function () {
8395
+ var _b, stderr, stdout;
8396
+ return __generator(this, function (_c) {
8397
+ switch (_c.label) {
8398
+ case 0: return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8399
+ case 1:
8400
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8401
+ if (!stderr && stdout) {
8402
+ return [2 /*return*/, stdout.trim()];
8403
+ }
8404
+ throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
8405
+ }
8406
+ });
8407
+ });
8408
+ }
8409
+ /**
8410
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8411
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8412
+ */
8413
+
8414
+ /**
8415
+ * @@@
8416
+ *
8417
+ * @public exported from `@promptbook/node`
8418
+ */
8419
+ function $provideFilesystemForNode(options) {
8420
+ if (!$isRunningInNode()) {
8421
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8422
+ }
8423
+ var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8424
+ TODO_USE(isVerbose);
8425
+ return {
8426
+ stat: promises.stat,
8427
+ access: promises.access,
8428
+ constants: promises.constants,
8429
+ readFile: promises.readFile,
8430
+ readdir: promises.readdir,
8431
+ };
8432
+ }
8433
+ /**
8434
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8435
+ */
8436
+
8437
+ /**
8438
+ * Checks if the file is executable
8439
+ *
8440
+ * @private within the repository
8441
+ */
8442
+ function isExecutable(path, fs) {
8443
+ return __awaiter(this, void 0, void 0, function () {
8444
+ return __generator(this, function (_a) {
8445
+ switch (_a.label) {
8446
+ case 0:
8447
+ _a.trys.push([0, 2, , 3]);
8448
+ return [4 /*yield*/, fs.access(path, fs.constants.X_OK)];
8449
+ case 1:
8450
+ _a.sent();
8451
+ return [2 /*return*/, true];
8452
+ case 2:
8453
+ _a.sent();
8454
+ return [2 /*return*/, false];
8455
+ case 3: return [2 /*return*/];
8456
+ }
8457
+ });
8458
+ });
8459
+ }
8460
+ /**
8461
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
8462
+ * TODO: [🖇] What about symlinks?
8463
+ */
8464
+
8465
+ // Note: Module `userhome` has no types available, so it is imported using `require`
8466
+ // @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
8467
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8468
+ var userhome = require('userhome');
8469
+ // Note: We want to use the `exec` as async function
8470
+ var exec = util.promisify(child_process.exec);
8471
+ /**
8472
+ * @@@
8473
+ *
8474
+ * @private within the repository
8475
+ */
8476
+ function locateAppOnMacOs(_a) {
8477
+ var appName = _a.appName, macOsName = _a.macOsName;
8478
+ return __awaiter(this, void 0, void 0, function () {
8479
+ var toExec, regPath, altPath, _b, stderr, stdout;
8480
+ return __generator(this, function (_c) {
8481
+ switch (_c.label) {
8482
+ case 0:
8483
+ toExec = "/Contents/MacOS/".concat(macOsName);
8484
+ regPath = "/Applications/".concat(macOsName, ".app") + toExec;
8485
+ altPath = userhome(regPath.slice(1));
8486
+ return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
8487
+ case 1:
8488
+ if (!_c.sent()) return [3 /*break*/, 2];
8489
+ return [2 /*return*/, regPath];
8490
+ case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
8491
+ case 3:
8492
+ if (_c.sent()) {
8493
+ return [2 /*return*/, altPath];
8494
+ }
8495
+ _c.label = 4;
8496
+ case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
8497
+ case 5:
8498
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8499
+ if (!stderr && stdout) {
8500
+ return [2 /*return*/, stdout.trim() + toExec];
8501
+ }
8502
+ throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
8503
+ }
8504
+ });
8505
+ });
8506
+ }
8507
+ /**
8508
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8509
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8510
+ */
8511
+
8512
+ /**
8513
+ * @@@
8514
+ *
8515
+ * @private within the repository
8516
+ */
8517
+ function locateAppOnWindows(_a) {
8518
+ var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
8519
+ return __awaiter(this, void 0, void 0, function () {
8520
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path$1, e_1_1;
8521
+ var e_1, _b;
8522
+ return __generator(this, function (_c) {
8523
+ switch (_c.label) {
8524
+ case 0:
8525
+ prefixes = [
8526
+ process.env.LOCALAPPDATA,
8527
+ path.join(process.env.LOCALAPPDATA || '', 'Programs'),
8528
+ process.env.PROGRAMFILES,
8529
+ process.env['PROGRAMFILES(X86)'],
8530
+ ];
8531
+ _c.label = 1;
8532
+ case 1:
8533
+ _c.trys.push([1, 6, 7, 8]);
8534
+ prefixes_1 = __values(prefixes), prefixes_1_1 = prefixes_1.next();
8535
+ _c.label = 2;
8536
+ case 2:
8537
+ if (!!prefixes_1_1.done) return [3 /*break*/, 5];
8538
+ prefix = prefixes_1_1.value;
8539
+ path$1 = prefix + windowsSuffix;
8540
+ return [4 /*yield*/, isExecutable(path$1, $provideFilesystemForNode())];
8541
+ case 3:
8542
+ if (_c.sent()) {
8543
+ return [2 /*return*/, path$1];
8544
+ }
8545
+ _c.label = 4;
8546
+ case 4:
8547
+ prefixes_1_1 = prefixes_1.next();
8548
+ return [3 /*break*/, 2];
8549
+ case 5: return [3 /*break*/, 8];
8550
+ case 6:
8551
+ e_1_1 = _c.sent();
8552
+ e_1 = { error: e_1_1 };
8553
+ return [3 /*break*/, 8];
8554
+ case 7:
8555
+ try {
8556
+ if (prefixes_1_1 && !prefixes_1_1.done && (_b = prefixes_1.return)) _b.call(prefixes_1);
8557
+ }
8558
+ finally { if (e_1) throw e_1.error; }
8559
+ return [7 /*endfinally*/];
8560
+ case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
8561
+ }
8562
+ });
8563
+ });
8564
+ }
8565
+ /**
8566
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8567
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8568
+ */
8569
+
8570
+ /**
8571
+ * Locates an application on the system
8572
+ *
8573
+ * @private within the repository
8574
+ */
8575
+ function locateApp(options) {
8576
+ if (!$isRunningInNode()) {
8577
+ throw new EnvironmentMismatchError('Locating apps works only in Node.js environment');
8578
+ }
8579
+ var appName = options.appName, linuxWhich = options.linuxWhich, windowsSuffix = options.windowsSuffix, macOsName = options.macOsName;
8580
+ if (process.platform === 'win32') {
8581
+ if (windowsSuffix) {
8582
+ return locateAppOnWindows({ appName: appName, windowsSuffix: windowsSuffix });
8583
+ }
8584
+ else {
8585
+ throw new Error("".concat(appName, " is not available on Windows."));
8586
+ }
8587
+ }
8588
+ else if (process.platform === 'darwin') {
8589
+ if (macOsName) {
8590
+ return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
8591
+ }
8592
+ else {
8593
+ throw new Error("".concat(appName, " is not available on macOS."));
8594
+ }
8595
+ }
8596
+ else {
8597
+ if (linuxWhich) {
8598
+ return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
8599
+ }
8600
+ else {
8601
+ throw new Error("".concat(appName, " is not available on Linux."));
8602
+ }
8603
+ }
8604
+ }
8605
+ /**
8606
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8607
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8608
+ */
8609
+
8610
+ /**
8611
+ * @@@
8612
+ *
8613
+ * @private within the repository
8614
+ */
8615
+ function locateLibreoffice() {
8616
+ return locateApp({
8617
+ appName: 'Libreoffice',
8618
+ linuxWhich: 'libreoffice',
8619
+ windowsSuffix: '\\LibreOffice\\program\\soffice.exe',
8620
+ macOsName: 'LibreOffice',
8621
+ });
8622
+ }
8623
+ /**
8624
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/legacy-documents`
8625
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8626
+ */
8627
+
8628
+ /**
8629
+ * @@@
8630
+ *
8631
+ * @private within the repository
8632
+ */
8633
+ function locatePandoc() {
8634
+ return locateApp({
8635
+ appName: 'Pandoc',
8636
+ linuxWhich: 'pandoc',
8637
+ windowsSuffix: '\\Pandoc\\pandoc.exe',
8638
+ macOsName: 'Pandoc',
8639
+ });
8640
+ }
8641
+ /**
8642
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/documents`
8643
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8644
+ */
8645
+
8646
+ /**
8647
+ * @@@
8648
+ *
8649
+ * @public exported from `@promptbook/node`
8650
+ */
8651
+ function $provideExecutablesForNode(options) {
8652
+ return __awaiter(this, void 0, void 0, function () {
8653
+ var _a, _b, isAutoInstalled, _c, isVerbose;
8654
+ var _d;
8655
+ return __generator(this, function (_e) {
8656
+ switch (_e.label) {
8657
+ case 0:
8658
+ if (!$isRunningInNode()) {
8659
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8660
+ }
8661
+ _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;
8662
+ TODO_USE(isAutoInstalled); // <- TODO: [🔱][🧠] Auto-install the executables
8663
+ TODO_USE(isVerbose);
8664
+ _d = {};
8665
+ return [4 /*yield*/, locatePandoc()];
8666
+ case 1:
8667
+ _d.pandocPath = _e.sent();
8668
+ return [4 /*yield*/, locateLibreoffice()];
8669
+ case 2: return [2 /*return*/, (_d.libreOfficePath = _e.sent(),
8670
+ _d)];
8671
+ }
8672
+ });
8673
+ });
8674
+ }
8675
+ /**
8676
+ * TODO: [🧠] Allow to override the executables without need to call `locatePandoc` / `locateLibreoffice` in case of provided
8677
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8678
+ */
8679
+
8388
8680
  /**
8389
8681
  * @@@
8390
8682
  *
@@ -8615,57 +8907,6 @@
8615
8907
  * TODO: [®] DRY Register logic
8616
8908
  */
8617
8909
 
8618
- /**
8619
- * @@@
8620
- *
8621
- * @public exported from `@promptbook/node`
8622
- */
8623
- function $provideExecutablesForNode(options) {
8624
- return __awaiter(this, void 0, void 0, function () {
8625
- var _a, _b, isAutoInstalled, _c, isVerbose;
8626
- return __generator(this, function (_d) {
8627
- if (!$isRunningInNode()) {
8628
- throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8629
- }
8630
- _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;
8631
- TODO_USE(isAutoInstalled);
8632
- TODO_USE(isVerbose);
8633
- return [2 /*return*/, {
8634
- // TODO: !!!!!! use `locate-app` library here
8635
- pandocPath: 'C:/Users/me/AppData/Local/Pandoc/pandoc.exe',
8636
- libreOfficePath: 'C:/Program Files/LibreOffice/program/swriter.exe',
8637
- }];
8638
- });
8639
- });
8640
- }
8641
- /**
8642
- * TODO: [🧠] THis should be maybe in different folder
8643
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8644
- */
8645
-
8646
- /**
8647
- * @@@
8648
- *
8649
- * @public exported from `@promptbook/node`
8650
- */
8651
- function $provideFilesystemForNode(options) {
8652
- if (!$isRunningInNode()) {
8653
- throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8654
- }
8655
- var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8656
- TODO_USE(isVerbose);
8657
- return {
8658
- stat: promises.stat,
8659
- access: promises.access,
8660
- constants: promises.constants,
8661
- readFile: promises.readFile,
8662
- readdir: promises.readdir,
8663
- };
8664
- }
8665
- /**
8666
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8667
- */
8668
-
8669
8910
  /**
8670
8911
  * @@@
8671
8912
  *
@@ -12745,7 +12986,7 @@
12745
12986
  assistant_id: this.assistantId,
12746
12987
  thread: {
12747
12988
  messages: [
12748
- // TODO: !!!!!! Allow threads to be passed
12989
+ // TODO: [🗯] !!!!!! Allow threads to be passed
12749
12990
  { role: 'user', content: rawPromptContent },
12750
12991
  ],
12751
12992
  },
@@ -12755,7 +12996,6 @@
12755
12996
  if (this.options.isVerbose) {
12756
12997
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
12757
12998
  }
12758
- console.log('!!!!!! OpenAI client', client);
12759
12999
  return [4 /*yield*/, client.beta.threads.createAndRunStream(rawRequest)];
12760
13000
  case 2:
12761
13001
  stream = _g.sent();
@@ -12773,7 +13013,7 @@
12773
13013
  messageDelta.content[0].type === 'text') {
12774
13014
  console.info('messageDelta', (_a = messageDelta.content[0].text) === null || _a === void 0 ? void 0 : _a.value);
12775
13015
  }
12776
- // TODO: !!!!!! report progress
13016
+ // <- TODO: [🐚] Make streaming and running tasks working
12777
13017
  });
12778
13018
  stream.on('messageCreated', function (message) {
12779
13019
  if (_this.options.isVerbose) {
@@ -12805,14 +13045,16 @@
12805
13045
  // eslint-disable-next-line prefer-const
12806
13046
  complete = getCurrentIsoDate();
12807
13047
  usage = UNCERTAIN_USAGE;
12808
- // TODO: !!!!!!> = computeOpenAiUsage(content, resultContent || '', rawResponse);
13048
+ // <- TODO: [🥘] Compute real usage for assistant
13049
+ // ?> const usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
12809
13050
  if (resultContent === null) {
12810
13051
  throw new PipelineExecutionError('No response message from OpenAI');
12811
13052
  }
12812
13053
  return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiAssistantExecutionTools ChatPromptResult', {
12813
13054
  content: resultContent,
12814
13055
  modelName: 'assistant',
12815
- // <- TODO: !!!!!! Can we detect really used model: rawResponse.model || modelName,
13056
+ // <- TODO: [🥘] Detect used model in assistant
13057
+ // ?> model: rawResponse.model || modelName,
12816
13058
  timing: {
12817
13059
  start: start,
12818
13060
  complete: complete,
@@ -12830,7 +13072,6 @@
12830
13072
  return OpenAiAssistantExecutionTools;
12831
13073
  }(OpenAiExecutionTools));
12832
13074
  /**
12833
- * TODO: !!!!!! DO not use colors - can be used in browser
12834
13075
  * TODO: [🧠][🧙‍♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
12835
13076
  * TODO: Maybe make custom OpenAiError
12836
13077
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
@@ -13449,9 +13690,14 @@
13449
13690
  asJson: function () {
13450
13691
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
13451
13692
  },
13452
- asBlob: function () {
13453
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
13454
- },
13693
+ /*
13694
+ TODO: [🥽]
13695
+ > asBlob() {
13696
+ > throw new UnexpectedError(
13697
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
13698
+ > );
13699
+ > },
13700
+ */
13455
13701
  };
13456
13702
  knowledge = this.markdownScraper.scrape(markdownSource);
13457
13703
  return [4 /*yield*/, cacheFilehandler.destroy()];
@@ -13617,9 +13863,14 @@
13617
13863
  asJson: function () {
13618
13864
  throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asJson`');
13619
13865
  },
13620
- asBlob: function () {
13621
- throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asBlob`');
13622
- },
13866
+ /*
13867
+ TODO: [🥽]
13868
+ > asBlob() {
13869
+ > throw new UnexpectedError(
13870
+ > 'Did not expect that `documentScraper` would need to get the content `asBlob`',
13871
+ > );
13872
+ > },
13873
+ */
13623
13874
  };
13624
13875
  knowledge = this.documentScraper.scrape(markdownSource);
13625
13876
  return [4 /*yield*/, cacheFilehandler.destroy()];
@@ -13824,196 +14075,6 @@
13824
14075
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
13825
14076
  */
13826
14077
 
13827
- /**
13828
- * Metadata of the scraper
13829
- *
13830
- * @private within the scraper directory
13831
- */
13832
- var websiteScraperMetadata = $deepFreeze({
13833
- title: 'Website scraper',
13834
- packageName: '@promptbook/website-crawler',
13835
- className: 'WebsiteScraper',
13836
- mimeTypes: ['text/html'],
13837
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
13838
- isAvilableInBrowser: false,
13839
- requiredExecutables: [],
13840
- }); /* <- TODO: [🤛] */
13841
- /**
13842
- * Registration of known scraper metadata
13843
- *
13844
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
13845
- *
13846
- * @public exported from `@promptbook/core`
13847
- * @public exported from `@promptbook/cli`
13848
- */
13849
- var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
13850
-
13851
- /**
13852
- * Create a new showdown converter instance
13853
- *
13854
- * @private utility of `WebsiteScraper`
13855
- */
13856
- function createShowdownConverter() {
13857
- return new showdown.Converter({
13858
- flavor: 'github',
13859
- /*
13860
- > import showdownHighlight from 'showdown-highlight';
13861
- > extensions: [
13862
- > showdownHighlight({
13863
- > // Whether to add the classes to the <pre> tag, default is false
13864
- > pre: true,
13865
- > // Whether to use hljs' auto language detection, default is true
13866
- > auto_detection: true,
13867
- > }),
13868
- > ],
13869
- */
13870
- });
13871
- }
13872
-
13873
- /**
13874
- * Scraper for websites
13875
- *
13876
- * @see `documentationUrl` for more details
13877
- * @public exported from `@promptbook/website-crawler`
13878
- */
13879
- var WebsiteScraper = /** @class */ (function () {
13880
- function WebsiteScraper(tools, options) {
13881
- this.tools = tools;
13882
- this.options = options;
13883
- this.markdownScraper = new MarkdownScraper(tools, options);
13884
- this.showdownConverter = createShowdownConverter();
13885
- }
13886
- Object.defineProperty(WebsiteScraper.prototype, "metadata", {
13887
- /**
13888
- * Metadata of the scraper which includes title, mime types, etc.
13889
- */
13890
- get: function () {
13891
- return websiteScraperMetadata;
13892
- },
13893
- enumerable: false,
13894
- configurable: true
13895
- });
13896
- /**
13897
- * Convert the website to `.md` file and returns intermediate source
13898
- *
13899
- * 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
13900
- */
13901
- WebsiteScraper.prototype.$convert = function (source) {
13902
- return __awaiter(this, void 0, void 0, function () {
13903
- var _a, _b,
13904
- // TODO: [🧠] Maybe in node use headless browser not just JSDOM
13905
- rootDirname, _c, cacheDirname, _d, intermediateFilesStrategy, _e, isVerbose, jsdom$1, _f, reader, article, html, i, cacheFilehandler, markdown;
13906
- return __generator(this, function (_g) {
13907
- switch (_g.label) {
13908
- case 0:
13909
- _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;
13910
- // TODO: !!!!!! Does this work in browser? Make it work.
13911
- if (source.url === null) {
13912
- throw new KnowledgeScrapeError('Website scraper requires URL');
13913
- }
13914
- _f = jsdom.JSDOM.bind;
13915
- return [4 /*yield*/, source.asText()];
13916
- case 1:
13917
- jsdom$1 = new (_f.apply(jsdom.JSDOM, [void 0, _g.sent(), {
13918
- url: source.url,
13919
- }]))();
13920
- reader = new readability.Readability(jsdom$1.window.document);
13921
- article = reader.parse();
13922
- html = (article === null || article === void 0 ? void 0 : article.content) || (article === null || article === void 0 ? void 0 : article.textContent) || jsdom$1.window.document.body.innerHTML;
13923
- // Note: Unwrap html such as it is convertable by `markdownConverter`
13924
- for (i = 0; i < 2; i++) {
13925
- html = html.replace(/<div\s*(?:id="readability-page-\d+"\s+class="page")?>(.*)<\/div>/is, '$1');
13926
- }
13927
- if (html.includes('<div')) {
13928
- html = (article === null || article === void 0 ? void 0 : article.textContent) || '';
13929
- }
13930
- return [4 /*yield*/, getScraperIntermediateSource(source, {
13931
- rootDirname: rootDirname,
13932
- cacheDirname: cacheDirname,
13933
- intermediateFilesStrategy: intermediateFilesStrategy,
13934
- extension: 'html',
13935
- isVerbose: isVerbose,
13936
- })];
13937
- case 2:
13938
- cacheFilehandler = _g.sent();
13939
- return [4 /*yield*/, promises.writeFile(cacheFilehandler.filename, html, 'utf-8')];
13940
- case 3:
13941
- _g.sent();
13942
- markdown = this.showdownConverter.makeMarkdown(html, jsdom$1.window.document);
13943
- return [2 /*return*/, __assign(__assign({}, cacheFilehandler), { markdown: markdown })];
13944
- }
13945
- });
13946
- });
13947
- };
13948
- /**
13949
- * Scrapes the website and returns the knowledge pieces or `null` if it can't scrape it
13950
- */
13951
- WebsiteScraper.prototype.scrape = function (source) {
13952
- return __awaiter(this, void 0, void 0, function () {
13953
- var cacheFilehandler, markdownSource, knowledge;
13954
- return __generator(this, function (_a) {
13955
- switch (_a.label) {
13956
- case 0: return [4 /*yield*/, this.$convert(source)];
13957
- case 1:
13958
- cacheFilehandler = _a.sent();
13959
- markdownSource = {
13960
- source: source.source,
13961
- filename: cacheFilehandler.filename,
13962
- url: null,
13963
- mimeType: 'text/markdown',
13964
- asText: function () {
13965
- return cacheFilehandler.markdown;
13966
- },
13967
- asJson: function () {
13968
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
13969
- },
13970
- asBlob: function () {
13971
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
13972
- },
13973
- };
13974
- knowledge = this.markdownScraper.scrape(markdownSource);
13975
- return [4 /*yield*/, cacheFilehandler.destroy()];
13976
- case 2:
13977
- _a.sent();
13978
- return [2 /*return*/, knowledge];
13979
- }
13980
- });
13981
- });
13982
- };
13983
- return WebsiteScraper;
13984
- }());
13985
- /**
13986
- * TODO: [👣] Scraped website in .md can act as cache item - there is no need to run conversion each time
13987
- * TODO: [🪂] Do it in parallel 11:11
13988
- * Note: No need to aggregate usage here, it is done by intercepting the llmTools
13989
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
13990
- */
13991
-
13992
- /**
13993
- * @@@
13994
- *
13995
- * @public exported from `@promptbook/website-crawler`
13996
- */
13997
- var createWebsiteScraper = Object.assign(function (tools, options) {
13998
- return new WebsiteScraper(tools, options);
13999
- }, websiteScraperMetadata); /* <- TODO: [🤛] */
14000
- /**
14001
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
14002
- */
14003
-
14004
- /**
14005
- * Registration of known scraper
14006
- *
14007
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
14008
- *
14009
- * @public exported from `@promptbook/website-crawler`
14010
- * @public exported from `@promptbook/cli`
14011
- */
14012
- var _WebsiteScraperRegistration = $scrapersRegister.register(createWebsiteScraper);
14013
- /**
14014
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
14015
- */
14016
-
14017
14078
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
14018
14079
  exports._AnthropicClaudeMetadataRegistration = _AnthropicClaudeMetadataRegistration;
14019
14080
  exports._AnthropicClaudeRegistration = _AnthropicClaudeRegistration;
@@ -14032,8 +14093,6 @@
14032
14093
  exports._OpenAiRegistration = _OpenAiRegistration;
14033
14094
  exports._PdfScraperMetadataRegistration = _PdfScraperMetadataRegistration;
14034
14095
  exports._PdfScraperRegistration = _PdfScraperRegistration;
14035
- exports._WebsiteScraperMetadataRegistration = _WebsiteScraperMetadataRegistration;
14036
- exports._WebsiteScraperRegistration = _WebsiteScraperRegistration;
14037
14096
 
14038
14097
  Object.defineProperty(exports, '__esModule', { value: true });
14039
14098