@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/esm/index.es.js CHANGED
@@ -10,6 +10,8 @@ import { unparse, parse } from 'papaparse';
10
10
  import { SHA256 } from 'crypto-js';
11
11
  import hexEncoder from 'crypto-js/enc-hex';
12
12
  import { lookup } from 'mime-types';
13
+ import { exec as exec$2, spawn } from 'child_process';
14
+ import { promisify } from 'util';
13
15
  import * as dotenv from 'dotenv';
14
16
  import sha256 from 'crypto-js/sha256';
15
17
  import glob from 'glob-promise';
@@ -17,16 +19,12 @@ import { io } from 'socket.io-client';
17
19
  import Anthropic from '@anthropic-ai/sdk';
18
20
  import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
19
21
  import OpenAI from 'openai';
20
- import { spawn } from 'child_process';
21
- import { Readability } from '@mozilla/readability';
22
- import { JSDOM } from 'jsdom';
23
- import { Converter } from 'showdown';
24
22
 
25
23
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
26
24
  /**
27
25
  * The version of the Promptbook library
28
26
  */
29
- var PROMPTBOOK_VERSION = '0.72.0-14';
27
+ var PROMPTBOOK_VERSION = '0.72.0-22';
30
28
  // TODO: [main] !!!! List here all the versions and annotate + put into script
31
29
 
32
30
  /*! *****************************************************************************
@@ -4927,7 +4925,6 @@ var $scrapersRegister = new $Register('scraper_constructors');
4927
4925
  * TODO: [®] DRY Register logic
4928
4926
  */
4929
4927
 
4930
- // TODO: !!!!!!last - Maybe delete this function
4931
4928
  /**
4932
4929
  * Creates a message with all registered scrapers
4933
4930
  *
@@ -5200,7 +5197,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5200
5197
  return __awaiter(this, void 0, void 0, function () {
5201
5198
  var sourceContent, name, _b, _c, rootDirname, _d,
5202
5199
  // <- TODO: process.cwd() if running in Node.js
5203
- isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType_1;
5200
+ isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5204
5201
  return __generator(this, function (_e) {
5205
5202
  switch (_e.label) {
5206
5203
  case 0:
@@ -5222,19 +5219,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5222
5219
  filename: null,
5223
5220
  url: url,
5224
5221
  mimeType: mimeType,
5225
- asBlob: function () {
5226
- return __awaiter(this, void 0, void 0, function () {
5227
- var content;
5228
- return __generator(this, function (_a) {
5229
- switch (_a.label) {
5230
- case 0: return [4 /*yield*/, response_1.blob()];
5231
- case 1:
5232
- content = _a.sent();
5233
- return [2 /*return*/, content];
5234
- }
5235
- });
5236
- });
5237
- },
5222
+ /*
5223
+ TODO: [🥽]
5224
+ > async asBlob() {
5225
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5226
+ > const content = await response.blob();
5227
+ > return content;
5228
+ > },
5229
+ */
5238
5230
  asJson: function () {
5239
5231
  return __awaiter(this, void 0, void 0, function () {
5240
5232
  var content;
@@ -5274,34 +5266,31 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5274
5266
  }
5275
5267
  filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
5276
5268
  fileExtension = getFileExtension(filename_1);
5277
- mimeType_1 = extensionToMimeType(fileExtension || '');
5269
+ mimeType = extensionToMimeType(fileExtension || '');
5278
5270
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5279
5271
  case 3:
5280
5272
  if (!(_e.sent())) {
5281
5273
  throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5282
5274
  }
5283
- // TODO: !!!!!! Test security file - file is scoped to the project (maybe do this in `filesystemTools`)
5275
+ // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5284
5276
  return [2 /*return*/, {
5285
5277
  source: name,
5286
5278
  filename: filename_1,
5287
5279
  url: null,
5288
- mimeType: mimeType_1,
5289
- asBlob: function () {
5290
- return __awaiter(this, void 0, void 0, function () {
5291
- var content;
5292
- return __generator(this, function (_a) {
5293
- switch (_a.label) {
5294
- case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
5295
- case 1:
5296
- content = _a.sent();
5297
- return [2 /*return*/, new Blob([
5298
- content,
5299
- // <- TODO: !!!!!! Test that this is working
5300
- ], { type: mimeType_1 })];
5301
- }
5302
- });
5303
- });
5304
- },
5280
+ mimeType: mimeType,
5281
+ /*
5282
+ TODO: [🥽]
5283
+ > async asBlob() {
5284
+ > const content = await tools.fs!.readFile(filename);
5285
+ > return new Blob(
5286
+ > [
5287
+ > content,
5288
+ > // <- TODO: [🥽] This is NOT tested, test it
5289
+ > ],
5290
+ > { type: mimeType },
5291
+ > );
5292
+ > },
5293
+ */
5305
5294
  asJson: function () {
5306
5295
  return __awaiter(this, void 0, void 0, function () {
5307
5296
  var _a, _b;
@@ -5337,9 +5326,14 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5337
5326
  asJson: function () {
5338
5327
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
5339
5328
  },
5340
- asBlob: function () {
5341
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
5342
- },
5329
+ /*
5330
+ TODO: [🥽]
5331
+ > asBlob() {
5332
+ > throw new UnexpectedError(
5333
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
5334
+ > );
5335
+ > },
5336
+ */
5343
5337
  }];
5344
5338
  }
5345
5339
  });
@@ -5664,6 +5658,7 @@ var knowledgeCommandParser = {
5664
5658
  'KNOWLEDGE ./hejny-cv.md',
5665
5659
  'KNOWLEDGE ./hejny-cv.pdf',
5666
5660
  'KNOWLEDGE ./hejny-cv.docx',
5661
+ // <- TODO: [😿] Allow ONLY files scoped in the (sub)directory NOT ../ and test it
5667
5662
  ],
5668
5663
  /**
5669
5664
  * Parses the KNOWLEDGE command
@@ -8372,6 +8367,301 @@ function pipelineStringToJson(pipelineString, tools, options) {
8372
8367
  * TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
8373
8368
  */
8374
8369
 
8370
+ // Note: We want to use the `exec` as async function
8371
+ var exec$1 = promisify(exec$2);
8372
+ /**
8373
+ * @@@
8374
+ *
8375
+ * @private within the repository
8376
+ */
8377
+ function locateAppOnLinux(_a) {
8378
+ var appName = _a.appName, linuxWhich = _a.linuxWhich;
8379
+ return __awaiter(this, void 0, void 0, function () {
8380
+ var _b, stderr, stdout;
8381
+ return __generator(this, function (_c) {
8382
+ switch (_c.label) {
8383
+ case 0: return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8384
+ case 1:
8385
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8386
+ if (!stderr && stdout) {
8387
+ return [2 /*return*/, stdout.trim()];
8388
+ }
8389
+ throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
8390
+ }
8391
+ });
8392
+ });
8393
+ }
8394
+ /**
8395
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8396
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8397
+ */
8398
+
8399
+ /**
8400
+ * @@@
8401
+ *
8402
+ * @public exported from `@promptbook/node`
8403
+ */
8404
+ function $provideFilesystemForNode(options) {
8405
+ if (!$isRunningInNode()) {
8406
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8407
+ }
8408
+ var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8409
+ TODO_USE(isVerbose);
8410
+ return {
8411
+ stat: stat,
8412
+ access: access,
8413
+ constants: constants,
8414
+ readFile: readFile,
8415
+ readdir: readdir,
8416
+ };
8417
+ }
8418
+ /**
8419
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8420
+ */
8421
+
8422
+ /**
8423
+ * Checks if the file is executable
8424
+ *
8425
+ * @private within the repository
8426
+ */
8427
+ function isExecutable(path, fs) {
8428
+ return __awaiter(this, void 0, void 0, function () {
8429
+ return __generator(this, function (_a) {
8430
+ switch (_a.label) {
8431
+ case 0:
8432
+ _a.trys.push([0, 2, , 3]);
8433
+ return [4 /*yield*/, fs.access(path, fs.constants.X_OK)];
8434
+ case 1:
8435
+ _a.sent();
8436
+ return [2 /*return*/, true];
8437
+ case 2:
8438
+ _a.sent();
8439
+ return [2 /*return*/, false];
8440
+ case 3: return [2 /*return*/];
8441
+ }
8442
+ });
8443
+ });
8444
+ }
8445
+ /**
8446
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
8447
+ * TODO: [🖇] What about symlinks?
8448
+ */
8449
+
8450
+ // Note: Module `userhome` has no types available, so it is imported using `require`
8451
+ // @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
8452
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8453
+ var userhome = require('userhome');
8454
+ // Note: We want to use the `exec` as async function
8455
+ var exec = promisify(exec$2);
8456
+ /**
8457
+ * @@@
8458
+ *
8459
+ * @private within the repository
8460
+ */
8461
+ function locateAppOnMacOs(_a) {
8462
+ var appName = _a.appName, macOsName = _a.macOsName;
8463
+ return __awaiter(this, void 0, void 0, function () {
8464
+ var toExec, regPath, altPath, _b, stderr, stdout;
8465
+ return __generator(this, function (_c) {
8466
+ switch (_c.label) {
8467
+ case 0:
8468
+ toExec = "/Contents/MacOS/".concat(macOsName);
8469
+ regPath = "/Applications/".concat(macOsName, ".app") + toExec;
8470
+ altPath = userhome(regPath.slice(1));
8471
+ return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
8472
+ case 1:
8473
+ if (!_c.sent()) return [3 /*break*/, 2];
8474
+ return [2 /*return*/, regPath];
8475
+ case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
8476
+ case 3:
8477
+ if (_c.sent()) {
8478
+ return [2 /*return*/, altPath];
8479
+ }
8480
+ _c.label = 4;
8481
+ case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
8482
+ case 5:
8483
+ _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8484
+ if (!stderr && stdout) {
8485
+ return [2 /*return*/, stdout.trim() + toExec];
8486
+ }
8487
+ throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
8488
+ }
8489
+ });
8490
+ });
8491
+ }
8492
+ /**
8493
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8494
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8495
+ */
8496
+
8497
+ /**
8498
+ * @@@
8499
+ *
8500
+ * @private within the repository
8501
+ */
8502
+ function locateAppOnWindows(_a) {
8503
+ var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
8504
+ return __awaiter(this, void 0, void 0, function () {
8505
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1;
8506
+ var e_1, _b;
8507
+ return __generator(this, function (_c) {
8508
+ switch (_c.label) {
8509
+ case 0:
8510
+ prefixes = [
8511
+ process.env.LOCALAPPDATA,
8512
+ join(process.env.LOCALAPPDATA || '', 'Programs'),
8513
+ process.env.PROGRAMFILES,
8514
+ process.env['PROGRAMFILES(X86)'],
8515
+ ];
8516
+ _c.label = 1;
8517
+ case 1:
8518
+ _c.trys.push([1, 6, 7, 8]);
8519
+ prefixes_1 = __values(prefixes), prefixes_1_1 = prefixes_1.next();
8520
+ _c.label = 2;
8521
+ case 2:
8522
+ if (!!prefixes_1_1.done) return [3 /*break*/, 5];
8523
+ prefix = prefixes_1_1.value;
8524
+ path = prefix + windowsSuffix;
8525
+ return [4 /*yield*/, isExecutable(path, $provideFilesystemForNode())];
8526
+ case 3:
8527
+ if (_c.sent()) {
8528
+ return [2 /*return*/, path];
8529
+ }
8530
+ _c.label = 4;
8531
+ case 4:
8532
+ prefixes_1_1 = prefixes_1.next();
8533
+ return [3 /*break*/, 2];
8534
+ case 5: return [3 /*break*/, 8];
8535
+ case 6:
8536
+ e_1_1 = _c.sent();
8537
+ e_1 = { error: e_1_1 };
8538
+ return [3 /*break*/, 8];
8539
+ case 7:
8540
+ try {
8541
+ if (prefixes_1_1 && !prefixes_1_1.done && (_b = prefixes_1.return)) _b.call(prefixes_1);
8542
+ }
8543
+ finally { if (e_1) throw e_1.error; }
8544
+ return [7 /*endfinally*/];
8545
+ case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
8546
+ }
8547
+ });
8548
+ });
8549
+ }
8550
+ /**
8551
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8552
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8553
+ */
8554
+
8555
+ /**
8556
+ * Locates an application on the system
8557
+ *
8558
+ * @private within the repository
8559
+ */
8560
+ function locateApp(options) {
8561
+ if (!$isRunningInNode()) {
8562
+ throw new EnvironmentMismatchError('Locating apps works only in Node.js environment');
8563
+ }
8564
+ var appName = options.appName, linuxWhich = options.linuxWhich, windowsSuffix = options.windowsSuffix, macOsName = options.macOsName;
8565
+ if (process.platform === 'win32') {
8566
+ if (windowsSuffix) {
8567
+ return locateAppOnWindows({ appName: appName, windowsSuffix: windowsSuffix });
8568
+ }
8569
+ else {
8570
+ throw new Error("".concat(appName, " is not available on Windows."));
8571
+ }
8572
+ }
8573
+ else if (process.platform === 'darwin') {
8574
+ if (macOsName) {
8575
+ return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
8576
+ }
8577
+ else {
8578
+ throw new Error("".concat(appName, " is not available on macOS."));
8579
+ }
8580
+ }
8581
+ else {
8582
+ if (linuxWhich) {
8583
+ return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
8584
+ }
8585
+ else {
8586
+ throw new Error("".concat(appName, " is not available on Linux."));
8587
+ }
8588
+ }
8589
+ }
8590
+ /**
8591
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node`
8592
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8593
+ */
8594
+
8595
+ /**
8596
+ * @@@
8597
+ *
8598
+ * @private within the repository
8599
+ */
8600
+ function locateLibreoffice() {
8601
+ return locateApp({
8602
+ appName: 'Libreoffice',
8603
+ linuxWhich: 'libreoffice',
8604
+ windowsSuffix: '\\LibreOffice\\program\\soffice.exe',
8605
+ macOsName: 'LibreOffice',
8606
+ });
8607
+ }
8608
+ /**
8609
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/legacy-documents`
8610
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8611
+ */
8612
+
8613
+ /**
8614
+ * @@@
8615
+ *
8616
+ * @private within the repository
8617
+ */
8618
+ function locatePandoc() {
8619
+ return locateApp({
8620
+ appName: 'Pandoc',
8621
+ linuxWhich: 'pandoc',
8622
+ windowsSuffix: '\\Pandoc\\pandoc.exe',
8623
+ macOsName: 'Pandoc',
8624
+ });
8625
+ }
8626
+ /**
8627
+ * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/documents`
8628
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8629
+ */
8630
+
8631
+ /**
8632
+ * @@@
8633
+ *
8634
+ * @public exported from `@promptbook/node`
8635
+ */
8636
+ function $provideExecutablesForNode(options) {
8637
+ return __awaiter(this, void 0, void 0, function () {
8638
+ var _a, _b, isAutoInstalled, _c, isVerbose;
8639
+ var _d;
8640
+ return __generator(this, function (_e) {
8641
+ switch (_e.label) {
8642
+ case 0:
8643
+ if (!$isRunningInNode()) {
8644
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8645
+ }
8646
+ _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;
8647
+ TODO_USE(isAutoInstalled); // <- TODO: [🔱][🧠] Auto-install the executables
8648
+ TODO_USE(isVerbose);
8649
+ _d = {};
8650
+ return [4 /*yield*/, locatePandoc()];
8651
+ case 1:
8652
+ _d.pandocPath = _e.sent();
8653
+ return [4 /*yield*/, locateLibreoffice()];
8654
+ case 2: return [2 /*return*/, (_d.libreOfficePath = _e.sent(),
8655
+ _d)];
8656
+ }
8657
+ });
8658
+ });
8659
+ }
8660
+ /**
8661
+ * TODO: [🧠] Allow to override the executables without need to call `locatePandoc` / `locateLibreoffice` in case of provided
8662
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8663
+ */
8664
+
8375
8665
  /**
8376
8666
  * @@@
8377
8667
  *
@@ -8602,57 +8892,6 @@ function $provideLlmToolsFromEnv(options) {
8602
8892
  * TODO: [®] DRY Register logic
8603
8893
  */
8604
8894
 
8605
- /**
8606
- * @@@
8607
- *
8608
- * @public exported from `@promptbook/node`
8609
- */
8610
- function $provideExecutablesForNode(options) {
8611
- return __awaiter(this, void 0, void 0, function () {
8612
- var _a, _b, isAutoInstalled, _c, isVerbose;
8613
- return __generator(this, function (_d) {
8614
- if (!$isRunningInNode()) {
8615
- throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8616
- }
8617
- _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;
8618
- TODO_USE(isAutoInstalled);
8619
- TODO_USE(isVerbose);
8620
- return [2 /*return*/, {
8621
- // TODO: !!!!!! use `locate-app` library here
8622
- pandocPath: 'C:/Users/me/AppData/Local/Pandoc/pandoc.exe',
8623
- libreOfficePath: 'C:/Program Files/LibreOffice/program/swriter.exe',
8624
- }];
8625
- });
8626
- });
8627
- }
8628
- /**
8629
- * TODO: [🧠] THis should be maybe in different folder
8630
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8631
- */
8632
-
8633
- /**
8634
- * @@@
8635
- *
8636
- * @public exported from `@promptbook/node`
8637
- */
8638
- function $provideFilesystemForNode(options) {
8639
- if (!$isRunningInNode()) {
8640
- throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8641
- }
8642
- var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8643
- TODO_USE(isVerbose);
8644
- return {
8645
- stat: stat,
8646
- access: access,
8647
- constants: constants,
8648
- readFile: readFile,
8649
- readdir: readdir,
8650
- };
8651
- }
8652
- /**
8653
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8654
- */
8655
-
8656
8895
  /**
8657
8896
  * @@@
8658
8897
  *
@@ -12732,7 +12971,7 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12732
12971
  assistant_id: this.assistantId,
12733
12972
  thread: {
12734
12973
  messages: [
12735
- // TODO: !!!!!! Allow threads to be passed
12974
+ // TODO: [🗯] !!!!!! Allow threads to be passed
12736
12975
  { role: 'user', content: rawPromptContent },
12737
12976
  ],
12738
12977
  },
@@ -12742,7 +12981,6 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12742
12981
  if (this.options.isVerbose) {
12743
12982
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
12744
12983
  }
12745
- console.log('!!!!!! OpenAI client', client);
12746
12984
  return [4 /*yield*/, client.beta.threads.createAndRunStream(rawRequest)];
12747
12985
  case 2:
12748
12986
  stream = _g.sent();
@@ -12760,7 +12998,7 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12760
12998
  messageDelta.content[0].type === 'text') {
12761
12999
  console.info('messageDelta', (_a = messageDelta.content[0].text) === null || _a === void 0 ? void 0 : _a.value);
12762
13000
  }
12763
- // TODO: !!!!!! report progress
13001
+ // <- TODO: [🐚] Make streaming and running tasks working
12764
13002
  });
12765
13003
  stream.on('messageCreated', function (message) {
12766
13004
  if (_this.options.isVerbose) {
@@ -12792,14 +13030,16 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12792
13030
  // eslint-disable-next-line prefer-const
12793
13031
  complete = getCurrentIsoDate();
12794
13032
  usage = UNCERTAIN_USAGE;
12795
- // TODO: !!!!!!> = computeOpenAiUsage(content, resultContent || '', rawResponse);
13033
+ // <- TODO: [🥘] Compute real usage for assistant
13034
+ // ?> const usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
12796
13035
  if (resultContent === null) {
12797
13036
  throw new PipelineExecutionError('No response message from OpenAI');
12798
13037
  }
12799
13038
  return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiAssistantExecutionTools ChatPromptResult', {
12800
13039
  content: resultContent,
12801
13040
  modelName: 'assistant',
12802
- // <- TODO: !!!!!! Can we detect really used model: rawResponse.model || modelName,
13041
+ // <- TODO: [🥘] Detect used model in assistant
13042
+ // ?> model: rawResponse.model || modelName,
12803
13043
  timing: {
12804
13044
  start: start,
12805
13045
  complete: complete,
@@ -12817,7 +13057,6 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12817
13057
  return OpenAiAssistantExecutionTools;
12818
13058
  }(OpenAiExecutionTools));
12819
13059
  /**
12820
- * TODO: !!!!!! DO not use colors - can be used in browser
12821
13060
  * TODO: [🧠][🧙‍♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
12822
13061
  * TODO: Maybe make custom OpenAiError
12823
13062
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
@@ -13436,9 +13675,14 @@ var DocumentScraper = /** @class */ (function () {
13436
13675
  asJson: function () {
13437
13676
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
13438
13677
  },
13439
- asBlob: function () {
13440
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
13441
- },
13678
+ /*
13679
+ TODO: [🥽]
13680
+ > asBlob() {
13681
+ > throw new UnexpectedError(
13682
+ > 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
13683
+ > );
13684
+ > },
13685
+ */
13442
13686
  };
13443
13687
  knowledge = this.markdownScraper.scrape(markdownSource);
13444
13688
  return [4 /*yield*/, cacheFilehandler.destroy()];
@@ -13604,9 +13848,14 @@ var LegacyDocumentScraper = /** @class */ (function () {
13604
13848
  asJson: function () {
13605
13849
  throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asJson`');
13606
13850
  },
13607
- asBlob: function () {
13608
- throw new UnexpectedError('Did not expect that `documentScraper` would need to get the content `asBlob`');
13609
- },
13851
+ /*
13852
+ TODO: [🥽]
13853
+ > asBlob() {
13854
+ > throw new UnexpectedError(
13855
+ > 'Did not expect that `documentScraper` would need to get the content `asBlob`',
13856
+ > );
13857
+ > },
13858
+ */
13610
13859
  };
13611
13860
  knowledge = this.documentScraper.scrape(markdownSource);
13612
13861
  return [4 /*yield*/, cacheFilehandler.destroy()];
@@ -13811,195 +14060,5 @@ var _PdfScraperRegistration = $scrapersRegister.register(createPdfScraper);
13811
14060
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
13812
14061
  */
13813
14062
 
13814
- /**
13815
- * Metadata of the scraper
13816
- *
13817
- * @private within the scraper directory
13818
- */
13819
- var websiteScraperMetadata = $deepFreeze({
13820
- title: 'Website scraper',
13821
- packageName: '@promptbook/website-crawler',
13822
- className: 'WebsiteScraper',
13823
- mimeTypes: ['text/html'],
13824
- documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
13825
- isAvilableInBrowser: false,
13826
- requiredExecutables: [],
13827
- }); /* <- TODO: [🤛] */
13828
- /**
13829
- * Registration of known scraper metadata
13830
- *
13831
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
13832
- *
13833
- * @public exported from `@promptbook/core`
13834
- * @public exported from `@promptbook/cli`
13835
- */
13836
- var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
13837
-
13838
- /**
13839
- * Create a new showdown converter instance
13840
- *
13841
- * @private utility of `WebsiteScraper`
13842
- */
13843
- function createShowdownConverter() {
13844
- return new Converter({
13845
- flavor: 'github',
13846
- /*
13847
- > import showdownHighlight from 'showdown-highlight';
13848
- > extensions: [
13849
- > showdownHighlight({
13850
- > // Whether to add the classes to the <pre> tag, default is false
13851
- > pre: true,
13852
- > // Whether to use hljs' auto language detection, default is true
13853
- > auto_detection: true,
13854
- > }),
13855
- > ],
13856
- */
13857
- });
13858
- }
13859
-
13860
- /**
13861
- * Scraper for websites
13862
- *
13863
- * @see `documentationUrl` for more details
13864
- * @public exported from `@promptbook/website-crawler`
13865
- */
13866
- var WebsiteScraper = /** @class */ (function () {
13867
- function WebsiteScraper(tools, options) {
13868
- this.tools = tools;
13869
- this.options = options;
13870
- this.markdownScraper = new MarkdownScraper(tools, options);
13871
- this.showdownConverter = createShowdownConverter();
13872
- }
13873
- Object.defineProperty(WebsiteScraper.prototype, "metadata", {
13874
- /**
13875
- * Metadata of the scraper which includes title, mime types, etc.
13876
- */
13877
- get: function () {
13878
- return websiteScraperMetadata;
13879
- },
13880
- enumerable: false,
13881
- configurable: true
13882
- });
13883
- /**
13884
- * Convert the website to `.md` file and returns intermediate source
13885
- *
13886
- * 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
13887
- */
13888
- WebsiteScraper.prototype.$convert = function (source) {
13889
- return __awaiter(this, void 0, void 0, function () {
13890
- var _a, _b,
13891
- // TODO: [🧠] Maybe in node use headless browser not just JSDOM
13892
- rootDirname, _c, cacheDirname, _d, intermediateFilesStrategy, _e, isVerbose, jsdom, _f, reader, article, html, i, cacheFilehandler, markdown;
13893
- return __generator(this, function (_g) {
13894
- switch (_g.label) {
13895
- case 0:
13896
- _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;
13897
- // TODO: !!!!!! Does this work in browser? Make it work.
13898
- if (source.url === null) {
13899
- throw new KnowledgeScrapeError('Website scraper requires URL');
13900
- }
13901
- _f = JSDOM.bind;
13902
- return [4 /*yield*/, source.asText()];
13903
- case 1:
13904
- jsdom = new (_f.apply(JSDOM, [void 0, _g.sent(), {
13905
- url: source.url,
13906
- }]))();
13907
- reader = new Readability(jsdom.window.document);
13908
- article = reader.parse();
13909
- html = (article === null || article === void 0 ? void 0 : article.content) || (article === null || article === void 0 ? void 0 : article.textContent) || jsdom.window.document.body.innerHTML;
13910
- // Note: Unwrap html such as it is convertable by `markdownConverter`
13911
- for (i = 0; i < 2; i++) {
13912
- html = html.replace(/<div\s*(?:id="readability-page-\d+"\s+class="page")?>(.*)<\/div>/is, '$1');
13913
- }
13914
- if (html.includes('<div')) {
13915
- html = (article === null || article === void 0 ? void 0 : article.textContent) || '';
13916
- }
13917
- return [4 /*yield*/, getScraperIntermediateSource(source, {
13918
- rootDirname: rootDirname,
13919
- cacheDirname: cacheDirname,
13920
- intermediateFilesStrategy: intermediateFilesStrategy,
13921
- extension: 'html',
13922
- isVerbose: isVerbose,
13923
- })];
13924
- case 2:
13925
- cacheFilehandler = _g.sent();
13926
- return [4 /*yield*/, writeFile(cacheFilehandler.filename, html, 'utf-8')];
13927
- case 3:
13928
- _g.sent();
13929
- markdown = this.showdownConverter.makeMarkdown(html, jsdom.window.document);
13930
- return [2 /*return*/, __assign(__assign({}, cacheFilehandler), { markdown: markdown })];
13931
- }
13932
- });
13933
- });
13934
- };
13935
- /**
13936
- * Scrapes the website and returns the knowledge pieces or `null` if it can't scrape it
13937
- */
13938
- WebsiteScraper.prototype.scrape = function (source) {
13939
- return __awaiter(this, void 0, void 0, function () {
13940
- var cacheFilehandler, markdownSource, knowledge;
13941
- return __generator(this, function (_a) {
13942
- switch (_a.label) {
13943
- case 0: return [4 /*yield*/, this.$convert(source)];
13944
- case 1:
13945
- cacheFilehandler = _a.sent();
13946
- markdownSource = {
13947
- source: source.source,
13948
- filename: cacheFilehandler.filename,
13949
- url: null,
13950
- mimeType: 'text/markdown',
13951
- asText: function () {
13952
- return cacheFilehandler.markdown;
13953
- },
13954
- asJson: function () {
13955
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
13956
- },
13957
- asBlob: function () {
13958
- throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asBlob`');
13959
- },
13960
- };
13961
- knowledge = this.markdownScraper.scrape(markdownSource);
13962
- return [4 /*yield*/, cacheFilehandler.destroy()];
13963
- case 2:
13964
- _a.sent();
13965
- return [2 /*return*/, knowledge];
13966
- }
13967
- });
13968
- });
13969
- };
13970
- return WebsiteScraper;
13971
- }());
13972
- /**
13973
- * TODO: [👣] Scraped website in .md can act as cache item - there is no need to run conversion each time
13974
- * TODO: [🪂] Do it in parallel 11:11
13975
- * Note: No need to aggregate usage here, it is done by intercepting the llmTools
13976
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
13977
- */
13978
-
13979
- /**
13980
- * @@@
13981
- *
13982
- * @public exported from `@promptbook/website-crawler`
13983
- */
13984
- var createWebsiteScraper = Object.assign(function (tools, options) {
13985
- return new WebsiteScraper(tools, options);
13986
- }, websiteScraperMetadata); /* <- TODO: [🤛] */
13987
- /**
13988
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
13989
- */
13990
-
13991
- /**
13992
- * Registration of known scraper
13993
- *
13994
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
13995
- *
13996
- * @public exported from `@promptbook/website-crawler`
13997
- * @public exported from `@promptbook/cli`
13998
- */
13999
- var _WebsiteScraperRegistration = $scrapersRegister.register(createWebsiteScraper);
14000
- /**
14001
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
14002
- */
14003
-
14004
- export { PROMPTBOOK_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };
14063
+ export { PROMPTBOOK_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration };
14005
14064
  //# sourceMappingURL=index.es.js.map